UNPKG

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