Repository navigation
feat(cli): check and register the App ID in init apns, for every setup - #2006
ArnabChatterjee20k wants to merge 12 commits into
Conversation
…PNs setup APNs refuses pushes for a bundle ID (TopicDisallowed) unless the team has it registered as an App ID with Push Notifications, and creating a key does not register it. The appwrite adapter now implements apns.AppIDPreparer: with the same Apple session it looks the bundle ID up through the portal's services-account/v1 bundleIds API, registers it as an explicit iOS App ID when missing and turns on Push Notifications when off, asking first unless told not to. The requests follow fastlane spaceship's web-session calls.
After creating a key, init apns reuses the fresh Apple sign-in to check the bundle ID's App ID and offers to register it or turn on Push Notifications. --register-app-id runs the step on its own, also for a project that is already set up, makes the changes without asking and fails the command when it cannot. A setup that cannot check App IDs only warns.
🟢 Tier S · Ready to mergeAdds bundle-ID validation and checks APNs setup selection before making provider changes. The Latest changes: The newest commits add early bundle-ID and setup validation, improve noninteractive sign-in errors and the Expo entitlement hint, and capture fastlane output for saved-sign-in runs.
📂 Walkthrough · 16
🔇 Filtered out · 1Findings Hansi considered but did not post.
Reviewed the commits since |
Every APNs setup now prepares App IDs: PrepareAppID joins CreateKey on apns.Adapter, and apns.PrepareAppID holds adapters to the same contract as apns.CreateKey (a valid bundle and team ID in, a consistent result for the right team out). ConfirmAppIDChange and AppIDName give every adapter the same questions and App ID name. Request.SavedSignInOnly lets a check use a saved sign-in without asking, returning ErrSignInNeeded when there is none.
The expo helper gains an app-id action on apple-utils' BundleId, and the Fastfile a prepare_app_id lane on spaceship's ConnectAPI BundleId with the portal session. Each checks the App ID first; the Go side asks, then a second run registers it and turns on Push Notifications. A saved-only check restores the setup's own saved session for the Apple ID (apple-utils' cookie file, spaceship's has_valid_session) and never asks, nor offers to install fastlane.
init apns checks the App ID whenever it runs, with any setup: right after a new key with that sign-in, else with a saved sign-in, else after asking whether to sign in (skipped without a terminal). Changes are asked about first. --register-app-id signs in when needed, changes without asking and fails the command when it cannot.
The portal's identifier filter also returns longer identifiers that start with the bundle ID, and the lookup read only the first page of 200. With more of those, the exact App ID could be on a later page, be taken as missing, and get a duplicate create that Apple refuses. The lookup now follows links.next until it finds the exact identifier or the pages run out.
After --create-key the App ID step signed in from scratch, so the expo and fastlane setups asked for the Apple ID and password again, and fastlane once more for the change after the question. Keys now carry the Apple ID that signed in; the check right after a new key uses that saved sign-in only, and signs in again without asking only if it cannot. In the expo and fastlane setups the change after the question reuses the check's saved sign-in too.
…nything A bundle ID with spaces created APNs providers for it, and an unknown --provider was only reported at the App ID check, after the providers were written. Both now fail first.
…eds a terminal The App ID check told people to pass --register-app-id even when they had, and the expo setup failed with apple-utils' own message naming EXPO_APPLE_ID. Every setup now names APPWRITE_APPLE_ID and APPWRITE_APPLE_PASSWORD, as key creation already did.
Without a terminal and with no saved Apple sign-in, the check was skipped with no reason given.
A check that only uses the saved sign-in asks nothing, but printed the lane's log, including 'Continuing with normal login', before reporting that it was skipped. The log is now shown only when the lane fails.
For an Expo app, init apns hinted only the background mode, while an Xcode project also gets the aps-environment entitlement.
What does this PR do?
appwrite init apnsnow makes sure the app's bundle ID is registered as an App ID with Push Notifications, on every run and with every key setup (appwrite,expo,fastlane). Without that, APNs refuses every push for the bundle ID withTopicDisallowed, even though the key and the Appwrite provider look fine.Creating a key doesn't register the App ID. Xcode only registers it for a device build with the Push Notifications capability added. Projects built only for the Simulator, using manual signing, or set up before push was added never get one. I hit this while testing #2000: a working team key, a configured provider, and
TopicDisallowedon the first push.Usage
Nothing new to remember: every
init apnschecks the App ID.How the check signs in:
--create-key)--reset)Before any change (registering the App ID, or turning push on), it asks. If the App ID is already ready, it only reports that.
--register-app-idis the explicit form, for scripts or for skipping the questions:It signs in if needed, makes the changes without asking, and fails the command if it can't. Without the flag, a failed check only warns.
How
PrepareAppIDis now part ofapns.Adapter, next toCreateKey, so every setup must implement it.apns.PrepareAppIDholds adapters to the same contract asapns.CreateKey: a valid bundle ID and team ID go in, and a consistent result for the right team comes out.apns.ConfirmAppIDChangeandapns.AppIDNamegive every setup the same questions and the same App ID name.Request.SavedSignInOnlylets the automatic check use only a saved sign-in. Without one, the adapter returnsapns.ErrSignInNeededinstead of prompting.services-account/v1/bundleIdsAPI with the existing cookie session, following fastlane spaceship's web-session calls:X-HTTP-Method-Override: GET;POST bundleIds;PATCH bundleIds/{id}withPUSH_NOTIFICATIONS.--action app-idmode built on apple-utils:BundleId.findAsync,createAsync,hasCapabilityAsyncandupdateBundleIdCapabilityAsync(PUSH_NOTIFICATIONS: ON);prepare_app_idlane built on spaceship'sConnectAPI::BundleIdwith the portal session:has_valid_sessionand never asks for a password;Test Plan
apns: thePrepareAppIDrequest checks and adapter contract (invalid team, wrong team, inconsistent results,ErrSignInNeeded),AppIDName, andConfirmAppIDChangewording.services-account/v1):node/fastlane:--resetonly on the first run;ErrSignInNeededand no run; with one, the saved-only flag is passed and no password is asked;--create-keywithout signing in again;init apns, already set up or not;--register-app-idsigns in, doesn't ask, and fails the command on error.gofmt,go vet,go test ./internal/apns/... ./internal/cmd/;node --check helper.js;ruby -c Fastfile.io.appwrite.apnstest.nativecurrently getsTopicDisallowed).Related PRs and Issues