appfeel / node-pushnotifications

Push notifications for GCM, APNS, MPNS, AMZ (automatic detection from device token)
MIT License
534 stars 123 forks source link

sendAPN handling of received token in success case inconsistent with other cases and providers #159

Closed henry-tm closed 3 years ago

henry-tm commented 3 years ago

When mapping through received token for sent notifications in sendAPN module the logic assumes that the received tokens are strings (https://github.com/appfeel/node-pushnotifications/blob/master/src/sendAPN.js [line 108ff]):

(response.sent || []).forEach((token) => {
  resumed.success += 1;
  resumed.message.push({
    regId: token,
    error: null,
  });
});

In fact, looking at the implemenation of the success case logic in the node-apn package, the device is wrapped in an object literal (https://github.com/node-apn/node-apn/blob/master/lib/client.js [line 74ff]):

...
stream.on("end", () => {
  if (status === "200") {
    resolve({ device });
  } else if ...

To be conistent with the other cases handled in the sendAPN module, it would be great to pick the device prop and set as regId instead of returning the property wrapped in an object literal.

alex-friedl commented 3 years ago

@henry-tm Thank you for reporting this! Should be fixed in v1.6.3