Packages
@notifkit/provider-fcm
The push transport, over Firebase Cloud Messaging, which reaches Android directly and iOS through APNs.
npm install @notifkit/provider-fcm
import { FcmTransport } from "@notifkit/provider-fcm";
new FcmTransport({
// The whole service-account JSON as a string, not a path to it.
serviceAccountJson: process.env.FIREBASE_SERVICE_ACCOUNT!,
});
Options
| Option | Required | Notes |
|---|---|---|
serviceAccountJson | yes | The service-account JSON, stringified. Parsed lazily on the first send. |
logger | no | Failures are logged at warn with the FCM error code. |
limits | no | Defaults to { limit: 1000, windowSeconds: 60 }: a longer window than the email transport's. |
The Firebase app is initialised once, lazily, as notifkit, keeping it separate from
any app your code initialised in the same process. Since initialisation waits for the first send,
an invalid service account shows up as a failed delivery, not a crash at boot.
Which template keys it reads
| Template key | Lands as |
|---|---|
subject | notification.title |
text or body | notification.body |
html or htmlBody | data.htmlBody, for the app to render itself |
data also carries taskId and eventId, so a tap handler can
report against its message. On Android, critical or high priority
becomes android.priority: "high", and everything else is normal. The APNs
payload has sound: "default" and badge: 1.