@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
@@ -20,7 +20,7 @@ import { FirebaseAnalyticsInternalName } from '@firebase/analytics-interop-types
20
20
  import { FirebaseInternalDependencies } from './interfaces/internal-dependencies';
21
21
  import { LogEvent } from './interfaces/logging-types';
22
22
  import { Provider } from '@firebase/component';
23
- import { _FirebaseInstallationsInternal } from '@firebase/installations';
23
+ import { _FirebaseInstallationsInternal, IdChangeUnsubscribeFn } from '@firebase/installations';
24
24
  export declare class MessagingService implements _FirebaseService {
25
25
  readonly app: FirebaseApp;
26
26
  readonly firebaseDependencies: FirebaseInternalDependencies;
@@ -29,8 +29,33 @@ export declare class MessagingService implements _FirebaseService {
29
29
  deliveryMetricsExportedToBigQueryEnabled: boolean;
30
30
  onBackgroundMessageHandler: NextFn<MessagePayload> | Observer<MessagePayload> | null;
31
31
  onMessageHandler: NextFn<MessagePayload> | Observer<MessagePayload> | null;
32
+ /** Observer for the event that the app instance is registered with FCM via Firebase Installation ID (FID). */
33
+ onRegisteredHandler: NextFn<string> | Observer<string> | null;
34
+ /** Observer for the event that the app instance is unregistered from FCM (FID no longer active). */
35
+ onUnregisteredHandler: NextFn<string> | Observer<string> | null;
36
+ /**
37
+ * Serializes the FID get + compare + notify step so concurrent register() calls
38
+ * do not race each other.
39
+ */
40
+ _registerNotifyChain: Promise<void>;
41
+ /** Unsubscribe from Installations `onIdChange` when messaging is deleted. */
42
+ _fidChangeUnsubscribe: IdChangeUnsubscribeFn | null;
32
43
  logEvents: LogEvent[];
33
- isLogServiceStarted: boolean;
44
+ /**
45
+ * Single source of truth for the logging loop lifecycle.
46
+ *
47
+ * `scheduled` holds the active timer id; `flushing` indicates an async dispatch
48
+ * is in progress (prevents duplicate starts); `stopped` means idle.
49
+ */
50
+ logQueue: LogQueueState;
34
51
  constructor(app: FirebaseApp, installations: _FirebaseInstallationsInternal, analyticsProvider: Provider<FirebaseAnalyticsInternalName>);
35
52
  _delete(): Promise<void>;
36
53
  }
54
+ export type LogQueueState = {
55
+ state: 'stopped';
56
+ } | {
57
+ state: 'scheduled';
58
+ timerId: ReturnType<typeof setTimeout>;
59
+ } | {
60
+ state: 'flushing';
61
+ };
@@ -14,5 +14,5 @@
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 declare function getFakeTokenDetails(): TokenDetails;
@@ -26,6 +26,9 @@ export declare const enum ErrorCode {
26
26
  FAILED_DEFAULT_REGISTRATION = "failed-service-worker-registration",
27
27
  TOKEN_SUBSCRIBE_FAILED = "token-subscribe-failed",
28
28
  TOKEN_SUBSCRIBE_NO_TOKEN = "token-subscribe-no-token",
29
+ FID_REGISTRATION_FAILED = "fid-registration-failed",
30
+ FID_UNREGISTER_FAILED = "fid-unregister-failed",
31
+ FID_REGISTRATION_IDB_SCHEMA_UNAVAILABLE = "fid-registration-idb-schema-unavailable",
29
32
  TOKEN_UNSUBSCRIBE_FAILED = "token-unsubscribe-failed",
30
33
  TOKEN_UPDATE_FAILED = "token-update-failed",
31
34
  TOKEN_UPDATE_NO_TOKEN = "token-update-no-token",
@@ -33,7 +36,8 @@ export declare const enum ErrorCode {
33
36
  USE_SW_AFTER_GET_TOKEN = "use-sw-after-get-token",
34
37
  INVALID_SW_REGISTRATION = "invalid-sw-registration",
35
38
  USE_VAPID_KEY_AFTER_GET_TOKEN = "use-vapid-key-after-get-token",
36
- INVALID_VAPID_KEY = "invalid-vapid-key"
39
+ INVALID_VAPID_KEY = "invalid-vapid-key",
40
+ INVALID_ON_REGISTERED_HANDLER = "invalid-on-registered-handler"
37
41
  }
38
42
  export declare const ERROR_MAP: ErrorMap<ErrorCode>;
39
43
  interface ErrorParams {
@@ -46,6 +50,12 @@ interface ErrorParams {
46
50
  [ErrorCode.TOKEN_SUBSCRIBE_FAILED]: {
47
51
  errorInfo: string;
48
52
  };
53
+ [ErrorCode.FID_REGISTRATION_FAILED]: {
54
+ errorInfo: string;
55
+ };
56
+ [ErrorCode.FID_UNREGISTER_FAILED]: {
57
+ errorInfo: string;
58
+ };
49
59
  [ErrorCode.TOKEN_UNSUBSCRIBE_FAILED]: {
50
60
  errorInfo: string;
51
61
  };
@@ -157,10 +157,44 @@ export { Observer };
157
157
  * @param nextOrObserver - This function, or observer object with `next` defined, is called when a
158
158
  * message is received and the app is currently in the background.
159
159
  *
160
- * @returns To stop listening for messages execute this returned function
160
+ * @returns To stop listening for messages execute this returned function.
161
161
  *
162
162
  * @public
163
163
  */
164
164
  export declare function onBackgroundMessage(messaging: Messaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;
165
+ /**
166
+ * Subscribes to an event that the app instance is registered with FCM via Firebase Installation ID (FID).
167
+ * Use the FID passed to the callback to upload it to your application server. When you receive an FID
168
+ * after calling {@link register}, instruct your backend to remove any legacy token for this instance.
169
+ *
170
+ * @param messaging - The {@link Messaging} instance.
171
+ * @param nextOrObserver - A function or observer object called when an FID is registered.
172
+ * @returns Unsubscribe function to stop listening.
173
+ *
174
+ * @public
175
+ */
176
+ export declare function onRegistered(messaging: Messaging, nextOrObserver: NextFn<string> | Observer<string>): Unsubscribe;
177
+ /**
178
+ * Subscribes to an event that the app instance is unregistered from FCM (FID no longer active).
179
+ * Use this to notify your backend to remove this FID to prevent 404 errors on send.
180
+ *
181
+ * @param messaging - The {@link Messaging} instance.
182
+ * @param nextOrObserver - A function or observer object called with the unregistered FID.
183
+ * @returns Unsubscribe function to stop listening.
184
+ *
185
+ * @public
186
+ */
187
+ export declare function onUnregistered(messaging: Messaging, nextOrObserver: NextFn<string> | Observer<string>): Unsubscribe;
188
+ /**
189
+ * Options for {@link register}. Same shape as GetTokenOptions for SW and VAPID configuration.
190
+ *
191
+ * @public
192
+ */
193
+ export declare interface RegisterOptions {
194
+ /** Optional VAPID key. See {@link GetTokenOptions.vapidKey}. */
195
+ vapidKey?: string;
196
+ /** Optional service worker registration. See {@link GetTokenOptions.serviceWorkerRegistration}. */
197
+ serviceWorkerRegistration?: ServiceWorkerRegistration;
198
+ }
165
199
  export { Unsubscribe };
166
200
  export {};
@@ -170,11 +170,48 @@ export { Observer }
170
170
  * @param nextOrObserver - This function, or observer object with `next` defined, is called when a
171
171
  * message is received and the app is currently in the background.
172
172
  *
173
- * @returns To stop listening for messages execute this returned function
173
+ * @returns To stop listening for messages execute this returned function.
174
174
  *
175
175
  * @public
176
176
  */
177
177
  export declare function onBackgroundMessage(messaging: Messaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;
178
+
179
+ /**
180
+ * Subscribes to an event that the app instance is registered with FCM via Firebase Installation ID (FID).
181
+ * Use the FID passed to the callback to upload it to your application server. When you receive an FID
182
+ * after calling {@link register}, instruct your backend to remove any legacy token for this instance.
183
+ *
184
+ * @param messaging - The {@link Messaging} instance.
185
+ * @param nextOrObserver - A function or observer object called when an FID is registered.
186
+ * @returns Unsubscribe function to stop listening.
187
+ *
188
+ * @public
189
+ */
190
+ export declare function onRegistered(messaging: Messaging, nextOrObserver: NextFn<string> | Observer<string>): Unsubscribe;
191
+
192
+ /**
193
+ * Subscribes to an event that the app instance is unregistered from FCM (FID no longer active).
194
+ * Use this to notify your backend to remove this FID to prevent 404 errors on send.
195
+ *
196
+ * @param messaging - The {@link Messaging} instance.
197
+ * @param nextOrObserver - A function or observer object called with the unregistered FID.
198
+ * @returns Unsubscribe function to stop listening.
199
+ *
200
+ * @public
201
+ */
202
+ export declare function onUnregistered(messaging: Messaging, nextOrObserver: NextFn<string> | Observer<string>): Unsubscribe;
203
+
204
+ /**
205
+ * Options for {@link register}. Same shape as GetTokenOptions for SW and VAPID configuration.
206
+ *
207
+ * @public
208
+ */
209
+ export declare interface RegisterOptions {
210
+ /** Optional VAPID key. See {@link GetTokenOptions.vapidKey}. */
211
+ vapidKey?: string;
212
+ /** Optional service worker registration. See {@link GetTokenOptions.serviceWorkerRegistration}. */
213
+ serviceWorkerRegistration?: ServiceWorkerRegistration;
214
+ }
178
215
  export { Unsubscribe }
179
216
 
180
217
  export { }
@@ -167,11 +167,48 @@ export { Observer }
167
167
  * @param nextOrObserver - This function, or observer object with `next` defined, is called when a
168
168
  * message is received and the app is currently in the background.
169
169
  *
170
- * @returns To stop listening for messages execute this returned function
170
+ * @returns To stop listening for messages execute this returned function.
171
171
  *
172
172
  * @public
173
173
  */
174
174
  export declare function onBackgroundMessage(messaging: Messaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;
175
+
176
+ /**
177
+ * Subscribes to an event that the app instance is registered with FCM via Firebase Installation ID (FID).
178
+ * Use the FID passed to the callback to upload it to your application server. When you receive an FID
179
+ * after calling {@link register}, instruct your backend to remove any legacy token for this instance.
180
+ *
181
+ * @param messaging - The {@link Messaging} instance.
182
+ * @param nextOrObserver - A function or observer object called when an FID is registered.
183
+ * @returns Unsubscribe function to stop listening.
184
+ *
185
+ * @public
186
+ */
187
+ export declare function onRegistered(messaging: Messaging, nextOrObserver: NextFn<string> | Observer<string>): Unsubscribe;
188
+
189
+ /**
190
+ * Subscribes to an event that the app instance is unregistered from FCM (FID no longer active).
191
+ * Use this to notify your backend to remove this FID to prevent 404 errors on send.
192
+ *
193
+ * @param messaging - The {@link Messaging} instance.
194
+ * @param nextOrObserver - A function or observer object called with the unregistered FID.
195
+ * @returns Unsubscribe function to stop listening.
196
+ *
197
+ * @public
198
+ */
199
+ export declare function onUnregistered(messaging: Messaging, nextOrObserver: NextFn<string> | Observer<string>): Unsubscribe;
200
+
201
+ /**
202
+ * Options for {@link register}. Same shape as GetTokenOptions for SW and VAPID configuration.
203
+ *
204
+ * @public
205
+ */
206
+ export declare interface RegisterOptions {
207
+ /** Optional VAPID key. See {@link GetTokenOptions.vapidKey}. */
208
+ vapidKey?: string;
209
+ /** Optional service worker registration. See {@link GetTokenOptions.serviceWorkerRegistration}. */
210
+ serviceWorkerRegistration?: ServiceWorkerRegistration;
211
+ }
175
212
  export { Unsubscribe }
176
213
 
177
214
  export { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firebase/messaging",
3
- "version": "0.12.26",
3
+ "version": "0.13.0-20260526192810",
4
4
  "description": "",
5
5
  "author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
6
6
  "main": "dist/index.cjs.js",
@@ -53,7 +53,7 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@firebase/installations": "0.6.22",
56
- "@firebase/messaging-interop-types": "0.2.4",
56
+ "@firebase/messaging-interop-types": "0.2.5-20260526192810",
57
57
  "@firebase/util": "1.15.1",
58
58
  "@firebase/component": "0.7.3",
59
59
  "idb": "7.1.1",