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

@engagespot/core-v2

v1.1.8

Published

Engagespot Javascript Core Functions

Downloads

5

Readme

Javascript Core

Javascript Core package wraps the REST API calls into easy to use functions for any Javascript app. With this package, you can build Notification Inbox, Subscribe users to web push, build preference manager etc.

:::tip Javascript core library doesn't provide any UI components. If you're looking for UI-Kit for Javascript, you should use our React component or Browser Javascript UI Kit. :::

Quick Setup

Before we start, make sure you have Engagespot API Key from your dashboard. Now, let's install the core package, and initialize.

npm i @engagespot/core --save

#or

yarn add @engagespot/core

Now let's add this library to a project with basic configurations.

import Engagespot from '@engagespot/core';

const engagespot = new Engagespot('YOUR_ENGAGESPOT_API_KEY', {
  userId: '[email protected]',
});

const notificationList = engagespot.getNotificationList();
await notificationList.fetch();
notificationList.data.forEach(notification => {
  console.log(notification.title, notification.message);
});

Engagespot Class

This class is used to create a new Engagespot instance.

Constructor

The constructor accepts the following arguments.

| Property | Type | Description | | --------------------------------- | ------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | | apiKey | string | Engagespot API Key | | options | Object | Options Object. (Properties explained below) | | options.userId | string | Any unique identifier to identify your app user | | options.userSignature | string | Required if your app has HMAC Authentication turned on. | | options.serviceWorkerRegistration | ServiceWorkerRegistration | Use this if your app has an existing Service Worker Registration |

Fetching Notifications

To fetch notification list, you should use the getNotificationList() method, which returns the NotificationList object. Note that, the NotificationList object will be empty, and you need to call the fetch() method to pull the latest notification data from server.

We've seen this in the example above. After calling fetch() which returns Promise<this>, you can access the notifications from data[]

Let's learn more about NotificationList class below.

NotificationList Class

Notification list is a collection of Notifications. It implements the NotificationItem interface.

export interface NotificationList {
  unreadCount: number;
  totalCount: number;

  data: NotificationItem[];

  fetch: (page: number, itemsPerPage: number) => Promise<this>;
  markAllAsSeen: () => Promise<this>;
}

Properties

The NotificationList interface has the following properties.

unreadCount

Number of unseen notifications in the list.

totalCount

Total number of notifications in the list

Methods

fetch

Fetches the notifications from the server and add them to the data[] property.

NotificationItem Interface

NotificationItem interface represents a single notification entity. It has several properties and methods to do actions on that particular notification.

interface NotificationItem {
  id: string;
  title: string;
  message?: string | null;
  icon?: string | null;
  url?: string | null;
  seenAt?: string | null;
  clickedAt?: string | null;
  createdAt?: string | null;

  fetch?:  () => Promise<this>;
  markAsClicked?:  () => Promise<this>;
  delete? () => Promise<this>
}

Properties

The NotificationItem interface has the following properties.

id

Id of the notification

title

Title of the notification

message

Body of notification. This can be null.

icon

URL of the notification icon. This can be null.

seenAt

Timestamp of seen event of this notification. This can be null.

clickedAt

Timestamp of click event of this notification. This can be null.

createdAt

Timestamp of created event of this notification.

Methods

The NotificationItem interface has the following methods.

fetch

Calls GET /notifications/:notificationId API and sets the properties of this class.

markAsClicked

Calls POST /notifications/:notificationId/click API and marks this notification as clicked.

delete

Calls DELETE /notifications/:notificationId API and deletes this notification.

Events

Engagespot Core emits several events which you can susbcribe to do custom actions.

onNotificationReceive

import Engagespot from '@engagespot/core';

const engagespot = new Engagespot('YOUR_ENGAGESPOT_API_KEY', {
  userId: '[email protected]',
});

engagespot.onNotificationReceive(notification => {
  //You'll get the notification object.
});

onNotificationClick

import Engagespot from '@engagespot/core';

const engagespot = new Engagespot('YOUR_ENGAGESPOT_API_KEY', {
  userId: '[email protected]',
});

engagespot.onNotificationClick(notification => {
  //You'll get the notification object.
});

onNotificationDelete

import Engagespot from '@engagespot/core';

const engagespot = new Engagespot('YOUR_ENGAGESPOT_API_KEY', {
  userId: '[email protected]',
});

engagespot.onNotificationDelete(notification => {
  //You'll get the notification object.
});

onNotificationSee

import Engagespot from '@engagespot/core';

const engagespot = new Engagespot('YOUR_ENGAGESPOT_API_KEY', {
  userId: '[email protected]',
});

engagespot.onNotificationSee(notification => {
  //You'll get the notification object.
});