From c6b67c5db7e310f1fff605d46921e9f62ad4841b Mon Sep 17 00:00:00 2001 From: Russell Wheatley Date: Mon, 29 Jul 2024 16:22:27 +0100 Subject: [PATCH] test(messaging): ensure modular API are exported properly (#7928) --- .../messaging/__tests__/messaging.test.ts | 153 +++++++++ packages/messaging/lib/index.d.ts | 2 + packages/messaging/lib/index.js | 34 +- packages/messaging/lib/modular/index.d.ts | 297 ++++++++++++++++++ packages/messaging/{ => lib}/modular/index.js | 140 +++++---- 5 files changed, 530 insertions(+), 96 deletions(-) create mode 100644 packages/messaging/__tests__/messaging.test.ts create mode 100644 packages/messaging/lib/modular/index.d.ts rename packages/messaging/{ => lib}/modular/index.js (63%) diff --git a/packages/messaging/__tests__/messaging.test.ts b/packages/messaging/__tests__/messaging.test.ts new file mode 100644 index 0000000000..a6650492b8 --- /dev/null +++ b/packages/messaging/__tests__/messaging.test.ts @@ -0,0 +1,153 @@ +import { describe, expect, it } from '@jest/globals'; + +import { + getMessaging, + deleteToken, + getToken, + onMessage, + onNotificationOpenedApp, + onTokenRefresh, + requestPermission, + isAutoInitEnabled, + setAutoInitEnabled, + getInitialNotification, + getDidOpenSettingsForNotification, + getIsHeadless, + registerDeviceForRemoteMessages, + isDeviceRegisteredForRemoteMessages, + unregisterDeviceForRemoteMessages, + getAPNSToken, + setAPNSToken, + hasPermission, + onDeletedMessages, + onMessageSent, + onSendError, + setBackgroundMessageHandler, + setOpenSettingsForNotificationsHandler, + sendMessage, + subscribeToTopic, + unsubscribeFromTopic, + isDeliveryMetricsExportToBigQueryEnabled, + isSupported, + experimentalSetDeliveryMetricsExportedToBigQueryEnabled, +} from '../lib'; + +describe('Firestore', function () { + describe('modular', function () { + it('`getMessaging` function is properly exposed to end user', function () { + expect(getMessaging).toBeDefined(); + }); + + it('`deleteToken` function is properly exposed to end user', function () { + expect(deleteToken).toBeDefined(); + }); + + it('`getToken` function is properly exposed to end user', function () { + expect(getToken).toBeDefined(); + }); + + it('`onMessage` function is properly exposed to end user', function () { + expect(onMessage).toBeDefined(); + }); + + it('`onNotificationOpenedApp` function is properly exposed to end user', function () { + expect(onNotificationOpenedApp).toBeDefined(); + }); + + it('`onTokenRefresh` function is properly exposed to end user', function () { + expect(onTokenRefresh).toBeDefined(); + }); + + it('`requestPermission` function is properly exposed to end user', function () { + expect(requestPermission).toBeDefined(); + }); + + it('`isAutoInitEnabled` function is properly exposed to end user', function () { + expect(isAutoInitEnabled).toBeDefined(); + }); + + it('`setAutoInitEnabled` function is properly exposed to end user', function () { + expect(setAutoInitEnabled).toBeDefined(); + }); + + it('`getInitialNotification` function is properly exposed to end user', function () { + expect(getInitialNotification).toBeDefined(); + }); + + it('`getDidOpenSettingsForNotification` function is properly exposed to end user', function () { + expect(getDidOpenSettingsForNotification).toBeDefined(); + }); + + it('`getIsHeadless` function is properly exposed to end user', function () { + expect(getIsHeadless).toBeDefined(); + }); + + it('`registerDeviceForRemoteMessages` function is properly exposed to end user', function () { + expect(registerDeviceForRemoteMessages).toBeDefined(); + }); + + it('`isDeviceRegisteredForRemoteMessages` function is properly exposed to end user', function () { + expect(isDeviceRegisteredForRemoteMessages).toBeDefined(); + }); + + it('`unregisterDeviceForRemoteMessages` function is properly exposed to end user', function () { + expect(unregisterDeviceForRemoteMessages).toBeDefined(); + }); + + it('`getAPNSToken` function is properly exposed to end user', function () { + expect(getAPNSToken).toBeDefined(); + }); + + it('`setAPNSToken` function is properly exposed to end user', function () { + expect(setAPNSToken).toBeDefined(); + }); + + it('`hasPermission` function is properly exposed to end user', function () { + expect(hasPermission).toBeDefined(); + }); + + it('`onDeletedMessages` function is properly exposed to end user', function () { + expect(onDeletedMessages).toBeDefined(); + }); + + it('`onMessageSent` function is properly exposed to end user', function () { + expect(onMessageSent).toBeDefined(); + }); + + it('`onSendError` function is properly exposed to end user', function () { + expect(onSendError).toBeDefined(); + }); + + it('`setBackgroundMessageHandler` function is properly exposed to end user', function () { + expect(setBackgroundMessageHandler).toBeDefined(); + }); + + it('`setOpenSettingsForNotificationsHandler` function is properly exposed to end user', function () { + expect(setOpenSettingsForNotificationsHandler).toBeDefined(); + }); + + it('`sendMessage` function is properly exposed to end user', function () { + expect(sendMessage).toBeDefined(); + }); + + it('`subscribeToTopic` function is properly exposed to end user', function () { + expect(subscribeToTopic).toBeDefined(); + }); + + it('`unsubscribeFromTopic` function is properly exposed to end user', function () { + expect(unsubscribeFromTopic).toBeDefined(); + }); + + it('`isDeliveryMetricsExportToBigQueryEnabled` function is properly exposed to end user', function () { + expect(isDeliveryMetricsExportToBigQueryEnabled).toBeDefined(); + }); + + it('`isSupported` function is properly exposed to end user', function () { + expect(isSupported).toBeDefined(); + }); + + it('`experimentalSetDeliveryMetricsExportedToBigQueryEnabled` function is properly exposed to end user', function () { + expect(experimentalSetDeliveryMetricsExportedToBigQueryEnabled).toBeDefined(); + }); + }); +}); diff --git a/packages/messaging/lib/index.d.ts b/packages/messaging/lib/index.d.ts index 2f4fdf5e6f..7d526ac7be 100644 --- a/packages/messaging/lib/index.d.ts +++ b/packages/messaging/lib/index.d.ts @@ -1156,3 +1156,5 @@ declare module '@react-native-firebase/app' { } } } + +export * from './modular'; diff --git a/packages/messaging/lib/index.js b/packages/messaging/lib/index.js index 661498aaa2..50a48a0495 100644 --- a/packages/messaging/lib/index.js +++ b/packages/messaging/lib/index.js @@ -34,38 +34,6 @@ import { AppRegistry, Platform } from 'react-native'; import remoteMessageOptions from './remoteMessageOptions'; import version from './version'; -export { - getMessaging, - deleteToken, - getToken, - onMessage, - onNotificationOpenedApp, - onTokenRefresh, - requestPermission, - isAutoInitEnabled, - setAutoInitEnabled, - getInitialNotification, - getDidOpenSettingsForNotification, - getIsHeadless, - registerDeviceForRemoteMessages, - isDeviceRegisteredForRemoteMessages, - unregisterDeviceForRemoteMessages, - getAPNSToken, - setAPNSToken, - hasPermission, - onDeletedMessages, - onMessageSent, - onSendError, - setBackgroundMessageHandler, - setOpenSettingsForNotificationsHandler, - sendMessage, - subscribeToTopic, - unsubscribeFromTopic, - experimentalSetDeliveryMetricsExportedToBigQueryEnabled, - isDeliveryMetricsExportToBigQueryEnabled, - isSupported, -} from '../modular/index'; - const statics = { AuthorizationStatus: { NOT_DETERMINED: -1, @@ -538,6 +506,8 @@ export default createModuleNamespace({ ModuleClass: FirebaseMessagingModule, }); +export * from './modular'; + // import messaging, { firebase } from '@react-native-firebase/messaging'; // messaging().X(...); // firebase.messaging().X(...); diff --git a/packages/messaging/lib/modular/index.d.ts b/packages/messaging/lib/modular/index.d.ts new file mode 100644 index 0000000000..0fcfaa7a98 --- /dev/null +++ b/packages/messaging/lib/modular/index.d.ts @@ -0,0 +1,297 @@ +import { FirebaseMessagingTypes } from '..'; +import { FirebaseApp } from '@firebase/app-types'; + +import Messaging = FirebaseStorageTypes.Module; + +/** + * Returns a Messaging instance for the given app. + * @param app - The Firebase app instance. Optional. + * @returns A Messaging instance. + */ +export function getMessaging(app?: FirebaseApp): Messaging; + +/** + * Removes access to an FCM token previously authorized by its scope. + * Messages sent by the server to this token will fail. + * @param messaging - Messaging instance. + * @param tokenOptions - Options to override senderId (iOS) and projectId (Android). + * @returns A promise that resolves when the token is deleted. + */ +export function deleteToken( + messaging: Messaging, + tokenOptions?: FirebaseMessagingTypes.NativeTokenOptions, +): Promise; + +/** + * Returns an FCM token for this device. Optionally, you can specify custom options for your own use case. + * @param messaging - Messaging instance. + * @param options - Options to override senderId (iOS) and appName. + * @returns A promise that resolves with the FCM token. + */ +export function getToken( + messaging: Messaging, + options?: FirebaseMessagingTypes.GetTokenOptions & FirebaseMessagingTypes.NativeTokenOptions, +): Promise; + +/** + * When any FCM payload is received, the listener callback is called with a `RemoteMessage`. + * This subscriber method is only called when the app is active (in the foreground). + * @param messaging - Messaging instance. + * @param listener - Called with a `RemoteMessage` when a new FCM payload is received from the server. + * @returns A function to unsubscribe from the message listener. + */ +export function onMessage( + messaging: Messaging, + listener: (message: FirebaseMessagingTypes.RemoteMessage) => any, +): () => void; + +/** + * When the user presses a notification displayed via FCM, this listener will be called if the app + * has opened from a background state. + * @param messaging - Messaging instance. + * @param listener - Called with a `RemoteMessage` when a notification press opens the application. + * @returns A function to unsubscribe from the notification opened listener. + */ +export function onNotificationOpenedApp( + messaging: Messaging, + listener: (message: FirebaseMessagingTypes.RemoteMessage) => any, +): () => void; + +/** + * Called when a new registration token is generated for the device. This event can happen when a + * token expires or when the server invalidates the token. + * This subscriber method is only called when the app is active (in the foreground). + * @param messaging - Messaging instance. + * @param listener - Called with an FCM token when the token is refreshed. + * @returns A function to unsubscribe from the token refresh listener. + */ +export function onTokenRefresh(messaging: Messaging, listener: (token: string) => any): () => void; + +/** + * On iOS, messaging permission must be requested by the current application before messages can + * be received or sent. + * @param messaging - Messaging instance. + * @param iosPermissions - All the available permissions for iOS that can be requested. + * @returns A promise that resolves with the authorization status. + */ +export function requestPermission( + messaging: Messaging, + iosPermissions?: FirebaseMessagingTypes.IOSPermissions, +): Promise; + +/** + * Returns whether messaging auto initialization is enabled or disabled for the device. + * @param messaging - Messaging instance. + * @returns A boolean indicating whether auto initialization is enabled. + */ +export function isAutoInitEnabled(messaging: Messaging): boolean; + +/** + * Sets whether messaging auto initialization is enabled or disabled for the device. + * @param messaging - Messaging instance. + * @param enabled - A boolean value to enable or disable auto initialization. + * @returns A promise that resolves when the setting is updated. + */ +export function setAutoInitEnabled(messaging: Messaging, enabled: boolean): Promise; + +/** + * When a notification from FCM has triggered the application to open from a quit state, + * this method will return a `RemoteMessage` containing the notification data, or `null` if + * the app was opened via another method. + * @param messaging - Messaging instance. + * @returns A promise that resolves with the initial notification or null. + */ +export function getInitialNotification( + messaging: Messaging, +): Promise; + +/** + * When the app is opened from iOS notifications settings from a quit state, + * this method will return `true` or `false` if the app was opened via another method. + * @param messaging - Messaging instance. + * @returns A promise that resolves with a boolean indicating if the app was opened from settings. + */ +export function getDidOpenSettingsForNotification(messaging: Messaging): Promise; + +/** + * Returns whether the root view is headless or not + * i.e. true if the app was launched in the background (for example, by data-only cloud message). + * @param messaging - Messaging instance. + * @returns A promise that resolves with a boolean indicating if the app is headless. + */ +export function getIsHeadless(messaging: Messaging): Promise; + +/** + * On iOS, if your app wants to receive remote messages from FCM (via APNs), you must explicitly register + * with APNs if auto-registration has been disabled. + * @param messaging - Messaging instance. + * @returns A promise that resolves when the device is registered. + */ +export function registerDeviceForRemoteMessages(messaging: Messaging): Promise; + +/** + * Returns a boolean value whether the user has registered for remote notifications via + * `registerDeviceForRemoteMessages()`. For iOS. Android always returns `true`. + * @param messaging - Messaging instance. + * @returns A boolean indicating if the device is registered for remote messages. + */ +export function isDeviceRegisteredForRemoteMessages(messaging: Messaging): boolean; + +/** + * Unregisters the app from receiving remote notifications. + * @param messaging - Messaging instance. + * @returns A promise that resolves when the device is unregistered. + */ +export function unregisterDeviceForRemoteMessages(messaging: Messaging): Promise; + +/** + * On iOS, it is possible to get the users APNs token. This may be required if you want to send messages to your + * iOS devices without using the FCM service. + * @param messaging - Messaging instance. + * @returns A promise that resolves with the APNs token or null. + */ +export function getAPNSToken(messaging: Messaging): Promise; + +/** + * On iOS, This method is used to set the APNs Token received by the application delegate. + * Note that the token is expected to be a hexadecimal string, as it is an NSData type in + * the underlying native firebase SDK, and raw data may only be passed as a string if it is + * hex encoded. Calling code is responsible for correct encoding, you should verify by comparing + * the results of `getAPNSToken()` with your token parameter to make sure they are equivalent. + * + * Messaging uses method swizzling to ensure that the APNs token is set automatically. + * However, if you have disabled swizzling by setting FirebaseAppDelegateProxyEnabled to NO + * in your app’s Info.plist, you should manually set the APNs token in your application + * delegate’s application(_:didRegisterForRemoteNotificationsWithDeviceToken:) method. + * + * If you would like to set the type of the APNs token, rather than relying on automatic + * detection, provide a type of either 'prod', 'sandbox'. Omitting the type parameter + * or specifying 'unknown' will rely on automatic type detection based on provisioning profile. + * + * At a native level you may also call objective-c `[FIRMessaging setAPNSToken];` as needed. + * + * @param messaging - Messaging instance. + * @param token - A hexadecimal string representing your APNs token. + * @param type - Optional. A string specifying 'prod', 'sandbox' or 'unknown' token type. + * @returns A promise that resolves when the APNs token is set. + */ +export function setAPNSToken(messaging: Messaging, token: string, type?: string): Promise; + +/** + * Returns a `AuthorizationStatus` as to whether the user has messaging permission for this app. + * @param messaging - Messaging instance. + * @returns A promise that resolves with the authorization status. + */ +export function hasPermission( + messaging: Messaging, +): Promise; + +/** + * Called when the FCM server deletes pending messages. + * @param messaging - Messaging instance. + * @param listener - Called when the FCM deletes pending messages. + * @returns A function to unsubscribe from the deleted messages listener. + */ +export function onDeletedMessages(messaging: Messaging, listener: () => void): () => void; + +/** + * When sending a `RemoteMessage`, this listener is called when the message has been sent to FCM. + * @param messaging - Messaging instance. + * @param listener - Called when the FCM sends the remote message to FCM. + * @returns A function to unsubscribe from the message sent listener. + */ +export function onMessageSent( + messaging: Messaging, + listener: (messageId: string) => any, +): () => void; + +/** + * When sending a `RemoteMessage`, this listener is called when an error is thrown and the + * message could not be sent. + * @param messaging - Messaging instance. + * @param listener - Called when the FCM sends the remote message to FCM. + * @returns A function to unsubscribe from the send error listener. + */ +export function onSendError( + messaging: Messaging, + listener: (evt: FirebaseMessagingTypes.SendErrorEvent) => any, +): () => void; + +/** + * Set a message handler function which is called when the app is in the background + * or terminated. In Android, a headless task is created, allowing you to access the React Native environment + * to perform tasks such as updating local storage, or sending a network request. + * @param messaging - Messaging instance. + * @param handler - Called when a message is sent and the application is in a background or terminated state. + * @returns {void} + */ +export function setBackgroundMessageHandler( + messaging: Messaging, + handler: (message: FirebaseMessagingTypes.RemoteMessage) => Promise, +): void; + +/** + * Set a handler function which is called when the `${App Name} notifications settings` + * link in iOS settings is clicked. + * @param messaging - Messaging instance. + * @param handler - Called when link in iOS settings is clicked. + * @returns {void} + */ +export function setOpenSettingsForNotificationsHandler( + messaging: Messaging, + handler: (message: FirebaseMessagingTypes.RemoteMessage) => any, +): void; + +/** + * Send a new `RemoteMessage` to the FCM server. + * @param messaging - Messaging instance. + * @param message - A `RemoteMessage` interface. + * @returns A promise that resolves when the message is sent. + */ +export function sendMessage( + messaging: Messaging, + message: FirebaseMessagingTypes.RemoteMessage, +): Promise; + +/** + * Apps can subscribe to a topic, which allows the FCM server to send targeted messages to only those + * devices subscribed to that topic. + * @param messaging - Messaging instance. + * @param topic - The topic name. + * @returns A promise that resolves when the subscription is complete. + */ +export function subscribeToTopic(messaging: Messaging, topic: string): Promise; + +/** + * Unsubscribe the device from a topic. + * @param messaging - Messaging instance. + * @param topic - The topic name. + * @returns A promise that resolves when the unsubscription is complete. + */ +export function unsubscribeFromTopic(messaging: Messaging, topic: string): Promise; + +/** + * Returns a boolean whether message delivery metrics are exported to BigQuery. + * @param messaging - Messaging instance. + * @returns A boolean indicating if message delivery metrics are exported to BigQuery. + */ +export function isDeliveryMetricsExportToBigQueryEnabled(messaging: Messaging): boolean; + +/** + * Checks if all required APIs exist in the browser. + * @param messaging - Messaging instance. + * @returns A boolean indicating if the APIs are supported. + */ +export function isSupported(messaging: Messaging): boolean; + +/** + * Sets whether message delivery metrics are exported to BigQuery is enabled or disabled. + * The value is false by default. Set this to true to allow exporting of message delivery metrics to BigQuery. + * @param messaging - Messaging instance. + * @param enabled - A boolean value to enable or disable exporting of message delivery metrics to BigQuery. + * @returns A promise that resolves when the setting is updated. + */ +export function experimentalSetDeliveryMetricsExportedToBigQueryEnabled( + messaging: Messaging, + enabled: boolean, +): Promise; diff --git a/packages/messaging/modular/index.js b/packages/messaging/lib/modular/index.js similarity index 63% rename from packages/messaging/modular/index.js rename to packages/messaging/lib/modular/index.js index 5c99d8f685..7395b225b6 100644 --- a/packages/messaging/modular/index.js +++ b/packages/messaging/lib/modular/index.js @@ -1,8 +1,20 @@ import { firebase } from '..'; +/** + * @typedef {import('..').FirebaseMessagingTypes} FirebaseMessagingTypes + * @typedef {import('..').FirebaseMessagingTypes.Module} Messaging + * @typedef {import('..').FirebaseMessagingTypes.RemoteMessage} RemoteMessage + * @typedef {import('..').FirebaseMessagingTypes.NativeTokenOptions} NativeTokenOptions + * @typedef {import('..').FirebaseMessagingTypes.GetTokenOptions} GetTokenOptions + * @typedef {import('..').FirebaseMessagingTypes.IOSPermissions} IOSPermissions + * @typedef {import('..').FirebaseMessagingTypes.AuthorizationStatus} AuthorizationStatus + * @typedef {import('..').FirebaseMessagingTypes.SendErrorEvent} SendErrorEvent + * @typedef {import('@firebase/app').FirebaseApp} FirebaseApp + */ + /** * Returns a Messaging instance for the given app. - * @param app - FirebaseApp. Optional. + * @param {FirebaseApp} [app] - FirebaseApp. Optional. * @returns {Messaging} */ export function getMessaging(app) { @@ -14,10 +26,10 @@ export function getMessaging(app) { } /** - * Removes access to an FCM token previously authorized by it's scope. + * Removes access to an FCM token previously authorized by its scope. * Messages sent by the server to this token will fail. - * @param messaging Messaging instance. - * @param tokenOptions Options to override senderId (iOS) and projectId (Android). + * @param {Messaging} messaging - Messaging instance. + * @param {NativeTokenOptions} [tokenOptions] - Options to override senderId (iOS) and projectId (Android). * @returns {Promise} */ export function deleteToken(messaging, tokenOptions) { @@ -29,9 +41,9 @@ export function deleteToken(messaging, tokenOptions) { } /** - * Returns an FCM token for this device. Optionally you can specify a custom options to your own use-case. - * @param messaging Messaging instance. - * @param options Options to override senderId (iOS) and appName + * Returns an FCM token for this device. Optionally, you can specify custom options for your own use case. + * @param {Messaging} messaging - Messaging instance. + * @param {GetTokenOptions & NativeTokenOptions} [options] - Options to override senderId (iOS) and appName. * @returns {Promise} */ export function getToken(messaging, options) { @@ -45,20 +57,20 @@ export function getToken(messaging, options) { /** * When any FCM payload is received, the listener callback is called with a `RemoteMessage`. * > This subscriber method is only called when the app is active (in the foreground). - * @param messaging Messaging instance. - * @param listener Called with a `RemoteMessage` when a new FCM payload is received from the server. - * @returns {Function} + * @param {Messaging} messaging - Messaging instance. + * @param {(message: RemoteMessage) => any} listener - Called with a `RemoteMessage` when a new FCM payload is received from the server. + * @returns {() => void} */ -export function onMessage(messaging, nextOrObserver) { - return messaging.onMessage(nextOrObserver); +export function onMessage(messaging, listener) { + return messaging.onMessage(listener); } /** * When the user presses a notification displayed via FCM, this listener will be called if the app * has opened from a background state. - * @param messaging Messaging instance. - * @param listener Called with a `RemoteMessage` when a notification press opens the application. - * @returns {Function} + * @param {Messaging} messaging - Messaging instance. + * @param {(message: RemoteMessage) => any} listener - Called with a `RemoteMessage` when a notification press opens the application. + * @returns {() => void} */ export function onNotificationOpenedApp(messaging, listener) { return messaging.onNotificationOpenedApp(listener); @@ -68,9 +80,9 @@ export function onNotificationOpenedApp(messaging, listener) { * Called when a new registration token is generated for the device. For example, this event can happen when a * token expires or when the server invalidates the token. * > This subscriber method is only called when the app is active (in the foreground). - * @param messaging Messaging instance. - * @param listener Called with a FCM token when the token is refreshed. - * @returns {Function} + * @param {Messaging} messaging - Messaging instance. + * @param {(token: string) => any} listener - Called with a FCM token when the token is refreshed. + * @returns {() => void} */ export function onTokenRefresh(messaging, listener) { return messaging.onTokenRefresh(listener); @@ -79,8 +91,8 @@ export function onTokenRefresh(messaging, listener) { /** * On iOS, messaging permission must be requested by the current application before messages can * be received or sent. - * @param messaging Messaging instance. - * @param iosPermissions All the available permissions for iOS that can be requested + * @param {Messaging} messaging - Messaging instance. + * @param {IOSPermissions} [iosPermissions] - All the available permissions for iOS that can be requested. * @returns {Promise} */ export function requestPermission(messaging, iosPermissions) { @@ -89,7 +101,7 @@ export function requestPermission(messaging, iosPermissions) { /** * Returns whether messaging auto initialization is enabled or disabled for the device. - * @param messaging Messaging instance. + * @param {Messaging} messaging - Messaging instance. * @returns {boolean} */ export function isAutoInitEnabled(messaging) { @@ -97,10 +109,10 @@ export function isAutoInitEnabled(messaging) { } /** - * Returns whether messaging auto initialization is enabled or disabled for the device. - * @param messaging Messaging instance. - * @param enabled A boolean value to enable or disable auto initialization. - * @returns {Promise} + * Sets whether messaging auto initialization is enabled or disabled for the device. + * @param {Messaging} messaging - Messaging instance. + * @param {boolean} enabled - A boolean value to enable or disable auto initialization. + * @returns {Promise} */ export function setAutoInitEnabled(messaging, enabled) { return messaging.setAutoInitEnabled(enabled); @@ -110,7 +122,7 @@ export function setAutoInitEnabled(messaging, enabled) { * When a notification from FCM has triggered the application to open from a quit state, * this method will return a `RemoteMessage` containing the notification data, or `null` if * the app was opened via another method. - * @param messaging Messaging instance. + * @param {Messaging} messaging - Messaging instance. * @returns {Promise} */ export function getInitialNotification(messaging) { @@ -120,7 +132,7 @@ export function getInitialNotification(messaging) { /** * When the app is opened from iOS notifications settings from a quit state, * this method will return `true` or `false` if the app was opened via another method. - * @param messaging Messaging instance. + * @param {Messaging} messaging - Messaging instance. * @returns {Promise} */ export function getDidOpenSettingsForNotification(messaging) { @@ -130,7 +142,7 @@ export function getDidOpenSettingsForNotification(messaging) { /** * Returns whether the root view is headless or not * i.e true if the app was launched in the background (for example, by data-only cloud message) - * @param messaging Messaging instance. + * @param {Messaging} messaging - Messaging instance. * @returns {Promise} */ export function getIsHeadless(messaging) { @@ -140,7 +152,7 @@ export function getIsHeadless(messaging) { /** * On iOS, if your app wants to receive remote messages from FCM (via APNs), you must explicitly register * with APNs if auto-registration has been disabled. - * @param messaging Messaging instance. + * @param {Messaging} messaging - Messaging instance. * @returns {Promise} */ export function registerDeviceForRemoteMessages(messaging) { @@ -149,8 +161,8 @@ export function registerDeviceForRemoteMessages(messaging) { /** * Returns a boolean value whether the user has registered for remote notifications via - * `registerDeviceForRemoteMessages()`. For iOS. Android always returns `true` - * @param messaging Messaging instance. + * `registerDeviceForRemoteMessages()`. For iOS. Android always returns `true`. + * @param {Messaging} messaging - Messaging instance. * @returns {boolean} */ export function isDeviceRegisteredForRemoteMessages(messaging) { @@ -159,7 +171,7 @@ export function isDeviceRegisteredForRemoteMessages(messaging) { /** * Unregisters the app from receiving remote notifications. - * @param messaging Messaging instance. + * @param {Messaging} messaging - Messaging instance. * @returns {Promise} */ export function unregisterDeviceForRemoteMessages(messaging) { @@ -169,7 +181,7 @@ export function unregisterDeviceForRemoteMessages(messaging) { /** * On iOS, it is possible to get the users APNs token. This may be required if you want to send messages to your * iOS devices without using the FCM service. - * @param messaging Messaging instance. + * @param {Messaging} messaging - Messaging instance. * @returns {Promise} */ export function getAPNSToken(messaging) { @@ -181,7 +193,7 @@ export function getAPNSToken(messaging) { * Note that the token is expected to be a hexadecimal string, as it is an NSData type in * the underlying native firebase SDK, and raw data may only be passed as a string if it is * hex encoded. Calling code is responsible for correct encoding, you should verify by comparing - * the results of `getAPNSToken()` with your token parameter to make sure they are equivalent + * the results of `getAPNSToken()` with your token parameter to make sure they are equivalent. * * Messaging uses method swizzling to ensure that the APNs token is set automatically. * However, if you have disabled swizzling by setting FirebaseAppDelegateProxyEnabled to NO @@ -192,11 +204,11 @@ export function getAPNSToken(messaging) { * detection, provide a type of either 'prod', 'sandbox'. Omitting the type parameter * or specifying 'unknown' will rely on automatic type detection based on provisioning profile. * - * At a native level you may also call objective-c `[FIRMessaging setAPNSToken];` as needed + * At a native level you may also call objective-c `[FIRMessaging setAPNSToken];` as needed. * - * @param messaging Messaging instance. - * @param {string} token a hexadecimal string representing your APNS token - * @param {string?} type specifying 'prod', 'sandbox' or 'unknown' token type + * @param {Messaging} messaging - Messaging instance. + * @param {string} token - A hexadecimal string representing your APNs token. + * @param {string} [type] - Optional. A string specifying 'prod', 'sandbox' or 'unknown' token type. * @returns {Promise} */ export function setAPNSToken(messaging, token, type) { @@ -205,7 +217,7 @@ export function setAPNSToken(messaging, token, type) { /** * Returns a `AuthorizationStatus` as to whether the user has messaging permission for this app. - * @param messaging Messaging instance. + * @param {Messaging} messaging - Messaging instance. * @returns {Promise} */ export function hasPermission(messaging) { @@ -214,9 +226,9 @@ export function hasPermission(messaging) { /** * Called when the FCM server deletes pending messages. - * @param messaging Messaging instance. - * @param listener Called when the FCM deletes pending messages. - * @returns {Function} + * @param {Messaging} messaging - Messaging instance. + * @param {() => void} listener - Called when the FCM deletes pending messages. + * @returns {() => void} */ export function onDeletedMessages(messaging, listener) { return messaging.onDeletedMessages(listener); @@ -224,9 +236,9 @@ export function onDeletedMessages(messaging, listener) { /** * When sending a `RemoteMessage`, this listener is called when the message has been sent to FCM. - * @param messaging Messaging instance. - * @param listener Called when the FCM sends the remote message to FCM. - * @returns {Function} + * @param {Messaging} messaging - Messaging instance. + * @param {(messageId: string) => any} listener - Called when the FCM sends the remote message to FCM. + * @returns {() => void} */ export function onMessageSent(messaging, listener) { return messaging.onMessageSent(listener); @@ -234,9 +246,9 @@ export function onMessageSent(messaging, listener) { /** * When sending a `RemoteMessage`, this listener is called when the message has been sent to FCM. - * @param messaging Messaging instance. - * @param listener Called when the FCM sends the remote message to FCM. - * @returns {Function} + * @param {Messaging} messaging - Messaging instance. + * @param {(evt: SendErrorEvent) => any} listener - Called when the FCM sends the remote message to FCM. + * @returns {() => void} */ export function onSendError(messaging, listener) { return messaging.onSendError(listener); @@ -246,8 +258,8 @@ export function onSendError(messaging, listener) { * Set a message handler function which is called when the app is in the background * or terminated. In Android, a headless task is created, allowing you to access the React Native environment * to perform tasks such as updating local storage, or sending a network request. - * @param messaging Messaging instance. - * @param handler Called when a message is sent and the application is in a background or terminated state. + * @param {Messaging} messaging - Messaging instance. + * @param {(message: RemoteMessage) => Promise} handler - Called when a message is sent and the application is in a background or terminated state. * @returns {void} */ export function setBackgroundMessageHandler(messaging, handler) { @@ -257,8 +269,8 @@ export function setBackgroundMessageHandler(messaging, handler) { /** * Set a handler function which is called when the `${App Name} notifications settings` * link in iOS settings is clicked. - * @param messaging Messaging instance. - * @param handler Called when link in iOS settings is clicked + * @param {Messaging} messaging - Messaging instance. + * @param {(message: RemoteMessage) => any} handler - Called when link in iOS settings is clicked. * @returns {void} */ export function setOpenSettingsForNotificationsHandler(messaging, handler) { @@ -267,8 +279,8 @@ export function setOpenSettingsForNotificationsHandler(messaging, handler) { /** * Send a new `RemoteMessage` to the FCM server. - * @param messaging Messaging instance. - * @param message A `RemoteMessage` interface. + * @param {Messaging} messaging - Messaging instance. + * @param {RemoteMessage} message - A `RemoteMessage` interface. * @returns {Promise} */ export function sendMessage(messaging, message) { @@ -278,8 +290,8 @@ export function sendMessage(messaging, message) { /** * Apps can subscribe to a topic, which allows the FCM server to send targeted messages to only those * devices subscribed to that topic. - * @param messaging Messaging instance. - * @param topic The topic name. + * @param {Messaging} messaging - Messaging instance. + * @param {string} topic - The topic name. * @returns {Promise} */ export function subscribeToTopic(messaging, topic) { @@ -288,8 +300,8 @@ export function subscribeToTopic(messaging, topic) { /** * Unsubscribe the device from a topic. - * @param messaging Messaging instance. - * @param topic The topic name. + * @param {Messaging} messaging - Messaging instance. + * @param {string} topic - The topic name. * @returns {Promise} */ export function unsubscribeFromTopic(messaging, topic) { @@ -298,7 +310,7 @@ export function unsubscribeFromTopic(messaging, topic) { /** * Returns a boolean whether message delivery metrics are exported to BigQuery. - * @param messaging Messaging instance. + * @param {Messaging} messaging - Messaging instance. * @returns {boolean} */ export function isDeliveryMetricsExportToBigQueryEnabled(messaging) { @@ -307,7 +319,7 @@ export function isDeliveryMetricsExportToBigQueryEnabled(messaging) { /** * Checks if all required APIs exist in the browser. - * @param messaging Messaging instance. + * @param {Messaging} messaging - Messaging instance. * @returns {boolean} */ export function isSupported(messaging) { @@ -317,10 +329,10 @@ export function isSupported(messaging) { /** * Sets whether message delivery metrics are exported to BigQuery is enabled or disabled. * The value is false by default. Set this to true to allow exporting of message delivery metrics to BigQuery. - * @param messaging Messaging instance. - * @param enabled A boolean value to enable or disable exporting of message delivery metrics to BigQuery. + * @param {Messaging} messaging - Messaging instance. + * @param {boolean} enabled - A boolean value to enable or disable exporting of message delivery metrics to BigQuery. * @returns {Promise} */ -export function experimentalSetDeliveryMetricsExportedToBigQueryEnabled(messaging, enable) { - return messaging.setDeliveryMetricsExportToBigQuery(enable); +export function experimentalSetDeliveryMetricsExportedToBigQueryEnabled(messaging, enabled) { + return messaging.setDeliveryMetricsExportToBigQuery(enabled); }