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.0 to 11.0.1

1

dist/apns.d.ts

@@ -12,3 +12,2 @@ /// <reference types="node" />

host?: string;
port?: number;
requestTimeout?: number;

@@ -15,0 +14,0 @@ pingInterval?: number;

2

dist/index.js

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

"use strict";var R=Object.create;var p=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,H=Object.prototype.hasOwnProperty;var v=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports),B=(o,e)=>{for(var t in e)p(o,t,{get:e[t],enumerable:!0})},T=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of D(e))!H.call(o,s)&&s!==t&&p(o,s,{get:()=>e[s],enumerable:!(n=O(e,s))||n.enumerable});return o};var C=(o,e,t)=>(t=o!=null?R(M(o)):{},T(e||!o||!o.__esModule?p(t,"default",{value:o,enumerable:!0}):t,o)),U=o=>T(p({},"__esModule",{value:!0}),o);var _=v(u=>{"use strict";Object.defineProperty(u,"__esModule",{value:!0});u._fetch=void 0;var k=require("node:timers"),c=require("node:http2");async function K(o,e){let{origin:t,pathname:n,search:s}=o,r=q(t,{keepAlive:e?.keepAlive}).request({...e?.headers,[c.constants.HTTP2_HEADER_METHOD]:e?.method??"GET",[c.constants.HTTP2_HEADER_PATH]:n+s},{endStream:!e?.body});e?.body&&r.write(e.body),r.end();let{headers:A,status:N}=await L(r,e);return{status:N,headers:A,body:r,buffer:()=>j(r)}}u._fetch=K;var m={};function q(o,e){let t=m[o];if(t)return t;let n=(0,c.connect)(o);m[o]=n;let s;e?.keepAlive&&(s=(0,k.setInterval)(()=>n.ping(G),e.keepAlive));let a=()=>{(0,k.clearInterval)(s),F(n,o)};return n.on("close",a),n.on("goaway",a),n.on("error",a),n.on("frameError",a),n.on("timeout",a),n}function F(o,e){m[e]=void 0,o.closed!==!0&&o.close()}function L(o,e){return new Promise((t,n)=>{e?.timeout&&o.setTimeout(e.timeout,n),o.on("error",n),o.on("response",s=>t({headers:s,status:Number(s[c.constants.HTTP2_HEADER_STATUS])}))})}function j(o){return new Promise((e,t)=>{let n=[];o.on("error",t),o.on("data",s=>n.push(s)),o.on("end",()=>e(Buffer.concat(n)))})}function G(){}});var I=v(l=>{"use strict";Object.defineProperty(l,"__esModule",{value:!0});l.fetch=void 0;var $=_();async function J(o,e){let t=typeof o=="string"?new URL(o):o,n=await(0,$._fetch)(t,{method:e?.method,headers:e?.headers,body:e?.body,keepAlive:e?.keepAlive,timeout:e?.timeout});return{headers:n.headers,status:n.status,ok:n.status>=200&&n.status<400,url:t.href,body:n.body,async buffer(){return n.buffer()},async arrayBuffer(){let s=await n.buffer();return Uint8Array.from(s)},async text(){return(await n.buffer()).toString("utf8")},async json(){let a=(await n.buffer()).toString("utf8");return JSON.parse(a)}}}l.fetch=J});var W={};B(W,{ApnsClient:()=>y,Errors:()=>g,Notification:()=>d,Priority:()=>f,PushType:()=>h,SilentNotification:()=>b});module.exports=U(W);var S=require("jsonwebtoken"),w=require("events"),P=C(I());var g=(i=>(i.badCertificate="BadCertificate",i.badCertificateEnvironment="BadCertificateEnvironment",i.badCollapseId="BadCollapseId",i.badDeviceToken="BadDeviceToken",i.badExpirationDate="BadExpirationDate",i.badMessageId="BadMessageId",i.badPath="BadPath",i.badPriority="BadPriority",i.badTopic="BadTopic",i.deviceTokenNotForTopic="DeviceTokenNotForTopic",i.duplicateHeaders="DuplicateHeaders",i.error="Error",i.expiredProviderToken="ExpiredProviderToken",i.forbidden="Forbidden",i.idleTimeout="IdleTimeout",i.internalServerError="InternalServerError",i.invalidProviderToken="InvalidProviderToken",i.invalidPushType="InvalidPushType",i.invalidSigningKey="InvalidSigningKey",i.methodNotAllowed="MethodNotAllowed",i.missingDeviceToken="MissingDeviceToken",i.missingProviderToken="MissingProviderToken",i.missingTopic="MissingTopic",i.payloadEmpty="PayloadEmpty",i.payloadTooLarge="PayloadTooLarge",i.serviceUnavailable="ServiceUnavailable",i.shutdown="Shutdown",i.tooManyProviderTokenUpdates="TooManyProviderTokenUpdates",i.tooManyRequests="TooManyRequests",i.topicDisallowed="TopicDisallowed",i.unknownError="UnknownError",i.unregistered="Unregistered",i))(g||{});var V=3,z="api.push.apple.com",x="ES256",Q=55*60*1e3,y=class extends w.EventEmitter{team;keyId;host;signingKey;defaultTopic;_token;constructor(e){super(),this.team=e.team,this.keyId=e.keyId,this.signingKey=e.signingKey,this.defaultTopic=e.defaultTopic,this.host=e.host??z,this._token=null,this.on("ExpiredProviderToken",()=>this._resetSigningToken())}send(e){return this._send(e)}sendMany(e){let t=e.map(n=>this._send(n).catch(s=>({error:s})));return Promise.all(t)}async _send(e){let t=encodeURIComponent(e.deviceToken),n=`https://${this.host}/${V}/device/${t}`,s={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())};e.options.expiration&&(s.headers["apns-expiration"]=typeof e.options.expiration=="number"?e.options.expiration.toFixed(0):(e.options.expiration.getTime()/1e3).toFixed(0)),e.options.collapseId&&(s.headers["apns-collapse-id"]=e.options.collapseId);let a=await(0,P.fetch)(n,s);return this._handleServerResponse(a,e)}async _handleServerResponse(e,t){if(e.status===200)return t;let n;try{n=await e.json()}catch{n={reason:"UnknownError"}}throw n.statusCode=e.status,n.notification=t,this.emit(n.reason,n),this.emit("Error",n),n}_getSigningToken(){if(this._token&&Date.now()-this._token.timestamp<Q)return this._token.value;let e={iss:this.team,iat:Math.floor(Date.now()/1e3)},t;try{t=(0,S.sign)(e,this.signingKey,{algorithm:x,header:{alg:x,kid:this.keyId}})}catch{t=null,this.emit("InvalidSigningKey")}return this._token={value:t,timestamp:Date.now()},t}_resetSigningToken(){this._token=null}};var h=(r=>(r.alert="alert",r.background="background",r.voip="voip",r.complication="complication",r.fileprovider="fileprovider",r.mdm="mdm",r))(h||{});var f=(t=>(t[t.immediate=10]="immediate",t[t.throttled=5]="throttled",t))(f||{});var d=class{deviceToken;options;constructor(e,t){this.deviceToken=e,this.options=t??{}}get pushType(){return this.options.type??"alert"}get priority(){return this.options.priority??10}buildApnsOptions(){let e={aps:this.options.aps??{}};this.options.alert&&(e.aps.alert=this.options.alert),typeof this.options.contentAvailable=="boolean"&&(e.aps["content-available"]=1),typeof this.options.sound=="string"&&(e.aps.sound=this.options.sound),typeof this.options.category=="string"&&(e.aps.category=this.options.category),typeof this.options.badge=="number"&&(e.aps.badge=this.options.badge),typeof this.options.threadId=="string"&&(e.aps["thread-id"]=this.options.threadId);for(let t in this.options.data)e[t]=this.options.data[t];return e}};var b=class extends d{constructor(e,t={}){super(e,{contentAvailable:!0,type:"background",priority:5,...t})}};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 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});
{
"name": "apns2",
"version": "11.0.0",
"version": "11.0.1",
"description": "Node client for connecting to Apple's Push Notification Service using the new HTTP/2 protocol with JSON web tokens.",

@@ -10,3 +10,3 @@ "author": "Andrew Barba <barba@hey.com>",

"engines": {
"node": ">=18"
"node": ">=16"
},

@@ -17,7 +17,7 @@ "repository": {

"dependencies": {
"fetch-http2": "^1.0.2",
"fetch-http2": "^1.0.5",
"jsonwebtoken": "^9.0.0"
},
"devDependencies": {
"@tsconfig/node18": "^1.0.1",
"@tsconfig/node16": "^1.0.3",
"@types/jsonwebtoken": "^9.0.1",

@@ -24,0 +24,0 @@ "@types/mocha": "^10.0.1",

@@ -142,10 +142,2 @@ # APNS2

## Close Connections
If you need to close connections to Apple's APNS servers in order to allow the Node process to exit, you can tear down the APNS client:
```typescript
await client.close()
```
Once a client is closed you will not be able to use it again. Instead you should instantiate a new client with `new ApnsClient()`.

@@ -159,4 +151,3 @@

const client = new ApnsClient({
host: 'api.push.apple.com',
port: 443,
host: 'api.push.apple.com'
...

@@ -177,2 +168,2 @@ })

`apns2` requires Node.js v16.14 or later
`apns2` requires Node.js v16 or later

Sorry, the diff of this file is not supported yet

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