Repository navigation
Add iOS account deletion and legal links #7645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 85 commits
Commits
Show all changes
91 commits
Select commit
Hold shift + click to select a range
16e2824
Add iOS account deletion and legal links
azooz2003-bit 0f88b97
Fix account deletion review issues
azooz2003-bit cf18f1a
Merge remote-tracking branch 'origin/main' into feat-ios-account-dele…
azooz2003-bit 760c4d9
Complete account deletion cleanup
azooz2003-bit aeedf88
Guard deleted account billing webhooks
azooz2003-bit ebaf859
Split mobile settings account review sections
azooz2003-bit 31808e1
Fix mobile settings section imports
azooz2003-bit 0f37717
Bound account deletion cleanup failures
azooz2003-bit b426270
Harden account deletion retries
azooz2003-bit 79edd76
Avoid billing purchase test mock leakage
azooz2003-bit d6e7ec5
Block account deletion race windows
azooz2003-bit 7150941
Close account deletion race windows
azooz2003-bit 02ce6e4
Treat post-delete cleanup as terminal
azooz2003-bit ffce0ac
Handle out-of-order subscription updates
azooz2003-bit d5e0971
Order account deletion cleanup safely
azooz2003-bit f7c181c
Avoid subscription primary key updates
azooz2003-bit a5f36a8
Attempt all account deletion VM teardown
azooz2003-bit b9fa4a2
Delete vault account data in bounded batches
azooz2003-bit b79f618
Scrub retained user references during account deletion
azooz2003-bit 63646bc
Parallelize vault object cleanup during account deletion
azooz2003-bit 8d68a59
Scrub team billing owner references on account deletion
azooz2003-bit 49ed190
Restore deletion metadata on cleanup failure
azooz2003-bit dba2b28
Close account deletion privacy gaps
azooz2003-bit ac590ae
Preserve visible account deletion failures
azooz2003-bit b12e742
Close account deletion residual gaps
azooz2003-bit f3d21a6
Handle local account deletion transport failures
azooz2003-bit 000bb3f
Split account deletion Swift helpers
azooz2003-bit 74c71aa
Keep destructive deletion failures retryable
azooz2003-bit e6e792c
Classify irreversible deletion cleanup safely
azooz2003-bit 3f2d3a5
Surface incomplete deletion cleanup on iOS
azooz2003-bit 41a10e4
Keep deletion retries safe after provider attempts
azooz2003-bit 2db126f
Close account deletion cleanup gaps
azooz2003-bit b55f23b
Record subscription state before deletion skips
azooz2003-bit b7e8e4a
Avoid stale auth during account deletion retry
azooz2003-bit fe4df74
Keep Stripe webhooks retryable for missing Stack users
azooz2003-bit a79d03a
Block delayed checkout writes during account deletion
azooz2003-bit c4e1de5
Skip stale Stripe metadata after account deletion
azooz2003-bit fffc650
Restore deletion metadata before destructive cleanup
azooz2003-bit 3a9c3d9
Bound account deletion identity cleanup
azooz2003-bit 402bfbd
Cancel deleting-account checkout completions
azooz2003-bit 46f719f
Close deletion cleanup retry gaps
azooz2003-bit e7aaf4d
Continue checkout cleanup after canceled subscriptions
azooz2003-bit 6c40a74
Treat Subrouter revoke attempts as destructive
azooz2003-bit b2833f5
Serialize account deletion with personal VM creation
azooz2003-bit 424c3b8
Preserve deletion state after SSH revoke cleanup
azooz2003-bit 871f805
Harden account deletion cleanup coverage
azooz2003-bit 1004394
Restrict account deletion to owned Stack teams
azooz2003-bit 463f904
Add deletion tombstone guards
azooz2003-bit f71a8db
Serialize checkout completion with account deletion
azooz2003-bit 9e6fa41
Cancel personal team billing during deletion
azooz2003-bit c3a49fc
Anonymize retained shared team VMs
azooz2003-bit 51825c9
Guard team checkout during account deletion
azooz2003-bit 728c545
Transfer retained team billing during deletion
azooz2003-bit aa2110c
Treat post-stack deletion failures as accepted
azooz2003-bit a924535
Serialize account deletion cleanup
azooz2003-bit ed30ccd
Fix deletion retry blockers
azooz2003-bit f7415c8
Handle pending account deletion safely
azooz2003-bit 80046dc
Move checkout entitlement sync after commit
azooz2003-bit e221420
Close account deletion edge cases
azooz2003-bit efec72f
Keep team checkout customers during deletion
azooz2003-bit 2d196e4
Keep account deletion leases fresh
azooz2003-bit 69f326f
Close account deletion VM cleanup gaps
azooz2003-bit 0bf7fb3
Keep incomplete account deletion retryable
azooz2003-bit dbbef35
Guard billing sync during account deletion
azooz2003-bit fdb9465
Skip tombstoned team billing webhooks
azooz2003-bit 0bf1784
Close account deletion billing races
azooz2003-bit 10bfed7
Close account deletion cleanup gaps
azooz2003-bit db70bbd
Synchronize account vault cleanup
azooz2003-bit d096099
Delete account vault upload tracking rows
azooz2003-bit 24f1db7
Block Base VM creation during account deletion
azooz2003-bit b19bc1e
Unwrap Base deletion block in DB test
azooz2003-bit c328efd
Handle terminal account deletion retries
azooz2003-bit 11bd876
Close account deletion retry blockers
azooz2003-bit 5d65ed8
Delete owned team Stripe rows during account deletion
azooz2003-bit 812d4b5
Fix deletion review state and support subject
azooz2003-bit 4fa4b4c
Page Stack teams during account deletion
azooz2003-bit a70b4db
Accept large non-paginated Stack teams
azooz2003-bit 2241674
Fail closed on ownerless team checkout completion
azooz2003-bit dd8a18c
Fail closed on ownerless team subscription webhooks
azooz2003-bit 15452d2
Serialize device registration with account deletion
azooz2003-bit a64c19f
Block account mutations before scope discovery
azooz2003-bit 4b0079d
Skip providerless VMs during deletion teardown
azooz2003-bit 5862c2e
Mark VM deletion destructive after provider destroy
azooz2003-bit d84a3df
Keep account deletion cleanup progressing
azooz2003-bit 3ff08ce
Separate account deletion VM blocks
azooz2003-bit 71b8c8f
Close account deletion cleanup gaps
azooz2003-bit 4da93ee
Merge remote-tracking branch 'origin/main' into feat-ios-account-dele…
azooz2003-bit 65327e9
Respect account deletion tombstone lease
azooz2003-bit 47f7ea5
Close account deletion route cleanup gaps
azooz2003-bit e957eae
Preserve legacy team checkout completion
azooz2003-bit 260fb26
Clear stale deletion auth lockouts
azooz2003-bit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
132 changes: 132 additions & 0 deletions
132
...es/Shared/CmuxAuthRuntime/Sources/CmuxAuthRuntime/Coordinator/AccountDeletionClient.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| import Foundation | ||
|
|
||
| typealias AccountDeletionRequestLoader = @Sendable (URLRequest) async throws -> (Data, URLResponse) | ||
|
|
||
| struct AccountDeletionClient: Sendable { | ||
| private let apiBaseURL: String | ||
| private let requestTimeout: TimeInterval | ||
| private let load: AccountDeletionRequestLoader | ||
|
|
||
| init( | ||
| apiBaseURL: String, | ||
| requestTimeout: TimeInterval = 60, | ||
| load: @escaping AccountDeletionRequestLoader = { request in | ||
| try await URLSession.shared.data(for: request) | ||
| } | ||
| ) { | ||
| self.apiBaseURL = apiBaseURL | ||
| self.requestTimeout = requestTimeout | ||
| self.load = load | ||
| } | ||
|
|
||
| @concurrent | ||
| func deleteAccount(accessToken: String, refreshToken: String) async throws -> AccountDeletionResult { | ||
| let trimmedBaseURL = apiBaseURL.hasSuffix("/") ? String(apiBaseURL.dropLast()) : apiBaseURL | ||
| guard let url = URL(string: trimmedBaseURL + "/api/account") else { | ||
| throw AccountDeletionRequestError.invalidAPIBaseURL | ||
| } | ||
|
|
||
| var request = URLRequest(url: url, timeoutInterval: requestTimeout) | ||
| request.httpMethod = "DELETE" | ||
| request.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization") | ||
| request.setValue(refreshToken, forHTTPHeaderField: "X-Stack-Refresh-Token") | ||
|
|
||
| let data: Data | ||
| let response: URLResponse | ||
| do { | ||
| (data, response) = try await load(request) | ||
| } catch let error as URLError where error.code == .timedOut { | ||
| throw AccountDeletionRequestError.timedOut | ||
| } catch let error as URLError { | ||
| guard !isDefiniteLocalAccountDeletionTransportFailure(error.code) else { | ||
| throw AccountDeletionRequestError.localTransportFailure | ||
| } | ||
| throw AccountDeletionRequestError.completionUnknown | ||
| } | ||
| guard let httpResponse = response as? HTTPURLResponse else { | ||
| throw AccountDeletionRequestError.invalidResponse | ||
| } | ||
| switch httpResponse.statusCode { | ||
| case 200..<300: | ||
| return try accountDeletionResult(in: data) | ||
| case 401: | ||
| throw AccountDeletionRequestError.unauthorized | ||
| default: | ||
| let errorCode = accountDeletionErrorCode(in: data) | ||
| if isRetryablePartialAccountDeletionError(errorCode) { | ||
| throw AccountDeletionRequestError.stackDeleteIncomplete | ||
| } | ||
| if isDefinitiveAccountDeletionFailureError(errorCode) { | ||
| throw AccountDeletionRequestError.rejected(statusCode: httpResponse.statusCode) | ||
| } | ||
| if isAmbiguousAccountDeletionHTTPStatus(httpResponse.statusCode) { | ||
| throw AccountDeletionRequestError.completionUnknown | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
| throw AccountDeletionRequestError.rejected(statusCode: httpResponse.statusCode) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private func accountDeletionResult(in data: Data) throws -> AccountDeletionResult { | ||
| guard | ||
| let object = try? JSONSerialization.jsonObject(with: data) as? [String: Any] | ||
| else { | ||
| return .completed | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
| if object["deletionPending"] as? Bool == true { | ||
| throw AccountDeletionRequestError.completionUnknown | ||
| } | ||
| guard object["cleanupIncomplete"] as? Bool == true else { | ||
| return .completed | ||
| } | ||
| return .completedWithIncompleteServerCleanup | ||
| } | ||
|
|
||
| private func accountDeletionErrorCode(in data: Data) -> String? { | ||
| guard | ||
| let object = try? JSONSerialization.jsonObject(with: data) as? [String: Any], | ||
| let error = object["error"] as? String | ||
| else { | ||
| return nil | ||
| } | ||
| return error | ||
| } | ||
|
|
||
| private func isRetryablePartialAccountDeletionError(_ code: String?) -> Bool { | ||
| code == "account_delete_retryable" || | ||
| code == "account_stack_delete_failed_after_data_delete" | ||
| } | ||
|
|
||
| private func isDefinitiveAccountDeletionFailureError(_ code: String?) -> Bool { | ||
| code == "account_delete_failed" | ||
| } | ||
|
|
||
| private func isAmbiguousAccountDeletionHTTPStatus(_ statusCode: Int) -> Bool { | ||
| statusCode == 408 || statusCode >= 500 | ||
| } | ||
|
|
||
| private func isDefiniteLocalAccountDeletionTransportFailure(_ code: URLError.Code) -> Bool { | ||
| switch code { | ||
| case .appTransportSecurityRequiresSecureConnection, | ||
| .badURL, | ||
| .callIsActive, | ||
| .cannotConnectToHost, | ||
| .cannotFindHost, | ||
| .cannotLoadFromNetwork, | ||
| .clientCertificateRejected, | ||
| .clientCertificateRequired, | ||
| .dataNotAllowed, | ||
| .dnsLookupFailed, | ||
| .internationalRoamingOff, | ||
| .notConnectedToInternet, | ||
| .secureConnectionFailed, | ||
| .serverCertificateHasBadDate, | ||
| .serverCertificateHasUnknownRoot, | ||
| .serverCertificateNotYetValid, | ||
| .serverCertificateUntrusted, | ||
| .unsupportedURL: | ||
| return true | ||
| default: | ||
| return false | ||
| } | ||
| } | ||
21 changes: 21 additions & 0 deletions
21
...red/CmuxAuthRuntime/Sources/CmuxAuthRuntime/Coordinator/AccountDeletionRequestError.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import Foundation | ||
|
|
||
| /// Errors returned by the native cmux account-deletion request. | ||
| public enum AccountDeletionRequestError: Error, Equatable { | ||
| /// The configured cmux API base URL could not build an account-deletion URL. | ||
| case invalidAPIBaseURL | ||
| /// The backend rejected the supplied Stack access or refresh token. | ||
| case unauthorized | ||
| /// cmux data was deleted, but Stack account deletion did not finish. | ||
| case stackDeleteIncomplete | ||
| /// The DELETE request timed out after reaching the transport layer. | ||
| case timedOut | ||
| /// The request may have reached the backend, but no definitive result returned. | ||
| case completionUnknown | ||
| /// The request failed locally before it could plausibly reach the backend. | ||
| case localTransportFailure | ||
| /// The backend returned a definitive non-success status. | ||
| case rejected(statusCode: Int) | ||
| /// URL loading returned a non-HTTP response. | ||
| case invalidResponse | ||
| } |
9 changes: 9 additions & 0 deletions
9
...es/Shared/CmuxAuthRuntime/Sources/CmuxAuthRuntime/Coordinator/AccountDeletionResult.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import Foundation | ||
|
|
||
| /// Result returned after the backend accepted account deletion. | ||
| public enum AccountDeletionResult: Equatable, Sendable { | ||
| /// Stack and cmux cleanup completed. | ||
| case completed | ||
| /// Stack account deletion completed, but the backend reported follow-up cmux cleanup needs support attention. | ||
| case completedWithIncompleteServerCleanup | ||
| } |
29 changes: 29 additions & 0 deletions
29
...CmuxAuthRuntime/Sources/CmuxAuthRuntime/Coordinator/AuthCoordinator+AccountDeletion.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import Foundation | ||
|
|
||
| extension AuthCoordinator { | ||
| /// Permanently deletes the current Stack account through cmux's backend. | ||
| /// | ||
| /// Callers clear local shell/auth state through their normal sign-out owner | ||
| /// after this succeeds so app-level teardown hooks run in the right order. | ||
| public func deleteAccount() async throws -> AccountDeletionResult { | ||
| let apiBaseURL = apiBaseURL | ||
| let timeout = timeouts.network | ||
| let tokens = try await runTokenTouchingPhase(.accountDeletion, timeout: timeout) { | ||
| try await self.currentTokens() | ||
| } | ||
| return try await AccountDeletionClient( | ||
| apiBaseURL: apiBaseURL, | ||
| requestTimeout: timeout.urlRequestTimeoutInterval | ||
| ).deleteAccount( | ||
| accessToken: tokens.accessToken, | ||
| refreshToken: tokens.refreshToken | ||
| ) | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
| } | ||
|
|
||
| private extension Duration { | ||
| var urlRequestTimeoutInterval: TimeInterval { | ||
| let value = components | ||
| return TimeInterval(value.seconds) + TimeInterval(value.attoseconds) / 1_000_000_000_000_000_000 | ||
| } | ||
| } | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.