From 59a0d7ed6a6a4d79217ef81d70b50cfdd638092a Mon Sep 17 00:00:00 2001 From: Tal Jacobson Date: Thu, 23 Mar 2017 00:43:20 +0200 Subject: [PATCH 1/6] create typescript definitions file --- index.d.ts | 390 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 390 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 00000000..d022b6ff --- /dev/null +++ b/index.d.ts @@ -0,0 +1,390 @@ + +// Type definitions for React Native Firebase v1.0.0-alpha7 +// Project: https://github.com/invertase/react-native-firebase +// TypeScript Version: 2.1 + +// TODO definitions for storage, database methods, undocumented features + + class FireBase { + constructor(config?: configurationOptions) + analytics(): Analytics + auth(): Auth + on(type: string, handler: (msg:any) => void): any + /** mimics firebase Web SDK */ + database(): any + /**RNFirebase mimics the Web Firebase SDK Storage, + * whilst providing some iOS and Android specific functionality. + */ + storage(): any + /** + * 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(): 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(): Crash + } + + /** + * 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 + } + /** + * 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 + } + + interface User { + /** + * The user's display name (if available). + */ + isplayName: 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: Object | 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 + /** + * Returns the users authentication token. + */ + getToken(): Promise + /** + * Reauthenticate the current user with credentials: + */ + reauthenticate(credential: Credential): Promise + /** + * Refreshes the current user. + */ + reload(): Promise + /** + * Sends a verification email to a user. + * This will Promise reject is the user is anonymous. + */ + sendEmailVerification(): Promise + /** + * 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 + /** + * 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 + /** + * Updates a user's profile data. + * Profile data should be an object of fields to update: + */ + updateProfile(profile: Object): Promise + } + + /** 3rd party provider Credentials */ + interface Credential { + provider: string, + token: string, + secret: string + } + + 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(event: Function): Function + /** + * 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 + /** + * 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 + /** + * Sign an anonymous user. + * If the user has already signed in, that user will be returned + */ + signInAnonymously(): Promise + /** + * Sign in the user with a 3rd party credential provider. + * credential requires the following properties: + */ + signInWithCredential(credential: Credential): Promise + /** + * 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 + /** + * 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 + /** + * Completes the password reset process, + * given a confirmation code and new password. + */ + signOut(): Promise + + } + + 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 + /** + * Returns the devices FCM token. + * This token can be used in the Firebase console to send messages to directly. + */ + getToken(): Promise + /** + * 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: Object) => any): void + /** + * Create a local notification from the device itself. + */ + createLocalNotification(notification: Object): any + /** + * Schedule a local notification to be shown on the device. + */ + scheduleLocalNotification(notification: Object): any + /** + * Returns an array of all currently scheduled notifications. + * ``` + * firebase.messaging().getScheduledLocalNotifications() + * .then((notifications) => { + * console.log('Current scheduled notifications: ', notifications); + * }); + * ``` + */ + getScheduledLocalNotifications(): Promise + /** + * 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 + /** + * IOS + * Sets the badge number on the iOS app icon. + */ + setBadgeNumber(value: number): void + /** + * IOS + * Returns the current badge number on the app icon. + */ + getBadgeNumber(): 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, + } + + 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: Error, maxStackSize: Number): void + } + From d4f31e0039b9f438d9c03c2d1eb587933943ea75 Mon Sep 17 00:00:00 2001 From: Tal Jacobson Date: Thu, 23 Mar 2017 12:06:07 +0200 Subject: [PATCH 2/6] Update index.d.ts namespace interfaces, export class as default --- index.d.ts | 111 ++++++++++++++++++++++++++++------------------------- 1 file changed, 58 insertions(+), 53 deletions(-) diff --git a/index.d.ts b/index.d.ts index d022b6ff..142da644 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,44 +1,46 @@ - // Type definitions for React Native Firebase v1.0.0-alpha7 // Project: https://github.com/invertase/react-native-firebase -// TypeScript Version: 2.1 +// Definitions by: Tal +// TypeScript Version: 2.1 -// TODO definitions for storage, database methods, undocumented features +declare module "react-native-firebase" { - class FireBase { - constructor(config?: configurationOptions) - analytics(): Analytics - auth(): Auth - on(type: string, handler: (msg:any) => void): any - /** mimics firebase Web SDK */ - database(): any - /**RNFirebase mimics the Web Firebase SDK Storage, - * whilst providing some iOS and Android specific functionality. - */ - storage(): any - /** - * 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(): 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(): Crash + export default class FireBase { + constructor(config?: RNFirebase.configurationOptions) + analytics(): RNFirebase.Analytics + auth(): RNFirebase.Auth + on(type: string, handler: (msg: any) => void): any + /** mimics firebase Web SDK */ + database(): any + /**RNFirebase mimics the Web Firebase SDK Storage, + * whilst providing some iOS and Android specific functionality. + */ + storage(): any + /** + * 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 + /** + * 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 } - /** - * 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 { + namespace RNFirebase { + + /** + * 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 @@ -100,11 +102,11 @@ * The secret iOS API key used for authenticating requests from our app */ APIKey?: string - } - /** - * firebase Analytics - */ - interface Analytics { + } + /** + * 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. */ @@ -138,9 +140,9 @@ * Sets a key/value pair of data on the current user. */ setUserProperty(name: string, value: string): void - } + } - interface User { + interface User { /** * The user's display name (if available). */ @@ -212,16 +214,16 @@ * Profile data should be an object of fields to update: */ updateProfile(profile: Object): Promise - } + } - /** 3rd party provider Credentials */ - interface Credential { + /** 3rd party provider Credentials */ + interface Credential { provider: string, token: string, secret: string - } + } - interface Auth { + interface Auth { /** * Returns the current Firebase authentication state. */ @@ -275,9 +277,9 @@ */ signOut(): Promise - } + } - interface Messaging { + interface Messaging { /** * Subscribes the device to a topic. */ @@ -362,18 +364,18 @@ REMOTE_NOTIFICATION_RESULT: Object WILL_PRESENT_RESULT: Object EVENT_TYPE: Object - } + } - interface RemoteMessage { + interface RemoteMessage { id: string, type: string, ttl?: number, sender: string, collapseKey?: string, data: Object, - } + } - interface Crash { + interface Crash { /** Logs a message that will appear in a subsequent crash report. */ log(message: string): void /** @@ -386,5 +388,8 @@ * An Error object must be passed into the report method. */ report(error: Error, maxStackSize: Number): void + } } + +} From aae9000a306628828bf770a5e71a7413faf032b7 Mon Sep 17 00:00:00 2001 From: Tal Jacobson Date: Thu, 23 Mar 2017 14:58:03 +0200 Subject: [PATCH 3/6] add database, storage interface toke some definitions from firebase npm d.ts file had to extend to align with the projects api --- index.d.ts | 259 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 249 insertions(+), 10 deletions(-) diff --git a/index.d.ts b/index.d.ts index 142da644..e689252e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -7,22 +7,22 @@ declare module "react-native-firebase" { export default class FireBase { constructor(config?: RNFirebase.configurationOptions) - analytics(): RNFirebase.Analytics - auth(): RNFirebase.Auth - on(type: string, handler: (msg: any) => void): any + analytics(): RNFirebase.Analytics; + auth(): RNFirebase.Auth; + on(type: string, handler: (msg: any) => void): any; /** mimics firebase Web SDK */ - database(): any + database(): RNFirebase.database.Database; /**RNFirebase mimics the Web Firebase SDK Storage, * whilst providing some iOS and Android specific functionality. */ - storage(): any + 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.Messaging; /** * RNFirebase provides crash reporting for your app out of the box. * Please note crashes do not appear in real-time on the console, @@ -30,11 +30,253 @@ declare module "react-native-firebase" { * 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(): RNFirebase.Crash; } namespace RNFirebase { + namespace storage { + interface StorageTask extends Promise { + on( + event: TaskEvent, + nextOrObserver: (snapshot: any) => any, + error: (error: Error) => 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): any; + /** + * Upload a file path + * @returns {Promise} + */ + putFile(filePath: Object, metadata?: Object): StorageTask; + } + + 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; + fullPath: string; + getDownloadURL(): Promise; + getMetadata(): Promise; + 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; + } + 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: Error) => any): Promise; + on(event: storage.TaskEvent, nextOrObserver?: null | Object, + error?: ((a: Error) => any) | null, complete?: (() => any) | null): Function; + pause(): boolean; + resume(): boolean; + snapshot: storage.UploadTaskSnapshot; + then( + onFulfilled?: ((a: storage.UploadTaskSnapshot) => any) | null, + onRejected?: ((a: Error) => any) | null): Promise; + } + + 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, 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 + /** + * connect to firebase backend + */ + goOnline(): void + /** + * disconnect to firebase backend + */ + goOffline(): void + } + + interface RnReference extends Reference { + keepSynced(bool: boolean): any + filter(name: string, value: 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; + 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: Error | null) => any): any + remove(onComplete?: (a: Error | null) => any): Promise; + root: database.Reference; + set(value: any, onComplete?: (a: Error | null) => any): Promise; + setPriority( + priority: string | number | null, + onComplete: (a: Error | null) => any): Promise; + setWithPriority( + newVal: any, newPriority: string | number | null, + onComplete?: (a: Error | null) => any): Promise; + transaction( + transactionUpdate: (a: any) => any, + onComplete?: + (a: Error | null, b: boolean, + c: database.DataSnapshot | null) => any, + applyLocally?: boolean): Promise; + update(values: Object, onComplete?: (a: Error | null) => any): Promise; + } + } /** * 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. @@ -276,7 +518,6 @@ declare module "react-native-firebase" { * given a confirmation code and new password. */ signOut(): Promise - } interface Messaging { @@ -390,6 +631,4 @@ declare module "react-native-firebase" { report(error: Error, maxStackSize: Number): void } } - - } From 32704e8cbaa8ac6f50484027054f813af698a8d0 Mon Sep 17 00:00:00 2001 From: taljacobson Date: Wed, 29 Mar 2017 00:49:12 +0300 Subject: [PATCH 4/6] add code to Error, fix typo, change authStateChange Method --- index.d.ts | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/index.d.ts b/index.d.ts index e689252e..8cf73782 100644 --- a/index.d.ts +++ b/index.d.ts @@ -34,13 +34,16 @@ declare module "react-native-firebase" { } namespace RNFirebase { + interface RnError extends Error { + code?: string; + } namespace storage { interface StorageTask extends Promise { on( event: TaskEvent, nextOrObserver: (snapshot: any) => any, - error: (error: Error) => any, + error: (error: RnError) => any, complete: (complete: any) => any ): any /** @@ -125,15 +128,15 @@ declare module "react-native-firebase" { interface UploadTask { cancel(): boolean; - catch(onRejected: (a: Error) => any): Promise; + catch(onRejected: (a: RnError) => any): Promise; on(event: storage.TaskEvent, nextOrObserver?: null | Object, - error?: ((a: Error) => any) | null, complete?: (() => any) | null): Function; + 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: Error) => any) | null): Promise; + onRejected?: ((a: RnError) => any) | null): Promise; } interface UploadTaskSnapshot { @@ -252,29 +255,29 @@ declare module "react-native-firebase" { 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: Error | null) => any): any - remove(onComplete?: (a: Error | null) => any): Promise; + push(value?: any, onComplete?: (a: RnError | null) => any): any + remove(onComplete?: (a: RnError | null) => any): Promise; root: database.Reference; - set(value: any, onComplete?: (a: Error | null) => any): Promise; + set(value: any, onComplete?: (a: RnError | null) => any): Promise; setPriority( priority: string | number | null, - onComplete: (a: Error | null) => any): Promise; + onComplete: (a: RnError | null) => any): Promise; setWithPriority( newVal: any, newPriority: string | number | null, - onComplete?: (a: Error | null) => any): Promise; + onComplete?: (a: RnError | null) => any): Promise; transaction( transactionUpdate: (a: any) => any, onComplete?: - (a: Error | null, b: boolean, + (a: RnError | null, b: boolean, c: database.DataSnapshot | null) => any, applyLocally?: boolean): Promise; - update(values: Object, onComplete?: (a: Error | null) => any): Promise; + update(values: Object, onComplete?: (a: RnError | null) => any): Promise; } } /** @@ -388,7 +391,7 @@ declare module "react-native-firebase" { /** * The user's display name (if available). */ - isplayName: string | null + displayName: string | null /** * - The user's email address (if available). */ @@ -479,7 +482,9 @@ declare module "react-native-firebase" { * 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(event: Function): Function + 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. @@ -628,7 +633,7 @@ declare module "react-native-firebase" { * Files a crash report, along with any previous logs to Firebase. * An Error object must be passed into the report method. */ - report(error: Error, maxStackSize: Number): void + report(error: RnError, maxStackSize: Number): void } } -} +} \ No newline at end of file From e5382b96dfc8ee67edef18ce39d8071d63325ae2 Mon Sep 17 00:00:00 2001 From: taljacobson Date: Thu, 30 Mar 2017 17:09:48 +0300 Subject: [PATCH 5/6] change some Object type to any to unblock typing, add GoogleApiAvailabilityType, add namespace for auth, messaging --- index.d.ts | 493 ++++++++++++++++++++++++++++------------------------- 1 file changed, 257 insertions(+), 236 deletions(-) diff --git a/index.d.ts b/index.d.ts index 8cf73782..ba4fc36c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -7,8 +7,9 @@ declare module "react-native-firebase" { export default class FireBase { constructor(config?: RNFirebase.configurationOptions) + log: any analytics(): RNFirebase.Analytics; - auth(): RNFirebase.Auth; + auth(): RNFirebase.auth.Auth; on(type: string, handler: (msg: any) => void): any; /** mimics firebase Web SDK */ database(): RNFirebase.database.Database; @@ -22,7 +23,7 @@ declare module "react-native-firebase" { * 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.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, @@ -30,13 +31,93 @@ declare module "react-native-firebase" { * 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(): RNFirebase.crash.Crash; + + googleApiAvailability: RNFirebase.GoogleApiAvailabilityType; + static initializeApp(options?: any, name?: string): FireBase } 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 extends Promise { @@ -67,12 +148,13 @@ declare module "react-native-firebase" { * @param {String} filePath Where to store the file * @return {Promise} * */ - downloadFile(filePath: string): any; + downloadFile(filePath: string): StorageTask; /** * Upload a file path * @returns {Promise} */ - putFile(filePath: Object, metadata?: Object): StorageTask; + putFile(filePath: string, metadata?: any): StorageTask; + setMaxDownloadRetryTime(time: number): void } interface Storage { @@ -280,74 +362,6 @@ declare module "react-native-firebase" { update(values: Object, onComplete?: (a: RnError | null) => any): Promise; } } - /** - * 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 - } /** * firebase Analytics */ @@ -411,7 +425,7 @@ declare module "react-native-firebase" { /** * - Additional provider-specific information about the user. */ - providerData: Object | null + providerData: any | null /** * - The authentication provider ID for the current user. * For example, 'facebook.com', or 'google.com'. @@ -467,173 +481,180 @@ declare module "react-native-firebase" { 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 - /** - * 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 - /** - * Sign an anonymous user. - * If the user has already signed in, that user will be returned - */ - signInAnonymously(): Promise - /** - * Sign in the user with a 3rd party credential provider. - * credential requires the following properties: - */ - signInWithCredential(credential: Credential): Promise - /** - * 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 - /** - * 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 - /** - * Completes the password reset process, - * given a confirmation code and new password. - */ - signOut(): Promise + 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 + /** + * 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 + /** + * Sign an anonymous user. + * If the user has already signed in, that user will be returned + */ + signInAnonymously(): Promise + /** + * Sign in the user with a 3rd party credential provider. + * credential requires the following properties: + */ + signInWithCredential(credential: Credential): Promise + /** + * 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 + /** + * 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 + /** + * Completes the password reset process, + * given a confirmation code and new password. + */ + signOut(): Promise + } } + + 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 - /** - * Returns the devices FCM token. - * This token can be used in the Firebase console to send messages to directly. - */ - getToken(): Promise - /** - * 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: Object) => any): void - /** - * Create a local notification from the device itself. - */ - createLocalNotification(notification: Object): any - /** - * Schedule a local notification to be shown on the device. - */ - scheduleLocalNotification(notification: Object): any - /** - * Returns an array of all currently scheduled notifications. - * ``` - * firebase.messaging().getScheduledLocalNotifications() - * .then((notifications) => { - * console.log('Current scheduled notifications: ', notifications); - * }); - * ``` - */ - getScheduledLocalNotifications(): Promise - /** - * 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 - /** - * IOS - * Sets the badge number on the iOS app icon. - */ - setBadgeNumber(value: number): void - /** - * IOS - * Returns the current badge number on the app icon. - */ - getBadgeNumber(): 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 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 + /** + * Returns the devices FCM token. + * This token can be used in the Firebase console to send messages to directly. + */ + getToken(forceRefresh?: Boolean): Promise + /** + * 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 + /** + * 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 + /** + * IOS + * Sets the badge number on the iOS app icon. + */ + setBadgeNumber(value: number): void + /** + * IOS + * Returns the current badge number on the app icon. + */ + getBadgeNumber(): 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 RemoteMessage { - id: string, - type: string, - ttl?: number, - sender: string, - collapseKey?: string, - data: Object, - } - - 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 + 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 + } } } } \ No newline at end of file From 9d32630d01830c40cdb14e5af83be31ad63bc70e Mon Sep 17 00:00:00 2001 From: taljacobson Date: Wed, 26 Apr 2017 22:12:59 +0300 Subject: [PATCH 6/6] add some non type blocking any's --- index.d.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/index.d.ts b/index.d.ts index ba4fc36c..82e1540e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -32,9 +32,10 @@ declare module "react-native-firebase" { * such as a pre-caught exception this is possible by using the report method. */ crash(): RNFirebase.crash.Crash; - + apps: Array; googleApiAvailability: RNFirebase.GoogleApiAvailabilityType; - static initializeApp(options?: any, name?: string): FireBase + static initializeApp(options?: any | RNFirebase.configurationOptions, name?: string): FireBase; + [key: string]: any; } namespace RNFirebase { @@ -155,6 +156,7 @@ declare module "react-native-firebase" { */ putFile(filePath: string, metadata?: any): StorageTask; setMaxDownloadRetryTime(time: number): void + [key: string]: any; } interface Storage { @@ -287,11 +289,13 @@ declare module "react-native-firebase" { * 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 + filter(name: string, value: any, key?: string): any; + [key: string]: any; } interface Query { @@ -398,7 +402,8 @@ declare module "react-native-firebase" { /** * Sets a key/value pair of data on the current user. */ - setUserProperty(name: string, value: string): void + setUserProperty(name: string, value: string): void; + [key: string]: any; } interface User { @@ -538,9 +543,10 @@ declare module "react-native-firebase" { * given a confirmation code and new password. */ signOut(): Promise + [key: string]: any; } } - + namespace messaging { interface Messaging { @@ -654,6 +660,7 @@ declare module "react-native-firebase" { * An Error object must be passed into the report method. */ report(error: RnError, maxStackSize: Number): void + [key: string]: any; } } }