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

@candlefinance/push

v0.5.5

Published

Gary Tokman

Downloads

7

Readme

Installation

yarn add @candlefinance/push

The motivation to write this came from the unmaintained and outdated libraries that exist today. This implementation is written in Swift in less than 200 lines of code.

Android support is coming soon. Check out #1 if you want to help.

Usage

iOS

  • [x] Request permissions
  • [x] Register for APNS token
  • [x] Remote push notifications
    • [x] Foreground
    • [x] Background
    • [x] Opened by tapping on the notification
  • [ ] Local push notifications

Setup

  1. You'll need to update your AppDelegate.swift to handle push check the example app here for an example.
  2. If your AppDelegate is in Objective-C (.mm|.m|.h), create a new AppDelegate.swift file and bridging header, then delete the Objective-C AppDelegate and main.m file. Finally, copy the contents of the example app's AppDelegate.swift and bridge header to your project.
  3. Make sure you're on iOS 15 or later.
  4. You can also use Objective-C just add bridging header and import the module.
  5. UNUserNotificationCenterDelegate set in AppDelegate.

Android

  • [x] Request permissions
  • [x] Register for FCM token
  • [x] Remote push notifications
    • [x] Foreground
    • [x] Background + Headless JS
    • [x] Opened by tapping on the notification
  • [ ] Local push notifications

Setup

  1. Add permissions in AndroidManifest.xml
  2. Add google-services.json in android/app directory from Firebase console.

API

import type { PushNotificationPermissionStatus } from '@candlefinance/push';
import { module as Push } from '@candlefinance/push';

// Shows dialog to request permission to send push notifications, gets APNS token
const isGranted = await push.requestPermissions();

// Get the APNS token w/o showing permission, useful if you want silent push notifications
push.registerForToken();

// Check permission status: 'granted', 'denied', or 'notDetermined'
const status = await push.getAuthorizationStatus();

// Listeners
React.useEffect(() => {
  const { NativeEvent, NativeHeadlessTaskKey } = Push.getConstants();
  console.log(NativeEvent, NativeHeadlessTaskKey);
  Push.addTokenEventListener(NativeEvent.TOKEN_RECEIVED, (token) => {
    console.log('TOKEN_RECEIVED:', token);
  });
  Push.addMessageEventListener(
    NativeEvent.BACKGROUND_MESSAGE_RECEIVED,
    (message, id) => {
      console.log('BACKGROUND_MESSAGE_RECEIVED:', message);
      if (id !== undefined) {
        console.log('Completing notification:', id);
        Push.completeNotification(id);
      }
    }
  );
  Push.addErrorListener(NativeEvent.FAILED_TO_REGISTER, (message) => {
    console.log('FAILED_TO_REGISTER:', message);
  });
  Push.addMessageEventListener(NativeEvent.NOTIFICATION_OPENED, (message) => {
    console.log('NOTIFICATION_OPENED:', message);
  });
  Push.addMessageEventListener(
    NativeEvent.FOREGROUND_MESSAGE_RECEIVED,
    (message) => {
      console.log('FOREGROUND_MESSAGE_RECEIVED:', message);
    }
  );
  Push.addMessageEventListener(
    NativeEvent.LAUNCH_NOTIFICATION_OPENED,
    (message) => {
      console.log('LAUNCH_NOTIFICATION_OPENED:', message);
    }
  );
  return () => {
    Push.removeListeners(NativeEvent.TOKEN_RECEIVED);
    Push.removeListeners(NativeEvent.BACKGROUND_MESSAGE_RECEIVED);
    Push.removeListeners(NativeEvent.NOTIFICATION_OPENED);
    Push.removeListeners(NativeEvent.FOREGROUND_MESSAGE_RECEIVED);
    Push.removeListeners(NativeEvent.LAUNCH_NOTIFICATION_OPENED);
  };
}, []);

Testing

If you run the example app, you can test push notifications by running the following command:

yarn push

This will use the payload.json file to send a push notification to the device. You can modify the payload to test different scenarios.

Apple also has a new console to test push notifications. If you print out the token from deviceTokenReceived listener, you can use it to send a push notification from the console.

SNS

If you're using AWS SNS, you can use the following code to send a push notification

 const message = // apns
        os === 'ios' ? JSON.stringify({ APNS: JSON.stringify(payload) })
          : // fcm
            JSON.stringify({
              GCM: JSON.stringify({
                      data: {
                        title: title,
                        body: body,
                        custom: customData,
                        data: customData,
                        priority: '1',
                        imageUrl:
                          'https://logo.png',
                        targetClass: 'com.yourapp.candle.MainActivity',
                      },
                    })
            })

Contributing

We are open to contributions. Please read our Contributing Guide for more information.

License

This project is licensed under the terms of the MIT license.

Discord

Post in #oss channel in our Discord if you have any questions or want to contribute.