fix: route native APNs tokens directly via apn package in push-send-q…#721
Open
fix: route native APNs tokens directly via apn package in push-send-q…#721
Conversation
…ueued iOS >= 1.5.5 stores raw APNs device tokens (64-char hex) in the DB. Firebase Admin SDK rejects these as invalid FCM registration tokens. Detect token format at send time: - 64-char hex → sendPushViaApns() using the apn package (already installed) - all others → sendPushViaFcm() via Firebase Admin SDK (unchanged) APNs provider uses existing credentials: APPLE_APN_KEY, APPLE_APN_KEY_ID, APPLE_TEAMID (already in push-notifications-secrets) and APN_TOPIC (already in push-notifications-config). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the push-send-queued cron job to detect raw APNs device tokens (64-char hex) at send time and route them through APNs (via the apn package) instead of Firebase Admin SDK, which rejects those tokens.
Changes:
- Add APNs provider initialization from
APPLE_APN_KEY,APPLE_APN_KEY_ID, andAPPLE_TEAMID. - Split push sending into
sendPushViaApns()andsendPushViaFcm(), selecting based on token format. - Shut down the APNs provider before process exit.
Comments suppressed due to low confidence (2)
services/cron-jobs/push-send-queued/src/index.ts:50
notification.topicfalls back to an empty string whenAPN_TOPICis unset. APNs requires a valid topic (bundle id); sending with''will cause pushes to fail. Consider validatingprocess.env.APN_TOPIC(and throwing a clear config error) before attempting to send via APNs, rather than defaulting to an empty string.
notification.topic = process.env.APN_TOPIC ?? '';
notification.payload = { data: { type, action: type, category, title, message, procedureId: procedureIds[0] } };
services/cron-jobs/push-send-queued/src/index.ts:140
apnsProvider?.shutdown()only runs afterawait start()completes successfully. Ifstart()throws/rejects, the APNs provider can keep sockets open and prevent the process from terminating cleanly. Wrap the main body in atry/finallysoshutdown()is always executed before exiting.
(async () => {
await mongoConnect();
console.log("outstanding push's", await PushNotificationModel.countDocuments({ sent: false }));
await start();
apnsProvider?.shutdown();
process.exit(0);
pnpm aborts node_modules removal without TTY in Docker build. Setting CI=true suppresses the interactive prompt. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
group=1 only captured major.minor.patch; alpha part was group=2. Merged into single capture group so 0.1.31-alpha.0 is tagged correctly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
…ueued
iOS >= 1.5.5 stores raw APNs device tokens (64-char hex) in the DB. Firebase Admin SDK rejects these as invalid FCM registration tokens.
Detect token format at send time:
APNs provider uses existing credentials: APPLE_APN_KEY, APPLE_APN_KEY_ID, APPLE_TEAMID (already in push-notifications-secrets) and APN_TOPIC (already in push-notifications-config).
Pullrequest
Issues
Checklist
Repositories Affected
How2Test
Todo