Files
xtool/Sources/XKit/DeveloperServices/App IDs/Entitlements/DeveloperServicesCapability.swift
Cesar Andres Pereira Bernal 0c63e6979f ds: allow one app group on free teams (#284)
## What does this PR do?

Resolves the FIXME in `DeveloperServicesCapability`: App Groups are no
longer filtered out on free teams, and
`DeveloperServicesAddAppOperation` assigns at most one group per app on
a free team (the constraint the FIXME mentioned).

Free teams can register and assign app groups through the Xcode
DeveloperServices API (as AltStore/SideStore do), so a widget and its
app can share `UserDefaults(suiteName:)` with a free Apple ID.

## How was it tested?

Built on Linux from `main` (4d0c429). Installed a Flutter app with a
WidgetKit extension on an iPhone (iOS 27.2) with a free Apple ID: the
app gets `group.XTL-<team>.<id>` in its entitlements and the widget
reads the app's data through it. `make lint` not run (no SwiftLint on
this machine).

## AI tool usage

How much of this PR was AI-assisted? (check one)

- [ ] **0** - No AI was used to write code
- [x] **1** - I was assisted by AI. I reviewed the finished result.
- [ ] **2** - I set the AI going and left it to it; nobody has read the
result - no review, or AI review only


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
  * App Groups are now available to free teams.
* Apps assigned to multiple App Groups are rejected with a clear error
message.
* Invalid app errors now include the app’s URL path, making it easier to
identify which app could not be added.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Kabir Oberai <oberai.kabir@gmail.com>
2026-10-30 02:11:54 -04:00

161 lines
4.8 KiB
Swift

//
// DeveloperServicesFeatureTypes.swift
// Supercharge
//
// Created by Kabir Oberai on 29/07/19.
// Copyright © 2019 Kabir Oberai. All rights reserved.
//
import Foundation
import DeveloperAPI
public struct DeveloperServicesCapability: Sendable, Hashable {
public var capabilityType: Components.Schemas.CapabilityType
public var isFree: Bool
public var settings: [Components.Schemas.CapabilitySetting]?
public init(
_ capabilityType: Components.Schemas.CapabilityType.Value1Payload,
isFree: Bool,
settings: [Components.Schemas.CapabilitySetting]? = nil
) {
self.capabilityType = .init(capabilityType)
self.isFree = isFree
self.settings = settings
}
public init(
rawName: String,
isFree: Bool,
settings: [Components.Schemas.CapabilitySetting]? = nil
) {
self.capabilityType = .init(value2: rawName)
self.isFree = isFree
self.settings = settings
}
}
protocol EntitlementWithCapability: Entitlement {
var capability: DeveloperServicesCapability { get }
}
extension Entitlement {
var anyCapability: DeveloperServicesCapability? {
(self as? EntitlementWithCapability)?.capability
}
}
// MARK: - Special Features
extension DataProtectionEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
let option: Components.Schemas.CapabilityOption.KeyPayload.Value1Payload = switch self {
case .complete: .completeProtection
case .unlessOpen: .protectedUnlessOpen
case .untilFirstAuth: .protectedUntilFirstUserAuth
}
return DeveloperServicesCapability(
.dataProtection,
isFree: true,
settings: [
.init(
key: .init(.dataProtectionPermissionLevel),
options: [.init(key: .init(option))]
)
]
)
}
}
// MARK: - Boolean Features
// https://github.com/fastlane/fastlane/blob/master/spaceship/lib/spaceship/portal/app_service.rb
extension AppGroupEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(.appGroups, isFree: true)
}
}
extension AppleSignInEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
// A primary App ID: the app is its own Sign in with Apple group.
DeveloperServicesCapability(
.appleIdAuth,
isFree: false,
settings: [
.init(
key: .init(.appleIdAuthAppConsent),
options: [.init(key: .init(.primaryAppConsent))]
)
]
)
}
}
extension AssociatedDomainsEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(.associatedDomains, isFree: false)
}
}
extension HealthKitEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(.healthkit, isFree: true)
}
}
extension HomeKitEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(.homekit, isFree: true)
}
}
extension InterAppAudioEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(.interAppAudio, isFree: true)
}
}
extension MultipathEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(.multipath, isFree: false)
}
}
extension NetworkExtensionEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(.networkExtensions, isFree: false)
}
}
extension VPNConfigurationEntitlement: EntitlementWithCapability {
public var capability: DeveloperServicesCapability {
DeveloperServicesCapability(.personalVpn, isFree: false)
}
}
extension APSEnvironmentEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(.pushNotifications, isFree: false)
}
}
extension SiriKitEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(.sirikit, isFree: false)
}
}
extension WirelessAccessoryEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(.wirelessAccessoryConfiguration, isFree: true)
}
}
extension WiFiAwareEntitlement: EntitlementWithCapability {
var capability: DeveloperServicesCapability {
DeveloperServicesCapability(rawName: "WIFI_AWARE", isFree: false)
}
}