Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apns2

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apns2 - npm Package Compare versions

Comparing version 11.0.1 to 11.1.0

2

dist/index.js

@@ -1,1 +0,1 @@

"use strict";var c=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var I=(s,i)=>{for(var e in i)c(s,e,{get:i[e],enumerable:!0})},x=(s,i,e,o)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of f(i))!b.call(s,n)&&n!==e&&c(s,n,{get:()=>i[n],enumerable:!(o=T(i,n))||o.enumerable});return s};var S=s=>x(c({},"__esModule",{value:!0}),s);var N={};I(N,{ApnsClient:()=>h,Errors:()=>g,Notification:()=>p,Priority:()=>l,PushType:()=>d,SilentNotification:()=>u});module.exports=S(N);var y=require("jsonwebtoken"),v=require("events"),k=require("fetch-http2");var g=(t=>(t.badCertificate="BadCertificate",t.badCertificateEnvironment="BadCertificateEnvironment",t.badCollapseId="BadCollapseId",t.badDeviceToken="BadDeviceToken",t.badExpirationDate="BadExpirationDate",t.badMessageId="BadMessageId",t.badPath="BadPath",t.badPriority="BadPriority",t.badTopic="BadTopic",t.deviceTokenNotForTopic="DeviceTokenNotForTopic",t.duplicateHeaders="DuplicateHeaders",t.error="Error",t.expiredProviderToken="ExpiredProviderToken",t.forbidden="Forbidden",t.idleTimeout="IdleTimeout",t.internalServerError="InternalServerError",t.invalidProviderToken="InvalidProviderToken",t.invalidPushType="InvalidPushType",t.invalidSigningKey="InvalidSigningKey",t.methodNotAllowed="MethodNotAllowed",t.missingDeviceToken="MissingDeviceToken",t.missingProviderToken="MissingProviderToken",t.missingTopic="MissingTopic",t.payloadEmpty="PayloadEmpty",t.payloadTooLarge="PayloadTooLarge",t.serviceUnavailable="ServiceUnavailable",t.shutdown="Shutdown",t.tooManyProviderTokenUpdates="TooManyProviderTokenUpdates",t.tooManyRequests="TooManyRequests",t.topicDisallowed="TopicDisallowed",t.unknownError="UnknownError",t.unregistered="Unregistered",t))(g||{});var P=3,_="api.push.apple.com",m="ES256",w=55*60*1e3,h=class extends v.EventEmitter{constructor(e){super();this.team=e.team,this.keyId=e.keyId,this.signingKey=e.signingKey,this.defaultTopic=e.defaultTopic,this.host=e.host??_,this._token=null,this.on("ExpiredProviderToken",()=>this._resetSigningToken())}send(e){return this._send(e)}sendMany(e){let o=e.map(n=>this._send(n).catch(r=>({error:r})));return Promise.all(o)}async _send(e){let o=encodeURIComponent(e.deviceToken),n=`https://${this.host}/${P}/device/${o}`,r={method:"POST",headers:{authorization:`bearer ${this._getSigningToken()}`,"apns-push-type":e.pushType,"apns-priority":e.priority.toString(),"apns-topic":e.options.topic??this.defaultTopic},body:JSON.stringify(e.buildApnsOptions()),keepAlive:5e3};e.options.expiration&&(r.headers["apns-expiration"]=typeof e.options.expiration=="number"?e.options.expiration.toFixed(0):(e.options.expiration.getTime()/1e3).toFixed(0)),e.options.collapseId&&(r.headers["apns-collapse-id"]=e.options.collapseId);let a=await(0,k.fetch)(n,r);return this._handleServerResponse(a,e)}async _handleServerResponse(e,o){if(e.status===200)return o;let n;try{n=await e.json()}catch{n={reason:"UnknownError"}}throw n.statusCode=e.status,n.notification=o,this.emit(n.reason,n),this.emit("Error",n),n}_getSigningToken(){if(this._token&&Date.now()-this._token.timestamp<w)return this._token.value;let e={iss:this.team,iat:Math.floor(Date.now()/1e3)},o;try{o=(0,y.sign)(e,this.signingKey,{algorithm:m,header:{alg:m,kid:this.keyId}})}catch{o=null,this.emit("InvalidSigningKey")}return this._token={value:o,timestamp:Date.now()},o}_resetSigningToken(){this._token=null}};var d=(a=>(a.alert="alert",a.background="background",a.voip="voip",a.complication="complication",a.fileprovider="fileprovider",a.mdm="mdm",a))(d||{});var l=(e=>(e[e.immediate=10]="immediate",e[e.throttled=5]="throttled",e))(l||{});var p=class{constructor(i,e){this.deviceToken=i,this.options=e??{}}get pushType(){return this.options.type??"alert"}get priority(){return this.options.priority??10}buildApnsOptions(){let i={aps:this.options.aps??{}};this.options.alert&&(i.aps.alert=this.options.alert),typeof this.options.contentAvailable=="boolean"&&(i.aps["content-available"]=1),typeof this.options.sound=="string"&&(i.aps.sound=this.options.sound),typeof this.options.category=="string"&&(i.aps.category=this.options.category),typeof this.options.badge=="number"&&(i.aps.badge=this.options.badge),typeof this.options.threadId=="string"&&(i.aps["thread-id"]=this.options.threadId);for(let e in this.options.data)i[e]=this.options.data[e];return i}};var u=class extends p{constructor(i,e={}){super(i,{contentAvailable:!0,type:"background",priority:5,...e})}};0&&(module.exports={ApnsClient,Errors,Notification,Priority,PushType,SilentNotification});
"use strict";var c=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var I=(s,i)=>{for(var e in i)c(s,e,{get:i[e],enumerable:!0})},x=(s,i,e,o)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of f(i))!b.call(s,n)&&n!==e&&c(s,n,{get:()=>i[n],enumerable:!(o=T(i,n))||o.enumerable});return s};var S=s=>x(c({},"__esModule",{value:!0}),s);var N={};I(N,{ApnsClient:()=>h,Errors:()=>g,Notification:()=>p,Priority:()=>l,PushType:()=>d,SilentNotification:()=>u});module.exports=S(N);var y=require("jsonwebtoken"),v=require("events"),k=require("fetch-http2");var g=(t=>(t.badCertificate="BadCertificate",t.badCertificateEnvironment="BadCertificateEnvironment",t.badCollapseId="BadCollapseId",t.badDeviceToken="BadDeviceToken",t.badExpirationDate="BadExpirationDate",t.badMessageId="BadMessageId",t.badPath="BadPath",t.badPriority="BadPriority",t.badTopic="BadTopic",t.deviceTokenNotForTopic="DeviceTokenNotForTopic",t.duplicateHeaders="DuplicateHeaders",t.error="Error",t.expiredProviderToken="ExpiredProviderToken",t.forbidden="Forbidden",t.idleTimeout="IdleTimeout",t.internalServerError="InternalServerError",t.invalidProviderToken="InvalidProviderToken",t.invalidPushType="InvalidPushType",t.invalidSigningKey="InvalidSigningKey",t.methodNotAllowed="MethodNotAllowed",t.missingDeviceToken="MissingDeviceToken",t.missingProviderToken="MissingProviderToken",t.missingTopic="MissingTopic",t.payloadEmpty="PayloadEmpty",t.payloadTooLarge="PayloadTooLarge",t.serviceUnavailable="ServiceUnavailable",t.shutdown="Shutdown",t.tooManyProviderTokenUpdates="TooManyProviderTokenUpdates",t.tooManyRequests="TooManyRequests",t.topicDisallowed="TopicDisallowed",t.unknownError="UnknownError",t.unregistered="Unregistered",t))(g||{});var _=3,P="api.push.apple.com",m="ES256",w=55*60*1e3,h=class extends v.EventEmitter{constructor(e){super();this.team=e.team,this.keyId=e.keyId,this.signingKey=e.signingKey,this.defaultTopic=e.defaultTopic,this.host=e.host??P,this._token=null,this.on("ExpiredProviderToken",()=>this._resetSigningToken())}send(e){return this._send(e)}sendMany(e){let o=e.map(n=>this._send(n).catch(r=>({error:r})));return Promise.all(o)}async _send(e){let o=encodeURIComponent(e.deviceToken),n=`https://${this.host}/${_}/device/${o}`,r={method:"POST",headers:{authorization:`bearer ${this._getSigningToken()}`,"apns-push-type":e.pushType,"apns-priority":e.priority.toString(),"apns-topic":e.options.topic??this.defaultTopic},body:JSON.stringify(e.buildApnsOptions()),keepAlive:5e3};e.options.expiration&&(r.headers["apns-expiration"]=typeof e.options.expiration=="number"?e.options.expiration.toFixed(0):(e.options.expiration.getTime()/1e3).toFixed(0)),e.options.collapseId&&(r.headers["apns-collapse-id"]=e.options.collapseId);let a=await(0,k.fetch)(n,r);return this._handleServerResponse(a,e)}async _handleServerResponse(e,o){if(e.status===200)return o;let n;try{n=await e.json()}catch{n={reason:"UnknownError"}}throw n.statusCode=e.status,n.notification=o,this.emit(n.reason,n),this.emit("Error",n),n}_getSigningToken(){if(this._token&&Date.now()-this._token.timestamp<w)return this._token.value;let e={iss:this.team,iat:Math.floor(Date.now()/1e3)},o;try{o=(0,y.sign)(e,this.signingKey,{algorithm:m,header:{alg:m,kid:this.keyId}})}catch{o=null,this.emit("InvalidSigningKey")}return this._token={value:o,timestamp:Date.now()},o}_resetSigningToken(){this._token=null}};var d=(a=>(a.alert="alert",a.background="background",a.voip="voip",a.complication="complication",a.fileprovider="fileprovider",a.mdm="mdm",a))(d||{});var l=(e=>(e[e.immediate=10]="immediate",e[e.throttled=5]="throttled",e))(l||{});var p=class{constructor(i,e){this.deviceToken=i,this.options=e??{}}get pushType(){return this.options.type??"alert"}get priority(){return this.options.priority??10}buildApnsOptions(){let i={aps:this.options.aps??{}};this.options.alert&&(i.aps.alert=this.options.alert),typeof this.options.contentAvailable=="boolean"&&(i.aps["content-available"]=1),typeof this.options.sound=="string"&&(i.aps.sound=this.options.sound),typeof this.options.category=="string"&&(i.aps.category=this.options.category),typeof this.options.badge=="number"&&(i.aps.badge=this.options.badge),typeof this.options.threadId=="string"&&(i.aps["thread-id"]=this.options.threadId);for(let e in this.options.data)i[e]=this.options.data[e];return i}};var u=class extends p{constructor(i,e={}){super(i,{contentAvailable:!0,type:"background",priority:5,...e})}};0&&(module.exports={ApnsClient,Errors,Notification,Priority,PushType,SilentNotification});
import { Notification, NotificationOptions } from './notification';
export declare class SilentNotification extends Notification {
constructor(deviceToken: string, options?: Pick<NotificationOptions, 'data'>);
constructor(deviceToken: string, options?: Omit<NotificationOptions, 'type' | 'alert' | 'priority' | 'contentAvailable'>);
}
{
"name": "apns2",
"version": "11.0.1",
"version": "11.1.0",
"description": "Node client for connecting to Apple's Push Notification Service using the new HTTP/2 protocol with JSON web tokens.",

@@ -5,0 +5,0 @@ "author": "Andrew Barba <barba@hey.com>",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc