firebase-admin-node icon indicating copy to clipboard operation
firebase-admin-node copied to clipboard

Upgrade from 11.11.1 to 12.0.0 and change from sendAll to sendEach throwing errors

Open dweissjcs opened this issue 2 years ago • 2 comments

Hello, I've upgraded to latest version of firebase-admin and got some deprecation method messages. One of them was sendAll which is gonna be replaced with sendEach. I checked interfaces and description provided in firebase-admin and it look same. But after switching to new sendEach method I started to get errors like

Rejected unknown error: {\"code\":\"app/invalid-credential\",\"message\":\"Failed to determine project ID: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND\"}

  • Firebase SDK version: 12.0.0
  • Firebase Product: messaging
  • Node.js version: 20.10.0
  • NPM version: 10.2.5

What has changed? Is there different approach to authorisation or something else needed to be changed? Is there any migration guide for upgrade from v11 to v12?

Thank you

dweissjcs avatar Jan 03 '24 11:01 dweissjcs

Also while debugging I have noticed circular dependency at firebase-admin have dependency "@firebase/database-compat": "^1.0.2", and database-compat have dependency back to "firebase-admin": "11.6.0",

dweissjcs avatar Jan 03 '24 12:01 dweissjcs

bump

dweissjcs avatar Jan 19 '24 07:01 dweissjcs

There were no changes to the credentials handling in v12. How do you initialize the SDK? Are you able to share some code samples with us?

lahirumaramba avatar Mar 05 '24 19:03 lahirumaramba

It's not with switch to v12, that upgrade gave us only deprecation message on fcm.messaging.sendAll.. The problem is when we switch from fcm.messaging.sendAll to fcm.messaging.sendEach

Cleaned a lot.. but its visible from it hopefully - "working way"

import fcm, { messaging as fcmTypes, FirebaseError } from 'firebase-admin';

public async sendBulk(items: any[]): Promise<any> {
    const fcmApp = fcm.apps?.find((app) => app?.name === credentials.credentialsId) ?? // this we have in config
      fcm.initializeApp(
        {
          credential: fcm.credential.cert(credentials),
        },
        credentials.credentialsId);
          
    fcm
          .messaging(fcmApp)
          // eslint-disable-next-line deprecation/deprecation -- this is deprecated method, we need to switch to .sendEach
          .sendAll(items)
          .then(({ responses }) => { // do some logic })
          .catch((error) => { // do some logic});
 }

and when we switch to .sendEach, we start getting that mentioned error

import fcm, { messaging as fcmTypes, FirebaseError } from 'firebase-admin';

public async sendBulk(items: any[]): Promise<any> {
    const fcmApp = fcm.apps?.find((app) => app?.name === credentials.credentialsId) ?? // this we have in config
      fcm.initializeApp(
        {
          credential: fcm.credential.cert(credentials),
        },
        credentials.credentialsId);
          
    fcm
          .messaging(fcmApp)
          .sendEach(items)
          .then(({ responses }) => { // do some logic })
          .catch((error) => { // do some logic});
 }

dweissjcs avatar Mar 06 '24 06:03 dweissjcs

Interesting... can you try adding projectId to see if that solves the issue?

initializeApp(
        {
          credential: fcm.credential.cert(credentials),
          projectId: `xxx-xxxxxx-xxx`, // this line
        },
        credentials.credentialsId);

lahirumaramba avatar Mar 07 '24 19:03 lahirumaramba

Thank you this helped.. Before it did not help because we had bad setup of tests which I fixed with this.. Thank you.. Anyway, is there any reason why sendEach is calling RPC one by one? Instead of sendAll where it sent all at once? Its 2-2.5 times slower than sendAll :( Thank you

dweissjcs avatar Mar 08 '24 14:03 dweissjcs

The backend API that was used by sendAll has been deprecated so we had to re implement the functionality using the send API, which sends multiple requests to the backend. We are aware of the performance issues and looking for ways to further optimize the functionality. Stay tuned!

(@jonathanedey FIY)

lahirumaramba avatar Mar 11 '24 17:03 lahirumaramba

When will sendAll stop working?

marcel-happyfloat avatar Apr 28 '24 11:04 marcel-happyfloat

I think it will stop working on June 20, 2024: https://firebase.google.com/support/faq/#fcm-depr-features

LebonNic avatar May 14 '24 07:05 LebonNic