npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ymys/directus-extension-fcm-hook

v2.3.9

Published

FCM Push Notifications Hook for Directus

Readme

Directus FCM Hook Extension

A Directus extension that automatically sends Firebase Cloud Messaging (FCM) push notifications when new items are created in the inbox collection.

Features

  • Automated Notifications: Triggers when a new message is added to your inbox.
  • FCM HTTP v1 API: Uses the modern Google OAuth 2.0 authentication.
  • HTML Stripping: Automatically strips HTML tags from message content for the notification body.
  • Metadata Support: Passes inbox ID and message type to the mobile app for deep-linking.

Prerequisites

To use this extension, your Directus schema must include the following:

1. user_devices Collection

Used to store FCM registration tokens for your users.

  • user_id: (Many-to-One to directus_users) The owner of the device.
  • token: (String) The FCM registration token.

2. inbox Collection

The collection that triggers personal notifications.

  • penerima: (Many-to-One to directus_users) The recipient of the message.
  • judul: (String) The title of the notification.
  • pesan: (Text/HTML) The body of the notification.
  • tipe_pesan: (String, Optional) Used for routing logic in the app.

3. broadcast Collection

Used for sending notifications to multiple users at once.

  • topic: (Many-to-One to broadcast_topics) If set, sends to an FCM Topic.
  • target_role: (Many-to-One to directus_roles) If set, sends to all users with this role.
  • judul: (String) The title of the notification.
  • pesan: (Text/HTML) The body of the notification.

[!NOTE] If both topic and target_role are empty in a broadcast, the notification will be sent to ALL users with registered devices.

Installation

  1. Install the package in your Directus project:
    npm install @ymys/directus-extension-fcm-hook
  2. Restart your Directus instance.

Configuration

Add the following environment variables to your Directus .env file. You can find these values in your Firebase Service Account JSON file.

| Variable | Description | | :--- | :--- | | FCM_PROJECT_ID | Your Firebase Project ID. | | FCM_CLIENT_EMAIL | The service account email (e.g., [email protected]). | | FCM_PRIVATE_KEY | The full private key including -----BEGIN PRIVATE KEY----- and -----END PRIVATE KEY-----. |

[!TIP] If your FCM_PRIVATE_KEY contains literal \n characters, the extension will automatically convert them to actual newlines.

How it Works

  1. When a record is created in inbox.
  2. The hook looks up all active tokens in the user_devices collection for the specified penerima.
  3. It generates a Google OAuth 2.0 Access Token on the fly.
  4. It sends a POST request to the FCM v1 API for each device token.
  5. The notification includes:
    • Title: From judul (defaults to "Pesan Baru").
    • Body: From pesan (HTML stripped, defaults to "Anda menerima pesan baru.").
    • Data Payload: Includes inbox_id and tipe_pesan inside routing_info.

License

MIT