forked from invertase/react-native-firebase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
665 lines (633 loc) · 22.4 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
// Type definitions for React Native Firebase v1.0.0-alpha7
// Project: https://github.com/invertase/react-native-firebase
// Definitions by: Tal <https://github.com/taljacobson>
// TypeScript Version: 2.1
declare module "react-native-firebase" {
export default class FireBase {
constructor(config?: RNFirebase.configurationOptions)
log: any
analytics(): RNFirebase.Analytics;
auth(): RNFirebase.auth.Auth;
on(type: string, handler: (msg: any) => void): any;
/** mimics firebase Web SDK */
database(): RNFirebase.database.Database;
/**RNFirebase mimics the Web Firebase SDK Storage,
* whilst providing some iOS and Android specific functionality.
*/
storage(): RNFirebase.storage.Storage;
/**
* Firebase Cloud Messaging (FCM) allows you to send push messages at no cost to both Android & iOS platforms.
* Assuming the installation instructions have been followed, FCM is ready to go.
* As the Firebase Web SDK has limited messaging functionality,
* the following methods within react-native-firebase have been created to handle FCM in the React Native environment.
*/
messaging(): RNFirebase.messaging.Messaging;
/**
* RNFirebase provides crash reporting for your app out of the box.
* Please note crashes do not appear in real-time on the console,
* they tend to take a number of hours to appear
* If you want to manually report a crash,
* such as a pre-caught exception this is possible by using the report method.
*/
crash(): RNFirebase.crash.Crash;
apps: Array<string>;
googleApiAvailability: RNFirebase.GoogleApiAvailabilityType;
static initializeApp(options?: any | RNFirebase.configurationOptions, name?: string): FireBase;
[key: string]: any;
}
namespace RNFirebase {
interface RnError extends Error {
code?: string;
}
type GoogleApiAvailabilityType = {
status: number,
isAvailable: boolean,
isUserResolvableError?: boolean,
error?: string
};
/**
* pass custom options by passing an object with configuration options.
* The configuration object will be generated first by the native configuration object, if set and then will be overridden if passed in JS.
* That is, all of the following key/value pairs are optional if the native configuration is set.
*/
interface configurationOptions {
/**
* default false
* When set to true, RNFirebase will log messages to the console and fire debug events we can listen to in js
* @usage
* firebase.on('debug', msg => console.log('Received debug message', msg))
*/
debug?: boolean;
/**
* default false
* When set to true, database persistence will be enabled.
*/
persistence?: boolean;
/**
* Default from app [NSBundle mainBundle] The bundle ID for the app to be bundled with
*/
bundleID?: string;
/**
* defualt ""
* The Google App ID that is used to uniquely identify an instance of an app.
*/
googleAppID?: string;
/**
* deufalt ""
* The database root (i.e. https://my-app.firebaseio.com)
*/
databaseURL?: string;
/**
* defualt ""
* URL scheme to set up durable deep link service
*/
deepLinkURLScheme?: string;
/**
* defualt ""
* The Google Cloud storage bucket name
*/
storageBucket?: string;
/**
* default ""
* The Android client ID used in Google AppInvite when an iOS app has it's android version
*/
androidClientID?: string;
/**
* default ""
* The Project number from the Google Developer's console used to configure Google Cloud Messaging
*/
GCMSenderID?: string;
/**
* default ""
* The tracking ID for Google Analytics
*/
trackingID?: string;
/**
* default ""
* The OAuth2 client ID for iOS application used to authenticate Google Users for signing in with Google
*/
clientID?: string;
/**
* defualt ""
* The secret iOS API key used for authenticating requests from our app
*/
APIKey?: string
}
namespace storage {
interface StorageTask<T> extends Promise<T> {
on(
event: TaskEvent,
nextOrObserver: (snapshot: any) => any,
error: (error: RnError) => any,
complete: (complete: any) => any
): any
/**
* is not currently supported by react-native-firebase
*/
pause(): void
/**
* is not currently supported by react-native-firebase
*/
resume(): void
/**
* is not currently supported by react-native-firebase
*/
cancel(): void
}
interface RNStorage extends Reference {
/**
* Downloads a reference to the device
* @param {String} filePath Where to store the file
* @return {Promise}
* */
downloadFile(filePath: string): StorageTask<any>;
/**
* Upload a file path
* @returns {Promise}
*/
putFile(filePath: string, metadata?: any): StorageTask<any>;
setMaxDownloadRetryTime(time: number): void
[key: string]: any;
}
interface Storage {
maxOperationRetryTime: number;
maxUploadRetryTime: number;
ref(path?: string): storage.RNStorage;
refFromURL(url: string): storage.RNStorage;
setMaxOperationRetryTime(time: number): any;
setMaxUploadRetryTime(time: number): any;
}
interface Reference {
bucket: string;
child(path: string): storage.Reference;
delete(): Promise<any>;
fullPath: string;
getDownloadURL(): Promise<any>;
getMetadata(): Promise<any>;
name: string;
parent: storage.Reference | null;
put(data: any | Uint8Array | ArrayBuffer,
metadata?: storage.UploadMetadata):
storage.UploadTask;
putString(
data: string, format?: storage.StringFormat,
metadata?: storage.UploadMetadata):
storage.UploadTask;
root: storage.Reference;
storage: storage.Storage;
toString(): string;
updateMetadata(metadata: storage.SettableMetadata):
Promise<any>;
}
interface UploadMetadata extends storage.SettableMetadata {
md5Hash?: string | null;
}
interface SettableMetadata {
cacheControl?: string | null;
contentDisposition?: string | null;
contentEncoding?: string | null;
contentLanguage?: string | null;
contentType?: string | null;
customMetadata?: { [/* warning: coerced from ? */ key: string]: string } | null;
}
type StringFormat = string;
var StringFormat: {
BASE64: StringFormat,
BASE64URL: StringFormat,
DATA_URL: StringFormat,
RAW: StringFormat,
}
interface UploadTask {
cancel(): boolean;
catch(onRejected: (a: RnError) => any): Promise<any>;
on(event: storage.TaskEvent, nextOrObserver?: null | Object,
error?: ((a: RnError) => any) | null, complete?: (() => any) | null): Function;
pause(): boolean;
resume(): boolean;
snapshot: storage.UploadTaskSnapshot;
then(
onFulfilled?: ((a: storage.UploadTaskSnapshot) => any) | null,
onRejected?: ((a: RnError) => any) | null): Promise<any>;
}
interface UploadTaskSnapshot {
bytesTransferred: number;
downloadURL: string | null;
metadata: storage.FullMetadata;
ref: storage.Reference;
state: storage.TaskState;
task: storage.UploadTask;
totalBytes: number;
}
interface FullMetadata extends storage.UploadMetadata {
bucket: string;
downloadURLs: string[];
fullPath: string;
generation: string;
metageneration: string;
name: string;
size: number;
timeCreated: string;
updated: string;
}
type TaskEvent = string;
var TaskEvent: {
STATE_CHANGED: TaskEvent,
};
type TaskState = string;
var TaskState: {
CANCELED: TaskState,
ERROR: TaskState,
PAUSED: TaskState,
RUNNING: TaskState,
SUCCESS: TaskState,
};
}
namespace database {
interface Database {
/**
* Returns a new firebase reference instance
* */
ref(path?: string): RnReference
/**
* register listener
*/
on(path: string, modifiersString: string, modifiers: Array<string>, eventName: string, cb: () => void, errorCb: () => void): any
/**
* unregister listener
*/
off(path: string, modifiersString: string, eventName?: string, origCB?: () => void): any
/**
* Removes all event handlers and their native subscriptions
*/
cleanup(): Promise<any>
/**
* connect to firebase backend
*/
goOnline(): void
/**
* disconnect to firebase backend
*/
goOffline(): void
[key: string]: any;
}
interface RnReference extends Reference {
keepSynced(bool: boolean): any
filter(name: string, value: any, key?: string): any;
[key: string]: any;
}
interface Query {
endAt(value: number | string | boolean | null, key?: string): database.Query;
equalTo(value: number | string | boolean | null, key?: string): database.Query;
isEqual(other: database.Query | null): boolean;
limitToFirst(limit: number): database.Query;
limitToLast(limit: number): database.Query;
off(eventType?: string,
callback?: (a: database.DataSnapshot, b?: string | null) => any,
context?: Object | null): any;
on(eventType: string,
callback: (a: database.DataSnapshot | null, b?: string) => any,
cancelCallbackOrContext?: Object | null, context?: Object | null):
(a: database.DataSnapshot | null, b?: string) => any;
once(
eventType: string,
successCallback?:
(a: database.DataSnapshot, b?: string) => any,
failureCallbackOrContext?: Object | null,
context?: Object | null): Promise<any>;
orderByChild(path: string): database.Query;
orderByKey(): database.Query;
orderByPriority(): database.Query;
orderByValue(): database.Query;
ref: database.Reference;
startAt(value: number | string | boolean | null, key?: string): database.Query;
toJSON(): Object;
toString(): string;
}
interface DataSnapshot {
child(path: string): database.DataSnapshot;
exists(): boolean;
exportVal(): any;
forEach(action: (a: database.DataSnapshot) => boolean): boolean;
getPriority(): string | number | null;
hasChild(path: string): boolean;
hasChildren(): boolean;
key: string | null;
numChildren(): number;
ref: database.Reference;
toJSON(): Object | null;
val(): any;
}
interface Reference extends database.Query {
child(path: string): database.Reference;
key: string | null;
onDisconnect(): any;
parent: database.Reference | null;
push(value?: any, onComplete?: (a: RnError | null) => any): any
remove(onComplete?: (a: RnError | null) => any): Promise<any>;
root: database.Reference;
set(value: any, onComplete?: (a: RnError | null) => any): Promise<any>;
setPriority(
priority: string | number | null,
onComplete: (a: RnError | null) => any): Promise<any>;
setWithPriority(
newVal: any, newPriority: string | number | null,
onComplete?: (a: RnError | null) => any): Promise<any>;
transaction(
transactionUpdate: (a: any) => any,
onComplete?:
(a: RnError | null, b: boolean,
c: database.DataSnapshot | null) => any,
applyLocally?: boolean): Promise<any>;
update(values: Object, onComplete?: (a: RnError | null) => any): Promise<any>;
}
}
/**
* firebase Analytics
*/
interface Analytics {
/**Log a custom event with optional params. */
logEvent(event: string, params?: Object): void
/** Sets whether analytics collection is enabled for this app on this device. */
setAnalyticsCollectionEnabled(enabled: boolean): void
/**
* Sets the current screen name, which specifies the current visual context in your app.
* Whilst screenClassOverride is optional,
* it is recommended it is always sent as your current class name,
* for example on Android it will always show as 'MainActivity' if not specified.
*/
setCurrentScreen(screenName: string, screenClassOverride?: string): void
/**
* Sets the minimum engagement time required before starting a session.
* The default value is 10000 (10 seconds)
*/
setMinimumSessionDuration(miliseconds: number): void
/**
* Sets the duration of inactivity that terminates the current session.
* The default value is 1800000 (30 minutes).
*/
setSessionTimeoutDuration(miliseconds: number): void
/**
* Gives a user a uniqiue identificaition.
* @example
* const id = firebase.auth().currentUser.uid;
*
* firebase.analytics().setUserId(id);
*/
setUserId(id: string): void
/**
* Sets a key/value pair of data on the current user.
*/
setUserProperty(name: string, value: string): void;
[key: string]: any;
}
interface User {
/**
* The user's display name (if available).
*/
displayName: string | null
/**
* - The user's email address (if available).
*/
email: string | null
/**
* - True if the user's email address has been verified.
*/
emailVerified: boolean
/**
*
*/
isAnonymous: boolean
/**
* - The URL of the user's profile picture (if available).
*/
photoURL: string | null
/**
* - Additional provider-specific information about the user.
*/
providerData: any | null
/**
* - The authentication provider ID for the current user.
* For example, 'facebook.com', or 'google.com'.
*/
providerId: string | null
/**
* - The user's unique ID.
*/
uid: string
/**
* Delete the current user.
*/
delete(): Promise<void>
/**
* Returns the users authentication token.
*/
getToken(): Promise<string>
/**
* Reauthenticate the current user with credentials:
*/
reauthenticate(credential: Credential): Promise<void>
/**
* Refreshes the current user.
*/
reload(): Promise<void>
/**
* Sends a verification email to a user.
* This will Promise reject is the user is anonymous.
*/
sendEmailVerification(): Promise<void>
/**
* Updates the user's email address.
* See Firebase docs for more information on security & email validation.
* This will Promise reject is the user is anonymous.
*/
updateEmail(email: string): Promise<void>
/**
* Important: this is a security sensitive operation that requires the user to have recently signed in.
* If this requirement isn't met, ask the user to authenticate again and then call firebase.User#reauthenticate.
* This will Promise reject is the user is anonymous.
*/
updatePassword(password: string): Promise<void>
/**
* Updates a user's profile data.
* Profile data should be an object of fields to update:
*/
updateProfile(profile: Object): Promise<void>
}
/** 3rd party provider Credentials */
interface Credential {
provider: string,
token: string,
secret: string
}
namespace auth {
interface Auth {
/**
* Returns the current Firebase authentication state.
*/
authenticated: boolean;
/**
* Returns the currently signed-in user (or null). See the User class documentation for further usage.
*/
currentUser: User | null
/**
* Listen for changes in the users auth state (logging in and out).
* This method returns a unsubscribe function to stop listening to events.
* Always ensure you unsubscribe from the listener when no longer needed to prevent updates to components no longer in use.
*/
onAuthStateChanged(
nextOrObserver: Object, error?: (a: RnError) => any,
completed?: () => any): () => any;
/**
* We can create a user by calling the createUserWithEmailAndPassword() function.
* The method accepts two parameters, an email and a password.
*/
createUserWithEmailAndPassword(email: string, password: string): Promise<User>
/**
* To sign a user in with their email and password, use the signInWithEmailAndPassword() function.
* It accepts two parameters, the user's email and password:
*/
signInWithEmailAndPassword(email: string, password: string): Promise<User>
/**
* Sign an anonymous user.
* If the user has already signed in, that user will be returned
*/
signInAnonymously(): Promise<User>
/**
* Sign in the user with a 3rd party credential provider.
* credential requires the following properties:
*/
signInWithCredential(credential: Credential): Promise<User>
/**
* Sign a user in with a self-signed JWT token.
* To sign a user using a self-signed custom token,
* use the signInWithCustomToken() function.
* It accepts one parameter, the custom token:
*/
signInWithCustomToken(token: string): Promise<User>
/**
* Sends a password reset email to the given email address.
* Unlike the web SDK,
* the email will contain a password reset link rather than a code.
*/
sendPasswordResetEmail(email: string): Promise<void>
/**
* Completes the password reset process,
* given a confirmation code and new password.
*/
signOut(): Promise<void>
[key: string]: any;
}
}
namespace messaging {
interface Messaging {
/**
* Subscribes the device to a topic.
*/
subscribeToTopic(topic: string): void
/**
* Unsubscribes the device from a topic.
*/
unsubscribeFromTopic(topic: string): void
/**
* When the application has been opened from a notification
* getInitialNotification is called and the notification payload is returned.
* Use onMessage for notifications when the app is running.
*/
getInitialNotification(): Promise<any>
/**
* Returns the devices FCM token.
* This token can be used in the Firebase console to send messages to directly.
*/
getToken(forceRefresh?: Boolean): Promise<string>
/**
* On the event a devices FCM token is refreshed by Google,
* the new token is returned in a callback listener.
*/
onTokenRefresh(listener: (token: string) => any): void
/**
* On a new message,
* the payload object is passed to the listener callback.
* This method is only triggered when the app is running.
* Use getInitialNotification for notifications which cause the app to open.
*/
onMessage(listener: (message: any) => any): void
/**
* Create a local notification from the device itself.
*/
createLocalNotification(notification: any): any
/**
* Schedule a local notification to be shown on the device.
*/
scheduleLocalNotification(notification: any): any
/**
* Returns an array of all currently scheduled notifications.
* ```
* firebase.messaging().getScheduledLocalNotifications()
* .then((notifications) => {
* console.log('Current scheduled notifications: ', notifications);
* });
* ```
*/
getScheduledLocalNotifications(): Promise<any[]>
/**
* Cancels a location notification by ID,
* or all notifications by *.
*/
cancelLocalNotification(id: string): void
/**
* Removes all delivered notifications from device by ID,
* or all notifications by *.
*/
removeDeliveredNotification(id: string): void
/**
* IOS
* Requests app notification permissions in an Alert dialog.
*/
requestPermissions(): void
/**
* Sets the badge number on the iOS app icon.
*/
setBadgeNumber(value: number): void
/**
* Returns the current badge number on the app icon.
*/
getBadgeNumber(): Promise<number>
/**
* Send an upstream message
* @param senderId
* @param payload
*/
send(senderId: string, payload: RemoteMessage): any
NOTIFICATION_TYPE: Object
REMOTE_NOTIFICATION_RESULT: Object
WILL_PRESENT_RESULT: Object
EVENT_TYPE: Object
}
interface RemoteMessage {
id: string,
type: string,
ttl?: number,
sender: string,
collapseKey?: string,
data: Object,
}
}
namespace crash {
interface Crash {
/** Logs a message that will appear in a subsequent crash report. */
log(message: string): void
/**
* Android: Logs a message that will appear in a subsequent crash report as well as in logcat.
* iOS: Logs the message in the subsequest crash report only (same as log).
*/
logcat(level: number, tag: string, message: string): void
/**
* Files a crash report, along with any previous logs to Firebase.
* An Error object must be passed into the report method.
*/
report(error: RnError, maxStackSize: Number): void
[key: string]: any;
}
}
}
}