Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.
Remember teamID
Kabir Oberai21efc6126a4d
diff --git a/Sources/Supersign/Integration/SuperchargeInstaller.swift b/Sources/Supersign/Integration/SuperchargeInstaller.swiftindex 8c79e1d..592546c 100644--- a/Sources/Supersign/Integration/SuperchargeInstaller.swift+++ b/Sources/Supersign/Integration/SuperchargeInstaller.swift@@ -18,8 +18,6 @@ extension LockdownClient {public protocol IntegratedInstallerDelegate: AnyObject, Sendable {- func fetchTeam(fromTeams teams: [DeveloperServicesTeam]) async -> DeveloperServicesTeam?-func setPresentedMessage(_ message: IntegratedInstaller.Message?)func installerDidUpdate(toStage stage: String, progress: Double?)@@ -85,6 +83,7 @@ public actor IntegratedInstaller {let lookupMode: LookupModelet appleID: Stringlet token: DeveloperServicesLoginToken+ let teamID: DeveloperServicesTeam.IDlet configureDevice: Boollet storage: KeyValueStoragepublic weak var delegate: IntegratedInstallerDelegate?@@ -145,6 +144,7 @@ public actor IntegratedInstaller {lookupMode: LookupMode,appleID: String,token: DeveloperServicesLoginToken,+ teamID: DeveloperServicesTeam.ID,configureDevice: Bool,storage: KeyValueStorage,delegate: IntegratedInstallerDelegate@@ -153,6 +153,7 @@ public actor IntegratedInstaller {self.lookupMode = lookupModeself.appleID = appleIDself.token = token+ self.teamID = teamIDself.configureDevice = configureDeviceself.storage = storageself.delegate = delegate@@ -272,7 +273,6 @@ public actor IntegratedInstaller {deviceInfo: DeviceInfo,token: DeveloperServicesLoginToken,client: DeveloperServicesClient,- team: DeveloperServicesTeam,ipa: URL,bundleID: String) async throws -> String {@@ -294,7 +294,6 @@ public actor IntegratedInstaller {deviceInfo: DeviceInfo,token: DeveloperServicesLoginToken,client: DeveloperServicesClient,- team: DeveloperServicesTeam,appDir: URL,bundleID: String) async throws -> String {@@ -315,7 +314,6 @@ public actor IntegratedInstaller {deviceInfo: deviceInfo,token: token,client: client,- team: team,ipa: ipa!,bundleID: bundleID)@@ -326,7 +324,7 @@ public actor IntegratedInstaller {provisioningData: ProvisioningData?,token: DeveloperServicesLoginToken,client: DeveloperServicesClient,- team: DeveloperServicesTeam,+ teamID: DeveloperServicesTeam.ID,appDir: URL) async throws -> String {try await self.updateStage(to: "Preparing device")@@ -336,7 +334,7 @@ public actor IntegratedInstaller {let context = try SigningContext(udid: udid,deviceName: deviceName,- teamID: team.id,+ teamID: teamID,client: client,signingInfoManager: KeyValueSigningInfoManager(storage: storage),platform: .iOS@@ -364,7 +362,7 @@ public actor IntegratedInstaller {udid: self.udid,pairingKeys: pairingKeys,deviceInfo: deviceInfo,- preferredTeamID: team.id.rawValue,+ preferredTeamID: teamID.rawValue,preferredSigningInfo: info,appleID: self.appleID,provisioningData: provisioningData,@@ -377,7 +375,6 @@ public actor IntegratedInstaller {deviceInfo: deviceInfo,token: token,client: client,- team: team,appDir: appDir,bundleID: bundleID)@@ -395,25 +392,12 @@ public actor IntegratedInstaller {deviceInfo: deviceInfo,anisetteProvider: anisetteProvider)- let teams = try await client.send(DeveloperServicesListTeamsRequest())- try await self.updateProgress(to: 1)- let team: DeveloperServicesTeam- switch teams.count {- case 0:- throw Error.noTeamFound- case 1:- team = teams[0]- default:- guard let selectedTeam = await self.delegate?.fetchTeam(fromTeams: teams)- else { throw CancellationError() }- team = selectedTeam- }return try await self.install(deviceInfo: deviceInfo,provisioningData: provisioningData,token: token,client: client,- team: team,+ teamID: teamID,appDir: appDir)}diff --git a/Sources/SupersignCLISupport/AuthCommand.swift b/Sources/SupersignCLISupport/AuthCommand.swiftindex b7aeea0..b603f91 100644--- a/Sources/SupersignCLISupport/AuthCommand.swift+++ b/Sources/SupersignCLISupport/AuthCommand.swift@@ -45,8 +45,27 @@ struct AuthOperation {password: password,twoFactorDelegate: authDelegate)- let fullToken = AuthToken(appleID: username, dsToken: token)++ let client = DeveloperServicesClient(+ loginToken: token,+ deviceInfo: deviceInfo,+ anisetteProvider: provider+ )+ let teams = try await client.send(DeveloperServicesListTeamsRequest())+ let team = try await Console.choose(+ from: teams,+ onNoElement: {+ throw Console.Error("No development teams found")+ },+ multiPrompt: "\nSelect a team",+ formatter: {+ "\($0.name) (\($0.id.rawValue))"+ }+ )++ let fullToken = AuthToken(appleID: username, teamID: team.id, dsToken: token)try fullToken.save()+print("Logged in")}}diff --git a/Sources/SupersignCLISupport/AuthToken.swift b/Sources/SupersignCLISupport/AuthToken.swiftindex e481687..30d243d 100644--- a/Sources/SupersignCLISupport/AuthToken.swift+++ b/Sources/SupersignCLISupport/AuthToken.swift@@ -1,76 +1,66 @@import Foundationimport Supersign-struct AuthToken {- let appleID: String- let dsToken: DeveloperServicesLoginToken-}--extension AuthToken {+struct AuthToken: Codable {+ var appleID: String+ var adsid: String+ var token: String+ var expiry: Date- // encoded format:- // - appleID (null terminated string)- // - adsid (null terminated string)- // - expiry (double)- // - token (data)-- init?(string: String) {- guard string.hasPrefix("@") else { return nil }- guard let data = Data(base64Encoded: String(string.dropFirst())) else { return nil }- let components = data.split(separator: 0, maxSplits: 2, omittingEmptySubsequences: false)- guard components.count == 3,- let appleID = String(data: components[0], encoding: .utf8),- !appleID.isEmpty,- let adsid = String(data: components[1], encoding: .utf8),- !adsid.isEmpty- else { return nil }+ private var _teamID: String+ var teamID: DeveloperServicesTeam.ID {+ get { .init(rawValue: _teamID) }+ set { _teamID = newValue.rawValue }+ }- let rest = components[2]- guard rest.count > MemoryLayout<Double>.size else { return nil }- var expiry: Double = 0- withUnsafeMutableBytes(of: &expiry) { _ = rest.copyBytes(to: $0) }+ private enum CodingKeys: String, CodingKey {+ case appleID+ case _teamID = "teamID"+ case adsid+ case token+ case expiry+ }+}- let token = rest.advanced(by: MemoryLayout<Double>.size).base64EncodedString()+extension AuthToken {+ init(+ appleID: String,+ teamID: DeveloperServicesTeam.ID,+ dsToken: DeveloperServicesLoginToken+ ) {self.appleID = appleID- self.dsToken = DeveloperServicesLoginToken(+ self._teamID = teamID.rawValue+ self.adsid = dsToken.adsid+ self.token = dsToken.token+ self.expiry = dsToken.expiry+ }++ var dsToken: DeveloperServicesLoginToken {+ DeveloperServicesLoginToken(adsid: adsid,token: token,- expiry: Date(timeIntervalSince1970: expiry)+ expiry: expiry)}- var string: String? {- guard var data = appleID.data(using: .utf8)- else { return nil }- data.append(0)- guard let adsidData = dsToken.adsid.data(using: .utf8)- else { return nil }- data.append(adsidData)- data.append(0)- withUnsafeBytes(of: dsToken.expiry.timeIntervalSince1970) {- data.append(Data($0))- }- guard let rawToken = Data(base64Encoded: dsToken.token)- else { return nil }- data.append(rawToken)- return "@\(data.base64EncodedString())"- }+ private static let encoder = JSONEncoder()+ private static let decoder = JSONDecoder()static func saved() throws -> Self {- guard let string = try SupersignCLI.config.storage.string(forKey: "SUPAuthToken"),- let token = AuthToken(string: string) else {+ guard let data = try SupersignCLI.config.storage.data(forKey: "SUPAuthToken") else {throw Console.Error("Please log in with `supersign ds login` before running this command.")}- return token+ return try decoder.decode(AuthToken.self, from: data)}static func clear() throws {- try SupersignCLI.config.storage.setString(nil, forKey: "SUPAuthToken")+ try SupersignCLI.config.storage.setData(nil, forKey: "SUPAuthToken")}func save() throws {- try SupersignCLI.config.storage.setString(string, forKey: "SUPAuthToken")+ let data = try Self.encoder.encode(self)+ try SupersignCLI.config.storage.setData(data, forKey: "SUPAuthToken")}}diff --git a/Sources/SupersignCLISupport/DSCommand.swift b/Sources/SupersignCLISupport/DSCommand.swiftindex d25538a..4646876 100644--- a/Sources/SupersignCLISupport/DSCommand.swift+++ b/Sources/SupersignCLISupport/DSCommand.swift@@ -8,10 +8,8 @@ struct DSTeamsListCommand: AsyncParsableCommand {abstract: "List Developer Services teams")- @Option(name: .shortAndLong) var account: String?-func run() async throws {- let token = try account.flatMap(AuthToken.init(string:)) ?? AuthToken.saved()+ let token = try AuthToken.saved()let deviceInfo = try DeviceInfo.fetch()let anisetteProvider = try ADIDataProvider.adiProvider(diff --git a/Sources/SupersignCLISupport/DevCommand.swift b/Sources/SupersignCLISupport/DevCommand.swiftindex 98d4b9c..d3e2f95 100644--- a/Sources/SupersignCLISupport/DevCommand.swift+++ b/Sources/SupersignCLISupport/DevCommand.swift@@ -109,12 +109,13 @@ struct DevRunCommand: AsyncParsableCommand {let client = try await connectionOptions.client()print("Installing to device: \(client.deviceName) (udid: \(client.udid))")- let installDelegate = SupersignCLIDelegate(preferredTeam: team.map(DeveloperServicesTeam.ID.init))+ let installDelegate = SupersignCLIDelegate()let installer = IntegratedInstaller(udid: client.udid,lookupMode: .only(client.connectionType),appleID: token.appleID,token: token.dsToken,+ teamID: token.teamID,configureDevice: false,storage: SupersignCLI.config.storage,delegate: installDelegatediff --git a/Sources/SupersignCLISupport/InstallCommand.swift b/Sources/SupersignCLISupport/InstallCommand.swiftindex 3383fa6..1b563cd 100644--- a/Sources/SupersignCLISupport/InstallCommand.swift+++ b/Sources/SupersignCLISupport/InstallCommand.swift@@ -27,12 +27,13 @@ struct InstallCommand: AsyncParsableCommand {print("Installing to device: \(client.deviceName) (udid: \(client.udid))")- let installDelegate = SupersignCLIDelegate(preferredTeam: team.map(DeveloperServicesTeam.ID.init))+ let installDelegate = SupersignCLIDelegate()let installer = IntegratedInstaller(udid: client.udid,lookupMode: .only(client.connectionType),appleID: token.appleID,token: token.dsToken,+ teamID: token.teamID,configureDevice: false,storage: SupersignCLI.config.storage,delegate: installDelegatediff --git a/Sources/SupersignCLISupport/SuperchargeCommand.swift b/Sources/SupersignCLISupport/SuperchargeCommand.swiftindex 2f25c2e..2366fda 100644--- a/Sources/SupersignCLISupport/SuperchargeCommand.swift+++ b/Sources/SupersignCLISupport/SuperchargeCommand.swift@@ -21,12 +21,13 @@ struct InstallSuperchargeCommand: AsyncParsableCommand {print("Installing to device: \(client.deviceName) (udid: \(client.udid))")- let installDelegate = SupersignCLIDelegate(preferredTeam: nil)+ let installDelegate = SupersignCLIDelegate()let installer = IntegratedInstaller(udid: client.udid,lookupMode: .only(client.connectionType),appleID: auth.appleID,token: auth.dsToken,+ teamID: auth.teamID,configureDevice: true,storage: SupersignCLI.config.storage,delegate: installDelegatediff --git a/Sources/SupersignCLISupport/SupersignCLIDelegate.swift b/Sources/SupersignCLISupport/SupersignCLIDelegate.swiftindex e8adb46..f64abe9 100644--- a/Sources/SupersignCLISupport/SupersignCLIDelegate.swift+++ b/Sources/SupersignCLISupport/SupersignCLIDelegate.swift@@ -14,30 +14,10 @@ actor SupersignCLIDelegate: IntegratedInstallerDelegate {case compressionFailed}- let preferredTeam: DeveloperServicesTeam.ID?- init(preferredTeam: DeveloperServicesTeam.ID?) {- self.preferredTeam = preferredTeam- }+ init() {}private let updateTask = LockIsolated<Task<Void, Never>?>(nil)- func fetchTeam(fromTeams teams: [DeveloperServicesTeam]) async -> DeveloperServicesTeam? {- if let preferredTeam = preferredTeam {- // Fails if a team with the requested ID isn't found.- // This is intentional to avoid interactivity.- return teams.first(where: { $0.id == preferredTeam })- }-- return try? await Console.choose(- from: teams,- onNoElement: { fatalError("No development teams available") },- multiPrompt: "\nSelect a team",- formatter: {- "\($0.name) (\($0.id.rawValue))"- }- )- }-nonisolated func setPresentedMessage(_ message: IntegratedInstaller.Message?) {let text: Stringswitch message {