Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add the ability to manage channels and send broadcasts #164

Open
wants to merge 80 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
b35fbb8
add TS missing properties
cbaker6 Dec 29, 2024
71f2cf1
feat: Add the ability to use different http methods
cbaker6 Dec 30, 2024
0b4022f
Merge branch 'master' into useBroadcastPath
cbaker6 Dec 30, 2024
49b5bf5
lint
cbaker6 Dec 30, 2024
5e83b2a
Merge branch 'useBroadcastPath' of https://github.com/cbaker6/node-ap…
cbaker6 Dec 30, 2024
e5bf411
test v2 as provider
cbaker6 Dec 30, 2024
5b029b7
replace original client with V2
cbaker6 Dec 30, 2024
755aeec
lint
cbaker6 Dec 30, 2024
058070c
create manageBroadcastSession
cbaker6 Dec 31, 2024
8136a8c
nit
cbaker6 Dec 31, 2024
3d348fc
nit
cbaker6 Dec 31, 2024
a1263c7
add channels method
cbaker6 Dec 31, 2024
36b3f35
nit
cbaker6 Dec 31, 2024
8ec017d
update typescript
cbaker6 Dec 31, 2024
53393f0
make JS match TS
cbaker6 Jan 1, 2025
6cf1299
delete non channel related headers when necessary
cbaker6 Jan 1, 2025
5193a14
Merge branch 'master' into useBroadcastPath
cbaker6 Jan 1, 2025
c21e682
use async/await
cbaker6 Jan 2, 2025
b7a5bfe
Merge branch 'useBroadcastPath' of https://github.com/cbaker6/node-ap…
cbaker6 Jan 2, 2025
dee2882
lint
cbaker6 Jan 2, 2025
576a62d
fix code on older versions of node
cbaker6 Jan 2, 2025
d006ded
add initial tests for manageBroadcastSession
cbaker6 Jan 2, 2025
6318b98
throw error if reached connectionRetryLimit
cbaker6 Jan 2, 2025
bcd1364
improve usage of connectionRetryLimit, defaults to 2 instead of 10
cbaker6 Jan 2, 2025
446c8f2
manageBroadcast -> manageChannels
cbaker6 Jan 2, 2025
2f814c9
make code for connectionRetryLimit match documentation
cbaker6 Jan 2, 2025
b280af9
convert provider tests to async/await
cbaker6 Jan 4, 2025
551e686
lint
cbaker6 Jan 4, 2025
46c3df2
add more provider tests
cbaker6 Jan 4, 2025
7202f41
add more notification tests
cbaker6 Jan 4, 2025
58e6a86
retry on http codes 408, 429, 500, 502, 503, 504
cbaker6 Jan 4, 2025
56d7337
add proxy test
cbaker6 Jan 4, 2025
4905239
add some client tests
cbaker6 Jan 5, 2025
e0bb26d
fix manage channels test
cbaker6 Jan 10, 2025
5519fa4
more tests
cbaker6 Jan 10, 2025
2f2027d
improve logging pings
cbaker6 Jan 10, 2025
8b75d4e
revert
cbaker6 Jan 10, 2025
db39674
add ping tests
cbaker6 Jan 11, 2025
12d7968
more logger coverage
cbaker6 Jan 11, 2025
84a0736
modify tests for older node
cbaker6 Jan 11, 2025
b6c149b
remove unnecessary check
cbaker6 Jan 11, 2025
a561daa
make shutdown async
cbaker6 Jan 13, 2025
4ddf509
lint
cbaker6 Jan 13, 2025
af39226
test unref
cbaker6 Jan 13, 2025
77f117d
try without JSON error test
cbaker6 Jan 13, 2025
854338e
xit some tests for now
cbaker6 Jan 13, 2025
07a8afe
modify logger tests to run on older node
cbaker6 Jan 13, 2025
b092680
run json tests
cbaker6 Jan 13, 2025
5f8f975
lint
cbaker6 Jan 13, 2025
8a926c3
test
cbaker6 Jan 13, 2025
694b04d
remove close connection tests
cbaker6 Jan 13, 2025
39027cf
don't retry on status 500
cbaker6 Jan 13, 2025
d4da764
pass reject in closure
cbaker6 Jan 13, 2025
55adff1
force proxy to close
cbaker6 Jan 13, 2025
7727d1e
nit
cbaker6 Jan 13, 2025
85bedf6
improve 500 errors
cbaker6 Jan 13, 2025
1efd838
more tests
cbaker6 Jan 14, 2025
20fc514
reduce use of callbacks
cbaker6 Jan 14, 2025
c04aa4e
add back proxy test
cbaker6 Jan 14, 2025
3c05075
fix manage channel proxy test
cbaker6 Jan 14, 2025
14e50f1
comment nits
cbaker6 Jan 14, 2025
354242d
increase coverage
cbaker6 Jan 14, 2025
065e88c
add destroySession test
cbaker6 Jan 14, 2025
4445430
nit
cbaker6 Jan 14, 2025
c2776f8
add docs for new features
cbaker6 Jan 15, 2025
4347a05
doc nits
cbaker6 Jan 15, 2025
70f0390
nit
cbaker6 Jan 15, 2025
6712dd8
add additional proxy option to typescript
cbaker6 Jan 15, 2025
821973b
Merge branch 'useBroadcastPath' of https://github.com/cbaker6/node-ap…
cbaker6 Jan 15, 2025
7590bce
remove topic in broadcast docs
cbaker6 Jan 15, 2025
932a79d
doc nits
cbaker6 Jan 15, 2025
9813ce8
Remove unnecessary code
cbaker6 Jan 15, 2025
b6b1a6f
allow experation header in manageChannels
cbaker6 Jan 15, 2025
209794a
Merge branch 'useBroadcastPath' of https://github.com/cbaker6/node-ap…
cbaker6 Jan 15, 2025
1ac618e
support 201 and 204 status codes
cbaker6 Jan 16, 2025
78e1d03
remove old socketError not available after node 8.x
cbaker6 Jan 16, 2025
ab6ece8
expose the rest of config params to TS
cbaker6 Jan 18, 2025
6b604c1
Update Provider documentation
cbaker6 Jan 18, 2025
a584c1a
doc nits
cbaker6 Jan 19, 2025
0482ac3
mocker uses default method parameter
cbaker6 Jan 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ This will result in the following notification payload being sent to the device.
```

## Manage Channels
Live Activities can be used to broadcast push notifications over channels. To do so, you will need your apps' `bundleId`.
Starting in iOS 18 and iPadOS 18 Live Activities can be used to broadcast push notifications over channels. To do so, you will need your apps' `bundleId`.

```javascript
let bundleId = "com.node.apn";
Expand Down Expand Up @@ -252,7 +252,7 @@ After the promise is fulfilled, `result` will look like the following:
Further information about managing channels can be found in [Apple's documentation](https://developer.apple.com/documentation/usernotifications/sending-channel-management-requests-to-apns).

## Sending A Broadcast Notification
After a channel is created using `manageChannels`, broadcast push notifications can be sent to any device subscribed to the respective `channelId` created for a `bundleId`. A broadcast notification looks similar to a standard Live Activity notification mentioned above but requires `note.channelId` to be populated. An example is below:
Starting in iOS 18 and iPadOS 18, after a channel is created using `manageChannels`, broadcast push notifications can be sent to any device subscribed to the respective `channelId` created for a `bundleId`. A broadcast notification looks similar to a standard Live Activity notification mentioned above but requires `note.channelId` to be populated. An example is below:

```javascript
let note = new apn.Notification();
Expand Down
7 changes: 0 additions & 7 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
) {
this.manageChannelsSession.ping((error, duration) => {
if (error && this.errorLogger.enabled) {
this.errorLogger(

Check warning on line 63 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L63

Added line #L63 was not covered by tests
'ManageChannelsSession No Ping response after ' +
duration +
' ms with error:' +
Expand Down Expand Up @@ -215,7 +215,7 @@
httpMethod,
retryCount
);
return { ...subDirectoryInformation, ...resentRequest };

Check warning on line 218 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L218

Added line #L218 was not covered by tests
} catch (error) {
if (error.status == 500) {
await this.closeAndDestroySession(this.manageChannelsSession);
Expand Down Expand Up @@ -272,7 +272,7 @@
httpMethod,
retryCount
);
return { ...subDirectoryInformation, ...resentRequest };

Check warning on line 275 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L275

Added line #L275 was not covered by tests
} catch (error) {
if (error.status == 500) {
await this.closeAndDestroySession(this.session);
Expand Down Expand Up @@ -323,7 +323,7 @@
httpMethod,
retryCount
);
return sentRequest;

Check warning on line 326 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L326

Added line #L326 was not covered by tests
} catch (error) {
// Recursivelly call self until retryCount is exhausted
// or error is thrown.
Expand All @@ -336,7 +336,7 @@
httpMethod,
retryCount
);
return sentRequest;

Check warning on line 339 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L339

Added line #L339 was not covered by tests
}
};

Expand Down Expand Up @@ -384,13 +384,6 @@
this.destroySession(session);
});

this.session.on('socketError', error => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this as it's no longer available in the older version of the node tested (version 14 LTS). The last time I see it is in node version 8.7.0.

I'm sure whatever it use to catch is still caught by the rest of the error handling in this promise

if (this.errorLogger.enabled) {
this.errorLogger(`Socket error: ${error}`);
}
this.closeAndDestroySession(session);
});

this.session.on('error', error => {
if (this.errorLogger.enabled) {
this.errorLogger(`Session error: ${error}`);
Expand Down Expand Up @@ -471,10 +464,10 @@
});

this.manageChannelsSession.on('socketError', error => {
if (this.errorLogger.enabled) {
this.errorLogger(`ManageChannelsSession Socket error: ${error}`);

Check warning on line 468 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L467-L468

Added lines #L467 - L468 were not covered by tests
}
this.closeAndDestroySession(session);

Check warning on line 470 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L470

Added line #L470 was not covered by tests
});

this.manageChannelsSession.on('error', error => {
Expand Down Expand Up @@ -603,12 +596,12 @@

if (status === 403 && response.reason === 'ExpiredProviderToken') {
this.config.token.regenerate(tokenGeneration);
const error = {

Check warning on line 599 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L599

Added line #L599 was not covered by tests
status,
retryAfter,
error: new VError(response.reason),
};
reject({ ...headerObject, ...error });

Check warning on line 604 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L604

Added line #L604 was not covered by tests
return;
} else if (status === 500 && response.reason === 'InternalServerError') {
const error = {
Expand Down Expand Up @@ -655,8 +648,8 @@

status = ABORTED_STATUS;

const error = { error: new VError('apn write aborted') };
reject(error);

Check warning on line 652 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L651-L652

Added lines #L651 - L652 were not covered by tests
});

request.on('error', error => {
Expand All @@ -676,12 +669,12 @@
});

request.on('frameError', (frameType, errorCode, streamId) => {
const errorMessage = `Request frame error: (frameType: ${frameType}, errorCode ${errorCode}, streamId: ${streamId})`;
if (this.errorLogger.enabled) {
this.errorLogger(errorMessage);

Check warning on line 674 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L672-L674

Added lines #L672 - L674 were not covered by tests
}
const error = new VError(errorMessage);
reject({ error });

Check warning on line 677 in lib/client.js

View check run for this annotation

Codecov / codecov/patch

lib/client.js#L676-L677

Added lines #L676 - L677 were not covered by tests
});

request.end();
Expand Down
Loading