Skip to content

fix: route native APNs tokens directly via apn package in push-send-q…#721

Open
ManAnRuck wants to merge 3 commits intomasterfrom
reenable-push
Open

fix: route native APNs tokens directly via apn package in push-send-q…#721
ManAnRuck wants to merge 3 commits intomasterfrom
reenable-push

Conversation

@ManAnRuck
Copy link
Member

…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).

Pullrequest

Issues

  • None

Checklist

  • None

Repositories Affected

  • bundestag.io
  • bundestag.io-admin
  • client
  • democracy-app.de
  • democracy-app.de-api
  • democracy-deutschland.de
  • docu
  • elasticsearch
  • None

How2Test

  • None

Todo

  • None

…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>
@ManAnRuck ManAnRuck self-assigned this Mar 3, 2026
Copilot AI review requested due to automatic review settings March 3, 2026 16:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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, and APPLE_TEAMID.
  • Split push sending into sendPushViaApns() and sendPushViaFcm(), 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.topic falls back to an empty string when APN_TOPIC is unset. APNs requires a valid topic (bundle id); sending with '' will cause pushes to fail. Consider validating process.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 after await start() completes successfully. If start() throws/rejects, the APNs provider can keep sockets open and prevent the process from terminating cleanly. Wrap the main body in a try/finally so shutdown() 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);

ManAnRuck and others added 2 commits March 3, 2026 18:27
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>
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.

2 participants