@firebase/messaging 0.12.26 → 0.13.0-20260526192810

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/esm/index.esm.js +919 -206
  2. package/dist/esm/index.esm.js.map +1 -1
  3. package/dist/esm/index.sw.esm.js +798 -85
  4. package/dist/esm/index.sw.esm.js.map +1 -1
  5. package/dist/esm/src/api/onRegistered.d.ts +27 -0
  6. package/dist/esm/src/api/onUnregistered.d.ts +27 -0
  7. package/dist/esm/src/api/register.d.ts +31 -0
  8. package/dist/esm/src/api/unregister.d.ts +25 -0
  9. package/dist/esm/src/api.d.ts +59 -2
  10. package/dist/esm/src/helpers/fid-change-registration.d.ts +30 -0
  11. package/dist/esm/src/helpers/logToFirelog.d.ts +2 -0
  12. package/dist/esm/src/helpers/migrate-old-database.d.ts +1 -1
  13. package/dist/esm/src/index.d.ts +1 -1
  14. package/dist/esm/src/index.sw.d.ts +1 -1
  15. package/dist/esm/src/interfaces/internal-message-payload.d.ts +7 -1
  16. package/dist/esm/src/interfaces/public-types.d.ts +11 -0
  17. package/dist/esm/src/internals/idb-manager.d.ts +17 -4
  18. package/dist/esm/src/internals/register-fid.d.ts +27 -0
  19. package/dist/esm/src/internals/requests.d.ts +35 -1
  20. package/dist/esm/src/internals/token-manager.d.ts +6 -3
  21. package/dist/esm/src/messaging-service.d.ts +27 -2
  22. package/dist/esm/src/testing/fakes/token-details.d.ts +1 -1
  23. package/dist/esm/src/util/errors.d.ts +11 -1
  24. package/dist/index-public.d.ts +68 -0
  25. package/dist/index.cjs.js +922 -205
  26. package/dist/index.cjs.js.map +1 -1
  27. package/dist/index.sw.cjs +799 -84
  28. package/dist/index.sw.cjs.map +1 -1
  29. package/dist/internal.d.ts +73 -0
  30. package/dist/private.d.ts +73 -0
  31. package/dist/src/api/onRegistered.d.ts +27 -0
  32. package/dist/src/api/onUnregistered.d.ts +27 -0
  33. package/dist/src/api/register.d.ts +31 -0
  34. package/dist/src/api/unregister.d.ts +25 -0
  35. package/dist/src/api.d.ts +59 -2
  36. package/dist/src/helpers/fid-change-registration.d.ts +30 -0
  37. package/dist/src/helpers/logToFirelog.d.ts +2 -0
  38. package/dist/src/helpers/migrate-old-database.d.ts +1 -1
  39. package/dist/src/index.d.ts +1 -1
  40. package/dist/src/index.sw.d.ts +1 -1
  41. package/dist/src/interfaces/internal-message-payload.d.ts +7 -1
  42. package/dist/src/interfaces/public-types.d.ts +11 -0
  43. package/dist/src/internals/idb-manager.d.ts +17 -4
  44. package/dist/src/internals/register-fid.d.ts +27 -0
  45. package/dist/src/internals/requests.d.ts +35 -1
  46. package/dist/src/internals/token-manager.d.ts +6 -3
  47. package/dist/src/messaging-service.d.ts +27 -2
  48. package/dist/src/testing/fakes/token-details.d.ts +1 -1
  49. package/dist/src/util/errors.d.ts +11 -1
  50. package/dist/sw/index-public.d.ts +35 -1
  51. package/dist/sw/internal.d.ts +38 -1
  52. package/dist/sw/private.d.ts +38 -1
  53. package/package.json +2 -2
  54. /package/dist/esm/src/interfaces/{token-details.d.ts → registration-details.d.ts} +0 -0
  55. /package/dist/src/interfaces/{token-details.d.ts → registration-details.d.ts} +0 -0
@@ -14,10 +14,18 @@ import { Unsubscribe } from '@firebase/util';
14
14
  * Deletes the registration token associated with this {@link Messaging} instance and unsubscribes
15
15
  * the {@link Messaging} instance from the push subscription.
16
16
  *
