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

apns2

Package Overview
Dependencies
Maintainers
0
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.7.1 to 11.8.0

12

dist/apns.d.ts

@@ -1,6 +0,5 @@

/// <reference types="node" />
/// <reference types="node" />
import { EventEmitter } from 'node:events';
import { type PrivateKey } from 'fast-jwt';
import { type Notification } from './notifications/notification';
import { EventEmitter } from "node:events";
import { type PrivateKey } from "fast-jwt";
import { FetchClient } from "fetch-http2";
import { type Notification } from "./notifications/notification";
export declare enum Host {

@@ -32,2 +31,3 @@ production = "api.push.apple.com",

readonly keepAlive?: boolean | number;
readonly fetchClient: FetchClient;
readonly pingInterval?: number;

@@ -38,3 +38,3 @@ private _token;

sendMany(notifications: Notification[]): Promise<(Notification | {
error: any;
error: unknown;
})[]>;

@@ -41,0 +41,0 @@ private _send;

@@ -12,3 +12,3 @@ "use strict";

// Signing algorithm for JSON web token
const SIGNING_ALGORITHM = 'ES256';
const SIGNING_ALGORITHM = "ES256";
// Reset our signing token every 55 minutes as reccomended by Apple

@@ -32,2 +32,3 @@ const RESET_TOKEN_INTERVAL_MS = 55 * 60 * 1000;

this.pingInterval = options.pingInterval;
this.fetchClient = new fetch_http2_1.FetchClient();
this._token = null;

@@ -48,20 +49,21 @@ this.on(errors_1.Errors.expiredProviderToken, () => this._resetSigningToken());

const url = `https://${this.host}/${API_VERSION}/device/${token}`;
const headers = {
authorization: `bearer ${this._getSigningToken()}`,
"apns-push-type": notification.pushType,
"apns-topic": notification.options.topic ?? this.defaultTopic,
};
const options = {
method: 'POST',
headers: {
authorization: `bearer ${this._getSigningToken()}`,
'apns-push-type': notification.pushType,
'apns-topic': notification.options.topic ?? this.defaultTopic
},
method: "POST",
headers: headers,
body: JSON.stringify(notification.buildApnsOptions()),
timeout: this.requestTimeout,
keepAlive: this.keepAlive ?? this.pingInterval ?? 5000
keepAlive: this.keepAlive ?? this.pingInterval ?? 5000,
};
if (notification.priority !== notification_1.Priority.immediate) {
options.headers['apns-priority'] = notification.priority.toString();
headers["apns-priority"] = notification.priority.toString();
}
const expiration = notification.options.expiration;
if (typeof expiration !== 'undefined') {
options.headers['apns-expiration'] =
typeof expiration === 'number'
if (typeof expiration !== "undefined") {
headers["apns-expiration"] =
typeof expiration === "number"
? expiration.toFixed(0)

@@ -71,5 +73,5 @@ : (expiration.getTime() / 1000).toFixed(0);

if (notification.options.collapseId) {
options.headers['apns-collapse-id'] = notification.options.collapseId;
headers["apns-collapse-id"] = notification.options.collapseId;
}
const res = await (0, fetch_http2_1.fetch)(url, options);
const res = await this.fetchClient.fetch(url, options);
return this._handleServerResponse(res, notification);

@@ -104,3 +106,3 @@ }

iss: this.team,
iat: Math.floor(Date.now() / 1000)
iat: Math.floor(Date.now() / 1000),
};

@@ -110,3 +112,3 @@ const signer = (0, fast_jwt_1.createSigner)({

algorithm: SIGNING_ALGORITHM,
kid: this.keyId
kid: this.keyId,
});

@@ -116,3 +118,3 @@ const token = signer(claims);

value: token,
timestamp: Date.now()
timestamp: Date.now(),
};

@@ -119,0 +121,0 @@ return token;

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

