From faa76032bb29ac475314f19d6212b9f1e4bd93db Mon Sep 17 00:00:00 2001 From: Andrew Barba Date: Tue, 20 Feb 2024 17:42:23 -0500 Subject: [PATCH] Add ApnsClient keepAlive --- CHANGELOG.md | 5 +++++ README.md | 2 +- package.json | 4 ++-- pnpm-lock.yaml | 8 ++++---- src/apns.ts | 9 ++++++++- test/apns2.test.ts | 2 +- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9924c8f..92d397b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ --- +## [11.5.0](https://github.com/AndrewBarba/apns2/releases/tag/11.5.0) + +1. Add `ApnsClient.keepAlive` +2. Deprecate `ApnsClient.pingInterval` + ## [11.4.0](https://github.com/AndrewBarba/apns2/releases/tag/11.4.0) 1. Add `location` push type diff --git a/README.md b/README.md index 493dea7..9945a51 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ const client = new ApnsClient({ signingKey: fs.readFileSync(`${__dirname}/path/to/auth.p8`), defaultTopic: `com.tablelist.Tablelist`, requestTimeout: 0, // optional, Default: 0 (without timeout) - pingInterval: 5000, // optional, Default: 5000 + keepAlive: true, // optional, Default: 5000 }) ``` diff --git a/package.json b/package.json index e0afcfe..f9c0468 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apns2", - "version": "11.4.0", + "version": "11.5.0", "description": "Node client for connecting to Apple's Push Notification Service using the new HTTP/2 protocol with JSON web tokens.", "author": "Andrew Barba ", "main": "dist/index.js", @@ -28,7 +28,7 @@ "watchos" ], "dependencies": { - "fetch-http2": "^1.3.0", + "fetch-http2": "^1.4.0", "fast-jwt": "^3.3.2" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 13a6367..dbf6791 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ dependencies: specifier: ^3.3.2 version: 3.3.2 fetch-http2: - specifier: ^1.3.0 - version: 1.3.0 + specifier: ^1.4.0 + version: 1.4.0 devDependencies: '@biomejs/biome': @@ -690,8 +690,8 @@ packages: mnemonist: 0.39.7 dev: false - /fetch-http2@1.3.0: - resolution: {integrity: sha512-UH37pMSGUOnHeXog91FHwcUC8/DmypYfQmKspF29UOBoS1BpGUU5YX6LjbYjeCZpGWjklfWiOyV/vOg1r7CHWw==} + /fetch-http2@1.4.0: + resolution: {integrity: sha512-EZJioHAd26PUg+IfAun3TjcJ2+PILm4jeULLuz0Z8SL2K23KoVnZw5sRCTdpXlspV6kEc6W4E+iG1fdbt0RZ0A==} engines: {node: '>=16'} dev: false diff --git a/src/apns.ts b/src/apns.ts index 2e4772f..a930b67 100644 --- a/src/apns.ts +++ b/src/apns.ts @@ -30,6 +30,9 @@ export interface ApnsOptions { defaultTopic?: string host?: Host | string requestTimeout?: number + keepAlive?: boolean | number + + // @deprecated Use keepAlive instead pingInterval?: number } @@ -40,6 +43,9 @@ export class ApnsClient extends EventEmitter { readonly signingKey: string | Buffer | PrivateKey readonly defaultTopic?: string readonly requestTimeout?: number + readonly keepAlive?: boolean | number + + // @deprecated Use keepAlive instead readonly pingInterval?: number private _token: SigningToken | null @@ -52,6 +58,7 @@ export class ApnsClient extends EventEmitter { this.defaultTopic = options.defaultTopic this.host = options.host ?? Host.production this.requestTimeout = options.requestTimeout + this.keepAlive = options.keepAlive this.pingInterval = options.pingInterval this._token = null this.on(Errors.expiredProviderToken, () => this._resetSigningToken()) @@ -80,7 +87,7 @@ export class ApnsClient extends EventEmitter { }, body: JSON.stringify(notification.buildApnsOptions()), timeout: this.requestTimeout, - keepAlive: this.pingInterval ?? 5000 + keepAlive: this.keepAlive ?? this.pingInterval ?? 5000 } if (notification.priority !== Priority.immediate) { diff --git a/test/apns2.test.ts b/test/apns2.test.ts index 5dc0a84..2a6f290 100644 --- a/test/apns2.test.ts +++ b/test/apns2.test.ts @@ -14,7 +14,7 @@ describe('apns', () => { keyId: '7U6GT5Q49J', signingKey: process.env.APNS_SIGNING_KEY ?? '', defaultTopic: 'com.tablelist.Tablelist', - pingInterval: 100 + keepAlive: 100 }) })