17
+ * If there is no legacy registration token but the client has FID-based registration metadata
18
+ * (from {@link register}), this deletes that registration on the server, clears local metadata, and
19
+ * invokes {@link onUnregistered} with the removed FID when successful.
20
+ *
17
21
  * @param messaging - The {@link Messaging} instance.
18
22
  *
19
23
  * @returns The promise resolves when the token has been successfully deleted.
20
24
  *
25
+ * @deprecated Use {@link onUnregistered} to observe when the client is no longer
26
+ * registered and update your backend accordingly, instead of explicitly deleting the
27
+ * registration token with this API.
28
+ *
21
29
  * @public
22
30
  */
23
31
  export declare function deleteToken(messaging: Messaging): Promise<boolean>;
@@ -67,6 +75,9 @@ export declare function getMessaging(app?: FirebaseApp): Messaging;
67
75
  *
68
76
  * @returns The promise resolves with an FCM registration token.
69
77
  *
78
+ * @deprecated Use {@link register} together with {@link onRegistered} for Firebase
79
+ * Installation ID-based messaging instead of retrieving an FCM registration token with this API.
80
+ *
70
81
  * @public
71
82
  */
72
83
  export declare function getToken(messaging: Messaging, options?: GetTokenOptions): Promise<string>;
@@ -215,6 +226,68 @@ export { Observer }
215
226
  * @public
216
227
  */
