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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sirenapp/js-sdk

v1.1.0

Published

JavaScript middleware designed to streamline interaction for managing and displaying in-app notifications seamlessly

Downloads

215

Readme

Siren JS SDK

The Siren JS SDK for In-App Notifications enhances Siren's capabilities by providing users with advanced notification management functionalities within their javascript applications. This feature ensures a seamless integration process, robust error handling, and compatibility with Siren's existing ecosystem

Installation

You can install the js sdk from npm

npm install @sirenapp/js-sdk

or from yarn

yarn add @sirenapp/js-sdk

or from cdn

<script src="https://siren-js.sirenapp.io/siren-js-umd-sdk.js"></script>

Usage

Initialize the SDK by creating a class instance as follows

import Siren from "@sirenapp/js-sdk"

const sirenInstance = new Siren({
        token: "your-user-token",
        recipientId: "your-recipient-id",
        onError: (error) => {
            # error callback function
        });
        actionCallbacks:{
            onEventReceive?: (response: NotificationsApiResponse, eventType: 'NOTIFICATIONS'| 'UNVIEWED_COUNT') => {
                 # callback function to receive data
            };
            onStatusChange?: (status: 'SUCCESS' | 'FAILED' | 'PENDING') =>{
                  # callback function triggered when token verification status changes
            }
        }

All the exposed methods can be accessed using sirenInstance object. For example,to fetch all notifications,

const response = await sirenInstance.fetchAllNotifications({ page: 0, size: 10 })

Siren constructor accepts the following arguments

Siren Methods

1. verifyToken

This method verifies the validity of the given tokens (recipientId and userToken).This method is called automatically while creating the instance . Once the verification is successful, the remaining exposed methods can be accessed.

await sirenInstance.verifyToken();

2. fetchUnviewedNotificationsCount

This method retrieves the count of unviewed notifications.

const { unviewedCount } = await sirenInstance.fetchUnviewedNotificationsCount()

3. fetchAllNotifications

This method retrieves list of notifications in a paginated manner.

const notifications = await sirenInstance.fetchAllNotifications({ page: 0, size: 15, start: '', end: '', isRead: false });

Response

 interface Notifications = {
    id: string;
    createdAt?: string;
    message: {
        channel: string;
        header: string;
        subHeader: string;
        body: string;
        actionUrl: string;
        avatar: {
            imageUrl: string;
            actionUrl: string | null;
        }
        additionalData: string;
    }
    requestId: string;
    isRead: boolean;
}[]

4. startRealTimeFetch

By specifying the parameter eventType as either NOTIFICATIONS or UNVIEWED_COUNT, this method triggers the real-time retrieval of notifications or the count of unviewed notifications. If NOTIFICATIONS is selected, further parameters (params) can be provided for additional customization or filtering

sirenInstance.startRealTimeFetch({ eventType: NOTIFICATIONS, params:{ page: 0, size: 15, start: '', end: '', isRead: false }});

sirenInstance.startRealTimeFetch({ eventType: UNVIEWED_COUNT });

Below are the accepted filters for notifications

5. stopRealTimeFetch

By specifying the parameter eventType as either NOTIFICATIONS or UNVIEWED_COUNT, this method stops the real-time retrieval of notifications or the count of unviewed notifications.

sirenInstance.stopRealTimeFetch(NOTIFICATIONS);


sirenInstance.stopRealTimeFetch(UNVIEWED_COUNT);

6. markAsReadById

This method marks the notification as read. It accepts a notification id as an argument.

await sirenInstance.markAsReadById("your-notification-id");

7. markAsReadByDate

This method marks the notifications as read till the given date. It accepts an ISO date string as an argument.

await sirenInstance.markAsReadByDate("2011-10-05T14:48:00.000Z");

8. deleteById

This method deletes a notification. It accepts a notification id as an argument.

await sirenInstance.deleteById("your-notification-id");

9. deleteByDate

This method deletes the notifications till the given date. It accepts an ISO date string as an argument

await sirenInstance.deleteByDate("2011-10-05T14:48:00.000Z");

10. markAllAsViewed

This method marks the notifications as viewed till the given date. This sets the unviewed count as 0 It accepts an ISO date string as an argument

await sirenInstance.markAllAsViewed("2011-10-05T14:48:00.000Z");