Comparing version 10.0.1 to 10.0.2
@@ -1,1 +0,1 @@ | ||
var S=Object.create;var l=Object.defineProperty,R=Object.defineProperties,w=Object.getOwnPropertyDescriptor,O=Object.getOwnPropertyDescriptors,A=Object.getOwnPropertyNames,k=Object.getOwnPropertySymbols,D=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var I=(i,t,e)=>t in i?l(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,p=(i,t)=>{for(var e in t||(t={}))_.call(t,e)&&I(i,e,t[e]);if(k)for(var e of k(t))N.call(t,e)&&I(i,e,t[e]);return i},c=(i,t)=>R(i,O(t));var q=(i,t)=>{for(var e in t)l(i,e,{get:t[e],enumerable:!0})},H=(i,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of A(t))!_.call(i,o)&&o!==e&&l(i,o,{get:()=>t[o],enumerable:!(s=w(t,o))||s.enumerable});return i};var M=(i,t,e)=>(e=i!=null?S(D(i)):{},H(t||!i||!i.__esModule?l(e,"default",{value:i,enumerable:!0}):e,i)),B=i=>H(l({},"__esModule",{value:!0}),i);var V={};q(V,{ApnsClient:()=>v,Errors:()=>T,Notification:()=>d,Priority:()=>m,PushType:()=>g,SilentNotification:()=>f});module.exports=B(V);var x=require("jsonwebtoken"),C=require("events");var h=M(require("http2")),{HTTP2_HEADER_SCHEME:K,HTTP2_HEADER_METHOD:U,HTTP2_HEADER_PATH:$,HTTP2_HEADER_STATUS:E,NGHTTP2_CANCEL:F}=h.constants,u=class{constructor(t,e={}){this.url=`https://${t}:${e.port}`,this.requestTimeout=e.requestTimeout??5e3,this.pingInterval=e.pingInterval??6e4,this.pingIntervalHandle=null,this.client=null}close(){return new Promise(t=>{this.client&&!this.client.closed?this.client.close(()=>t(null)):t(null)})}destroy(t,e){this.client&&!this.client.destroyed&&this.client.destroy(t,e)}request(t){return new Promise((e,s)=>{let o=c(p({},t.headers),{[K]:"https",[U]:t.method,[$]:t.path}),r=this._getOrCreateClient().request(o),a={},b="";r.setTimeout(this.requestTimeout,()=>{r.close(F),s(new Error(`http2: timeout ${t.method} ${t.path}`))}),r.on("response",y=>{Object.assign(a,y)}),r.on("data",y=>{b+=y.toString("utf8")}),r.on("end",()=>{e({statusCode:Number(a[E]),headers:a,body:b})}),r.on("error",s),t.body&&r.write(t.body),r.end()})}_getOrCreateClient(){if(this.client)return this.client;let t=h.connect(this.url);return t.on("close",()=>this._closeAndDestroy(t)),t.on("error",()=>this._closeAndDestroy(t)),t.on("socketError",()=>this._closeAndDestroy(t)),t.on("goaway",()=>this._closeAndDestroy(t)),this.pingInterval&&this._createPingInterval(t),this.client=t,t}_createPingInterval(t){let e=()=>{t.ping(()=>{})};this.pingIntervalHandle=setInterval(e,this.pingInterval).unref()}async _closeAndDestroy(t){clearInterval(this.pingIntervalHandle),await this.close(),this.destroy(),this.client=null}};var T=(n=>(n.badCertificate="BadCertificate",n.badCertificateEnvironment="BadCertificateEnvironment",n.badCollapseId="BadCollapseId",n.badDeviceToken="BadDeviceToken",n.badExpirationDate="BadExpirationDate",n.badMessageId="BadMessageId",n.badPath="BadPath",n.badPriority="BadPriority",n.badTopic="BadTopic",n.deviceTokenNotForTopic="DeviceTokenNotForTopic",n.duplicateHeaders="DuplicateHeaders",n.error="Error",n.expiredProviderToken="ExpiredProviderToken",n.forbidden="Forbidden",n.idleTimeout="IdleTimeout",n.internalServerError="InternalServerError",n.invalidProviderToken="InvalidProviderToken",n.invalidPushType="InvalidPushType",n.invalidSigningKey="InvalidSigningKey",n.methodNotAllowed="MethodNotAllowed",n.missingDeviceToken="MissingDeviceToken",n.missingProviderToken="MissingProviderToken",n.missingTopic="MissingTopic",n.payloadEmpty="PayloadEmpty",n.payloadTooLarge="PayloadTooLarge",n.serviceUnavailable="ServiceUnavailable",n.shutdown="Shutdown",n.tooManyProviderTokenUpdates="TooManyProviderTokenUpdates",n.tooManyRequests="TooManyRequests",n.topicDisallowed="TopicDisallowed",n.unknownError="UnknownError",n.unregistered="Unregistered",n))(T||{});var L=3,G="api.push.apple.com";var P="ES256",J=55*60*1e3,v=class extends C.EventEmitter{constructor(e){super();this.team=e.team,this.keyId=e.keyId,this.signingKey=e.signingKey,this.defaultTopic=e.defaultTopic,this.client=new u(e.host??G,{port:e.port,requestTimeout:e.requestTimeout,pingInterval:e.pingInterval}),this._token=null,this.on("ExpiredProviderToken",()=>this._resetSigningToken())}send(e){return this._send(e)}sendMany(e){let s=e.map(o=>this._send(o).catch(r=>({error:r})));return Promise.all(s)}close(){return this.client.close()}_send(e){let s={method:"POST",path:`/${L}/device/${encodeURIComponent(e.deviceToken)}`,headers:{authorization:`bearer ${this._getSigningToken()}`,"apns-push-type":e.pushType,"apns-priority":e.priority.toString(),"apns-topic":e.options.topic??this.defaultTopic}};return 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),this.client.request(c(p({},s),{body:JSON.stringify(e.buildApnsOptions())})).then(o=>this._handleServerResponse(o,e))}_handleServerResponse(e,s){if(e.statusCode===200)return s;let o;try{o=JSON.parse(e.body)}catch{o={reason:"UnknownError"}}throw o.statusCode=e.statusCode,o.notification=s,this.emit(o.reason,o),this.emit("Error",o),o}_getSigningToken(){if(this._token&&Date.now()-this._token.timestamp<J)return this._token.value;let e={iss:this.team,iat:Math.floor(Date.now()/1e3)},s;try{s=(0,x.sign)(e,this.signingKey,{algorithm:P,header:{alg:P,kid:this.keyId}})}catch{s=null,this.emit("InvalidSigningKey")}return this._token={value:s,timestamp:Date.now()},s}_resetSigningToken(){this._token=null}};var g=(a=>(a.alert="alert",a.background="background",a.voip="voip",a.complication="complication",a.fileprovider="fileprovider",a.mdm="mdm",a))(g||{});var m=(e=>(e[e.immediate=10]="immediate",e[e.throttled=5]="throttled",e))(m||{});var d=class{constructor(t,e){this.deviceToken=t,this.options=e??{}}get pushType(){return this.options.type??"alert"}get priority(){return this.options.priority??10}buildApnsOptions(){let t={aps:this.options.aps??{}};this.options.alert&&(t.aps.alert=this.options.alert),typeof this.options.contentAvailable=="boolean"&&(t.aps["content-available"]=1),typeof this.options.sound=="string"&&(t.aps.sound=this.options.sound),typeof this.options.category=="string"&&(t.aps.category=this.options.category),typeof this.options.badge=="number"&&(t.aps.badge=this.options.badge),typeof this.options.threadId=="string"&&(t.aps["thread-id"]=this.options.threadId);for(let e in this.options.data)t[e]=this.options.data[e];return t}};var f=class extends d{constructor(t,e={}){super(t,p({contentAvailable:!0,type:"background",priority:5},e))}};0&&(module.exports={ApnsClient,Errors,Notification,Priority,PushType,SilentNotification}); | ||
var S=Object.create;var l=Object.defineProperty,R=Object.defineProperties,w=Object.getOwnPropertyDescriptor,O=Object.getOwnPropertyDescriptors,A=Object.getOwnPropertyNames,k=Object.getOwnPropertySymbols,D=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var I=(i,t,e)=>t in i?l(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,p=(i,t)=>{for(var e in t||(t={}))_.call(t,e)&&I(i,e,t[e]);if(k)for(var e of k(t))N.call(t,e)&&I(i,e,t[e]);return i},c=(i,t)=>R(i,O(t));var q=(i,t)=>{for(var e in t)l(i,e,{get:t[e],enumerable:!0})},H=(i,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of A(t))!_.call(i,o)&&o!==e&&l(i,o,{get:()=>t[o],enumerable:!(s=w(t,o))||s.enumerable});return i};var M=(i,t,e)=>(e=i!=null?S(D(i)):{},H(t||!i||!i.__esModule?l(e,"default",{value:i,enumerable:!0}):e,i)),B=i=>H(l({},"__esModule",{value:!0}),i);var V={};q(V,{ApnsClient:()=>v,Errors:()=>T,Notification:()=>d,Priority:()=>m,PushType:()=>g,SilentNotification:()=>f});module.exports=B(V);var P=require("jsonwebtoken"),C=require("events");var h=M(require("http2")),{HTTP2_HEADER_SCHEME:K,HTTP2_HEADER_METHOD:U,HTTP2_HEADER_PATH:$,HTTP2_HEADER_STATUS:E,NGHTTP2_CANCEL:F}=h.constants,u=class{constructor(t,e={}){this.url=`https://${t}:${e.port??443}`,this.requestTimeout=e.requestTimeout??5e3,this.pingInterval=e.pingInterval??6e4,this.pingIntervalHandle=null,this.client=null}close(){return new Promise(t=>{this.client&&!this.client.closed?this.client.close(()=>t(null)):t(null)})}destroy(t,e){this.client&&!this.client.destroyed&&this.client.destroy(t,e)}request(t){return new Promise((e,s)=>{let o=c(p({},t.headers),{[K]:"https",[U]:t.method,[$]:t.path}),r=this._getOrCreateClient().request(o),a={},b="";r.setTimeout(this.requestTimeout,()=>{r.close(F),s(new Error(`http2: timeout ${t.method} ${t.path}`))}),r.on("response",y=>{Object.assign(a,y)}),r.on("data",y=>{b+=y.toString("utf8")}),r.on("end",()=>{e({statusCode:Number(a[E]),headers:a,body:b})}),r.on("error",s),t.body&&r.write(t.body),r.end()})}_getOrCreateClient(){if(this.client)return this.client;let t=h.connect(this.url);return t.on("close",()=>this._closeAndDestroy(t)),t.on("error",()=>this._closeAndDestroy(t)),t.on("socketError",()=>this._closeAndDestroy(t)),t.on("goaway",()=>this._closeAndDestroy(t)),this.pingInterval&&this._createPingInterval(t),this.client=t,t}_createPingInterval(t){let e=()=>{t.ping(()=>{})};this.pingIntervalHandle=setInterval(e,this.pingInterval).unref()}async _closeAndDestroy(t){clearInterval(this.pingIntervalHandle),await this.close(),this.destroy(),this.client=null}};var T=(n=>(n.badCertificate="BadCertificate",n.badCertificateEnvironment="BadCertificateEnvironment",n.badCollapseId="BadCollapseId",n.badDeviceToken="BadDeviceToken",n.badExpirationDate="BadExpirationDate",n.badMessageId="BadMessageId",n.badPath="BadPath",n.badPriority="BadPriority",n.badTopic="BadTopic",n.deviceTokenNotForTopic="DeviceTokenNotForTopic",n.duplicateHeaders="DuplicateHeaders",n.error="Error",n.expiredProviderToken="ExpiredProviderToken",n.forbidden="Forbidden",n.idleTimeout="IdleTimeout",n.internalServerError="InternalServerError",n.invalidProviderToken="InvalidProviderToken",n.invalidPushType="InvalidPushType",n.invalidSigningKey="InvalidSigningKey",n.methodNotAllowed="MethodNotAllowed",n.missingDeviceToken="MissingDeviceToken",n.missingProviderToken="MissingProviderToken",n.missingTopic="MissingTopic",n.payloadEmpty="PayloadEmpty",n.payloadTooLarge="PayloadTooLarge",n.serviceUnavailable="ServiceUnavailable",n.shutdown="Shutdown",n.tooManyProviderTokenUpdates="TooManyProviderTokenUpdates",n.tooManyRequests="TooManyRequests",n.topicDisallowed="TopicDisallowed",n.unknownError="UnknownError",n.unregistered="Unregistered",n))(T||{});var L=3,G="api.push.apple.com",x="ES256",J=55*60*1e3,v=class extends C.EventEmitter{constructor(e){super();this.team=e.team,this.keyId=e.keyId,this.signingKey=e.signingKey,this.defaultTopic=e.defaultTopic,this.client=new u(e.host??G,{port:e.port,requestTimeout:e.requestTimeout,pingInterval:e.pingInterval}),this._token=null,this.on("ExpiredProviderToken",()=>this._resetSigningToken())}send(e){return this._send(e)}sendMany(e){let s=e.map(o=>this._send(o).catch(r=>({error:r})));return Promise.all(s)}close(){return this.client.close()}_send(e){let s={method:"POST",path:`/${L}/device/${encodeURIComponent(e.deviceToken)}`,headers:{authorization:`bearer ${this._getSigningToken()}`,"apns-push-type":e.pushType,"apns-priority":e.priority.toString(),"apns-topic":e.options.topic??this.defaultTopic}};return 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),this.client.request(c(p({},s),{body:JSON.stringify(e.buildApnsOptions())})).then(o=>this._handleServerResponse(o,e))}_handleServerResponse(e,s){if(e.statusCode===200)return s;let o;try{o=JSON.parse(e.body)}catch{o={reason:"UnknownError"}}throw o.statusCode=e.statusCode,o.notification=s,this.emit(o.reason,o),this.emit("Error",o),o}_getSigningToken(){if(this._token&&Date.now()-this._token.timestamp<J)return this._token.value;let e={iss:this.team,iat:Math.floor(Date.now()/1e3)},s;try{s=(0,P.sign)(e,this.signingKey,{algorithm:x,header:{alg:x,kid:this.keyId}})}catch{s=null,this.emit("InvalidSigningKey")}return this._token={value:s,timestamp:Date.now()},s}_resetSigningToken(){this._token=null}};var g=(a=>(a.alert="alert",a.background="background",a.voip="voip",a.complication="complication",a.fileprovider="fileprovider",a.mdm="mdm",a))(g||{});var m=(e=>(e[e.immediate=10]="immediate",e[e.throttled=5]="throttled",e))(m||{});var d=class{constructor(t,e){this.deviceToken=t,this.options=e??{}}get pushType(){return this.options.type??"alert"}get priority(){return this.options.priority??10}buildApnsOptions(){let t={aps:this.options.aps??{}};this.options.alert&&(t.aps.alert=this.options.alert),typeof this.options.contentAvailable=="boolean"&&(t.aps["content-available"]=1),typeof this.options.sound=="string"&&(t.aps.sound=this.options.sound),typeof this.options.category=="string"&&(t.aps.category=this.options.category),typeof this.options.badge=="number"&&(t.aps.badge=this.options.badge),typeof this.options.threadId=="string"&&(t.aps["thread-id"]=this.options.threadId);for(let e in this.options.data)t[e]=this.options.data[e];return t}};var f=class extends d{constructor(t,e={}){super(t,p({contentAvailable:!0,type:"background",priority:5},e))}};0&&(module.exports={ApnsClient,Errors,Notification,Priority,PushType,SilentNotification}); |
{ | ||
"name": "apns2", | ||
"version": "10.0.1", | ||
"version": "10.0.2", | ||
"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>", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
19012
1