Skip to content

Update apn to version 2.1.2 #52

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

Closed
wants to merge 5 commits into from

Conversation

Schwobaland
Copy link

Update to apn. This enables parse to use http2-API from Apple. Tokens can be used instead of certificates. So one push-config enables to push to different apps.

There are some new options for configuring push-adapter:

@param {Object} args.token {Object} Configuration for Provider Authentication Tokens. (Defaults to: null i.e. fallback to Certificates)
@param {Buffer|String} args.token.key The filename of the provider token key (as supplied by Apple) to load from disk, or a Buffer/String containing the key data.
@param {String} args.token.keyId The ID of the key issued by Apple
@param {String} args.token.teamId ID of the team associated with the provider token key
@param {String} args.topic Specififies an App-Id for this Provider

Old property bundleId is mapped to topic for backward-compatibility.

@natanrolnik
Copy link
Contributor

@Schwobaland thanks for your contribution! It seems that the tests are failing. Can you take a look why?

@Schwobaland
Copy link
Author

Seems that apn 2.1.2 is not compatible with node 4.3. Tests are running with node 5. Parse-server has node 4.3 as minimum requirement. So - should i close this pull request? Or can minimum requirements be changed to node 5 or 6 (lts-version).

@flovilmart
Copy link
Contributor

@Schwobaland we bumped the min version to 4.6, and now everything looks good on the tests.

@@ -1,68 +1,31 @@
var APNS = require('../src/APNS');
let APNS = require('../src/APNS');
Copy link
Contributor

Choose a reason for hiding this comment

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

const

Copy link
Author

Choose a reason for hiding this comment

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

done

key: 'prodKey.pem',
it('can initialize with cert', (done) => {
let args = {
cert: new Buffer('testCert'),
Copy link
Contributor

Choose a reason for hiding this comment

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

this should still work with a string no?

Copy link
Author

Choose a reason for hiding this comment

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

it should work, if the string contains a (resolvable) filename or a string, that matches against /-----BEGIN ([A-Z\s*]+)-----/. See here for details.
Will change one of the test-cases to test this.

production: true,
bundleId: 'bundleId'
topic: 'topic'
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd keep bundleId as the main option with topic being optional to maximize backwards compatibility.

perhaps if using bundleId we could log a warning: bundleId is deprecated, use topic instead

Copy link
Author

Choose a reason for hiding this comment

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

There was already a mapping of bundleId to topic. I will add a warning, if bundleId is used.

expect(prodApnsOptions.cert).toBe(args.cert);
expect(prodApnsOptions.key).toBe(args.key);
expect(prodApnsOptions.production).toBe(args.production);
done();
});

it('can initialize with multiple certs', (done) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not supported anymore? I personally rely on that capability.

Copy link
Author

Choose a reason for hiding this comment

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

this is supported for different topics/bundleIds.
But I haven't found any possibility, to implement a retry for notifications, that a rejected by apns because of wrong provider or wrong production- / test-device.

Example: You have two provider, one for production use and one for development. Both share the same topic/bundleId. So _chooseProviders would return [prodProvider, devProvider] based on priority-sorting in constructor. So send-Method uses the first one to send the notification. If device is registered using apple-development-provisioning-profile, the notification would not be delivered, because of wrong provider. In parse-device-object is no flag, that describes, wether this device is using development- or production-profile.

In "old" parse-push-adapter (using apn version 1.X), there was a retry-functionality. This isn't available in my version.

I will add this test-case again to test different topics.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for multiple certs

done();
});

