@carisls/apple-pusher

0.4.4 • Public • Published

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

Package Sidebar

Install

npm i @carisls/apple-pusher

Weekly Downloads

9

Version

0.4.4

License

MIT

Unpacked Size

16.5 kB

Total Files

12

Last publish

Collaborators

  • mstrujic-caris
  • michaelortho