export * from './apns';
export * from './errors';
export * from './notifications/notification';
export * from './notifications/silent-notification';
export * from "./apns";
export * from "./errors";
export * from "./notifications/notification";
export * from "./notifications/silent-notification";

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

import { Priority } from './constants/priority';
import { PushType } from './constants/push-type';
import { Priority } from "./constants/priority";
import { PushType } from "./constants/push-type";
export { PushType, Priority };

@@ -4,0 +4,0 @@ export interface NotificationOptions {

@@ -21,3 +21,3 @@ "use strict";

const result = {
aps: this.options.aps ?? {}
aps: this.options.aps ?? {},
};

@@ -29,20 +29,20 @@ // Check for alert

// Check for "silent" notification
if (typeof this.options.contentAvailable === 'boolean') {
result.aps['content-available'] = this.options.contentAvailable ? 1 : 0;
if (typeof this.options.contentAvailable === "boolean") {
result.aps["content-available"] = this.options.contentAvailable ? 1 : 0;
}
// Check for sound
if (typeof this.options.sound === 'string' || typeof this.options.sound === 'object') {
if (typeof this.options.sound === "string" || typeof this.options.sound === "object") {
result.aps.sound = this.options.sound;
}
// Check for category
if (typeof this.options.category === 'string') {
if (typeof this.options.category === "string") {
result.aps.category = this.options.category;
}
// Check for badge
if (typeof this.options.badge === 'number') {
if (typeof this.options.badge === "number") {
result.aps.badge = this.options.badge;
}
// Check for threadId
if (typeof this.options.threadId === 'string') {
result.aps['thread-id'] = this.options.threadId;
if (typeof this.options.threadId === "string") {
result.aps["thread-id"] = this.options.threadId;
}

@@ -54,4 +54,4 @@ // Add optional message data

// Check for mutable content
if (typeof this.options.mutableContent === 'boolean') {
result.aps['mutable-content'] = this.options.mutableContent ? 1 : 0;
if (typeof this.options.mutableContent === "boolean") {
result.aps["mutable-content"] = this.options.mutableContent ? 1 : 0;
}

@@ -58,0 +58,0 @@ return result;

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

import { Notification, type NotificationOptions } from './notification';
import { Notification, type NotificationOptions } from "./notification";
export declare class SilentNotification extends Notification {
constructor(deviceToken: string, options?: Omit<NotificationOptions, 'type' | 'alert' | 'priority' | 'contentAvailable'>);
constructor(deviceToken: string, options?: Omit<NotificationOptions, "type" | "alert" | "priority" | "contentAvailable">);
}

@@ -11,3 +11,3 @@ "use strict";

priority: notification_1.Priority.throttled,
...options
...options,
});

@@ -14,0 +14,0 @@ }

{
"name": "apns2",
"version": "11.7.1",
"version": "11.8.0",
"description": "Node client for connecting to Apple's Push Notification Service using the new HTTP/2 protocol with JSON web tokens.",

@@ -31,12 +31,12 @@ "author": "Andrew Barba <barba@hey.com>",

"dependencies": {
"fast-jwt": "^4.0.1",
"fetch-http2": "^1.4.0"
"fast-jwt": "^4.0.5",
"fetch-http2": "^1.5.0"
},
"devDependencies": {
"@biomejs/biome": "^1.7.3",
"@biomejs/biome": "^1.9.4",
"@tsconfig/node16": "^16.1.3",
"@types/node": "^20.12.12",
"chai": "^5.1.1",
"typescript": "^5.4.5",
"vitest": "^1.6.0"
"@types/node": "^22.9.0",
"chai": "^5.1.2",
"typescript": "^5.6.3",
"vitest": "^2.1.5"
},

@@ -47,5 +47,5 @@ "scripts": {

"lint:format": "biome format --write src test",
"lint:check": "biome check --apply-unsafe src test",
"lint:check": "biome check --write --unsafe src test",
"test": "vitest --run --dir test"
}
}
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