Repository navigation
fix(account): route APNs push targets by bundle ID and environment - #14589
Conversation
The Apple SDK registers its APNs token with bundleId and environment but no providerId. Both were dropped, so the target fell back to the default push provider: an arbitrary enabled one, which could be Appwrite push, the wrong APNs environment or FCM. Accept optional bundleId and environment on create and update push target. Without a providerId, a target is routed to the oldest enabled APNs provider whose bundle ID and sandbox flag match. No match keeps today's behaviour. Update re-routes an APNs or providerless target, so an install moving from a debug build to TestFlight follows, and leaves other providers alone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. 🟡 2 medium 💬 Inline comments (1)
📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to🟡 Medium — Sibling query misses targets on other providers after routing · account.php:5491–5496 · // app/controllers/api/account.php
5491 empty($providerId)
5492 ? Query::isNull('providerId')
5493 : Query::equal('providerId', [$providerId]),
5494 Query::orderAsc('$sequence'),
5495 Query::limit(APP_LIMIT_SUBQUERY),
5496 ]));The new 🧹 Nitpicks (1) — 🟢 1 low
This PR lets client apps route push targets to a specific APNs provider by bundle ID and register against the sandbox or production APNs gateway. The account API's create and update push-target routes accept two new optional params, resolve a matching messaging provider when no explicit provider is given, and expire superseded sibling targets for the same device. The SDK parameter lock and e2e suite are updated to cover the new surface.
Review found three issues: the sibling-target dedup query can miss targets registered under a different provider after routing, the APNs provider update endpoint writes the bundle ID under a key the new routing does not read, and the new Reviewed commit: d3f2f03 |
🟢 Tier S · Ready to mergeAdds optional bundle ID and APNs environment routing for push-target creation and updates, selecting the oldest enabled matching APNs provider while preserving explicit-provider behavior and adopting legacy providerless targets. It also exposes the parameters in the SDK lock and corrects APNs provider updates to persist bundle IDs under the key used by routing and delivery. Latest changes: The newest commit fixes APNs provider updates to store bundle IDs as
📂 Walkthrough · 4
Reviewed the commits since |
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
There was a problem hiding this comment.
Adds APNs bundleId and environment routing parameters to push target create/update in the account API, with matching parameter-lock and e2e test updates.
Key findings
- 🟡 Sibling query misses targets on other providers after routing — account.php:5491
- 🟡 Provider update writes bundle ID under wrong key — account.php:5460
…g it A routed registration looked for same-session siblings on the resolved APNs provider only, so an install that registered before routing kept its providerless target. A rotated token left that target live beside the new one, and an unchanged token hit the unique identifier index with a 409. When the provider comes from bundleId and environment, include providerless siblings in the lookup, and move the adopted target onto the resolved provider. Routing tests now use their own session, so they don't adopt the shared session's targets. Co-Authored-By: Claude Opus 5.5 <[email protected]>
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
…dleId The APNs provider update endpoint wrote the bundle ID to credentials.bundle, while create, the enable check, the APNs adapter and push target routing all read credentials.bundleId. A bundle ID changed through update never took effect for delivery or routing. Write bundleId and drop the stale key. Co-Authored-By: Claude Opus 5.5 <[email protected]>
….bundle key Until appwrite#14589, updating an APNs provider's bundle ID wrote it to credentials.bundle and left credentials.bundleId on the value from creation. Those rows still deliver and route with the old bundle ID, and the API shows it, until the provider is updated with a bundle ID again. Prefer a legacy `bundle` value wherever APNs credentials are read: the APNs adapter, push target routing and the Provider response model. Any update of the provider now promotes it into bundleId, so the row repairs itself on the next save. Co-Authored-By: Claude Opus 5.5 <[email protected]>
What does this PR do?
The Apple SDK (
sdk-for-apple21.0.0) registers its APNs device token with:POST /v1/account/targets/pushand body{ targetId, identifier, environment, bundleId }, with noproviderId;PUT /v1/account/targets/:targetId/pushand body{ identifier, environment, bundleId }.Neither endpoint declared
bundleIdorenvironment, so the router dropped them and the target was saved withproviderId: null. At send time a providerless target uses$default, which isfindOne(providers, enabled, type = push)with no ordering. In the setup thatappwrite init apnsand the Appwrite Push docs produce (Appwrite push + APNs production + APNs sandbox), the token lands on any of these:Two iOS apps with different bundle IDs in one project couldn't be told apart either.
Fix
Create: optional
bundleIdandenvironment(sandbox|production), declared last. WhenproviderIdis empty andbundleIdis set, the target goes to the oldest enabled APNs provider whosecredentials.bundleIdmatches and whoseoptions.sandboxmatches the environment. With no environment, the bundle ID alone decides.providerIdstill wins.providerId: null, so nothing that works now breaks.Update: the same params. A target on no provider or on an APNs provider is moved to the matching APNs provider when it differs, for example the same install moving from a debug build to TestFlight. Targets on other providers are never moved, and no match leaves the current provider in place.
The worker is unchanged. Apps already in the field heal on their next launch: the SDK re-registers every launch through POST, then PUT on 409.
APNs provider update fix (found in review):
Messaging/Http/Providers/Apns/Update.phpwrote the bundle ID tocredentials.bundle. Create, the enable check, the APNs adapter and this routing all readcredentials.bundleId, so a bundle ID changed through update never took effect for delivery or routing. It now writesbundleIdand drops the stale key.Credentials are encrypted, so providers are loaded with the indexed
provider,typeandenabledfilters and matched in PHP.The new params are public and optional on
account.createPushTargetandaccount.updatePushTargetin the client SDKs, appended toapp/config/sdks/parameters.lock.json.Test Plan
E2E in
tests/e2e/Services/Account/AccountCustomClientTest.php. Each test uses unique bundle IDs, with placeholder APNs credentials, so Apple is never contacted:testCreatePushTargetRoutesApnsByBundleAndEnvironment, alongside an Appwrite push provider:sandboxroutes to the oldest enabled sandbox provider. A disabled one created first and a newer duplicate are both skipped.productionroutes to the production provider.providerIdwins.providerId: null.environment: developmentreturns 400.testUpdatePushTargetReroutesApnsEnvironment:testCreatePushTargetAdoptsLegacyProviderlessTarget:testCreatePushTargetRoutesApnsByUpdatedBundleId: after a provider's bundle ID is updated, the new ID routes to it and the old one no longer does.The routing tests each use a fresh user and session, standing in for one device install.
Locally I ran
php -l, Pint and PHPStan (no new errors on changed lines; the rest is the stale local vendor). E2E and theParametersTestlock check run in CI.Related PRs and Issues
🤖 Generated with Claude Code