forked from node-apn/node-apn
-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
cbaker6
wants to merge
64
commits into
parse-community:master
Choose a base branch
from
cbaker6:useBroadcastPath
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,613
−321
Open
Changes from 23 commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
b35fbb8
add TS missing properties
cbaker6 71f2cf1
feat: Add the ability to use different http methods
cbaker6 0b4022f
Merge branch 'master' into useBroadcastPath
cbaker6 49b5bf5
lint
cbaker6 5e83b2a
Merge branch 'useBroadcastPath' of https://github.com/cbaker6/node-ap…
cbaker6 e5bf411
test v2 as provider
cbaker6 5b029b7
replace original client with V2
cbaker6 755aeec
lint
cbaker6 058070c
create manageBroadcastSession
cbaker6 8136a8c
nit
cbaker6 3d348fc
nit
cbaker6 a1263c7
add channels method
cbaker6 36b3f35
nit
cbaker6 8ec017d
update typescript
cbaker6 53393f0
make JS match TS
cbaker6 6cf1299
delete non channel related headers when necessary
cbaker6 5193a14
Merge branch 'master' into useBroadcastPath
cbaker6 c21e682
use async/await
cbaker6 b7a5bfe
Merge branch 'useBroadcastPath' of https://github.com/cbaker6/node-ap…
cbaker6 dee2882
lint
cbaker6 576a62d
fix code on older versions of node
cbaker6 d006ded
add initial tests for manageBroadcastSession
cbaker6 6318b98
throw error if reached connectionRetryLimit
cbaker6 bcd1364
improve usage of connectionRetryLimit, defaults to 2 instead of 10
cbaker6 446c8f2
manageBroadcast -> manageChannels
cbaker6 2f814c9
make code for connectionRetryLimit match documentation
cbaker6 b280af9
convert provider tests to async/await
cbaker6 551e686
lint
cbaker6 46c3df2
add more provider tests
cbaker6 7202f41
add more notification tests
cbaker6 58e6a86
retry on http codes 408, 429, 500, 502, 503, 504
cbaker6 56d7337
add proxy test
cbaker6 4905239
add some client tests
cbaker6 e0bb26d
fix manage channels test
cbaker6 5519fa4
more tests
cbaker6 2f2027d
improve logging pings
cbaker6 8b75d4e
revert
cbaker6 db39674
add ping tests
cbaker6 12d7968
more logger coverage
cbaker6 84a0736
modify tests for older node
cbaker6 b6c149b
remove unnecessary check
cbaker6 a561daa
make shutdown async
cbaker6 4ddf509
lint
cbaker6 af39226
test unref
cbaker6 77f117d
try without JSON error test
cbaker6 854338e
xit some tests for now
cbaker6 07a8afe
modify logger tests to run on older node
cbaker6 b092680
run json tests
cbaker6 5f8f975
lint
cbaker6 8a926c3
test
cbaker6 694b04d
remove close connection tests
cbaker6 39027cf
don't retry on status 500
cbaker6 d4da764
pass reject in closure
cbaker6 55adff1
force proxy to close
cbaker6 7727d1e
nit
cbaker6 85bedf6
improve 500 errors
cbaker6 1efd838
more tests
cbaker6 20fc514
reduce use of callbacks
cbaker6 c04aa4e
add back proxy test
cbaker6 3c05075
fix manage channel proxy test
cbaker6 14e50f1
comment nits
cbaker6 354242d
increase coverage
cbaker6 065e88c
add destroySession test
cbaker6 4445430
nit
cbaker6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,11 +99,34 @@ interface Aps { | |
"mutable-content"?: undefined | 1 | ||
"url-args"?: string[] | ||
category?: string | ||
"thread-id"?: string | ||
"interruption-level"?: string | ||
"relevance-score"?: number | ||
"filter-criteria"?: string | ||
"stale-date"?: number | ||
"content-state"?: Object | ||
timestamp?: number | ||
event?: string | ||
"dismissal-date"?: number | ||
"attributes-type"?: string | ||
attributes?: Object | ||
} | ||
|
||
export interface ResponseSent { | ||
device: string; | ||
} | ||
|
||
export interface BroadcastResponse { | ||
bundleId: string; | ||
"apns-request-id"?: string; | ||
"apns-channel-id"?: string; | ||
"message-storage-policy"?: number; | ||
"push-type"?: string; | ||
"channels"?: string[]; | ||
} | ||
|
||
export interface LoggerResponse extends Partial<ResponseSent>, Partial<BroadcastResponse> {} | ||
|
||
export interface ResponseFailure { | ||
device: string; | ||
error?: Error; | ||
|
@@ -114,28 +137,56 @@ export interface ResponseFailure { | |
}; | ||
} | ||
|
||
export interface Responses { | ||
sent: ResponseSent[]; | ||
failed: ResponseFailure[]; | ||
export interface BroadcastResponseFailure extends Omit<ResponseFailure, "device"> { | ||
bundleId: string; | ||
} | ||
|
||
export interface LoggerResponseFailure extends Partial<ResponseFailure>, Partial<BroadcastResponseFailure> {} | ||
|
||
export interface Responses<R,F> { | ||
sent: R[]; | ||
failed: F[]; | ||
} | ||
|
||
export class Provider extends EventEmitter { | ||
constructor(options: ProviderOptions); | ||
/** | ||
* This is main interface for sending notifications. Create a Notification object and pass it in, along with a single recipient or an array of them and node-apn will take care of the rest, delivering a copy of the notification to each recipient. | ||
* This is main interface for sending notifications. | ||
* | ||
* @remarks | ||
* Create a Notification object and pass it in, along with a single recipient or an array of them and node-apn will take care of the rest, delivering a copy of the notification to each recipient. | ||
* | ||
* @param notification - The notification to send. | ||
* @param recipients - A String or an Array of Strings containing the hex-encoded device token. | ||
*/ | ||
send(notification: Notification, recipients: string|string[]): Promise<Responses<ResponseSent,ResponseFailure>>; | ||
|
||
/** | ||
* Manage channels using a specific action. | ||
* | ||
* @param notifications - A Notification or an Array of Notifications to send. Each notification should specify the respective channelId it's directed to. | ||
* @param bundleId - The bundleId for your application. | ||
* @param action - Specifies the action to perform on the channel(s). | ||
*/ | ||
manageChannels(notifications: Notification|Notification[], bundleId: string, action: ChannelAction): Promise<Responses<BroadcastResponse,BroadcastResponseFailure>>; | ||
|
||
/** | ||
* Broadcast notificaitons to channel(s). | ||
* | ||
* A "recipient" is a String containing the hex-encoded device token. | ||
* @param notifications - A Notification or an Array of Notifications to send. Each notification should specify the respective channelId it's directed to. | ||
* @param bundleId: The bundleId for your application. | ||
*/ | ||
send(notification: Notification, recipients: string|string[]): Promise<Responses>; | ||
broadcast(notifications: Notification|Notification[], bundleId: string): Promise<Responses<BroadcastResponse,BroadcastResponseFailure>>; | ||
|
||
/** | ||
* Set an info logger, and optionally an errorLogger to separately log errors. | ||
* | ||
* @remarks | ||
* In order to log, these functions must have a property '.enabled' that is true. | ||
* (The default logger uses the npm 'debug' module which sets '.enabled' | ||
* based on the DEBUG environment variable) | ||
*/ | ||
setLogger(logger: (msg: string) => void, errorLogger?: (msg: string) => void): Promise<Responses>; | ||
setLogger(logger: (msg: string) => void, errorLogger?: (msg: string) => void): Promise<Responses<LoggerResponse,LoggerResponseFailure>>; | ||
|
||
/** | ||
* Indicate to node-apn that it should close all open connections when the queue of pending notifications is fully drained. This will allow your application to terminate. | ||
|
@@ -146,28 +197,35 @@ export class Provider extends EventEmitter { | |
export class MultiProvider extends EventEmitter { | ||
constructor(options: MultiProviderOptions); | ||
/** | ||
* This is main interface for sending notifications. Create a Notification object and pass it in, along with a single recipient or an array of them and node-apn will take care of the rest, delivering a copy of the notification to each recipient. | ||
* This is main interface for sending notifications. | ||
* | ||
* @remarks | ||
* Create a Notification object and pass it in, along with a single recipient or an array of them and node-apn will take care of the rest, delivering a copy of the notification to each recipient. | ||
* | ||
* A "recipient" is a String containing the hex-encoded device token. | ||
* @param notification - The notification to send. | ||
* @param recipients - A String or an Array of Strings containing the hex-encoded device token. | ||
*/ | ||
send(notification: Notification, recipients: string|string[]): Promise<Responses>; | ||
send(notification: Notification, recipients: string|string[]): Promise<Responses<ResponseSent,ResponseFailure>>; | ||
|
||
/** | ||
* Set an info logger, and optionally an errorLogger to separately log errors. | ||
* | ||
* @remarks | ||
* In order to log, these functions must have a property '.enabled' that is true. | ||
* (The default logger uses the npm 'debug' module which sets '.enabled' | ||
* (The default logger uses the npm 'debug' module which sets '.enabled' | ||
* based on the DEBUG environment variable) | ||
*/ | ||
setLogger(logger: (msg: string) => void, errorLogger?: (msg: string) => void): Promise<Responses>; | ||
setLogger(logger: (msg: string) => void, errorLogger?: (msg: string) => void): Promise<Responses<LoggerResponse,LoggerResponseFailure>>; | ||
|
||
/** | ||
* Indicate to node-apn that it should close all open connections when the queue of pending notifications is fully drained. This will allow your application to terminate. | ||
*/ | ||
shutdown(callback?: () => void): void; | ||
} | ||
|
||
export type NotificationPushType = 'background' | 'alert' | 'voip' | 'pushtotalk' | 'liveactivity'; | ||
export type NotificationPushType = 'background' | 'alert' | 'voip' | 'pushtotalk' | 'liveactivity' | 'location' | 'complication' | 'fileprovider' | 'mdm'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding |
||
|
||
export type ChannelAction = 'create' | 'read' | 'readAll' | 'delete'; | ||
|
||
export interface NotificationAlertOptions { | ||
title?: string; | ||
|
@@ -198,21 +256,22 @@ export class Notification { | |
*/ | ||
public id: string; | ||
/** | ||
* The UNIX timestamp representing when the notification should expire. This does not contribute to the 2048 byte payload size limit. An expiry of 0 indicates that the notification expires immediately. | ||
* A UUID to identify this request. | ||
*/ | ||
public expiry: number; | ||
public requestId: string; | ||
/** | ||
* Multiple notifications with same collapse identifier are displayed to the user as a single notification. The value should not exceed 64 bytes. | ||
* A base64-encoded string that identifies the channel to publish the payload. | ||
The channel ID is generated by sending channel creation request to APNs. | ||
*/ | ||
public collapseId: string; | ||
public channelId: string; | ||
/** | ||
* Multiple notifications with same collapse identifier are displayed to the user as a single notification. The value should not exceed 64 bytes. | ||
*/ | ||
public requestId: string; | ||
public collapseId: string; | ||
/** | ||
* An optional custom request identifier that’s returned back in the response. The request identifier must be encoded as a UUID string. | ||
* The UNIX timestamp representing when the notification should expire. This does not contribute to the 2048 byte payload size limit. An expiry of 0 indicates that the notification expires immediately. | ||
*/ | ||
public channelId: string; | ||
public expiry: number; | ||
/** | ||
* Provide one of the following values: | ||
* | ||
|
@@ -225,7 +284,6 @@ export class Notification { | |
* The type of the notification. | ||
*/ | ||
public pushType: NotificationPushType; | ||
|
||
/** | ||
* An app-specific identifier for grouping related notifications. | ||
*/ | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used generics here to:
I attempted to write this in a way to still work out-of-the-box with no breaking, but I'm not a TS expert, so feel free to chime in if you see an issue.