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

@carisls/apple-pusher

v0.4.4

Published

Component to deliver Apple push notifications

Downloads

25

Readme

Caris Apple Pusher

NPM Version NPM Downloads Install Size GitHub Actions

Introduction

This component is used by various Caris services to push certain notifications to third party users about orders, cases and trials.

Prerequisites

In order to use this component, user needs to get:

  • privateKey for push notifications from Apple Developer account
  • keyId for that key
  • teamId for Apple Developer Account

Installation

npm i @caris/apple-pusher

Token Authentication

This component is using a token authentication to pass authorization check with Apple. Apple requires that token should be generated not more than once at least each 60 minutes, but not more than one in 20 minutes. For that reason, we need to keep previously used tokens and pass the last one to each call to this module and module will decide if a new token is needed.

How to send Requisitions notification

const pusherModule = require('@carisls/apple-pusher');
const pusher = pusherModule({
  teamId,
  keyId,
  privateKey,
  topic
});

// Send notification
pusher.pushRequisitions(
  '715ea424697fb9b0706637c43f806f46445564357a79a4fe866095910a632a4e', // deviceId
  '123332', // requisitionId
  'eyJhbGciOiJFUzI1NiIsImtpZCI6IjQ1UkVZMzk0U0QifQ.eyJpc3MiOiJLNDVFVFNXMDJRIiwiaWF0IjoxNjMwOTU5NTg4fQ.RmQny_nR11rsnJyT9_kvKWPl5KkZsq7kDkC8XIbiYJEbFzB5-ZbvLHBaGyWAPPSCSd2VGUHVtV_LZifCUs6TFg' // lastToken
)
  .then((result) => {
    /* Result will have
        - id returned by Apple APN as apns-id
        - status (HttpStatusCode 200 if ok)
        - token (new or old depending on expiration)
     */
  })
  .catch((err) => {
    /* Error will have
        - id returned by Apple APN as apns-id
        - status (HttpStatusCode 400, 403, 413, etc)
        - message (in case of error explaining the error)
        - token (new or old depending on expiration)
     */
  });

How to Generate Token for Testing?

Sometimes we want to test how our settings with Apple work. The easiest way is to try to send message manually. For that, we need token.

If you pass some token to the function it will check if it needs to be extended and if not, it will just return the same token.

const pusherModule = require('@carisls/apple-pusher');
const pusher = pusherModule({
  teamId,
  keyId,
  privateKey,
  topic
});

pusher
  .generateToken()
  .then((token) => {
    // Token is returned
  })
  .catch((err) => {
    // There was an error
  });

CLI (Command Line Interface)

For testing we have CLI pusher that can be installed by running:

npm i -g @carisls/apple-pusher

This will register a global command pusher that can be used to generate token or to push notifications.

For a complete list of options, you can run

pusher --help

Generate token

To generate a token that can be used for subsequent calls, you can run:

pusher -n -t <teamId> -k <keyId> --privateKey <base64 encoded privateKey>

Example:

pusher -n -t K45ETSW02Q -k 45REY394SD --privateKey LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JR0VBZ0VBTUJBR0J5cUdTTTQ5QWdFR0JTdUJCQUFLQkcwd2F3SUJBUVFnMlNLQ0FPckpEMnF3cW5FdzdjdFkKTm5jYXlJbkdZc01kLy9yZnc0dTM3TjZoUkFOQ0FBUkRaRlR5YmhhTnpsTCswb2s1VkRiS1N0S1BNZWNmNkhDNQovRFhrTXI0ZktLRVVxaEFJbGlTWDBoSmhzd1Vsb2trZElZVXlrVStBTlVOek5uanVmRVpFCi0tLS0tRU5EIFBSSVZBVEUgS0VZLS0tLS0K

Send Notification

To send some notification, you need to execute this:

pusher -x <token> -b <topic/bundleId> -d <deviceId> -a <type>

Example:

pusher -x eyJhbGciOiJFUzI1NiIsImtpZCI6IjQ1UkVZMzk0U0QifQ.eyJpc3MiOiJLNDVFVFNXMDJRIiwiaWF0IjoxNjMxMDM5OTY5fQ.pPKoMpkrH81velYaov81ogRA_lTThE6VYc44KwJRnMtcfwODRkPeb5UjnicWllxGed7JLyqwnQW_83ej0eS9IQ -b org.myCompany.AppName -d c851135547d66958c82395287b3dcb76673d7e40f864c628ab6106ff2e8464ac -a requisition