1 | /**
|
2 | * @license
|
3 | * Copyright 2021 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: 'FirebaseError';
|
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.MultiFactorUser} 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 | type FirebaseSignInProvider =
|
1010 | | 'custom'
|
1011 | | 'email'
|
1012 | | 'password'
|
1013 | | 'phone'
|
1014 | | 'anonymous'
|
1015 | | 'google.com'
|
1016 | | 'facebook.com'
|
1017 | | 'github.com'
|
1018 | | 'twitter.com'
|
1019 | | 'microsoft.com'
|
1020 | | 'apple.com';
|
1021 |
|
1022 | interface FirebaseIdToken {
|
1023 | /** Always set to https://securetoken.google.com/PROJECT_ID */
|
1024 | iss: string;
|
1025 |
|
1026 | /** Always set to PROJECT_ID */
|
1027 | aud: string;
|
1028 |
|
1029 | /** The user's unique ID */
|
1030 | sub: string;
|
1031 |
|
1032 | /** The token issue time, in seconds since epoch */
|
1033 | iat: number;
|
1034 |
|
1035 | /** The token expiry time, normally 'iat' + 3600 */
|
1036 | exp: number;
|
1037 |
|
1038 | /** The user's unique ID. Must be equal to 'sub' */
|
1039 | user_id: string;
|
1040 |
|
1041 | /** The time the user authenticated, normally 'iat' */
|
1042 | auth_time: number;
|
1043 |
|
1044 | /** The sign in provider, only set when the provider is 'anonymous' */
|
1045 | provider_id?: 'anonymous';
|
1046 |
|
1047 | /** The user's primary email */
|
1048 | email?: string;
|
1049 |
|
1050 | /** The user's email verification status */
|
1051 | email_verified?: boolean;
|
1052 |
|
1053 | /** The user's primary phone number */
|
1054 | phone_number?: string;
|
1055 |
|
1056 | /** The user's display name */
|
1057 | name?: string;
|
1058 |
|
1059 | /** The user's profile photo URL */
|
1060 | picture?: string;
|
1061 |
|
1062 | /** Information on all identities linked to this user */
|
1063 | firebase: {
|
1064 | /** The primary sign-in provider */
|
1065 | sign_in_provider: FirebaseSignInProvider;
|
1066 |
|
1067 | /** A map of providers to the user's list of unique identifiers from each provider */
|
1068 | identities?: { [provider in FirebaseSignInProvider]?: string[] };
|
1069 | };
|
1070 |
|
1071 | /** Custom claims set by the developer */
|
1072 | [claim: string]: unknown;
|
1073 |
|
1074 | // NO LONGER SUPPORTED. Use "sub" instead. (Not a jsdoc comment to avoid generating docs.)
|
1075 | uid?: never;
|
1076 | }
|
1077 |
|
1078 | export type EmulatorMockTokenOptions = (
|
1079 | | { user_id: string }
|
1080 | | { sub: string }
|
1081 | ) &
|
1082 | Partial<FirebaseIdToken>;
|
1083 |
|
1084 | /**
|
1085 | * Retrieves a Firebase {@link firebase.app.App app} instance.
|
1086 | *
|
1087 | * When called with no arguments, the default app is returned. When an app name
|
1088 | * is provided, the app corresponding to that name is returned.
|
1089 | *
|
1090 | * An exception is thrown if the app being retrieved has not yet been
|
1091 | * initialized.
|
1092 | *
|
1093 | * @example
|
1094 | * ```javascript
|
1095 | * // Return the default app
|
1096 | * var app = firebase.app();
|
1097 | * ```
|
1098 | *
|
1099 | * @example
|
1100 | * ```javascript
|
1101 | * // Return a named app
|
1102 | * var otherApp = firebase.app("otherApp");
|
1103 | * ```
|
1104 | *
|
1105 | * @param name Optional name of the app to return. If no name is
|
1106 | * provided, the default is `"[DEFAULT]"`.
|
1107 | *
|
1108 | * @return The app corresponding to the provided app name.
|
1109 | * If no app name is provided, the default app is returned.
|
1110 | */
|
1111 | function app(name?: string): firebase.app.App;
|
1112 |
|
1113 | /**
|
1114 | * A (read-only) array of all initialized apps.
|
1115 | */
|
1116 | var apps: firebase.app.App[];
|
1117 |
|
1118 | /**
|
1119 | * Gets the {@link firebase.auth.Auth `Auth`} service for the default app or a
|
1120 | * given app.
|
1121 | *
|
1122 | * `firebase.auth()` can be called with no arguments to access the default app's
|
1123 | * {@link firebase.auth.Auth `Auth`} service or as `firebase.auth(app)` to
|
1124 | * access the {@link firebase.auth.Auth `Auth`} service associated with a
|
1125 | * specific app.
|
1126 | *
|
1127 | * @example
|
1128 | * ```javascript
|
1129 | *
|
1130 | * // Get the Auth service for the default app
|
1131 | * var defaultAuth = firebase.auth();
|
1132 | * ```
|
1133 | * @example
|
1134 | * ```javascript
|
1135 | *
|
1136 | * // Get the Auth service for a given app
|
1137 | * var otherAuth = firebase.auth(otherApp);
|
1138 | * ```
|
1139 | * @param app
|
1140 | */
|
1141 | function auth(app?: firebase.app.App): firebase.auth.Auth;
|
1142 |
|
1143 | /**
|
1144 | * Gets the {@link firebase.database.Database `Database`} service for the
|
1145 | * default app or a given app.
|
1146 | *
|
1147 | * `firebase.database()` can be called with no arguments to access the default
|
1148 | * app's {@link firebase.database.Database `Database`} service or as
|
1149 | * `firebase.database(app)` to access the
|
1150 | * {@link firebase.database.Database `Database`} service associated with a
|
1151 | * specific app.
|
1152 | *
|
1153 | * `firebase.database` is also a namespace that can be used to access global
|
1154 | * constants and methods associated with the `Database` service.
|
1155 | *
|
1156 | * @example
|
1157 | * ```javascript
|
1158 | * // Get the Database service for the default app
|
1159 | * var defaultDatabase = firebase.database();
|
1160 | * ```
|
1161 | *
|
1162 | * @example
|
1163 | * ```javascript
|
1164 | * // Get the Database service for a specific app
|
1165 | * var otherDatabase = firebase.database(app);
|
1166 | * ```
|
1167 | *
|
1168 | * @namespace
|
1169 | * @param app Optional app whose Database service to
|
1170 | * return. If not provided, the default Database service will be returned.
|
1171 | * @return The default Database service if no app
|
1172 | * is provided or the Database service associated with the provided app.
|
1173 | */
|
1174 | function database(app?: firebase.app.App): firebase.database.Database;
|
1175 |
|
1176 | /**
|
1177 | * Creates and initializes a Firebase {@link firebase.app.App app} instance.
|
1178 | *
|
1179 | * See
|
1180 | * {@link
|
1181 | * https://firebase.google.com/docs/web/setup#add_firebase_to_your_app
|
1182 | * Add Firebase to your app} and
|
1183 | * {@link
|
1184 | * https://firebase.google.com/docs/web/learn-more#multiple-projects
|
1185 | * Initialize multiple projects} for detailed documentation.
|
1186 | *
|
1187 | * @example
|
1188 | * ```javascript
|
1189 | *
|
1190 | * // Initialize default app
|
1191 | * // Retrieve your own options values by adding a web app on
|
1192 | * // https://console.firebase.google.com
|
1193 | * firebase.initializeApp({
|
1194 | * apiKey: "AIza....", // Auth / General Use
|
1195 | * appId: "1:27992087142:web:ce....", // General Use
|
1196 | * projectId: "my-firebase-project", // General Use
|
1197 | * authDomain: "YOUR_APP.firebaseapp.com", // Auth with popup/redirect
|
1198 | * databaseURL: "https://YOUR_APP.firebaseio.com", // Realtime Database
|
1199 | * storageBucket: "YOUR_APP.appspot.com", // Storage
|
1200 | * messagingSenderId: "123456789", // Cloud Messaging
|
1201 | * measurementId: "G-12345" // Analytics
|
1202 | * });
|
1203 | * ```
|
1204 | *
|
1205 | * @example
|
1206 | * ```javascript
|
1207 | *
|
1208 | * // Initialize another app
|
1209 | * var otherApp = firebase.initializeApp({
|
1210 | * apiKey: "AIza....",
|
1211 | * appId: "1:27992087142:web:ce....",
|
1212 | * projectId: "my-firebase-project",
|
1213 | * databaseURL: "https://<OTHER_DATABASE_NAME>.firebaseio.com",
|
1214 | * storageBucket: "<OTHER_STORAGE_BUCKET>.appspot.com"
|
1215 | * }, "nameOfOtherApp");
|
1216 | * ```
|
1217 | *
|
1218 | * @param options Options to configure the app's services.
|
1219 | * @param name Optional name of the app to initialize. If no name
|
1220 | * is provided, the default is `"[DEFAULT]"`.
|
1221 | *
|
1222 | * @return {!firebase.app.App} The initialized app.
|
1223 | */
|
1224 | function initializeApp(options: Object, name?: string): firebase.app.App;
|
1225 |
|
1226 | /**
|
1227 | * Gets the {@link firebase.messaging.Messaging `Messaging`} service for the
|
1228 | * default app or a given app.
|
1229 | *
|
1230 | * `firebase.messaging()` can be called with no arguments to access the default
|
1231 | * app's {@link firebase.messaging.Messaging `Messaging`} service or as
|
1232 | * `firebase.messaging(app)` to access the
|
1233 | * {@link firebase.messaging.Messaging `Messaging`} service associated with a
|
1234 | * specific app.
|
1235 | *
|
1236 | * Calling `firebase.messaging()` in a service worker results in Firebase
|
1237 | * generating notifications if the push message payload has a `notification`
|
1238 | * parameter.
|
1239 | *
|
1240 | * @webonly
|
1241 | *
|
1242 | * @example
|
1243 | * ```javascript
|
1244 | * // Get the Messaging service for the default app
|
1245 | * var defaultMessaging = firebase.messaging();
|
1246 | * ```
|
1247 | *
|
1248 | * @example
|
1249 | * ```javascript
|
1250 | * // Get the Messaging service for a given app
|
1251 | * var otherMessaging = firebase.messaging(otherApp);
|
1252 | * ```
|
1253 | *
|
1254 | * @namespace
|
1255 | * @param app The app to create a Messaging service for.
|
1256 | * If not passed, uses the default app.
|
1257 | */
|
1258 | function messaging(app?: firebase.app.App): firebase.messaging.Messaging;
|
1259 |
|
1260 | /**
|
1261 | * Gets the {@link firebase.storage.Storage `Storage`} service for the default
|
1262 | * app or a given app.
|
1263 | *
|
1264 | * `firebase.storage()` can be called with no arguments to access the default
|
1265 | * app's {@link firebase.storage.Storage `Storage`} service or as
|
1266 | * `firebase.storage(app)` to access the
|
1267 | * {@link firebase.storage.Storage `Storage`} service associated with a
|
1268 | * specific app.
|
1269 | *
|
1270 | * @example
|
1271 | * ```javascript
|
1272 | * // Get the Storage service for the default app
|
1273 | * var defaultStorage = firebase.storage();
|
1274 | * ```
|
1275 | *
|
1276 | * @example
|
1277 | * ```javascript
|
1278 | * // Get the Storage service for a given app
|
1279 | * var otherStorage = firebase.storage(otherApp);
|
1280 | * ```
|
1281 | *
|
1282 | * @param app The app to create a storage service for.
|
1283 | * If not passed, uses the default app.
|
1284 | */
|
1285 | function storage(app?: firebase.app.App): firebase.storage.Storage;
|
1286 |
|
1287 | function firestore(app?: firebase.app.App): firebase.firestore.Firestore;
|
1288 |
|
1289 | function functions(app?: firebase.app.App): firebase.functions.Functions;
|
1290 |
|
1291 | /**
|
1292 | * Gets the {@link firebase.performance.Performance `Performance`} service.
|
1293 | *
|
1294 | * `firebase.performance()` can be called with no arguments to access the default
|
1295 | * app's { firebase.performance.Performance `Performance`} service.
|
1296 | * The {`Performance`} service does not work with
firebase.performance.Performance |
1297 | * any other app.
|
1298 | *
|
1299 | *
|
1300 | *
|
1301 | *
|
1302 | * ```javascript
|
1303 | * // Get the Performance service for the default app
|
1304 | * const defaultPerformance = firebase.performance();
|
1305 | * ```
|
1306 | *
|
1307 | * for. Performance Monitoring only works with
app The app to create a performance service |
1308 | * the default app.
|
1309 | * If not passed, uses the default app.
|
1310 | */
|
1311 | function performance(
|
1312 | app?: firebase.app.App
|
1313 | ): firebase.performance.Performance;
|
1314 |
|
1315 | /**
|
1316 | * Gets the {@link firebase.remoteConfig.RemoteConfig `RemoteConfig`} instance.
|
1317 | *
|
1318 | * @webonly
|
1319 | *
|
1320 | * @example
|
1321 | * ```javascript
|
1322 | * // Get the RemoteConfig instance for the default app
|
1323 | * const defaultRemoteConfig = firebase.remoteConfig();
|
1324 | * ```
|
1325 | *
|
1326 | * @param app The app to create a Remote Config service for. If not passed, uses the default app.
|
1327 | */
|
1328 | function remoteConfig(
|
1329 | app?: firebase.app.App
|
1330 | ): firebase.remoteConfig.RemoteConfig;
|
1331 |
|
1332 | /**
|
1333 | * Gets the {@link firebase.analytics.Analytics `Analytics`} service.
|
1334 | *
|
1335 | * `firebase.analytics()` can be called with no arguments to access the default
|
1336 | * app's {@link firebase.analytics.Analytics `Analytics`} service.
|
1337 | *
|
1338 | * @webonly
|
1339 | *
|
1340 | * @example
|
1341 | * ```javascript
|
1342 | * // Get the Analytics service for the default app
|
1343 | * const defaultAnalytics = firebase.analytics();
|
1344 | * ```
|
1345 | *
|
1346 | * @param app The app to create an analytics service for.
|
1347 | * If not passed, uses the default app.
|
1348 | */
|
1349 | function analytics(app?: firebase.app.App): firebase.analytics.Analytics;
|
1350 |
|
1351 | function appCheck(app?: firebase.app.App): firebase.appCheck.AppCheck;
|
1352 | }
|
1353 |
|
1354 | declare namespace firebase.app {
|
1355 | /**
|
1356 | * A Firebase App holds the initialization information for a collection of
|
1357 | * services.
|
1358 | *
|
1359 | * Do not call this constructor directly. Instead, use
|
1360 | * {@link firebase.initializeApp|`firebase.initializeApp()`} to create an app.
|
1361 | *
|
1362 | */
|
1363 | interface App {
|
1364 | /**
|
1365 | * Gets the {@link firebase.auth.Auth `Auth`} service for the current app.
|
1366 | *
|
1367 | * @example
|
1368 | * ```javascript
|
1369 | * var auth = app.auth();
|
1370 | * // The above is shorthand for:
|
1371 | * // var auth = firebase.auth(app);
|
1372 | * ```
|
1373 | */
|
1374 | auth(): firebase.auth.Auth;
|
1375 | /**
|
1376 | * Gets the {@link firebase.database.Database `Database`} service for the
|
1377 | * current app.
|
1378 | *
|
1379 | * @example
|
1380 | * ```javascript
|
1381 | * var database = app.database();
|
1382 | * // The above is shorthand for:
|
1383 | * // var database = firebase.database(app);
|
1384 | * ```
|
1385 | */
|
1386 | database(url?: string): firebase.database.Database;
|
1387 | /**
|
1388 | * Renders this app unusable and frees the resources of all associated
|
1389 | * services.
|
1390 | *
|
1391 | * @example
|
1392 | * ```javascript
|
1393 | * app.delete()
|
1394 | * .then(function() {
|
1395 | * console.log("App deleted successfully");
|
1396 | * })
|
1397 | * .catch(function(error) {
|
1398 | * console.log("Error deleting app:", error);
|
1399 | * });
|
1400 | * ```
|
1401 | */
|
1402 | delete(): Promise<any>;
|
1403 | /**
|
1404 | * Gets the {@link firebase.installations.Installations `Installations`} service for the
|
1405 | * current app.
|
1406 | *
|
1407 | * @webonly
|
1408 | *
|
1409 | * @example
|
1410 | * ```javascript
|
1411 | * const installations = app.installations();
|
1412 | * // The above is shorthand for:
|
1413 | * // const installations = firebase.installations(app);
|
1414 | * ```
|
1415 | */
|
1416 | installations(): firebase.installations.Installations;
|
1417 | /**
|
1418 | * Gets the {@link firebase.messaging.Messaging `Messaging`} service for the
|
1419 | * current app.
|
1420 | *
|
1421 | * @webonly
|
1422 | *
|
1423 | * @example
|
1424 | * ```javascript
|
1425 | * var messaging = app.messaging();
|
1426 | * // The above is shorthand for:
|
1427 | * // var messaging = firebase.messaging(app);
|
1428 | * ```
|
1429 | */
|
1430 | messaging(): firebase.messaging.Messaging;
|
1431 | /**
|
1432 | * The (read-only) name for this app.
|
1433 | *
|
1434 | * The default app's name is `"[DEFAULT]"`.
|
1435 | *
|
1436 | * @example
|
1437 | * ```javascript
|
1438 | * // The default app's name is "[DEFAULT]"
|
1439 | * firebase.initializeApp(defaultAppConfig);
|
1440 | * console.log(firebase.app().name); // "[DEFAULT]"
|
1441 | * ```
|
1442 | *
|
1443 | * @example
|
1444 | * ```javascript
|
1445 | * // A named app's name is what you provide to initializeApp()
|
1446 | * var otherApp = firebase.initializeApp(otherAppConfig, "other");
|
1447 | * console.log(otherApp.name); // "other"
|
1448 | * ```
|
1449 | */
|
1450 | name: string;
|
1451 | /**
|
1452 | * The settable config flag for GDPR opt-in/opt-out
|
1453 | */
|
1454 | automaticDataCollectionEnabled: boolean;
|
1455 | /**
|
1456 | * The (read-only) configuration options for this app. These are the original
|
1457 | * parameters given in
|
1458 | * {@link firebase.initializeApp `firebase.initializeApp()`}.
|
1459 | *
|
1460 | * @example
|
1461 | * ```javascript
|
1462 | * var app = firebase.initializeApp(config);
|
1463 | * console.log(app.options.databaseURL === config.databaseURL); // true
|
1464 | * ```
|
1465 | */
|
1466 | options: Object;
|
1467 | /**
|
1468 | * Gets the {@link firebase.storage.Storage `Storage`} service for the current
|
1469 | * app, optionally initialized with a custom storage bucket.
|
1470 | *
|
1471 | * @example
|
1472 | * ```javascript
|
1473 | * var storage = app.storage();
|
1474 | * // The above is shorthand for:
|
1475 | * // var storage = firebase.storage(app);
|
1476 | * ```
|
1477 | *
|
1478 | * @example
|
1479 | * ```javascript
|
1480 | * var storage = app.storage("gs://your-app.appspot.com");
|
1481 | * ```
|
1482 | *
|
1483 | * @param url The gs:// url to your Firebase Storage Bucket.
|
1484 | * If not passed, uses the app's default Storage Bucket.
|
1485 | */
|
1486 | storage(url?: string): firebase.storage.Storage;
|
1487 | firestore(): firebase.firestore.Firestore;
|
1488 | functions(regionOrCustomDomain?: string): firebase.functions.Functions;
|
1489 | /**
|
1490 | * Gets the { firebase.performance.Performance `Performance`} service for the
|
1491 | * current app. If the current app is not the default one, throws an error.
|
1492 | *
|
1493 | *
|
1494 | *
|
1495 | *
|
1496 | * ```javascript
|
1497 | * const perf = app.performance();
|
1498 | * // The above is shorthand for:
|
1499 | * // const perf = firebase.performance(app);
|
1500 | * ```
|
1501 | */
|
1502 | performance(): firebase.performance.Performance;
|
1503 | /**
|
1504 | * Gets the {@link firebase.remoteConfig.RemoteConfig `RemoteConfig`} instance.
|
1505 | *
|
1506 | * @webonly
|
1507 | *
|
1508 | * @example
|
1509 | * ```javascript
|
1510 | * const rc = app.remoteConfig();
|
1511 | * // The above is shorthand for:
|
1512 | * // const rc = firebase.remoteConfig(app);
|
1513 | * ```
|
1514 | */
|
1515 | remoteConfig(): firebase.remoteConfig.RemoteConfig;
|
1516 | /**
|
1517 | * Gets the {@link firebase.analytics.Analytics `Analytics`} service for the
|
1518 | * current app. If the current app is not the default one, throws an error.
|
1519 | *
|
1520 | * @webonly
|
1521 | *
|
1522 | * @example
|
1523 | * ```javascript
|
1524 | * const analytics = app.analytics();
|
1525 | * // The above is shorthand for:
|
1526 | * // const analytics = firebase.analytics(app);
|
1527 | * ```
|
1528 | */
|
1529 | analytics(): firebase.analytics.Analytics;
|
1530 | appCheck(): firebase.appCheck.AppCheck;
|
1531 | }
|
1532 | }
|
1533 |
|
1534 | /**
|
1535 | * @webonly
|
1536 | */
|
1537 | declare namespace firebase.appCheck {
|
1538 | /**
|
1539 | * Result returned by
|
1540 | * {@link firebase.appCheck.AppCheck.getToken `firebase.appCheck().getToken()`}.
|
1541 | */
|
1542 | interface AppCheckTokenResult {
|
1543 | token: string;
|
1544 | }
|
1545 | /*
|
1546 | * reCAPTCHA v3 token provider.
|
1547 | */
|
1548 | class ReCaptchaV3Provider {
|
1549 | /**
|
1550 | * @param siteKey - reCAPTCHA v3 site key (public key).
|
1551 | */
|
1552 | constructor(siteKey: string);
|
1553 | }
|
1554 | /*
|
1555 | * reCAPTCHA Enterprise token provider.
|
1556 | */
|
1557 | class ReCaptchaEnterpriseProvider {
|
1558 | /**
|
1559 | * @param keyId - reCAPTCHA Enterprise key ID.
|
1560 | */
|
1561 | constructor(keyId: string);
|
1562 | }
|
1563 | /*
|
1564 | * Custom token provider.
|
1565 | */
|
1566 | class CustomProvider {
|
1567 | /**
|
1568 | * @param options - Options for creating the custom provider.
|
1569 | */
|
1570 | constructor(options: CustomProviderOptions);
|
1571 | }
|
1572 | /**
|
1573 | * Options when creating a CustomProvider.
|
1574 | */
|
1575 | interface CustomProviderOptions {
|
1576 | /**
|
1577 | * Function to get an App Check token through a custom provider
|
1578 | * service.
|
1579 | */
|
1580 | getToken: () => Promise<AppCheckToken>;
|
1581 | }
|
1582 |
|
1583 | /**
|
1584 | * The Firebase AppCheck service interface.
|
1585 | *
|
1586 | * Do not call this constructor directly. Instead, use
|
1587 | * {@link firebase.appCheck `firebase.appCheck()`}.
|
1588 | */
|
1589 | export interface AppCheck {
|
1590 | /**
|
1591 | * Activate AppCheck
|
1592 | * @param provider This can be a `ReCaptchaV3Provider` instance,
|
1593 | * a `ReCaptchaEnterpriseProvider` instance, a `CustomProvider` instance,
|
1594 | * an object with a custom `getToken()` method, or a reCAPTCHA site key.
|
1595 | * @param isTokenAutoRefreshEnabled If true, the SDK automatically
|
1596 | * refreshes App Check tokens as needed. If undefined, defaults to the
|
1597 | * value of `app.automaticDataCollectionEnabled`, which defaults to
|
1598 | * false and can be set in the app config.
|
1599 | */
|
1600 | activate(
|
1601 | provider:
|
1602 | | ReCaptchaV3Provider
|
1603 | | ReCaptchaEnterpriseProvider
|
1604 | | CustomProvider
|
1605 | | AppCheckProvider
|
1606 | | { getToken: () => AppCheckToken }
|
1607 | | string,
|
1608 | isTokenAutoRefreshEnabled?: boolean
|
1609 | ): void;
|
1610 |
|
1611 | /**
|
1612 | *
|
1613 | * @param isTokenAutoRefreshEnabled If true, the SDK automatically
|
1614 | * refreshes App Check tokens as needed. This overrides any value set
|
1615 | * during `activate()`.
|
1616 | */
|
1617 | setTokenAutoRefreshEnabled(isTokenAutoRefreshEnabled: boolean): void;
|
1618 | /**
|
1619 | * Get the current App Check token. Attaches to the most recent
|
1620 | * in-flight request if one is present. Returns null if no token
|
1621 | * is present and no token requests are in-flight.
|
1622 | *
|
1623 | * @param forceRefresh - If true, will always try to fetch a fresh token.
|
1624 | * If false, will use a cached token if found in storage.
|
1625 | */
|
1626 | getToken(
|
1627 | forceRefresh?: boolean
|
1628 | ): Promise<firebase.appCheck.AppCheckTokenResult>;
|
1629 |
|
1630 | /**
|
1631 | * Registers a listener to changes in the token state. There can be more
|
1632 | * than one listener registered at the same time for one or more
|
1633 | * App Check instances. The listeners call back on the UI thread whenever
|
1634 | * the current token associated with this App Check instance changes.
|
1635 | *
|
1636 | * @param observer An object with `next`, `error`, and `complete`
|
1637 | * properties. `next` is called with an
|
1638 | * {@link firebase.appCheck.AppCheckTokenResult `AppCheckTokenResult`}
|
1639 | * whenever the token changes. `error` is optional and is called if an
|
1640 | * error is thrown by the listener (the `next` function). `complete`
|
1641 | * is unused, as the token stream is unending.
|
1642 | *
|
1643 | * @returns A function that unsubscribes this listener.
|
1644 | */
|
1645 | onTokenChanged(observer: {
|
1646 | next: (tokenResult: firebase.appCheck.AppCheckTokenResult) => void;
|
1647 | error?: (error: Error) => void;
|
1648 | complete?: () => void;
|
1649 | }): Unsubscribe;
|
1650 |
|
1651 | /**
|
1652 | * Registers a listener to changes in the token state. There can be more
|
1653 | * than one listener registered at the same time for one or more
|
1654 | * App Check instances. The listeners call back on the UI thread whenever
|
1655 | * the current token associated with this App Check instance changes.
|
1656 | *
|
1657 | * @param onNext When the token changes, this function is called with aa
|
1658 | * {@link firebase.appCheck.AppCheckTokenResult `AppCheckTokenResult`}.
|
1659 | * @param onError Optional. Called if there is an error thrown by the
|
1660 | * listener (the `onNext` function).
|
1661 | * @param onCompletion Currently unused, as the token stream is unending.
|
1662 | * @returns A function that unsubscribes this listener.
|
1663 | */
|
1664 | onTokenChanged(
|
1665 | onNext: (tokenResult: firebase.appCheck.AppCheckTokenResult) => void,
|
1666 | onError?: (error: Error) => void,
|
1667 | onCompletion?: () => void
|
1668 | ): Unsubscribe;
|
1669 | }
|
1670 |
|
1671 | /**
|
1672 | * An App Check provider. This can be either the built-in reCAPTCHA
|
1673 | * provider or a custom provider. For more on custom providers, see
|
1674 | * https://firebase.google.com/docs/app-check/web-custom-provider
|
1675 | */
|
1676 | interface AppCheckProvider {
|
1677 | /**
|
1678 | * Returns an AppCheck token.
|
1679 | */
|
1680 | getToken(): Promise<AppCheckToken>;
|
1681 | }
|
1682 |
|
1683 | /**
|
1684 | * The token returned from an {@link firebase.appCheck.AppCheckProvider `AppCheckProvider`}.
|
1685 | */
|
1686 | interface AppCheckToken {
|
1687 | /**
|
1688 | * The token string in JWT format.
|
1689 | */
|
1690 | readonly token: string;
|
1691 | /**
|
1692 | * The local timestamp after which the token will expire.
|
1693 | */
|
1694 | readonly expireTimeMillis: number;
|
1695 | }
|
1696 | }
|
1697 |
|
1698 | /**
|
1699 | * @webonly
|
1700 | */
|
1701 | declare namespace firebase.installations {
|
1702 | /**
|
1703 | * The Firebase Installations service interface.
|
1704 | *
|
1705 | * Do not call this constructor directly. Instead, use
|
1706 | * {@link firebase.installations `firebase.installations()`}.
|
1707 | */
|
1708 | export interface Installations {
|
1709 | /**
|
1710 | * The {@link firebase.app.App app} associated with the `Installations` service
|
1711 | * instance.
|
1712 | *
|
1713 | * @example
|
1714 | * ```javascript
|
1715 | * var app = analytics.app;
|
1716 | * ```
|
1717 | */
|
1718 | app: firebase.app.App;
|
1719 | /**
|
1720 | * Creates a Firebase Installation if there isn't one for the app and
|
1721 | * returns the Installation ID.
|
1722 | *
|
1723 | * @return Firebase Installation ID
|
1724 | */
|
1725 | getId(): Promise<string>;
|
1726 |
|
1727 | /**
|
1728 | * Returns an Authentication Token for the current Firebase Installation.
|
1729 | *
|
1730 | * @return Firebase Installation Authentication Token
|
1731 | */
|
1732 | getToken(forceRefresh?: boolean): Promise<string>;
|
1733 |
|
1734 | /**
|
1735 | * Deletes the Firebase Installation and all associated data.
|
1736 | */
|
1737 | delete(): Promise<void>;
|
1738 |
|
1739 | /**
|
1740 | * Sets a new callback that will get called when Installlation ID changes.
|
1741 | * Returns an unsubscribe function that will remove the callback when called.
|
1742 | */
|
1743 | onIdChange(callback: (installationId: string) => void): () => void;
|
1744 | }
|
1745 | }
|
1746 |
|
1747 | /**
|
1748 | * @webonly
|
1749 | */
|
1750 | declare namespace firebase.performance {
|
1751 | /**
|
1752 | * The Firebase Performance Monitoring service interface.
|
1753 | *
|
1754 | * Do not call this constructor directly. Instead, use
|
1755 | * {@link firebase.performance `firebase.performance()`}.
|
1756 | */
|
1757 | export interface Performance {
|
1758 | /**
|
1759 | * The {@link firebase.app.App app} associated with the `Performance` service
|
1760 | * instance.
|
1761 | *
|
1762 | * @example
|
1763 | * ```javascript
|
1764 | * var app = analytics.app;
|
1765 | * ```
|
1766 | */
|
1767 | app: firebase.app.App;
|
1768 | /**
|
1769 | * Creates an uninitialized instance of {@link firebase.performance.Trace `trace`} and returns
|
1770 | * it.
|
1771 | *
|
1772 | * @param traceName The name of the trace instance.
|
1773 | * @return The Trace instance.
|
1774 | */
|
1775 | trace(traceName: string): Trace;
|
1776 |
|
1777 | /**
|
1778 | * Controls the logging of automatic traces and HTTP/S network monitoring.
|
1779 | */
|
1780 | instrumentationEnabled: boolean;
|
1781 | /**
|
1782 | * Controls the logging of custom traces.
|
1783 | */
|
1784 | dataCollectionEnabled: boolean;
|
1785 | }
|
1786 |
|
1787 | export interface Trace {
|
1788 | /**
|
1789 | * Starts the timing for the {@link firebase.performance.Trace `trace`} instance.
|
1790 | */
|
1791 | start(): void;
|
1792 | /**
|
1793 | * Stops the timing of the {@link firebase.performance.Trace `trace`} instance and logs the
|
1794 | * data of the instance.
|
1795 | */
|
1796 | stop(): void;
|
1797 | /**
|
1798 | * Records a {@link firebase.performance.Trace `trace`} from given parameters. This provides a
|
1799 | * direct way to use {@link firebase.performance.Trace `trace`} without a need to start/stop.
|
1800 | * This is useful for use cases in which the {@link firebase.performance.Trace `trace`} cannot
|
1801 | * directly be used (e.g. if the duration was captured before the Performance SDK was loaded).
|
1802 | *
|
1803 | * @param startTime Trace start time since epoch in millisec.
|
1804 | * @param duration The duraction of the trace in millisec.
|
1805 | * @param options An object which can optionally hold maps of custom metrics and
|
1806 | * custom attributes.
|
1807 | */
|
1808 | record(
|
1809 | startTime: number,
|
1810 | duration: number,
|
1811 | options?: {
|
1812 | metrics?: { [key: string]: number };
|
1813 | attributes?: { [key: string]: string };
|
1814 | }
|
1815 | ): void;
|
1816 | /**
|
1817 | * Adds to the value of a custom metric. If a custom metric with the provided name does not
|
1818 | * exist, it creates one with that name and the value equal to the given number.
|
1819 | *
|
1820 | * @param metricName The name of the custom metric.
|
1821 | * @param num The number to be added to the value of the custom metric. If not provided, it
|
1822 | * uses a default value of one.
|
1823 | */
|
1824 | incrementMetric(metricName: string, num?: number): void;
|
1825 | /**
|
1826 | * Sets the value of the specified custom metric to the given number regardless of whether
|
1827 | * a metric with that name already exists on the {@link firebase.performance.Trace `trace`}
|
1828 | * instance or not.
|
1829 | *
|
1830 | * @param metricName Name of the custom metric.
|
1831 | * @param num Value to of the custom metric.
|
1832 | */
|
1833 | putMetric(metricName: string, num: number): void;
|
1834 | /**
|
1835 | * Returns the value of the custom metric by that name. If a custom metric with that name does
|
1836 | * not exist returns zero.
|
1837 | *
|
1838 | * @param metricName Name of the custom metric.
|
1839 | */
|
1840 | getMetric(metricName: string): number;
|
1841 | /**
|
1842 | * Set a custom attribute of a {@link firebase.performance.Trace `trace`} to a certain value.
|
1843 | *
|
1844 | * @param attr Name of the custom attribute.
|
1845 | * @param value Value of the custom attribute.
|
1846 | */
|
1847 | putAttribute(attr: string, value: string): void;
|
1848 | /**
|
1849 | * Retrieves the value that the custom attribute is set to.
|
1850 | *
|
1851 | * @param attr Name of the custom attribute.
|
1852 | */
|
1853 | getAttribute(attr: string): string | undefined;
|
1854 | /**
|
1855 | * Removes the specified custom attribute from a {@link firebase.performance.Trace `trace`}
|
1856 | * instance.
|
1857 | *
|
1858 | * @param attr Name of the custom attribute.
|
1859 | */
|
1860 |
|
1861 | removeAttribute(attr: string): void;
|
1862 | /**
|
1863 | * Returns a map of all custom attributes of a {@link firebase.performance.Trace `trace`}
|
1864 | * instance.
|
1865 | */
|
1866 | getAttributes(): { [key: string]: string };
|
1867 | }
|
1868 | }
|
1869 |
|
1870 | /**
|
1871 | * @webonly
|
1872 | */
|
1873 | declare namespace firebase.remoteConfig {
|
1874 | /**
|
1875 | * The Firebase Remote Config service interface.
|
1876 | *
|
1877 | * Do not call this constructor directly. Instead, use
|
1878 | * {@link firebase.remoteConfig `firebase.remoteConfig()`}.
|
1879 | */
|
1880 | export interface RemoteConfig {
|
1881 | /**
|
1882 | * The {@link firebase.app.App app} associated with the `Performance` service
|
1883 | * instance.
|
1884 | *
|
1885 | * @example
|
1886 | * ```javascript
|
1887 | * var app = analytics.app;
|
1888 | * ```
|
1889 | */
|
1890 | app: firebase.app.App;
|
1891 | /**
|
1892 | * Defines configuration for the Remote Config SDK.
|
1893 | */
|
1894 | settings: Settings;
|
1895 |
|
1896 | /**
|
1897 | * Object containing default values for conigs.
|
1898 | */
|
1899 | defaultConfig: { [key: string]: string | number | boolean };
|
1900 |
|
1901 | /**
|
1902 | * The Unix timestamp in milliseconds of the last <i>successful</i> fetch, or negative one if
|
1903 | * the {@link RemoteConfig} instance either hasn't fetched or initialization
|
1904 | * is incomplete.
|
1905 | */
|
1906 | fetchTimeMillis: number;
|
1907 |
|
1908 | /**
|
1909 | * The status of the last fetch <i>attempt</i>.
|
1910 | */
|
1911 | lastFetchStatus: FetchStatus;
|
1912 |
|
1913 | /**
|
1914 | * Makes the last fetched config available to the getters.
|
1915 | * Returns a promise which resolves to true if the current call activated the fetched configs.
|
1916 | * If the fetched configs were already activated, the promise will resolve to false.
|
1917 | */
|
1918 | activate(): Promise<boolean>;
|
1919 |
|
1920 | /**
|
1921 | * Ensures the last activated config are available to the getters.
|
1922 | */
|
1923 | ensureInitialized(): Promise<void>;
|
1924 |
|
1925 | /**
|
1926 | * Fetches and caches configuration from the Remote Config service.
|
1927 | */
|
1928 | fetch(): Promise<void>;
|
1929 |
|
1930 | /**
|
1931 | * Performs fetch and activate operations, as a convenience.
|
1932 | * Returns a promise which resolves to true if the current call activated the fetched configs.
|
1933 | * If the fetched configs were already activated, the promise will resolve to false.
|
1934 | */
|
1935 | fetchAndActivate(): Promise<boolean>;
|
1936 |
|
1937 | /**
|
1938 | * Gets all config.
|
1939 | */
|
1940 | getAll(): { [key: string]: Value };
|
1941 |
|
1942 | /**
|
1943 | * Gets the value for the given key as a boolean.
|
1944 | *
|
1945 | * Convenience method for calling <code>remoteConfig.getValue(key).asBoolean()</code>.
|
1946 | */
|
1947 | getBoolean(key: string): boolean;
|
1948 |
|
1949 | /**
|
1950 | * Gets the value for the given key as a number.
|
1951 | *
|
1952 | * Convenience method for calling <code>remoteConfig.getValue(key).asNumber()</code>.
|
1953 | */
|
1954 | getNumber(key: string): number;
|
1955 |
|
1956 | /**
|
1957 | * Gets the value for the given key as a String.
|
1958 | *
|
1959 | * Convenience method for calling <code>remoteConfig.getValue(key).asString()</code>.
|
1960 | */
|
1961 | getString(key: string): string;
|
1962 |
|
1963 | /**
|
1964 | * Gets the {@link Value} for the given key.
|
1965 | */
|
1966 | getValue(key: string): Value;
|
1967 |
|
1968 | /**
|
1969 | * Defines the log level to use.
|
1970 | */
|
1971 | setLogLevel(logLevel: LogLevel): void;
|
1972 | }
|
1973 |
|
1974 | /**
|
1975 | * Indicates the source of a value.
|
1976 | *
|
1977 | * <ul>
|
1978 | * <li>"static" indicates the value was defined by a static constant.</li>
|
1979 | * <li>"default" indicates the value was defined by default config.</li>
|
1980 | * <li>"remote" indicates the value was defined by fetched config.</li>
|
1981 | * </ul>
|
1982 | */
|
1983 | export type ValueSource = 'static' | 'default' | 'remote';
|
1984 |
|
1985 | /**
|
1986 | * Wraps a value with metadata and type-safe getters.
|
1987 | */
|
1988 | export interface Value {
|
1989 | /**
|
1990 | * Gets the value as a boolean.
|
1991 | *
|
1992 | * The following values (case insensitive) are interpreted as true:
|
1993 | * "1", "true", "t", "yes", "y", "on". Other values are interpreted as false.
|
1994 | */
|
1995 | asBoolean(): boolean;
|
1996 |
|
1997 | /**
|
1998 | * Gets the value as a number. Comparable to calling <code>Number(value) || 0</code>.
|
1999 | */
|
2000 | asNumber(): number;
|
2001 |
|
2002 | /**
|
2003 | * Gets the value as a string.
|
2004 | */
|
2005 | asString(): string;
|
2006 |
|
2007 | /**
|
2008 | * Gets the {@link ValueSource} for the given key.
|
2009 | */
|
2010 | getSource(): ValueSource;
|
2011 | }
|
2012 |
|
2013 | /**
|
2014 | * Defines configuration options for the Remote Config SDK.
|
2015 | */
|
2016 | export interface Settings {
|
2017 | /**
|
2018 | * Defines the maximum age in milliseconds of an entry in the config cache before
|
2019 | * it is considered stale. Defaults to 43200000 (Twelve hours).
|
2020 | */
|
2021 | minimumFetchIntervalMillis: number;
|
2022 |
|
2023 | /**
|
2024 | * Defines the maximum amount of milliseconds to wait for a response when fetching
|
2025 | * configuration from the Remote Config server. Defaults to 60000 (One minute).
|
2026 | */
|
2027 | fetchTimeoutMillis: number;
|
2028 | }
|
2029 |
|
2030 | /**
|
2031 | * Summarizes the outcome of the last attempt to fetch config from the Firebase Remote Config server.
|
2032 | *
|
2033 | * <ul>
|
2034 | * <li>"no-fetch-yet" indicates the {@link RemoteConfig} instance has not yet attempted
|
2035 | * to fetch config, or that SDK initialization is incomplete.</li>
|
2036 | * <li>"success" indicates the last attempt succeeded.</li>
|
2037 | * <li>"failure" indicates the last attempt failed.</li>
|
2038 | * <li>"throttle" indicates the last attempt was rate-limited.</li>
|
2039 | * </ul>
|
2040 | */
|
2041 | export type FetchStatus = 'no-fetch-yet' | 'success' | 'failure' | 'throttle';
|
2042 |
|
2043 | /**
|
2044 | * Defines levels of Remote Config logging.
|
2045 | */
|
2046 | export type LogLevel = 'debug' | 'error' | 'silent';
|
2047 | /**
|
2048 | * This method provides two different checks:
|
2049 | *
|
2050 | * 1. Check if IndexedDB exists in the browser environment.
|
2051 | * 2. Check if the current browser context allows IndexedDB `open()` calls.
|
2052 | *
|
2053 | * It returns a `Promise` which resolves to true if a {@link RemoteConfig} instance
|
2054 | * can be initialized in this environment, or false if it cannot.
|
2055 | */
|
2056 | export function isSupported(): Promise<boolean>;
|
2057 | }
|
2058 |
|
2059 | declare namespace firebase.functions {
|
2060 | /**
|
2061 | * An HttpsCallableResult wraps a single result from a function call.
|
2062 | */
|
2063 | export interface HttpsCallableResult {
|
2064 | readonly data: any;
|
2065 | }
|
2066 | /**
|
2067 | * An HttpsCallable is a reference to a "callable" http trigger in
|
2068 | * Google Cloud Functions.
|
2069 | */
|
2070 | export interface HttpsCallable {
|
2071 | (data?: any): Promise<HttpsCallableResult>;
|
2072 | }
|
2073 | export interface HttpsCallableOptions {
|
2074 | timeout?: number;
|
2075 | }
|
2076 | /**
|
2077 | * The Cloud Functions for Firebase service interface.
|
2078 | *
|
2079 | * Do not call this constructor directly. Instead, use
|
2080 | * {@link firebase.functions `firebase.functions()`}.
|
2081 | */
|
2082 | export class Functions {
|
2083 | private constructor();
|
2084 |
|
2085 | /**
|
2086 | * Modify this instance to communicate with the Cloud Functions emulator.
|
2087 | *
|
2088 | * Note: this must be called before this instance has been used to do any operations.
|
2089 | *
|
2090 | * @param host The emulator host (ex: localhost)
|
2091 | * @param port The emulator port (ex: 5001)
|
2092 | */
|
2093 | useEmulator(host: string, port: number): void;
|
2094 |
|
2095 | /**
|
2096 | * Changes this instance to point to a Cloud Functions emulator running
|
2097 | * locally. See https://firebase.google.com/docs/functions/local-emulator
|
2098 | *
|
2099 | * @deprecated Prefer the useEmulator(host, port) method.
|
2100 | * @param origin The origin of the local emulator, such as
|
2101 | * "http://localhost:5005".
|
2102 | */
|
2103 | useFunctionsEmulator(url: string): void;
|
2104 | /**
|
2105 | * Gets an `HttpsCallable` instance that refers to the function with the given
|
2106 | * name.
|
2107 | *
|
2108 | * @param name The name of the https callable function.
|
2109 | * @param options The options for this HttpsCallable instance.
|
2110 | * @return The `HttpsCallable` instance.
|
2111 | */
|
2112 | httpsCallable(name: string, options?: HttpsCallableOptions): HttpsCallable;
|
2113 | }
|
2114 | /**
|
2115 | * The set of Firebase Functions status codes. The codes are the same at the
|
2116 | * ones exposed by gRPC here:
|
2117 | * https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
|
2118 | *
|
2119 | * Possible values:
|
2120 | * - 'cancelled': The operation was cancelled (typically by the caller).
|
2121 | * - 'unknown': Unknown error or an error from a different error domain.
|
2122 | * - 'invalid-argument': Client specified an invalid argument. Note that this
|
2123 | * differs from 'failed-precondition'. 'invalid-argument' indicates
|
2124 | * arguments that are problematic regardless of the state of the system
|
2125 | * (e.g. an invalid field name).
|
2126 | * - 'deadline-exceeded': Deadline expired before operation could complete.
|
2127 | * For operations that change the state of the system, this error may be
|
2128 | * returned even if the operation has completed successfully. For example,
|
2129 | * a successful response from a server could have been delayed long enough
|
2130 | * for the deadline to expire.
|
2131 | * - 'not-found': Some requested document was not found.
|
2132 | * - 'already-exists': Some document that we attempted to create already
|
2133 | * exists.
|
2134 | * - 'permission-denied': The caller does not have permission to execute the
|
2135 | * specified operation.
|
2136 | * - 'resource-exhausted': Some resource has been exhausted, perhaps a
|
2137 | * per-user quota, or perhaps the entire file system is out of space.
|
2138 | * - 'failed-precondition': Operation was rejected because the system is not
|
2139 | * in a state required for the operation's execution.
|
2140 | * - 'aborted': The operation was aborted, typically due to a concurrency
|
2141 | * issue like transaction aborts, etc.
|
2142 | * - 'out-of-range': Operation was attempted past the valid range.
|
2143 | * - 'unimplemented': Operation is not implemented or not supported/enabled.
|
2144 | * - 'internal': Internal errors. Means some invariants expected by
|
2145 | * underlying system has been broken. If you see one of these errors,
|
2146 | * something is very broken.
|
2147 | * - 'unavailable': The service is currently unavailable. This is most likely
|
2148 | * a transient condition and may be corrected by retrying with a backoff.
|
2149 | * - 'data-loss': Unrecoverable data loss or corruption.
|
2150 | * - 'unauthenticated': The request does not have valid authentication
|
2151 | * credentials for the operation.
|
2152 | */
|
2153 | export type FunctionsErrorCode =
|
2154 | | 'ok'
|
2155 | | 'cancelled'
|
2156 | | 'unknown'
|
2157 | | 'invalid-argument'
|
2158 | | 'deadline-exceeded'
|
2159 | | 'not-found'
|
2160 | | 'already-exists'
|
2161 | | 'permission-denied'
|
2162 | | 'resource-exhausted'
|
2163 | | 'failed-precondition'
|
2164 | | 'aborted'
|
2165 | | 'out-of-range'
|
2166 | | 'unimplemented'
|
2167 | | 'internal'
|
2168 | | 'unavailable'
|
2169 | | 'data-loss'
|
2170 | | 'unauthenticated';
|
2171 | export interface HttpsError extends Error {
|
2172 | /**
|
2173 | * A standard error code that will be returned to the client. This also
|
2174 | * determines the HTTP status code of the response, as defined in code.proto.
|
2175 | */
|
2176 | readonly code: FunctionsErrorCode;
|
2177 | /**
|
2178 | * Extra data to be converted to JSON and included in the error response.
|
2179 | */
|
2180 | readonly details?: any;
|
2181 | }
|
2182 | }
|
2183 |
|
2184 | declare namespace firebase.auth {
|
2185 | /**
|
2186 | * A utility class to parse email action URLs.
|
2187 | */
|
2188 | class ActionCodeURL {
|
2189 | private constructor();
|
2190 | /**
|
2191 | * The API key of the email action link.
|
2192 | */
|
2193 | apiKey: string;
|
2194 | /**
|
2195 | * The action code of the email action link.
|
2196 | */
|
2197 | code: string;
|
2198 | /**
|
2199 | * The continue URL of the email action link. Null if not provided.
|
2200 | */
|
2201 | continueUrl: string | null;
|
2202 | /**
|
2203 | * The language code of the email action link. Null if not provided.
|
2204 | */
|
2205 | languageCode: string | null;
|
2206 | /**
|
2207 | * The action performed by the email action link. It returns from one
|
2208 | * of the types from { firebase.auth.ActionCodeInfo}.
|
2209 | */
|
2210 | operation: firebase.auth.ActionCodeInfo.Operation;
|
2211 | /**
|
2212 | * Parses the email action link string and returns an ActionCodeURL object
|
2213 | * if the link is valid, otherwise returns null.
|
2214 | *
|
2215 | * @param link The email action link string.
|
2216 | * @return The ActionCodeURL object, or null if the link is invalid.
|
2217 | */
|
2218 | static parseLink(link: string): firebase.auth.ActionCodeURL | null;
|
2219 | /**
|
2220 | * The tenant ID of the email action link. Null if the email action
|
2221 | * is from the parent project.
|
2222 | */
|
2223 | tenantId: string | null;
|
2224 | }
|
2225 | /**
|
2226 | * A response from {@link firebase.auth.Auth.checkActionCode}.
|
2227 | */
|
2228 | interface ActionCodeInfo {
|
2229 | /**
|
2230 | * The data associated with the action code.
|
2231 | *
|
2232 | * For the `PASSWORD_RESET`, `VERIFY_EMAIL`, and `RECOVER_EMAIL` actions, this object
|
2233 | * contains an `email` field with the address the email was sent to.
|
2234 | *
|
2235 | * For the RECOVER_EMAIL action, which allows a user to undo an email address
|
2236 | * change, this object also contains a `previousEmail` field with the user account's
|
2237 | * current email address. After the action completes, the user's email address will
|
2238 | * revert to the value in the `email` field from the value in `previousEmail` field.
|
2239 | *
|
2240 | * For the VERIFY_AND_CHANGE_EMAIL action, which allows a user to verify the email
|
2241 | * before updating it, this object contains a `previousEmail` field with the user
|
2242 | * account's email address before updating. After the action completes, the user's
|
2243 | * email address will be updated to the value in the `email` field from the value
|
2244 | * in `previousEmail` field.
|
2245 | *
|
2246 | * For the REVERT_SECOND_FACTOR_ADDITION action, which allows a user to unenroll
|
2247 | * a newly added second factor, this object contains a `multiFactorInfo` field with
|
2248 | * the information about the second factor. For phone second factor, the
|
2249 | * `multiFactorInfo` is a {@link firebase.auth.PhoneMultiFactorInfo} object,
|
2250 | * which contains the phone number.
|
2251 | */
|
2252 | data: {
|
2253 | email?: string | null;
|
2254 | /**
|
2255 | * @deprecated
|
2256 | * This field is deprecated in favor of previousEmail.
|
2257 | */
|
2258 | fromEmail?: string | null;
|
2259 | multiFactorInfo?: firebase.auth.MultiFactorInfo | null;
|
2260 | previousEmail?: string | null;
|
2261 | };
|
2262 | /**
|
2263 | * The type of operation that generated the action code. This could be:
|
2264 | * <ul>
|
2265 | * <li>`EMAIL_SIGNIN`: email sign in code generated via
|
2266 | * {@link firebase.auth.Auth.sendSignInLinkToEmail}.</li>
|
2267 | * <li>`PASSWORD_RESET`: password reset code generated via
|
2268 | * {@link firebase.auth.Auth.sendPasswordResetEmail}.</li>
|
2269 | * <li>`RECOVER_EMAIL`: email change revocation code generated via
|
2270 | * {@link firebase.User.updateEmail}.</li>
|
2271 | * <li>`REVERT_SECOND_FACTOR_ADDITION`: revert second factor addition
|
2272 | * code generated via
|
2273 | * {@link firebase.User.MultiFactorUser.enroll}.</li>
|
2274 | * <li>`VERIFY_AND_CHANGE_EMAIL`: verify and change email code generated
|
2275 | * via {@link firebase.User.verifyBeforeUpdateEmail}.</li>
|
2276 | * <li>`VERIFY_EMAIL`: email verification code generated via
|
2277 | * {@link firebase.User.sendEmailVerification}.</li>
|
2278 | * </ul>
|
2279 | */
|
2280 | operation: string;
|
2281 | }
|
2282 |
|
2283 | /**
|
2284 | * This is the interface that defines the required continue/state URL with
|
2285 | * optional Android and iOS bundle identifiers.
|
2286 | * The action code setting fields are:
|
2287 | * <ul>
|
2288 | * <li><p>url: Sets the link continue/state URL, which has different meanings
|
2289 | * in different contexts:</p>
|
2290 | * <ul>
|
2291 | * <li>When the link is handled in the web action widgets, this is the deep
|
2292 | * link in the continueUrl query parameter.</li>
|
2293 | * <li>When the link is handled in the app directly, this is the continueUrl
|
2294 | * query parameter in the deep link of the Dynamic Link.</li>
|
2295 | * </ul>
|
2296 | * </li>
|
2297 | * <li>iOS: Sets the iOS bundle ID. This will try to open the link in an iOS app
|
2298 | * if it is installed.</li>
|
2299 | * <li>android: Sets the Android package name. This will try to open the link in
|
2300 | * an android app if it is installed. If installApp is passed, it specifies
|
2301 | * whether to install the Android app if the device supports it and the app
|
2302 | * is not already installed. If this field is provided without a
|
2303 | * packageName, an error is thrown explaining that the packageName must be
|
2304 | * provided in conjunction with this field.
|
2305 | * If minimumVersion is specified, and an older version of the app is
|
2306 | * installed, the user is taken to the Play Store to upgrade the app.</li>
|
2307 | * <li>handleCodeInApp: The default is false. When set to true, the action code
|
2308 | * link will be be sent as a Universal Link or Android App Link and will be
|
2309 | * opened by the app if installed. In the false case, the code will be sent
|
2310 | * to the web widget first and then on continue will redirect to the app if
|
2311 | * installed.</li>
|
2312 | * </ul>
|
2313 | */
|
2314 | type ActionCodeSettings = {
|
2315 | android?: {
|
2316 | installApp?: boolean;
|
2317 | minimumVersion?: string;
|
2318 | packageName: string;
|
2319 | };
|
2320 | handleCodeInApp?: boolean;
|
2321 | iOS?: { bundleId: string };
|
2322 | url: string;
|
2323 | dynamicLinkDomain?: string;
|
2324 | };
|
2325 |
|
2326 | /**
|
2327 | * A structure containing additional user information from a federated identity
|
2328 | * provider.
|
2329 | */
|
2330 | type AdditionalUserInfo = {
|
2331 | isNewUser: boolean;
|
2332 | profile: Object | null;
|
2333 | providerId: string;
|
2334 | username?: string | null;
|
2335 | };
|
2336 |
|
2337 | /**
|
2338 | * A verifier for domain verification and abuse prevention. Currently, the
|
2339 | * only implementation is {@link firebase.auth.RecaptchaVerifier}.
|
2340 | */
|
2341 | interface ApplicationVerifier {
|
2342 | /**
|
2343 | * Identifies the type of application verifier (e.g. "recaptcha").
|
2344 | */
|
2345 | type: string;
|
2346 | /**
|
2347 | * Executes the verification process.
|
2348 | * @return A Promise for a token that can be used to
|
2349 | * assert the validity of a request.
|
2350 | */
|
2351 | verify(): Promise<string>;
|
2352 | }
|
2353 |
|
2354 | /**
|
2355 | * Interface representing an Auth instance's settings, currently used for
|
2356 | * enabling/disabling app verification for phone Auth testing.
|
2357 | */
|
2358 | interface AuthSettings {
|
2359 | /**
|
2360 | * When set, this property disables app verification for the purpose of testing
|
2361 | * phone authentication. For this property to take effect, it needs to be set
|
2362 | * before rendering a reCAPTCHA app verifier. When this is disabled, a
|
2363 | * mock reCAPTCHA is rendered instead. This is useful for manual testing during
|
2364 | * development or for automated integration tests.
|
2365 | *
|
2366 | * In order to use this feature, you will need to
|
2367 | * {@link https://firebase.google.com/docs/auth/web/phone-auth#test-with-whitelisted-phone-numbers
|
2368 | * whitelist your phone number} via the
|
2369 | * Firebase Console.
|
2370 | *
|
2371 | * The default value is false (app verification is enabled).
|
2372 | */
|
2373 | appVerificationDisabledForTesting: boolean;
|
2374 | }
|
2375 |
|
2376 | /**
|
2377 | * Interface representing the Auth config.
|
2378 | *
|
2379 | * @public
|
2380 | */
|
2381 | export interface Config {
|
2382 | /**
|
2383 | * The API Key used to communicate with the Firebase Auth backend.
|
2384 | */
|
2385 | apiKey: string;
|
2386 | /**
|
2387 | * The host at which the Firebase Auth backend is running.
|
2388 | */
|
2389 | apiHost: string;
|
2390 | /**
|
2391 | * The scheme used to communicate with the Firebase Auth backend.
|
2392 | */
|
2393 | apiScheme: string;
|
2394 | /**
|
2395 | * The host at which the Secure Token API is running.
|
2396 | */
|
2397 | tokenApiHost: string;
|
2398 | /**
|
2399 | * The SDK Client Version.
|
2400 | */
|
2401 | sdkClientVersion: string;
|
2402 | /**
|
2403 | * The domain at which the web widgets are hosted (provided via Firebase Config).
|
2404 | */
|
2405 | authDomain?: string;
|
2406 | }
|
2407 |
|
2408 | /**
|
2409 | * Configuration of Firebase Authentication Emulator.
|
2410 | */
|
2411 | export interface EmulatorConfig {
|
2412 | /**
|
2413 | * The protocol used to communicate with the emulator ("http"/"https").
|
2414 | */
|
2415 | readonly protocol: string;
|
2416 | /**
|
2417 | * The hostname of the emulator, which may be a domain ("localhost"), IPv4 address ("127.0.0.1")
|
2418 | * or quoted IPv6 address ("[::1]").
|
2419 | */
|
2420 | readonly host: string;
|
2421 | /**
|
2422 | * The port of the emulator, or null if port isn't specified (i.e. protocol default).
|
2423 | */
|
2424 | readonly port: number | null;
|
2425 | /**
|
2426 | * The emulator-specific options.
|
2427 | */
|
2428 | readonly options: {
|
2429 | /**
|
2430 | * Whether the warning banner attached to the DOM was disabled.
|
2431 | */
|
2432 | readonly disableWarnings: boolean;
|
2433 | };
|
2434 | }
|
2435 |
|
2436 | /**
|
2437 | * The Firebase Auth service interface.
|
2438 | *
|
2439 | * Do not call this constructor directly. Instead, use
|
2440 | * {@link firebase.auth `firebase.auth()`}.
|
2441 | *
|
2442 | * See
|
2443 | * {@link https://firebase.google.com/docs/auth/ Firebase Authentication}
|
2444 | * for a full guide on how to use the Firebase Auth service.
|
2445 | *
|
2446 | */
|
2447 | interface Auth {
|
2448 | /** The name of the app associated with the Auth service instance. */
|
2449 | readonly name: string;
|
2450 | /** The config used to initialize this instance. */
|
2451 | readonly config: Config;
|
2452 | /** The current emulator configuration (or null). */
|
2453 | readonly emulatorConfig: EmulatorConfig | null;
|
2454 | /**
|
2455 | * The {@link firebase.app.App app} associated with the `Auth` service
|
2456 | * instance.
|
2457 | *
|
2458 | * @example
|
2459 | * ```javascript
|
2460 | * var app = auth.app;
|
2461 | * ```
|
2462 | */
|
2463 | app: firebase.app.App;
|
2464 | /**
|
2465 | * Applies a verification code sent to the user by email or other out-of-band
|
2466 | * mechanism.
|
2467 | *
|
2468 | * <h4>Error Codes</h4>
|
2469 | * <dl>
|
2470 | * <dt>auth/expired-action-code</dt>
|
2471 | * <dd>Thrown if the action code has expired.</dd>
|
2472 | * <dt>auth/invalid-action-code</dt>
|
2473 | * <dd>Thrown if the action code is invalid. This can happen if the code is
|
2474 | * malformed or has already been used.</dd>
|
2475 | * <dt>auth/user-disabled</dt>
|
2476 | * <dd>Thrown if the user corresponding to the given action code has been
|
2477 | * disabled.</dd>
|
2478 | * <dt>auth/user-not-found</dt>
|
2479 | * <dd>Thrown if there is no user corresponding to the action code. This may
|
2480 | * have happened if the user was deleted between when the action code was
|
2481 | * issued and when this method was called.</dd>
|
2482 | * </dl>
|
2483 | *
|
2484 | * @param code A verification code sent to the user.
|
2485 | */
|
2486 | applyActionCode(code: string): Promise<void>;
|
2487 | /**
|
2488 | * Checks a verification code sent to the user by email or other out-of-band
|
2489 | * mechanism.
|
2490 | *
|
2491 | * Returns metadata about the code.
|
2492 | *
|
2493 | * <h4>Error Codes</h4>
|
2494 | * <dl>
|
2495 | * <dt>auth/expired-action-code</dt>
|
2496 | * <dd>Thrown if the action code has expired.</dd>
|
2497 | * <dt>auth/invalid-action-code</dt>
|
2498 | * <dd>Thrown if the action code is invalid. This can happen if the code is
|
2499 | * malformed or has already been used.</dd>
|
2500 | * <dt>auth/user-disabled</dt>
|
2501 | * <dd>Thrown if the user corresponding to the given action code has been
|
2502 | * disabled.</dd>
|
2503 | * <dt>auth/user-not-found</dt>
|
2504 | * <dd>Thrown if there is no user corresponding to the action code. This may
|
2505 | * have happened if the user was deleted between when the action code was
|
2506 | * issued and when this method was called.</dd>
|
2507 | * </dl>
|
2508 | *
|
2509 | * @param code A verification code sent to the user.
|
2510 | */
|
2511 | checkActionCode(code: string): Promise<firebase.auth.ActionCodeInfo>;
|
2512 | /**
|
2513 | * Completes the password reset process, given a confirmation code and new
|
2514 | * password.
|
2515 | *
|
2516 | * <h4>Error Codes</h4>
|
2517 | * <dl>
|
2518 | * <dt>auth/expired-action-code</dt>
|
2519 | * <dd>Thrown if the password reset code has expired.</dd>
|
2520 | * <dt>auth/invalid-action-code</dt>
|
2521 | * <dd>Thrown if the password reset code is invalid. This can happen if the
|
2522 | * code is malformed or has already been used.</dd>
|
2523 | * <dt>auth/user-disabled</dt>
|
2524 | * <dd>Thrown if the user corresponding to the given password reset code has
|
2525 | * been disabled.</dd>
|
2526 | * <dt>auth/user-not-found</dt>
|
2527 | * <dd>Thrown if there is no user corresponding to the password reset code. This
|
2528 | * may have happened if the user was deleted between when the code was
|
2529 | * issued and when this method was called.</dd>
|
2530 | * <dt>auth/weak-password</dt>
|
2531 | * <dd>Thrown if the new password is not strong enough.</dd>
|
2532 | * </dl>
|
2533 | *
|
2534 | * @param code The confirmation code send via email to the user.
|
2535 | * @param newPassword The new password.
|
2536 | */
|
2537 | confirmPasswordReset(code: string, newPassword: string): Promise<void>;
|
2538 |
|
2539 | /**
|
2540 | * Creates a new user account associated with the specified email address and
|
2541 | * password.
|
2542 | *
|
2543 | * On successful creation of the user account, this user will also be
|
2544 | * signed in to your application.
|
2545 | *
|
2546 | * User account creation can fail if the account already exists or the password
|
2547 | * is invalid.
|
2548 | *
|
2549 | * Note: The email address acts as a unique identifier for the user and
|
2550 | * enables an email-based password reset. This function will create
|
2551 | * a new user account and set the initial user password.
|
2552 | *
|
2553 | * <h4>Error Codes</h4>
|
2554 | * <dl>
|
2555 | * <dt>auth/email-already-in-use</dt>
|
2556 | * <dd>Thrown if there already exists an account with the given email
|
2557 | * address.</dd>
|
2558 | * <dt>auth/invalid-email</dt>
|
2559 | * <dd>Thrown if the email address is not valid.</dd>
|
2560 | * <dt>auth/operation-not-allowed</dt>
|
2561 | * <dd>Thrown if email/password accounts are not enabled. Enable email/password
|
2562 | * accounts in the Firebase Console, under the Auth tab.</dd>
|
2563 | * <dt>auth/weak-password</dt>
|
2564 | * <dd>Thrown if the password is not strong enough.</dd>
|
2565 | * </dl>
|
2566 | *
|
2567 | * @example
|
2568 | * ```javascript
|
2569 | * firebase.auth().createUserWithEmailAndPassword(email, password)
|
2570 | * .catch(function(error) {
|
2571 | * // Handle Errors here.
|
2572 | * var errorCode = error.code;
|
2573 | * var errorMessage = error.message;
|
2574 | * if (errorCode == 'auth/weak-password') {
|
2575 | * alert('The password is too weak.');
|
2576 | * } else {
|
2577 | * alert(errorMessage);
|
2578 | * }
|
2579 | * console.log(error);
|
2580 | * });
|
2581 | * ```
|
2582 | * @param email The user's email address.
|
2583 | * @param password The user's chosen password.
|
2584 | */
|
2585 | createUserWithEmailAndPassword(
|
2586 | email: string,
|
2587 | password: string
|
2588 | ): Promise<firebase.auth.UserCredential>;
|
2589 | /**
|
2590 | * The currently signed-in user (or null).
|
2591 | */
|
2592 | currentUser: firebase.User | null;
|
2593 |
|
2594 | /**
|
2595 | * Gets the list of possible sign in methods for the given email address. This
|
2596 | * is useful to differentiate methods of sign-in for the same provider,
|
2597 | * eg. `EmailAuthProvider` which has 2 methods of sign-in, email/password and
|
2598 | * email/link.
|
2599 | *
|
2600 | * <h4>Error Codes</h4>
|
2601 | * <dl>
|
2602 | * <dt>auth/invalid-email</dt>
|
2603 | * <dd>Thrown if the email address is not valid.</dd>
|
2604 | * </dl>
|
2605 | */
|
2606 | fetchSignInMethodsForEmail(email: string): Promise<Array<string>>;
|
2607 |
|
2608 | /**
|
2609 | * Checks if an incoming link is a sign-in with email link.
|
2610 | */
|
2611 | isSignInWithEmailLink(emailLink: string): boolean;
|
2612 | /**
|
2613 | * Returns a UserCredential from the redirect-based sign-in flow.
|
2614 | *
|
2615 | * If sign-in succeeded, returns the signed in user. If sign-in was
|
2616 | * unsuccessful, fails with an error. If no redirect operation was called,
|
2617 | * returns a UserCredential with a null User.
|
2618 | *
|
2619 | * <h4>Error Codes</h4>
|
2620 | * <dl>
|
2621 | * <dt>auth/account-exists-with-different-credential</dt>
|
2622 | * <dd>Thrown if there already exists an account with the email address
|
2623 | * asserted by the credential. Resolve this by calling
|
2624 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail} with the error.email
|
2625 | * and then asking the user to sign in using one of the returned providers.
|
2626 | * Once the user is signed in, the original credential retrieved from the
|
2627 | * error.credential can be linked to the user with
|
2628 | * {@link firebase.User.linkWithCredential} to prevent the user from signing
|
2629 | * in again to the original provider via popup or redirect. If you are using
|
2630 | * redirects for sign in, save the credential in session storage and then
|
2631 | * retrieve on redirect and repopulate the credential using for example
|
2632 | * {@link firebase.auth.GoogleAuthProvider.credential} depending on the
|
2633 | * credential provider id and complete the link.</dd>
|
2634 | * <dt>auth/auth-domain-config-required</dt>
|
2635 | * <dd>Thrown if authDomain configuration is not provided when calling
|
2636 | * firebase.initializeApp(). Check Firebase Console for instructions on
|
2637 | * determining and passing that field.</dd>
|
2638 | * <dt>auth/credential-already-in-use</dt>
|
2639 | * <dd>Thrown if the account corresponding to the credential already exists
|
2640 | * among your users, or is already linked to a Firebase User.
|
2641 | * For example, this error could be thrown if you are upgrading an anonymous
|
2642 | * user to a Google user by linking a Google credential to it and the Google
|
2643 | * credential used is already associated with an existing Firebase Google
|
2644 | * user.
|
2645 | * An <code>error.email</code> and <code>error.credential</code>
|
2646 | * ({@link firebase.auth.AuthCredential}) fields are also provided. You can
|
2647 | * recover from this error by signing in with that credential directly via
|
2648 | * {@link firebase.auth.Auth.signInWithCredential}.</dd>
|
2649 | * <dt>auth/email-already-in-use</dt>
|
2650 | * <dd>Thrown if the email corresponding to the credential already exists
|
2651 | * among your users. When thrown while linking a credential to an existing
|
2652 | * user, an <code>error.email</code> and <code>error.credential</code>
|
2653 | * ({@link firebase.auth.AuthCredential}) fields are also provided.
|
2654 | * You have to link the credential to the existing user with that email if
|
2655 | * you wish to continue signing in with that credential. To do so, call
|
2656 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}, sign in to
|
2657 | * <code>error.email</code> via one of the providers returned and then
|
2658 | * {@link firebase.User.linkWithCredential} the original credential to that
|
2659 | * newly signed in user.</dd>
|
2660 | * <dt>auth/operation-not-allowed</dt>
|
2661 | * <dd>Thrown if the type of account corresponding to the credential
|
2662 | * is not enabled. Enable the account type in the Firebase Console, under
|
2663 | * the Auth tab.</dd>
|
2664 | * <dt>auth/operation-not-supported-in-this-environment</dt>
|
2665 | * <dd>Thrown if this operation is not supported in the environment your
|
2666 | * application is running on. "location.protocol" must be http or https.
|
2667 | * </dd>
|
2668 | * <dt>auth/timeout</dt>
|
2669 | * <dd>Thrown typically if the app domain is not authorized for OAuth operations
|
2670 | * for your Firebase project. Edit the list of authorized domains from the
|
2671 | * Firebase console.</dd>
|
2672 | * </dl>
|
2673 | *
|
2674 | * @webonly
|
2675 | *
|
2676 | * @example
|
2677 | * ```javascript
|
2678 | * // First, we perform the signInWithRedirect.
|
2679 | * // Creates the provider object.
|
2680 | * var provider = new firebase.auth.FacebookAuthProvider();
|
2681 | * // You can add additional scopes to the provider:
|
2682 | * provider.addScope('email');
|
2683 | * provider.addScope('user_friends');
|
2684 | * // Sign in with redirect:
|
2685 | * auth.signInWithRedirect(provider)
|
2686 | * ////////////////////////////////////////////////////////////
|
2687 | * // The user is redirected to the provider's sign in flow...
|
2688 | * ////////////////////////////////////////////////////////////
|
2689 | * // Then redirected back to the app, where we check the redirect result:
|
2690 | * auth.getRedirectResult().then(function(result) {
|
2691 | * // The firebase.User instance:
|
2692 | * var user = result.user;
|
2693 | * // The Facebook firebase.auth.AuthCredential containing the Facebook
|
2694 | * // access token:
|
2695 | * var credential = result.credential;
|
2696 | * // As this API can be used for sign-in, linking and reauthentication,
|
2697 | * // check the operationType to determine what triggered this redirect
|
2698 | * // operation.
|
2699 | * var operationType = result.operationType;
|
2700 | * }, function(error) {
|
2701 | * // The provider's account email, can be used in case of
|
2702 | * // auth/account-exists-with-different-credential to fetch the providers
|
2703 | * // linked to the email:
|
2704 | * var email = error.email;
|
2705 | * // The provider's credential:
|
2706 | * var credential = error.credential;
|
2707 | * // In case of auth/account-exists-with-different-credential error,
|
2708 | * // you can fetch the providers using this:
|
2709 | * if (error.code === 'auth/account-exists-with-different-credential') {
|
2710 | * auth.fetchSignInMethodsForEmail(email).then(function(providers) {
|
2711 | * // The returned 'providers' is a list of the available providers
|
2712 | * // linked to the email address. Please refer to the guide for a more
|
2713 | * // complete explanation on how to recover from this error.
|
2714 | * });
|
2715 | * }
|
2716 | * });
|
2717 | * ```
|
2718 | */
|
2719 | getRedirectResult(): Promise<firebase.auth.UserCredential>;
|
2720 | /**
|
2721 | * The current Auth instance's language code. This is a readable/writable
|
2722 | * property. When set to null, the default Firebase Console language setting
|
2723 | * is applied. The language code will propagate to email action templates
|
2724 | * (password reset, email verification and email change revocation), SMS
|
2725 | * templates for phone authentication, reCAPTCHA verifier and OAuth
|
2726 | * popup/redirect operations provided the specified providers support
|
2727 | * localization with the language code specified.
|
2728 | */
|
2729 | languageCode: string | null;
|
2730 | /**
|
2731 | * The current Auth instance's settings. This is used to edit/read configuration
|
2732 | * related options like app verification mode for phone authentication.
|
2733 | */
|
2734 | settings: firebase.auth.AuthSettings;
|
2735 | /**
|
2736 | * Adds an observer for changes to the user's sign-in state.
|
2737 | *
|
2738 | * Prior to 4.0.0, this triggered the observer when users were signed in,
|
2739 | * signed out, or when the user's ID token changed in situations such as token
|
2740 | * expiry or password change. After 4.0.0, the observer is only triggered
|
2741 | * on sign-in or sign-out.
|
2742 | *
|
2743 | * To keep the old behavior, see {@link firebase.auth.Auth.onIdTokenChanged}.
|
2744 | *
|
2745 | * @example
|
2746 | * ```javascript
|
2747 | * firebase.auth().onAuthStateChanged(function(user) {
|
2748 | * if (user) {
|
2749 | * // User is signed in.
|
2750 | * }
|
2751 | * });
|
2752 | * ```
|
2753 | */
|
2754 | onAuthStateChanged(
|
2755 | nextOrObserver:
|
2756 | | firebase.Observer<any>
|
2757 | | ((a: firebase.User | null) => any),
|
2758 | error?: (a: firebase.auth.Error) => any,
|
2759 | completed?: firebase.Unsubscribe
|
2760 | ): firebase.Unsubscribe;
|
2761 | /**
|
2762 | * Adds an observer for changes to the signed-in user's ID token, which includes
|
2763 | * sign-in, sign-out, and token refresh events. This method has the same
|
2764 | * behavior as {@link firebase.auth.Auth.onAuthStateChanged} had prior to 4.0.0.
|
2765 | *
|
2766 | * @example
|
2767 | * ```javascript
|
2768 | * firebase.auth().onIdTokenChanged(function(user) {
|
2769 | * if (user) {
|
2770 | * // User is signed in or token was refreshed.
|
2771 | * }
|
2772 | * });
|
2773 | * ```
|
2774 | * @param
|
2775 | * nextOrObserver An observer object or a function triggered on change.
|
2776 | * @param error Optional A function
|
2777 | * triggered on auth error.
|
2778 | * @param completed Optional A function triggered when the
|
2779 | * observer is removed.
|
2780 | */
|
2781 | onIdTokenChanged(
|
2782 | nextOrObserver:
|
2783 | | firebase.Observer<any>
|
2784 | | ((a: firebase.User | null) => any),
|
2785 | error?: (a: firebase.auth.Error) => any,
|
2786 | completed?: firebase.Unsubscribe
|
2787 | ): firebase.Unsubscribe;
|
2788 | /**
|
2789 | * Sends a sign-in email link to the user with the specified email.
|
2790 | *
|
2791 | * The sign-in operation has to always be completed in the app unlike other out
|
2792 | * of band email actions (password reset and email verifications). This is
|
2793 | * because, at the end of the flow, the user is expected to be signed in and
|
2794 | * their Auth state persisted within the app.
|
2795 | *
|
2796 | * To complete sign in with the email link, call
|
2797 | * {@link firebase.auth.Auth.signInWithEmailLink} with the email address and
|
2798 | * the email link supplied in the email sent to the user.
|
2799 | *
|
2800 | * <h4>Error Codes</h4>
|
2801 | * <dl>
|
2802 | * <dt>auth/argument-error</dt>
|
2803 | * <dd>Thrown if handleCodeInApp is false.</dd>
|
2804 | * <dt>auth/invalid-email</dt>
|
2805 | * <dd>Thrown if the email address is not valid.</dd>
|
2806 | * <dt>auth/missing-android-pkg-name</dt>
|
2807 | * <dd>An Android package name must be provided if the Android app is required
|
2808 | * to be installed.</dd>
|
2809 | * <dt>auth/missing-continue-uri</dt>
|
2810 | * <dd>A continue URL must be provided in the request.</dd>
|
2811 | * <dt>auth/missing-ios-bundle-id</dt>
|
2812 | * <dd>An iOS Bundle ID must be provided if an App Store ID is provided.</dd>
|
2813 | * <dt>auth/invalid-continue-uri</dt>
|
2814 | * <dd>The continue URL provided in the request is invalid.</dd>
|
2815 | * <dt>auth/unauthorized-continue-uri</dt>
|
2816 | * <dd>The domain of the continue URL is not whitelisted. Whitelist
|
2817 | * the domain in the Firebase console.</dd>
|
2818 | * </dl>
|
2819 | *
|
2820 | * @example
|
2821 | * ```javascript
|
2822 | * var actionCodeSettings = {
|
2823 | * // The URL to redirect to for sign-in completion. This is also the deep
|
2824 | * // link for mobile redirects. The domain (www.example.com) for this URL
|
2825 | * // must be whitelisted in the Firebase Console.
|
2826 | * url: 'https://www.example.com/finishSignUp?cartId=1234',
|
2827 | * iOS: {
|
2828 | * bundleId: 'com.example.ios'
|
2829 | * },
|
2830 | * android: {
|
2831 | * packageName: 'com.example.android',
|
2832 | * installApp: true,
|
2833 | * minimumVersion: '12'
|
2834 | * },
|
2835 | * // This must be true.
|
2836 | * handleCodeInApp: true
|
2837 | * };
|
2838 | * firebase.auth().sendSignInLinkToEmail('user@example.com', actionCodeSettings)
|
2839 | * .then(function() {
|
2840 | * // The link was successfully sent. Inform the user. Save the email
|
2841 | * // locally so you don't need to ask the user for it again if they open
|
2842 | * // the link on the same device.
|
2843 | * })
|
2844 | * .catch(function(error) {
|
2845 | * // Some error occurred, you can inspect the code: error.code
|
2846 | * });
|
2847 | * ```
|
2848 | * @param email The email account to sign in with.
|
2849 | * @param actionCodeSettings The action
|
2850 | * code settings. The action code settings which provides Firebase with
|
2851 | * instructions on how to construct the email link. This includes the
|
2852 | * sign in completion URL or the deep link for mobile redirects, the mobile
|
2853 | * apps to use when the sign-in link is opened on an Android or iOS device.
|
2854 | * Mobile app redirects will only be applicable if the developer configures
|
2855 | * and accepts the Firebase Dynamic Links terms of condition.
|
2856 | * The Android package name and iOS bundle ID will be respected only if they
|
2857 | * are configured in the same Firebase Auth project used.
|
2858 | */
|
2859 | sendSignInLinkToEmail(
|
2860 | email: string,
|
2861 | actionCodeSettings: firebase.auth.ActionCodeSettings
|
2862 | ): Promise<void>;
|
2863 |
|
2864 | /**
|
2865 | * Sends a password reset email to the given email address.
|
2866 | *
|
2867 | * To complete the password reset, call
|
2868 | * {@link firebase.auth.Auth.confirmPasswordReset} with the code supplied in the
|
2869 | * email sent to the user, along with the new password specified by the user.
|
2870 | *
|
2871 | * <h4>Error Codes</h4>
|
2872 | * <dl>
|
2873 | * <dt>auth/invalid-email</dt>
|
2874 | * <dd>Thrown if the email address is not valid.</dd>
|
2875 | * <dt>auth/missing-android-pkg-name</dt>
|
2876 | * <dd>An Android package name must be provided if the Android app is required
|
2877 | * to be installed.</dd>
|
2878 | * <dt>auth/missing-continue-uri</dt>
|
2879 | * <dd>A continue URL must be provided in the request.</dd>
|
2880 | * <dt>auth/missing-ios-bundle-id</dt>
|
2881 | * <dd>An iOS Bundle ID must be provided if an App Store ID is provided.</dd>
|
2882 | * <dt>auth/invalid-continue-uri</dt>
|
2883 | * <dd>The continue URL provided in the request is invalid.</dd>
|
2884 | * <dt>auth/unauthorized-continue-uri</dt>
|
2885 | * <dd>The domain of the continue URL is not whitelisted. Whitelist
|
2886 | * the domain in the Firebase console.</dd>
|
2887 | * <dt>auth/user-not-found</dt>
|
2888 | * <dd>Thrown if there is no user corresponding to the email address.</dd>
|
2889 | * </dl>
|
2890 | *
|
2891 | * @example
|
2892 | * ```javascript
|
2893 | * var actionCodeSettings = {
|
2894 | * url: 'https://www.example.com/?email=user@example.com',
|
2895 | * iOS: {
|
2896 | * bundleId: 'com.example.ios'
|
2897 | * },
|
2898 | * android: {
|
2899 | * packageName: 'com.example.android',
|
2900 | * installApp: true,
|
2901 | * minimumVersion: '12'
|
2902 | * },
|
2903 | * handleCodeInApp: true
|
2904 | * };
|
2905 | * firebase.auth().sendPasswordResetEmail(
|
2906 | * 'user@example.com', actionCodeSettings)
|
2907 | * .then(function() {
|
2908 | * // Password reset email sent.
|
2909 | * })
|
2910 | * .catch(function(error) {
|
2911 | * // Error occurred. Inspect error.code.
|
2912 | * });
|
2913 | * ```
|
2914 | *
|
2915 | * @param email The email address with the password to be reset.
|
2916 | * @param actionCodeSettings The action
|
2917 | * code settings. If specified, the state/continue URL will be set as the
|
2918 | * "continueUrl" parameter in the password reset link. The default password
|
2919 | * reset landing page will use this to display a link to go back to the app
|
2920 | * if it is installed.
|
2921 | * If the actionCodeSettings is not specified, no URL is appended to the
|
2922 | * action URL.
|
2923 | * The state URL provided must belong to a domain that is whitelisted by the
|
2924 | * developer in the console. Otherwise an error will be thrown.
|
2925 | * Mobile app redirects will only be applicable if the developer configures
|
2926 | * and accepts the Firebase Dynamic Links terms of condition.
|
2927 | * The Android package name and iOS bundle ID will be respected only if they
|
2928 | * are configured in the same Firebase Auth project used.
|
2929 | */
|
2930 | sendPasswordResetEmail(
|
2931 | email: string,
|
2932 | actionCodeSettings?: firebase.auth.ActionCodeSettings | null
|
2933 | ): Promise<void>;
|
2934 |
|
2935 | /**
|
2936 | * Changes the current type of persistence on the current Auth instance for the
|
2937 | * currently saved Auth session and applies this type of persistence for
|
2938 | * future sign-in requests, including sign-in with redirect requests. This will
|
2939 | * return a promise that will resolve once the state finishes copying from one
|
2940 | * type of storage to the other.
|
2941 | * Calling a sign-in method after changing persistence will wait for that
|
2942 | * persistence change to complete before applying it on the new Auth state.
|
2943 | *
|
2944 | * This makes it easy for a user signing in to specify whether their session
|
2945 | * should be remembered or not. It also makes it easier to never persist the
|
2946 | * Auth state for applications that are shared by other users or have sensitive
|
2947 | * data.
|
2948 | *
|
2949 | * The default for web browser apps and React Native apps is 'local' (provided
|
2950 | * the browser supports this mechanism) whereas it is 'none' for Node.js backend
|
2951 | * apps.
|
2952 | *
|
2953 | * <h4>Error Codes (thrown synchronously)</h4>
|
2954 | * <dl>
|
2955 | * <dt>auth/invalid-persistence-type</dt>
|
2956 | * <dd>Thrown if the specified persistence type is invalid.</dd>
|
2957 | * <dt>auth/unsupported-persistence-type</dt>
|
2958 | * <dd>Thrown if the current environment does not support the specified
|
2959 | * persistence type.</dd>
|
2960 | * </dl>
|
2961 | *
|
2962 | * @example
|
2963 | * ```javascript
|
2964 | * firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION)
|
2965 | * .then(function() {
|
2966 | * // Existing and future Auth states are now persisted in the current
|
2967 | * // session only. Closing the window would clear any existing state even if
|
2968 | * // a user forgets to sign out.
|
2969 | * });
|
2970 | * ```
|
2971 | */
|
2972 | setPersistence(persistence: firebase.auth.Auth.Persistence): Promise<void>;
|
2973 |
|
2974 | /**
|
2975 | * Asynchronously signs in with the given credentials, and returns any available
|
2976 | * additional user information, such as user name.
|
2977 | *
|
2978 | * <h4>Error Codes</h4>
|
2979 | * <dl>
|
2980 | * <dt>auth/account-exists-with-different-credential</dt>
|
2981 | * <dd>Thrown if there already exists an account with the email address
|
2982 | * asserted by the credential. Resolve this by calling
|
2983 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail} and then asking the
|
2984 | * user to sign in using one of the returned providers. Once the user is
|
2985 | * signed in, the original credential can be linked to the user with
|
2986 | * {@link firebase.User.linkWithCredential}.</dd>
|
2987 | * <dt>auth/invalid-credential</dt>
|
2988 | * <dd>Thrown if the credential is malformed or has expired.</dd>
|
2989 | * <dt>auth/operation-not-allowed</dt>
|
2990 | * <dd>Thrown if the type of account corresponding to the credential
|
2991 | * is not enabled. Enable the account type in the Firebase Console, under
|
2992 | * the Auth tab.</dd>
|
2993 | * <dt>auth/user-disabled</dt>
|
2994 | * <dd>Thrown if the user corresponding to the given credential has been
|
2995 | * disabled.</dd>
|
2996 | * <dt>auth/user-not-found</dt>
|
2997 | * <dd>Thrown if signing in with a credential from
|
2998 | * {@link firebase.auth.EmailAuthProvider.credential} and there is no user
|
2999 | * corresponding to the given email. </dd>
|
3000 | * <dt>auth/wrong-password</dt>
|
3001 | * <dd>Thrown if signing in with a credential from
|
3002 | * {@link firebase.auth.EmailAuthProvider.credential} and the password is
|
3003 | * invalid for the given email, or if the account corresponding to the email
|
3004 | * does not have a password set.</dd>
|
3005 | * <dt>auth/invalid-verification-code</dt>
|
3006 | * <dd>Thrown if the credential is a
|
3007 | * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
|
3008 | * code of the credential is not valid.</dd>
|
3009 | * <dt>auth/invalid-verification-id</dt>
|
3010 | * <dd>Thrown if the credential is a
|
3011 | * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
|
3012 | * ID of the credential is not valid.</dd>
|
3013 | * </dl>
|
3014 | *
|
3015 | * @deprecated
|
3016 | * This method is deprecated. Use
|
3017 | * {@link firebase.auth.Auth.signInWithCredential} instead.
|
3018 | *
|
3019 | * @example
|
3020 | * ```javascript
|
3021 | * firebase.auth().signInAndRetrieveDataWithCredential(credential)
|
3022 | * .then(function(userCredential) {
|
3023 | * console.log(userCredential.additionalUserInfo.username);
|
3024 | * });
|
3025 | * ```
|
3026 | * @param credential The auth credential.
|
3027 | */
|
3028 | signInAndRetrieveDataWithCredential(
|
3029 | credential: firebase.auth.AuthCredential
|
3030 | ): Promise<firebase.auth.UserCredential>;
|
3031 | /**
|
3032 | * Asynchronously signs in as an anonymous user.
|
3033 | *
|
3034 | *
|
3035 | * If there is already an anonymous user signed in, that user will be returned;
|
3036 | * otherwise, a new anonymous user identity will be created and returned.
|
3037 | *
|
3038 | * <h4>Error Codes</h4>
|
3039 | * <dl>
|
3040 | * <dt>auth/operation-not-allowed</dt>
|
3041 | * <dd>Thrown if anonymous accounts are not enabled. Enable anonymous accounts
|
3042 | * in the Firebase Console, under the Auth tab.</dd>
|
3043 | * </dl>
|
3044 | *
|
3045 | * @example
|
3046 | * ```javascript
|
3047 | * firebase.auth().signInAnonymously().catch(function(error) {
|
3048 | * // Handle Errors here.
|
3049 | * var errorCode = error.code;
|
3050 | * var errorMessage = error.message;
|
3051 | *
|
3052 | * if (errorCode === 'auth/operation-not-allowed') {
|
3053 | * alert('You must enable Anonymous auth in the Firebase Console.');
|
3054 | * } else {
|
3055 | * console.error(error);
|
3056 | * }
|
3057 | * });
|
3058 | * ```
|
3059 | */
|
3060 | signInAnonymously(): Promise<firebase.auth.UserCredential>;
|
3061 |
|
3062 | /**
|
3063 | * Asynchronously signs in with the given credentials.
|
3064 | *
|
3065 | * <h4>Error Codes</h4>
|
3066 | * <dl>
|
3067 | * <dt>auth/account-exists-with-different-credential</dt>
|
3068 | * <dd>Thrown if there already exists an account with the email address
|
3069 | * asserted by the credential. Resolve this by calling
|
3070 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail} and then asking the
|
3071 | * user to sign in using one of the returned providers. Once the user is
|
3072 | * signed in, the original credential can be linked to the user with
|
3073 | * {@link firebase.User.linkWithCredential}.</dd>
|
3074 | * <dt>auth/invalid-credential</dt>
|
3075 | * <dd>Thrown if the credential is malformed or has expired.</dd>
|
3076 | * <dt>auth/operation-not-allowed</dt>
|
3077 | * <dd>Thrown if the type of account corresponding to the credential
|
3078 | * is not enabled. Enable the account type in the Firebase Console, under
|
3079 | * the Auth tab.</dd>
|
3080 | * <dt>auth/user-disabled</dt>
|
3081 | * <dd>Thrown if the user corresponding to the given credential has been
|
3082 | * disabled.</dd>
|
3083 | * <dt>auth/user-not-found</dt>
|
3084 | * <dd>Thrown if signing in with a credential from
|
3085 | * {@link firebase.auth.EmailAuthProvider.credential} and there is no user
|
3086 | * corresponding to the given email. </dd>
|
3087 | * <dt>auth/wrong-password</dt>
|
3088 | * <dd>Thrown if signing in with a credential from
|
3089 | * {@link firebase.auth.EmailAuthProvider.credential} and the password is
|
3090 | * invalid for the given email, or if the account corresponding to the email
|
3091 | * does not have a password set.</dd>
|
3092 | * <dt>auth/invalid-verification-code</dt>
|
3093 | * <dd>Thrown if the credential is a
|
3094 | * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
|
3095 | * code of the credential is not valid.</dd>
|
3096 | * <dt>auth/invalid-verification-id</dt>
|
3097 | * <dd>Thrown if the credential is a
|
3098 | * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
|
3099 | * ID of the credential is not valid.</dd>
|
3100 | * </dl>
|
3101 | *
|
3102 | * @example
|
3103 | * ```javascript
|
3104 | * firebase.auth().signInWithCredential(credential).catch(function(error) {
|
3105 | * // Handle Errors here.
|
3106 | * var errorCode = error.code;
|
3107 | * var errorMessage = error.message;
|
3108 | * // The email of the user's account used.
|
3109 | * var email = error.email;
|
3110 | * // The firebase.auth.AuthCredential type that was used.
|
3111 | * var credential = error.credential;
|
3112 | * if (errorCode === 'auth/account-exists-with-different-credential') {
|
3113 | * alert('Email already associated with another account.');
|
3114 | * // Handle account linking here, if using.
|
3115 | * } else {
|
3116 | * console.error(error);
|
3117 | * }
|
3118 | * });
|
3119 | * ```
|
3120 | *
|
3121 | * @param credential The auth credential.
|
3122 | */
|
3123 | signInWithCredential(
|
3124 | credential: firebase.auth.AuthCredential
|
3125 | ): Promise<firebase.auth.UserCredential>;
|
3126 | /**
|
3127 | * Asynchronously signs in using a custom token.
|
3128 | *
|
3129 | * Custom tokens are used to integrate Firebase Auth with existing auth systems,
|
3130 | * and must be generated by the auth backend.
|
3131 | *
|
3132 | * Fails with an error if the token is invalid, expired, or not accepted by the
|
3133 | * Firebase Auth service.
|
3134 | *
|
3135 | * <h4>Error Codes</h4>
|
3136 | * <dl>
|
3137 | * <dt>auth/custom-token-mismatch</dt>
|
3138 | * <dd>Thrown if the custom token is for a different Firebase App.</dd>
|
3139 | * <dt>auth/invalid-custom-token</dt>
|
3140 | * <dd>Thrown if the custom token format is incorrect.</dd>
|
3141 | * </dl>
|
3142 | *
|
3143 | * @example
|
3144 | * ```javascript
|
3145 | * firebase.auth().signInWithCustomToken(token).catch(function(error) {
|
3146 | * // Handle Errors here.
|
3147 | * var errorCode = error.code;
|
3148 | * var errorMessage = error.message;
|
3149 | * if (errorCode === 'auth/invalid-custom-token') {
|
3150 | * alert('The token you provided is not valid.');
|
3151 | * } else {
|
3152 | * console.error(error);
|
3153 | * }
|
3154 | * });
|
3155 | * ```
|
3156 | *
|
3157 | * @param token The custom token to sign in with.
|
3158 | */
|
3159 | signInWithCustomToken(token: string): Promise<firebase.auth.UserCredential>;
|
3160 | /**
|
3161 | * Asynchronously signs in using an email and password.
|
3162 | *
|
3163 | * Fails with an error if the email address and password do not match.
|
3164 | *
|
3165 | * Note: The user's password is NOT the password used to access the user's email
|
3166 | * account. The email address serves as a unique identifier for the user, and
|
3167 | * the password is used to access the user's account in your Firebase project.
|
3168 | *
|
3169 | * See also: {@link firebase.auth.Auth.createUserWithEmailAndPassword}.
|
3170 | *
|
3171 | * <h4>Error Codes</h4>
|
3172 | * <dl>
|
3173 | * <dt>auth/invalid-email</dt>
|
3174 | * <dd>Thrown if the email address is not valid.</dd>
|
3175 | * <dt>auth/user-disabled</dt>
|
3176 | * <dd>Thrown if the user corresponding to the given email has been
|
3177 | * disabled.</dd>
|
3178 | * <dt>auth/user-not-found</dt>
|
3179 | * <dd>Thrown if there is no user corresponding to the given email.</dd>
|
3180 | * <dt>auth/wrong-password</dt>
|
3181 | * <dd>Thrown if the password is invalid for the given email, or the account
|
3182 | * corresponding to the email does not have a password set.</dd>
|
3183 | * </dl>
|
3184 | *
|
3185 | * @example
|
3186 | * ```javascript
|
3187 | * firebase.auth().signInWithEmailAndPassword(email, password)
|
3188 | * .catch(function(error) {
|
3189 | * // Handle Errors here.
|
3190 | * var errorCode = error.code;
|
3191 | * var errorMessage = error.message;
|
3192 | * if (errorCode === 'auth/wrong-password') {
|
3193 | * alert('Wrong password.');
|
3194 | * } else {
|
3195 | * alert(errorMessage);
|
3196 | * }
|
3197 | * console.log(error);
|
3198 | * });
|
3199 | * ```
|
3200 | *
|
3201 | * @param email The users email address.
|
3202 | * @param password The users password.
|
3203 | */
|
3204 | signInWithEmailAndPassword(
|
3205 | email: string,
|
3206 | password: string
|
3207 | ): Promise<firebase.auth.UserCredential>;
|
3208 |
|
3209 | /**
|
3210 | * Asynchronously signs in using a phone number. This method sends a code via
|
3211 | * SMS to the given phone number, and returns a
|
3212 | * {@link firebase.auth.ConfirmationResult}. After the user provides the code
|
3213 | * sent to their phone, call {@link firebase.auth.ConfirmationResult.confirm}
|
3214 | * with the code to sign the user in.
|
3215 | *
|
3216 | * For abuse prevention, this method also requires a
|
3217 | * {@link firebase.auth.ApplicationVerifier}. The Firebase Auth SDK includes
|
3218 | * a reCAPTCHA-based implementation, {@link firebase.auth.RecaptchaVerifier}.
|
3219 | *
|
3220 | * <h4>Error Codes</h4>
|
3221 | * <dl>
|
3222 | * <dt>auth/captcha-check-failed</dt>
|
3223 | * <dd>Thrown if the reCAPTCHA response token was invalid, expired, or if
|
3224 | * this method was called from a non-whitelisted domain.</dd>
|
3225 | * <dt>auth/invalid-phone-number</dt>
|
3226 | * <dd>Thrown if the phone number has an invalid format.</dd>
|
3227 | * <dt>auth/missing-phone-number</dt>
|
3228 | * <dd>Thrown if the phone number is missing.</dd>
|
3229 | * <dt>auth/quota-exceeded</dt>
|
3230 | * <dd>Thrown if the SMS quota for the Firebase project has been exceeded.</dd>
|
3231 | * <dt>auth/user-disabled</dt>
|
3232 | * <dd>Thrown if the user corresponding to the given phone number has been
|
3233 | * disabled.</dd>
|
3234 | * <dt>auth/operation-not-allowed</dt>
|
3235 | * <dd>Thrown if you have not enabled the provider in the Firebase Console. Go
|
3236 | * to the Firebase Console for your project, in the Auth section and the
|
3237 | * <strong>Sign in Method</strong> tab and configure the provider.</dd>
|
3238 | * </dl>
|
3239 | *
|
3240 | * @example
|
3241 | * ```javascript
|
3242 | * // 'recaptcha-container' is the ID of an element in the DOM.
|
3243 | * var applicationVerifier = new firebase.auth.RecaptchaVerifier(
|
3244 | * 'recaptcha-container');
|
3245 | * firebase.auth().signInWithPhoneNumber(phoneNumber, applicationVerifier)
|
3246 | * .then(function(confirmationResult) {
|
3247 | * var verificationCode = window.prompt('Please enter the verification ' +
|
3248 | * 'code that was sent to your mobile device.');
|
3249 | * return confirmationResult.confirm(verificationCode);
|
3250 | * })
|
3251 | * .catch(function(error) {
|
3252 | * // Handle Errors here.
|
3253 | * });
|
3254 | * ```
|
3255 | *
|
3256 | * @param phoneNumber The user's phone number in E.164 format (e.g.
|
3257 | * +16505550101).
|
3258 | * @param applicationVerifier
|
3259 | */
|
3260 | signInWithPhoneNumber(
|
3261 | phoneNumber: string,
|
3262 | applicationVerifier: firebase.auth.ApplicationVerifier
|
3263 | ): Promise<firebase.auth.ConfirmationResult>;
|
3264 | /**
|
3265 | * Asynchronously signs in using an email and sign-in email link. If no link
|
3266 | * is passed, the link is inferred from the current URL.
|
3267 | *
|
3268 | * Fails with an error if the email address is invalid or OTP in email link
|
3269 | * expires.
|
3270 | *
|
3271 | * Note: Confirm the link is a sign-in email link before calling this method
|
3272 | * {@link firebase.auth.Auth.isSignInWithEmailLink}.
|
3273 | *
|
3274 | * <h4>Error Codes</h4>
|
3275 | * <dl>
|
3276 | * <dt>auth/expired-action-code</dt>
|
3277 | * <dd>Thrown if OTP in email link expires.</dd>
|
3278 | * <dt>auth/invalid-email</dt>
|
3279 | * <dd>Thrown if the email address is not valid.</dd>
|
3280 | * <dt>auth/user-disabled</dt>
|
3281 | * <dd>Thrown if the user corresponding to the given email has been
|
3282 | * disabled.</dd>
|
3283 | * </dl>
|
3284 | *
|
3285 | * @example
|
3286 | * ```javascript
|
3287 | * firebase.auth().signInWithEmailLink(email, emailLink)
|
3288 | * .catch(function(error) {
|
3289 | * // Some error occurred, you can inspect the code: error.code
|
3290 | * // Common errors could be invalid email and invalid or expired OTPs.
|
3291 | * });
|
3292 | * ```
|
3293 | *
|
3294 | * @param email The email account to sign in with.
|
3295 | * @param emailLink The optional link which contains the OTP needed
|
3296 | * to complete the sign in with email link. If not specified, the current
|
3297 | * URL is used instead.
|
3298 | */
|
3299 | signInWithEmailLink(
|
3300 | email: string,
|
3301 | emailLink?: string
|
3302 | ): Promise<firebase.auth.UserCredential>;
|
3303 | /**
|
3304 | * Authenticates a Firebase client using a popup-based OAuth authentication
|
3305 | * flow.
|
3306 | *
|
3307 | * If succeeds, returns the signed in user along with the provider's credential.
|
3308 | * If sign in was unsuccessful, returns an error object containing additional
|
3309 | * information about the error.
|
3310 | *
|
3311 | * <h4>Error Codes</h4>
|
3312 | * <dl>
|
3313 | * <dt>auth/account-exists-with-different-credential</dt>
|
3314 | * <dd>Thrown if there already exists an account with the email address
|
3315 | * asserted by the credential. Resolve this by calling
|
3316 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail} with the error.email
|
3317 | * and then asking the user to sign in using one of the returned providers.
|
3318 | * Once the user is signed in, the original credential retrieved from the
|
3319 | * error.credential can be linked to the user with
|
3320 | * {@link firebase.User.linkWithCredential} to prevent the user from signing
|
3321 | * in again to the original provider via popup or redirect. If you are using
|
3322 | * redirects for sign in, save the credential in session storage and then
|
3323 | * retrieve on redirect and repopulate the credential using for example
|
3324 | * {@link firebase.auth.GoogleAuthProvider.credential} depending on the
|
3325 | * credential provider id and complete the link.</dd>
|
3326 | * <dt>auth/auth-domain-config-required</dt>
|
3327 | * <dd>Thrown if authDomain configuration is not provided when calling
|
3328 | * firebase.initializeApp(). Check Firebase Console for instructions on
|
3329 | * determining and passing that field.</dd>
|
3330 | * <dt>auth/cancelled-popup-request</dt>
|
3331 | * <dd>Thrown if successive popup operations are triggered. Only one popup
|
3332 | * request is allowed at one time. All the popups would fail with this error
|
3333 | * except for the last one.</dd>
|
3334 | * <dt>auth/operation-not-allowed</dt>
|
3335 | * <dd>Thrown if the type of account corresponding to the credential
|
3336 | * is not enabled. Enable the account type in the Firebase Console, under
|
3337 | * the Auth tab.</dd>
|
3338 | * <dt>auth/operation-not-supported-in-this-environment</dt>
|
3339 | * <dd>Thrown if this operation is not supported in the environment your
|
3340 | * application is running on. "location.protocol" must be http or https.
|
3341 | * </dd>
|
3342 | * <dt>auth/popup-blocked</dt>
|
3343 | * <dd>Thrown if the popup was blocked by the browser, typically when this
|
3344 | * operation is triggered outside of a click handler.</dd>
|
3345 | * <dt>auth/popup-closed-by-user</dt>
|
3346 | * <dd>Thrown if the popup window is closed by the user without completing the
|
3347 | * sign in to the provider.</dd>
|
3348 | * <dt>auth/unauthorized-domain</dt>
|
3349 | * <dd>Thrown if the app domain is not authorized for OAuth operations for your
|
3350 | * Firebase project. Edit the list of authorized domains from the Firebase
|
3351 | * console.</dd>
|
3352 | * </dl>
|
3353 | *
|
3354 | * @webonly
|
3355 | *
|
3356 | * @example
|
3357 | * ```javascript
|
3358 | * // Creates the provider object.
|
3359 | * var provider = new firebase.auth.FacebookAuthProvider();
|
3360 | * // You can add additional scopes to the provider:
|
3361 | * provider.addScope('email');
|
3362 | * provider.addScope('user_friends');
|
3363 | * // Sign in with popup:
|
3364 | * auth.signInWithPopup(provider).then(function(result) {
|
3365 | * // The firebase.User instance:
|
3366 | * var user = result.user;
|
3367 | * // The Facebook firebase.auth.AuthCredential containing the Facebook
|
3368 | * // access token:
|
3369 | * var credential = result.credential;
|
3370 | * }, function(error) {
|
3371 | * // The provider's account email, can be used in case of
|
3372 | * // auth/account-exists-with-different-credential to fetch the providers
|
3373 | * // linked to the email:
|
3374 | * var email = error.email;
|
3375 | * // The provider's credential:
|
3376 | * var credential = error.credential;
|
3377 | * // In case of auth/account-exists-with-different-credential error,
|
3378 | * // you can fetch the providers using this:
|
3379 | * if (error.code === 'auth/account-exists-with-different-credential') {
|
3380 | * auth.fetchSignInMethodsForEmail(email).then(function(providers) {
|
3381 | * // The returned 'providers' is a list of the available providers
|
3382 | * // linked to the email address. Please refer to the guide for a more
|
3383 | * // complete explanation on how to recover from this error.
|
3384 | * });
|
3385 | * }
|
3386 | * });
|
3387 | * ```
|
3388 | *
|
3389 | * @param provider The provider to authenticate.
|
3390 | * The provider has to be an OAuth provider. Non-OAuth providers like {@link
|
3391 | * firebase.auth.EmailAuthProvider} will throw an error.
|
3392 | */
|
3393 | signInWithPopup(
|
3394 | provider: firebase.auth.AuthProvider
|
3395 | ): Promise<firebase.auth.UserCredential>;
|
3396 | /**
|
3397 | * Authenticates a Firebase client using a full-page redirect flow. To handle
|
3398 | * the results and errors for this operation, refer to {@link
|
3399 | * firebase.auth.Auth.getRedirectResult}.
|
3400 | *
|
3401 | * <h4>Error Codes</h4>
|
3402 | * <dl>
|
3403 | * <dt>auth/auth-domain-config-required</dt>
|
3404 | * <dd>Thrown if authDomain configuration is not provided when calling
|
3405 | * firebase.initializeApp(). Check Firebase Console for instructions on
|
3406 | * determining and passing that field.</dd>
|
3407 | * <dt>auth/operation-not-supported-in-this-environment</dt>
|
3408 | * <dd>Thrown if this operation is not supported in the environment your
|
3409 | * application is running on. "location.protocol" must be http or https.
|
3410 | * </dd>
|
3411 | * <dt>auth/unauthorized-domain</dt>
|
3412 | * <dd>Thrown if the app domain is not authorized for OAuth operations for your
|
3413 | * Firebase project. Edit the list of authorized domains from the Firebase
|
3414 | * console.</dd>
|
3415 | * </dl>
|
3416 | *
|
3417 | * @webonly
|
3418 | *
|
3419 | * @param provider The provider to authenticate.
|
3420 | * The provider has to be an OAuth provider. Non-OAuth providers like {@link
|
3421 | * firebase.auth.EmailAuthProvider} will throw an error.
|
3422 | */
|
3423 | signInWithRedirect(provider: firebase.auth.AuthProvider): Promise<void>;
|
3424 | /**
|
3425 | * Signs out the current user.
|
3426 | */
|
3427 | signOut(): Promise<void>;
|
3428 | /**
|
3429 | * The current Auth instance's tenant ID. This is a readable/writable
|
3430 | * property. When you set the tenant ID of an Auth instance, all future
|
3431 | * sign-in/sign-up operations will pass this tenant ID and sign in or
|
3432 | * sign up users to the specified tenant project.
|
3433 | * When set to null, users are signed in to the parent project. By default,
|
3434 | * this is set to null.
|
3435 | *
|
3436 | * @example
|
3437 | * ```javascript
|
3438 | * // Set the tenant ID on Auth instance.
|
3439 | * firebase.auth().tenantId = ‘TENANT_PROJECT_ID’;
|
3440 | *
|
3441 | * // All future sign-in request now include tenant ID.
|
3442 | * firebase.auth().signInWithEmailAndPassword(email, password)
|
3443 | * .then(function(result) {
|
3444 | * // result.user.tenantId should be ‘TENANT_PROJECT_ID’.
|
3445 | * }).catch(function(error) {
|
3446 | * // Handle error.
|
3447 | * });
|
3448 | * ```
|
3449 | */
|
3450 | tenantId: string | null;
|
3451 | /**
|
3452 | * Asynchronously sets the provided user as `currentUser` on the current Auth
|
3453 | * instance. A new instance copy of the user provided will be made and set as
|
3454 | * `currentUser`.
|
3455 | *
|
3456 | * This will trigger {@link firebase.auth.Auth.onAuthStateChanged} and
|
3457 | * {@link firebase.auth.Auth.onIdTokenChanged} listeners like other sign in
|
3458 | * methods.
|
3459 | *
|
3460 | * The operation fails with an error if the user to be updated belongs to a
|
3461 | * different Firebase project.
|
3462 | *
|
3463 | * <h4>Error Codes</h4>
|
3464 | * <dl>
|
3465 | * <dt>auth/invalid-user-token</dt>
|
3466 | * <dd>Thrown if the user to be updated belongs to a diffent Firebase
|
3467 | * project.</dd>
|
3468 | * <dt>auth/user-token-expired</dt>
|
3469 | * <dd>Thrown if the token of the user to be updated is expired.</dd>
|
3470 | * <dt>auth/null-user</dt>
|
3471 | * <dd>Thrown if the user to be updated is null.</dd>
|
3472 | * <dt>auth/tenant-id-mismatch</dt>
|
3473 | * <dd>Thrown if the provided user's tenant ID does not match the
|
3474 | * underlying Auth instance's configured tenant ID</dd>
|
3475 | * </dl>
|
3476 | */
|
3477 | updateCurrentUser(user: firebase.User | null): Promise<void>;
|
3478 | /**
|
3479 | * Sets the current language to the default device/browser preference.
|
3480 | */
|
3481 | useDeviceLanguage(): void;
|
3482 | /**
|
3483 | * Modify this Auth instance to communicate with the Firebase Auth emulator. This must be
|
3484 | * called synchronously immediately following the first call to `firebase.auth()`. Do not use
|
3485 | * with production credentials as emulator traffic is not encrypted.
|
3486 | *
|
3487 | * @param url The URL at which the emulator is running (eg, 'http://localhost:9099')
|
3488 | */
|
3489 | useEmulator(url: string): void;
|
3490 | /**
|
3491 | * Checks a password reset code sent to the user by email or other out-of-band
|
3492 | * mechanism.
|
3493 | *
|
3494 | * Returns the user's email address if valid.
|
3495 | *
|
3496 | * <h4>Error Codes</h4>
|
3497 | * <dl>
|
3498 | * <dt>auth/expired-action-code</dt>
|
3499 | * <dd>Thrown if the password reset code has expired.</dd>
|
3500 | * <dt>auth/invalid-action-code</dt>
|
3501 | * <dd>Thrown if the password reset code is invalid. This can happen if the code
|
3502 | * is malformed or has already been used.</dd>
|
3503 | * <dt>auth/user-disabled</dt>
|
3504 | * <dd>Thrown if the user corresponding to the given password reset code has
|
3505 | * been disabled.</dd>
|
3506 | * <dt>auth/user-not-found</dt>
|
3507 | * <dd>Thrown if there is no user corresponding to the password reset code. This
|
3508 | * may have happened if the user was deleted between when the code was
|
3509 | * issued and when this method was called.</dd>
|
3510 | * </dl>
|
3511 | *
|
3512 | * @param code A verification code sent to the user.
|
3513 | */
|
3514 | verifyPasswordResetCode(code: string): Promise<string>;
|
3515 | }
|
3516 |
|
3517 | /**
|
3518 | * Interface that represents the credentials returned by an auth provider.
|
3519 | * Implementations specify the details about each auth provider's credential
|
3520 | * requirements.
|
3521 | *
|
3522 | */
|
3523 | abstract class AuthCredential {
|
3524 | /**
|
3525 | * The authentication provider ID for the credential.
|
3526 | * For example, 'facebook.com', or 'google.com'.
|
3527 | */
|
3528 | providerId: string;
|
3529 | /**
|
3530 | * The authentication sign in method for the credential.
|
3531 | * For example, 'password', or 'emailLink. This corresponds to the sign-in
|
3532 | * method identifier as returned in
|
3533 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
|
3534 | */
|
3535 | signInMethod: string;
|
3536 | /**
|
3537 | * Returns a JSON-serializable representation of this object.
|
3538 | */
|
3539 | toJSON(): Object;
|
3540 | /**
|
3541 | * Static method to deserialize a JSON representation of an object into an
|
3542 | * {@link firebase.auth.AuthCredential}. Input can be either Object or the
|
3543 | * stringified representation of the object. When string is provided,
|
3544 | * JSON.parse would be called first. If the JSON input does not represent
|
3545 | * an`AuthCredential`, null is returned.
|
3546 | * @param json The plain object representation of an
|
3547 | * AuthCredential.
|
3548 | */
|
3549 | static fromJSON(json: Object | string): AuthCredential | null;
|
3550 | }
|
3551 |
|
3552 | /**
|
3553 | * Interface that represents the OAuth credentials returned by an OAuth
|
3554 | * provider. Implementations specify the details about each auth provider's
|
3555 | * credential requirements.
|
3556 | *
|
3557 | */
|
3558 | class OAuthCredential extends AuthCredential {
|
3559 | private constructor();
|
3560 | /**
|
3561 | * The OAuth ID token associated with the credential if it belongs to an
|
3562 | * OIDC provider, such as `google.com`.
|
3563 | */
|
3564 | idToken?: string;
|
3565 | /**
|
3566 | * The OAuth access token associated with the credential if it belongs to
|
3567 | * an OAuth provider, such as `facebook.com`, `twitter.com`, etc.
|
3568 | */
|
3569 | accessToken?: string;
|
3570 | /**
|
3571 | * The OAuth access token secret associated with the credential if it
|
3572 | * belongs to an OAuth 1.0 provider, such as `twitter.com`.
|
3573 | */
|
3574 | secret?: string;
|
3575 | }
|
3576 |
|
3577 | /**
|
3578 | * Interface that represents an auth provider.
|
3579 | */
|
3580 | interface AuthProvider {
|
3581 | providerId: string;
|
3582 | }
|
3583 |
|
3584 | /**
|
3585 | * A result from a phone number sign-in, link, or reauthenticate call.
|
3586 | */
|
3587 | interface ConfirmationResult {
|
3588 | /**
|
3589 | * Finishes a phone number sign-in, link, or reauthentication, given the code
|
3590 | * that was sent to the user's mobile device.
|
3591 | *
|
3592 | * <h4>Error Codes</h4>
|
3593 | * <dl>
|
3594 | * <dt>auth/invalid-verification-code</dt>
|
3595 | * <dd>Thrown if the verification code is not valid.</dd>
|
3596 | * <dt>auth/missing-verification-code</dt>
|
3597 | * <dd>Thrown if the verification code is missing.</dd>
|
3598 | * </dl>
|
3599 | */
|
3600 | confirm(verificationCode: string): Promise<firebase.auth.UserCredential>;
|
3601 | /**
|
3602 | * The phone number authentication operation's verification ID. This can be used
|
3603 | * along with the verification code to initialize a phone auth credential.
|
3604 | */
|
3605 | verificationId: string;
|
3606 | }
|
3607 |
|
3608 | /**
|
3609 | * Email and password auth provider implementation.
|
3610 | *
|
3611 | * To authenticate: {@link firebase.auth.Auth.createUserWithEmailAndPassword}
|
3612 | * and {@link firebase.auth.Auth.signInWithEmailAndPassword}.
|
3613 | */
|
3614 | class EmailAuthProvider extends EmailAuthProvider_Instance {
|
3615 | static PROVIDER_ID: string;
|
3616 | /**
|
3617 | * This corresponds to the sign-in method identifier as returned in
|
3618 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
|
3619 | */
|
3620 | static EMAIL_PASSWORD_SIGN_IN_METHOD: string;
|
3621 | /**
|
3622 | * This corresponds to the sign-in method identifier as returned in
|
3623 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
|
3624 | */
|
3625 | static EMAIL_LINK_SIGN_IN_METHOD: string;
|
3626 | /**
|
3627 | * @example
|
3628 | * ```javascript
|
3629 | * var cred = firebase.auth.EmailAuthProvider.credential(
|
3630 | * email,
|
3631 | * password
|
3632 | * );
|
3633 | * ```
|
3634 | *
|
3635 | * @param email Email address.
|
3636 | * @param password User account password.
|
3637 | * @return The auth provider credential.
|
3638 | */
|
3639 | static credential(
|
3640 | email: string,
|
3641 | password: string
|
3642 | ): firebase.auth.AuthCredential;
|
3643 | /**
|
3644 | * Initialize an `EmailAuthProvider` credential using an email and an email link
|
3645 | * after a sign in with email link operation.
|
3646 | *
|
3647 | * @example
|
3648 | * ```javascript
|
3649 | * var cred = firebase.auth.EmailAuthProvider.credentialWithLink(
|
3650 | * email,
|
3651 | * emailLink
|
3652 | * );
|
3653 | * ```
|
3654 | *
|
3655 | * @param email Email address.
|
3656 | * @param emailLink Sign-in email link.
|
3657 | * @return The auth provider credential.
|
3658 | */
|
3659 | static credentialWithLink(
|
3660 | email: string,
|
3661 | emailLink: string
|
3662 | ): firebase.auth.AuthCredential;
|
3663 | }
|
3664 | /**
|
3665 | * @hidden
|
3666 | */
|
3667 | class EmailAuthProvider_Instance implements firebase.auth.AuthProvider {
|
3668 | providerId: string;
|
3669 | }
|
3670 |
|
3671 | /**
|
3672 | * An authentication error.
|
3673 | * For method-specific error codes, refer to the specific methods in the
|
3674 | * documentation. For common error codes, check the reference below. Use{@link
|
3675 | * firebase.auth.Error.code} to get the specific error code. For a detailed
|
3676 | * message, use {@link firebase.auth.Error.message}.
|
3677 | * Errors with the code <strong>auth/account-exists-with-different-credential
|
3678 | * </strong> will have the additional fields <strong>email</strong> and <strong>
|
3679 | * credential</strong> which are needed to provide a way to resolve these
|
3680 | * specific errors. Refer to {@link firebase.auth.Auth.signInWithPopup} for more
|
3681 | * information.
|
3682 | *
|
3683 | * <h4>Common Error Codes</h4>
|
3684 | * <dl>
|
3685 | * <dt>auth/app-deleted</dt>
|
3686 | * <dd>Thrown if the instance of FirebaseApp has been deleted.</dd>
|
3687 | * <dt>auth/app-not-authorized</dt>
|
3688 | * <dd>Thrown if the app identified by the domain where it's hosted, is not
|
3689 | * authorized to use Firebase Authentication with the provided API key.
|
3690 | * Review your key configuration in the Google API console.</dd>
|
3691 | * <dt>auth/argument-error</dt>
|
3692 | * <dd>Thrown if a method is called with incorrect arguments.</dd>
|
3693 | * <dt>auth/invalid-api-key</dt>
|
3694 | * <dd>Thrown if the provided API key is invalid. Please check that you have
|
3695 | * copied it correctly from the Firebase Console.</dd>
|
3696 | * <dt>auth/invalid-user-token</dt>
|
3697 | * <dd>Thrown if the user's credential is no longer valid. The user must sign in
|
3698 | * again.</dd>
|
3699 | * <dt>auth/invalid-tenant-id</dt>
|
3700 | * <dd>Thrown if the tenant ID provided is invalid.</dd>
|
3701 | * <dt>auth/network-request-failed</dt>
|
3702 | * <dd>Thrown if a network error (such as timeout, interrupted connection or
|
3703 | * unreachable host) has occurred.</dd>
|
3704 | * <dt>auth/operation-not-allowed</dt>
|
3705 | * <dd>Thrown if you have not enabled the provider in the Firebase Console. Go
|
3706 | * to the Firebase Console for your project, in the Auth section and the
|
3707 | * <strong>Sign in Method</strong> tab and configure the provider.</dd>
|
3708 | * <dt>auth/requires-recent-login</dt>
|
3709 | * <dd>Thrown if the user's last sign-in time does not meet the security
|
3710 | * threshold. Use {@link firebase.User.reauthenticateWithCredential} to
|
3711 | * resolve. This does not apply if the user is anonymous.</dd>
|
3712 | * <dt>auth/too-many-requests</dt>
|
3713 | * <dd>Thrown if requests are blocked from a device due to unusual activity.
|
3714 | * Trying again after some delay would unblock.</dd>
|
3715 | * <dt>auth/unauthorized-domain</dt>
|
3716 | * <dd>Thrown if the app domain is not authorized for OAuth operations for your
|
3717 | * Firebase project. Edit the list of authorized domains from the Firebase
|
3718 | * console.</dd>
|
3719 | * <dt>auth/user-disabled</dt>
|
3720 | * <dd>Thrown if the user account has been disabled by an administrator.
|
3721 | * Accounts can be enabled or disabled in the Firebase Console, the Auth
|
3722 | * section and Users subsection.</dd>
|
3723 | * <dt>auth/user-token-expired</dt>
|
3724 | * <dd>Thrown if the user's credential has expired. This could also be thrown if
|
3725 | * a user has been deleted. Prompting the user to sign in again should
|
3726 | * resolve this for either case.</dd>
|
3727 | * <dt>auth/web-storage-unsupported</dt>
|
3728 | * <dd>Thrown if the browser does not support web storage or if the user
|
3729 | * disables them.</dd>
|
3730 | * </dl>
|
3731 | */
|
3732 | interface Error {
|
3733 | name: string;
|
3734 | /**
|
3735 | * Unique error code.
|
3736 | */
|
3737 | code: string;
|
3738 | /**
|
3739 | * Complete error message.
|
3740 | */
|
3741 | message: string;
|
3742 | }
|
3743 |
|
3744 | /**
|
3745 | * The account conflict error.
|
3746 | * Refer to {@link firebase.auth.Auth.signInWithPopup} for more information.
|
3747 | *
|
3748 | * <h4>Common Error Codes</h4>
|
3749 | * <dl>
|
3750 | * <dt>auth/account-exists-with-different-credential</dt>
|
3751 | * <dd>Thrown if there already exists an account with the email address
|
3752 | * asserted by the credential. Resolve this by calling
|
3753 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail} with the error.email
|
3754 | * and then asking the user to sign in using one of the returned providers.
|
3755 | * Once the user is signed in, the original credential retrieved from the
|
3756 | * error.credential can be linked to the user with
|
3757 | * {@link firebase.User.linkWithCredential} to prevent the user from signing
|
3758 | * in again to the original provider via popup or redirect. If you are using
|
3759 | * redirects for sign in, save the credential in session storage and then
|
3760 | * retrieve on redirect and repopulate the credential using for example
|
3761 | * {@link firebase.auth.GoogleAuthProvider.credential} depending on the
|
3762 | * credential provider id and complete the link.</dd>
|
3763 | * <dt>auth/credential-already-in-use</dt>
|
3764 | * <dd>Thrown if the account corresponding to the credential already exists
|
3765 | * among your users, or is already linked to a Firebase User.
|
3766 | * For example, this error could be thrown if you are upgrading an anonymous
|
3767 | * user to a Google user by linking a Google credential to it and the Google
|
3768 | * credential used is already associated with an existing Firebase Google
|
3769 | * user.
|
3770 | * The fields <code>error.email</code>, <code>error.phoneNumber</code>, and
|
3771 | * <code>error.credential</code> ({@link firebase.auth.AuthCredential})
|
3772 | * may be provided, depending on the type of credential. You can recover
|
3773 | * from this error by signing in with <code>error.credential</code> directly
|
3774 | * via {@link firebase.auth.Auth.signInWithCredential}.</dd>
|
3775 | * <dt>auth/email-already-in-use</dt>
|
3776 | * <dd>Thrown if the email corresponding to the credential already exists
|
3777 | * among your users. When thrown while linking a credential to an existing
|
3778 | * user, an <code>error.email</code> and <code>error.credential</code>
|
3779 | * ({@link firebase.auth.AuthCredential}) fields are also provided.
|
3780 | * You have to link the credential to the existing user with that email if
|
3781 | * you wish to continue signing in with that credential. To do so, call
|
3782 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}, sign in to
|
3783 | * <code>error.email</code> via one of the providers returned and then
|
3784 | * {@link firebase.User.linkWithCredential} the original credential to that
|
3785 | * newly signed in user.</dd>
|
3786 | * </dl>
|
3787 | */
|
3788 | interface AuthError extends firebase.auth.Error {
|
3789 | /**
|
3790 | * The {@link firebase.auth.AuthCredential} that can be used to resolve the
|
3791 | * error.
|
3792 | */
|
3793 | credential?: firebase.auth.AuthCredential;
|
3794 | /**
|
3795 | * The email of the user's account used for sign-in/linking.
|
3796 | */
|
3797 | email?: string;
|
3798 | /**
|
3799 | * The phone number of the user's account used for sign-in/linking.
|
3800 | */
|
3801 | phoneNumber?: string;
|
3802 | /**
|
3803 | * The tenant ID being used for sign-in/linking. If you use
|
3804 | * {@link firebase.auth.Auth.signInWithRedirect} to sign in, you have to
|
3805 | * set the tenant ID on Auth instanace again as the tenant ID is not
|
3806 | * persisted after redirection.
|
3807 | */
|
3808 | tenantId?: string;
|
3809 | }
|
3810 |
|
3811 | /**
|
3812 | * The error thrown when the user needs to provide a second factor to sign in
|
3813 | * successfully.
|
3814 | * The error code for this error is <code>auth/multi-factor-auth-required</code>.
|
3815 | * This error provides a {@link firebase.auth.MultiFactorResolver} object,
|
3816 | * which you can use to get the second sign-in factor from the user.
|
3817 | *
|
3818 | * @example
|
3819 | * ```javascript
|
3820 | * firebase.auth().signInWithEmailAndPassword()
|
3821 | * .then(function(result) {
|
3822 | * // User signed in. No 2nd factor challenge is needed.
|
3823 | * })
|
3824 | * .catch(function(error) {
|
3825 | * if (error.code == 'auth/multi-factor-auth-required') {
|
3826 | * var resolver = error.resolver;
|
3827 | * var multiFactorHints = resolver.hints;
|
3828 | * } else {
|
3829 | * // Handle other errors.
|
3830 | * }
|
3831 | * });
|
3832 | *
|
3833 | * resolver.resolveSignIn(multiFactorAssertion)
|
3834 | * .then(function(userCredential) {
|
3835 | * // User signed in.
|
3836 | * });
|
3837 | * ```
|
3838 | */
|
3839 | interface MultiFactorError extends firebase.auth.AuthError {
|
3840 | /**
|
3841 | * The multi-factor resolver to complete second factor sign-in.
|
3842 | */
|
3843 | resolver: firebase.auth.MultiFactorResolver;
|
3844 | }
|
3845 |
|
3846 | /**
|
3847 | * Facebook auth provider.
|
3848 | *
|
3849 | * @example
|
3850 | * ```javascript
|
3851 | * // Sign in using a redirect.
|
3852 | * firebase.auth().getRedirectResult().then(function(result) {
|
3853 | * if (result.credential) {
|
3854 | * // This gives you a Google Access Token.
|
3855 | * var token = result.credential.accessToken;
|
3856 | * }
|
3857 | * var user = result.user;
|
3858 | * })
|
3859 | * // Start a sign in process for an unauthenticated user.
|
3860 | * var provider = new firebase.auth.FacebookAuthProvider();
|
3861 | * provider.addScope('user_birthday');
|
3862 | * firebase.auth().signInWithRedirect(provider);
|
3863 | * ```
|
3864 | *
|
3865 | * @example
|
3866 | * ```javascript
|
3867 | * // Sign in using a popup.
|
3868 | * var provider = new firebase.auth.FacebookAuthProvider();
|
3869 | * provider.addScope('user_birthday');
|
3870 | * firebase.auth().signInWithPopup(provider).then(function(result) {
|
3871 | * // This gives you a Facebook Access Token.
|
3872 | * var token = result.credential.accessToken;
|
3873 | * // The signed-in user info.
|
3874 | * var user = result.user;
|
3875 | * });
|
3876 | * ```
|
3877 | *
|
3878 | * @see {@link firebase.auth.Auth.onAuthStateChanged} to receive sign in state
|
3879 | * changes.
|
3880 | */
|
3881 | class FacebookAuthProvider extends FacebookAuthProvider_Instance {
|
3882 | static PROVIDER_ID: string;
|
3883 | /**
|
3884 | * This corresponds to the sign-in method identifier as returned in
|
3885 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
|
3886 | */
|
3887 | static FACEBOOK_SIGN_IN_METHOD: string;
|
3888 | /**
|
3889 | * @example
|
3890 | * ```javascript
|
3891 | * var cred = firebase.auth.FacebookAuthProvider.credential(
|
3892 | * // `event` from the Facebook auth.authResponseChange callback.
|
3893 | * event.authResponse.accessToken
|
3894 | * );
|
3895 | * ```
|
3896 | *
|
3897 | * @param token Facebook access token.
|
3898 | */
|
3899 | static credential(token: string): firebase.auth.OAuthCredential;
|
3900 | }
|
3901 | /**
|
3902 | * @hidden
|
3903 | */
|
3904 | class FacebookAuthProvider_Instance implements firebase.auth.AuthProvider {
|
3905 | /**
|
3906 | * @param scope Facebook OAuth scope.
|
3907 | * @return The provider instance itself.
|
3908 | */
|
3909 | addScope(scope: string): firebase.auth.AuthProvider;
|
3910 | providerId: string;
|
3911 | /**
|
3912 | * Sets the OAuth custom parameters to pass in a Facebook OAuth request for
|
3913 | * popup and redirect sign-in operations.
|
3914 | * Valid parameters include 'auth_type', 'display' and 'locale'.
|
3915 | * For a detailed list, check the
|
3916 | * {@link https://goo.gl/pve4fo Facebook}
|
3917 | * documentation.
|
3918 | * Reserved required OAuth 2.0 parameters such as 'client_id', 'redirect_uri',
|
3919 | * 'scope', 'response_type' and 'state' are not allowed and will be ignored.
|
3920 | * @param customOAuthParameters The custom OAuth parameters to pass
|
3921 | * in the OAuth request.
|
3922 | * @return The provider instance itself.
|
3923 | */
|
3924 | setCustomParameters(
|
3925 | customOAuthParameters: Object
|
3926 | ): firebase.auth.AuthProvider;
|
3927 | }
|
3928 |
|
3929 | /**
|
3930 | * GitHub auth provider.
|
3931 | *
|
3932 | * GitHub requires an OAuth 2.0 redirect, so you can either handle the redirect
|
3933 | * directly, or use the signInWithPopup handler:
|
3934 | *
|
3935 | * @example
|
3936 | * ```javascript
|
3937 | * // Using a redirect.
|
3938 | * firebase.auth().getRedirectResult().then(function(result) {
|
3939 | * if (result.credential) {
|
3940 | * // This gives you a GitHub Access Token.
|
3941 | * var token = result.credential.accessToken;
|
3942 | * }
|
3943 | * var user = result.user;
|
3944 | * }).catch(function(error) {
|
3945 | * // Handle Errors here.
|
3946 | * var errorCode = error.code;
|
3947 | * var errorMessage = error.message;
|
3948 | * // The email of the user's account used.
|
3949 | * var email = error.email;
|
3950 | * // The firebase.auth.AuthCredential type that was used.
|
3951 | * var credential = error.credential;
|
3952 | * if (errorCode === 'auth/account-exists-with-different-credential') {
|
3953 | * alert('You have signed up with a different provider for that email.');
|
3954 | * // Handle linking here if your app allows it.
|
3955 | * } else {
|
3956 | * console.error(error);
|
3957 | * }
|
3958 | * });
|
3959 | *
|
3960 | * // Start a sign in process for an unauthenticated user.
|
3961 | * var provider = new firebase.auth.GithubAuthProvider();
|
3962 | * provider.addScope('repo');
|
3963 | * firebase.auth().signInWithRedirect(provider);
|
3964 | * ```
|
3965 | *
|
3966 | * @example
|
3967 | * ```javascript
|
3968 | * // With popup.
|
3969 | * var provider = new firebase.auth.GithubAuthProvider();
|
3970 | * provider.addScope('repo');
|
3971 | * firebase.auth().signInWithPopup(provider).then(function(result) {
|
3972 | * // This gives you a GitHub Access Token.
|
3973 | * var token = result.credential.accessToken;
|
3974 | * // The signed-in user info.
|
3975 | * var user = result.user;
|
3976 | * }).catch(function(error) {
|
3977 | * // Handle Errors here.
|
3978 | * var errorCode = error.code;
|
3979 | * var errorMessage = error.message;
|
3980 | * // The email of the user's account used.
|
3981 | * var email = error.email;
|
3982 | * // The firebase.auth.AuthCredential type that was used.
|
3983 | * var credential = error.credential;
|
3984 | * if (errorCode === 'auth/account-exists-with-different-credential') {
|
3985 | * alert('You have signed up with a different provider for that email.');
|
3986 | * // Handle linking here if your app allows it.
|
3987 | * } else {
|
3988 | * console.error(error);
|
3989 | * }
|
3990 | * });
|
3991 | * ```
|
3992 | *
|
3993 | * @see {@link firebase.auth.Auth.onAuthStateChanged} to receive sign in state
|
3994 | * changes.
|
3995 | */
|
3996 | class GithubAuthProvider extends GithubAuthProvider_Instance {
|
3997 | static PROVIDER_ID: string;
|
3998 | /**
|
3999 | * This corresponds to the sign-in method identifier as returned in
|
4000 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
|
4001 | */
|
4002 | static GITHUB_SIGN_IN_METHOD: string;
|
4003 | /**
|
4004 | * @example
|
4005 | * ```javascript
|
4006 | * var cred = firebase.auth.FacebookAuthProvider.credential(
|
4007 | * // `event` from the Facebook auth.authResponseChange callback.
|
4008 | * event.authResponse.accessToken
|
4009 | * );
|
4010 | * ```
|
4011 | *
|
4012 | * @param token Github access token.
|
4013 | * @return {!firebase.auth.OAuthCredential} The auth provider credential.
|
4014 | */
|
4015 | static credential(token: string): firebase.auth.OAuthCredential;
|
4016 | }
|
4017 | /**
|
4018 | * @hidden
|
4019 | */
|
4020 | class GithubAuthProvider_Instance implements firebase.auth.AuthProvider {
|
4021 | /**
|
4022 | * @param scope Github OAuth scope.
|
4023 | * @return The provider instance itself.
|
4024 | */
|
4025 | addScope(scope: string): firebase.auth.AuthProvider;
|
4026 | providerId: string;
|
4027 | /**
|
4028 | * Sets the OAuth custom parameters to pass in a GitHub OAuth request for popup
|
4029 | * and redirect sign-in operations.
|
4030 | * Valid parameters include 'allow_signup'.
|
4031 | * For a detailed list, check the
|
4032 | * {@link https://developer.github.com/v3/oauth/ GitHub} documentation.
|
4033 | * Reserved required OAuth 2.0 parameters such as 'client_id', 'redirect_uri',
|
4034 | * 'scope', 'response_type' and 'state' are not allowed and will be ignored.
|
4035 | * @param customOAuthParameters The custom OAuth parameters to pass
|
4036 | * in the OAuth request.
|
4037 | * @return The provider instance itself.
|
4038 | */
|
4039 | setCustomParameters(
|
4040 | customOAuthParameters: Object
|
4041 | ): firebase.auth.AuthProvider;
|
4042 | }
|
4043 |
|
4044 | /**
|
4045 | * Google auth provider.
|
4046 | *
|
4047 | * @example
|
4048 | * ```javascript
|
4049 | * // Using a redirect.
|
4050 | * firebase.auth().getRedirectResult().then(function(result) {
|
4051 | * if (result.credential) {
|
4052 | * // This gives you a Google Access Token.
|
4053 | * var token = result.credential.accessToken;
|
4054 | * }
|
4055 | * var user = result.user;
|
4056 | * });
|
4057 | *
|
4058 | * // Start a sign in process for an unauthenticated user.
|
4059 | * var provider = new firebase.auth.GoogleAuthProvider();
|
4060 | * provider.addScope('profile');
|
4061 | * provider.addScope('email');
|
4062 | * firebase.auth().signInWithRedirect(provider);
|
4063 | * ```
|
4064 | *
|
4065 | * @example
|
4066 | * ```javascript
|
4067 | * // Using a popup.
|
4068 | * var provider = new firebase.auth.GoogleAuthProvider();
|
4069 | * provider.addScope('profile');
|
4070 | * provider.addScope('email');
|
4071 | * firebase.auth().signInWithPopup(provider).then(function(result) {
|
4072 | * // This gives you a Google Access Token.
|
4073 | * var token = result.credential.accessToken;
|
4074 | * // The signed-in user info.
|
4075 | * var user = result.user;
|
4076 | * });
|
4077 | * ```
|
4078 | *
|
4079 | * @see {@link firebase.auth.Auth.onAuthStateChanged} to receive sign in state
|
4080 | * changes.
|
4081 | */
|
4082 | class GoogleAuthProvider extends GoogleAuthProvider_Instance {
|
4083 | static PROVIDER_ID: string;
|
4084 | /**
|
4085 | * This corresponds to the sign-in method identifier as returned in
|
4086 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
|
4087 | */
|
4088 | static GOOGLE_SIGN_IN_METHOD: string;
|
4089 | /**
|
4090 | * Creates a credential for Google. At least one of ID token and access token
|
4091 | * is required.
|
4092 | *
|
4093 | * @example
|
4094 | * ```javascript
|
4095 | * // \`googleUser\` from the onsuccess Google Sign In callback.
|
4096 | * var credential = firebase.auth.GoogleAuthProvider.credential(
|
4097 | googleUser.getAuthResponse().id_token);
|
4098 | * firebase.auth().signInWithCredential(credential)
|
4099 | * ```
|
4100 | * @param idToken Google ID token.
|
4101 | * @param accessToken Google access token.
|
4102 | * @return The auth provider credential.
|
4103 | */
|
4104 | static credential(
|
4105 | idToken?: string | null,
|
4106 | accessToken?: string | null
|
4107 | ): firebase.auth.OAuthCredential;
|
4108 | }
|
4109 | /**
|
4110 | * @hidden
|
4111 | */
|
4112 | class GoogleAuthProvider_Instance implements firebase.auth.AuthProvider {
|
4113 | /**
|
4114 | * @param scope Google OAuth scope.
|
4115 | * @return The provider instance itself.
|
4116 | */
|
4117 | addScope(scope: string): firebase.auth.AuthProvider;
|
4118 | providerId: string;
|
4119 | /**
|
4120 | * Sets the OAuth custom parameters to pass in a Google OAuth request for popup
|
4121 | * and redirect sign-in operations.
|
4122 | * Valid parameters include 'hd', 'hl', 'include_granted_scopes', 'login_hint'
|
4123 | * and 'prompt'.
|
4124 | * For a detailed list, check the
|
4125 | * {@link https://goo.gl/Xo01Jm Google}
|
4126 | * documentation.
|
4127 | * Reserved required OAuth 2.0 parameters such as 'client_id', 'redirect_uri',
|
4128 | * 'scope', 'response_type' and 'state' are not allowed and will be ignored.
|
4129 | * @param customOAuthParameters The custom OAuth parameters to pass
|
4130 | * in the OAuth request.
|
4131 | * @return The provider instance itself.
|
4132 | */
|
4133 | setCustomParameters(
|
4134 | customOAuthParameters: Object
|
4135 | ): firebase.auth.AuthProvider;
|
4136 | }
|
4137 |
|
4138 | /**
|
4139 | * Generic OAuth provider.
|
4140 | *
|
4141 | * @example
|
4142 | * ```javascript
|
4143 | * // Using a redirect.
|
4144 | * firebase.auth().getRedirectResult().then(function(result) {
|
4145 | * if (result.credential) {
|
4146 | * // This gives you the OAuth Access Token for that provider.
|
4147 | * var token = result.credential.accessToken;
|
4148 | * }
|
4149 | * var user = result.user;
|
4150 | * });
|
4151 | *
|
4152 | * // Start a sign in process for an unauthenticated user.
|
4153 | * var provider = new firebase.auth.OAuthProvider('google.com');
|
4154 | * provider.addScope('profile');
|
4155 | * provider.addScope('email');
|
4156 | * firebase.auth().signInWithRedirect(provider);
|
4157 | * ```
|
4158 | * @example
|
4159 | * ```javascript
|
4160 | * // Using a popup.
|
4161 | * var provider = new firebase.auth.OAuthProvider('google.com');
|
4162 | * provider.addScope('profile');
|
4163 | * provider.addScope('email');
|
4164 | * firebase.auth().signInWithPopup(provider).then(function(result) {
|
4165 | * // This gives you the OAuth Access Token for that provider.
|
4166 | * var token = result.credential.accessToken;
|
4167 | * // The signed-in user info.
|
4168 | * var user = result.user;
|
4169 | * });
|
4170 | * ```
|
4171 | *
|
4172 | * @see {@link firebase.auth.Auth.onAuthStateChanged} to receive sign in state
|
4173 | * changes.
|
4174 | * @param providerId The associated provider ID, such as `github.com`.
|
4175 | */
|
4176 | class OAuthProvider implements firebase.auth.AuthProvider {
|
4177 | constructor(providerId: string);
|
4178 | providerId: string;
|
4179 | /**
|
4180 | * @param scope Provider OAuth scope to add.
|
4181 | */
|
4182 | addScope(scope: string): firebase.auth.AuthProvider;
|
4183 | /**
|
4184 | * Creates a Firebase credential from a generic OAuth provider's access token or
|
4185 | * ID token. The raw nonce is required when an ID token with a nonce field is
|
4186 | * provided. The SHA-256 hash of the raw nonce must match the nonce field in
|
4187 | * the ID token.
|
4188 | *
|
4189 | * @example
|
4190 | * ```javascript
|
4191 | * // `googleUser` from the onsuccess Google Sign In callback.
|
4192 | * // Initialize a generate OAuth provider with a `google.com` providerId.
|
4193 | * var provider = new firebase.auth.OAuthProvider('google.com');
|
4194 | * var credential = provider.credential({
|
4195 | * idToken: googleUser.getAuthResponse().id_token,
|
4196 | * });
|
4197 | * firebase.auth().signInWithCredential(credential)
|
4198 | * ```
|
4199 | *
|
4200 | * @param optionsOrIdToken Either the options object containing
|
4201 | * the ID token, access token and raw nonce or the ID token string.
|
4202 | * @param accessToken The OAuth access token.
|
4203 | */
|
4204 | credential(
|
4205 | optionsOrIdToken: firebase.auth.OAuthCredentialOptions | string | null,
|
4206 | accessToken?: string
|
4207 | ): firebase.auth.OAuthCredential;
|
4208 | /**
|
4209 | * Sets the OAuth custom parameters to pass in an OAuth request for popup
|
4210 | * and redirect sign-in operations.
|
4211 | * For a detailed list, check the
|
4212 | * reserved required OAuth 2.0 parameters such as `client_id`, `redirect_uri`,
|
4213 | * `scope`, `response_type` and `state` are not allowed and will be ignored.
|
4214 | * @param customOAuthParameters The custom OAuth parameters to pass
|
4215 | * in the OAuth request.
|
4216 | */
|
4217 | setCustomParameters(
|
4218 | customOAuthParameters: Object
|
4219 | ): firebase.auth.AuthProvider;
|
4220 | }
|
4221 |
|
4222 | class SAMLAuthProvider implements firebase.auth.AuthProvider {
|
4223 | constructor(providerId: string);
|
4224 | providerId: string;
|
4225 | }
|
4226 |
|
4227 | /**
|
4228 | * Interface representing ID token result obtained from
|
4229 | * {string
firebase.User.getIdTokenResult}. It contains the ID token JWT |
4230 | * and other helper properties for getting different data associated with the
|
4231 | * token as well as all the decoded payload claims.
|
4232 | *
|
4233 | * Note that these claims are not to be trusted as they are parsed client side.
|
4234 | * Only server side verification can guarantee the integrity of the token
|
4235 | * claims.
|
4236 | */
|
4237 | interface IdTokenResult {
|
4238 | /**
|
4239 | * The Firebase Auth ID token JWT string.
|
4240 | */
|
4241 | token: string;
|
4242 | /**
|
4243 | * The ID token expiration time formatted as a UTC string.
|
4244 | */
|
4245 | expirationTime: string;
|
4246 | /**
|
4247 | * The authentication time formatted as a UTC string. This is the time the
|
4248 | * user authenticated (signed in) and not the time the token was refreshed.
|
4249 | */
|
4250 | authTime: string;
|
4251 | /**
|
4252 | * The ID token issued at time formatted as a UTC string.
|
4253 | */
|
4254 | issuedAtTime: string;
|
4255 | /**
|
4256 | * The sign-in provider through which the ID token was obtained (anonymous,
|
4257 | * custom, phone, password, etc). Note, this does not map to provider IDs.
|
4258 | */
|
4259 | signInProvider: string | null;
|
4260 | /**
|
4261 | * The type of second factor associated with this session, provided the user
|
4262 | * was multi-factor authenticated (eg. phone, etc).
|
4263 | */
|
4264 | signInSecondFactor: string | null;
|
4265 | /**
|
4266 | * The entire payload claims of the ID token including the standard reserved
|
4267 | * claims as well as the custom claims.
|
4268 | */
|
4269 | claims: {
|
4270 | [key: string]: any;
|
4271 | };
|
4272 | }
|
4273 |
|
4274 | /**
|
4275 | * Defines the options for initializing an
|
4276 | * {@link firebase.auth.OAuthCredential}. For ID tokens with nonce claim,
|
4277 | * the raw nonce has to also be provided.
|
4278 | */
|
4279 | interface OAuthCredentialOptions {
|
4280 | /**
|
4281 | * The OAuth ID token used to initialize the OAuthCredential.
|
4282 | */
|
4283 | idToken?: string;
|
4284 | /**
|
4285 | * The OAuth access token used to initialize the OAuthCredential.
|
4286 | */
|
4287 | accessToken?: string;
|
4288 | /**
|
4289 | * The raw nonce associated with the ID token. It is required when an ID token
|
4290 | * with a nonce field is provided. The SHA-256 hash of the raw nonce must match
|
4291 | * the nonce field in the ID token.
|
4292 | */
|
4293 | rawNonce?: string;
|
4294 | }
|
4295 |
|
4296 | /**
|
4297 | * The base class for asserting ownership of a second factor. This is used to
|
4298 | * facilitate enrollment of a second factor on an existing user
|
4299 | * or sign-in of a user who already verified the first factor.
|
4300 | *
|
4301 | */
|
4302 | abstract class MultiFactorAssertion {
|
4303 | /**
|
4304 | * The identifier of the second factor.
|
4305 | */
|
4306 | factorId: string;
|
4307 | }
|
4308 |
|
4309 | /**
|
4310 | * The class for asserting ownership of a phone second factor.
|
4311 | */
|
4312 | class PhoneMultiFactorAssertion extends firebase.auth.MultiFactorAssertion {
|
4313 | private constructor();
|
4314 | }
|
4315 |
|
4316 | /**
|
4317 | * The class used to initialize { firebase.auth.PhoneMultiFactorAssertion}.
|
4318 | */
|
4319 | class PhoneMultiFactorGenerator {
|
4320 | private constructor();
|
4321 | /**
|
4322 | * The identifier of the phone second factor: `phone`.
|
4323 | */
|
4324 | static FACTOR_ID: string;
|
4325 | /**
|
4326 | * Initializes the { firebase.auth.PhoneMultiFactorAssertion} to confirm ownership
|
4327 | * of the phone second factor.
|
4328 | */
|
4329 | static assertion(
|
4330 | phoneAuthCredential: firebase.auth.PhoneAuthCredential
|
4331 | ): firebase.auth.PhoneMultiFactorAssertion;
|
4332 | }
|
4333 |
|
4334 | /**
|
4335 | * A structure containing the information of a second factor entity.
|
4336 | */
|
4337 | interface MultiFactorInfo {
|
4338 | /**
|
4339 | * The multi-factor enrollment ID.
|
4340 | */
|
4341 | uid: string;
|
4342 | /**
|
4343 | * The user friendly name of the current second factor.
|
4344 | */
|
4345 | displayName?: string | null;
|
4346 | /**
|
4347 | * The enrollment date of the second factor formatted as a UTC string.
|
4348 | */
|
4349 | enrollmentTime: string;
|
4350 | /**
|
4351 | * The identifier of the second factor.
|
4352 | */
|
4353 | factorId: string;
|
4354 | }
|
4355 |
|
4356 | /**
|
4357 | * The subclass of the MultiFactorInfo interface for phone number second factors.
|
4358 | * The factorId of this second factor is
|
4359 | * {@link firebase.auth.PhoneMultiFactorGenerator.FACTOR_ID}.
|
4360 | */
|
4361 | interface PhoneMultiFactorInfo extends firebase.auth.MultiFactorInfo {
|
4362 | /**
|
4363 | * The phone number associated with the current second factor.
|
4364 | */
|
4365 | phoneNumber: string;
|
4366 | }
|
4367 |
|
4368 | /**
|
4369 | * The information required to verify the ownership of a phone number. The
|
4370 | * information that's required depends on whether you are doing single-factor
|
4371 | * sign-in, multi-factor enrollment or multi-factor sign-in.
|
4372 | */
|
4373 | type PhoneInfoOptions =
|
4374 | | firebase.auth.PhoneSingleFactorInfoOptions
|
4375 | | firebase.auth.PhoneMultiFactorEnrollInfoOptions
|
4376 | | firebase.auth.PhoneMultiFactorSignInInfoOptions;
|
4377 | /**
|
4378 | * The phone info options for single-factor sign-in. Only phone number is
|
4379 | * required.
|
4380 | */
|
4381 | interface PhoneSingleFactorInfoOptions {
|
4382 | phoneNumber: string;
|
4383 | }
|
4384 |
|
4385 | /**
|
4386 | * The phone info options for multi-factor enrollment. Phone number and
|
4387 | * multi-factor session are required.
|
4388 | */
|
4389 | interface PhoneMultiFactorEnrollInfoOptions {
|
4390 | phoneNumber: string;
|
4391 | session: firebase.auth.MultiFactorSession;
|
4392 | }
|
4393 |
|
4394 | /**
|
4395 | * The phone info options for multi-factor sign-in. Either multi-factor hint or
|
4396 | * multi-factor UID and multi-factor session are required.
|
4397 | */
|
4398 | interface PhoneMultiFactorSignInInfoOptions {
|
4399 | multiFactorHint?: firebase.auth.MultiFactorInfo;
|
4400 | multiFactorUid?: string;
|
4401 | session: firebase.auth.MultiFactorSession;
|
4402 | }
|
4403 |
|
4404 | /**
|
4405 | * The class used to facilitate recovery from
|
4406 | * {@link firebase.auth.MultiFactorError} when a user needs to provide a second
|
4407 | * factor to sign in.
|
4408 | *
|
4409 | * @example
|
4410 | * ```javascript
|
4411 | * firebase.auth().signInWithEmailAndPassword()
|
4412 | * .then(function(result) {
|
4413 | * // User signed in. No 2nd factor challenge is needed.
|
4414 | * })
|
4415 | * .catch(function(error) {
|
4416 | * if (error.code == 'auth/multi-factor-auth-required') {
|
4417 | * var resolver = error.resolver;
|
4418 | * // Show UI to let user select second factor.
|
4419 | * var multiFactorHints = resolver.hints;
|
4420 | * } else {
|
4421 | * // Handle other errors.
|
4422 | * }
|
4423 | * });
|
4424 | *
|
4425 | * // The enrolled second factors that can be used to complete
|
4426 | * // sign-in are returned in the `MultiFactorResolver.hints` list.
|
4427 | * // UI needs to be presented to allow the user to select a second factor
|
4428 | * // from that list.
|
4429 | *
|
4430 | * var selectedHint = // ; selected from multiFactorHints
|
4431 | * var phoneAuthProvider = new firebase.auth.PhoneAuthProvider();
|
4432 | * var phoneInfoOptions = {
|
4433 | * multiFactorHint: selectedHint,
|
4434 | * session: resolver.session
|
4435 | * };
|
4436 | * phoneAuthProvider.verifyPhoneNumber(
|
4437 | * phoneInfoOptions,
|
4438 | * appVerifier
|
4439 | * ).then(function(verificationId) {
|
4440 | * // store verificationID and show UI to let user enter verification code.
|
4441 | * });
|
4442 | *
|
4443 | * // UI to enter verification code and continue.
|
4444 | * // Continue button click handler
|
4445 | * var phoneAuthCredential =
|
4446 | * firebase.auth.PhoneAuthProvider.credential(verificationId, verificationCode);
|
4447 | * var multiFactorAssertion =
|
4448 | * firebase.auth.PhoneMultiFactorGenerator.assertion(phoneAuthCredential);
|
4449 | * resolver.resolveSignIn(multiFactorAssertion)
|
4450 | * .then(function(userCredential) {
|
4451 | * // User signed in.
|
4452 | * });
|
4453 | * ```
|
4454 | */
|
4455 | class MultiFactorResolver {
|
4456 | private constructor();
|
4457 | /**
|
4458 | * The Auth instance used to sign in with the first factor.
|
4459 | */
|
4460 | auth: firebase.auth.Auth;
|
4461 | /**
|
4462 | * The session identifier for the current sign-in flow, which can be used
|
4463 | * to complete the second factor sign-in.
|
4464 | */
|
4465 | session: firebase.auth.MultiFactorSession;
|
4466 | /**
|
4467 | * The list of hints for the second factors needed to complete the sign-in
|
4468 | * for the current session.
|
4469 | */
|
4470 | hints: firebase.auth.MultiFactorInfo[];
|
4471 | /**
|
4472 | * A helper function to help users complete sign in with a second factor
|
4473 | * using an { firebase.auth.MultiFactorAssertion} confirming the user
|
4474 | * successfully completed the second factor challenge.
|
4475 | *
|
4476 | * <h4>Error Codes</h4>
|
4477 | * <dl>
|
4478 | * <dt>auth/invalid-verification-code</dt>
|
4479 | * <dd>Thrown if the verification code is not valid.</dd>
|
4480 | * <dt>auth/missing-verification-code</dt>
|
4481 | * <dd>Thrown if the verification code is missing.</dd>
|
4482 | * <dt>auth/invalid-verification-id</dt>
|
4483 | * <dd>Thrown if the credential is a
|
4484 | * { firebase.auth.PhoneAuthProvider.credential} and the verification
|
4485 | * ID of the credential is not valid.</dd>
|
4486 | * <dt>auth/missing-verification-id</dt>
|
4487 | * <dd>Thrown if the verification ID is missing.</dd>
|
4488 | * <dt>auth/code-expired</dt>
|
4489 | * <dd>Thrown if the verification code has expired.</dd>
|
4490 | * <dt>auth/invalid-multi-factor-session</dt>
|
4491 | * <dd>Thrown if the request does not contain a valid proof of first factor
|
4492 | * successful sign-in.</dd>
|
4493 | * <dt>auth/missing-multi-factor-session</dt>
|
4494 | * <dd>Thrown if The request is missing proof of first factor successful
|
4495 | * sign-in.</dd>
|
4496 | * </dl>
|
4497 | *
|
4498 | * in with.
assertion The multi-factor assertion to resolve sign- |
4499 | * with the user credential object.
The promise that resolves |
4500 | */
|
4501 | resolveSignIn(
|
4502 | assertion: firebase.auth.MultiFactorAssertion
|
4503 | ): Promise<firebase.auth.UserCredential>;
|
4504 | }
|
4505 |
|
4506 | /**
|
4507 | * The multi-factor session object used for enrolling a second factor on a
|
4508 | * user or helping sign in an enrolled user with a second factor.
|
4509 | */
|
4510 | class MultiFactorSession {
|
4511 | private constructor();
|
4512 | }
|
4513 |
|
4514 | /**
|
4515 | * Classes that represents the Phone Auth credentials returned by a
|
4516 | * { firebase.auth.PhoneAuthProvider}.
|
4517 | *
|
4518 | */
|
4519 | class PhoneAuthCredential extends AuthCredential {
|
4520 | private constructor();
|
4521 | }
|
4522 |
|
4523 | /**
|
4524 | * Phone number auth provider.
|
4525 | *
|
4526 | * @example
|
4527 | * ```javascript
|
4528 | * // 'recaptcha-container' is the ID of an element in the DOM.
|
4529 | * var applicationVerifier = new firebase.auth.RecaptchaVerifier(
|
4530 | * 'recaptcha-container');
|
4531 | * var provider = new firebase.auth.PhoneAuthProvider();
|
4532 | * provider.verifyPhoneNumber('+16505550101', applicationVerifier)
|
4533 | * .then(function(verificationId) {
|
4534 | * var verificationCode = window.prompt('Please enter the verification ' +
|
4535 | * 'code that was sent to your mobile device.');
|
4536 | * return firebase.auth.PhoneAuthProvider.credential(verificationId,
|
4537 | * verificationCode);
|
4538 | * })
|
4539 | * .then(function(phoneCredential) {
|
4540 | * return firebase.auth().signInWithCredential(phoneCredential);
|
4541 | * });
|
4542 | * ```
|
4543 | * @param auth The Firebase Auth instance in which
|
4544 | * sign-ins should occur. Uses the default Auth instance if unspecified.
|
4545 | */
|
4546 | class PhoneAuthProvider extends PhoneAuthProvider_Instance {
|
4547 | static PROVIDER_ID: string;
|
4548 | /**
|
4549 | * This corresponds to the sign-in method identifier as returned in
|
4550 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
|
4551 | */
|
4552 | static PHONE_SIGN_IN_METHOD: string;
|
4553 | /**
|
4554 | * Creates a phone auth credential, given the verification ID from
|
4555 | * {@link firebase.auth.PhoneAuthProvider.verifyPhoneNumber} and the code
|
4556 | * that was sent to the user's mobile device.
|
4557 | *
|
4558 | * <h4>Error Codes</h4>
|
4559 | * <dl>
|
4560 | * <dt>auth/missing-verification-code</dt>
|
4561 | * <dd>Thrown if the verification code is missing.</dd>
|
4562 | * <dt>auth/missing-verification-id</dt>
|
4563 | * <dd>Thrown if the verification ID is missing.</dd>
|
4564 | * </dl>
|
4565 | *
|
4566 | * @param verificationId The verification ID returned from
|
4567 | * {@link firebase.auth.PhoneAuthProvider.verifyPhoneNumber}.
|
4568 | * @param verificationCode The verification code sent to the user's
|
4569 | * mobile device.
|
4570 | * @return The auth provider credential.
|
4571 | */
|
4572 | static credential(
|
4573 | verificationId: string,
|
4574 | verificationCode: string
|
4575 | ): firebase.auth.AuthCredential;
|
4576 | }
|
4577 | /**
|
4578 | * @hidden
|
4579 | */
|
4580 | class PhoneAuthProvider_Instance implements firebase.auth.AuthProvider {
|
4581 | constructor(auth?: firebase.auth.Auth | null);
|
4582 | providerId: string;
|
4583 | /**
|
4584 | * Starts a phone number authentication flow by sending a verification code to
|
4585 | * the given phone number. Returns an ID that can be passed to
|
4586 | * {this flow.
firebase.auth.PhoneAuthProvider.credential} to identify |
4587 | *
|
4588 | * For abuse prevention, this method also requires a
|
4589 | * { firebase.auth.ApplicationVerifier}. The Firebase Auth SDK includes
|
4590 | * a reCAPTCHA-based implementation, { firebase.auth.RecaptchaVerifier}.
|
4591 | *
|
4592 | * <h4>Error Codes</h4>
|
4593 | * <dl>
|
4594 | * <dt>auth/captcha-check-failed</dt>
|
4595 | * <dd>Thrown if the reCAPTCHA response token was invalid, expired, or if
|
4596 | * this method was called from a non-whitelisted domain.</dd>
|
4597 | * <dt>auth/invalid-phone-number</dt>
|
4598 | * <dd>Thrown if the phone number has an invalid format.</dd>
|
4599 | * <dt>auth/missing-phone-number</dt>
|
4600 | * <dd>Thrown if the phone number is missing.</dd>
|
4601 | * <dt>auth/quota-exceeded</dt>
|
4602 | * <dd>Thrown if the SMS quota for the Firebase project has been exceeded.</dd>
|
4603 | * <dt>auth/user-disabled</dt>
|
4604 | * <dd>Thrown if the user corresponding to the given phone number has been
|
4605 | * disabled.</dd>
|
4606 | * <dt>auth/maximum-second-factor-count-exceeded</dt>
|
4607 | * <dd>Thrown if The maximum allowed number of second factors on a user
|
4608 | * has been exceeded.</dd>
|
4609 | * <dt>auth/second-factor-already-in-use</dt>
|
4610 | * <dd>Thrown if the second factor is already enrolled on this account.</dd>
|
4611 | * <dt>auth/unsupported-first-factor</dt>
|
4612 | * <dd>Thrown if the first factor being used to sign in is not supported.</dd>
|
4613 | * <dt>auth/unverified-email</dt>
|
4614 | * <dd>Thrown if the email of the account is not verified.</dd>
|
4615 | * </dl>
|
4616 | *
|
4617 | * @param phoneInfoOptions The user's {@link firebase.auth.PhoneInfoOptions}.
|
4618 | * The phone number should be in E.164 format (e.g. +16505550101).
|
4619 | * applicationVerifier
|
4620 | * Promise for the verification ID.
A |
4621 | */
|
4622 | verifyPhoneNumber(
|
4623 | phoneInfoOptions: firebase.auth.PhoneInfoOptions | string,
|
4624 | applicationVerifier: firebase.auth.ApplicationVerifier
|
4625 | ): Promise<string>;
|
4626 | }
|
4627 |
|
4628 | /**
|
4629 | * An {@link https://www.google.com/recaptcha/ reCAPTCHA}-based application
|
4630 | * verifier.
|
4631 | *
|
4632 | * @webonly
|
4633 | *
|
4634 | * @param container The reCAPTCHA container parameter. This
|
4635 | * has different meaning depending on whether the reCAPTCHA is hidden or
|
4636 | * visible. For a visible reCAPTCHA the container must be empty. If a string
|
4637 | * is used, it has to correspond to an element ID. The corresponding element
|
4638 | * must also must be in the DOM at the time of initialization.
|
4639 | * @param parameters The optional reCAPTCHA parameters. Check the
|
4640 | * reCAPTCHA docs for a comprehensive list. All parameters are accepted
|
4641 | * except for the sitekey. Firebase Auth backend provisions a reCAPTCHA for
|
4642 | * each project and will configure this upon rendering. For an invisible
|
4643 | * reCAPTCHA, a size key must have the value 'invisible'.
|
4644 | * @param app The corresponding Firebase app. If none is
|
4645 | * provided, the default Firebase App instance is used. A Firebase App
|
4646 | * instance must be initialized with an API key, otherwise an error will be
|
4647 | * thrown.
|
4648 | */
|
4649 | class RecaptchaVerifier extends RecaptchaVerifier_Instance {}
|
4650 | /**
|
4651 | * @webonly
|
4652 | * @hidden
|
4653 | */
|
4654 | class RecaptchaVerifier_Instance
|
4655 | implements firebase.auth.ApplicationVerifier
|
4656 | {
|
4657 | constructor(
|
4658 | container: any | string,
|
4659 | parameters?: Object | null,
|
4660 | app?: firebase.app.App | null
|
4661 | );
|
4662 | /**
|
4663 | * Clears the reCAPTCHA widget from the page and destroys the current instance.
|
4664 | */
|
4665 | clear(): void;
|
4666 | /**
|
4667 | * Renders the reCAPTCHA widget on the page.
|
4668 | * @return A Promise that resolves with the
|
4669 | * reCAPTCHA widget ID.
|
4670 | */
|
4671 | render(): Promise<number>;
|
4672 | /**
|
4673 | * The application verifier type. For a reCAPTCHA verifier, this is 'recaptcha'.
|
4674 | */
|
4675 | type: string;
|
4676 | /**
|
4677 | * Waits for the user to solve the reCAPTCHA and resolves with the reCAPTCHA
|
4678 | * token.
|
4679 | * @return A Promise for the reCAPTCHA token.
|
4680 | */
|
4681 | verify(): Promise<string>;
|
4682 | }
|
4683 |
|
4684 | /**
|
4685 | * Twitter auth provider.
|
4686 | *
|
4687 | * @example
|
4688 | * ```javascript
|
4689 | * // Using a redirect.
|
4690 | * firebase.auth().getRedirectResult().then(function(result) {
|
4691 | * if (result.credential) {
|
4692 | * // For accessing the Twitter API.
|
4693 | * var token = result.credential.accessToken;
|
4694 | * var secret = result.credential.secret;
|
4695 | * }
|
4696 | * var user = result.user;
|
4697 | * });
|
4698 | *
|
4699 | * // Start a sign in process for an unauthenticated user.
|
4700 | * var provider = new firebase.auth.TwitterAuthProvider();
|
4701 | * firebase.auth().signInWithRedirect(provider);
|
4702 | * ```
|
4703 | * @example
|
4704 | * ```javascript
|
4705 | * // Using a popup.
|
4706 | * var provider = new firebase.auth.TwitterAuthProvider();
|
4707 | * firebase.auth().signInWithPopup(provider).then(function(result) {
|
4708 | * // For accessing the Twitter API.
|
4709 | * var token = result.credential.accessToken;
|
4710 | * var secret = result.credential.secret;
|
4711 | * // The signed-in user info.
|
4712 | * var user = result.user;
|
4713 | * });
|
4714 | * ```
|
4715 | *
|
4716 | * @see {in state
firebase.auth.Auth.onAuthStateChanged} to receive sign |
4717 | * changes.
|
4718 | */
|
4719 | class TwitterAuthProvider extends TwitterAuthProvider_Instance {
|
4720 | static PROVIDER_ID: string;
|
4721 | /**
|
4722 | * This corresponds to the sign-in method identifier as returned in
|
4723 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
|
4724 | *
|
4725 | */
|
4726 | static TWITTER_SIGN_IN_METHOD: string;
|
4727 | /**
|
4728 | * @param token Twitter access token.
|
4729 | * @param secret Twitter secret.
|
4730 | * @return The auth provider credential.
|
4731 | */
|
4732 | static credential(
|
4733 | token: string,
|
4734 | secret: string
|
4735 | ): firebase.auth.OAuthCredential;
|
4736 | }
|
4737 | /**
|
4738 | * @hidden
|
4739 | */
|
4740 | class TwitterAuthProvider_Instance implements firebase.auth.AuthProvider {
|
4741 | providerId: string;
|
4742 | /**
|
4743 | * Sets the OAuth custom parameters to pass in a Twitter OAuth request for popup
|
4744 | * and redirect sign-in operations.
|
4745 | * Valid parameters include 'lang'.
|
4746 | * Reserved required OAuth 1.0 parameters such as 'oauth_consumer_key',
|
4747 | * 'oauth_token', 'oauth_signature', etc are not allowed and will be ignored.
|
4748 | * @param customOAuthParameters The custom OAuth parameters to pass
|
4749 | * in the OAuth request.
|
4750 | * @return The provider instance itself.
|
4751 | */
|
4752 | setCustomParameters(
|
4753 | customOAuthParameters: Object
|
4754 | ): firebase.auth.AuthProvider;
|
4755 | }
|
4756 |
|
4757 | /**
|
4758 | * A structure containing a User, an AuthCredential, the operationType, and
|
4759 | * any additional user information that was returned from the identity provider.
|
4760 | * operationType could be 'signIn' for a sign-in operation, 'link' for a linking
|
4761 | * operation and 'reauthenticate' for a reauthentication operation.
|
4762 | */
|
4763 | type UserCredential = {
|
4764 | additionalUserInfo?: firebase.auth.AdditionalUserInfo | null;
|
4765 | credential: firebase.auth.AuthCredential | null;
|
4766 | operationType?: string | null;
|
4767 | user: firebase.User | null;
|
4768 | };
|
4769 |
|
4770 | /**
|
4771 | * Interface representing a user's metadata.
|
4772 | */
|
4773 | interface UserMetadata {
|
4774 | creationTime?: string;
|
4775 | lastSignInTime?: string;
|
4776 | }
|
4777 | }
|
4778 |
|
4779 | /**
|
4780 | * @webonly
|
4781 | */
|
4782 | declare namespace firebase.analytics {
|
4783 | /**
|
4784 | * The Firebase Analytics service interface.
|
4785 | *
|
4786 | * Do not call this constructor directly. Instead, use
|
4787 | * {@link firebase.analytics `firebase.analytics()`}.
|
4788 | */
|
4789 | export interface Analytics {
|
4790 | /**
|
4791 | * The {@link firebase.app.App app} associated with the `Analytics` service
|
4792 | * instance.
|
4793 | *
|
4794 | * @example
|
4795 | * ```javascript
|
4796 | * var app = analytics.app;
|
4797 | * ```
|
4798 | */
|
4799 | app: firebase.app.App;
|
4800 |
|
4801 | /**
|
4802 | * Sends analytics event with given `eventParams`. This method
|
4803 | * automatically associates this logged event with this Firebase web
|
4804 | * app instance on this device.
|
4805 | * List of recommended event parameters can be found in
|
4806 | * {@link https://developers.google.com/gtagjs/reference/ga4-events
|
4807 | * | the GA4 reference documentation}.
|
4808 | */
|
4809 | logEvent(
|
4810 | eventName: 'add_payment_info',
|
4811 | eventParams?: {
|
4812 | coupon?: EventParams['coupon'];
|
4813 | currency?: EventParams['currency'];
|
4814 | items?: EventParams['items'];
|
4815 | payment_type?: EventParams['payment_type'];
|
4816 | value?: EventParams['value'];
|
4817 | [key: string]: any;
|
4818 | },
|
4819 | options?: firebase.analytics.AnalyticsCallOptions
|
4820 | ): void;
|
4821 |
|
4822 | /**
|
4823 | * Sends analytics event with given `eventParams`. This method
|
4824 | * automatically associates this logged event with this Firebase web
|
4825 | * app instance on this device.
|
4826 | * List of recommended event parameters can be found in
|
4827 | * {@link https://developers.google.com/gtagjs/reference/ga4-events
|
4828 | * | the GA4 reference documentation}.
|
4829 | */
|
4830 | logEvent(
|
4831 | eventName: 'add_shipping_info',
|
4832 | eventParams?: {
|
4833 | coupon?: EventParams['coupon'];
|
4834 | currency?: EventParams['currency'];
|
4835 | items?: EventParams['items'];
|
4836 | shipping_tier?: EventParams['shipping_tier'];
|
4837 | value?: EventParams['value'];
|
4838 | [key: string]: any;
|
4839 | },
|
4840 | options?: firebase.analytics.AnalyticsCallOptions
|
4841 | ): void;
|
4842 |
|
4843 | /**
|
4844 | * Sends analytics event with given `eventParams`. This method
|
4845 | * automatically associates this logged event with this Firebase web
|
4846 | * app instance on this device.
|
4847 | * List of recommended event parameters can be found in
|
4848 | * {@link https://developers.google.com/gtagjs/reference/ga4-events
|
4849 | * | the GA4 reference documentation}.
|
4850 | */
|
4851 | logEvent(
|
4852 | eventName: 'add_to_cart' | 'add_to_wishlist' | 'remove_from_cart',
|
4853 | eventParams?: {
|
4854 | currency?: EventParams['currency'];
|
4855 | value?: EventParams['value'];
|
4856 | items?: EventParams['items'];
|
4857 | [key: string]: any;
|
4858 | },
|
4859 | options?: firebase.analytics.AnalyticsCallOptions
|
4860 | ): void;
|
4861 |
|
4862 | /**
|
4863 | * Sends analytics event with given `eventParams`. This method
|
4864 | * automatically associates this logged event with this Firebase web
|
4865 | * app instance on this device.
|
4866 | * List of recommended event parameters can be found in
|
4867 | * {@link https://developers.google.com/gtagjs/reference/ga4-events
|
4868 | * | the GA4 reference documentation}.
|
4869 | */
|
4870 | logEvent(
|
4871 | eventName: 'begin_checkout',
|
4872 | eventParams?: {
|
4873 | currency?: EventParams['currency'];
|
4874 | coupon?: EventParams['coupon'];
|
4875 | value?: EventParams['value'];
|
4876 | items?: EventParams['items'];
|
4877 | [key: string]: any;
|
4878 | },
|
4879 | options?: firebase.analytics.AnalyticsCallOptions
|
4880 | ): void;
|
4881 |
|
4882 | /**
|
4883 | * Sends analytics event with given `eventParams`. This method
|
4884 | * automatically associates this logged event with this Firebase web
|
4885 | * app instance on this device.
|
4886 | * List of recommended event parameters can be found in
|
4887 | * {@link https://developers.google.com/gtagjs/reference/ga4-events
|
4888 | * | the GA4 reference documentation}.
|
4889 | */
|
4890 | logEvent(
|
4891 | eventName: 'checkout_progress',
|
4892 | eventParams?: {
|
4893 | currency?: EventParams['currency'];
|
4894 | coupon?: EventParams['coupon'];
|
4895 | value?: EventParams['value'];
|
4896 | items?: EventParams['items'];
|
4897 | checkout_step?: EventParams['checkout_step'];
|
4898 | checkout_option?: EventParams['checkout_option'];
|
4899 | [key: string]: any;
|
4900 | },
|
4901 | options?: firebase.analytics.AnalyticsCallOptions
|
4902 | ): void;
|
4903 |
|
4904 | /**
|
4905 | * Sends analytics event with given `eventParams`. This method
|
4906 | * automatically associates this logged event with this Firebase web
|
4907 | * app instance on this device.
|
4908 | * See
|
4909 | * {@link https://developers.google.com/analytics/devguides/collection/ga4/exceptions
|
4910 | * | Measure exceptions}.
|
4911 | */
|
4912 | logEvent(
|
4913 | eventName: 'exception',
|
4914 | eventParams?: {
|
4915 | description?: EventParams['description'];
|
4916 | fatal?: EventParams['fatal'];
|
4917 | [key: string]: any;
|
4918 | },
|
4919 | options?: firebase.analytics.AnalyticsCallOptions
|
4920 | ): void;
|
4921 |
|
4922 | /**
|
4923 | * Sends analytics event with given `eventParams`. This method
|
4924 | * automatically associates this logged event with this Firebase web
|
4925 | * app instance on this device.
|
4926 | * List of recommended event parameters can be found in
|
4927 | * {@link https://developers.google.com/gtagjs/reference/ga4-events
|
4928 | * | the GA4 reference documentation}.
|
4929 | */
|
4930 | logEvent(
|
4931 | eventName: 'generate_lead',
|
4932 | eventParams?: {
|
4933 | value?: EventParams['value'];
|
4934 | currency?: EventParams['currency'];
|
4935 | [key: string]: any;
|
4936 | },
|
4937 | options?: firebase.analytics.AnalyticsCallOptions
|
4938 | ): void;
|
4939 |
|
4940 | /**
|
4941 | * Sends analytics event with given `eventParams`. This method
|
4942 | * automatically associates this logged event with this Firebase web
|
4943 | * app instance on this device.
|
4944 | * List of recommended event parameters can be found in
|
4945 | * {@link https://developers.google.com/gtagjs/reference/ga4-events
|
4946 | * | the GA4 reference documentation}.
|
4947 | */
|
4948 | logEvent(
|
4949 | eventName: 'login',
|
4950 | eventParams?: {
|
4951 | method?: EventParams['method'];
|
4952 | [key: string]: any;
|
4953 | },
|
4954 | options?: firebase.analytics.AnalyticsCallOptions
|
4955 | ): void;
|
4956 |
|
4957 | /**
|
4958 | * Sends analytics event with given `eventParams`. This method
|
4959 | * automatically associates this logged event with this Firebase web
|
4960 | * app instance on this device.
|
4961 | * See
|
4962 | * {@link https://developers.google.com/analytics/devguides/collection/ga4/page-view
|
4963 | * | Page views}.
|
4964 | */
|
4965 | logEvent(
|
4966 | eventName: 'page_view',
|
4967 | eventParams?: {
|
4968 | page_title?: string;
|
4969 | page_location?: string;
|
4970 | page_path?: string;
|
4971 | [key: string]: any;
|
4972 | },
|
4973 | options?: firebase.analytics.AnalyticsCallOptions
|
4974 | ): void;
|
4975 |
|
4976 | /**
|
4977 | * Sends analytics event with given `eventParams`. This method
|
4978 | * automatically associates this logged event with this Firebase web
|
4979 | * app instance on this device.
|
4980 | * List of recommended event parameters can be found in
|
4981 | * {@link https://developers.google.com/gtagjs/reference/ga4-events
|
4982 | * | the GA4 reference documentation}.
|
4983 | */
|
4984 | logEvent(
|
4985 | eventName: 'purchase' | 'refund',
|
4986 | eventParams?: {
|
4987 | value?: EventParams['value'];
|
4988 | currency?: EventParams['currency'];
|
4989 | transaction_id: EventParams['transaction_id'];
|
4990 | tax?: EventParams['tax'];
|
4991 | shipping?: EventParams['shipping'];
|
4992 | items?: EventParams['items'];
|
4993 | coupon?: EventParams['coupon'];
|
4994 | affiliation?: EventParams['affiliation'];
|
4995 | [key: string]: any;
|
4996 | },
|
4997 | options?: firebase.analytics.AnalyticsCallOptions
|
4998 | ): void;
|
4999 |
|
5000 | /**
|
5001 | * Sends analytics event with given `eventParams`. This method
|
5002 | * automatically associates this logged event with this Firebase web
|
5003 | * app instance on this device.
|
5004 | * See {@link https://firebase.google.com/docs/analytics/screenviews
|
5005 | * | Track Screenviews}.
|
5006 | */
|
5007 | logEvent(
|
5008 | eventName: 'screen_view',
|
5009 | eventParams?: {
|
5010 | firebase_screen: EventParams['firebase_screen'];
|
5011 | firebase_screen_class: EventParams['firebase_screen_class'];
|
5012 | [key: string]: any;
|
5013 | },
|
5014 | options?: firebase.analytics.AnalyticsCallOptions
|
5015 | ): void;
|
5016 |
|
5017 | /**
|
5018 | * Sends analytics event with given `eventParams`. This method
|
5019 | * automatically associates this logged event with this Firebase web
|
5020 | * app instance on this device.
|
5021 | * List of recommended event parameters can be found in
|
5022 | * {@link https://developers.google.com/gtagjs/reference/ga4-events
|
5023 | * | the GA4 reference documentation}.
|
5024 | */
|
5025 | logEvent(
|
5026 | eventName: 'search' | 'view_search_results',
|
5027 | eventParams?: {
|
5028 | search_term?: EventParams['search_term'];
|
5029 | [key: string]: any;
|
5030 | },
|
5031 | options?: firebase.analytics.AnalyticsCallOptions
|
5032 | ): void;
|
5033 |
|
5034 | /**
|
5035 | * Sends analytics event with given `eventParams`. This method
|
5036 | * automatically associates this logged event with this Firebase web
|
5037 | * app instance on this device.
|
5038 | * List of recommended event parameters can be found in
|
5039 | * {@link https://developers.google.com/gtagjs/reference/ga4-events
|
5040 | * | the GA4 reference documentation}.
|
5041 | */
|
5042 | logEvent(
|
5043 | eventName: 'select_content',
|
5044 | eventParams?: {
|
5045 | content_type?: EventParams['content_type'];
|
5046 | item_id?: EventParams['item_id'];
|
5047 | [key: string]: any;
|
5048 | },
|
5049 | options?: firebase.analytics.AnalyticsCallOptions
|
5050 | ): void;
|
5051 |
|
5052 | /**
|
5053 | * Sends analytics event with given `eventParams`. This method
|
5054 | * automatically associates this logged event with this Firebase web
|
5055 | * app instance on this device.
|
5056 | * List of recommended event parameters can be found in
|
5057 | * {@link https://developers.google.com/gtagjs/reference/ga4-events
|
5058 | * | the GA4 reference documentation}.
|
5059 | */
|
5060 | logEvent(
|
5061 | eventName: 'select_item',
|
5062 | eventParams?: {
|
5063 | items?: EventParams['items'];
|
5064 | item_list_name?: EventParams['item_list_name'];
|
5065 | item_list_id?: EventParams['item_list_id'];
|
5066 | [key: string]: any;
|
5067 | },
|
5068 | options?: firebase.analytics.AnalyticsCallOptions
|
5069 | ): void;
|
5070 |
|
5071 | /**
|
5072 | * Sends analytics event with given `eventParams`. This method
|
5073 | * automatically associates this logged event with this Firebase web
|
5074 | * app instance on this device.
|
5075 | * List of recommended event parameters can be found in
|
5076 | * {@link https://developers.google.com/gtagjs/reference/ga4-events
|
5077 | * | the GA4 reference documentation}.
|
5078 | */
|
5079 | logEvent(
|
5080 | eventName: 'select_promotion' | 'view_promotion',
|
5081 | eventParams?: {
|
5082 | items?: EventParams['items'];
|
5083 | promotion_id?: EventParams['promotion_id'];
|
5084 | promotion_name?: EventParams['promotion_name'];
|
5085 | [key: string]: any;
|
5086 | },
|
5087 | options?: firebase.analytics.AnalyticsCallOptions
|
5088 | ): void;
|
5089 |
|
5090 | /**
|
5091 | * Sends analytics event with given `eventParams`. This method
|
5092 | * automatically associates this logged event with this Firebase web
|
5093 | * app instance on this device.
|
5094 | * List of recommended event parameters can be found in
|
5095 | * {@link https://developers.google.com/gtagjs/reference/ga4-events
|
5096 | * | the GA4 reference documentation}.
|
5097 | */
|
5098 | logEvent(
|
5099 | eventName: 'set_checkout_option',
|
5100 | eventParams?: {
|
5101 | checkout_step?: EventParams['checkout_step'];
|
5102 | checkout_option?: EventParams['checkout_option'];
|
5103 | [key: string]: any;
|
5104 | },
|
5105 | options?: firebase.analytics.AnalyticsCallOptions
|
5106 | ): void;
|
5107 |
|
5108 | /**
|
5109 | * Sends analytics event with given `eventParams`. This method
|
5110 | * automatically associates this logged event with this Firebase web
|
5111 | * app instance on this device.
|
5112 | * List of recommended event parameters can be found in
|
5113 | * {@link https://developers.google.com/gtagjs/reference/ga4-events
|
5114 | * | the GA4 reference documentation}.
|
5115 | */
|
5116 | logEvent(
|
5117 | eventName: 'share',
|
5118 | eventParams?: {
|
5119 | method?: EventParams['method'];
|
5120 | content_type?: EventParams['content_type'];
|
5121 | item_id?: EventParams['item_id'];
|
5122 | [key: string]: any;
|
5123 | },
|
5124 | options?: firebase.analytics.AnalyticsCallOptions
|
5125 | ): void;
|
5126 |
|
5127 | /**
|
5128 | * Sends analytics event with given `eventParams`. This method
|
5129 | * automatically associates this logged event with this Firebase web
|
5130 | * app instance on this device.
|
5131 | * List of recommended event parameters can be found in
|
5132 | * {@link https://developers.google.com/gtagjs/reference/ga4-events
|
5133 | * | the GA4 reference documentation}.
|
5134 | */
|
5135 | logEvent(
|
5136 | eventName: 'sign_up',
|
5137 | eventParams?: {
|
5138 | method?: EventParams['method'];
|
5139 | [key: string]: any;
|
5140 | },
|
5141 | options?: firebase.analytics.AnalyticsCallOptions
|
5142 | ): void;
|
5143 |
|
5144 | /**
|
5145 | * Sends analytics event with given `eventParams`. This method
|
5146 | * automatically associates this logged event with this Firebase web
|
5147 | * app instance on this device.
|
5148 | * List of recommended event parameters can be found in
|
5149 | * {@link https://developers.google.com/gtagjs/reference/ga4-events
|
5150 | * | the GA4 reference documentation}.
|
5151 | */
|
5152 | logEvent(
|
5153 | eventName: 'timing_complete',
|
5154 | eventParams?: {
|
5155 | name: string;
|
5156 | value: number;
|
5157 | event_category?: string;
|
5158 | event_label?: string;
|
5159 | [key: string]: any;
|
5160 | },
|
5161 | options?: firebase.analytics.AnalyticsCallOptions
|
5162 | ): void;
|
5163 |
|
5164 | /**
|
5165 | * Sends analytics event with given `eventParams`. This method
|
5166 | * automatically associates this logged event with this Firebase web
|
5167 | * app instance on this device.
|
5168 | * List of recommended event parameters can be found in
|
5169 | * {@link https://developers.google.com/gtagjs/reference/ga4-events
|
5170 | * | the GA4 reference documentation}.
|
5171 | */
|
5172 | logEvent(
|
5173 | eventName: 'view_cart' | 'view_item',
|
5174 | eventParams?: {
|
5175 | currency?: EventParams['currency'];
|
5176 | items?: EventParams['items'];
|
5177 | value?: EventParams['value'];
|
5178 | [key: string]: any;
|
5179 | },
|
5180 | options?: firebase.analytics.AnalyticsCallOptions
|
5181 | ): void;
|
5182 |
|
5183 | /**
|
5184 | * Sends analytics event with given `eventParams`. This method
|
5185 | * automatically associates this logged event with this Firebase web
|
5186 | * app instance on this device.
|
5187 | * List of recommended event parameters can be found in
|
5188 | * {@link https://developers.google.com/gtagjs/reference/ga4-events
|
5189 | * | the GA4 reference documentation}.
|
5190 | */
|
5191 | logEvent(
|
5192 | eventName: 'view_item_list',
|
5193 | eventParams?: {
|
5194 | items?: EventParams['items'];
|
5195 | item_list_name?: EventParams['item_list_name'];
|
5196 | item_list_id?: EventParams['item_list_id'];
|
5197 | [key: string]: any;
|
5198 | },
|
5199 | options?: firebase.analytics.AnalyticsCallOptions
|
5200 | ): void;
|
5201 |
|
5202 | /**
|
5203 | * Sends analytics event with given `eventParams`. This method
|
5204 | * automatically associates this logged event with this Firebase web
|
5205 | * app instance on this device.
|
5206 | * List of recommended event parameters can be found in
|
5207 | * {@link https://developers.google.com/gtagjs/reference/ga4-events
|
5208 | * | the GA4 reference documentation}.
|
5209 | */
|
5210 | logEvent<T extends string>(
|
5211 | eventName: CustomEventName<T>,
|
5212 | eventParams?: { [key: string]: any },
|
5213 | options?: firebase.analytics.AnalyticsCallOptions
|
5214 | ): void;
|
5215 |
|
5216 | /**
|
5217 | * Use gtag 'config' command to set 'screen_name'.
|
5218 | */
|
5219 | setCurrentScreen(
|
5220 | screenName: string,
|
5221 | options?: firebase.analytics.AnalyticsCallOptions
|
5222 | ): void;
|
5223 |
|
5224 | /**
|
5225 | * Use gtag 'config' command to set 'user_id'.
|
5226 | */
|
5227 | setUserId(
|
5228 | id: string,
|
5229 | options?: firebase.analytics.AnalyticsCallOptions
|
5230 | ): void;
|
5231 |
|
5232 | /**
|
5233 | * Use gtag 'config' command to set all params specified.
|
5234 | */
|
5235 | setUserProperties(
|
5236 | properties: firebase.analytics.CustomParams,
|
5237 | options?: firebase.analytics.AnalyticsCallOptions
|
5238 | ): void;
|
5239 |
|
5240 | /**
|
5241 | * Sets whether analytics collection is enabled for this app on this device.
|
5242 | * window['ga-disable-analyticsId'] = true;
|
5243 | */
|
5244 | setAnalyticsCollectionEnabled(enabled: boolean): void;
|
5245 | }
|
5246 |
|
5247 | export type CustomEventName<T> = T extends EventNameString ? never : T;
|
5248 |
|
5249 | /**
|
5250 | * Additional options that can be passed to Firebase Analytics method
|
5251 | * calls such as `logEvent`, `setCurrentScreen`, etc.
|
5252 | */
|
5253 | export interface AnalyticsCallOptions {
|
5254 | /**
|
5255 | * If true, this config or event call applies globally to all
|
5256 | * analytics properties on the page.
|
5257 | */
|
5258 | global: boolean;
|
5259 | }
|
5260 |
|
5261 | /**
|
5262 | * Specifies custom options for your Firebase Analytics instance.
|
5263 | * You must set these before initializing `firebase.analytics()`.
|
5264 | */
|
5265 | export interface SettingsOptions {
|
5266 | /** Sets custom name for `gtag` function. */
|
5267 | gtagName?: string;
|
5268 | /** Sets custom name for `dataLayer` array used by gtag. */
|
5269 | dataLayerName?: string;
|
5270 | }
|
5271 |
|
5272 | /**
|
5273 | * Configures Firebase Analytics to use custom `gtag` or `dataLayer` names.
|
5274 | * Intended to be used if `gtag.js` script has been installed on
|
5275 | * this page independently of Firebase Analytics, and is using non-default
|
5276 | * names for either the `gtag` function or for `dataLayer`.
|
5277 | * Must be called before calling `firebase.analytics()` or it won't
|
5278 | * have any effect.
|
5279 | */
|
5280 | export function settings(settings: firebase.analytics.SettingsOptions): void;
|
5281 |
|
5282 | /**
|
5283 | * Standard gtag.js control parameters.
|
5284 | * For more information, see
|
5285 | * {@link https://developers.google.com/gtagjs/reference/parameter
|
5286 | * the gtag.js documentation on parameters}.
|
5287 | */
|
5288 | export interface ControlParams {
|
5289 | groups?: string | string[];
|
5290 | send_to?: string | string[];
|
5291 | event_callback?: () => void;
|
5292 | event_timeout?: number;
|
5293 | }
|
5294 |
|
5295 | /**
|
5296 | * Standard gtag.js event parameters.
|
5297 | * For more information, see
|
5298 | * {@link https://developers.google.com/gtagjs/reference/parameter
|
5299 | * the gtag.js documentation on parameters}.
|
5300 | */
|
5301 | export interface EventParams {
|
5302 | checkout_option?: string;
|
5303 | checkout_step?: number;
|
5304 | item_id?: string;
|
5305 | content_type?: string;
|
5306 | coupon?: string;
|
5307 | currency?: string;
|
5308 | description?: string;
|
5309 | fatal?: boolean;
|
5310 | items?: Item[];
|
5311 | method?: string;
|
5312 | number?: string;
|
5313 | promotions?: Promotion[];
|
5314 | screen_name?: string;
|
5315 | /**
|
5316 | * Firebase-specific. Use to log a `screen_name` to Firebase Analytics.
|
5317 | */
|
5318 | firebase_screen?: string;
|
5319 | /**
|
5320 | * Firebase-specific. Use to log a `screen_class` to Firebase Analytics.
|
5321 | */
|
5322 | firebase_screen_class?: string;
|
5323 | search_term?: string;
|
5324 | shipping?: Currency;
|
5325 | tax?: Currency;
|
5326 | transaction_id?: string;
|
5327 | value?: number;
|
5328 | event_label?: string;
|
5329 | event_category: string;
|
5330 | shipping_tier?: string;
|
5331 | item_list_id?: string;
|
5332 | item_list_name?: string;
|
5333 | promotion_id?: string;
|
5334 | promotion_name?: string;
|
5335 | payment_type?: string;
|
5336 | affiliation?: string;
|
5337 | }
|
5338 |
|
5339 | /**
|
5340 | * Any custom params the user may pass to gtag.js.
|
5341 | */
|
5342 | export interface CustomParams {
|
5343 | [key: string]: any;
|
5344 | }
|
5345 |
|
5346 | /**
|
5347 | * Type for standard gtag.js event names. `logEvent` also accepts any
|
5348 | * custom string and interprets it as a custom event name.
|
5349 | */
|
5350 | export type EventNameString =
|
5351 | | 'add_payment_info'
|
5352 | | 'add_shipping_info'
|
5353 | | 'add_to_cart'
|
5354 | | 'add_to_wishlist'
|
5355 | | 'begin_checkout'
|
5356 | | 'checkout_progress'
|
5357 | | 'exception'
|
5358 | | 'generate_lead'
|
5359 | | 'login'
|
5360 | | 'page_view'
|
5361 | | 'purchase'
|
5362 | | 'refund'
|
5363 | | 'remove_from_cart'
|
5364 | | 'screen_view'
|
5365 | | 'search'
|
5366 | | 'select_content'
|
5367 | | 'select_item'
|
5368 | | 'select_promotion'
|
5369 | | 'set_checkout_option'
|
5370 | | 'share'
|
5371 | | 'sign_up'
|
5372 | | 'timing_complete'
|
5373 | | 'view_cart'
|
5374 | | 'view_item'
|
5375 | | 'view_item_list'
|
5376 | | 'view_promotion'
|
5377 | | 'view_search_results';
|
5378 |
|
5379 | /**
|
5380 | * Enum of standard gtag.js event names provided for convenient
|
5381 | * developer usage. `logEvent` will also accept any custom string
|
5382 | * and interpret it as a custom event name.
|
5383 | */
|
5384 | export enum EventName {
|
5385 | ADD_PAYMENT_INFO = 'add_payment_info',
|
5386 | ADD_SHIPPING_INFO = 'add_shipping_info',
|
5387 | ADD_TO_CART = 'add_to_cart',
|
5388 | ADD_TO_WISHLIST = 'add_to_wishlist',
|
5389 | BEGIN_CHECKOUT = 'begin_checkout',
|
5390 | /** @deprecated */
|
5391 | CHECKOUT_PROGRESS = 'checkout_progress',
|
5392 | EXCEPTION = 'exception',
|
5393 | GENERATE_LEAD = 'generate_lead',
|
5394 | LOGIN = 'login',
|
5395 | PAGE_VIEW = 'page_view',
|
5396 | PURCHASE = 'purchase',
|
5397 | REFUND = 'refund',
|
5398 | REMOVE_FROM_CART = 'remove_from_cart',
|
5399 | SCREEN_VIEW = 'screen_view',
|
5400 | SEARCH = 'search',
|
5401 | SELECT_CONTENT = 'select_content',
|
5402 | SELECT_ITEM = 'select_item',
|
5403 | SELECT_PROMOTION = 'select_promotion',
|
5404 | /** @deprecated */
|
5405 | SET_CHECKOUT_OPTION = 'set_checkout_option',
|
5406 | SHARE = 'share',
|
5407 | SIGN_UP = 'sign_up',
|
5408 | TIMING_COMPLETE = 'timing_complete',
|
5409 | VIEW_CART = 'view_cart',
|
5410 | VIEW_ITEM = 'view_item',
|
5411 | VIEW_ITEM_LIST = 'view_item_list',
|
5412 | VIEW_PROMOTION = 'view_promotion',
|
5413 | VIEW_SEARCH_RESULTS = 'view_search_results'
|
5414 | }
|
5415 |
|
5416 | export type Currency = string | number;
|
5417 |
|
5418 | export interface Item {
|
5419 | item_id?: string;
|
5420 | item_name?: string;
|
5421 | item_brand?: string;
|
5422 | item_category?: string;
|
5423 | item_category2?: string;
|
5424 | item_category3?: string;
|
5425 | item_category4?: string;
|
5426 | item_category5?: string;
|
5427 | item_variant?: string;
|
5428 | price?: Currency;
|
5429 | quantity?: number;
|
5430 | index?: number;
|
5431 | coupon?: string;
|
5432 | item_list_name?: string;
|
5433 | item_list_id?: string;
|
5434 | discount?: Currency;
|
5435 | affiliation?: string;
|
5436 | creative_name?: string;
|
5437 | creative_slot?: string;
|
5438 | promotion_id?: string;
|
5439 | promotion_name?: string;
|
5440 | location_id?: string;
|
5441 | /** @deprecated Use item_brand instead. */
|
5442 | brand?: string;
|
5443 | /** @deprecated Use item_category instead. */
|
5444 | category?: string;
|
5445 | /** @deprecated Use item_id instead. */
|
5446 | id?: string;
|
5447 | /** @deprecated Use item_name instead. */
|
5448 | name?: string;
|
5449 | }
|
5450 |
|
5451 | /** @deprecated Use Item instead. */
|
5452 | export interface Promotion {
|
5453 | creative_name?: string;
|
5454 | creative_slot?: string;
|
5455 | id?: string;
|
5456 | name?: string;
|
5457 | }
|
5458 |
|
5459 | /**
|
5460 | * An async function that returns true if current browser context supports initialization of analytics module
|
5461 | * (`firebase.analytics()`).
|
5462 | *
|
5463 | * Returns false otherwise.
|
5464 | *
|
5465 | *
|
5466 | */
|
5467 | function isSupported(): Promise<boolean>;
|
5468 | }
|
5469 |
|
5470 | declare namespace firebase.auth.Auth {
|
5471 | type Persistence = string;
|
5472 | /**
|
5473 | * An enumeration of the possible persistence mechanism types.
|
5474 | */
|
5475 | var Persistence: {
|
5476 | /**
|
5477 | * Indicates that the state will be persisted even when the browser window is
|
5478 | * closed or the activity is destroyed in react-native.
|
5479 | */
|
5480 | LOCAL: Persistence;
|
5481 | /**
|
5482 | * Indicates that the state will only be stored in memory and will be cleared
|
5483 | * when the window or activity is refreshed.
|
5484 | */
|
5485 | NONE: Persistence;
|
5486 | /**
|
5487 | * Indicates that the state will only persist in current session/tab, relevant
|
5488 | * to web only, and will be cleared when the tab is closed.
|
5489 | */
|
5490 | SESSION: Persistence;
|
5491 | };
|
5492 | }
|
5493 |
|
5494 | declare namespace firebase.User {
|
5495 | /**
|
5496 | * This is the interface that defines the multi-factor related properties and
|
5497 | * operations pertaining to a {@link firebase.User}.
|
5498 | */
|
5499 | interface MultiFactorUser {
|
5500 | /**
|
5501 | * Returns a list of the user's enrolled second factors.
|
5502 | */
|
5503 | enrolledFactors: firebase.auth.MultiFactorInfo[];
|
5504 | /**
|
5505 | * Enrolls a second factor as identified by the
|
5506 | * {@link firebase.auth.MultiFactorAssertion} for the current user.
|
5507 | * On resolution, the user tokens are updated to reflect the change in the
|
5508 | * JWT payload.
|
5509 | * Accepts an additional display name parameter used to identify the second
|
5510 | * factor to the end user.
|
5511 | * Recent re-authentication is required for this operation to succeed.
|
5512 | * On successful enrollment, existing Firebase sessions (refresh tokens) are
|
5513 | * revoked. When a new factor is enrolled, an email notification is sent
|
5514 | * to the user’s email.
|
5515 | *
|
5516 | * <h4>Error Codes</h4>
|
5517 | * <dl>
|
5518 | * <dt>auth/invalid-verification-code</dt>
|
5519 | * <dd>Thrown if the verification code is not valid.</dd>
|
5520 | * <dt>auth/missing-verification-code</dt>
|
5521 | * <dd>Thrown if the verification code is missing.</dd>
|
5522 | * <dt>auth/invalid-verification-id</dt>
|
5523 | * <dd>Thrown if the credential is a
|
5524 | * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
|
5525 | * ID of the credential is not valid.</dd>
|
5526 | * <dt>auth/missing-verification-id</dt>
|
5527 | * <dd>Thrown if the verification ID is missing.</dd>
|
5528 | * <dt>auth/code-expired</dt>
|
5529 | * <dd>Thrown if the verification code has expired.</dd>
|
5530 | * <dt>auth/maximum-second-factor-count-exceeded</dt>
|
5531 | * <dd>Thrown if The maximum allowed number of second factors on a user
|
5532 | * has been exceeded.</dd>
|
5533 | * <dt>auth/second-factor-already-in-use</dt>
|
5534 | * <dd>Thrown if the second factor is already enrolled on this account.</dd>
|
5535 | * <dt>auth/unsupported-first-factor</dt>
|
5536 | * <dd>Thrown if the first factor being used to sign in is not supported.</dd>
|
5537 | * <dt>auth/unverified-email</dt>
|
5538 | * <dd>Thrown if the email of the account is not verified.</dd>
|
5539 | * <dt>auth/requires-recent-login</dt>
|
5540 | * <dd>Thrown if the user's last sign-in time does not meet the security
|
5541 | * threshold. Use {@link firebase.User.reauthenticateWithCredential} to
|
5542 | * resolve.</dd>
|
5543 | * </dl>
|
5544 | *
|
5545 | * @example
|
5546 | * ```javascript
|
5547 | * firebase.auth().currentUser.multiFactor.getSession()
|
5548 | * .then(function(multiFactorSession) {
|
5549 | * // Send verification code
|
5550 | * var phoneAuthProvider = new firebase.auth.PhoneAuthProvider();
|
5551 | * var phoneInfoOptions = {
|
5552 | * phoneNumber: phoneNumber,
|
5553 | * session: multiFactorSession
|
5554 | * };
|
5555 | * return phoneAuthProvider.verifyPhoneNumber(
|
5556 | * phoneInfoOptions, appVerifier);
|
5557 | * }).then(function(verificationId) {
|
5558 | * // Store verificationID and show UI to let user enter verification code.
|
5559 | * });
|
5560 | *
|
5561 | * var phoneAuthCredential =
|
5562 | * firebase.auth.PhoneAuthProvider.credential(verificationId, verificationCode);
|
5563 | * var multiFactorAssertion =
|
5564 | * firebase.auth.PhoneMultiFactorGenerator.assertion(phoneAuthCredential);
|
5565 | * firebase.auth().currentUser.multiFactor.enroll(multiFactorAssertion)
|
5566 | * .then(function() {
|
5567 | * // Second factor enrolled.
|
5568 | * });
|
5569 | * ```
|
5570 | *
|
5571 | * @param assertion The multi-factor assertion to enroll with.
|
5572 | * @param displayName The display name of the second factor.
|
5573 | */
|
5574 | enroll(
|
5575 | assertion: firebase.auth.MultiFactorAssertion,
|
5576 | displayName?: string | null
|
5577 | ): Promise<void>;
|
5578 | /**
|
5579 | * Returns the session identifier for a second factor enrollment operation.
|
5580 | * This is used to identify the current user trying to enroll a second factor.
|
5581 | * @return The promise that resolves with the
|
5582 | * {@link firebase.auth.MultiFactorSession}.
|
5583 | *
|
5584 | * <h4>Error Codes</h4>
|
5585 | * <dl>
|
5586 | * <dt>auth/user-token-expired</dt>
|
5587 | * <dd>Thrown if the token of the user is expired.</dd>
|
5588 | * </dl>
|
5589 | */
|
5590 | getSession(): Promise<firebase.auth.MultiFactorSession>;
|
5591 | /**
|
5592 | * Unenrolls the specified second factor. To specify the factor to remove, pass
|
5593 | * a {@link firebase.auth.MultiFactorInfo} object
|
5594 | * (retrieved from <code>enrolledFactors()</code>)
|
5595 | * or the factor's UID string.
|
5596 | * Sessions are not revoked when the account is downgraded. An email
|
5597 | * notification is likely to be sent to the user notifying them of the change.
|
5598 | * Recent re-authentication is required for this operation to succeed.
|
5599 | * When an existing factor is unenrolled, an email notification is sent to the
|
5600 | * user’s email.
|
5601 | *
|
5602 | * <h4>Error Codes</h4>
|
5603 | * <dl>
|
5604 | * <dt>auth/multi-factor-info-not-found</dt>
|
5605 | * <dd>Thrown if the user does not have a second factor matching the
|
5606 | * identifier provided.</dd>
|
5607 | * <dt>auth/requires-recent-login</dt>
|
5608 | * <dd>Thrown if the user's last sign-in time does not meet the security
|
5609 | * threshold. Use {@link firebase.User.reauthenticateWithCredential} to
|
5610 | * resolve.</dd>
|
5611 | * </dl>
|
5612 | *
|
5613 | * @example
|
5614 | * ```javascript
|
5615 | * var options = firebase.auth().currentUser.multiFactor.enrolledFactors;
|
5616 | * // Present user the option to unenroll.
|
5617 | * return firebase.auth().currentUser.multiFactor.unenroll(options[i])
|
5618 | * .then(function() {
|
5619 | * // User successfully unenrolled selected factor.
|
5620 | * }).catch(function(error) {
|
5621 | * // Handler error.
|
5622 | * });
|
5623 | * ```
|
5624 | *
|
5625 | * @param option The multi-factor option to unenroll.
|
5626 | */
|
5627 | unenroll(option: firebase.auth.MultiFactorInfo | string): Promise<void>;
|
5628 | }
|
5629 | }
|
5630 |
|
5631 | declare namespace firebase.auth.ActionCodeInfo {
|
5632 | type Operation = string;
|
5633 | /**
|
5634 | * An enumeration of the possible email action types.
|
5635 | */
|
5636 | var Operation: {
|
5637 | /**
|
5638 | * The email link sign-in action.
|
5639 | */
|
5640 | EMAIL_SIGNIN: Operation;
|
5641 | /**
|
5642 | * The password reset action.
|
5643 | */
|
5644 | PASSWORD_RESET: Operation;
|
5645 | /**
|
5646 | * The email revocation action.
|
5647 | */
|
5648 | RECOVER_EMAIL: Operation;
|
5649 | /**
|
5650 | * The revert second factor addition email action.
|
5651 | */
|
5652 | REVERT_SECOND_FACTOR_ADDITION: Operation;
|
5653 | /**
|
5654 | * The verify and update email action.
|
5655 | */
|
5656 | VERIFY_AND_CHANGE_EMAIL: Operation;
|
5657 | /**
|
5658 | * The email verification action.
|
5659 | */
|
5660 | VERIFY_EMAIL: Operation;
|
5661 | };
|
5662 | }
|
5663 |
|
5664 | declare namespace firebase.database {
|
5665 | /**
|
5666 | * A `DataSnapshot` contains data from a Database location.
|
5667 | *
|
5668 | * Any time you read data from the Database, you receive the data as a
|
5669 | * `DataSnapshot`. A `DataSnapshot` is passed to the event callbacks you attach
|
5670 | * with `on()` or `once()`. You can extract the contents of the snapshot as a
|
5671 | * JavaScript object by calling the `val()` method. Alternatively, you can
|
5672 | * traverse into the snapshot by calling `child()` to return child snapshots
|
5673 | * (which you could then call `val()` on).
|
5674 | *
|
5675 | * A `DataSnapshot` is an efficiently generated, immutable copy of the data at
|
5676 | * a Database location. It cannot be modified and will never change (to modify
|
5677 | * data, you always call the `set()` method on a `Reference` directly).
|
5678 | *
|
5679 | */
|
5680 | interface DataSnapshot {
|
5681 | /**
|
5682 | * Gets another `DataSnapshot` for the location at the specified relative path.
|
5683 | *
|
5684 | * Passing a relative path to the `child()` method of a DataSnapshot returns
|
5685 | * another `DataSnapshot` for the location at the specified relative path. The
|
5686 | * relative path can either be a simple child name (for example, "ada") or a
|
5687 | * deeper, slash-separated path (for example, "ada/name/first"). If the child
|
5688 | * location has no data, an empty `DataSnapshot` (that is, a `DataSnapshot`
|
5689 | * whose value is `null`) is returned.
|
5690 | *
|
5691 | * @example
|
5692 | * ```javascript
|
5693 | * // Assume we have the following data in the Database:
|
5694 | * {
|
5695 | * "name": {
|
5696 | * "first": "Ada",
|
5697 | * "last": "Lovelace"
|
5698 | * }
|
5699 | * }
|
5700 | *
|
5701 | * // Test for the existence of certain keys within a DataSnapshot
|
5702 | * var ref = firebase.database().ref("users/ada");
|
5703 | * ref.once("value")
|
5704 | * .then(function(snapshot) {
|
5705 | * var name = snapshot.child("name").val(); // {first:"Ada",last:"Lovelace"}
|
5706 | * var firstName = snapshot.child("name/first").val(); // "Ada"
|
5707 | * var lastName = snapshot.child("name").child("last").val(); // "Lovelace"
|
5708 | * var age = snapshot.child("age").val(); // null
|
5709 | * });
|
5710 | * ```
|
5711 | *
|
5712 | * @param path A relative path to the location of child data.
|
5713 | */
|
5714 | child(path: string): firebase.database.DataSnapshot;
|
5715 | /**
|
5716 | * Returns true if this `DataSnapshot` contains any data. It is slightly more
|
5717 | * efficient than using `snapshot.val() !== null`.
|
5718 | *
|
5719 | * @example
|
5720 | * ```javascript
|
5721 | * // Assume we have the following data in the Database:
|
5722 | * {
|
5723 | * "name": {
|
5724 | * "first": "Ada",
|
5725 | * "last": "Lovelace"
|
5726 | * }
|
5727 | * }
|
5728 | *
|
5729 | * // Test for the existence of certain keys within a DataSnapshot
|
5730 | * var ref = firebase.database().ref("users/ada");
|
5731 | * ref.once("value")
|
5732 | * .then(function(snapshot) {
|
5733 | * var a = snapshot.exists(); // true
|
5734 | * var b = snapshot.child("name").exists(); // true
|
5735 | * var c = snapshot.child("name/first").exists(); // true
|
5736 | * var d = snapshot.child("name/middle").exists(); // false
|
5737 | * });
|
5738 | * ```
|
5739 | */
|
5740 | exists(): boolean;
|
5741 | /**
|
5742 | * Exports the entire contents of the DataSnapshot as a JavaScript object.
|
5743 | *
|
5744 | * The `exportVal()` method is similar to `val()`, except priority information
|
5745 | * is included (if available), making it suitable for backing up your data.
|
5746 | *
|
5747 | * @return The DataSnapshot's contents as a JavaScript value (Object,
|
5748 | * Array, string, number, boolean, or `null`).
|
5749 | */
|
5750 | exportVal(): any;
|
5751 | /**
|
5752 | * Enumerates the top-level children in the `DataSnapshot`.
|
5753 | *
|
5754 | * Because of the way JavaScript objects work, the ordering of data in the
|
5755 | * JavaScript object returned by `val()` is not guaranteed to match the ordering
|
5756 | * on the server nor the ordering of `child_added` events. That is where
|
5757 | * `forEach()` comes in handy. It guarantees the children of a `DataSnapshot`
|
5758 | * will be iterated in their query order.
|
5759 | *
|
5760 | * If no explicit `orderBy*()` method is used, results are returned
|
5761 | * ordered by key (unless priorities are used, in which case, results are
|
5762 | * returned by priority).
|
5763 | *
|
5764 | * @example
|
5765 | * ```javascript
|
5766 | * // Assume we have the following data in the Database:
|
5767 | * {
|
5768 | * "users": {
|
5769 | * "ada": {
|
5770 | * "first": "Ada",
|
5771 | * "last": "Lovelace"
|
5772 | * },
|
5773 | * "alan": {
|
5774 | * "first": "Alan",
|
5775 | * "last": "Turing"
|
5776 | * }
|
5777 | * }
|
5778 | * }
|
5779 | *
|
5780 | * // Loop through users in order with the forEach() method. The callback
|
5781 | * // provided to forEach() will be called synchronously with a DataSnapshot
|
5782 | * // for each child:
|
5783 | * var query = firebase.database().ref("users").orderByKey();
|
5784 | * query.once("value")
|
5785 | * .then(function(snapshot) {
|
5786 | * snapshot.forEach(function(childSnapshot) {
|
5787 | * // key will be "ada" the first time and "alan" the second time
|
5788 | * var key = childSnapshot.key;
|
5789 | * // childData will be the actual contents of the child
|
5790 | * var childData = childSnapshot.val();
|
5791 | * });
|
5792 | * });
|
5793 | * ```
|
5794 | *
|
5795 | * @example
|
5796 | * ```javascript
|
5797 | * // You can cancel the enumeration at any point by having your callback
|
5798 | * // function return true. For example, the following code sample will only
|
5799 | * // fire the callback function one time:
|
5800 | * var query = firebase.database().ref("users").orderByKey();
|
5801 | * query.once("value")
|
5802 | * .then(function(snapshot) {
|
5803 | * snapshot.forEach(function(childSnapshot) {
|
5804 | * var key = childSnapshot.key; // "ada"
|
5805 | *
|
5806 | * // Cancel enumeration
|
5807 | * return true;
|
5808 | * });
|
5809 | * });
|
5810 | * ```
|
5811 | *
|
5812 | * @param action A function
|
5813 | * that will be called for each child DataSnapshot. The callback can return
|
5814 | * true to cancel further enumeration.
|
5815 | * @return true if enumeration was canceled due to your callback
|
5816 | * returning true.
|
5817 | */
|
5818 | forEach(
|
5819 | action: (a: firebase.database.DataSnapshot) => boolean | void
|
5820 | ): boolean;
|
5821 | /**
|
5822 | * Gets the priority value of the data in this `DataSnapshot`.
|
5823 | *
|
5824 | * Applications need not use priority but can order collections by
|
5825 | * ordinary properties (see
|
5826 | * {@link
|
5827 | * https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data
|
5828 | * Sorting and filtering data}).
|
5829 | */
|
5830 | getPriority(): string | number | null;
|
5831 | /**
|
5832 | * Returns true if the specified child path has (non-null) data.
|
5833 | *
|
5834 | * @example
|
5835 | * ```javascript
|
5836 | * // Assume we have the following data in the Database:
|
5837 | * {
|
5838 | * "name": {
|
5839 | * "first": "Ada",
|
5840 | * "last": "Lovelace"
|
5841 | * }
|
5842 | * }
|
5843 | *
|
5844 | * // Determine which child keys in DataSnapshot have data.
|
5845 | * var ref = firebase.database().ref("users/ada");
|
5846 | * ref.once("value")
|
5847 | * .then(function(snapshot) {
|
5848 | * var hasName = snapshot.hasChild("name"); // true
|
5849 | * var hasAge = snapshot.hasChild("age"); // false
|
5850 | * });
|
5851 | * ```
|
5852 | *
|
5853 | * @param path A relative path to the location of a potential child.
|
5854 | * @return `true` if data exists at the specified child path; else
|
5855 | * `false`.
|
5856 | */
|
5857 | hasChild(path: string): boolean;
|
5858 | /**
|
5859 | * Returns whether or not the `DataSnapshot` has any non-`null` child
|
5860 | * properties.
|
5861 | *
|
5862 | * You can use `hasChildren()` to determine if a `DataSnapshot` has any
|
5863 | * children. If it does, you can enumerate them using `forEach()`. If it
|
5864 | * doesn't, then either this snapshot contains a primitive value (which can be
|
5865 | * retrieved with `val()`) or it is empty (in which case, `val()` will return
|
5866 | * `null`).
|
5867 | *
|
5868 | * @example
|
5869 | * ```javascript
|
5870 | * // Assume we have the following data in the Database:
|
5871 | * {
|
5872 | * "name": {
|
5873 | * "first": "Ada",
|
5874 | * "last": "Lovelace"
|
5875 | * }
|
5876 | * }
|
5877 | *
|
5878 | * var ref = firebase.database().ref("users/ada");
|
5879 | * ref.once("value")
|
5880 | * .then(function(snapshot) {
|
5881 | * var a = snapshot.hasChildren(); // true
|
5882 | * var b = snapshot.child("name").hasChildren(); // true
|
5883 | * var c = snapshot.child("name/first").hasChildren(); // false
|
5884 | * });
|
5885 | * ```
|
5886 | *
|
5887 | * @return true if this snapshot has any children; else false.
|
5888 | */
|
5889 | hasChildren(): boolean;
|
5890 | /**
|
5891 | * The key (last part of the path) of the location of this `DataSnapshot`.
|
5892 | *
|
5893 | * The last token in a Database location is considered its key. For example,
|
5894 | * "ada" is the key for the /users/ada/ node. Accessing the key on any
|
5895 | * `DataSnapshot` will return the key for the location that generated it.
|
5896 | * However, accessing the key on the root URL of a Database will return `null`.
|
5897 | *
|
5898 | * @example
|
5899 | * ```javascript
|
5900 | * // Assume we have the following data in the Database:
|
5901 | * {
|
5902 | * "name": {
|
5903 | * "first": "Ada",
|
5904 | * "last": "Lovelace"
|
5905 | * }
|
5906 | * }
|
5907 | *
|
5908 | * var ref = firebase.database().ref("users/ada");
|
5909 | * ref.once("value")
|
5910 | * .then(function(snapshot) {
|
5911 | * var key = snapshot.key; // "ada"
|
5912 | * var childKey = snapshot.child("name/last").key; // "last"
|
5913 | * });
|
5914 | * ```
|
5915 | *
|
5916 | * @example
|
5917 | * ```javascript
|
5918 | * var rootRef = firebase.database().ref();
|
5919 | * rootRef.once("value")
|
5920 | * .then(function(snapshot) {
|
5921 | * var key = snapshot.key; // null
|
5922 | * var childKey = snapshot.child("users/ada").key; // "ada"
|
5923 | * });
|
5924 | * ```
|
5925 | */
|
5926 | key: string | null;
|
5927 | /**
|
5928 | * Returns the number of child properties of this `DataSnapshot`.
|
5929 | *
|
5930 | * @example
|
5931 | * ```javascript
|
5932 | * // Assume we have the following data in the Database:
|
5933 | * {
|
5934 | * "name": {
|
5935 | * "first": "Ada",
|
5936 | * "last": "Lovelace"
|
5937 | * }
|
5938 | * }
|
5939 | *
|
5940 | * var ref = firebase.database().ref("users/ada");
|
5941 | * ref.once("value")
|
5942 | * .then(function(snapshot) {
|
5943 | * var a = snapshot.numChildren(); // 1 ("name")
|
5944 | * var b = snapshot.child("name").numChildren(); // 2 ("first", "last")
|
5945 | * var c = snapshot.child("name/first").numChildren(); // 0
|
5946 | * });
|
5947 | * ```
|
5948 | */
|
5949 | numChildren(): number;
|
5950 | /**
|
5951 | * Extracts a JavaScript value from a `DataSnapshot`.
|
5952 | *
|
5953 | * Depending on the data in a `DataSnapshot`, the `val()` method may return a
|
5954 | * scalar type (string, number, or boolean), an array, or an object. It may also
|
5955 | * return null, indicating that the `DataSnapshot` is empty (contains no data).
|
5956 | *
|
5957 | * @example
|
5958 | * ```javascript
|
5959 | * // Write and then read back a string from the Database.
|
5960 | * ref.set("hello")
|
5961 | * .then(function() {
|
5962 | * return ref.once("value");
|
5963 | * })
|
5964 | * .then(function(snapshot) {
|
5965 | * var data = snapshot.val(); // data === "hello"
|
5966 | * });
|
5967 | * ```
|
5968 | *
|
5969 | * @example
|
5970 | * ```javascript
|
5971 | * // Write and then read back a JavaScript object from the Database.
|
5972 | * ref.set({ name: "Ada", age: 36 })
|
5973 | * .then(function() {
|
5974 | * return ref.once("value");
|
5975 | * })
|
5976 | * .then(function(snapshot) {
|
5977 | * var data = snapshot.val();
|
5978 | * // data is { "name": "Ada", "age": 36 }
|
5979 | * // data.name === "Ada"
|
5980 | * // data.age === 36
|
5981 | * });
|
5982 | * ```
|
5983 | *
|
5984 | * @return The DataSnapshot's contents as a JavaScript value (Object,
|
5985 | * Array, string, number, boolean, or `null`).
|
5986 | */
|
5987 | val(): any;
|
5988 | /**
|
5989 | * The `Reference` for the location that generated this `DataSnapshot`.
|
5990 | */
|
5991 | ref: firebase.database.Reference;
|
5992 | /**
|
5993 | * Returns a JSON-serializable representation of this object.
|
5994 | */
|
5995 | toJSON(): Object | null;
|
5996 | }
|
5997 |
|
5998 | /**
|
5999 | * The Firebase Database service interface.
|
6000 | *
|
6001 | * Do not call this constructor directly. Instead, use
|
6002 | * {@link firebase.database `firebase.database()`}.
|
6003 | *
|
6004 | * See
|
6005 | * {@link
|
6006 | * https://firebase.google.com/docs/database/web/start/
|
6007 | * Installation & Setup in JavaScript}
|
6008 | * for a full guide on how to use the Firebase Database service.
|
6009 | */
|
6010 | interface Database {
|
6011 | /**
|
6012 | * The {@link firebase.app.App app} associated with the `Database` service
|
6013 | * instance.
|
6014 | *
|
6015 | * @example
|
6016 | * ```javascript
|
6017 | * var app = database.app;
|
6018 | * ```
|
6019 | */
|
6020 | app: firebase.app.App;
|
6021 | /**
|
6022 | * Modify this instance to communicate with the Realtime Database emulator.
|
6023 | *
|
6024 | * <p>Note: This method must be called before performing any other operation.
|
6025 | *
|
6026 | * @param host the emulator host (ex: localhost)
|
6027 | * @param port the emulator port (ex: 8080)
|
6028 | * @param options.mockUserToken the mock auth token to use for unit testing Security Rules
|
6029 | */
|
6030 | useEmulator(
|
6031 | host: string,
|
6032 | port: number,
|
6033 | options?: {
|
6034 | mockUserToken?: EmulatorMockTokenOptions | string;
|
6035 | }
|
6036 | ): void;
|
6037 | /**
|
6038 | * Disconnects from the server (all Database operations will be completed
|
6039 | * offline).
|
6040 | *
|
6041 | * The client automatically maintains a persistent connection to the Database
|
6042 | * server, which will remain active indefinitely and reconnect when
|
6043 | * disconnected. However, the `goOffline()` and `goOnline()` methods may be used
|
6044 | * to control the client connection in cases where a persistent connection is
|
6045 | * undesirable.
|
6046 | *
|
6047 | * While offline, the client will no longer receive data updates from the
|
6048 | * Database. However, all Database operations performed locally will continue to
|
6049 | * immediately fire events, allowing your application to continue behaving
|
6050 | * normally. Additionally, each operation performed locally will automatically
|
6051 | * be queued and retried upon reconnection to the Database server.
|
6052 | *
|
6053 | * To reconnect to the Database and begin receiving remote events, see
|
6054 | * `goOnline()`.
|
6055 | *
|
6056 | * @example
|
6057 | * ```javascript
|
6058 | * firebase.database().goOffline();
|
6059 | * ```
|
6060 | */
|
6061 | goOffline(): any;
|
6062 | /**
|
6063 | * Reconnects to the server and synchronizes the offline Database state
|
6064 | * with the server state.
|
6065 | *
|
6066 | * This method should be used after disabling the active connection with
|
6067 | * `goOffline()`. Once reconnected, the client will transmit the proper data
|
6068 | * and fire the appropriate events so that your client "catches up"
|
6069 | * automatically.
|
6070 | *
|
6071 | * @example
|
6072 | * ```javascript
|
6073 | * firebase.database().goOnline();
|
6074 | * ```
|
6075 | */
|
6076 | goOnline(): any;
|
6077 | /**
|
6078 | * Returns a `Reference` representing the location in the Database
|
6079 | * corresponding to the provided path. If no path is provided, the `Reference`
|
6080 | * will point to the root of the Database.
|
6081 | *
|
6082 | * @example
|
6083 | * ```javascript
|
6084 | * // Get a reference to the root of the Database
|
6085 | * var rootRef = firebase.database().ref();
|
6086 | * ```
|
6087 | *
|
6088 | * @example
|
6089 | * ```javascript
|
6090 | * // Get a reference to the /users/ada node
|
6091 | * var adaRef = firebase.database().ref("users/ada");
|
6092 | * // The above is shorthand for the following operations:
|
6093 | * //var rootRef = firebase.database().ref();
|
6094 | * //var adaRef = rootRef.child("users/ada");
|
6095 | * ```
|
6096 | *
|
6097 | * @param path Optional path representing the location the returned
|
6098 | * `Reference` will point. If not provided, the returned `Reference` will
|
6099 | * point to the root of the Database.
|
6100 | * @return If a path is provided, a `Reference`
|
6101 | * pointing to the provided path. Otherwise, a `Reference` pointing to the
|
6102 | * root of the Database.
|
6103 | */
|
6104 | ref(path?: string): firebase.database.Reference;
|
6105 | /**
|
6106 | * Returns a `Reference` representing the location in the Database
|
6107 | * corresponding to the provided Firebase URL.
|
6108 | *
|
6109 | * An exception is thrown if the URL is not a valid Firebase Database URL or it
|
6110 | * has a different domain than the current `Database` instance.
|
6111 | *
|
6112 | * Note that all query parameters (`orderBy`, `limitToLast`, etc.) are ignored
|
6113 | * and are not applied to the returned `Reference`.
|
6114 | *
|
6115 | * @example
|
6116 | * ```javascript
|
6117 | * // Get a reference to the root of the Database
|
6118 | * var rootRef = firebase.database().ref("https://<DATABASE_NAME>.firebaseio.com");
|
6119 | * ```
|
6120 | *
|
6121 | * @example
|
6122 | * ```javascript
|
6123 | * // Get a reference to the /users/ada node
|
6124 | * var adaRef = firebase.database().ref("https://<DATABASE_NAME>.firebaseio.com/users/ada");
|
6125 | * ```
|
6126 | *
|
6127 | * @param url The Firebase URL at which the returned `Reference` will
|
6128 | * point.
|
6129 | * @return A `Reference` pointing to the provided
|
6130 | * Firebase URL.
|
6131 | */
|
6132 | refFromURL(url: string): firebase.database.Reference;
|
6133 | }
|
6134 |
|
6135 | /**
|
6136 | * The `onDisconnect` class allows you to write or clear data when your client
|
6137 | * disconnects from the Database server. These updates occur whether your
|
6138 | * client disconnects cleanly or not, so you can rely on them to clean up data
|
6139 | * even if a connection is dropped or a client crashes.
|
6140 | *
|
6141 | * The `onDisconnect` class is most commonly used to manage presence in
|
6142 | * applications where it is useful to detect how many clients are connected and
|
6143 | * when other clients disconnect. See
|
6144 | * {@link
|
6145 | * https://firebase.google.com/docs/database/web/offline-capabilities
|
6146 | * Enabling Offline Capabilities in JavaScript} for more information.
|
6147 | *
|
6148 | * To avoid problems when a connection is dropped before the requests can be
|
6149 | * transferred to the Database server, these functions should be called before
|
6150 | * writing any data.
|
6151 | *
|
6152 | * Note that `onDisconnect` operations are only triggered once. If you want an
|
6153 | * operation to occur each time a disconnect occurs, you'll need to re-establish
|
6154 | * the `onDisconnect` operations each time you reconnect.
|
6155 | */
|
6156 | interface OnDisconnect {
|
6157 | /**
|
6158 | * Cancels all previously queued `onDisconnect()` set or update events for this
|
6159 | * location and all children.
|
6160 | *
|
6161 | * If a write has been queued for this location via a `set()` or `update()` at a
|
6162 | * parent location, the write at this location will be canceled, though writes
|
6163 | * to sibling locations will still occur.
|
6164 | *
|
6165 | * @example
|
6166 | * ```javascript
|
6167 | * var ref = firebase.database().ref("onlineState");
|
6168 | * ref.onDisconnect().set(false);
|
6169 | * // ... sometime later
|
6170 | * ref.onDisconnect().cancel();
|
6171 | * ```
|
6172 | *
|
6173 | * @param onComplete An optional callback function that will
|
6174 | * be called when synchronization to the server has completed. The callback
|
6175 | * will be passed a single parameter: null for success, or an Error object
|
6176 | * indicating a failure.
|
6177 | * @return Resolves when synchronization to the server
|
6178 | * is complete.
|
6179 | */
|
6180 | cancel(onComplete?: (a: Error | null) => any): Promise<any>;
|
6181 | /**
|
6182 | * Ensures the data at this location is deleted when the client is disconnected
|
6183 | * (due to closing the browser, navigating to a new page, or network issues).
|
6184 | *
|
6185 | * @param onComplete An optional callback function that will
|
6186 | * be called when synchronization to the server has completed. The callback
|
6187 | * will be passed a single parameter: null for success, or an Error object
|
6188 | * indicating a failure.
|
6189 | * @return Resolves when synchronization to the server
|
6190 | * is complete.
|
6191 | */
|
6192 | remove(onComplete?: (a: Error | null) => any): Promise<any>;
|
6193 | /**
|
6194 | * Ensures the data at this location is set to the specified value when the
|
6195 | * client is disconnected (due to closing the browser, navigating to a new page,
|
6196 | * or network issues).
|
6197 | *
|
6198 | * `set()` is especially useful for implementing "presence" systems, where a
|
6199 | * value should be changed or cleared when a user disconnects so that they
|
6200 | * appear "offline" to other users. See
|
6201 | * {@link
|
6202 | * https://firebase.google.com/docs/database/web/offline-capabilities
|
6203 | * Enabling Offline Capabilities in JavaScript} for more information.
|
6204 | *
|
6205 | * Note that `onDisconnect` operations are only triggered once. If you want an
|
6206 | * operation to occur each time a disconnect occurs, you'll need to re-establish
|
6207 | * the `onDisconnect` operations each time.
|
6208 | *
|
6209 | * @example
|
6210 | * ```javascript
|
6211 | * var ref = firebase.database().ref("users/ada/status");
|
6212 | * ref.onDisconnect().set("I disconnected!");
|
6213 | * ```
|
6214 | *
|
6215 | * @param value The value to be written to this location on
|
6216 | * disconnect (can be an object, array, string, number, boolean, or null).
|
6217 | * @param onComplete An optional callback function that
|
6218 | * will be called when synchronization to the Database server has completed.
|
6219 | * The callback will be passed a single parameter: null for success, or an
|
6220 | * `Error` object indicating a failure.
|
6221 | * @return Resolves when synchronization to the
|
6222 | * Database is complete.
|
6223 | */
|
6224 | set(value: any, onComplete?: (a: Error | null) => any): Promise<any>;
|
6225 | /**
|
6226 | * Ensures the data at this location is set to the specified value and priority
|
6227 | * when the client is disconnected (due to closing the browser, navigating to a
|
6228 | * new page, or network issues).
|
6229 | */
|
6230 | setWithPriority(
|
6231 | value: any,
|
6232 | priority: number | string | null,
|
6233 | onComplete?: (a: Error | null) => any
|
6234 | ): Promise<any>;
|
6235 | /**
|
6236 | * Writes multiple values at this location when the client is disconnected (due
|
6237 | * to closing the browser, navigating to a new page, or network issues).
|
6238 | *
|
6239 | * The `values` argument contains multiple property-value pairs that will be
|
6240 | * written to the Database together. Each child property can either be a simple
|
6241 | * property (for example, "name") or a relative path (for example, "name/first")
|
6242 | * from the current location to the data to update.
|
6243 | *
|
6244 | * As opposed to the `set()` method, `update()` can be use to selectively update
|
6245 | * only the referenced properties at the current location (instead of replacing
|
6246 | * all the child properties at the current location).
|
6247 | *
|
6248 | * See more examples using the connected version of
|
6249 | * {@link firebase.database.Reference.update `update()`}.
|
6250 | *
|
6251 | * @example
|
6252 | * ```javascript
|
6253 | * var ref = firebase.database().ref("users/ada");
|
6254 | * ref.update({
|
6255 | * onlineState: true,
|
6256 | * status: "I'm online."
|
6257 | * });
|
6258 | * ref.onDisconnect().update({
|
6259 | * onlineState: false,
|
6260 | * status: "I'm offline."
|
6261 | * });
|
6262 | * ```
|
6263 | *
|
6264 | * @param values Object containing multiple values.
|
6265 | * @param onComplete An optional callback function that will
|
6266 | * be called when synchronization to the server has completed. The
|
6267 | * callback will be passed a single parameter: null for success, or an Error
|
6268 | * object indicating a failure.
|
6269 | * @return Resolves when synchronization to the
|
6270 | * Database is complete.
|
6271 | */
|
6272 | update(values: Object, onComplete?: (a: Error | null) => any): Promise<any>;
|
6273 | }
|
6274 |
|
6275 | type EventType =
|
6276 | | 'value'
|
6277 | | 'child_added'
|
6278 | | 'child_changed'
|
6279 | | 'child_moved'
|
6280 | | 'child_removed';
|
6281 |
|
6282 | /**
|
6283 | * A `Query` sorts and filters the data at a Database location so only a subset
|
6284 | * of the child data is included. This can be used to order a collection of
|
6285 | * data by some attribute (for example, height of dinosaurs) as well as to
|
6286 | * restrict a large list of items (for example, chat messages) down to a number
|
6287 | * suitable for synchronizing to the client. Queries are created by chaining
|
6288 | * together one or more of the filter methods defined here.
|
6289 | *
|
6290 | * Just as with a `Reference`, you can receive data from a `Query` by using the
|
6291 | * `on()` method. You will only receive events and `DataSnapshot`s for the
|
6292 | * subset of the data that matches your query.
|
6293 | *
|
6294 | * Read our documentation on
|
6295 | * {@link
|
6296 | * https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data
|
6297 | * Sorting and filtering data} for more information.
|
6298 | */
|
6299 | interface Query {
|
6300 | /**
|
6301 | * Creates a `Query` with the specified ending point.
|
6302 | *
|
6303 | * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
|
6304 | * allows you to choose arbitrary starting and ending points for your queries.
|
6305 | *
|
6306 | * The ending point is inclusive, so children with exactly the specified value
|
6307 | * will be included in the query. The optional key argument can be used to
|
6308 | * further limit the range of the query. If it is specified, then children that
|
6309 | * have exactly the specified value must also have a key name less than or equal
|
6310 | * to the specified key.
|
6311 | *
|
6312 | * You can read more about `endAt()` in
|
6313 | * {@link
|
6314 | * https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
|
6315 | * Filtering data}.
|
6316 | *
|
6317 | * @example
|
6318 | * ```javascript
|
6319 | * // Find all dinosaurs whose names come before Pterodactyl lexicographically.
|
6320 | * // Include Pterodactyl in the result.
|
6321 | * var ref = firebase.database().ref("dinosaurs");
|
6322 | * ref.orderByKey().endAt("pterodactyl").on("child_added", function(snapshot) {
|
6323 | * console.log(snapshot.key);
|
6324 | * });
|
6325 | * ```
|
6326 | *
|
6327 | * @param value The value to end at. The argument
|
6328 | * type depends on which `orderBy*()` function was used in this query.
|
6329 | * Specify a value that matches the `orderBy*()` type. When used in
|
6330 | * combination with `orderByKey()`, the value must be a string.
|
6331 | * @param key The child key to end at, among the children with the
|
6332 | * previously specified priority. This argument is only allowed if ordering by
|
6333 | * child, value, or priority.
|
6334 | */
|
6335 | endAt(
|
6336 | value: number | string | boolean | null,
|
6337 | key?: string
|
6338 | ): firebase.database.Query;
|
6339 | /**
|
6340 | * Creates a `Query` with the specified ending point (exclusive).
|
6341 | *
|
6342 | * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
|
6343 | * allows you to choose arbitrary starting and ending points for your queries.
|
6344 | *
|
6345 | * The ending point is exclusive. If only a value is provided, children
|
6346 | * with a value less than the specified value will be included in the query.
|
6347 | * If a key is specified, then children must have a value lesss than or equal
|
6348 | * to the specified value and a a key name less than the specified key.
|
6349 | *
|
6350 | * @example
|
6351 | * ```javascript
|
6352 | * // Find all dinosaurs whose names come before Pterodactyl lexicographically.
|
6353 | * // Do not include Pterodactyl in the result.
|
6354 | * var ref = firebase.database().ref("dinosaurs");
|
6355 | * ref.orderByKey().endBefore("pterodactyl").on("child_added", function(snapshot) {
|
6356 | * console.log(snapshot.key);
|
6357 | * });
|
6358 | *
|
6359 | * @param value The value to end before. The argument
|
6360 | * type depends on which `orderBy*()` function was used in this query.
|
6361 | * Specify a value that matches the `orderBy*()` type. When used in
|
6362 | * combination with `orderByKey()`, the value must be a string.
|
6363 | * @param key The child key to end before, among the children with the
|
6364 | * previously specified priority. This argument is only allowed if ordering by
|
6365 | * child, value, or priority.
|
6366 | */
|
6367 | endBefore(
|
6368 | value: number | string | boolean | null,
|
6369 | key?: string
|
6370 | ): firebase.database.Query;
|
6371 | /**
|
6372 | * Creates a `Query` that includes children that match the specified value.
|
6373 | *
|
6374 | * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
|
6375 | * allows you to choose arbitrary starting and ending points for your queries.
|
6376 | *
|
6377 | * The optional key argument can be used to further limit the range of the
|
6378 | * query. If it is specified, then children that have exactly the specified
|
6379 | * value must also have exactly the specified key as their key name. This can be
|
6380 | * used to filter result sets with many matches for the same value.
|
6381 | *
|
6382 | * You can read more about `equalTo()` in
|
6383 | * {@link
|
6384 | * https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
|
6385 | * Filtering data}.
|
6386 | *
|
6387 | * @example
|
6388 | * ```javascript
|
6389 | * // Find all dinosaurs whose height is exactly 25 meters.
|
6390 | * var ref = firebase.database().ref("dinosaurs");
|
6391 | * ref.orderByChild("height").equalTo(25).on("child_added", function(snapshot) {
|
6392 | * console.log(snapshot.key);
|
6393 | * });
|
6394 | * ```
|
6395 | *
|
6396 | * @param value The value to match for. The
|
6397 | * argument type depends on which `orderBy*()` function was used in this
|
6398 | * query. Specify a value that matches the `orderBy*()` type. When used in
|
6399 | * combination with `orderByKey()`, the value must be a string.
|
6400 | * @param key The child key to start at, among the children with the
|
6401 | * previously specified priority. This argument is only allowed if ordering by
|
6402 | * child, value, or priority.
|
6403 | */
|
6404 | equalTo(
|
6405 | value: number | string | boolean | null,
|
6406 | key?: string
|
6407 | ): firebase.database.Query;
|
6408 | /**
|
6409 | * Returns whether or not the current and provided queries represent the same
|
6410 | * location, have the same query parameters, and are from the same instance of
|
6411 | * `firebase.app.App`.
|
6412 | *
|
6413 | * Two `Reference` objects are equivalent if they represent the same location
|
6414 | * and are from the same instance of `firebase.app.App`.
|
6415 | *
|
6416 | * Two `Query` objects are equivalent if they represent the same location, have
|
6417 | * the same query parameters, and are from the same instance of
|
6418 | * `firebase.app.App`. Equivalent queries share the same sort order, limits, and
|
6419 | * starting and ending points.
|
6420 | *
|
6421 | * @example
|
6422 | * ```javascript
|
6423 | * var rootRef = firebase.database.ref();
|
6424 | * var usersRef = rootRef.child("users");
|
6425 | *
|
6426 | * usersRef.isEqual(rootRef); // false
|
6427 | * usersRef.isEqual(rootRef.child("users")); // true
|
6428 | * usersRef.parent.isEqual(rootRef); // true
|
6429 | * ```
|
6430 | *
|
6431 | * @example
|
6432 | * ```javascript
|
6433 | * var rootRef = firebase.database.ref();
|
6434 | * var usersRef = rootRef.child("users");
|
6435 | * var usersQuery = usersRef.limitToLast(10);
|
6436 | *
|
6437 | * usersQuery.isEqual(usersRef); // false
|
6438 | * usersQuery.isEqual(usersRef.limitToLast(10)); // true
|
6439 | * usersQuery.isEqual(rootRef.limitToLast(10)); // false
|
6440 | * usersQuery.isEqual(usersRef.orderByKey().limitToLast(10)); // false
|
6441 | * ```
|
6442 | *
|
6443 | * @param other The query to compare against.
|
6444 | * @return Whether or not the current and provided queries are
|
6445 | * equivalent.
|
6446 | */
|
6447 | isEqual(other: firebase.database.Query | null): boolean;
|
6448 | /**
|
6449 | * Generates a new `Query` limited to the first specific number of children.
|
6450 | *
|
6451 | * The `limitToFirst()` method is used to set a maximum number of children to be
|
6452 | * synced for a given callback. If we set a limit of 100, we will initially only
|
6453 | * receive up to 100 `child_added` events. If we have fewer than 100 messages
|
6454 | * stored in our Database, a `child_added` event will fire for each message.
|
6455 | * However, if we have over 100 messages, we will only receive a `child_added`
|
6456 | * event for the first 100 ordered messages. As items change, we will receive
|
6457 | * `child_removed` events for each item that drops out of the active list so
|
6458 | * that the total number stays at 100.
|
6459 | *
|
6460 | * You can read more about `limitToFirst()` in
|
6461 | * {@link
|
6462 | * https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
|
6463 | * Filtering data}.
|
6464 | *
|
6465 | * @example
|
6466 | * ```javascript
|
6467 | * // Find the two shortest dinosaurs.
|
6468 | * var ref = firebase.database().ref("dinosaurs");
|
6469 | * ref.orderByChild("height").limitToFirst(2).on("child_added", function(snapshot) {
|
6470 | * // This will be called exactly two times (unless there are less than two
|
6471 | * // dinosaurs in the Database).
|
6472 | *
|
6473 | * // It will also get fired again if one of the first two dinosaurs is
|
6474 | * // removed from the data set, as a new dinosaur will now be the second
|
6475 | * // shortest.
|
6476 | * console.log(snapshot.key);
|
6477 | * });
|
6478 | * ```
|
6479 | *
|
6480 | * @param limit The maximum number of nodes to include in this query.
|
6481 | */
|
6482 | limitToFirst(limit: number): firebase.database.Query;
|
6483 | /**
|
6484 | * Generates a new `Query` object limited to the last specific number of
|
6485 | * children.
|
6486 | *
|
6487 | * The `limitToLast()` method is used to set a maximum number of children to be
|
6488 | * synced for a given callback. If we set a limit of 100, we will initially only
|
6489 | * receive up to 100 `child_added` events. If we have fewer than 100 messages
|
6490 | * stored in our Database, a `child_added` event will fire for each message.
|
6491 | * However, if we have over 100 messages, we will only receive a `child_added`
|
6492 | * event for the last 100 ordered messages. As items change, we will receive
|
6493 | * `child_removed` events for each item that drops out of the active list so
|
6494 | * that the total number stays at 100.
|
6495 | *
|
6496 | * You can read more about `limitToLast()` in
|
6497 | * {@link
|
6498 | * https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
|
6499 | * Filtering data}.
|
6500 | *
|
6501 | * @example
|
6502 | * ```javascript
|
6503 | * // Find the two heaviest dinosaurs.
|
6504 | * var ref = firebase.database().ref("dinosaurs");
|
6505 | * ref.orderByChild("weight").limitToLast(2).on("child_added", function(snapshot) {
|
6506 | * // This callback will be triggered exactly two times, unless there are
|
6507 | * // fewer than two dinosaurs stored in the Database. It will also get fired
|
6508 | * // for every new, heavier dinosaur that gets added to the data set.
|
6509 | * console.log(snapshot.key);
|
6510 | * });
|
6511 | * ```
|
6512 | *
|
6513 | * @param limit The maximum number of nodes to include in this query.
|
6514 | */
|
6515 | limitToLast(limit: number): firebase.database.Query;
|
6516 | /**
|
6517 | * Detaches a callback previously attached with `on()`.
|
6518 | *
|
6519 | * Detach a callback previously attached with `on()`. Note that if `on()` was
|
6520 | * called multiple times with the same eventType and callback, the callback
|
6521 | * will be called multiple times for each event, and `off()` must be called
|
6522 | * multiple times to remove the callback. Calling `off()` on a parent listener
|
6523 | * will not automatically remove listeners registered on child nodes, `off()`
|
6524 | * must also be called on any child listeners to remove the callback.
|
6525 | *
|
6526 | * If a callback is not specified, all callbacks for the specified eventType
|
6527 | * will be removed. Similarly, if no eventType is specified, all callbacks
|
6528 | * for the `Reference` will be removed.
|
6529 | *
|
6530 | * @example
|
6531 | * ```javascript
|
6532 | * var onValueChange = function(dataSnapshot) { ... };
|
6533 | * ref.on('value', onValueChange);
|
6534 | * ref.child('meta-data').on('child_added', onChildAdded);
|
6535 | * // Sometime later...
|
6536 | * ref.off('value', onValueChange);
|
6537 | *
|
6538 | * // You must also call off() for any child listeners on ref
|
6539 | * // to cancel those callbacks
|
6540 | * ref.child('meta-data').off('child_added', onValueAdded);
|
6541 | * ```
|
6542 | *
|
6543 | * @example
|
6544 | * ```javascript
|
6545 | * // Or you can save a line of code by using an inline function
|
6546 | * // and on()'s return value.
|
6547 | * var onValueChange = ref.on('value', function(dataSnapshot) { ... });
|
6548 | * // Sometime later...
|
6549 | * ref.off('value', onValueChange);
|
6550 | * ```
|
6551 | *
|
6552 | * @param eventType One of the following strings: "value",
|
6553 | * "child_added", "child_changed", "child_removed", or "child_moved." If
|
6554 | * omitted, all callbacks for the `Reference` will be removed.
|
6555 | * @param callback The callback function that was passed to `on()` or
|
6556 | * `undefined` to remove all callbacks.
|
6557 | * @param context The context that was passed to `on()`.
|
6558 | */
|
6559 | off(
|
6560 | eventType?: EventType,
|
6561 | callback?: (a: firebase.database.DataSnapshot, b?: string | null) => any,
|
6562 | context?: Object | null
|
6563 | ): void;
|
6564 |
|
6565 | /**
|
6566 | * Gets the most up-to-date result for this query.
|
6567 | *
|
6568 | * @return A promise which resolves to the resulting DataSnapshot if
|
6569 | * a value is available, or rejects if the client is unable to return
|
6570 | * a value (e.g., if the server is unreachable and there is nothing
|
6571 | * cached).
|
6572 | */
|
6573 | get(): Promise<DataSnapshot>;
|
6574 |
|
6575 | /**
|
6576 | * Listens for data changes at a particular location.
|
6577 | *
|
6578 | * This is the primary way to read data from a Database. Your callback
|
6579 | * will be triggered for the initial data and again whenever the data changes.
|
6580 | * Use `off( )` to stop receiving updates. See
|
6581 | * {@link https://firebase.google.com/docs/database/web/retrieve-data
|
6582 | * Retrieve Data on the Web}
|
6583 | * for more details.
|
6584 | *
|
6585 | * <h4>value event</h4>
|
6586 | *
|
6587 | * This event will trigger once with the initial data stored at this location,
|
6588 | * and then trigger again each time the data changes. The `DataSnapshot` passed
|
6589 | * to the callback will be for the location at which `on()` was called. It
|
6590 | * won't trigger until the entire contents has been synchronized. If the
|
6591 | * location has no data, it will be triggered with an empty `DataSnapshot`
|
6592 | * (`val()` will return `null`).
|
6593 | *
|
6594 | * <h4>child_added event</h4>
|
6595 | *
|
6596 | * This event will be triggered once for each initial child at this location,
|
6597 | * and it will be triggered again every time a new child is added. The
|
6598 | * `DataSnapshot` passed into the callback will reflect the data for the
|
6599 | * relevant child. For ordering purposes, it is passed a second argument which
|
6600 | * is a string containing the key of the previous sibling child by sort order,
|
6601 | * or `null` if it is the first child.
|
6602 | *
|
6603 | * <h4>child_removed event</h4>
|
6604 | *
|
6605 | * This event will be triggered once every time a child is removed. The
|
6606 | * `DataSnapshot` passed into the callback will be the old data for the child
|
6607 | * that was removed. A child will get removed when either:
|
6608 | *
|
6609 | * - a client explicitly calls `remove()` on that child or one of its ancestors
|
6610 | * - a client calls `set(null)` on that child or one of its ancestors
|
6611 | * - that child has all of its children removed
|
6612 | * - there is a query in effect which now filters out the child (because it's
|
6613 | * sort order changed or the max limit was hit)
|
6614 | *
|
6615 | * <h4>child_changed event</h4>
|
6616 | *
|
6617 | * This event will be triggered when the data stored in a child (or any of its
|
6618 | * descendants) changes. Note that a single `child_changed` event may represent
|
6619 | * multiple changes to the child. The `DataSnapshot` passed to the callback will
|
6620 | * contain the new child contents. For ordering purposes, the callback is also
|
6621 | * passed a second argument which is a string containing the key of the previous
|
6622 | * sibling child by sort order, or `null` if it is the first child.
|
6623 | *
|
6624 | * <h4>child_moved event</h4>
|
6625 | *
|
6626 | * This event will be triggered when a child's sort order changes such that its
|
6627 | * position relative to its siblings changes. The `DataSnapshot` passed to the
|
6628 | * callback will be for the data of the child that has moved. It is also passed
|
6629 | * a second argument which is a string containing the key of the previous
|
6630 | * sibling child by sort order, or `null` if it is the first child.
|
6631 | *
|
6632 | * @example **Handle a new value:**
|
6633 | * ```javascript
|
6634 | * ref.on('value', function(dataSnapshot) {
|
6635 | * ...
|
6636 | * });
|
6637 | * ```
|
6638 | *
|
6639 | * @example **Handle a new child:**
|
6640 | * ```javascript
|
6641 | * ref.on('child_added', function(childSnapshot, prevChildKey) {
|
6642 | * ...
|
6643 | * });
|
6644 | * ```
|
6645 | *
|
6646 | * @example **Handle child removal:**
|
6647 | * ```javascript
|
6648 | * ref.on('child_removed', function(oldChildSnapshot) {
|
6649 | * ...
|
6650 | * });
|
6651 | * ```
|
6652 | *
|
6653 | * @example **Handle child data changes:**
|
6654 | * ```javascript
|
6655 | * ref.on('child_changed', function(childSnapshot, prevChildKey) {
|
6656 | * ...
|
6657 | * });
|
6658 | * ```
|
6659 | *
|
6660 | * @example **Handle child ordering changes:**
|
6661 | * ```javascript
|
6662 | * ref.on('child_moved', function(childSnapshot, prevChildKey) {
|
6663 | * ...
|
6664 | * });
|
6665 | * ```
|
6666 | *
|
6667 | * @param eventType One of the following strings: "value",
|
6668 | * "child_added", "child_changed", "child_removed", or "child_moved."
|
6669 | * @param callback A
|
6670 | * callback that fires when the specified event occurs. The callback will be
|
6671 | * passed a DataSnapshot. For ordering purposes, "child_added",
|
6672 | * "child_changed", and "child_moved" will also be passed a string containing
|
6673 | * the key of the previous child, by sort order, or `null` if it is the
|
6674 | * first child.
|
6675 | * @param cancelCallbackOrContext An optional
|
6676 | * callback that will be notified if your event subscription is ever canceled
|
6677 | * because your client does not have permission to read this data (or it had
|
6678 | * permission but has now lost it). This callback will be passed an `Error`
|
6679 | * object indicating why the failure occurred.
|
6680 | * @param context If provided, this object will be used as `this`
|
6681 | * when calling your callback(s).
|
6682 | * @return The provided
|
6683 | * callback function is returned unmodified. This is just for convenience if
|
6684 | * you want to pass an inline function to `on()` but store the callback
|
6685 | * function for later passing to `off()`.
|
6686 | */
|
6687 | on(
|
6688 | eventType: EventType,
|
6689 | callback: (a: firebase.database.DataSnapshot, b?: string | null) => any,
|
6690 | cancelCallbackOrContext?: ((a: Error) => any) | Object | null,
|
6691 | context?: Object | null
|
6692 | ): (a: firebase.database.DataSnapshot | null, b?: string | null) => any;
|
6693 |
|
6694 | /**
|
6695 | * Listens for exactly one event of the specified event type, and then stops
|
6696 | * listening.
|
6697 | *
|
6698 | * This is equivalent to calling {@link firebase.database.Query.on `on()`}, and
|
6699 | * then calling {@link firebase.database.Query.off `off()`} inside the callback
|
6700 | * function. See {@link firebase.database.Query.on `on()`} for details on the
|
6701 | * event types.
|
6702 | *
|
6703 | * @example
|
6704 | * ```javascript
|
6705 | * // Basic usage of .once() to read the data located at ref.
|
6706 | * ref.once('value')
|
6707 | * .then(function(dataSnapshot) {
|
6708 | * // handle read data.
|
6709 | * });
|
6710 | * ```
|
6711 | *
|
6712 | * @param eventType One of the following strings: "value",
|
6713 | * "child_added", "child_changed", "child_removed", or "child_moved."
|
6714 | * @param successCallback A
|
6715 | * callback that fires when the specified event occurs. The callback will be
|
6716 | * passed a DataSnapshot. For ordering purposes, "child_added",
|
6717 | * "child_changed", and "child_moved" will also be passed a string containing
|
6718 | * the key of the previous child by sort order, or `null` if it is the
|
6719 | * first child.
|
6720 | * @param failureCallbackOrContext An optional
|
6721 | * callback that will be notified if your client does not have permission to
|
6722 | * read the data. This callback will be passed an `Error` object indicating
|
6723 | * why the failure occurred.
|
6724 | * @param context If provided, this object will be used as `this`
|
6725 | * when calling your callback(s).
|
6726 | */
|
6727 | once(
|
6728 | eventType: EventType,
|
6729 | successCallback?: (
|
6730 | a: firebase.database.DataSnapshot,
|
6731 | b?: string | null
|
6732 | ) => any,
|
6733 | failureCallbackOrContext?: ((a: Error) => void) | Object | null,
|
6734 | context?: Object | null
|
6735 | ): Promise<firebase.database.DataSnapshot>;
|
6736 | /**
|
6737 | * Generates a new `Query` object ordered by the specified child key.
|
6738 | *
|
6739 | * Queries can only order by one key at a time. Calling `orderByChild()`
|
6740 | * multiple times on the same query is an error.
|
6741 | *
|
6742 | * Firebase queries allow you to order your data by any child key on the fly.
|
6743 | * However, if you know in advance what your indexes will be, you can define
|
6744 | * them via the .indexOn rule in your Security Rules for better performance. See
|
6745 | * the {@link https://firebase.google.com/docs/database/security/indexing-data
|
6746 | * .indexOn} rule for more information.
|
6747 | *
|
6748 | * You can read more about `orderByChild()` in
|
6749 | * {@link
|
6750 | * https://firebase.google.com/docs/database/web/lists-of-data#sort_data
|
6751 | * Sort data}.
|
6752 | *
|
6753 | * @example
|
6754 | * ```javascript
|
6755 | * var ref = firebase.database().ref("dinosaurs");
|
6756 | * ref.orderByChild("height").on("child_added", function(snapshot) {
|
6757 | * console.log(snapshot.key + " was " + snapshot.val().height + " m tall");
|
6758 | * });
|
6759 | * ```
|
6760 | */
|
6761 | orderByChild(path: string): firebase.database.Query;
|
6762 | /**
|
6763 | * Generates a new `Query` object ordered by key.
|
6764 | *
|
6765 | * Sorts the results of a query by their (ascending) key values.
|
6766 | *
|
6767 | * You can read more about `orderByKey()` in
|
6768 | * {@link
|
6769 | * https://firebase.google.com/docs/database/web/lists-of-data#sort_data
|
6770 | * Sort data}.
|
6771 | *
|
6772 | * @example
|
6773 | * ```javascript
|
6774 | * var ref = firebase.database().ref("dinosaurs");
|
6775 | * ref.orderByKey().on("child_added", function(snapshot) {
|
6776 | * console.log(snapshot.key);
|
6777 | * });
|
6778 | * ```
|
6779 | */
|
6780 | orderByKey(): firebase.database.Query;
|
6781 | /**
|
6782 | * Generates a new `Query` object ordered by priority.
|
6783 | *
|
6784 | * Applications need not use priority but can order collections by
|
6785 | * ordinary properties (see
|
6786 | * {@link
|
6787 | * https://firebase.google.com/docs/database/web/lists-of-data#sort_data
|
6788 | * Sort data} for alternatives to priority.
|
6789 | */
|
6790 | orderByPriority(): firebase.database.Query;
|
6791 | /**
|
6792 | * Generates a new `Query` object ordered by value.
|
6793 | *
|
6794 | * If the children of a query are all scalar values (string, number, or
|
6795 | * boolean), you can order the results by their (ascending) values.
|
6796 | *
|
6797 | * You can read more about `orderByValue()` in
|
6798 | * {@link
|
6799 | * https://firebase.google.com/docs/database/web/lists-of-data#sort_data
|
6800 | * Sort data}.
|
6801 | *
|
6802 | * @example
|
6803 | * ```javascript
|
6804 | * var scoresRef = firebase.database().ref("scores");
|
6805 | * scoresRef.orderByValue().limitToLast(3).on("value", function(snapshot) {
|
6806 | * snapshot.forEach(function(data) {
|
6807 | * console.log("The " + data.key + " score is " + data.val());
|
6808 | * });
|
6809 | * });
|
6810 | * ```
|
6811 | */
|
6812 | orderByValue(): firebase.database.Query;
|
6813 | /**
|
6814 | * Returns a `Reference` to the `Query`'s location.
|
6815 | */
|
6816 | ref: firebase.database.Reference;
|
6817 | /**
|
6818 | * Creates a `Query` with the specified starting point.
|
6819 | *
|
6820 | * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
|
6821 | * allows you to choose arbitrary starting and ending points for your queries.
|
6822 | *
|
6823 | * The starting point is inclusive, so children with exactly the specified value
|
6824 | * will be included in the query. The optional key argument can be used to
|
6825 | * further limit the range of the query. If it is specified, then children that
|
6826 | * have exactly the specified value must also have a key name greater than or
|
6827 | * equal to the specified key.
|
6828 | *
|
6829 | * You can read more about `startAt()` in
|
6830 | * {@link
|
6831 | * https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
|
6832 | * Filtering data}.
|
6833 | *
|
6834 | * @example
|
6835 | * ```javascript
|
6836 | * // Find all dinosaurs that are at least three meters tall.
|
6837 | * var ref = firebase.database().ref("dinosaurs");
|
6838 | * ref.orderByChild("height").startAt(3).on("child_added", function(snapshot) {
|
6839 | * console.log(snapshot.key)
|
6840 | * });
|
6841 | * ```
|
6842 | *
|
6843 | * @param value The value to start at. The argument
|
6844 | * type depends on which `orderBy*()` function was used in this query.
|
6845 | * Specify a value that matches the `orderBy*()` type. When used in
|
6846 | * combination with `orderByKey()`, the value must be a string.
|
6847 | * @param key The child key to start at. This argument is only allowed
|
6848 | * if ordering by child, value, or priority.
|
6849 | */
|
6850 | startAt(
|
6851 | value: number | string | boolean | null,
|
6852 | key?: string
|
6853 | ): firebase.database.Query;
|
6854 | /**
|
6855 | * Creates a `Query` with the specified starting point (exclusive).
|
6856 | *
|
6857 | * Using `startAt()`, `startAfter()`, `endBefore()`, `endAt()` and `equalTo()`
|
6858 | * allows you to choose arbitrary starting and ending points for your queries.
|
6859 | *
|
6860 | * The starting point is exclusive. If only a value is provided, children
|
6861 | * with a value greater than the specified value will be included in the query.
|
6862 | * If a key is specified, then children must have a value greater than or equal
|
6863 | * to the specified value and a a key name greater than the specified key.
|
6864 | *
|
6865 | * @example
|
6866 | * ```javascript
|
6867 | * // Find all dinosaurs that are more than three meters tall.
|
6868 | * var ref = firebase.database().ref("dinosaurs");
|
6869 | * ref.orderByChild("height").startAfter(3).on("child_added", function(snapshot) {
|
6870 | * console.log(snapshot.key)
|
6871 | * });
|
6872 | * ```
|
6873 | *
|
6874 | * @param value The value to start after. The argument
|
6875 | * type depends on which `orderBy*()` function was used in this query.
|
6876 | * Specify a value that matches the `orderBy*()` type. When used in
|
6877 | * combination with `orderByKey()`, the value must be a string.
|
6878 | * @param key The child key to start after. This argument is only allowed
|
6879 | * if ordering by child, value, or priority.
|
6880 | */
|
6881 | startAfter(
|
6882 | value: number | string | boolean | null,
|
6883 | key?: string
|
6884 | ): firebase.database.Query;
|
6885 | /**
|
6886 | * Returns a JSON-serializable representation of this object.
|
6887 | *
|
6888 | * @return A JSON-serializable representation of this object.
|
6889 | */
|
6890 | toJSON(): Object;
|
6891 | /**
|
6892 | * Gets the absolute URL for this location.
|
6893 | *
|
6894 | * The `toString()` method returns a URL that is ready to be put into a browser,
|
6895 | * curl command, or a `firebase.database().refFromURL()` call. Since all of
|
6896 | * those expect the URL to be url-encoded, `toString()` returns an encoded URL.
|
6897 | *
|
6898 | * Append '.json' to the returned URL when typed into a browser to download
|
6899 | * JSON-formatted data. If the location is secured (that is, not publicly
|
6900 | * readable), you will get a permission-denied error.
|
6901 | *
|
6902 | * @example
|
6903 | * ```javascript
|
6904 | * // Calling toString() on a root Firebase reference returns the URL where its
|
6905 | * // data is stored within the Database:
|
6906 | * var rootRef = firebase.database().ref();
|
6907 | * var rootUrl = rootRef.toString();
|
6908 | * // rootUrl === "https://sample-app.firebaseio.com/".
|
6909 | *
|
6910 | * // Calling toString() at a deeper Firebase reference returns the URL of that
|
6911 | * // deep path within the Database:
|
6912 | * var adaRef = rootRef.child('users/ada');
|
6913 | * var adaURL = adaRef.toString();
|
6914 | * // adaURL === "https://sample-app.firebaseio.com/users/ada".
|
6915 | * ```
|
6916 | *
|
6917 | * @return The absolute URL for this location.
|
6918 | */
|
6919 | toString(): string;
|
6920 | }
|
6921 |
|
6922 | /**
|
6923 | * A `Reference` represents a specific location in your Database and can be used
|
6924 | * for reading or writing data to that Database location.
|
6925 | *
|
6926 | * You can reference the root or child location in your Database by calling
|
6927 | * `firebase.database().ref()` or `firebase.database().ref("child/path")`.
|
6928 | *
|
6929 | * Writing is done with the `set()` method and reading can be done with the
|
6930 | * `on()` method. See
|
6931 | * {@link
|
6932 | * https://firebase.google.com/docs/database/web/read-and-write
|
6933 | * Read and Write Data on the Web}
|
6934 | */
|
6935 | interface Reference extends firebase.database.Query {
|
6936 | /**
|
6937 | * Gets a `Reference` for the location at the specified relative path.
|
6938 | *
|
6939 | * The relative path can either be a simple child name (for example, "ada") or
|
6940 | * a deeper slash-separated path (for example, "ada/name/first").
|
6941 | *
|
6942 | * @example
|
6943 | * ```javascript
|
6944 | * var usersRef = firebase.database().ref('users');
|
6945 | * var adaRef = usersRef.child('ada');
|
6946 | * var adaFirstNameRef = adaRef.child('name/first');
|
6947 | * var path = adaFirstNameRef.toString();
|
6948 | * // path is now 'https://sample-app.firebaseio.com/users/ada/name/first'
|
6949 | * ```
|
6950 | *
|
6951 | * @param path A relative path from this location to the desired child
|
6952 | * location.
|
6953 | * @return The specified child location.
|
6954 | */
|
6955 | child(path: string): firebase.database.Reference;
|
6956 | /**
|
6957 | * The last part of the `Reference`'s path.
|
6958 | *
|
6959 | * For example, `"ada"` is the key for
|
6960 | * `https://<DATABASE_NAME>.firebaseio.com/users/ada`.
|
6961 | *
|
6962 | * The key of a root `Reference` is `null`.
|
6963 | *
|
6964 | * @example
|
6965 | * ```javascript
|
6966 | * // The key of a root reference is null
|
6967 | * var rootRef = firebase.database().ref();
|
6968 | * var key = rootRef.key; // key === null
|
6969 | * ```
|
6970 | *
|
6971 | * @example
|
6972 | * ```javascript
|
6973 | * // The key of any non-root reference is the last token in the path
|
6974 | * var adaRef = firebase.database().ref("users/ada");
|
6975 | * var key = adaRef.key; // key === "ada"
|
6976 | * key = adaRef.child("name/last").key; // key === "last"
|
6977 | * ```
|
6978 | */
|
6979 | key: string | null;
|
6980 | /**
|
6981 | * Returns an `OnDisconnect` object - see
|
6982 | * {@link
|
6983 | * https://firebase.google.com/docs/database/web/offline-capabilities
|
6984 | * Enabling Offline Capabilities in JavaScript} for more information on how
|
6985 | * to use it.
|
6986 | */
|
6987 | onDisconnect(): firebase.database.OnDisconnect;
|
6988 | /**
|
6989 | * The parent location of a `Reference`.
|
6990 | *
|
6991 | * The parent of a root `Reference` is `null`.
|
6992 | *
|
6993 | * @example
|
6994 | * ```javascript
|
6995 | * // The parent of a root reference is null
|
6996 | * var rootRef = firebase.database().ref();
|
6997 | * parent = rootRef.parent; // parent === null
|
6998 | * ```
|
6999 | *
|
7000 | * @example
|
7001 | * ```javascript
|
7002 | * // The parent of any non-root reference is the parent location
|
7003 | * var usersRef = firebase.database().ref("users");
|
7004 | * var adaRef = firebase.database().ref("users/ada");
|
7005 | * // usersRef and adaRef.parent represent the same location
|
7006 | * ```
|
7007 | */
|
7008 | parent: firebase.database.Reference | null;
|
7009 | /**
|
7010 | * Generates a new child location using a unique key and returns its
|
7011 | * `Reference`.
|
7012 | *
|
7013 | * This is the most common pattern for adding data to a collection of items.
|
7014 | *
|
7015 | * If you provide a value to `push()`, the value is written to the
|
7016 | * generated location. If you don't pass a value, nothing is written to the
|
7017 | * database and the child remains empty (but you can use the `Reference`
|
7018 | * elsewhere).
|
7019 | *
|
7020 | * The unique keys generated by `push()` are ordered by the current time, so the
|
7021 | * resulting list of items is chronologically sorted. The keys are also
|
7022 | * designed to be unguessable (they contain 72 random bits of entropy).
|
7023 | *
|
7024 | *
|
7025 | * See
|
7026 | * {@link
|
7027 | * https://firebase.google.com/docs/database/web/lists-of-data#append_to_a_list_of_data
|
7028 | * Append to a list of data}
|
7029 | * </br>See
|
7030 | * {@link
|
7031 | * https://firebase.googleblog.com/2015/02/the-2120-ways-to-ensure-unique_68.html
|
7032 | * The 2^120 Ways to Ensure Unique Identifiers}
|
7033 | *
|
7034 | * @example
|
7035 | * ```javascript
|
7036 | * var messageListRef = firebase.database().ref('message_list');
|
7037 | * var newMessageRef = messageListRef.push();
|
7038 | * newMessageRef.set({
|
7039 | * 'user_id': 'ada',
|
7040 | * 'text': 'The Analytical Engine weaves algebraical patterns just as the Jacquard loom weaves flowers and leaves.'
|
7041 | * });
|
7042 | * // We've appended a new message to the message_list location.
|
7043 | * var path = newMessageRef.toString();
|
7044 | * // path will be something like
|
7045 | * // 'https://sample-app.firebaseio.com/message_list/-IKo28nwJLH0Nc5XeFmj'
|
7046 | * ```
|
7047 | *
|
7048 | * @param value Optional value to be written at the generated location.
|
7049 | * @param onComplete Callback called when write to server is
|
7050 | * complete.
|
7051 | * @return Combined `Promise` and `Reference`; resolves when write is complete, but can be
|
7052 | * used immediately as the `Reference` to the child location.
|
7053 | */
|
7054 | push(
|
7055 | value?: any,
|
7056 | onComplete?: (a: Error | null) => any
|
7057 | ): firebase.database.ThenableReference;
|
7058 | /**
|
7059 | * Removes the data at this Database location.
|
7060 | *
|
7061 | * Any data at child locations will also be deleted.
|
7062 | *
|
7063 | * The effect of the remove will be visible immediately and the corresponding
|
7064 | * event 'value' will be triggered. Synchronization of the remove to the
|
7065 | * Firebase servers will also be started, and the returned Promise will resolve
|
7066 | * when complete. If provided, the onComplete callback will be called
|
7067 | * asynchronously after synchronization has finished.
|
7068 | *
|
7069 | * @example
|
7070 | * ```javascript
|
7071 | * var adaRef = firebase.database().ref('users/ada');
|
7072 | * adaRef.remove()
|
7073 | * .then(function() {
|
7074 | * console.log("Remove succeeded.")
|
7075 | * })
|
7076 | * .catch(function(error) {
|
7077 | * console.log("Remove failed: " + error.message)
|
7078 | * });
|
7079 | * ```
|
7080 | *
|
7081 | * @param onComplete Callback called when write to server is
|
7082 | * complete.
|
7083 | * @return Resolves when remove on server is complete.
|
7084 | */
|
7085 | remove(onComplete?: (a: Error | null) => any): Promise<any>;
|
7086 | /**
|
7087 | * The root `Reference` of the Database.
|
7088 | *
|
7089 | * @example
|
7090 | * ```javascript
|
7091 | * // The root of a root reference is itself
|
7092 | * var rootRef = firebase.database().ref();
|
7093 | * // rootRef and rootRef.root represent the same location
|
7094 | * ```
|
7095 | *
|
7096 | * @example
|
7097 | * ```javascript
|
7098 | * // The root of any non-root reference is the root location
|
7099 | * var adaRef = firebase.database().ref("users/ada");
|
7100 | * // rootRef and adaRef.root represent the same location
|
7101 | * ```
|
7102 | */
|
7103 | root: firebase.database.Reference;
|
7104 | /**
|
7105 | * Writes data to this Database location.
|
7106 | *
|
7107 | * This will overwrite any data at this location and all child locations.
|
7108 | *
|
7109 | * The effect of the write will be visible immediately, and the corresponding
|
7110 | * events ("value", "child_added", etc.) will be triggered. Synchronization of
|
7111 | * the data to the Firebase servers will also be started, and the returned
|
7112 | * Promise will resolve when complete. If provided, the `onComplete` callback
|
7113 | * will be called asynchronously after synchronization has finished.
|
7114 | *
|
7115 | * Passing `null` for the new value is equivalent to calling `remove()`; namely,
|
7116 | * all data at this location and all child locations will be deleted.
|
7117 | *
|
7118 | * `set()` will remove any priority stored at this location, so if priority is
|
7119 | * meant to be preserved, you need to use `setWithPriority()` instead.
|
7120 | *
|
7121 | * Note that modifying data with `set()` will cancel any pending transactions
|
7122 | * at that location, so extreme care should be taken if mixing `set()` and
|
7123 | * `transaction()` to modify the same data.
|
7124 | *
|
7125 | * A single `set()` will generate a single "value" event at the location where
|
7126 | * the `set()` was performed.
|
7127 | *
|
7128 | * @example
|
7129 | * ```javascript
|
7130 | * var adaNameRef = firebase.database().ref('users/ada/name');
|
7131 | * adaNameRef.child('first').set('Ada');
|
7132 | * adaNameRef.child('last').set('Lovelace');
|
7133 | * // We've written 'Ada' to the Database location storing Ada's first name,
|
7134 | * // and 'Lovelace' to the location storing her last name.
|
7135 | * ```
|
7136 | *
|
7137 | * @example
|
7138 | * ```javascript
|
7139 | * adaNameRef.set({ first: 'Ada', last: 'Lovelace' });
|
7140 | * // Exact same effect as the previous example, except we've written
|
7141 | * // Ada's first and last name simultaneously.
|
7142 | * ```
|
7143 | *
|
7144 | * @example
|
7145 | * ```javascript
|
7146 | * adaNameRef.set({ first: 'Ada', last: 'Lovelace' })
|
7147 | * .then(function() {
|
7148 | * console.log('Synchronization succeeded');
|
7149 | * })
|
7150 | * .catch(function(error) {
|
7151 | * console.log('Synchronization failed');
|
7152 | * });
|
7153 | * // Same as the previous example, except we will also log a message
|
7154 | * // when the data has finished synchronizing.
|
7155 | * ```
|
7156 | *
|
7157 | * @param value The value to be written (string, number, boolean, object,
|
7158 | * array, or null).
|
7159 | * @param onComplete Callback called when write to server is
|
7160 | * complete.
|
7161 | * @return Resolves when write to server is complete.
|
7162 | */
|
7163 | set(value: any, onComplete?: (a: Error | null) => any): Promise<any>;
|
7164 | /**
|
7165 | * Sets a priority for the data at this Database location.
|
7166 | *
|
7167 | * Applications need not use priority but can order collections by
|
7168 | * ordinary properties (see
|
7169 | * {@link
|
7170 | * https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data
|
7171 | * Sorting and filtering data}).
|
7172 | */
|
7173 | setPriority(
|
7174 | priority: string | number | null,
|
7175 | onComplete: (a: Error | null) => any
|
7176 | ): Promise<any>;
|
7177 | /**
|
7178 | * Writes data the Database location. Like `set()` but also specifies the
|
7179 | * priority for that data.
|
7180 | *
|
7181 | * Applications need not use priority but can order collections by
|
7182 | * ordinary properties (see
|
7183 | * {@link
|
7184 | * https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data
|
7185 | * Sorting and filtering data}).
|
7186 | */
|
7187 | setWithPriority(
|
7188 | newVal: any,
|
7189 | newPriority: string | number | null,
|
7190 | onComplete?: (a: Error | null) => any
|
7191 | ): Promise<any>;
|
7192 | /**
|
7193 | * Atomically modifies the data at this location.
|
7194 | *
|
7195 | * Atomically modify the data at this location. Unlike a normal `set()`, which
|
7196 | * just overwrites the data regardless of its previous value, `transaction()` is
|
7197 | * used to modify the existing value to a new value, ensuring there are no
|
7198 | * conflicts with other clients writing to the same location at the same time.
|
7199 | *
|
7200 | * To accomplish this, you pass `transaction()` an update function which is used
|
7201 | * to transform the current value into a new value. If another client writes to
|
7202 | * the location before your new value is successfully written, your update
|
7203 | * function will be called again with the new current value, and the write will
|
7204 | * be retried. This will happen repeatedly until your write succeeds without
|
7205 | * conflict or you abort the transaction by not returning a value from your
|
7206 | * update function.
|
7207 | *
|
7208 | * Note: Modifying data with `set()` will cancel any pending transactions at
|
7209 | * that location, so extreme care should be taken if mixing `set()` and
|
7210 | * `transaction()` to update the same data.
|
7211 | *
|
7212 | * Note: When using transactions with Security and Firebase Rules in place, be
|
7213 | * aware that a client needs `.read` access in addition to `.write` access in
|
7214 | * order to perform a transaction. This is because the client-side nature of
|
7215 | * transactions requires the client to read the data in order to transactionally
|
7216 | * update it.
|
7217 | *
|
7218 | * @example
|
7219 | * ```javascript
|
7220 | * // Increment Ada's rank by 1.
|
7221 | * var adaRankRef = firebase.database().ref('users/ada/rank');
|
7222 | * adaRankRef.transaction(function(currentRank) {
|
7223 | * // If users/ada/rank has never been set, currentRank will be `null`.
|
7224 | * return currentRank + 1;
|
7225 | * });
|
7226 | * ```
|
7227 | *
|
7228 | * @example
|
7229 | * ```javascript
|
7230 | * // Try to create a user for ada, but only if the user id 'ada' isn't
|
7231 | * // already taken
|
7232 | * var adaRef = firebase.database().ref('users/ada');
|
7233 | * adaRef.transaction(function(currentData) {
|
7234 | * if (currentData === null) {
|
7235 | * return { name: { first: 'Ada', last: 'Lovelace' } };
|
7236 | * } else {
|
7237 | * console.log('User ada already exists.');
|
7238 | * return; // Abort the transaction.
|
7239 | * }
|
7240 | * }, function(error, committed, snapshot) {
|
7241 | * if (error) {
|
7242 | * console.log('Transaction failed abnormally!', error);
|
7243 | * } else if (!committed) {
|
7244 | * console.log('We aborted the transaction (because ada already exists).');
|
7245 | * } else {
|
7246 | * console.log('User ada added!');
|
7247 | * }
|
7248 | * console.log("Ada's data: ", snapshot.val());
|
7249 | * });
|
7250 | * ```
|
7251 | *
|
7252 | * @param transactionUpdate A developer-supplied function which
|
7253 | * will be passed the current data stored at this location (as a JavaScript
|
7254 | * object). The function should return the new value it would like written (as
|
7255 | * a JavaScript object). If `undefined` is returned (i.e. you return with no
|
7256 | * arguments) the transaction will be aborted and the data at this location
|
7257 | * will not be modified.
|
7258 | * @param onComplete A callback
|
7259 | * function that will be called when the transaction completes. The callback
|
7260 | * is passed three arguments: a possibly-null `Error`, a `boolean` indicating
|
7261 | * whether the transaction was committed, and a `DataSnapshot` indicating the
|
7262 | * final result. If the transaction failed abnormally, the first argument will
|
7263 | * be an `Error` object indicating the failure cause. If the transaction
|
7264 | * finished normally, but no data was committed because no data was returned
|
7265 | * from `transactionUpdate`, then second argument will be false. If the
|
7266 | * transaction completed and committed data to Firebase, the second argument
|
7267 | * will be true. Regardless, the third argument will be a `DataSnapshot`
|
7268 | * containing the resulting data in this location.
|
7269 | * @param applyLocally By default, events are raised each time the
|
7270 | * transaction update function runs. So if it is run multiple times, you may
|
7271 | * see intermediate states. You can set this to false to suppress these
|
7272 | * intermediate states and instead wait until the transaction has completed
|
7273 | * before events are raised.
|
7274 | * @return Returns a Promise that can optionally be used instead of the onComplete
|
7275 | * callback to handle success and failure.
|
7276 | */
|
7277 | transaction(
|
7278 | transactionUpdate: (a: any) => any,
|
7279 | onComplete?: (
|
7280 | a: Error | null,
|
7281 | b: boolean,
|
7282 | c: firebase.database.DataSnapshot | null
|
7283 | ) => any,
|
7284 | applyLocally?: boolean
|
7285 | ): Promise<any>;
|
7286 | /**
|
7287 | * Writes multiple values to the Database at once.
|
7288 | *
|
7289 | * The `values` argument contains multiple property-value pairs that will be
|
7290 | * written to the Database together. Each child property can either be a simple
|
7291 | * property (for example, "name") or a relative path (for example,
|
7292 | * "name/first") from the current location to the data to update.
|
7293 | *
|
7294 | * As opposed to the `set()` method, `update()` can be use to selectively update
|
7295 | * only the referenced properties at the current location (instead of replacing
|
7296 | * all the child properties at the current location).
|
7297 | *
|
7298 | * The effect of the write will be visible immediately, and the corresponding
|
7299 | * events ('value', 'child_added', etc.) will be triggered. Synchronization of
|
7300 | * the data to the Firebase servers will also be started, and the returned
|
7301 | * Promise will resolve when complete. If provided, the `onComplete` callback
|
7302 | * will be called asynchronously after synchronization has finished.
|
7303 | *
|
7304 | * A single `update()` will generate a single "value" event at the location
|
7305 | * where the `update()` was performed, regardless of how many children were
|
7306 | * modified.
|
7307 | *
|
7308 | * Note that modifying data with `update()` will cancel any pending
|
7309 | * transactions at that location, so extreme care should be taken if mixing
|
7310 | * `update()` and `transaction()` to modify the same data.
|
7311 | *
|
7312 | * Passing `null` to `update()` will remove the data at this location.
|
7313 | *
|
7314 | * See
|
7315 | * {@link
|
7316 | * https://firebase.googleblog.com/2015/09/introducing-multi-location-updates-and_86.html
|
7317 | * Introducing multi-location updates and more}.
|
7318 | *
|
7319 | * @example
|
7320 | * ```javascript
|
7321 | * var adaNameRef = firebase.database().ref('users/ada/name');
|
7322 | * // Modify the 'first' and 'last' properties, but leave other data at
|
7323 | * // adaNameRef unchanged.
|
7324 | * adaNameRef.update({ first: 'Ada', last: 'Lovelace' });
|
7325 | * ```
|
7326 | *
|
7327 | * @param values Object containing multiple values.
|
7328 | * @param onComplete Callback called when write to server is
|
7329 | * complete.
|
7330 | * @return Resolves when update on server is complete.
|
7331 | */
|
7332 | update(values: Object, onComplete?: (a: Error | null) => any): Promise<any>;
|
7333 | }
|
7334 |
|
7335 | interface ThenableReference
|
7336 | extends firebase.database.Reference,
|
7337 | Pick<Promise<Reference>, 'then' | 'catch'> {}
|
7338 |
|
7339 | /**
|
7340 | * Logs debugging information to the console.
|
7341 | *
|
7342 | * @example
|
7343 | * ```javascript
|
7344 | * // Enable logging
|
7345 | * firebase.database.enableLogging(true);
|
7346 | * ```
|
7347 | *
|
7348 | * @example
|
7349 | * ```javascript
|
7350 | * // Disable logging
|
7351 | * firebase.database.enableLogging(false);
|
7352 | * ```
|
7353 | *
|
7354 | * @example
|
7355 | * ```javascript
|
7356 | * // Enable logging across page refreshes
|
7357 | * firebase.database.enableLogging(true, true);
|
7358 | * ```
|
7359 | *
|
7360 | * @example
|
7361 | * ```javascript
|
7362 | * // Provide custom logger which prefixes log statements with "[FIREBASE]"
|
7363 | * firebase.database.enableLogging(function(message) {
|
7364 | * console.log("[FIREBASE]", message);
|
7365 | * });
|
7366 | * ```
|
7367 | *
|
7368 | * @param logger Enables logging if `true`;
|
7369 | * disables logging if `false`. You can also provide a custom logger function
|
7370 | * to control how things get logged.
|
7371 | * @param persistent Remembers the logging state between page
|
7372 | * refreshes if `true`.
|
7373 | */
|
7374 | function enableLogging(
|
7375 | logger?: boolean | ((a: string) => any),
|
7376 | persistent?: boolean
|
7377 | ): any;
|
7378 |
|
7379 | export type EmulatorMockTokenOptions = firebase.EmulatorMockTokenOptions;
|
7380 | }
|
7381 |
|
7382 | declare namespace firebase.database.ServerValue {
|
7383 | /**
|
7384 | * A placeholder value for auto-populating the current timestamp (time
|
7385 | * since the Unix epoch, in milliseconds) as determined by the Firebase
|
7386 | * servers.
|
7387 | *
|
7388 | * @example
|
7389 | * ```javascript
|
7390 | * var sessionsRef = firebase.database().ref("sessions");
|
7391 | * sessionsRef.push({
|
7392 | * startedAt: firebase.database.ServerValue.TIMESTAMP
|
7393 | * });
|
7394 | * ```
|
7395 | */
|
7396 | var TIMESTAMP: Object;
|
7397 |
|
7398 | /**
|
7399 | * Returns a placeholder value that can be used to atomically increment the
|
7400 | * current database value by the provided delta.
|
7401 | *
|
7402 | * @param delta the amount to modify the current value atomically.
|
7403 | * @return a placeholder value for modifying data atomically server-side.
|
7404 | */
|
7405 | function increment(delta: number): Object;
|
7406 | }
|
7407 |
|
7408 | /**
|
7409 | * @webonly
|
7410 | */
|
7411 | declare namespace firebase.messaging {
|
7412 | /**
|
7413 | * The Firebase Messaging service interface.
|
7414 | *
|
7415 | * Do not call this constructor directly. Instead, use
|
7416 | * {@link firebase.messaging `firebase.messaging()`}.
|
7417 | *
|
7418 | * See {@link https://firebase.google.com/docs/cloud-messaging/js/client
|
7419 | * Set Up a JavaScript Firebase Cloud Messaging Client App} for a full guide on how to use the
|
7420 | * Firebase Messaging service.
|
7421 | *
|
7422 | */
|
7423 | interface Messaging {
|
7424 | /**
|
7425 | * Deletes the registration token associated with this messaging instance and unsubscribes the
|
7426 | * messaging instance from the push subscription.
|
7427 | *
|
7428 | * @return The promise resolves when the token has been successfully deleted.
|
7429 | */
|
7430 | deleteToken(): Promise<boolean>;
|
7431 |
|
7432 | /**
|
7433 | * Subscribes the messaging instance to push notifications. Returns an FCM registration token
|
7434 | * that can be used to send push messages to that messaging instance.
|
7435 | *
|
7436 | * If a notification permission isn't already granted, this method asks the user for permission.
|
7437 | * The returned promise rejects if the user does not allow the app to show notifications.
|
7438 | *
|
7439 | * @param options.vapidKey The public server key provided to push services. It is used to
|
7440 | * authenticate the push subscribers to receive push messages only from sending servers that
|
7441 | * hold the corresponding private key. If it is not provided, a default VAPID key is used. Note
|
7442 | * that some push services (Chrome Push Service) require a non-default VAPID key. Therefore, it
|
7443 | * is recommended to generate and import a VAPID key for your project with
|
7444 | * {@link https://firebase.google.com/docs/cloud-messaging/js/client#configure_web_credentials_with_fcm Configure Web Credentials with FCM}.
|
7445 | * See
|
7446 | * {@link https://developers.google.com/web/fundamentals/push-notifications/web-push-protocol The Web Push Protocol}
|
7447 | * for details on web push services.}
|
7448 | *
|
7449 | * @param options.serviceWorkerRegistration The service worker registration for receiving push
|
7450 | * messaging. If the registration is not provided explicitly, you need to have a
|
7451 | * `firebase-messaging-sw.js` at your root location. See
|
7452 | * {@link https://firebase.google.com/docs/cloud-messaging/js/client#retrieve-the-current-registration-token Retrieve the current registration token}
|
7453 | * for more details.
|
7454 | *
|
7455 | * @return The promise resolves with an FCM registration token.
|
7456 | *
|
7457 | */
|
7458 | getToken(options?: {
|
7459 | vapidKey?: string;
|
7460 | serviceWorkerRegistration?: ServiceWorkerRegistration;
|
7461 | }): Promise<string>;
|
7462 |
|
7463 | /**
|
7464 | * When a push message is received and the user is currently on a page for your origin, the
|
7465 | * message is passed to the page and an `onMessage()` event is dispatched with the payload of
|
7466 | * the push message.
|
7467 | *
|
7468 | * @param
|
7469 | * nextOrObserver This function, or observer object with `next` defined,
|
7470 | * is called when a message is received and the user is currently viewing your page.
|
7471 | * @return To stop listening for messages execute this returned function.
|
7472 | */
|
7473 | onMessage(
|
7474 | nextOrObserver: firebase.NextFn<any> | firebase.Observer<any>
|
7475 | ): firebase.Unsubscribe;
|
7476 |
|
7477 | /**
|
7478 | * Called when a message is received while the app is in the background. An app is considered to
|
7479 | * be in the background if no active window is displayed.
|
7480 | *
|
7481 | * @param
|
7482 | * nextOrObserver This function, or observer object with `next` defined,
|
7483 | * is called when a message is received and the app is currently in the background.
|
7484 | *
|
7485 | * @return To stop listening for messages execute this returned function
|
7486 | */
|
7487 | onBackgroundMessage(
|
7488 | nextOrObserver:
|
7489 | | firebase.NextFn<MessagePayload>
|
7490 | | firebase.Observer<MessagePayload>
|
7491 | ): firebase.Unsubscribe;
|
7492 | }
|
7493 |
|
7494 | /**
|
7495 | * Message payload that contains the notification payload that is represented with
|
7496 | * {@link firebase.messaging.NotificationPayload} and the data payload that contains an arbitrary
|
7497 | * number of key-value pairs sent by developers through the
|
7498 | * {@link https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#notification Send API}
|
7499 | */
|
7500 | export interface MessagePayload {
|
7501 | /**
|
7502 | * See {@link firebase.messaging.NotificationPayload}.
|
7503 | */
|
7504 | notification?: NotificationPayload;
|
7505 |
|
7506 | /**
|
7507 | * Arbitrary key/value pairs.
|
7508 | */
|
7509 | data?: { [key: string]: string };
|
7510 |
|
7511 | /**
|
7512 | * See {@link firebase.messaging.FcmOptions}.
|
7513 | */
|
7514 | fcmOptions?: FcmOptions;
|
7515 |
|
7516 | /**
|
7517 | * The sender of this message.
|
7518 | */
|
7519 | from: string;
|
7520 |
|
7521 | /**
|
7522 | * The collapse key of this message. See
|
7523 | * {@link https://firebase.google.com/docs/cloud-messaging/concept-options#collapsible_and_non-collapsible_messages
|
7524 | * Collapsible and non-collapsible messages}.
|
7525 | */
|
7526 | collapseKey: string;
|
7527 | }
|
7528 |
|
7529 | /**
|
7530 | * Options for features provided by the FCM SDK for Web. See
|
7531 | * {@link https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#webpushfcmoptions
|
7532 | * WebpushFcmOptions}.
|
7533 | */
|
7534 | export interface FcmOptions {
|
7535 | /**
|
7536 | * The link to open when the user clicks on the notification. For all URL values, HTTPS is
|
7537 | * required. For example, by setting this value to your app's URL, a notification click event
|
7538 | * will put your app in focus for the user.
|
7539 | */
|
7540 | link?: string;
|
7541 |
|
7542 | /**
|
7543 | * Label associated with the message's analytics data. See
|
7544 | * {@link https://firebase.google.com/docs/cloud-messaging/understand-delivery#adding-analytics-labels-to-messages
|
7545 | * Adding analytics labels}.
|
7546 | */
|
7547 | analyticsLabel?: string;
|
7548 | }
|
7549 |
|
7550 | /**
|
7551 | * Parameters that define how a push notification is displayed to users.
|
7552 | */
|
7553 | export interface NotificationPayload {
|
7554 | /**
|
7555 | * The title of a notification.
|
7556 | */
|
7557 | title?: string;
|
7558 |
|
7559 | /**
|
7560 | * The body of a notification.
|
7561 | */
|
7562 | body?: string;
|
7563 |
|
7564 | /**
|
7565 | * The URL of the image that is shown with the notification. See
|
7566 | * {@link https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#notification
|
7567 | * `notification.image`} for supported image format.
|
7568 | */
|
7569 | image?: string;
|
7570 | }
|
7571 |
|
7572 | function isSupported(): boolean;
|
7573 | }
|
7574 |
|
7575 | declare namespace firebase.storage {
|
7576 | /**
|
7577 | * The full set of object metadata, including read-only properties.
|
7578 | */
|
7579 | interface FullMetadata extends firebase.storage.UploadMetadata {
|
7580 | /**
|
7581 | * The bucket this object is contained in.
|
7582 | */
|
7583 | bucket: string;
|
7584 | /**
|
7585 | * The full path of this object.
|
7586 | */
|
7587 | fullPath: string;
|
7588 | /**
|
7589 | * The object's generation.
|
7590 | * @see {@link https://cloud.google.com/storage/docs/generations-preconditions}
|
7591 | */
|
7592 | generation: string;
|
7593 | /**
|
7594 | * The object's metageneration.
|
7595 | * @see {@link https://cloud.google.com/storage/docs/generations-preconditions}
|
7596 | */
|
7597 | metageneration: string;
|
7598 | /**
|
7599 | * The short name of this object, which is the last component of the full path.
|
7600 | * For example, if fullPath is 'full/path/image.png', name is 'image.png'.
|
7601 | */
|
7602 | name: string;
|
7603 | /**
|
7604 | * The size of this object, in bytes.
|
7605 | */
|
7606 | size: number;
|
7607 | /**
|
7608 | * A date string representing when this object was created.
|
7609 | */
|
7610 | timeCreated: string;
|
7611 | /**
|
7612 | * A date string representing when this object was last updated.
|
7613 | */
|
7614 | updated: string;
|
7615 | }
|
7616 |
|
7617 | /**
|
7618 | * Represents a reference to a Google Cloud Storage object. Developers can
|
7619 | * upload, download, and delete objects, as well as get/set object metadata.
|
7620 | */
|
7621 | interface Reference {
|
7622 | /**
|
7623 | * The name of the bucket containing this reference's object.
|
7624 | */
|
7625 | bucket: string;
|
7626 | /**
|
7627 | * Returns a reference to a relative path from this reference.
|
7628 | * @param path The relative path from this reference.
|
7629 | * Leading, trailing, and consecutive slashes are removed.
|
7630 | * @return The reference to the given path.
|
7631 | */
|
7632 | child(path: string): firebase.storage.Reference;
|
7633 | /**
|
7634 | * Deletes the object at this reference's location.
|
7635 | * @return A Promise that resolves if the deletion
|
7636 | * succeeded and rejects if it failed, including if the object didn't exist.
|
7637 | */
|
7638 | delete(): Promise<void>;
|
7639 | /**
|
7640 | * The full path of this object.
|
7641 | */
|
7642 | fullPath: string;
|
7643 | /**
|
7644 | * Fetches a long lived download URL for this object.
|
7645 | * @return A Promise that resolves with the download
|
7646 | * URL or rejects if the fetch failed, including if the object did not
|
7647 | * exist.
|
7648 | */
|
7649 | getDownloadURL(): Promise<string>;
|
7650 | /**
|
7651 | * Fetches metadata for the object at this location, if one exists.
|
7652 | * @return A Promise that
|
7653 | * resolves with the metadata, or rejects if the fetch failed, including if
|
7654 | * the object did not exist.
|
7655 | */
|
7656 | getMetadata(): Promise<FullMetadata>;
|
7657 | /**
|
7658 | * The short name of this object, which is the last component of the full path.
|
7659 | * For example, if fullPath is 'full/path/image.png', name is 'image.png'.
|
7660 | */
|
7661 | name: string;
|
7662 | /**
|
7663 | * A reference pointing to the parent location of this reference, or null if
|
7664 | * this reference is the root.
|
7665 | */
|
7666 | parent: firebase.storage.Reference | null;
|
7667 | /**
|
7668 | * Uploads data to this reference's location.
|
7669 | * @param data The data to upload.
|
7670 | * @param metadata Metadata for the newly
|
7671 | * uploaded object.
|
7672 | * @return An object that can be used to monitor
|
7673 | * and manage the upload.
|
7674 | */
|
7675 | put(
|
7676 | data: Blob | Uint8Array | ArrayBuffer,
|
7677 | metadata?: firebase.storage.UploadMetadata
|
7678 | ): firebase.storage.UploadTask;
|
7679 | /**
|
7680 | * Uploads string data to this reference's location.
|
7681 | * @param data The string to upload.
|
7682 | * @param format The format of the string to
|
7683 | * upload.
|
7684 | * @param metadata Metadata for the newly
|
7685 | * uploaded object.
|
7686 | * @throws If the format is not an allowed format, or if the given string
|
7687 | * doesn't conform to the specified format.
|
7688 | */
|
7689 | putString(
|
7690 | data: string,
|
7691 | format?: firebase.storage.StringFormat,
|
7692 | metadata?: firebase.storage.UploadMetadata
|
7693 | ): firebase.storage.UploadTask;
|
7694 | /**
|
7695 | * A reference to the root of this reference's bucket.
|
7696 | */
|
7697 | root: firebase.storage.Reference;
|
7698 | /**
|
7699 | * The storage service associated with this reference.
|
7700 | */
|
7701 | storage: firebase.storage.Storage;
|
7702 | /**
|
7703 | * Returns a gs:// URL for this object in the form
|
7704 | * `gs://<bucket>/<path>/<to>/<object>`
|
7705 | * @return The gs:// URL.
|
7706 | */
|
7707 | toString(): string;
|
7708 | /**
|
7709 | * Updates the metadata for the object at this location, if one exists.
|
7710 | * @param metadata The new metadata.
|
7711 | * Setting a property to 'null' removes it on the server, while leaving
|
7712 | * a property as 'undefined' has no effect.
|
7713 | * @return A Promise that
|
7714 | * resolves with the full updated metadata or rejects if the updated failed,
|
7715 | * including if the object did not exist.
|
7716 | */
|
7717 | updateMetadata(
|
7718 | metadata: firebase.storage.SettableMetadata
|
7719 | ): Promise<FullMetadata>;
|
7720 | /**
|
7721 | * List all items (files) and prefixes (folders) under this storage reference.
|
7722 | *
|
7723 | * This is a helper method for calling `list()` repeatedly until there are
|
7724 | * no more results. The default pagination size is 1000.
|
7725 | *
|
7726 | * Note: The results may not be consistent if objects are changed while this
|
7727 | * operation is running.
|
7728 | *
|
7729 | * Warning: `listAll` may potentially consume too many resources if there are
|
7730 | * too many results.
|
7731 | *
|
7732 | * @return A Promise that resolves with all the items and prefixes under
|
7733 | * the current storage reference. `prefixes` contains references to
|
7734 | * sub-directories and `items` contains references to objects in this
|
7735 | * folder. `nextPageToken` is never returned.
|
7736 | */
|
7737 | listAll(): Promise<ListResult>;
|
7738 | /**
|
7739 | * List items (files) and prefixes (folders) under this storage reference.
|
7740 | *
|
7741 | * List API is only available for Firebase Rules Version 2.
|
7742 | *
|
7743 | * GCS is a key-blob store. Firebase Storage imposes the semantic of '/'
|
7744 | * delimited folder structure.
|
7745 | * Refer to GCS's List API if you want to learn more.
|
7746 | *
|
7747 | * To adhere to Firebase Rules's Semantics, Firebase Storage does not
|
7748 | * support objects whose paths end with "/" or contain two consecutive
|
7749 | * "/"s. Firebase Storage List API will filter these unsupported objects.
|
7750 | * `list()` may fail if there are too many unsupported objects in the bucket.
|
7751 | *
|
7752 | * @param options See `ListOptions` for details.
|
7753 | * @return A Promise that resolves with the items and prefixes.
|
7754 | * `prefixes` contains references to sub-folders and `items`
|
7755 | * contains references to objects in this folder. `nextPageToken`
|
7756 | * can be used to get the rest of the results.
|
7757 | */
|
7758 | list(options?: ListOptions): Promise<ListResult>;
|
7759 | }
|
7760 |
|
7761 | /**
|
7762 | * Result returned by list().
|
7763 | */
|
7764 | interface ListResult {
|
7765 | /**
|
7766 | * References to prefixes (sub-folders). You can call list() on them to
|
7767 | * get its contents.
|
7768 | *
|
7769 | * Folders are implicit based on '/' in the object paths.
|
7770 | * For example, if a bucket has two objects '/a/b/1' and '/a/b/2', list('/a')
|
7771 | * will return '/a/b' as a prefix.
|
7772 | */
|
7773 | prefixes: Reference[];
|
7774 | /**
|
7775 | * Objects in this directory.
|
7776 | * You can call getMetadata() and getDownloadUrl() on them.
|
7777 | */
|
7778 | items: Reference[];
|
7779 | /**
|
7780 | * If set, there might be more results for this list. Use this token to resume the list.
|
7781 | */
|
7782 | nextPageToken: string | null;
|
7783 | }
|
7784 |
|
7785 | /**
|
7786 | * The options `list()` accepts.
|
7787 | */
|
7788 | interface ListOptions {
|
7789 | /**
|
7790 | * If set, limits the total number of `prefixes` and `items` to return.
|
7791 | * The default and maximum maxResults is 1000.
|
7792 | */
|
7793 | maxResults?: number | null;
|
7794 | /**
|
7795 | * The `nextPageToken` from a previous call to `list()`. If provided,
|
7796 | * listing is resumed from the previous position.
|
7797 | */
|
7798 | pageToken?: string | null;
|
7799 | }
|
7800 |
|
7801 | /**
|
7802 | * Object metadata that can be set at any time.
|
7803 | */
|
7804 | interface SettableMetadata {
|
7805 | /**
|
7806 | * Served as the 'Cache-Control' header on object download.
|
7807 | */
|
7808 | cacheControl?: string | null;
|
7809 | contentDisposition?: string | null;
|
7810 | /**
|
7811 | * Served as the 'Content-Encoding' header on object download.
|
7812 | */
|
7813 | contentEncoding?: string | null;
|
7814 | /**
|
7815 | * Served as the 'Content-Language' header on object download.
|
7816 | */
|
7817 | contentLanguage?: string | null;
|
7818 | /**
|
7819 | * Served as the 'Content-Type' header on object download.
|
7820 | */
|
7821 | contentType?: string | null;
|
7822 | /**
|
7823 | * Additional user-defined custom metadata.
|
7824 | */
|
7825 | customMetadata?: {
|
7826 | [/* warning: coerced from ? */ key: string]: string;
|
7827 | } | null;
|
7828 | }
|
7829 |
|
7830 | /**
|
7831 | * The Firebase Storage service interface.
|
7832 | *
|
7833 | * Do not call this constructor directly. Instead, use
|
7834 | * {@link firebase.storage `firebase.storage()`}.
|
7835 | *
|
7836 | * See
|
7837 | * {@link
|
7838 | * https://firebase.google.com/docs/storage/web/start/
|
7839 | * Get Started on Web}
|
7840 | * for a full guide on how to use the Firebase Storage service.
|
7841 | */
|
7842 | interface Storage {
|
7843 | /**
|
7844 | * The {@link firebase.app.App app} associated with the `Storage` service
|
7845 | * instance.
|
7846 | *
|
7847 | * @example
|
7848 | * ```javascript
|
7849 | * var app = storage.app;
|
7850 | * ```
|
7851 | */
|
7852 | app: firebase.app.App;
|
7853 | /**
|
7854 | * The maximum time to retry operations other than uploads or downloads in
|
7855 | * milliseconds.
|
7856 | */
|
7857 | maxOperationRetryTime: number;
|
7858 | /**
|
7859 | * The maximum time to retry uploads in milliseconds.
|
7860 | */
|
7861 | maxUploadRetryTime: number;
|
7862 | /**
|
7863 | * Returns a reference for the given path in the default bucket.
|
7864 | * @param path A relative path to initialize the reference with,
|
7865 | * for example `path/to/image.jpg`. If not passed, the returned reference
|
7866 | * points to the bucket root.
|
7867 | * @return A reference for the given path.
|
7868 | */
|
7869 | ref(path?: string): firebase.storage.Reference;
|
7870 | /**
|
7871 | * Returns a reference for the given absolute URL.
|
7872 | * @param url A URL in the form: <br />
|
7873 | * 1) a gs:// URL, for example `gs://bucket/files/image.png` <br />
|
7874 | * 2) a download URL taken from object metadata. <br />
|
7875 | * @return A reference for the given URL.
|
7876 | */
|
7877 | refFromURL(url: string): firebase.storage.Reference;
|
7878 | /**
|
7879 | * @param time The new maximum operation retry time in milliseconds.
|
7880 | * @see {@link firebase.storage.Storage.maxOperationRetryTime}
|
7881 | */
|
7882 | setMaxOperationRetryTime(time: number): any;
|
7883 | /**
|
7884 | * @param time The new maximum upload retry time in milliseconds.
|
7885 | * @see {@link firebase.storage.Storage.maxUploadRetryTime}
|
7886 | */
|
7887 | setMaxUploadRetryTime(time: number): any;
|
7888 | /**
|
7889 | * Modify this `Storage` instance to communicate with the Cloud Storage emulator.
|
7890 | *
|
7891 | * @param host - The emulator host (ex: localhost)
|
7892 | * @param port - The emulator port (ex: 5001)
|
7893 | * @param options.mockUserToken the mock auth token to use for unit testing Security Rules
|
7894 | */
|
7895 | useEmulator(
|
7896 | host: string,
|
7897 | port: number,
|
7898 | options?: {
|
7899 | mockUserToken?: EmulatorMockTokenOptions | string;
|
7900 | }
|
7901 | ): void;
|
7902 | }
|
7903 |
|
7904 | /**
|
7905 | * @enum {string}
|
7906 | * An enumeration of the possible string formats for upload.
|
7907 | */
|
7908 | type StringFormat = string;
|
7909 | var StringFormat: {
|
7910 | /**
|
7911 | * Indicates the string should be interpreted as base64-encoded data.
|
7912 | * Padding characters (trailing '='s) are optional.
|
7913 | * Example: The string 'rWmO++E6t7/rlw==' becomes the byte sequence
|
7914 | * ad 69 8e fb e1 3a b7 bf eb 97
|
7915 | */
|
7916 | BASE64: StringFormat;
|
7917 | /**
|
7918 | * Indicates the string should be interpreted as base64url-encoded data.
|
7919 | * Padding characters (trailing '='s) are optional.
|
7920 | * Example: The string 'rWmO--E6t7_rlw==' becomes the byte sequence
|
7921 | * ad 69 8e fb e1 3a b7 bf eb 97
|
7922 | */
|
7923 | BASE64URL: StringFormat;
|
7924 | /**
|
7925 | * Indicates the string is a data URL, such as one obtained from
|
7926 | * canvas.toDataURL().
|
7927 | * Example: the string 'data:application/octet-stream;base64,aaaa'
|
7928 | * becomes the byte sequence
|
7929 | * 69 a6 9a
|
7930 | * (the content-type "application/octet-stream" is also applied, but can
|
7931 | * be overridden in the metadata object).
|
7932 | */
|
7933 | DATA_URL: StringFormat;
|
7934 | /**
|
7935 | * Indicates the string should be interpreted "raw", that is, as normal text.
|
7936 | * The string will be interpreted as UTF-16, then uploaded as a UTF-8 byte
|
7937 | * sequence.
|
7938 | * Example: The string 'Hello! \ud83d\ude0a' becomes the byte sequence
|
7939 | * 48 65 6c 6c 6f 21 20 f0 9f 98 8a
|
7940 | */
|
7941 | RAW: StringFormat;
|
7942 | };
|
7943 |
|
7944 | /**
|
7945 | * An event that is triggered on a task.
|
7946 | * @enum {string}
|
7947 | * @see {@link firebase.storage.UploadTask.on}
|
7948 | */
|
7949 | type TaskEvent = string;
|
7950 | var TaskEvent: {
|
7951 | /**
|
7952 | * For this event,
|
7953 | * <ul>
|
7954 | * <li>The `next` function is triggered on progress updates and when the
|
7955 | * task is paused/resumed with a
|
7956 | * {@link firebase.storage.UploadTaskSnapshot} as the first
|
7957 | * argument.</li>
|
7958 | * <li>The `error` function is triggered if the upload is canceled or fails
|
7959 | * for another reason.</li>
|
7960 | * <li>The `complete` function is triggered if the upload completes
|
7961 | * successfully.</li>
|
7962 | * </ul>
|
7963 | */
|
7964 | STATE_CHANGED: TaskEvent;
|
7965 | };
|
7966 |
|
7967 | /**
|
7968 | * Represents the current state of a running upload.
|
7969 | * @enum {string}
|
7970 | */
|
7971 | type TaskState = string;
|
7972 | var TaskState: {
|
7973 | CANCELED: TaskState;
|
7974 | ERROR: TaskState;
|
7975 | PAUSED: TaskState;
|
7976 | RUNNING: TaskState;
|
7977 | SUCCESS: TaskState;
|
7978 | };
|
7979 |
|
7980 | /**
|
7981 | * Object metadata that can be set at upload.
|
7982 | */
|
7983 | interface UploadMetadata extends firebase.storage.SettableMetadata {
|
7984 | /**
|
7985 | * A Base64-encoded MD5 hash of the object being uploaded.
|
7986 | */
|
7987 | md5Hash?: string | null;
|
7988 | }
|
7989 |
|
7990 | /**
|
7991 | * An error returned by the Firebase Storage SDK.
|
7992 | */
|
7993 | interface FirebaseStorageError extends FirebaseError {
|
7994 | serverResponse: string | null;
|
7995 | }
|
7996 |
|
7997 | interface StorageObserver<T> {
|
7998 | next?: NextFn<T> | null;
|
7999 | error?: (error: FirebaseStorageError) => void | null;
|
8000 | complete?: CompleteFn | null;
|
8001 | }
|
8002 |
|
8003 | /**
|
8004 | * Represents the process of uploading an object. Allows you to monitor and
|
8005 | * manage the upload.
|
8006 | */
|
8007 | interface UploadTask {
|
8008 | /**
|
8009 | * Cancels a running task. Has no effect on a complete or failed task.
|
8010 | * @return True if the cancel had an effect.
|
8011 | */
|
8012 | cancel(): boolean;
|
8013 | /**
|
8014 | * Equivalent to calling `then(null, onRejected)`.
|
8015 | */
|
8016 | catch(onRejected: (error: FirebaseStorageError) => any): Promise<any>;
|
8017 | /**
|
8018 | * Listens for events on this task.
|
8019 | *
|
8020 | * Events have three callback functions (referred to as `next`, `error`, and
|
8021 | * `complete`).
|
8022 | *
|
8023 | * If only the event is passed, a function that can be used to register the
|
8024 | * callbacks is returned. Otherwise, the callbacks are passed after the event.
|
8025 | *
|
8026 | * Callbacks can be passed either as three separate arguments <em>or</em> as the
|
8027 | * `next`, `error`, and `complete` properties of an object. Any of the three
|
8028 | * callbacks is optional, as long as at least one is specified. In addition,
|
8029 | * when you add your callbacks, you get a function back. You can call this
|
8030 | * function to unregister the associated callbacks.
|
8031 | *
|
8032 | * @example **Pass callbacks separately or in an object.**
|
8033 | * ```javascript
|
8034 | * var next = function(snapshot) {};
|
8035 | * var error = function(error) {};
|
8036 | * var complete = function() {};
|
8037 | *
|
8038 | * // The first example.
|
8039 | * uploadTask.on(
|
8040 | * firebase.storage.TaskEvent.STATE_CHANGED,
|
8041 | * next,
|
8042 | * error,
|
8043 | * complete);
|
8044 | *
|
8045 | * // This is equivalent to the first example.
|
8046 | * uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, {
|
8047 | * 'next': next,
|
8048 | * 'error': error,
|
8049 | * 'complete': complete
|
8050 | * });
|
8051 | *
|
8052 | * // This is equivalent to the first example.
|
8053 | * var subscribe = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
|
8054 | * subscribe(next, error, complete);
|
8055 | *
|
8056 | * // This is equivalent to the first example.
|
8057 | * var subscribe = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
|
8058 | * subscribe({
|
8059 | * 'next': next,
|
8060 | * 'error': error,
|
8061 | * 'complete': complete
|
8062 | * });
|
8063 | * ```
|
8064 | *
|
8065 | * @example **Any callback is optional.**
|
8066 | * ```javascript
|
8067 | * // Just listening for completion, this is legal.
|
8068 | * uploadTask.on(
|
8069 | * firebase.storage.TaskEvent.STATE_CHANGED,
|
8070 | * null,
|
8071 | * null,
|
8072 | * function() {
|
8073 | * console.log('upload complete!');
|
8074 | * });
|
8075 | *
|
8076 | * // Just listening for progress/state changes, this is legal.
|
8077 | * uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, function(snapshot) {
|
8078 | * var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
|
8079 | * console.log(percent + "% done");
|
8080 | * });
|
8081 | *
|
8082 | * // This is also legal.
|
8083 | * uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, {
|
8084 | * 'complete': function() {
|
8085 | * console.log('upload complete!');
|
8086 | * }
|
8087 | * });
|
8088 | * ```
|
8089 | *
|
8090 | * @example **Use the returned function to remove callbacks.**
|
8091 | * ```javascript
|
8092 | * var unsubscribe = uploadTask.on(
|
8093 | * firebase.storage.TaskEvent.STATE_CHANGED,
|
8094 | * function(snapshot) {
|
8095 | * var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
|
8096 | * console.log(percent + "% done");
|
8097 | * // Stop after receiving one update.
|
8098 | * unsubscribe();
|
8099 | * });
|
8100 | *
|
8101 | * // This code is equivalent to the above.
|
8102 | * var handle = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
|
8103 | * unsubscribe = handle(function(snapshot) {
|
8104 | * var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
|
8105 | * console.log(percent + "% done");
|
8106 | * // Stop after receiving one update.
|
8107 | * unsubscribe();
|
8108 | * });
|
8109 | * ```
|
8110 | *
|
8111 | * @param event The event to listen for.
|
8112 | * @param nextOrObserver
|
8113 | * The `next` function, which gets called for each item in
|
8114 | * the event stream, or an observer object with some or all of these three
|
8115 | * properties (`next`, `error`, `complete`).
|
8116 | * @param error A function that gets called with a `FirebaseStorageError`
|
8117 | * if the event stream ends due to an error.
|
8118 | * @param complete A function that gets called if the
|
8119 | * event stream ends normally.
|
8120 | * @return
|
8121 | * If only the event argument is passed, returns a function you can use to
|
8122 | * add callbacks (see the examples above). If more than just the event
|
8123 | * argument is passed, returns a function you can call to unregister the
|
8124 | * callbacks.
|
8125 | */
|
8126 | on(
|
8127 | event: firebase.storage.TaskEvent,
|
8128 | nextOrObserver?:
|
8129 | | StorageObserver<UploadTaskSnapshot>
|
8130 | | null
|
8131 | | ((snapshot: UploadTaskSnapshot) => any),
|
8132 | error?: ((error: FirebaseStorageError) => any) | null,
|
8133 | complete?: firebase.Unsubscribe | null
|
8134 | ): Function;
|
8135 | /**
|
8136 | * Pauses a running task. Has no effect on a paused or failed task.
|
8137 | * @return True if the pause had an effect.
|
8138 | */
|
8139 | pause(): boolean;
|
8140 | /**
|
8141 | * Resumes a paused task. Has no effect on a running or failed task.
|
8142 | * @return True if the resume had an effect.
|
8143 | */
|
8144 | resume(): boolean;
|
8145 | /**
|
8146 | * A snapshot of the current task state.
|
8147 | */
|
8148 | snapshot: firebase.storage.UploadTaskSnapshot;
|
8149 | /**
|
8150 | * This object behaves like a Promise, and resolves with its snapshot data when
|
8151 | * the upload completes.
|
8152 | * @param onFulfilled
|
8153 | * The fulfillment callback. Promise chaining works as normal.
|
8154 | * @param onRejected The rejection callback.
|
8155 | */
|
8156 | then(
|
8157 | onFulfilled?:
|
8158 | | ((snapshot: firebase.storage.UploadTaskSnapshot) => any)
|
8159 | | null,
|
8160 | onRejected?: ((error: FirebaseStorageError) => any) | null
|
8161 | ): Promise<any>;
|
8162 | }
|
8163 |
|
8164 | /**
|
8165 | * Holds data about the current state of the upload task.
|
8166 | */
|
8167 | interface UploadTaskSnapshot {
|
8168 | /**
|
8169 | * The number of bytes that have been successfully uploaded so far.
|
8170 | */
|
8171 | bytesTransferred: number;
|
8172 | /**
|
8173 | * Before the upload completes, contains the metadata sent to the server.
|
8174 | * After the upload completes, contains the metadata sent back from the server.
|
8175 | */
|
8176 | metadata: firebase.storage.FullMetadata;
|
8177 | /**
|
8178 | * The reference that spawned this snapshot's upload task.
|
8179 | */
|
8180 | ref: firebase.storage.Reference;
|
8181 | /**
|
8182 | * The current state of the task.
|
8183 | */
|
8184 | state: firebase.storage.TaskState;
|
8185 | /**
|
8186 | * The task of which this is a snapshot.
|
8187 | */
|
8188 | task: firebase.storage.UploadTask;
|
8189 | /**
|
8190 | * The total number of bytes to be uploaded.
|
8191 | */
|
8192 | totalBytes: number;
|
8193 | }
|
8194 | }
|
8195 |
|
8196 | declare namespace firebase.firestore {
|
8197 | /**
|
8198 | * Document data (for use with `DocumentReference.set()`) consists of fields
|
8199 | * mapped to values.
|
8200 | */
|
8201 | export type DocumentData = { [field: string]: any };
|
8202 |
|
8203 | /**
|
8204 | * Update data (for use with `DocumentReference.update()`) consists of field
|
8205 | * paths (e.g. 'foo' or 'foo.baz') mapped to values. Fields that contain dots
|
8206 | * reference nested fields within the document.
|
8207 | */
|
8208 | export type UpdateData = { [fieldPath: string]: any };
|
8209 |
|
8210 | /**
|
8211 | * Constant used to indicate the LRU garbage collection should be disabled.
|
8212 | * Set this value as the `cacheSizeBytes` on the settings passed to the
|
8213 | * `Firestore` instance.
|
8214 | */
|
8215 | export const CACHE_SIZE_UNLIMITED: number;
|
8216 |
|
8217 | /**
|
8218 | * Specifies custom configurations for your Cloud Firestore instance.
|
8219 | * You must set these before invoking any other methods.
|
8220 | */
|
8221 | export interface Settings {
|
8222 | /** The hostname to connect to. */
|
8223 | host?: string;
|
8224 | /** Whether to use SSL when connecting. */
|
8225 | ssl?: boolean;
|
8226 |
|
8227 | /**
|
8228 | * An approximate cache size threshold for the on-disk data. If the cache grows beyond this
|
8229 | * size, Firestore will start removing data that hasn't been recently used. The size is not a
|
8230 | * guarantee that the cache will stay below that size, only that if the cache exceeds the given
|
8231 | * size, cleanup will be attempted.
|
8232 | *
|
8233 | * The default value is 40 MB. The threshold must be set to at least 1 MB, and can be set to
|
8234 | * CACHE_SIZE_UNLIMITED to disable garbage collection.
|
8235 | */
|
8236 | cacheSizeBytes?: number;
|
8237 |
|
8238 | /**
|
8239 | * Forces the SDK’s underlying network transport (WebChannel) to use
|
8240 | * long-polling. Each response from the backend will be closed immediately
|
8241 | * after the backend sends data (by default responses are kept open in
|
8242 | * case the backend has more data to send). This avoids incompatibility
|
8243 | * issues with certain proxies, antivirus software, etc. that incorrectly
|
8244 | * buffer traffic indefinitely. Use of this option will cause some
|
8245 | * performance degradation though.
|
8246 | *
|
8247 | * This setting cannot be used with `experimentalAutoDetectLongPolling` and
|
8248 | * may be removed in a future release. If you find yourself using it to
|
8249 | * work around a specific network reliability issue, please tell us about
|
8250 | * it in https://github.com/firebase/firebase-js-sdk/issues/1674.
|
8251 | *
|
8252 | * @webonly
|
8253 | */
|
8254 | experimentalForceLongPolling?: boolean;
|
8255 |
|
8256 | /**
|
8257 | * Configures the SDK's underlying transport (WebChannel) to automatically detect if
|
8258 | * long-polling should be used. This is very similar to `experimentalForceLongPolling`,
|
8259 | * but only uses long-polling if required.
|
8260 | *
|
8261 | * This setting will likely be enabled by default in future releases and cannot be
|
8262 | * combined with `experimentalForceLongPolling`.
|
8263 | *
|
8264 | * @webonly
|
8265 | */
|
8266 | experimentalAutoDetectLongPolling?: boolean;
|
8267 |
|
8268 | /**
|
8269 | * Whether to skip nested properties that are set to `undefined` during
|
8270 | * object serialization. If set to `true`, these properties are skipped
|
8271 | * and not written to Firestore. If set to `false` or omitted, the SDK
|
8272 | * throws an exception when it encounters properties of type `undefined`.
|
8273 | */
|
8274 | ignoreUndefinedProperties?: boolean;
|
8275 |
|
8276 | /**
|
8277 | * Whether to merge the provided settings with the existing settings. If
|
8278 | * set to `true`, the settings are merged with existing settings. If
|
8279 | * set to `false` or left unset, the settings replace the existing
|
8280 | * settings.
|
8281 | */
|
8282 | merge?: boolean;
|
8283 | }
|
8284 |
|
8285 | /**
|
8286 | * Settings that can be passed to Firestore.enablePersistence() to configure
|
8287 | * Firestore persistence.
|
8288 | */
|
8289 | export interface PersistenceSettings {
|
8290 | /**
|
8291 | * Whether to synchronize the in-memory state of multiple tabs. Setting this
|
8292 | * to `true` in all open tabs enables shared access to local persistence,
|
8293 | * shared execution of queries and latency-compensated local document updates
|
8294 | * across all connected instances.
|
8295 | *
|
8296 | * To enable this mode, `synchronizeTabs:true` needs to be set globally in all
|
8297 | * active tabs. If omitted or set to 'false', `enablePersistence()` will fail
|
8298 | * in all but the first tab.
|
8299 | */
|
8300 | synchronizeTabs?: boolean;
|
8301 |
|
8302 | /**
|
8303 | * Whether to force enable persistence for the client. This cannot be used
|
8304 | * with `synchronizeTabs:true` and is primarily intended for use with Web
|
8305 | * Workers. Setting this to `true` will enable persistence, but cause other
|
8306 | * tabs using persistence to fail.
|
8307 | *
|
8308 | * This setting may be removed in a future release. If you find yourself
|
8309 | * using it for a specific use case or run into any issues, please tell us
|
8310 | * about it in
|
8311 | * https://github.com/firebase/firebase-js-sdk/issues/983.
|
8312 | */
|
8313 | experimentalForceOwningTab?: boolean;
|
8314 | }
|
8315 |
|
8316 | export type LogLevel = 'debug' | 'error' | 'silent';
|
8317 |
|
8318 | /**
|
8319 | * Sets the verbosity of Cloud Firestore logs (debug, error, or silent).
|
8320 | *
|
8321 | * @param logLevel
|
8322 | * The verbosity you set for activity and error logging. Can be any of
|
8323 | * the following values:
|
8324 | *
|
8325 | * <ul>
|
8326 | * <li><code>debug</code> for the most verbose logging level, primarily for
|
8327 | * debugging.</li>
|
8328 | * <li><code>error</code> to log errors only.</li>
|
8329 | * <li><code>silent</code> to turn off logging.</li>
|
8330 | * </ul>
|
8331 | */
|
8332 | export function setLogLevel(logLevel: LogLevel): void;
|
8333 |
|
8334 | /**
|
8335 | * Converter used by `withConverter()` to transform user objects of type T
|
8336 | * into Firestore data.
|
8337 | *
|
8338 | * Using the converter allows you to specify generic type arguments when
|
8339 | * storing and retrieving objects from Firestore.
|
8340 | *
|
8341 | * @example
|
8342 | * ```typescript
|
8343 | * class Post {
|
8344 | * constructor(readonly title: string, readonly author: string) {}
|
8345 | *
|
8346 | * toString(): string {
|
8347 | * return this.title + ', by ' + this.author;
|
8348 | * }
|
8349 | * }
|
8350 | *
|
8351 | * const postConverter = {
|
8352 | * toFirestore(post: Post): firebase.firestore.DocumentData {
|
8353 | * return {title: post.title, author: post.author};
|
8354 | * },
|
8355 | * fromFirestore(
|
8356 | * snapshot: firebase.firestore.QueryDocumentSnapshot,
|
8357 | * options: firebase.firestore.SnapshotOptions
|
8358 | * ): Post {
|
8359 | * const data = snapshot.data(options)!;
|
8360 | * return new Post(data.title, data.author);
|
8361 | * }
|
8362 | * };
|
8363 | *
|
8364 | * const postSnap = await firebase.firestore()
|
8365 | * .collection('posts')
|
8366 | * .withConverter(postConverter)
|
8367 | * .doc().get();
|
8368 | * const post = postSnap.data();
|
8369 | * if (post !== undefined) {
|
8370 | * post.title; // string
|
8371 | * post.toString(); // Should be defined
|
8372 | * post.someNonExistentProperty; // TS error
|
8373 | * }
|
8374 | * ```
|
8375 | */
|
8376 | export interface FirestoreDataConverter<T> {
|
8377 | /**
|
8378 | * Called by the Firestore SDK to convert a custom model object of type T
|
8379 | * into a plain Javascript object (suitable for writing directly to the
|
8380 | * Firestore database). To use `set()` with `merge` and `mergeFields`,
|
8381 | * `toFirestore()` must be defined with `Partial<T>`.
|
8382 | */
|
8383 | toFirestore(modelObject: T): DocumentData;
|
8384 | toFirestore(modelObject: Partial<T>, options: SetOptions): DocumentData;
|
8385 |
|
8386 | /**
|
8387 | * Called by the Firestore SDK to convert Firestore data into an object of
|
8388 | * type T. You can access your data by calling: `snapshot.data(options)`.
|
8389 | *
|
8390 | * @param snapshot A QueryDocumentSnapshot containing your data and metadata.
|
8391 | * @param options The SnapshotOptions from the initial call to `data()`.
|
8392 | */
|
8393 | fromFirestore(snapshot: QueryDocumentSnapshot, options: SnapshotOptions): T;
|
8394 | }
|
8395 |
|
8396 | /**
|
8397 | * The Cloud Firestore service interface.
|
8398 | *
|
8399 | * Do not call this constructor directly. Instead, use
|
8400 | * {@link firebase.firestore `firebase.firestore()`}.
|
8401 | */
|
8402 | export class Firestore {
|
8403 | private constructor();
|
8404 | /**
|
8405 | * Specifies custom settings to be used to configure the `Firestore`
|
8406 | * instance. Must be set before invoking any other methods.
|
8407 | *
|
8408 | * @param settings The settings to use.
|
8409 | */
|
8410 | settings(settings: Settings): void;
|
8411 |
|
8412 | /**
|
8413 | * Modify this instance to communicate with the Cloud Firestore emulator.
|
8414 | *
|
8415 | * <p>Note: this must be called before this instance has been used to do any operations.
|
8416 | *
|
8417 | * @param host the emulator host (ex: localhost).
|
8418 | * @param port the emulator port (ex: 9000).
|
8419 | * @param options.mockUserToken - the mock auth token to use for unit
|
8420 | * testing Security Rules.
|
8421 | */
|
8422 | useEmulator(
|
8423 | host: string,
|
8424 | port: number,
|
8425 | options?: {
|
8426 | mockUserToken?: EmulatorMockTokenOptions | string;
|
8427 | }
|
8428 | ): void;
|
8429 |
|
8430 | /**
|
8431 | * Attempts to enable persistent storage, if possible.
|
8432 | *
|
8433 | * Must be called before any other methods (other than settings() and
|
8434 | * clearPersistence()).
|
8435 | *
|
8436 | * If this fails, enablePersistence() will reject the promise it returns.
|
8437 | * Note that even after this failure, the firestore instance will remain
|
8438 | * usable, however offline persistence will be disabled.
|
8439 | *
|
8440 | * There are several reasons why this can fail, which can be identified by
|
8441 | * the `code` on the error.
|
8442 | *
|
8443 | * * failed-precondition: The app is already open in another browser tab.
|
8444 | * * unimplemented: The browser is incompatible with the offline
|
8445 | * persistence implementation.
|
8446 | *
|
8447 | * @param settings Optional settings object to configure persistence.
|
8448 | * @return A promise that represents successfully enabling persistent
|
8449 | * storage.
|
8450 | */
|
8451 | enablePersistence(settings?: PersistenceSettings): Promise<void>;
|
8452 |
|
8453 | /**
|
8454 | * Gets a `CollectionReference` instance that refers to the collection at
|
8455 | * the specified path.
|
8456 | *
|
8457 | * @param collectionPath A slash-separated path to a collection.
|
8458 | * @return The `CollectionReference` instance.
|
8459 | */
|
8460 | collection(collectionPath: string): CollectionReference<DocumentData>;
|
8461 |
|
8462 | /**
|
8463 | * Gets a `DocumentReference` instance that refers to the document at the
|
8464 | * specified path.
|
8465 | *
|
8466 | * @param documentPath A slash-separated path to a document.
|
8467 | * @return The `DocumentReference` instance.
|
8468 | */
|
8469 | doc(documentPath: string): DocumentReference<DocumentData>;
|
8470 |
|
8471 | /**
|
8472 | * Creates and returns a new Query that includes all documents in the
|
8473 | * database that are contained in a collection or subcollection with the
|
8474 | * given collectionId.
|
8475 | *
|
8476 | * @param collectionId Identifies the collections to query over. Every
|
8477 | * collection or subcollection with this ID as the last segment of its path
|
8478 | * will be included. Cannot contain a slash.
|
8479 | * @return The created Query.
|
8480 | */
|
8481 | collectionGroup(collectionId: string): Query<DocumentData>;
|
8482 |
|
8483 | /**
|
8484 | * Executes the given `updateFunction` and then attempts to commit the changes
|
8485 | * applied within the transaction. If any document read within the transaction
|
8486 | * has changed, Cloud Firestore retries the `updateFunction`. If it fails to
|
8487 | * commit after 5 attempts, the transaction fails.
|
8488 | *
|
8489 | * The maximum number of writes allowed in a single transaction is 500, but
|
8490 | * note that each usage of `FieldValue.serverTimestamp()`,
|
8491 | * `FieldValue.arrayUnion()`, `FieldValue.arrayRemove()`, or
|
8492 | * `FieldValue.increment()` inside a transaction counts as an additional write.
|
8493 | *
|
8494 | * @param updateFunction
|
8495 | * The function to execute within the transaction context.
|
8496 | *
|
8497 | * @return
|
8498 | * If the transaction completed successfully or was explicitly aborted
|
8499 | * (the `updateFunction` returned a failed promise),
|
8500 | * the promise returned by the updateFunction is returned here. Else, if the
|
8501 | * transaction failed, a rejected promise with the corresponding failure
|
8502 | * error will be returned.
|
8503 | */
|
8504 | runTransaction<T>(
|
8505 | updateFunction: (transaction: Transaction) => Promise<T>
|
8506 | ): Promise<T>;
|
8507 |
|
8508 | /**
|
8509 | * Creates a write batch, used for performing multiple writes as a single
|
8510 | * atomic operation. The maximum number of writes allowed in a single WriteBatch
|
8511 | * is 500, but note that each usage of `FieldValue.serverTimestamp()`,
|
8512 | * `FieldValue.arrayUnion()`, `FieldValue.arrayRemove()`, or
|
8513 | * `FieldValue.increment()` inside a WriteBatch counts as an additional write.
|
8514 | *
|
8515 | * @return
|
8516 | * A `WriteBatch` that can be used to atomically execute multiple writes.
|
8517 | */
|
8518 | batch(): WriteBatch;
|
8519 |
|
8520 | /**
|
8521 | * The {@link firebase.app.App app} associated with this `Firestore` service
|
8522 | * instance.
|
8523 | */
|
8524 | app: firebase.app.App;
|
8525 |
|
8526 | /**
|
8527 | * Clears the persistent storage. This includes pending writes and cached
|
8528 | * documents.
|
8529 | *
|
8530 | * Must be called while the firestore instance is not started (after the app
|
8531 | * is shutdown or when the app is first initialized). On startup, this
|
8532 | * method must be called before other methods (other than settings()). If
|
8533 | * the firestore instance is still running, the promise will be rejected
|
8534 | * with the error code of `failed-precondition`.
|
8535 | *
|
8536 | * Note: clearPersistence() is primarily intended to help write reliable
|
8537 | * tests that use Cloud Firestore. It uses an efficient mechanism for
|
8538 | * dropping existing data but does not attempt to securely overwrite or
|
8539 | * otherwise make cached data unrecoverable. For applications that are
|
8540 | * sensitive to the disclosure of cached data in between user sessions, we
|
8541 | * strongly recommend not enabling persistence at all.
|
8542 | *
|
8543 | * @return A promise that is resolved when the persistent storage is
|
8544 | * cleared. Otherwise, the promise is rejected with an error.
|
8545 | */
|
8546 | clearPersistence(): Promise<void>;
|
8547 |
|
8548 | /**
|
8549 | * Re-enables use of the network for this Firestore instance after a prior
|
8550 | * call to {@link firebase.firestore.Firestore.disableNetwork
|
8551 | * `disableNetwork()`}.
|
8552 | *
|
8553 | * @return A promise that is resolved once the network has been
|
8554 | * enabled.
|
8555 | */
|
8556 | enableNetwork(): Promise<void>;
|
8557 |
|
8558 | /**
|
8559 | * Disables network usage for this instance. It can be re-enabled via
|
8560 | * {@link firebase.firestore.Firestore.enableNetwork `enableNetwork()`}. While
|
8561 | * the network is disabled, any snapshot listeners or get() calls will return
|
8562 | * results from cache, and any write operations will be queued until the network
|
8563 | * is restored.
|
8564 | *
|
8565 | * @return A promise that is resolved once the network has been
|
8566 | * disabled.
|
8567 | */
|
8568 | disableNetwork(): Promise<void>;
|
8569 |
|
8570 | /**
|
8571 | * Waits until all currently pending writes for the active user have been acknowledged by the
|
8572 | * backend.
|
8573 | *
|
8574 | * The returned Promise resolves immediately if there are no outstanding writes. Otherwise, the
|
8575 | * Promise waits for all previously issued writes (including those written in a previous app
|
8576 | * session), but it does not wait for writes that were added after the method is called. If you
|
8577 | * want to wait for additional writes, call `waitForPendingWrites()` again.
|
8578 | *
|
8579 | * Any outstanding `waitForPendingWrites()` Promises are rejected during user changes.
|
8580 | *
|
8581 | * @return A Promise which resolves when all currently pending writes have been
|
8582 | * acknowledged by the backend.
|
8583 | */
|
8584 | waitForPendingWrites(): Promise<void>;
|
8585 |
|
8586 | /**
|
8587 | * Attaches a listener for a snapshots-in-sync event. The snapshots-in-sync
|
8588 | * event indicates that all listeners affected by a given change have fired,
|
8589 | * even if a single server-generated change affects multiple listeners.
|
8590 | *
|
8591 | * NOTE: The snapshots-in-sync event only indicates that listeners are in sync
|
8592 | * with each other, but does not relate to whether those snapshots are in sync
|
8593 | * with the server. Use SnapshotMetadata in the individual listeners to
|
8594 | * determine if a snapshot is from the cache or the server.
|
8595 | *
|
8596 | * @param observer A single object containing `next` and `error` callbacks.
|
8597 | * @return An unsubscribe function that can be called to cancel the snapshot
|
8598 | * listener.
|
8599 | */
|
8600 | onSnapshotsInSync(observer: {
|
8601 | next?: (value: void) => void;
|
8602 | error?: (error: FirestoreError) => void;
|
8603 | complete?: () => void;
|
8604 | }): () => void;
|
8605 |
|
8606 | /**
|
8607 | * Attaches a listener for a snapshots-in-sync event. The snapshots-in-sync
|
8608 | * event indicates that all listeners affected by a given change have fired,
|
8609 | * even if a single server-generated change affects multiple listeners.
|
8610 | *
|
8611 | * NOTE: The snapshots-in-sync event only indicates that listeners are in sync
|
8612 | * with each other, but does not relate to whether those snapshots are in sync
|
8613 | * with the server. Use SnapshotMetadata in the individual listeners to
|
8614 | * determine if a snapshot is from the cache or the server.
|
8615 | *
|
8616 | * @param onSync A callback to be called every time all snapshot listeners are
|
8617 | * in sync with each other.
|
8618 | * @return An unsubscribe function that can be called to cancel the snapshot
|
8619 | * listener.
|
8620 | */
|
8621 | onSnapshotsInSync(onSync: () => void): () => void;
|
8622 |
|
8623 | /**
|
8624 | * Terminates this Firestore instance.
|
8625 | *
|
8626 | * After calling `terminate()` only the `clearPersistence()` method may be used. Any other method
|
8627 | * will throw a `FirestoreError`.
|
8628 | *
|
8629 | * To restart after termination, create a new instance of FirebaseFirestore with
|
8630 | * `firebase.firestore()`.
|
8631 | *
|
8632 | * Termination does not cancel any pending writes, and any promises that are awaiting a response
|
8633 | * from the server will not be resolved. If you have persistence enabled, the next time you
|
8634 | * start this instance, it will resume sending these writes to the server.
|
8635 | *
|
8636 | * Note: Under normal circumstances, calling `terminate()` is not required. This
|
8637 | * method is useful only when you want to force this instance to release all of its resources or
|
8638 | * in combination with `clearPersistence()` to ensure that all local state is destroyed
|
8639 | * between test runs.
|
8640 | *
|
8641 | * @return A promise that is resolved when the instance has been successfully terminated.
|
8642 | */
|
8643 | terminate(): Promise<void>;
|
8644 |
|
8645 | /**
|
8646 | * Loads a Firestore bundle into the local cache.
|
8647 | *
|
8648 | * @param bundleData
|
8649 | * An object representing the bundle to be loaded. Valid objects are `ArrayBuffer`,
|
8650 | * `ReadableStream<Uint8Array>` or `string`.
|
8651 | *
|
8652 | * @return
|
8653 | * A `LoadBundleTask` object, which notifies callers with progress updates, and completion
|
8654 | * or error events. It can be used as a `Promise<LoadBundleTaskProgress>`.
|
8655 | */
|
8656 | loadBundle(
|
8657 | bundleData: ArrayBuffer | ReadableStream<Uint8Array> | string
|
8658 | ): LoadBundleTask;
|
8659 |
|
8660 | /**
|
8661 | * Reads a Firestore `Query` from local cache, identified by the given name.
|
8662 | *
|
8663 | * The named queries are packaged into bundles on the server side (along
|
8664 | * with resulting documents), and loaded to local cache using `loadBundle`. Once in local
|
8665 | * cache, use this method to extract a `Query` by name.
|
8666 | */
|
8667 | namedQuery(name: string): Promise<Query<DocumentData> | null>;
|
8668 |
|
8669 | /**
|
8670 | * @hidden
|
8671 | */
|
8672 | INTERNAL: { delete: () => Promise<void> };
|
8673 | }
|
8674 |
|
8675 | /**
|
8676 | * Represents the task of loading a Firestore bundle. It provides progress of bundle
|
8677 | * loading, as well as task completion and error events.
|
8678 | *
|
8679 | * The API is compatible with `Promise<LoadBundleTaskProgress>`.
|
8680 | */
|
8681 | export interface LoadBundleTask extends PromiseLike<LoadBundleTaskProgress> {
|
8682 | /**
|
8683 | * Registers functions to listen to bundle loading progress events.
|
8684 | * @param next
|
8685 | * Called when there is a progress update from bundle loading. Typically `next` calls occur
|
8686 | * each time a Firestore document is loaded from the bundle.
|
8687 | * @param error
|
8688 | * Called when an error occurs during bundle loading. The task aborts after reporting the
|
8689 | * error, and there should be no more updates after this.
|
8690 | * @param complete
|
8691 | * Called when the loading task is complete.
|
8692 | */
|
8693 | onProgress(
|
8694 | next?: (progress: LoadBundleTaskProgress) => any,
|
8695 | error?: (error: Error) => any,
|
8696 | complete?: () => void
|
8697 | ): void;
|
8698 |
|
8699 | /**
|
8700 | * Implements the `Promise<LoadBundleTaskProgress>.then` interface.
|
8701 | *
|
8702 | * @param onFulfilled
|
8703 | * Called on the completion of the loading task with a final `LoadBundleTaskProgress` update.
|
8704 | * The update will always have its `taskState` set to `"Success"`.
|
8705 | * @param onRejected
|
8706 | * Called when an error occurs during bundle loading.
|
8707 | */
|
8708 | then<T, R>(
|
8709 | onFulfilled?: (a: LoadBundleTaskProgress) => T | PromiseLike<T>,
|
8710 | onRejected?: (a: Error) => R | PromiseLike<R>
|
8711 | ): Promise<T | R>;
|
8712 |
|
8713 | /**
|
8714 | * Implements the `Promise<LoadBundleTaskProgress>.catch` interface.
|
8715 | *
|
8716 | * @param onRejected
|
8717 | * Called when an error occurs during bundle loading.
|
8718 | */
|
8719 | catch<R>(
|
8720 | onRejected: (a: Error) => R | PromiseLike<R>
|
8721 | ): Promise<R | LoadBundleTaskProgress>;
|
8722 | }
|
8723 |
|
8724 | /**
|
8725 | * Represents a progress update or a final state from loading bundles.
|
8726 | */
|
8727 | export interface LoadBundleTaskProgress {
|
8728 | /** How many documents have been loaded. */
|
8729 | documentsLoaded: number;
|
8730 | /** How many documents are in the bundle being loaded. */
|
8731 | totalDocuments: number;
|
8732 | /** How many bytes have been loaded. */
|
8733 | bytesLoaded: number;
|
8734 | /** How many bytes are in the bundle being loaded. */
|
8735 | totalBytes: number;
|
8736 | /** Current task state. */
|
8737 | taskState: TaskState;
|
8738 | }
|
8739 |
|
8740 | /**
|
8741 | * Represents the state of bundle loading tasks.
|
8742 | *
|
8743 | * Both 'Error' and 'Success' are sinking state: task will abort or complete and there will
|
8744 | * be no more updates after they are reported.
|
8745 | */
|
8746 | export type TaskState = 'Error' | 'Running' | 'Success';
|
8747 |
|
8748 | /**
|
8749 | * An immutable object representing a geo point in Firestore. The geo point
|
8750 | * is represented as latitude/longitude pair.
|
8751 | *
|
8752 | * Latitude values are in the range of [-90, 90].
|
8753 | * Longitude values are in the range of [-180, 180].
|
8754 | */
|
8755 | export class GeoPoint {
|
8756 | /**
|
8757 | * Creates a new immutable GeoPoint object with the provided latitude and
|
8758 | * longitude values.
|
8759 | * @param latitude The latitude as number between -90 and 90.
|
8760 | * @param longitude The longitude as number between -180 and 180.
|
8761 | */
|
8762 | constructor(latitude: number, longitude: number);
|
8763 |
|
8764 | /**
|
8765 | * The latitude of this GeoPoint instance.
|
8766 | */
|
8767 | readonly latitude: number;
|
8768 | /**
|
8769 | * The longitude of this GeoPoint instance.
|
8770 | */
|
8771 | readonly longitude: number;
|
8772 |
|
8773 | /**
|
8774 | * Returns true if this `GeoPoint` is equal to the provided one.
|
8775 | *
|
8776 | * @param other The `GeoPoint` to compare against.
|
8777 | * @return true if this `GeoPoint` is equal to the provided one.
|
8778 | */
|
8779 | isEqual(other: GeoPoint): boolean;
|
8780 | }
|
8781 |
|
8782 | /**
|
8783 | * A Timestamp represents a point in time independent of any time zone or
|
8784 | * calendar, represented as seconds and fractions of seconds at nanosecond
|
8785 | * resolution in UTC Epoch time.
|
8786 | *
|
8787 | * It is encoded using the Proleptic Gregorian
|
8788 | * Calendar which extends the Gregorian calendar backwards to year one. It is
|
8789 | * encoded assuming all minutes are 60 seconds long, i.e. leap seconds are
|
8790 | * "smeared" so that no leap second table is needed for interpretation. Range is
|
8791 | * from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z.
|
8792 | *
|
8793 | * @see https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto
|
8794 | */
|
8795 | export class Timestamp {
|
8796 | /**
|
8797 | * Creates a new timestamp.
|
8798 | *
|
8799 | * @param seconds The number of seconds of UTC time since Unix epoch
|
8800 | * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
|
8801 | * 9999-12-31T23:59:59Z inclusive.
|
8802 | * @param nanoseconds The non-negative fractions of a second at nanosecond
|
8803 | * resolution. Negative second values with fractions must still have
|
8804 | * non-negative nanoseconds values that count forward in time. Must be
|
8805 | * from 0 to 999,999,999 inclusive.
|
8806 | */
|
8807 | constructor(seconds: number, nanoseconds: number);
|
8808 |
|
8809 | /**
|
8810 | * Creates a new timestamp with the current date, with millisecond precision.
|
8811 | *
|
8812 | * @return a new timestamp representing the current date.
|
8813 | */
|
8814 | static now(): Timestamp;
|
8815 |
|
8816 | /**
|
8817 | * Creates a new timestamp from the given date.
|
8818 | *
|
8819 | * @param date The date to initialize the `Timestamp` from.
|
8820 | * @return A new `Timestamp` representing the same point in time as the given
|
8821 | * date.
|
8822 | */
|
8823 | static fromDate(date: Date): Timestamp;
|
8824 |
|
8825 | /**
|
8826 | * Creates a new timestamp from the given number of milliseconds.
|
8827 | *
|
8828 | * @param milliseconds Number of milliseconds since Unix epoch
|
8829 | * 1970-01-01T00:00:00Z.
|
8830 | * @return A new `Timestamp` representing the same point in time as the given
|
8831 | * number of milliseconds.
|
8832 | */
|
8833 | static fromMillis(milliseconds: number): Timestamp;
|
8834 |
|
8835 | readonly seconds: number;
|
8836 | readonly nanoseconds: number;
|
8837 |
|
8838 | /**
|
8839 | * Convert a Timestamp to a JavaScript `Date` object. This conversion causes
|
8840 | * a loss of precision since `Date` objects only support millisecond precision.
|
8841 | *
|
8842 | * @return JavaScript `Date` object representing the same point in time as
|
8843 | * this `Timestamp`, with millisecond precision.
|
8844 | */
|
8845 | toDate(): Date;
|
8846 |
|
8847 | /**
|
8848 | * Convert a timestamp to a numeric timestamp (in milliseconds since epoch).
|
8849 | * This operation causes a loss of precision.
|
8850 | *
|
8851 | * @return The point in time corresponding to this timestamp, represented as
|
8852 | * the number of milliseconds since Unix epoch 1970-01-01T00:00:00Z.
|
8853 | */
|
8854 | toMillis(): number;
|
8855 |
|
8856 | /**
|
8857 | * Returns true if this `Timestamp` is equal to the provided one.
|
8858 | *
|
8859 | * @param other The `Timestamp` to compare against.
|
8860 | * @return true if this `Timestamp` is equal to the provided one.
|
8861 | */
|
8862 | isEqual(other: Timestamp): boolean;
|
8863 |
|
8864 | /**
|
8865 | * Converts this object to a primitive string, which allows Timestamp objects to be compared
|
8866 | * using the `>`, `<=`, `>=` and `>` operators.
|
8867 | */
|
8868 | valueOf(): string;
|
8869 | }
|
8870 |
|
8871 | /**
|
8872 | * An immutable object representing an array of bytes.
|
8873 | */
|
8874 | export class Blob {
|
8875 | private constructor();
|
8876 |
|
8877 | /**
|
8878 | * Creates a new Blob from the given Base64 string, converting it to
|
8879 | * bytes.
|
8880 | *
|
8881 | * @param base64
|
8882 | * The Base64 string used to create the Blob object.
|
8883 | */
|
8884 | static fromBase64String(base64: string): Blob;
|
8885 |
|
8886 | /**
|
8887 | * Creates a new Blob from the given Uint8Array.
|
8888 | *
|
8889 | * @param array
|
8890 | * The Uint8Array used to create the Blob object.
|
8891 | */
|
8892 | static fromUint8Array(array: Uint8Array): Blob;
|
8893 |
|
8894 | /**
|
8895 | * Returns the bytes of a Blob as a Base64-encoded string.
|
8896 | *
|
8897 | * @return
|
8898 | * The Base64-encoded string created from the Blob object.
|
8899 | */
|
8900 | public toBase64(): string;
|
8901 |
|
8902 | /**
|
8903 | * Returns the bytes of a Blob in a new Uint8Array.
|
8904 | *
|
8905 | * @return
|
8906 | * The Uint8Array created from the Blob object.
|
8907 | */
|
8908 | public toUint8Array(): Uint8Array;
|
8909 |
|
8910 | /**
|
8911 | * Returns true if this `Blob` is equal to the provided one.
|
8912 | *
|
8913 | * @param other The `Blob` to compare against.
|
8914 | * @return true if this `Blob` is equal to the provided one.
|
8915 | */
|
8916 | isEqual(other: Blob): boolean;
|
8917 | }
|
8918 |
|
8919 | /**
|
8920 | * A reference to a transaction.
|
8921 | * The `Transaction` object passed to a transaction's updateFunction provides
|
8922 | * the methods to read and write data within the transaction context. See
|
8923 | * `Firestore.runTransaction()`.
|
8924 | */
|
8925 | export class Transaction {
|
8926 | private constructor();
|
8927 |
|
8928 | /**
|
8929 | * Reads the document referenced by the provided `DocumentReference.`
|
8930 | *
|
8931 | * @param documentRef A reference to the document to be read.
|
8932 | * @return A DocumentSnapshot for the read data.
|
8933 | */
|
8934 | get<T>(documentRef: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
|
8935 |
|
8936 | /**
|
8937 | * Writes to the document referred to by the provided `DocumentReference`.
|
8938 | * If the document does not exist yet, it will be created. If you pass
|
8939 | * `SetOptions`, the provided data can be merged into the existing document.
|
8940 | *
|
8941 | * @param documentRef A reference to the document to be set.
|
8942 | * @param data An object of the fields and values for the document.
|
8943 | * @param options An object to configure the set behavior.
|
8944 | * @return This `Transaction` instance. Used for chaining method calls.
|
8945 | */
|
8946 | set<T>(
|
8947 | documentRef: DocumentReference<T>,
|
8948 | data: Partial<T>,
|
8949 | options: SetOptions
|
8950 | ): Transaction;
|
8951 |
|
8952 | /**
|
8953 | * Writes to the document referred to by the provided `DocumentReference`.
|
8954 | * If the document does not exist yet, it will be created. If you pass
|
8955 | * `SetOptions`, the provided data can be merged into the existing document.
|
8956 | *
|
8957 | * @param documentRef A reference to the document to be set.
|
8958 | * @param data An object of the fields and values for the document.
|
8959 | * @return This `Transaction` instance. Used for chaining method calls.
|
8960 | */
|
8961 | set<T>(documentRef: DocumentReference<T>, data: T): Transaction;
|
8962 |
|
8963 | /**
|
8964 | * Updates fields in the document referred to by the provided
|
8965 | * `DocumentReference`. The update will fail if applied to a document that
|
8966 | * does not exist.
|
8967 | *
|
8968 | * @param documentRef A reference to the document to be updated.
|
8969 | * @param data An object containing the fields and values with which to
|
8970 | * update the document. Fields can contain dots to reference nested fields
|
8971 | * within the document.
|
8972 | * @return This `Transaction` instance. Used for chaining method calls.
|
8973 | */
|
8974 | update(documentRef: DocumentReference<any>, data: UpdateData): Transaction;
|
8975 |
|
8976 | /**
|
8977 | * Updates fields in the document referred to by the provided
|
8978 | * `DocumentReference`. The update will fail if applied to a document that
|
8979 | * does not exist.
|
8980 | *
|
8981 | * Nested fields can be updated by providing dot-separated field path
|
8982 | * strings or by providing FieldPath objects.
|
8983 | *
|
8984 | * @param documentRef A reference to the document to be updated.
|
8985 | * @param field The first field to update.
|
8986 | * @param value The first value.
|
8987 | * @param moreFieldsAndValues Additional key/value pairs.
|
8988 | * @return A Promise resolved once the data has been successfully written
|
8989 | * to the backend (Note that it won't resolve while you're offline).
|
8990 | */
|
8991 | update(
|
8992 | documentRef: DocumentReference<any>,
|
8993 | field: string | FieldPath,
|
8994 | value: any,
|
8995 | ...moreFieldsAndValues: any[]
|
8996 | ): Transaction;
|
8997 |
|
8998 | /**
|
8999 | * Deletes the document referred to by the provided `DocumentReference`.
|
9000 | *
|
9001 | * @param documentRef A reference to the document to be deleted.
|
9002 | * @return This `Transaction` instance. Used for chaining method calls.
|
9003 | */
|
9004 | delete(documentRef: DocumentReference<any>): Transaction;
|
9005 | }
|
9006 |
|
9007 | /**
|
9008 | * A write batch, used to perform multiple writes as a single atomic unit.
|
9009 | *
|
9010 | * A `WriteBatch` object can be acquired by calling `Firestore.batch()`. It
|
9011 | * provides methods for adding writes to the write batch. None of the
|
9012 | * writes will be committed (or visible locally) until `WriteBatch.commit()`
|
9013 | * is called.
|
9014 | *
|
9015 | * Unlike transactions, write batches are persisted offline and therefore are
|
9016 | * preferable when you don't need to condition your writes on read data.
|
9017 | */
|
9018 | export class WriteBatch {
|
9019 | private constructor();
|
9020 |
|
9021 | /**
|
9022 | * Writes to the document referred to by the provided `DocumentReference`.
|
9023 | * If the document does not exist yet, it will be created. If you pass
|
9024 | * `SetOptions`, the provided data can be merged into the existing document.
|
9025 | *
|
9026 | * @param documentRef A reference to the document to be set.
|
9027 | * @param data An object of the fields and values for the document.
|
9028 | * @param options An object to configure the set behavior.
|
9029 | * @return This `WriteBatch` instance. Used for chaining method calls.
|
9030 | */
|
9031 | set<T>(
|
9032 | documentRef: DocumentReference<T>,
|
9033 | data: Partial<T>,
|
9034 | options: SetOptions
|
9035 | ): WriteBatch;
|
9036 |
|
9037 | /**
|
9038 | * Writes to the document referred to by the provided `DocumentReference`.
|
9039 | * If the document does not exist yet, it will be created. If you pass
|
9040 | * `SetOptions`, the provided data can be merged into the existing document.
|
9041 | *
|
9042 | * @param documentRef A reference to the document to be set.
|
9043 | * @param data An object of the fields and values for the document.
|
9044 | * @return This `WriteBatch` instance. Used for chaining method calls.
|
9045 | */
|
9046 | set<T>(documentRef: DocumentReference<T>, data: T): WriteBatch;
|
9047 |
|
9048 | /**
|
9049 | * Updates fields in the document referred to by the provided
|
9050 | * `DocumentReference`. The update will fail if applied to a document that
|
9051 | * does not exist.
|
9052 | *
|
9053 | * @param documentRef A reference to the document to be updated.
|
9054 | * @param data An object containing the fields and values with which to
|
9055 | * update the document. Fields can contain dots to reference nested fields
|
9056 | * within the document.
|
9057 | * @return This `WriteBatch` instance. Used for chaining method calls.
|
9058 | */
|
9059 | update(documentRef: DocumentReference<any>, data: UpdateData): WriteBatch;
|
9060 |
|
9061 | /**
|
9062 | * Updates fields in the document referred to by this `DocumentReference`.
|
9063 | * The update will fail if applied to a document that does not exist.
|
9064 | *
|
9065 | * Nested fields can be update by providing dot-separated field path strings
|
9066 | * or by providing FieldPath objects.
|
9067 | *
|
9068 | * @param documentRef A reference to the document to be updated.
|
9069 | * @param field The first field to update.
|
9070 | * @param value The first value.
|
9071 | * @param moreFieldsAndValues Additional key value pairs.
|
9072 | * @return A Promise resolved once the data has been successfully written
|
9073 | * to the backend (Note that it won't resolve while you're offline).
|
9074 | */
|
9075 | update(
|
9076 | documentRef: DocumentReference<any>,
|
9077 | field: string | FieldPath,
|
9078 | value: any,
|
9079 | ...moreFieldsAndValues: any[]
|
9080 | ): WriteBatch;
|
9081 |
|
9082 | /**
|
9083 | * Deletes the document referred to by the provided `DocumentReference`.
|
9084 | *
|
9085 | * @param documentRef A reference to the document to be deleted.
|
9086 | * @return This `WriteBatch` instance. Used for chaining method calls.
|
9087 | */
|
9088 | delete(documentRef: DocumentReference<any>): WriteBatch;
|
9089 |
|
9090 | /**
|
9091 | * Commits all of the writes in this write batch as a single atomic unit.
|
9092 | *
|
9093 | * @return A Promise resolved once all of the writes in the batch have been
|
9094 | * successfully written to the backend as an atomic unit. Note that it won't
|
9095 | * resolve while you're offline.
|
9096 | */
|
9097 | commit(): Promise<void>;
|
9098 | }
|
9099 |
|
9100 | /**
|
9101 | * An options object that can be passed to `DocumentReference.onSnapshot()`,
|
9102 | * `Query.onSnapshot()` and `QuerySnapshot.docChanges()` to control which
|
9103 | * types of changes to include in the result set.
|
9104 | */
|
9105 | export interface SnapshotListenOptions {
|
9106 | /**
|
9107 | * Include a change even if only the metadata of the query or of a document
|
9108 | * changed. Default is false.
|
9109 | */
|
9110 | readonly includeMetadataChanges?: boolean;
|
9111 | }
|
9112 |
|
9113 | /**
|
9114 | * An options object that configures the behavior of `set()` calls in
|
9115 | * {@link firebase.firestore.DocumentReference.set DocumentReference}, {@link
|
9116 | * firebase.firestore.WriteBatch.set WriteBatch} and {@link
|
9117 | * firebase.firestore.Transaction.set Transaction}. These calls can be
|
9118 | * configured to perform granular merges instead of overwriting the target
|
9119 | * documents in their entirety by providing a `SetOptions` with `merge: true`.
|
9120 | */
|
9121 | export interface SetOptions {
|
9122 | /**
|
9123 | * Changes the behavior of a set() call to only replace the values specified
|
9124 | * in its data argument. Fields omitted from the set() call remain
|
9125 | * untouched.
|
9126 | */
|
9127 | readonly merge?: boolean;
|
9128 |
|
9129 | /**
|
9130 | * Changes the behavior of set() calls to only replace the specified field
|
9131 | * paths. Any field path that is not specified is ignored and remains
|
9132 | * untouched.
|
9133 | */
|
9134 | readonly mergeFields?: (string | FieldPath)[];
|
9135 | }
|
9136 |
|
9137 | /**
|
9138 | * An options object that configures the behavior of `get()` calls on
|
9139 | * `DocumentReference` and `Query`. By providing a `GetOptions` object, these
|
9140 | * methods can be configured to fetch results only from the server, only from
|
9141 | * the local cache or attempt to fetch results from the server and fall back to
|
9142 | * the cache (which is the default).
|
9143 | */
|
9144 | export interface GetOptions {
|
9145 | /**
|
9146 | * Describes whether we should get from server or cache.
|
9147 | *
|
9148 | * Setting to `default` (or not setting at all), causes Firestore to try to
|
9149 | * retrieve an up-to-date (server-retrieved) snapshot, but fall back to
|
9150 | * returning cached data if the server can't be reached.
|
9151 | *
|
9152 | * Setting to `server` causes Firestore to avoid the cache, generating an
|
9153 | * error if the server cannot be reached. Note that the cache will still be
|
9154 | * updated if the server request succeeds. Also note that latency-compensation
|
9155 | * still takes effect, so any pending write operations will be visible in the
|
9156 | * returned data (merged into the server-provided data).
|
9157 | *
|
9158 | * Setting to `cache` causes Firestore to immediately return a value from the
|
9159 | * cache, ignoring the server completely (implying that the returned value
|
9160 | * may be stale with respect to the value on the server.) If there is no data
|
9161 | * in the cache to satisfy the `get()` call, `DocumentReference.get()` will
|
9162 | * return an error and `QuerySnapshot.get()` will return an empty
|
9163 | * `QuerySnapshot` with no documents.
|
9164 | */
|
9165 | readonly source?: 'default' | 'server' | 'cache';
|
9166 | }
|
9167 |
|
9168 | /**
|
9169 | * A `DocumentReference` refers to a document location in a Firestore database
|
9170 | * and can be used to write, read, or listen to the location. The document at
|
9171 | * the referenced location may or may not exist. A `DocumentReference` can
|
9172 | * also be used to create a `CollectionReference` to a subcollection.
|
9173 | */
|
9174 | export class DocumentReference<T = DocumentData> {
|
9175 | private constructor();
|
9176 |
|
9177 | /**
|
9178 | * The document's identifier within its collection.
|
9179 | */
|
9180 | readonly id: string;
|
9181 |
|
9182 | /**
|
9183 | * The {@link firebase.firestore.Firestore} the document is in.
|
9184 | * This is useful for performing transactions, for example.
|
9185 | */
|
9186 | readonly firestore: Firestore;
|
9187 |
|
9188 | /**
|
9189 | * The Collection this `DocumentReference` belongs to.
|
9190 | */
|
9191 | readonly parent: CollectionReference<T>;
|
9192 |
|
9193 | /**
|
9194 | * A string representing the path of the referenced document (relative
|
9195 | * to the root of the database).
|
9196 | */
|
9197 | readonly path: string;
|
9198 |
|
9199 | /**
|
9200 | * Gets a `CollectionReference` instance that refers to the collection at
|
9201 | * the specified path.
|
9202 | *
|
9203 | * @param collectionPath A slash-separated path to a collection.
|
9204 | * @return The `CollectionReference` instance.
|
9205 | */
|
9206 | collection(collectionPath: string): CollectionReference<DocumentData>;
|
9207 |
|
9208 | /**
|
9209 | * Returns true if this `DocumentReference` is equal to the provided one.
|
9210 | *
|
9211 | * @param other The `DocumentReference` to compare against.
|
9212 | * @return true if this `DocumentReference` is equal to the provided one.
|
9213 | */
|
9214 | isEqual(other: DocumentReference<T>): boolean;
|
9215 |
|
9216 | /**
|
9217 | * Writes to the document referred to by this `DocumentReference`. If the
|
9218 | * document does not yet exist, it will be created. If you pass
|
9219 | * `SetOptions`, the provided data can be merged into an existing document.
|
9220 | *
|
9221 | * @param data A map of the fields and values for the document.
|
9222 | * @param options An object to configure the set behavior.
|
9223 | * @return A Promise resolved once the data has been successfully written
|
9224 | * to the backend (Note that it won't resolve while you're offline).
|
9225 | */
|
9226 | set(data: Partial<T>, options: SetOptions): Promise<void>;
|
9227 |
|
9228 | /**
|
9229 | * Writes to the document referred to by this `DocumentReference`. If the
|
9230 | * document does not yet exist, it will be created. If you pass
|
9231 | * `SetOptions`, the provided data can be merged into an existing document.
|
9232 | *
|
9233 | * @param data A map of the fields and values for the document.
|
9234 | * @return A Promise resolved once the data has been successfully written
|
9235 | * to the backend (Note that it won't resolve while you're offline).
|
9236 | */
|
9237 | set(data: T): Promise<void>;
|
9238 |
|
9239 | /**
|
9240 | * Updates fields in the document referred to by this `DocumentReference`.
|
9241 | * The update will fail if applied to a document that does not exist.
|
9242 | *
|
9243 | * @param data An object containing the fields and values with which to
|
9244 | * update the document. Fields can contain dots to reference nested fields
|
9245 | * within the document.
|
9246 | * @return A Promise resolved once the data has been successfully written
|
9247 | * to the backend (Note that it won't resolve while you're offline).
|
9248 | */
|
9249 | update(data: UpdateData): Promise<void>;
|
9250 |
|
9251 | /**
|
9252 | * Updates fields in the document referred to by this `DocumentReference`.
|
9253 | * The update will fail if applied to a document that does not exist.
|
9254 | *
|
9255 | * Nested fields can be updated by providing dot-separated field path
|
9256 | * strings or by providing FieldPath objects.
|
9257 | *
|
9258 | * @param field The first field to update.
|
9259 | * @param value The first value.
|
9260 | * @param moreFieldsAndValues Additional key value pairs.
|
9261 | * @return A Promise resolved once the data has been successfully written
|
9262 | * to the backend (Note that it won't resolve while you're offline).
|
9263 | */
|
9264 | update(
|
9265 | field: string | FieldPath,
|
9266 | value: any,
|
9267 | ...moreFieldsAndValues: any[]
|
9268 | ): Promise<void>;
|
9269 |
|
9270 | /**
|
9271 | * Deletes the document referred to by this `DocumentReference`.
|
9272 | *
|
9273 | * @return A Promise resolved once the document has been successfully
|
9274 | * deleted from the backend (Note that it won't resolve while you're
|
9275 | * offline).
|
9276 | */
|
9277 | delete(): Promise<void>;
|
9278 |
|
9279 | /**
|
9280 | * Reads the document referred to by this `DocumentReference`.
|
9281 | *
|
9282 | * Note: By default, get() attempts to provide up-to-date data when possible
|
9283 | * by waiting for data from the server, but it may return cached data or fail
|
9284 | * if you are offline and the server cannot be reached. This behavior can be
|
9285 | * altered via the `GetOptions` parameter.
|
9286 | *
|
9287 | * @param options An object to configure the get behavior.
|
9288 | * @return A Promise resolved with a DocumentSnapshot containing the
|
9289 | * current document contents.
|
9290 | */
|
9291 | get(options?: GetOptions): Promise<DocumentSnapshot<T>>;
|
9292 |
|
9293 | /**
|
9294 | * Attaches a listener for DocumentSnapshot events. You may either pass
|
9295 | * individual `onNext` and `onError` callbacks or pass a single observer
|
9296 | * object with `next` and `error` callbacks.
|
9297 | *
|
9298 | * NOTE: Although an `onCompletion` callback can be provided, it will
|
9299 | * never be called because the snapshot stream is never-ending.
|
9300 | *
|
9301 | * @param observer A single object containing `next` and `error` callbacks.
|
9302 | * @return An unsubscribe function that can be called to cancel
|
9303 | * the snapshot listener.
|
9304 | */
|
9305 | onSnapshot(observer: {
|
9306 | next?: (snapshot: DocumentSnapshot<T>) => void;
|
9307 | error?: (error: FirestoreError) => void;
|
9308 | complete?: () => void;
|
9309 | }): () => void;
|
9310 | /**
|
9311 | * Attaches a listener for DocumentSnapshot events. You may either pass
|
9312 | * individual `onNext` and `onError` callbacks or pass a single observer
|
9313 | * object with `next` and `error` callbacks.
|
9314 | *
|
9315 | * NOTE: Although an `onCompletion` callback can be provided, it will
|
9316 | * never be called because the snapshot stream is never-ending.
|
9317 | *
|
9318 | * @param options Options controlling the listen behavior.
|
9319 | * @param observer A single object containing `next` and `error` callbacks.
|
9320 | * @return An unsubscribe function that can be called to cancel
|
9321 | * the snapshot listener.
|
9322 | */
|
9323 | onSnapshot(
|
9324 | options: SnapshotListenOptions,
|
9325 | observer: {
|
9326 | next?: (snapshot: DocumentSnapshot<T>) => void;
|
9327 | error?: (error: FirestoreError) => void;
|
9328 | complete?: () => void;
|
9329 | }
|
9330 | ): () => void;
|
9331 | /**
|
9332 | * Attaches a listener for DocumentSnapshot events. You may either pass
|
9333 | * individual `onNext` and `onError` callbacks or pass a single observer
|
9334 | * object with `next` and `error` callbacks.
|
9335 | *
|
9336 | * NOTE: Although an `onCompletion` callback can be provided, it will
|
9337 | * never be called because the snapshot stream is never-ending.
|
9338 | *
|
9339 | * @param onNext A callback to be called every time a new `DocumentSnapshot`
|
9340 | * is available.
|
9341 | * @param onError A callback to be called if the listen fails or is
|
9342 | * cancelled. No further callbacks will occur.
|
9343 | * @return An unsubscribe function that can be called to cancel
|
9344 | * the snapshot listener.
|
9345 | */
|
9346 | onSnapshot(
|
9347 | onNext: (snapshot: DocumentSnapshot<T>) => void,
|
9348 | onError?: (error: FirestoreError) => void,
|
9349 | onCompletion?: () => void
|
9350 | ): () => void;
|
9351 | /**
|
9352 | * Attaches a listener for DocumentSnapshot events. You may either pass
|
9353 | * individual `onNext` and `onError` callbacks or pass a single observer
|
9354 | * object with `next` and `error` callbacks.
|
9355 | *
|
9356 | * NOTE: Although an `onCompletion` callback can be provided, it will
|
9357 | * never be called because the snapshot stream is never-ending.
|
9358 | *
|
9359 | * @param options Options controlling the listen behavior.
|
9360 | * @param onNext A callback to be called every time a new `DocumentSnapshot`
|
9361 | * is available.
|
9362 | * @param onError A callback to be called if the listen fails or is
|
9363 | * cancelled. No further callbacks will occur.
|
9364 | * @return An unsubscribe function that can be called to cancel
|
9365 | * the snapshot listener.
|
9366 | */
|
9367 | onSnapshot(
|
9368 | options: SnapshotListenOptions,
|
9369 | onNext: (snapshot: DocumentSnapshot<T>) => void,
|
9370 | onError?: (error: FirestoreError) => void,
|
9371 | onCompletion?: () => void
|
9372 | ): () => void;
|
9373 |
|
9374 | /**
|
9375 | * Applies a custom data converter to this DocumentReference, allowing you
|
9376 | * to use your own custom model objects with Firestore. When you call
|
9377 | * set(), get(), etc. on the returned DocumentReference instance, the
|
9378 | * provided converter will convert between Firestore data and your custom
|
9379 | * type U.
|
9380 | *
|
9381 | * Passing in `null` as the converter parameter removes the current
|
9382 | * converter.
|
9383 | *
|
9384 | * @param converter Converts objects to and from Firestore. Passing in
|
9385 | * `null` removes the current converter.
|
9386 | * @return A DocumentReference<U> that uses the provided converter.
|
9387 | */
|
9388 | withConverter(converter: null): DocumentReference<DocumentData>;
|
9389 | /**
|
9390 | * Applies a custom data converter to this DocumentReference, allowing you
|
9391 | * to use your own custom model objects with Firestore. When you call
|
9392 | * set(), get(), etc. on the returned DocumentReference instance, the
|
9393 | * provided converter will convert between Firestore data and your custom
|
9394 | * type U.
|
9395 | *
|
9396 | * Passing in `null` as the converter parameter removes the current
|
9397 | * converter.
|
9398 | *
|
9399 | * @param converter Converts objects to and from Firestore. Passing in
|
9400 | * `null` removes the current converter.
|
9401 | * @return A DocumentReference<U> that uses the provided converter.
|
9402 | */
|
9403 | withConverter<U>(
|
9404 | converter: FirestoreDataConverter<U>
|
9405 | ): DocumentReference<U>;
|
9406 | }
|
9407 |
|
9408 | /**
|
9409 | * Options that configure how data is retrieved from a `DocumentSnapshot`
|
9410 | * (e.g. the desired behavior for server timestamps that have not yet been set
|
9411 | * to their final value).
|
9412 | */
|
9413 | export interface SnapshotOptions {
|
9414 | /**
|
9415 | * If set, controls the return value for server timestamps that have not yet
|
9416 | * been set to their final value.
|
9417 | *
|
9418 | * By specifying 'estimate', pending server timestamps return an estimate
|
9419 | * based on the local clock. This estimate will differ from the final value
|
9420 | * and cause these values to change once the server result becomes available.
|
9421 | *
|
9422 | * By specifying 'previous', pending timestamps will be ignored and return
|
9423 | * their previous value instead.
|
9424 | *
|
9425 | * If omitted or set to 'none', `null` will be returned by default until the
|
9426 | * server value becomes available.
|
9427 | */
|
9428 | readonly serverTimestamps?: 'estimate' | 'previous' | 'none';
|
9429 | }
|
9430 |
|
9431 | /**
|
9432 | * Metadata about a snapshot, describing the state of the snapshot.
|
9433 | */
|
9434 | export interface SnapshotMetadata {
|
9435 | /**
|
9436 | * True if the snapshot contains the result of local writes (e.g. set() or
|
9437 | * update() calls) that have not yet been committed to the backend.
|
9438 | * If your listener has opted into metadata updates (via
|
9439 | * `SnapshotListenOptions`) you will receive another
|
9440 | * snapshot with `hasPendingWrites` equal to false once the writes have been
|
9441 | * committed to the backend.
|
9442 | */
|
9443 | readonly hasPendingWrites: boolean;
|
9444 |
|
9445 | /**
|
9446 | * True if the snapshot was created from cached data rather than guaranteed
|
9447 | * up-to-date server data. If your listener has opted into metadata updates
|
9448 | * (via `SnapshotListenOptions`)
|
9449 | * you will receive another snapshot with `fromCache` set to false once
|
9450 | * the client has received up-to-date data from the backend.
|
9451 | */
|
9452 | readonly fromCache: boolean;
|
9453 |
|
9454 | /**
|
9455 | * Returns true if this `SnapshotMetadata` is equal to the provided one.
|
9456 | *
|
9457 | * @param other The `SnapshotMetadata` to compare against.
|
9458 | * @return true if this `SnapshotMetadata` is equal to the provided one.
|
9459 | */
|
9460 | isEqual(other: SnapshotMetadata): boolean;
|
9461 | }
|
9462 |
|
9463 | /**
|
9464 | * A `DocumentSnapshot` contains data read from a document in your Firestore
|
9465 | * database. The data can be extracted with `.data()` or `.get(<field>)` to
|
9466 | * get a specific field.
|
9467 | *
|
9468 | * For a `DocumentSnapshot` that points to a non-existing document, any data
|
9469 | * access will return 'undefined'. You can use the `exists` property to
|
9470 | * explicitly verify a document's existence.
|
9471 | */
|
9472 | export class DocumentSnapshot<T = DocumentData> {
|
9473 | protected constructor();
|
9474 |
|
9475 | /**
|
9476 | * Property of the `DocumentSnapshot` that signals whether or not the data
|
9477 | * exists. True if the document exists.
|
9478 | */
|
9479 | readonly exists: boolean;
|
9480 | /**
|
9481 | * The `DocumentReference` for the document included in the `DocumentSnapshot`.
|
9482 | */
|
9483 | readonly ref: DocumentReference<T>;
|
9484 | /**
|
9485 | * Property of the `DocumentSnapshot` that provides the document's ID.
|
9486 | */
|
9487 | readonly id: string;
|
9488 | /**
|
9489 | * Metadata about the `DocumentSnapshot`, including information about its
|
9490 | * source and local modifications.
|
9491 | */
|
9492 | readonly metadata: SnapshotMetadata;
|
9493 |
|
9494 | /**
|
9495 | * Retrieves all fields in the document as an Object. Returns 'undefined' if
|
9496 | * the document doesn't exist.
|
9497 | *
|
9498 | * By default, `FieldValue.serverTimestamp()` values that have not yet been
|
9499 | * set to their final value will be returned as `null`. You can override
|
9500 | * this by passing an options object.
|
9501 | *
|
9502 | * @param options An options object to configure how data is retrieved from
|
9503 | * the snapshot (e.g. the desired behavior for server timestamps that have
|
9504 | * not yet been set to their final value).
|
9505 | * @return An Object containing all fields in the document or 'undefined' if
|
9506 | * the document doesn't exist.
|
9507 | */
|
9508 | data(options?: SnapshotOptions): T | undefined;
|
9509 |
|
9510 | /**
|
9511 | * Retrieves the field specified by `fieldPath`. Returns `undefined` if the
|
9512 | * document or field doesn't exist.
|
9513 | *
|
9514 | * By default, a `FieldValue.serverTimestamp()` that has not yet been set to
|
9515 | * its final value will be returned as `null`. You can override this by
|
9516 | * passing an options object.
|
9517 | *
|
9518 | * @param fieldPath The path (e.g. 'foo' or 'foo.bar') to a specific field.
|
9519 | * @param options An options object to configure how the field is retrieved
|
9520 | * from the snapshot (e.g. the desired behavior for server timestamps that have
|
9521 | * not yet been set to their final value).
|
9522 | * @return The data at the specified field location or undefined if no such
|
9523 | * field exists in the document.
|
9524 | */
|
9525 | get(fieldPath: string | FieldPath, options?: SnapshotOptions): any;
|
9526 |
|
9527 | /**
|
9528 | * Returns true if this `DocumentSnapshot` is equal to the provided one.
|
9529 | *
|
9530 | * @param other The `DocumentSnapshot` to compare against.
|
9531 | * @return true if this `DocumentSnapshot` is equal to the provided one.
|
9532 | */
|
9533 | isEqual(other: DocumentSnapshot<T>): boolean;
|
9534 | }
|
9535 |
|
9536 | /**
|
9537 | * A `QueryDocumentSnapshot` contains data read from a document in your
|
9538 | * Firestore database as part of a query. The document is guaranteed to exist
|
9539 | * and its data can be extracted with `.data()` or `.get(<field>)` to get a
|
9540 | * specific field.
|
9541 | *
|
9542 | * A `QueryDocumentSnapshot` offers the same API surface as a
|
9543 | * `DocumentSnapshot`. Since query results contain only existing documents, the
|
9544 | * `exists` property will always be true and `data()` will never return
|
9545 | * 'undefined'.
|
9546 | */
|
9547 | export class QueryDocumentSnapshot<
|
9548 | T = DocumentData
|
9549 | > extends DocumentSnapshot<T> {
|
9550 | private constructor();
|
9551 |
|
9552 | /**
|
9553 | * Retrieves all fields in the document as an Object.
|
9554 | *
|
9555 | * By default, `FieldValue.serverTimestamp()` values that have not yet been
|
9556 | * set to their final value will be returned as `null`. You can override
|
9557 | * this by passing an options object.
|
9558 | *
|
9559 | * @override
|
9560 | * @param options An options object to configure how data is retrieved from
|
9561 | * the snapshot (e.g. the desired behavior for server timestamps that have
|
9562 | * not yet been set to their final value).
|
9563 | * @return An Object containing all fields in the document.
|
9564 | */
|
9565 | data(options?: SnapshotOptions): T;
|
9566 | }
|
9567 |
|
9568 | /**
|
9569 | * The direction of a `Query.orderBy()` clause is specified as 'desc' or 'asc'
|
9570 | * (descending or ascending).
|
9571 | */
|
9572 | export type OrderByDirection = 'desc' | 'asc';
|
9573 |
|
9574 | /**
|
9575 | * Filter conditions in a `Query.where()` clause are specified using the
|
9576 | * strings '<', '<=', '==', '!=', '>=', '>', 'array-contains', 'in',
|
9577 | * 'array-contains-any', and 'not-in'.
|
9578 | */
|
9579 | export type WhereFilterOp =
|
9580 | | '<'
|
9581 | | '<='
|
9582 | | '=='
|
9583 | | '!='
|
9584 | | '>='
|
9585 | | '>'
|
9586 | | 'array-contains'
|
9587 | | 'in'
|
9588 | | 'array-contains-any'
|
9589 | | 'not-in';
|
9590 |
|
9591 | /**
|
9592 | * A `Query` refers to a Query which you can read or listen to. You can also
|
9593 | * construct refined `Query` objects by adding filters and ordering.
|
9594 | */
|
9595 | export class Query<T = DocumentData> {
|
9596 | protected constructor();
|
9597 |
|
9598 | /**
|
9599 | * The `Firestore` for the Firestore database (useful for performing
|
9600 | * transactions, etc.).
|
9601 | */
|
9602 | readonly firestore: Firestore;
|
9603 |
|
9604 | /**
|
9605 | * Creates and returns a new Query with the additional filter that documents
|
9606 | * must contain the specified field and the value should satisfy the
|
9607 | * relation constraint provided.
|
9608 | *
|
9609 | * @param fieldPath The path to compare
|
9610 | * @param opStr The operation string (e.g "<", "<=", "==", ">", ">=").
|
9611 | * @param value The value for comparison
|
9612 | * @return The created Query.
|
9613 | */
|
9614 | where(
|
9615 | fieldPath: string | FieldPath,
|
9616 | opStr: WhereFilterOp,
|
9617 | value: any
|
9618 | ): Query<T>;
|
9619 |
|
9620 | /**
|
9621 | * Creates and returns a new Query that's additionally sorted by the
|
9622 | * specified field, optionally in descending order instead of ascending.
|
9623 | *
|
9624 | * @param fieldPath The field to sort by.
|
9625 | * @param directionStr Optional direction to sort by (`asc` or `desc`). If
|
9626 | * not specified, order will be ascending.
|
9627 | * @return The created Query.
|
9628 | */
|
9629 | orderBy(
|
9630 | fieldPath: string | FieldPath,
|
9631 | directionStr?: OrderByDirection
|
9632 | ): Query<T>;
|
9633 |
|
9634 | /**
|
9635 | * Creates and returns a new Query that only returns the first matching
|
9636 | * documents.
|
9637 | *
|
9638 | * @param limit The maximum number of items to return.
|
9639 | * @return The created Query.
|
9640 | */
|
9641 | limit(limit: number): Query<T>;
|
9642 |
|
9643 | /**
|
9644 | * Creates and returns a new Query that only returns the last matching
|
9645 | * documents.
|
9646 | *
|
9647 | * You must specify at least one `orderBy` clause for `limitToLast` queries,
|
9648 | * otherwise an exception will be thrown during execution.
|
9649 | *
|
9650 | * @param limit The maximum number of items to return.
|
9651 | * @return The created Query.
|
9652 | */
|
9653 | limitToLast(limit: number): Query<T>;
|
9654 |
|
9655 | /**
|
9656 | * Creates and returns a new Query that starts at the provided document
|
9657 | * (inclusive). The starting position is relative to the order of the query.
|
9658 | * The document must contain all of the fields provided in the `orderBy` of
|
9659 | * this query.
|
9660 | *
|
9661 | * @param snapshot The snapshot of the document to start at.
|
9662 | * @return The created Query.
|
9663 | */
|
9664 | startAt(snapshot: DocumentSnapshot<any>): Query<T>;
|
9665 |
|
9666 | /**
|
9667 | * Creates and returns a new Query that starts at the provided fields
|
9668 | * relative to the order of the query. The order of the field values
|
9669 | * must match the order of the order by clauses of the query.
|
9670 | *
|
9671 | * @param fieldValues The field values to start this query at, in order
|
9672 | * of the query's order by.
|
9673 | * @return The created Query.
|
9674 | */
|
9675 | startAt(...fieldValues: any[]): Query<T>;
|
9676 |
|
9677 | /**
|
9678 | * Creates and returns a new Query that starts after the provided document
|
9679 | * (exclusive). The starting position is relative to the order of the query.
|
9680 | * The document must contain all of the fields provided in the orderBy of
|
9681 | * this query.
|
9682 | *
|
9683 | * @param snapshot The snapshot of the document to start after.
|
9684 | * @return The created Query.
|
9685 | */
|
9686 | startAfter(snapshot: DocumentSnapshot<any>): Query<T>;
|
9687 |
|
9688 | /**
|
9689 | * Creates and returns a new Query that starts after the provided fields
|
9690 | * relative to the order of the query. The order of the field values
|
9691 | * must match the order of the order by clauses of the query.
|
9692 | *
|
9693 | * @param fieldValues The field values to start this query after, in order
|
9694 | * of the query's order by.
|
9695 | * @return The created Query.
|
9696 | */
|
9697 | startAfter(...fieldValues: any[]): Query<T>;
|
9698 |
|
9699 | /**
|
9700 | * Creates and returns a new Query that ends before the provided document
|
9701 | * (exclusive). The end position is relative to the order of the query. The
|
9702 | * document must contain all of the fields provided in the orderBy of this
|
9703 | * query.
|
9704 | *
|
9705 | * @param snapshot The snapshot of the document to end before.
|
9706 | * @return The created Query.
|
9707 | */
|
9708 | endBefore(snapshot: DocumentSnapshot<any>): Query<T>;
|
9709 |
|
9710 | /**
|
9711 | * Creates and returns a new Query that ends before the provided fields
|
9712 | * relative to the order of the query. The order of the field values
|
9713 | * must match the order of the order by clauses of the query.
|
9714 | *
|
9715 | * @param fieldValues The field values to end this query before, in order
|
9716 | * of the query's order by.
|
9717 | * @return The created Query.
|
9718 | */
|
9719 | endBefore(...fieldValues: any[]): Query<T>;
|
9720 |
|
9721 | /**
|
9722 | * Creates and returns a new Query that ends at the provided document
|
9723 | * (inclusive). The end position is relative to the order of the query. The
|
9724 | * document must contain all of the fields provided in the orderBy of this
|
9725 | * query.
|
9726 | *
|
9727 | * @param snapshot The snapshot of the document to end at.
|
9728 | * @return The created Query.
|
9729 | */
|
9730 | endAt(snapshot: DocumentSnapshot<any>): Query<T>;
|
9731 |
|
9732 | /**
|
9733 | * Creates and returns a new Query that ends at the provided fields
|
9734 | * relative to the order of the query. The order of the field values
|
9735 | * must match the order of the order by clauses of the query.
|
9736 | *
|
9737 | * @param fieldValues The field values to end this query at, in order
|
9738 | * of the query's order by.
|
9739 | * @return The created Query.
|
9740 | */
|
9741 | endAt(...fieldValues: any[]): Query<T>;
|
9742 |
|
9743 | /**
|
9744 | * Returns true if this `Query` is equal to the provided one.
|
9745 | *
|
9746 | * @param other The `Query` to compare against.
|
9747 | * @return true if this `Query` is equal to the provided one.
|
9748 | */
|
9749 | isEqual(other: Query<T>): boolean;
|
9750 |
|
9751 | /**
|
9752 | * Executes the query and returns the results as a `QuerySnapshot`.
|
9753 | *
|
9754 | * Note: By default, get() attempts to provide up-to-date data when possible
|
9755 | * by waiting for data from the server, but it may return cached data or fail
|
9756 | * if you are offline and the server cannot be reached. This behavior can be
|
9757 | * altered via the `GetOptions` parameter.
|
9758 | *
|
9759 | * @param options An object to configure the get behavior.
|
9760 | * @return A Promise that will be resolved with the results of the Query.
|
9761 | */
|
9762 | get(options?: GetOptions): Promise<QuerySnapshot<T>>;
|
9763 |
|
9764 | /**
|
9765 | * Attaches a listener for QuerySnapshot events. You may either pass
|
9766 | * individual `onNext` and `onError` callbacks or pass a single observer
|
9767 | * object with `next` and `error` callbacks. The listener can be cancelled by
|
9768 | * calling the function that is returned when `onSnapshot` is called.
|
9769 | *
|
9770 | * NOTE: Although an `onCompletion` callback can be provided, it will
|
9771 | * never be called because the snapshot stream is never-ending.
|
9772 | *
|
9773 | * @param observer A single object containing `next` and `error` callbacks.
|
9774 | * @return An unsubscribe function that can be called to cancel
|
9775 | * the snapshot listener.
|
9776 | */
|
9777 | onSnapshot(observer: {
|
9778 | next?: (snapshot: QuerySnapshot<T>) => void;
|
9779 | error?: (error: FirestoreError) => void;
|
9780 | complete?: () => void;
|
9781 | }): () => void;
|
9782 | /**
|
9783 | * Attaches a listener for QuerySnapshot events. You may either pass
|
9784 | * individual `onNext` and `onError` callbacks or pass a single observer
|
9785 | * object with `next` and `error` callbacks. The listener can be cancelled by
|
9786 | * calling the function that is returned when `onSnapshot` is called.
|
9787 | *
|
9788 | * NOTE: Although an `onCompletion` callback can be provided, it will
|
9789 | * never be called because the snapshot stream is never-ending.
|
9790 | *
|
9791 | * @param options Options controlling the listen behavior.
|
9792 | * @param observer A single object containing `next` and `error` callbacks.
|
9793 | * @return An unsubscribe function that can be called to cancel
|
9794 | * the snapshot listener.
|
9795 | */
|
9796 | onSnapshot(
|
9797 | options: SnapshotListenOptions,
|
9798 | observer: {
|
9799 | next?: (snapshot: QuerySnapshot<T>) => void;
|
9800 | error?: (error: FirestoreError) => void;
|
9801 | complete?: () => void;
|
9802 | }
|
9803 | ): () => void;
|
9804 | /**
|
9805 | * Attaches a listener for QuerySnapshot events. You may either pass
|
9806 | * individual `onNext` and `onError` callbacks or pass a single observer
|
9807 | * object with `next` and `error` callbacks. The listener can be cancelled by
|
9808 | * calling the function that is returned when `onSnapshot` is called.
|
9809 | *
|
9810 | * NOTE: Although an `onCompletion` callback can be provided, it will
|
9811 | * never be called because the snapshot stream is never-ending.
|
9812 | *
|
9813 | * @param onNext A callback to be called every time a new `QuerySnapshot`
|
9814 | * is available.
|
9815 | * @param onError A callback to be called if the listen fails or is
|
9816 | * cancelled. No further callbacks will occur.
|
9817 | * @return An unsubscribe function that can be called to cancel
|
9818 | * the snapshot listener.
|
9819 | */
|
9820 | onSnapshot(
|
9821 | onNext: (snapshot: QuerySnapshot<T>) => void,
|
9822 | onError?: (error: FirestoreError) => void,
|
9823 | onCompletion?: () => void
|
9824 | ): () => void;
|
9825 | /**
|
9826 | * Attaches a listener for QuerySnapshot events. You may either pass
|
9827 | * individual `onNext` and `onError` callbacks or pass a single observer
|
9828 | * object with `next` and `error` callbacks. The listener can be cancelled by
|
9829 | * calling the function that is returned when `onSnapshot` is called.
|
9830 | *
|
9831 | * NOTE: Although an `onCompletion` callback can be provided, it will
|
9832 | * never be called because the snapshot stream is never-ending.
|
9833 | *
|
9834 | * @param options Options controlling the listen behavior.
|
9835 | * @param onNext A callback to be called every time a new `QuerySnapshot`
|
9836 | * is available.
|
9837 | * @param onError A callback to be called if the listen fails or is
|
9838 | * cancelled. No further callbacks will occur.
|
9839 | * @return An unsubscribe function that can be called to cancel
|
9840 | * the snapshot listener.
|
9841 | */
|
9842 | onSnapshot(
|
9843 | options: SnapshotListenOptions,
|
9844 | onNext: (snapshot: QuerySnapshot<T>) => void,
|
9845 | onError?: (error: FirestoreError) => void,
|
9846 | onCompletion?: () => void
|
9847 | ): () => void;
|
9848 |
|
9849 | /**
|
9850 | * Applies a custom data converter to this Query, allowing you to use your
|
9851 | * own custom model objects with Firestore. When you call get() on the
|
9852 | * returned Query, the provided converter will convert between Firestore
|
9853 | * data and your custom type U.
|
9854 | *
|
9855 | * Passing in `null` as the converter parameter removes the current
|
9856 | * converter.
|
9857 | *
|
9858 | * @param converter Converts objects to and from Firestore. Passing in
|
9859 | * `null` removes the current converter.
|
9860 | * @return A Query<U> that uses the provided converter.
|
9861 | */
|
9862 | withConverter(converter: null): Query<DocumentData>;
|
9863 | /**
|
9864 | * Applies a custom data converter to this Query, allowing you to use your
|
9865 | * own custom model objects with Firestore. When you call get() on the
|
9866 | * returned Query, the provided converter will convert between Firestore
|
9867 | * data and your custom type U.
|
9868 | *
|
9869 | * Passing in `null` as the converter parameter removes the current
|
9870 | * converter.
|
9871 | *
|
9872 | * @param converter Converts objects to and from Firestore. Passing in
|
9873 | * `null` removes the current converter.
|
9874 | * @return A Query<U> that uses the provided converter.
|
9875 | */
|
9876 | withConverter<U>(converter: FirestoreDataConverter<U>): Query<U>;
|
9877 | }
|
9878 |
|
9879 | /**
|
9880 | * A `QuerySnapshot` contains zero or more `DocumentSnapshot` objects
|
9881 | * representing the results of a query. The documents can be accessed as an
|
9882 | * array via the `docs` property or enumerated using the `forEach` method. The
|
9883 | * number of documents can be determined via the `empty` and `size`
|
9884 | * properties.
|
9885 | */
|
9886 | export class QuerySnapshot<T = DocumentData> {
|
9887 | private constructor();
|
9888 |
|
9889 | /**
|
9890 | * The query on which you called `get` or `onSnapshot` in order to get this
|
9891 | * `QuerySnapshot`.
|
9892 | */
|
9893 | readonly query: Query<T>;
|
9894 | /**
|
9895 | * Metadata about this snapshot, concerning its source and if it has local
|
9896 | * modifications.
|
9897 | */
|
9898 | readonly metadata: SnapshotMetadata;
|
9899 |
|
9900 | /** An array of all the documents in the `QuerySnapshot`. */
|
9901 | readonly docs: Array<QueryDocumentSnapshot<T>>;
|
9902 |
|
9903 | /** The number of documents in the `QuerySnapshot`. */
|
9904 | readonly size: number;
|
9905 |
|
9906 | /** True if there are no documents in the `QuerySnapshot`. */
|
9907 | readonly empty: boolean;
|
9908 |
|
9909 | /**
|
9910 | * Returns an array of the documents changes since the last snapshot. If this
|
9911 | * is the first snapshot, all documents will be in the list as added changes.
|
9912 | *
|
9913 | * @param options `SnapshotListenOptions` that control whether metadata-only
|
9914 | * changes (i.e. only `DocumentSnapshot.metadata` changed) should trigger
|
9915 | * snapshot events.
|
9916 | */
|
9917 | docChanges(options?: SnapshotListenOptions): Array<DocumentChange<T>>;
|
9918 |
|
9919 | /**
|
9920 | * Enumerates all of the documents in the `QuerySnapshot`.
|
9921 | *
|
9922 | * @param callback A callback to be called with a `QueryDocumentSnapshot` for
|
9923 | * each document in the snapshot.
|
9924 | * @param thisArg The `this` binding for the callback.
|
9925 | */
|
9926 | forEach(
|
9927 | callback: (result: QueryDocumentSnapshot<T>) => void,
|
9928 | thisArg?: any
|
9929 | ): void;
|
9930 |
|
9931 | /**
|
9932 | * Returns true if this `QuerySnapshot` is equal to the provided one.
|
9933 | *
|
9934 | * @param other The `QuerySnapshot` to compare against.
|
9935 | * @return true if this `QuerySnapshot` is equal to the provided one.
|
9936 | */
|
9937 | isEqual(other: QuerySnapshot<T>): boolean;
|
9938 | }
|
9939 |
|
9940 | /**
|
9941 | * The type of a `DocumentChange` may be 'added', 'removed', or 'modified'.
|
9942 | */
|
9943 | export type DocumentChangeType = 'added' | 'removed' | 'modified';
|
9944 |
|
9945 | /**
|
9946 | * A `DocumentChange` represents a change to the documents matching a query.
|
9947 | * It contains the document affected and the type of change that occurred.
|
9948 | */
|
9949 | export interface DocumentChange<T = DocumentData> {
|
9950 | /** The type of change ('added', 'modified', or 'removed'). */
|
9951 | readonly type: DocumentChangeType;
|
9952 |
|
9953 | /** The document affected by this change. */
|
9954 | readonly doc: QueryDocumentSnapshot<T>;
|
9955 |
|
9956 | /**
|
9957 | * The index of the changed document in the result set immediately prior to
|
9958 | * this `DocumentChange` (i.e. supposing that all prior `DocumentChange` objects
|
9959 | * have been applied). Is -1 for 'added' events.
|
9960 | */
|
9961 | readonly oldIndex: number;
|
9962 |
|
9963 | /**
|
9964 | * The index of the changed document in the result set immediately after
|
9965 | * this `DocumentChange` (i.e. supposing that all prior `DocumentChange`
|
9966 | * objects and the current `DocumentChange` object have been applied).
|
9967 | * Is -1 for 'removed' events.
|
9968 | */
|
9969 | readonly newIndex: number;
|
9970 | }
|
9971 |
|
9972 | /**
|
9973 | * A `CollectionReference` object can be used for adding documents, getting
|
9974 | * document references, and querying for documents (using the methods
|
9975 | * inherited from `Query`).
|
9976 | */
|
9977 | export class CollectionReference<T = DocumentData> extends Query<T> {
|
9978 | private constructor();
|
9979 |
|
9980 | /** The collection's identifier. */
|
9981 | readonly id: string;
|
9982 |
|
9983 | /**
|
9984 | * A reference to the containing `DocumentReference` if this is a subcollection.
|
9985 | * If this isn't a subcollection, the reference is null.
|
9986 | */
|
9987 | readonly parent: DocumentReference<DocumentData> | null;
|
9988 |
|
9989 | /**
|
9990 | * A string representing the path of the referenced collection (relative
|
9991 | * to the root of the database).
|
9992 | */
|
9993 | readonly path: string;
|
9994 |
|
9995 | /**
|
9996 | * Get a `DocumentReference` for the document within the collection at the
|
9997 | * specified path. If no path is specified, an automatically-generated
|
9998 | * unique ID will be used for the returned DocumentReference.
|
9999 | *
|
10000 | * @param documentPath A slash-separated path to a document.
|
10001 | * @return The `DocumentReference` instance.
|
10002 | */
|
10003 | doc(documentPath?: string): DocumentReference<T>;
|
10004 |
|
10005 | /**
|
10006 | * Add a new document to this collection with the specified data, assigning
|
10007 | * it a document ID automatically.
|
10008 | *
|
10009 | * @param data An Object containing the data for the new document.
|
10010 | * @return A Promise resolved with a `DocumentReference` pointing to the
|
10011 | * newly created document after it has been written to the backend.
|
10012 | */
|
10013 | add(data: T): Promise<DocumentReference<T>>;
|
10014 |
|
10015 | /**
|
10016 | * Returns true if this `CollectionReference` is equal to the provided one.
|
10017 | *
|
10018 | * @param other The `CollectionReference` to compare against.
|
10019 | * @return true if this `CollectionReference` is equal to the provided one.
|
10020 | */
|
10021 | isEqual(other: CollectionReference<T>): boolean;
|
10022 |
|
10023 | /**
|
10024 | * Applies a custom data converter to this CollectionReference, allowing you
|
10025 | * to use your own custom model objects with Firestore. When you call add()
|
10026 | * on the returned CollectionReference instance, the provided converter will
|
10027 | * convert between Firestore data and your custom type U.
|
10028 | *
|
10029 | * Passing in `null` as the converter parameter removes the current
|
10030 | * converter.
|
10031 | *
|
10032 | * @param converter Converts objects to and from Firestore. Passing in
|
10033 | * `null` removes the current converter.
|
10034 | * @return A CollectionReference<U> that uses the provided converter.
|
10035 | */
|
10036 | withConverter(converter: null): CollectionReference<DocumentData>;
|
10037 | /**
|
10038 | * Applies a custom data converter to this CollectionReference, allowing you
|
10039 | * to use your own custom model objects with Firestore. When you call add()
|
10040 | * on the returned CollectionReference instance, the provided converter will
|
10041 | * convert between Firestore data and your custom type U.
|
10042 | *
|
10043 | * Passing in `null` as the converter parameter removes the current
|
10044 | * converter.
|
10045 | *
|
10046 | * @param converter Converts objects to and from Firestore. Passing in
|
10047 | * `null` removes the current converter.
|
10048 | * @return A CollectionReference<U> that uses the provided converter.
|
10049 | */
|
10050 | withConverter<U>(
|
10051 | converter: FirestoreDataConverter<U>
|
10052 | ): CollectionReference<U>;
|
10053 | }
|
10054 |
|
10055 | /**
|
10056 | * Sentinel values that can be used when writing document fields with `set()`
|
10057 | * or `update()`.
|
10058 | */
|
10059 | export class FieldValue {
|
10060 | private constructor();
|
10061 |
|
10062 | /**
|
10063 | * Returns a sentinel used with `set()` or `update()` to include a
|
10064 | * server-generated timestamp in the written data.
|
10065 | */
|
10066 | static serverTimestamp(): FieldValue;
|
10067 |
|
10068 | /**
|
10069 | * Returns a sentinel for use with `update()` to mark a field for deletion.
|
10070 | */
|
10071 | static delete(): FieldValue;
|
10072 |
|
10073 | /**
|
10074 | * Returns a special value that can be used with `set()` or `update()` that tells
|
10075 | * the server to union the given elements with any array value that already
|
10076 | * exists on the server. Each specified element that doesn't already exist in
|
10077 | * the array will be added to the end. If the field being modified is not
|
10078 | * already an array it will be overwritten with an array containing exactly
|
10079 | * the specified elements.
|
10080 | *
|
10081 | * @param elements The elements to union into the array.
|
10082 | * @return The FieldValue sentinel for use in a call to `set()` or `update()`.
|
10083 | */
|
10084 | static arrayUnion(...elements: any[]): FieldValue;
|
10085 |
|
10086 | /**
|
10087 | * Returns a special value that can be used with `set()` or `update()` that tells
|
10088 | * the server to remove the given elements from any array value that already
|
10089 | * exists on the server. All instances of each element specified will be
|
10090 | * removed from the array. If the field being modified is not already an
|
10091 | * array it will be overwritten with an empty array.
|
10092 | *
|
10093 | * @param elements The elements to remove from the array.
|
10094 | * @return The FieldValue sentinel for use in a call to `set()` or `update()`.
|
10095 | */
|
10096 | static arrayRemove(...elements: any[]): FieldValue;
|
10097 |
|
10098 | /**
|
10099 | * Returns a special value that can be used with `set()` or `update()` that tells
|
10100 | * the server to increment the field's current value by the given value.
|
10101 | *
|
10102 | * If either the operand or the current field value uses floating point precision,
|
10103 | * all arithmetic follows IEEE 754 semantics. If both values are integers,
|
10104 | * values outside of JavaScript's safe number range (`Number.MIN_SAFE_INTEGER` to
|
10105 | * `Number.MAX_SAFE_INTEGER`) are also subject to precision loss. Furthermore,
|
10106 | * once processed by the Firestore backend, all integer operations are capped
|
10107 | * between -2^63 and 2^63-1.
|
10108 | *
|
10109 | * If the current field value is not of type `number`, or if the field does not
|
10110 | * yet exist, the transformation sets the field to the given value.
|
10111 | *
|
10112 | * @param n The value to increment by.
|
10113 | * @return The FieldValue sentinel for use in a call to `set()` or `update()`.
|
10114 | */
|
10115 | static increment(n: number): FieldValue;
|
10116 |
|
10117 | /**
|
10118 | * Returns true if this `FieldValue` is equal to the provided one.
|
10119 | *
|
10120 | * @param other The `FieldValue` to compare against.
|
10121 | * @return true if this `FieldValue` is equal to the provided one.
|
10122 | */
|
10123 | isEqual(other: FieldValue): boolean;
|
10124 | }
|
10125 |
|
10126 | /**
|
10127 | * A FieldPath refers to a field in a document. The path may consist of a
|
10128 | * single field name (referring to a top-level field in the document), or a
|
10129 | * list of field names (referring to a nested field in the document).
|
10130 | *
|
10131 | * Create a FieldPath by providing field names. If more than one field
|
10132 | * name is provided, the path will point to a nested field in a document.
|
10133 | *
|
10134 | */
|
10135 | export class FieldPath {
|
10136 | /**
|
10137 | * Creates a FieldPath from the provided field names. If more than one field
|
10138 | * name is provided, the path will point to a nested field in a document.
|
10139 | *
|
10140 | * @param fieldNames A list of field names.
|
10141 | */
|
10142 | constructor(...fieldNames: string[]);
|
10143 |
|
10144 | /**
|
10145 | * Returns a special sentinel `FieldPath` to refer to the ID of a document.
|
10146 | * It can be used in queries to sort or filter by the document ID.
|
10147 | */
|
10148 | static documentId(): FieldPath;
|
10149 |
|
10150 | /**
|
10151 | * Returns true if this `FieldPath` is equal to the provided one.
|
10152 | *
|
10153 | * @param other The `FieldPath` to compare against.
|
10154 | * @return true if this `FieldPath` is equal to the provided one.
|
10155 | */
|
10156 | isEqual(other: FieldPath): boolean;
|
10157 | }
|
10158 |
|
10159 | /**
|
10160 | * The set of Firestore status codes. The codes are the same at the ones
|
10161 | * exposed by gRPC here:
|
10162 | * https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
|
10163 | *
|
10164 | * Possible values:
|
10165 | * - 'cancelled': The operation was cancelled (typically by the caller).
|
10166 | * - 'unknown': Unknown error or an error from a different error domain.
|
10167 | * - 'invalid-argument': Client specified an invalid argument. Note that this
|
10168 | * differs from 'failed-precondition'. 'invalid-argument' indicates
|
10169 | * arguments that are problematic regardless of the state of the system
|
10170 | * (e.g. an invalid field name).
|
10171 | * - 'deadline-exceeded': Deadline expired before operation could complete.
|
10172 | * For operations that change the state of the system, this error may be
|
10173 | * returned even if the operation has completed successfully. For example,
|
10174 | * a successful response from a server could have been delayed long enough
|
10175 | * for the deadline to expire.
|
10176 | * - 'not-found': Some requested document was not found.
|
10177 | * - 'already-exists': Some document that we attempted to create already
|
10178 | * exists.
|
10179 | * - 'permission-denied': The caller does not have permission to execute the
|
10180 | * specified operation.
|
10181 | * - 'resource-exhausted': Some resource has been exhausted, perhaps a
|
10182 | * per-user quota, or perhaps the entire file system is out of space.
|
10183 | * - 'failed-precondition': Operation was rejected because the system is not
|
10184 | * in a state required for the operation's execution.
|
10185 | * - 'aborted': The operation was aborted, typically due to a concurrency
|
10186 | * issue like transaction aborts, etc.
|
10187 | * - 'out-of-range': Operation was attempted past the valid range.
|
10188 | * - 'unimplemented': Operation is not implemented or not supported/enabled.
|
10189 | * - 'internal': Internal errors. Means some invariants expected by
|
10190 | * underlying system has been broken. If you see one of these errors,
|
10191 | * something is very broken.
|
10192 | * - 'unavailable': The service is currently unavailable. This is most likely
|
10193 | * a transient condition and may be corrected by retrying with a backoff.
|
10194 | * - 'data-loss': Unrecoverable data loss or corruption.
|
10195 | * - 'unauthenticated': The request does not have valid authentication
|
10196 | * credentials for the operation.
|
10197 | */
|
10198 | export type FirestoreErrorCode =
|
10199 | | 'cancelled'
|
10200 | | 'unknown'
|
10201 | | 'invalid-argument'
|
10202 | | 'deadline-exceeded'
|
10203 | | 'not-found'
|
10204 | | 'already-exists'
|
10205 | | 'permission-denied'
|
10206 | | 'resource-exhausted'
|
10207 | | 'failed-precondition'
|
10208 | | 'aborted'
|
10209 | | 'out-of-range'
|
10210 | | 'unimplemented'
|
10211 | | 'internal'
|
10212 | | 'unavailable'
|
10213 | | 'data-loss'
|
10214 | | 'unauthenticated';
|
10215 |
|
10216 | /** An error returned by a Firestore operation. */
|
10217 | // TODO(b/63008957): FirestoreError should extend firebase.FirebaseError
|
10218 | export interface FirestoreError {
|
10219 | code: FirestoreErrorCode;
|
10220 | message: string;
|
10221 | name: string;
|
10222 | stack?: string;
|
10223 | }
|
10224 |
|
10225 | export type EmulatorMockTokenOptions = firebase.EmulatorMockTokenOptions;
|
10226 | }
|
10227 |
|
10228 | export default firebase;
|
10229 | export as namespace firebase;
|
10230 |
|
\ | No newline at end of file |