node-apn icon indicating copy to clipboard operation
node-apn copied to clipboard

feat: Add `apns-id` header to client return value

Open RedPhoenixQ opened this issue 1 month ago β€’ 7 comments

This exposes the apns-id header that is returned to identify a notification for debugging and tracking.

Summary by CodeRabbit

  • New Features

    • APNs notification IDs returned by the server are now captured, surfaced with results, and included in subsequent request headers when available.
  • Tests

    • Test suite expanded to verify APNs ID extraction/merging into results and correct request/connection behavior under concurrent requests.

✏️ Tip: You can customize this high-level summary in your review settings.

RedPhoenixQ avatar Jan 08 '26 15:01 RedPhoenixQ

πŸš€ Thanks for opening this pull request!

πŸ“ Walkthrough

Walkthrough

Client now captures apns-id from response headers into a local notificationId, threads it through the request flow, and updated createHeaderObject to accept notificationId so outgoing requests include an apns-id header when available.

Changes

Cohort / File(s) Summary
Client logic
lib/client.js
Introduce local notificationId in request flow; parse apns-id from response headers and store it; pass notificationId into createHeaderObject; update Client.prototype.createHeaderObject(uniqueId, requestId, channelId, notificationId) and header construction to include apns-id when present.
Tests
test/client.js
Add tests asserting server apns-id response headers are merged into returned results for device and channel flows and that concurrent requests and connection reuse behavior remain unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

πŸš₯ Pre-merge checks | βœ… 3
βœ… Passed checks (3 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The title clearly and specifically describes the main change: exposing the APNs apns-id header in the client return value, which matches the core objective of the PR.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • [ ] πŸ“ Generate docstrings
πŸ§ͺ Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Jan 08 '26 15:01 coderabbitai[bot]

:white_check_mark: Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
:white_check_mark: Open Source Security 0 0 0 0 0 issues

:computer: Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

parseplatformorg avatar Jan 08 '26 15:01 parseplatformorg

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 95.86%. Comparing base (0d8bc6b) to head (9ea743a). :warning: Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #195      +/-   ##
==========================================
+ Coverage   95.84%   95.86%   +0.01%     
==========================================
  Files          23       23              
  Lines         842      846       +4     
==========================================
+ Hits          807      811       +4     
  Misses         35       35              

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Jan 10 '26 03:01 codecov[bot]

I added the header to existing tests, hope that is satisfactory. The other propagated headers are also tested indirectly but are more directly linked to a specific type of api call. In my understanding the apns-id header should be returned for every type of remote notification creation (generated by server if not provided).

If you'd want a separate test for this specific header I'll do that.

RedPhoenixQ avatar Jan 10 '26 13:01 RedPhoenixQ

@RedPhoenixQ Thanks, we generally ask for not modifying existing tests if not necessary and add a new, specific test with an identifier that describes what it tests. So could you please revert the changes (unless necessary for existing tests to pass) and add a distinct test like it('returns APNs notification ID in response') or whether best describes it?

mtrezza avatar Jan 11 '26 01:01 mtrezza

I misunderstood the purpose of the ManageChannelsClient tests and there indeed doesn't need to be a separate test there as is also uses the Client. I removed the duplicate

RedPhoenixQ avatar Jan 11 '26 23:01 RedPhoenixQ

@RedPhoenixQ could you rebase the PR and see the test in https://github.com/parse-community/node-apn/pull/195#discussion_r2747487085 for ways to simplify your suggested test.

mtrezza avatar Jan 30 '26 18:01 mtrezza

Thank you for taking the time. I've simplified the test as per the recommendation (amending the commit) and rebased on master

RedPhoenixQ avatar Jan 30 '26 22:01 RedPhoenixQ

πŸŽ‰ This change has been released in version 7.1.0

parseplatformorg avatar Jan 31 '26 01:01 parseplatformorg