217
228
  export declare function onMessage(messaging: Messaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;
229
+
230
+ /**
231
+ * Subscribes to an event that the app instance is registered with FCM via Firebase Installation ID (FID).
232
+ * Use the FID passed to the callback to upload it to your application server. When you receive an FID
233
+ * after calling {@link register}, instruct your backend to remove any legacy token for this instance.
234
+ *
235
+ * @param messaging - The {@link Messaging} instance.
236
+ * @param nextOrObserver - A function or observer object called when an FID is registered.
237
+ * @returns Unsubscribe function to stop listening.
238
+ *
239
+ * @public
240
+ */
241
+ export declare function onRegistered(messaging: Messaging, nextOrObserver: NextFn<string> | Observer<string>): Unsubscribe;
242
+
243
+ /**
244
+ * Subscribes to an event that the app instance is unregistered from FCM (FID no longer active).
245
+ * Use this to notify your backend to remove this FID to prevent 404 errors on send.
246
+ *
247
+ * @param messaging - The {@link Messaging} instance.
248
+ * @param nextOrObserver - A function or observer object called with the unregistered FID.
249
+ * @returns Unsubscribe function to stop listening.
250
+ *
251
+ * @public
252
+ */
253
+ export declare function onUnregistered(messaging: Messaging, nextOrObserver: NextFn<string> | Observer<string>): Unsubscribe;
254
+
255
+ /**
256
+ * Registers the app instance with FCM using its Firebase Installation ID (FID). The FID is
257
+ * delivered via the {@link onRegistered} callback, not as a return value. Call this to establish
258
+ * an FID-based identity; once {@link onRegistered} provides an FID, instruct your backend to
259
+ * remove any legacy token previously associated with this instance. The backend send API
260
+ * supports FID as a target.
261
+ *
262
+ * @param messaging - The {@link Messaging} instance.
263
+ * @param options - Optional. VAPID key and/or service worker registration (same as getToken).
264
+ * @returns Promise that resolves when registration has been initiated; FID is delivered via onRegistered.
265
+ *
266
+ * @public
267
+ */
268
+ export declare function register(messaging: Messaging, options?: RegisterOptions): Promise<void>;
269
+
270
+ /**
271
+ * Options for {@link register}. Same shape as GetTokenOptions for SW and VAPID configuration.
272
+ *
273
+ * @public
274
+ */
275
+ export declare interface RegisterOptions {
276
+ /** Optional VAPID key. See {@link GetTokenOptions.vapidKey}. */
277
+ vapidKey?: string;
278
+ /** Optional service worker registration. See {@link GetTokenOptions.serviceWorkerRegistration}. */
279
+ serviceWorkerRegistration?: ServiceWorkerRegistration;
280
+ }
281
+
282
+ /**
283
+ * Unregisters the app instance from FCM by deleting its FID-based registration.
284
+ * On success, triggers {@link onUnregistered} (if registered) with the unregistered FID.
285
+ *
286
+ * @param messaging - The {@link Messaging} instance.
287
+ *
288
+ * @public
289
+ */
290
+ export declare function unregister(messaging: Messaging): Promise<void>;
218
291
  export { Unsubscribe }
219
292
 
220
293
  export { }
package/dist/private.d.ts CHANGED
@@ -14,10 +14,18 @@ import { Unsubscribe } from '@firebase/util';
14
14
  * Deletes the registration token associated with this {@link Messaging} instance and unsubscribes
15
15
  * the {@link Messaging} instance from the push subscription.
16
16
  *
17
+ * If there is no legacy registration token but the client has FID-based registration metadata
18
+ * (from {@link register}), this deletes that registration on the server, clears local metadata, and
19
+ * invokes {@link onUnregistered} with the removed FID when successful.
20
+ *
17
21
  * @param messaging - The {@link Messaging} instance.
18
22
  *
19
23
  * @returns The promise resolves when the token has been successfully deleted.
20
24
  *
25
+ * @deprecated Use {@link onUnregistered} to observe when the client is no longer
26
+ * registered and update your backend accordingly, instead of explicitly deleting the
27
+ * registration token with this API.
28
+ *
21
29
  * @public
22
30
  */
23
31
  export declare function deleteToken(messaging: Messaging): Promise<boolean>;
@@ -64,6 +72,9 @@ export declare function getMessaging(app?: FirebaseApp): Messaging;
64
72
  *
65
73
  * @returns The promise resolves with an FCM registration token.
66
74
  *
75
+ * @deprecated Use {@link register} together with {@link onRegistered} for Firebase
76
+ * Installation ID-based messaging instead of retrieving an FCM registration token with this API.
77
+ *
67
78
  * @public
68
79
  */
69
80
  export declare function getToken(messaging: Messaging, options?: GetTokenOptions): Promise<string>;
@@ -212,6 +223,68 @@ export { Observer }
212
223
  * @public
213
224
  */
214
225
  export declare function onMessage(messaging: Messaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;
226
+
227
+ /**
228
+ * Subscribes to an event that the app instance is registered with FCM via Firebase Installation ID (FID).
229
+ * Use the FID passed to the callback to upload it to your application server. When you receive an FID
230
+ * after calling {@link register}, instruct your backend to remove any legacy token for this instance.
231
+ *
232
+ * @param messaging - The {@link Messaging} instance.
233
+ * @param nextOrObserver - A function or observer object called when an FID is registered.
234
+ * @returns Unsubscribe function to stop listening.
235
+ *
236
+ * @public
237
+ */
238
+ export declare function onRegistered(messaging: Messaging, nextOrObserver: NextFn<string> | Observer<string>): Unsubscribe;
239
+
240
+ /**
241
+ * Subscribes to an event that the app instance is unregistered from FCM (FID no longer active).
242
+ * Use this to notify your backend to remove this FID to prevent 404 errors on send.
243
+ *
244
+ * @param messaging - The {@link Messaging} instance.
245
+ * @param nextOrObserver - A function or observer object called with the unregistered FID.
246
+ * @returns Unsubscribe function to stop listening.
247
+ *
248
+ * @public
249
+ */
250
+ export declare function onUnregistered(messaging: Messaging, nextOrObserver: NextFn<string> | Observer<string>): Unsubscribe;
251
+
252
+ /**
253
+ * Registers the app instance with FCM using its Firebase Installation ID (FID). The FID is
254
+ * delivered via the {@link onRegistered} callback, not as a return value. Call this to establish
255
+ * an FID-based identity; once {@link onRegistered} provides an FID, instruct your backend to
256
+ * remove any legacy token previously associated with this instance. The backend send API
257
+ * supports FID as a target.
258
+ *
259
+ * @param messaging - The {@link Messaging} instance.
260
+ * @param options - Optional. VAPID key and/or service worker registration (same as getToken).
261
+ * @returns Promise that resolves when registration has been initiated; FID is delivered via onRegistered.
262
+ *
263
+ * @public
264
+ */
265
+ export declare function register(messaging: Messaging, options?: RegisterOptions): Promise<void>;
266
+
267
+ /**
268
+ * Options for {@link register}. Same shape as GetTokenOptions for SW and VAPID configuration.
269
+ *
270
+ * @public
271
+ */
272
+ export declare interface RegisterOptions {
273
+ /** Optional VAPID key. See {@link GetTokenOptions.vapidKey}. */
274
+ vapidKey?: string;
275
+ /** Optional service worker registration. See {@link GetTokenOptions.serviceWorkerRegistration}. */
276
+ serviceWorkerRegistration?: ServiceWorkerRegistration;
277
+ }
278
+
279
+ /**
280
+ * Unregisters the app instance from FCM by deleting its FID-based registration.
281
+ * On success, triggers {@link onUnregistered} (if registered) with the unregistered FID.
282
+ *
283
+ * @param messaging - The {@link Messaging} instance.
284
+ *
285
+ * @public
286
+ */
287
+ export declare function unregister(messaging: Messaging): Promise<void>;
215
288
  export { Unsubscribe }
216
289
 
217
290
  export { }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { NextFn, Observer, Unsubscribe } from '../interfaces/public-types';
18
+ import { MessagingService } from '../messaging-service';
19
+ /**
20
+ * Subscribes to an event that the app instance is registered with FCM via Firebase Installation ID (FID).
21
+ * Use the FID passed to the callback to upload it to your application server.
22
+ *
23
+ * @param messaging - The {@link MessagingService} instance.
24
+ * @param nextOrObserver - A function or observer object called when an FID is registered.
25
+ * @returns Unsubscribe function to stop listening.
26
+ */
27
+ export declare function onRegistered(messaging: MessagingService, nextOrObserver: NextFn<string> | Observer<string>): Unsubscribe;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { NextFn, Observer, Unsubscribe } from '../interfaces/public-types';
18
+ import { MessagingService } from '../messaging-service';
19
+ /**
20
+ * Subscribes to an event that the app instance is unregistered from FCM so the FID is no longer active.
21
+ * Use this to notify your backend to remove this FID to prevent 404 errors on send.
22
+ *
23
+ * @param messaging - The {@link MessagingService} instance.
24
+ * @param nextOrObserver - A function or observer object called with the unregistered FID.
25
+ * @returns Unsubscribe function to stop listening.
26
+ */
27
+ export declare function onUnregistered(messaging: MessagingService, nextOrObserver: NextFn<string> | Observer<string>): Unsubscribe;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { MessagingService } from '../messaging-service';
18
+ import { RegisterOptions } from '../interfaces/public-types';
19
+ /**
20
+ * Registers the app instance with FCM using its Firebase Installation ID (FID). The FID is
21
+ * delivered via the `onRegistered` callback. Call this to establish an FID-based identity.
22
+ * Once `onRegistered` provides an FID, instruct your backend to remove any legacy token
23
+ * previously associated with this instance. The backend send API supports FID as a target.
24
+ *
25
+ * When called multiple times, `onRegistered` is invoked on each call with the current FID.
26
+ * Backend registration sync runs on first register, when the FID changes, or on weekly refresh.
27
+ *
28
+ * @param messaging - The MessagingService instance.
29
+ * @param options - Optional. Same options as getToken (vapidKey, serviceWorkerRegistration).
30
+ */
31
+ export declare function register(messaging: MessagingService, options?: RegisterOptions): Promise<void>;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { MessagingService } from '../messaging-service';
18
+ /**
19
+ * Unregisters the app instance from FCM by deleting its FID-based registration.
20
+ *
21
+ * On success, triggers the `onUnregistered` callback (if set) with the unregistered FID.
22
+ *
23
+ * @param messaging - The MessagingService instance.
24
+ */
25
+ export declare function unregister(messaging: MessagingService): Promise<void>;
package/dist/src/api.d.ts CHANGED
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  import { FirebaseApp } from '@firebase/app';
18
- import { GetTokenOptions, MessagePayload, Messaging } from './interfaces/public-types';
18
+ import { GetTokenOptions, MessagePayload, Messaging, RegisterOptions } from './interfaces/public-types';
19
19
  import { NextFn, Observer, Unsubscribe } from '@firebase/util';
20
20
  /**
21
21
  * Retrieves a Firebase Cloud Messaging instance.
@@ -46,6 +46,9 @@ export declare function getMessagingInSw(app?: FirebaseApp): Messaging;
46
46
  *
47
47
  * @returns The promise resolves with an FCM registration token.
48
48
  *
49
+ * @deprecated Use {@link register} together with {@link onRegistered} for Firebase
50
+ * Installation ID-based messaging instead of retrieving an FCM registration token with this API.
51
+ *
49
52
  * @public
50
53
  */
51
54
  export declare function getToken(messaging: Messaging, options?: GetTokenOptions): Promise<string>;
@@ -53,10 +56,18 @@ export declare function getToken(messaging: Messaging, options?: GetTokenOptions
53
56
  * Deletes the registration token associated with this {@link Messaging} instance and unsubscribes
54
57
  * the {@link Messaging} instance from the push subscription.
55
58
  *
59
+ * If there is no legacy registration token but the client has FID-based registration metadata
60
+ * (from {@link register}), this deletes that registration on the server, clears local metadata, and
61
+ * invokes {@link onUnregistered} with the removed FID when successful.
62
+ *
56
63
  * @param messaging - The {@link Messaging} instance.
57
64
  *
58
65
  * @returns The promise resolves when the token has been successfully deleted.
59
66
  *
67
+ * @deprecated Use {@link onUnregistered} to observe when the client is no longer
68
+ * registered and update your backend accordingly, instead of explicitly deleting the
69
+ * registration token with this API.
70
+ *
60
71
  * @public
61
72
  */
62
73
  export declare function deleteToken(messaging: Messaging): Promise<boolean>;
@@ -82,11 +93,57 @@ export declare function onMessage(messaging: Messaging, nextOrObserver: NextFn<M
82
93
  * @param nextOrObserver - This function, or observer object with `next` defined, is called when a
83
94
  * message is received and the app is currently in the background.
84
95
  *
85
- * @returns To stop listening for messages execute this returned function
96
+ * @returns To stop listening for messages execute this returned function.
86
97
  *
87
98
  * @public
88
99
  */
89
100
  export declare function onBackgroundMessage(messaging: Messaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;
101
+ /**
102
+ * Registers the app instance with FCM using its Firebase Installation ID (FID). The FID is
103
+ * delivered via the {@link onRegistered} callback, not as a return value. Call this to establish
104
+ * an FID-based identity; once {@link onRegistered} provides an FID, instruct your backend to
105
+ * remove any legacy token previously associated with this instance. The backend send API
106
+ * supports FID as a target.
107
+ *
108
+ * @param messaging - The {@link Messaging} instance.
109
+ * @param options - Optional. VAPID key and/or service worker registration (same as getToken).
110
+ * @returns Promise that resolves when registration has been initiated; FID is delivered via onRegistered.
111
+ *
112
+ * @public
113
+ */
114
+ export declare function register(messaging: Messaging, options?: RegisterOptions): Promise<void>;
115
+ /**
116
+ * Unregisters the app instance from FCM by deleting its FID-based registration.
117
+ * On success, triggers {@link onUnregistered} (if registered) with the unregistered FID.
118
+ *
119
+ * @param messaging - The {@link Messaging} instance.
120
+ *
121
+ * @public
122
+ */
123
+ export declare function unregister(messaging: Messaging): Promise<void>;
124
+ /**
125
+ * Subscribes to an event that the app instance is registered with FCM via Firebase Installation ID (FID).
126
+ * Use the FID passed to the callback to upload it to your application server. When you receive an FID
127
+ * after calling {@link register}, instruct your backend to remove any legacy token for this instance.
128
+ *
129
+ * @param messaging - The {@link Messaging} instance.
130
+ * @param nextOrObserver - A function or observer object called when an FID is registered.
131
+ * @returns Unsubscribe function to stop listening.
132
+ *
133
+ * @public
134
+ */
135
+ export declare function onRegistered(messaging: Messaging, nextOrObserver: NextFn<string> | Observer<string>): Unsubscribe;
136
+ /**
137
+ * Subscribes to an event that the app instance is unregistered from FCM (FID no longer active).
138
+ * Use this to notify your backend to remove this FID to prevent 404 errors on send.
139
+ *
140
+ * @param messaging - The {@link Messaging} instance.
141
+ * @param nextOrObserver - A function or observer object called with the unregistered FID.
142
+ * @returns Unsubscribe function to stop listening.
143
+ *
144
+ * @public
145
+ */
146
+ export declare function onUnregistered(messaging: Messaging, nextOrObserver: NextFn<string> | Observer<string>): Unsubscribe;
90
147
  /**
91
148
  * Enables or disables Firebase Cloud Messaging message delivery metrics export to BigQuery. By
92
149
  * default, message delivery metrics are not exported to BigQuery. Use this method to enable or
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { IdChangeUnsubscribeFn, Installations } from '@firebase/installations';
18
+ import { MessagingService } from '../messaging-service';
19
+ /**
20
+ * Re-runs FCM FID registration when push subscription keys change (e.g. `pushsubscriptionchange`
21
+ * in the service worker). No-op if the app instance was never registered via `register()`.
22
+ * Best-effort: callers should catch failures when permission or push may be unavailable.
23
+ */
24
+ export declare function refreshFidRegistrationIfStored(messaging: MessagingService): Promise<string | undefined>;
25
+ /**
26
+ * When the Firebase Installation ID changes, re-run `register()` so FCM registration and
27
+ * onRegistered run for the new FID. No-op if no onRegistered handler is set or the app
28
+ * instance was never registered with FCM.
29
+ */
30
+ export declare function subscribeFidChangeRegistration(messaging: MessagingService, installations: Installations): IdChangeUnsubscribeFn;
@@ -18,6 +18,8 @@ import { LogEvent, LogRequest } from '../interfaces/logging-types';
18
18
  import { MessagePayloadInternal } from '../interfaces/internal-message-payload';
19
19
  import { MessagingService } from '../messaging-service';
20
20
  export declare function startLoggingService(messaging: MessagingService): void;
21
+ /** Clears queued Firelog events, cancels any pending flush timer, and stops the logging loop. */
22
+ export declare function stopLoggingServiceAndClearQueue(messaging: MessagingService): void;
21
23
  /**
22
24
  *
23
25
  * @param messaging the messaging instance.
@@ -14,7 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { TokenDetails } from '../interfaces/token-details';
17
+ import { TokenDetails } from '../interfaces/registration-details';
18
18
  export interface V2TokenDetails {
19
19
  fcmToken: string;
20
20
  swScope: string;
@@ -22,7 +22,7 @@
22
22
  */
23
23
  import '@firebase/installations';
24
24
  import { Messaging } from './interfaces/public-types';
25
- export { getToken, deleteToken, onMessage, getMessagingInWindow as getMessaging } from './api';
25
+ export { getToken, deleteToken, register, unregister, onMessage, onRegistered, onUnregistered, getMessagingInWindow as getMessaging } from './api';
26
26
  export { isWindowSupported as isSupported } from './api/isSupported';
27
27
  export * from './interfaces/public-types';
28
28
  declare module '@firebase/component' {
@@ -17,7 +17,7 @@
17
17
  import '@firebase/installations';
18
18
  import { Messaging } from './interfaces/public-types';
19
19
  export * from './interfaces/public-types';
20
- export { onBackgroundMessage, getMessagingInSw as getMessaging, experimentalSetDeliveryMetricsExportedToBigQueryEnabled } from './api';
20
+ export { onBackgroundMessage, onRegistered, onUnregistered, getMessagingInSw as getMessaging, experimentalSetDeliveryMetricsExportedToBigQueryEnabled } from './api';
21
21
  export { isSwSupported as isSupported } from './api/isSupported';
22
22
  declare module '@firebase/component' {
23
23
  interface NameServiceMapping {
@@ -53,7 +53,8 @@ export interface FcmOptionsInternal {
53
53
  }
54
54
  export declare enum MessageType {
55
55
  PUSH_RECEIVED = "push-received",
56
- NOTIFICATION_CLICKED = "notification-clicked"
56
+ NOTIFICATION_CLICKED = "notification-clicked",
57
+ FID_REGISTERED = "fid-registered"
57
58
  }
58
59
  /** Additional data of a message sent from the FN Console. */
59
60
  export interface ConsoleMessageData {
@@ -62,4 +63,9 @@ export interface ConsoleMessageData {
62
63
  [CONSOLE_CAMPAIGN_NAME]?: string;
63
64
  [CONSOLE_CAMPAIGN_ANALYTICS_ENABLED]?: '1';
64
65
  }
66
+ export interface FidRegisteredPayload {
67
+ isFirebaseMessaging: boolean;
68
+ messageType: MessageType.FID_REGISTERED;
69
+ fid: string;
70
+ }
65
71
  export {};
@@ -121,6 +121,17 @@ export interface GetTokenOptions {
121
121
  */
122
122
  serviceWorkerRegistration?: ServiceWorkerRegistration;
123
123
  }
124
+ /**
125
+ * Options for {@link register}. Same shape as GetTokenOptions for SW and VAPID configuration.
126
+ *
127
+ * @public
128
+ */
129
+ export interface RegisterOptions {
130
+ /** Optional VAPID key. See {@link GetTokenOptions.vapidKey}. */
131
+ vapidKey?: string;
132
+ /** Optional service worker registration. See {@link GetTokenOptions.serviceWorkerRegistration}. */
133
+ serviceWorkerRegistration?: ServiceWorkerRegistration;
134
+ }
124
135
  /**
125
136
  * Public interface of the Firebase Cloud Messaging SDK.
126
137
  *
@@ -14,14 +14,27 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ import { deleteDB, openDB } from 'idb';
17
18
  import { FirebaseInternalDependencies } from '../interfaces/internal-dependencies';
18
- import { TokenDetails } from '../interfaces/token-details';
19
+ import { TokenDetails } from '../interfaces/registration-details';
19
20
  export declare const DATABASE_NAME = "firebase-messaging-database";
20
- /** Gets record(s) from the objectStore that match the given key. */
21
+ export interface FidRegistrationDetails {
22
+ fid: string;
23
+ lastRegisterTime: number;
24
+ vapidKey?: string;
25
+ }
26
+ interface IdbImpl {
27
+ openDB: typeof openDB;
28
+ deleteDB: typeof deleteDB;
29
+ }
30
+ export declare function _setIdbForTests(impl: IdbImpl): void;
31
+ export declare function _resetIdbForTests(): void;
21
32
  export declare function dbGet(firebaseDependencies: FirebaseInternalDependencies): Promise<TokenDetails | undefined>;
22
- /** Assigns or overwrites the record for the given key with the given value. */
23
33
  export declare function dbSet(firebaseDependencies: FirebaseInternalDependencies, tokenDetails: TokenDetails): Promise<TokenDetails>;
24
- /** Removes record(s) from the objectStore that match the given key. */
25
34
  export declare function dbRemove(firebaseDependencies: FirebaseInternalDependencies): Promise<void>;
35
+ export declare function dbGetFidRegistration(firebaseDependencies: FirebaseInternalDependencies): Promise<FidRegistrationDetails | undefined>;
36
+ export declare function dbSetFidRegistration(firebaseDependencies: FirebaseInternalDependencies, details: FidRegistrationDetails): Promise<FidRegistrationDetails>;
37
+ export declare function dbRemoveFidRegistration(firebaseDependencies: FirebaseInternalDependencies): Promise<void>;
26
38
  /** Deletes the DB. Useful for tests. */
27
39
  export declare function dbDelete(): Promise<void>;
40
+ export {};
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { MessagingService } from '../messaging-service';
18
+ /**
19
+ * For the new FID-based register path:
20
+ * - Create (or refresh) an FCM Web registration in the backend via CreateRegistration.
21
+ * - Use the FIS auth token produced by the installations instance (implicitly associated with FID).
22
+ * - CreateRegistration must echo the installation in `name` (e.g.
23
+ * `projects/{projectId}/registrations/{fid}`); it must match `expectedFid` from
24
+ * Installations.getId(). On mismatch we refresh the auth token and retry, then fail with
25
+ * `fid-registration-failed`.
26
+ */
27
+ export declare function registerFcmRegistrationWithFid(messaging: MessagingService, expectedFid: string): Promise<void>;
@@ -14,16 +14,30 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { SubscriptionOptions, TokenDetails } from '../interfaces/token-details';
17
+ import { SubscriptionOptions, TokenDetails } from '../interfaces/registration-details';
18
18
  import { FirebaseInternalDependencies } from '../interfaces/internal-dependencies';
19
+ /** Max attempts (initial fetch + retries) when CreateRegistration `fetch()` throws. */
20
+ export declare const FID_REGISTRATION_FETCH_MAX_ATTEMPTS = 3;
21
+ /** Base delay in ms; backoff is `BASE * 2^attempt` after each failed attempt. */
22
+ export declare const FID_REGISTRATION_FETCH_BASE_BACKOFF_MS = 1000;
19
23
  export interface ApiResponse {
20
24
  token?: string;
25
+ /**
26
+ * CreateRegistration resource name, e.g. `projects/{projectId}/registrations/{fid}`.
27
+ */
28
+ name?: string;
21
29
  error?: {
22
30
  message: string;
23
31
  };
24
32
  }
25
33
  export interface ApiRequestBody {
34
+ fcm_sdk_version?: string;
26
35
  web: {
36
+ /**
37
+ * Client identifier for the registration: the site host (e.g. `www.example.com`) when the
38
+ * service worker scope is a URL, otherwise the app name.
39
+ */
40
+ origin: string;
27
41
  endpoint: string;
28
42
  p256dh: string;
29
43
  auth: string;
@@ -31,5 +45,25 @@ export interface ApiRequestBody {
31
45
  };
32
46
  }
33
47
  export declare function requestGetToken(firebaseDependencies: FirebaseInternalDependencies, subscriptionOptions: SubscriptionOptions): Promise<string>;
48
+ /**
49
+ * Creates (or refreshes) an FCM Web registration via CreateRegistration.
50
+ *
51
+ * This is used by the FID-based register path, where we don't require the returned FCM token, but
52
+ * we do require a non-empty `name` (echoing the Firebase Installation ID) in the success response body.
53
+ */
54
+ export interface CreateRegistrationResult {
55
+ /** Firebase Installation ID parsed from the CreateRegistration response `name` field. */
56
+ responseFid: string;
57
+ }
58
+ export declare function requestCreateRegistration(firebaseDependencies: FirebaseInternalDependencies, subscriptionOptions: SubscriptionOptions): Promise<CreateRegistrationResult>;
59
+ /**
60
+ * Deletes an FCM Web registration via DeleteRegistration using the Firebase Installation ID (FID).
61
+ */
62
+ export declare function requestDeleteRegistration(firebaseDependencies: FirebaseInternalDependencies, fid: string): Promise<void>;
34
63
  export declare function requestUpdateToken(firebaseDependencies: FirebaseInternalDependencies, tokenDetails: TokenDetails): Promise<string>;
35
64
  export declare function requestDeleteToken(firebaseDependencies: FirebaseInternalDependencies, token: string): Promise<void>;
65
+ /**
66
+ * Hostname for the registering web client (e.g. `www.example.com`), or the app name
67
+ * (`appNameFallback`) when the scope cannot be resolved (e.g. some test environments).
68
+ */
69
+ export declare function getRegistrationOrigin(swScope: string, appNameFallback: string): string;
@@ -17,7 +17,10 @@
17
17
  import { MessagingService } from '../messaging-service';
18
18
  export declare function getTokenInternal(messaging: MessagingService): Promise<string>;
19
19
  /**
20
- * This method deletes the token from the database, unsubscribes the token from FCM, and unregisters
21
- * the push subscription if it exists.
20
+ * Revokes the app's FCM registration: legacy token (getToken/deleteToken) and/or FID-based
21
+ * registration (register/unregister), clears local caches, notifies onUnregistered when a stored
22
+ * FID existed, then unsubscribes the push subscription when present.
22
23
  */
23
- export declare function deleteTokenInternal(messaging: MessagingService): Promise<boolean>;
24
+ export declare function revokeRegistrationInternal(messaging: MessagingService): Promise<boolean>;
25
+ export declare function notifyOnRegistered(messaging: MessagingService, fid: string): void;
26
+ export declare function notifyOnUnregistered(messaging: MessagingService, fid: string): void;