Skip to content

armgit / xtool

Public Imported from GitHub
0

Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.

More migration

Kabir Oberaif2d3d996ab8e
diff --git a/Sources/Supersign/DeveloperServices/App IDs/DeveloperServicesAddAppIDRequest.swift b/Sources/Supersign/DeveloperServices/App IDs/DeveloperServicesAddAppIDRequest.swift
deleted file mode 100644
index d8095f7..0000000
--- a/Sources/Supersign/DeveloperServices/App IDs/DeveloperServicesAddAppIDRequest.swift
+++ /dev/null
@@ -1,66 +0,0 @@
-//
-// DeveloperServicesAddAppIDRequest.swift
-// Supercharge
-//
-// Created by Kabir Oberai on 24/07/19.
-// Copyright © 2019 Kabir Oberai. All rights reserved.
-//
-
-import Foundation
-
-public struct DeveloperServicesAddAppIDRequest: DeveloperServicesPlatformRequest {
-
- public struct Response: Decodable, Sendable {
- let appId: DeveloperServicesAppID
- }
- public typealias Value = DeveloperServicesAppID
-
- public let platform: DeveloperServicesPlatform
- public let teamID: DeveloperServicesTeam.ID
- public let bundleID: String
- public let appName: String
- public let entitlements: Entitlements
- public let additionalFeatures: [DeveloperServicesFeature]
- public let isFree: Bool
-
- var subAction: String { return "addAppId" }
- var subParameters: [String: Any] {
- var parameters: [String: Any] = [
- "teamId": teamID.rawValue,
- "identifier": bundleID,
- "name": appName
- ]
-
- DeveloperServicesAppIDRequestApplier.apply(
- entitlements: entitlements,
- additionalFeatures: additionalFeatures,
- to: &parameters,
- isFree: isFree
- )
-
- return parameters
- }
-
- public func parse(_ response: Response) -> DeveloperServicesAppID {
- response.appId
- }
-
- public init(
- platform: DeveloperServicesPlatform,
- teamID: DeveloperServicesTeam.ID,
- bundleID: String,
- appName: String,
- entitlements: Entitlements,
- additionalFeatures: [DeveloperServicesFeature],
- isFree: Bool
- ) {
- self.platform = platform
- self.teamID = teamID
- self.bundleID = bundleID
- self.appName = appName
- self.entitlements = entitlements
- self.additionalFeatures = additionalFeatures
- self.isFree = isFree
- }
-
-}
diff --git a/Sources/Supersign/DeveloperServices/App IDs/DeveloperServicesAddAppOperation.swift b/Sources/Supersign/DeveloperServices/App IDs/DeveloperServicesAddAppOperation.swift
index a7ef9a9..d180434 100644
--- a/Sources/Supersign/DeveloperServices/App IDs/DeveloperServicesAddAppOperation.swift
+++ b/Sources/Supersign/DeveloperServices/App IDs/DeveloperServicesAddAppOperation.swift
@@ -7,6 +7,7 @@
//
import Foundation
+import DeveloperAPI
public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
@@ -50,32 +51,40 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
bundleID: String,
entitlements: Entitlements,
isFreeTeam: Bool,
- appIDs: [String: DeveloperServicesAppID]
+ appIDs: [String: Components.Schemas.BundleId]
) async throws -> DeveloperServicesAppID {
+ let appIDID: String
if let appID = appIDs[bundleID] {
- let request = DeveloperServicesUpdateAppIDRequest(
- platform: self.context.platform,
- teamID: self.context.teamID,
- appIDID: appID.id,
- entitlements: entitlements,
- additionalFeatures: [],
- isFree: isFreeTeam
- )
- return try await context.client.send(request)
+ appIDID = appID.id
} else {
let newBundleID = ProvisioningIdentifiers.identifier(fromSanitized: bundleID, context: self.context)
let name = ProvisioningIdentifiers.appName(fromSanitized: bundleID)
- let request = DeveloperServicesAddAppIDRequest(
- platform: self.context.platform,
- teamID: self.context.teamID,
- bundleID: newBundleID,
- appName: name,
- entitlements: entitlements,
- additionalFeatures: [],
- isFree: isFreeTeam
+ let createResponse = try await context.developerAPIClient.bundleIdsCreateInstance(
+ body: .json(
+ .init(
+ data: .init(
+ _type: .bundleIds,
+ attributes: .init(
+ name: name,
+ platform: .ios,
+ identifier: newBundleID
+ )
+ )
+ )
+ )
)
- return try await context.client.send(request)
+ appIDID = try createResponse.created.body.json.data.id
}
+
+ let request = DeveloperServicesUpdateAppIDRequest(
+ platform: self.context.platform,
+ teamID: self.context.teamID,
+ appIDID: .init(rawValue: appIDID),
+ entitlements: entitlements,
+ additionalFeatures: [],
+ isFree: isFreeTeam
+ )
+ return try await context.client.send(request)
}
/// Registers the app and creates a profile. Returns the resultant entitlements as well as
@@ -84,7 +93,7 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
private func addApp(
_ app: URL,
isFreeTeam: Bool,
- appIDs: [String: DeveloperServicesAppID]
+ appIDs: [String: Components.Schemas.BundleId]
) async throws -> ProvisioningInfo {
let infoURL = app.appendingPathComponent("Info.plist")
guard let data = try? Data(contentsOf: infoURL),
@@ -154,10 +163,13 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
}
// keyed by sanitized bundle ID
- private func getCurrentAppIDs() async throws -> [String: DeveloperServicesAppID] {
- let request = DeveloperServicesListAppIDsRequest(platform: context.platform, teamID: context.teamID)
- let appIDs = try await context.client.send(request)
- let keyedIDs = appIDs.map { (ProvisioningIdentifiers.sanitize(identifier: $0.bundleID), $0) }
+ private func getCurrentAppIDs() async throws -> [String: Components.Schemas.BundleId] {
+ let bundleIDs = try await context.developerAPIClient.bundleIdsGetCollection().ok.body.json.data
+ let keyedIDs = bundleIDs
+ .compactMap { id -> (String, Components.Schemas.BundleId)? in
+ guard let bundleID = id.attributes?.identifier else { return nil }
+ return (ProvisioningIdentifiers.sanitize(identifier: bundleID), id)
+ }
return Dictionary(keyedIDs, uniquingKeysWith: { $1 })
}
diff --git a/Sources/Supersign/DeveloperServices/App IDs/DeveloperServicesListAppIDsRequest.swift b/Sources/Supersign/DeveloperServices/App IDs/DeveloperServicesListAppIDsRequest.swift
deleted file mode 100644
index 45fe66f..0000000
--- a/Sources/Supersign/DeveloperServices/App IDs/DeveloperServicesListAppIDsRequest.swift
+++ /dev/null
@@ -1,35 +0,0 @@
-//
-// DeveloperServicesListAppIDsRequest.swift
-// Supercharge
-//
-// Created by Kabir Oberai on 24/07/19.
-// Copyright © 2019 Kabir Oberai. All rights reserved.
-//
-
-import Foundation
-
-public struct DeveloperServicesListAppIDsRequest: DeveloperServicesPlatformRequest {
-
- public struct Response: Decodable, Sendable {
- public let appIds: [DeveloperServicesAppID]
- }
- public typealias Value = [DeveloperServicesAppID]
-
- public let platform: DeveloperServicesPlatform
- public let teamID: DeveloperServicesTeam.ID
-
- var subAction: String { return "listAppIds" }
- var subParameters: [String: Any] {
- return ["teamId": teamID.rawValue]
- }
-
- public func parse(_ response: Response) -> [DeveloperServicesAppID] {
- response.appIds
- }
-
- public init(platform: DeveloperServicesPlatform, teamID: DeveloperServicesTeam.ID) {
- self.platform = platform
- self.teamID = teamID
- }
-
-}
diff --git a/Sources/Supersign/DeveloperServices/Profiles/DeveloperServicesFetchProfileOperation.swift b/Sources/Supersign/DeveloperServices/Profiles/DeveloperServicesFetchProfileOperation.swift
index d4fdc7f..b686edf 100644
--- a/Sources/Supersign/DeveloperServices/Profiles/DeveloperServicesFetchProfileOperation.swift
+++ b/Sources/Supersign/DeveloperServices/Profiles/DeveloperServicesFetchProfileOperation.swift
@@ -29,24 +29,30 @@ public struct DeveloperServicesFetchProfileOperation: DeveloperServicesOperation
let bundleIDs = try await context.developerAPIClient
.bundleIdsGetCollection(query: .init(
filter_lbrack_identifier_rbrack_: [bundleID],
+ fields_lbrack_profiles_rbrack_: [.bundleId],
include: [.profiles]
))
.ok.body.json
+ // filter[identifier] is a prefix filter so we need to manually upgrade to equality
+ let filtered = bundleIDs.data.filter { $0.attributes?.identifier == self.bundleID }
+
let bundleID: Components.Schemas.BundleId
- switch bundleIDs.data.count {
+ switch filtered.count {
case 0:
throw Errors.bundleIDNotFound
case 1:
- bundleID = bundleIDs.data[0]
+ bundleID = filtered[0]
default:
throw Errors.tooManyMatchingBundleIDs
}
+ // note: free developer accounts don't seem to persist profiles at all
+ // so this will often be empty.
let profiles = bundleIDs
.included?
.compactMap { included -> Components.Schemas.Profile? in
- if case .Profile(let profile) = included {
+ if case .Profile(let profile) = included, profile.relationships?.bundleId?.data?.id == bundleID.id {
profile
} else {
nil