-
Notifications
You must be signed in to change notification settings - Fork 306
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
New send notification #218
New send notification #218
Conversation
# The first commit's message is: Changes to new API surface for sendNotification # This is the 2nd commit message: Add more files to .npmignore
@@ -63,4 +66,7 @@ webPush.sendNotification(endpoint, params).then(() => { | |||
}).then(() => { | |||
process.exit(0); | |||
}); | |||
<<<<<<< HEAD |
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.
Leftover from merge.
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.
Fixed.
const ece = require('http_ece'); | ||
const urlBase64 = require('urlsafe-base64'); | ||
|
||
// New standard, Firefox 46+ and Chrome 50+. |
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.
Nit: I guess we could remove this comment now.
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.
Removed.
@marco-c good news, got FF running on Linux and OS X without the GH_TOKEN. |
|
||
/** | ||
* This method takes the required VAPID parameters and returns the required | ||
* header to added to a Web Push Protocol Request. |
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.
Nit: to be added
/** | ||
* This method takes the required VAPID parameters and returns the required | ||
* header to added to a Web Push Protocol Request. | ||
* @param {string} audience This must be the origni of the push service. |
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.
Nit: origin
} | ||
} | ||
|
||
// Test subscription is an Object |
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.
Are these comments notes for tests that you wanted to write?
requestOptions.headers.Authorization = 'key=' + currentGCMAPIKey; | ||
} | ||
} else if (currentVapidDetails) { | ||
// VAPID isn't supported by GCM. |
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.
Nit: This comment no longer applies here, should be moved to the if
before
}); | ||
|
||
// TODO:2 good tests for the vapid headers | ||
// TODO: Make sure you can v |
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.
Nit: this TODO comment is cut 😄
@@ -31,6 +33,13 @@ | |||
}; | |||
const testDirectory = './test/output/'; | |||
|
|||
webPush.setGCMAPIKey('AIzaSyAwmdX6KKd4hPfIcGU2SOfj9vuRDW6u-wo'); | |||
webPush.setVapidDetails( |
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.
This means that we're going to run all tests with vapid, right? Unless you change tests like:
test('send/receive notification with payload with ' + browser.getPrettyName(), function() {
this.timeout(PUSH_TEST_TIMEOUT);
return runTest(browser, {
payload: 'marco'
});
});
to:
test('send/receive notification with payload with ' + browser.getPrettyName(), function() {
this.timeout(PUSH_TEST_TIMEOUT);
return runTest(browser, {
payload: 'marco',
vapid: null,
});
});
@@ -163,18 +177,15 @@ | |||
} | |||
|
|||
if (!pushPayload) { | |||
promise = webPush.sendNotification(subscription.endpoint, { | |||
promise = webPush.sendNotification(subscription, null, { | |||
vapid: vapid |
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.
This should be vapidDetails
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.
Argh. This is exactly the kind of problem I'm trying to avoid :P
I've added an extra check and test to avoid unexpected keys in the extra options.
@@ -25,4 +31,10 @@ suite('setGCMAPIKey', function() { | |||
webPush.setGCMAPIKey(42); | |||
}, Error); | |||
}); | |||
|
|||
test('undefined valud', function() { |
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.
Nit: value
Great! Are you opening a new PR for that? Or do you want to update this one? |
LGTM, just a bunch of nits and a comment regarding the Selenium tests (with the changes we're going to run everything with VAPID, but before we were testing both with and without VAPID). |
} | ||
|
||
if (!userAuth) { | ||
throw new Error('No user auth provided for encryption.'); | ||
} | ||
|
||
if (typeof userAuth !== 'string') { | ||
throw new Error('User auth must be a string.'); | ||
throw new Error('The subscirption auth key must be a string.'); |
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.
Nit: subscription :)
Oh, we also need to fix the documentation in the README for the new signature. |
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've addressed all the comments you've raised, thank you so much for the review.
I've changed back to the old way of managing vapid details and that has actually fixed an issue I was seeing on my OS X machine but no where else.
Regarding the README, do you want to update that now or just before we publish this signature?
I expect many developers are using the README for the current API surface.
@@ -163,18 +177,15 @@ | |||
} | |||
|
|||
if (!pushPayload) { | |||
promise = webPush.sendNotification(subscription.endpoint, { | |||
promise = webPush.sendNotification(subscription, null, { | |||
vapid: vapid |
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.
Argh. This is exactly the kind of problem I'm trying to avoid :P
I've added an extra check and test to avoid unexpected keys in the extra options.
Fixes #192, #216, #184, #200
@marco-c sorry that this is such a large set of changes.
Found a couple of issues in the sendNotification tests, I've re-organised the code a little to be easier to separate concerns a bit more and added a few simple error checks to catch errors earlier on.