UNPKG

6.79 kBTypeScriptView Raw
1/**
2 * Firebase Cloud Messaging
3 *
4 * @packageDocumentation
5 */
6import { FirebaseApp } from '@firebase/app';
7
8import { NextFn , Observer , Unsubscribe } from '@firebase/util';
9
10/**
11 * Deletes the registration token associated with this {@link Messaging} instance and unsubscribes
12 * the {@link Messaging} instance from the push subscription.
13 *
14 * @param messaging - The {@link Messaging} instance.
15 *
16 * @returns The promise resolves when the token has been successfully deleted.
17 *
18 * @public
19 */
20export declare function deleteToken(messaging: Messaging): Promise<boolean>;
21/**
22 * Options for features provided by the FCM SDK for Web. See {@link
23 * https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#webpushfcmoptions |
24 * WebpushFcmOptions}
25 *
26 * @public
27 */
28export declare interface FcmOptions {
29 /**
30 * The link to open when the user clicks on the notification.
31 */
32 link?: string;
33 /**
34 * The label associated with the message's analytics data.
35 */
36 analyticsLabel?: string;
37}
38/* Excluded from this release type: _FirebaseMessagingName */
39/**
40 * Retrieves a Firebase Cloud Messaging instance.
41 *
42 * @returns The Firebase Cloud Messaging instance associated with the provided firebase app.
43 *
44 * @public
45 */
46export declare function getMessaging(app?: FirebaseApp): Messaging;
47/**
48 * Subscribes the {@link Messaging} instance to push notifications. Returns an Firebase Cloud
49 * Messaging registration token that can be used to send push messages to that {@link Messaging}
50 * instance.
51 *
52 * If a notification permission isn't already granted, this method asks the user for permission. The
53 * returned promise rejects if the user does not allow the app to show notifications.
54 *
55 * @param messaging - The {@link Messaging} instance.
56 * @param options - Provides an optional vapid key and an optinoal service worker registration
57 *
58 * @returns The promise resolves with an FCM registration token.
59 *
60 * @public
61 */
62export declare function getToken(messaging: Messaging, options?: GetTokenOptions): Promise<string>;
63/**
64 * Options for {@link getToken}
65 *
66 * @public
67 */
68export declare interface GetTokenOptions {
69 /**
70 * The public server key provided to push services. It is used to
71 * authenticate the push subscribers to receive push messages only from sending servers that hold
72 * the corresponding private key. If it is not provided, a default VAPID key is used. Note that some
73 * push services (Chrome Push Service) require a non-default VAPID key. Therefore, it is recommended
74 * to generate and import a VAPID key for your project with
75 * {@link https://firebase.google.com/docs/cloud-messaging/js/client#configure_web_credentials_with_fcm | Configure Web Credentials with FCM}.
76 * See
77 * {@link https://developers.google.com/web/fundamentals/push-notifications/web-push-protocol | The Web Push Protocol}
78 * for details on web push services.
79 */
80 vapidKey?: string;
81 /**
82 * The service worker registration for receiving push
83 * messaging. If the registration is not provided explicitly, you need to have a
84 * `firebase-messaging-sw.js` at your root location. See
85 * {@link https://firebase.google.com/docs/cloud-messaging/js/client#retrieve-the-current-registration-token | Retrieve the current registration token}
86 * for more details.
87 */
88 serviceWorkerRegistration?: ServiceWorkerRegistration;
89}
90/**
91 * @license
92 * Copyright 2020 Google LLC
93 *
94 * Licensed under the Apache License, Version 2.0 (the "License");
95 * you may not use this file except in compliance with the License.
96 * You may obtain a copy of the License at
97 *
98 * http://www.apache.org/licenses/LICENSE-2.0
99 *
100 * Unless required by applicable law or agreed to in writing, software
101 * distributed under the License is distributed on an "AS IS" BASIS,
102 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
103 * See the License for the specific language governing permissions and
104 * limitations under the License.
105 */
106/**
107 * Checks if all required APIs exist in the browser.
108 * @returns a Promise that resolves to a boolean.
109 *
110 * @public
111 */
112export declare function isSupported(): Promise<boolean>;
113/**
114 * Message payload that contains the notification payload that is represented with
115 * {@link NotificationPayload} and the data payload that contains an arbitrary
116 * number of key-value pairs sent by developers through the
117 * {@link https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#notification | Send API}
118 *
119 * @public
120 */
121export declare interface MessagePayload {
122 /**
123 * {@inheritdoc NotificationPayload}
124 */
125 notification?: NotificationPayload;
126 /**
127 * Arbitrary key/value payload.
128 */
129 data?: {
130 [key: string]: string;
131 };
132 /**
133 * {@inheritdoc FcmOptions}
134 */
135 fcmOptions?: FcmOptions;
136 /**
137 * The sender of this message.
138 */
139 from: string;
140 /**
141 * The collapse key of the message. See
142 * {@link https://firebase.google.com/docs/cloud-messaging/concept-options#collapsible_and_non-collapsible_messages | Non-collapsible and collapsible messages}
143 */
144 collapseKey: string;
145 /**
146 * The message id of a message.
147 */
148 messageId: string;
149}
150/**
151 * Public interface of the Firebase Cloud Messaging SDK.
152 *
153 * @public
154 */
155export declare interface Messaging {
156 /**
157 * The {@link @firebase/app#FirebaseApp} this `Messaging` instance is associated with.
158 */
159 app: FirebaseApp;
160}
161export { NextFn };
162/**
163 * Display notification details. They are sent through the
164 * {@link https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#notification | Send API}
165 *
166 * @public
167 */
168export declare interface NotificationPayload {
169 /**
170 * The notification's title.
171 */
172 title?: string;
173 /**
174 * The notification's body text.
175 */
176 body?: string;
177 /**
178 * The URL of an image that is downloaded on the device and displayed in the notification.
179 */
180 image?: string;
181}
182export { Observer };
183/**
184 * When a push message is received and the user is currently on a page for your origin, the
185 * message is passed to the page and an `onMessage()` event is dispatched with the payload of
186 * the push message.
187 *
188 *
189 * @param messaging - The {@link Messaging} instance.
190 * @param nextOrObserver - This function, or observer object with `next` defined,
191 * is called when a message is received and the user is currently viewing your page.
192 * @returns To stop listening for messages execute this returned function.
193 *
194 * @public
195 */
196export declare function onMessage(messaging: Messaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;
197export { Unsubscribe };
198export {};