it('can choose conns for device with valid appIdentifier', (done) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

not supported anymore either?

Copy link
Author

Choose a reason for hiding this comment

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

see it('can choose providers for device with valid appIdentifier'....

src/APNS.js Outdated
conn.on('timeout', () => {
log.verbose(LOG_PREFIX, 'APNS Connection %d Timeout', conn.index);
});
let provider = this._createProvider(apnsArgs);
Copy link
Contributor

Choose a reason for hiding this comment

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

the _createProvider should be 'static' as it doesn't need this

Copy link
Author

Choose a reason for hiding this comment

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

done

src/APNS.js Outdated
* @param {String} topic Topic the Notification is sent to
* @returns {Object} A apns Notification
*/
_generateNotification(coreData, expirationTime, topic) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this should stay static as well as is doesn't require this

Copy link
Author

Choose a reason for hiding this comment

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

done

src/APNS.js Outdated
log.verbose(LOG_PREFIX, 'APNS transmitted to %s', token);
return this._createSuccesfullPromise(token);
});
response.failed.forEach((failure) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

this will just be a no-op as it will create promises that are never handled.

Copy link
Author

Choose a reason for hiding this comment

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

will return a Promise.all with all promises

Copy link
Contributor

Choose a reason for hiding this comment

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

That's better :)

@flovilmart
Copy link
Contributor

flovilmart commented Feb 6, 2017

Hi @Schwobaland, thanks for that Pull Request! We have a few things here and there before we can merge that one! Thanks again!

@Schwobaland
Copy link
Author

Hi @flovilmart, thanks for commenting. Fixed some of your requested changes. Please review this comment. I'm not sure, how to handle this, because of backward-compatibility.

I will be using two instances of parse-server: One for production and one for development. So for my use-cases this is not a problem, but...

@flovilmart
Copy link
Contributor

@Schwobaland I'll have a look for multiple certs for a single topic, and I'll open a Pr on your branche before we get to merge that what do you think?

@Schwobaland
Copy link
Author

@flovilmart Sounds good! I'll wait for your PR 👍

src/APNS.js Outdated
response.failed.forEach((failure) => {
if (failure.error) {
log.error(LOG_PREFIX, 'APNS error transmitting to device %s with error %s', failure.device, failure.error);
promises.push(PNS._createErrorPromise(failure.device, failure.error));
Copy link
Contributor

Choose a reason for hiding this comment

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

typo. PNS should be APNS

Copy link
Author

Choose a reason for hiding this comment

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

@jeacott1 thanks. Fixed this.

@jeacott1
Copy link
Contributor

I've been playing with apn 2.1.3, and thus far its been pretty unreliable unfortunately. the existing apn 1.x is more stable, but tracking doesn't work well.

@flovilmart
Copy link
Contributor

@jeacott1 what do you mean by unstable?

@jeacott1
Copy link
Contributor

jeacott1 commented Mar 5, 2017

http2 errors, and other sporadic exceptions. many have been mitigated by downgrading node to 5.11.1, but that causes other performance issues.

@flovilmart
Copy link
Contributor

Anything worth reporting to the APN maintainer? Or related to the current implementation?

@jeacott1
Copy link
Contributor

jeacott1 commented Mar 6, 2017

I think most of the issues are already documented either with apn, http2, or nodejs.
eg: node-apn/node-apn#449

@flovilmart
Copy link
Contributor

@Schwobaland seems that it's getting updated to 2.1.3 last month, can you bump? I may takeover your branch as I'm in the midst of removing babel altogether from the package.

@Schwobaland Schwobaland mentioned this pull request Mar 19, 2017
@codecov
Copy link

codecov bot commented Mar 19, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@6f382f1). Click here to learn what that means.
The diff coverage is 100%.

@@           Coverage Diff           @@
##             master    #52   +/-   ##
=======================================
  Coverage          ?   100%           
=======================================
  Files             ?      5           
  Lines             ?    249           
  Branches          ?      0           
=======================================
  Hits              ?    249           
  Misses            ?      0           
  Partials          ?      0
Impacted Files Coverage Δ
src/index.js 100% <ø> (ø)
src/APNS.js 100% <100%> (ø)
src/GCM.js 100% <100%> (ø)
src/ParsePushAdapter.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6f382f1...f667715. Read the comment docs.

@flovilmart
Copy link
Contributor

Closing as superset by #72 , thanks @Schwobaland for getting the ball rolling on that, one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants