xtool.git
Publicgit clone https://git.maproj.org/xtool.gitxtool.git / Sources / XKit / DeveloperServices / App IDs / Entitlements / DeveloperServicesCapability.swift
DeveloperServicesCapability.swift160 lines · 4.8 KiBRaw
| 1 | // |
| 2 | // DeveloperServicesFeatureTypes.swift |
| 3 | // Supercharge |
| 4 | // |
| 5 | // Created by Kabir Oberai on 29/07/19. |
| 6 | // Copyright © 2019 Kabir Oberai. All rights reserved. |
| 7 | // |
| 8 | |
| 9 | import Foundation |
| 10 | import DeveloperAPI |
| 11 | |
| 12 | public struct DeveloperServicesCapability: Sendable, Hashable { |
| 13 | public var capabilityType: Components.Schemas.CapabilityType |
| 14 | public var isFree: Bool |
| 15 | public var settings: [Components.Schemas.CapabilitySetting]? |
| 16 | |
| 17 | public init( |
| 18 | _ capabilityType: Components.Schemas.CapabilityType.Value1Payload, |
| 19 | isFree: Bool, |
| 20 | settings: [Components.Schemas.CapabilitySetting]? = nil |
| 21 | ) { |
| 22 | self.capabilityType = .init(capabilityType) |
| 23 | self.isFree = isFree |
| 24 | self.settings = settings |
| 25 | } |
| 26 | |
| 27 | public init( |
| 28 | rawName: String, |
| 29 | isFree: Bool, |
| 30 | settings: [Components.Schemas.CapabilitySetting]? = nil |
| 31 | ) { |
| 32 | self.capabilityType = .init(value2: rawName) |
| 33 | self.isFree = isFree |
| 34 | self.settings = settings |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | protocol EntitlementWithCapability: Entitlement { |
| 39 | var capability: DeveloperServicesCapability { get } |
| 40 | } |
| 41 | |
| 42 | extension Entitlement { |
| 43 | var anyCapability: DeveloperServicesCapability? { |
| 44 | (self as? EntitlementWithCapability)?.capability |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | // MARK: - Special Features |
| 49 | |
| 50 | extension DataProtectionEntitlement: EntitlementWithCapability { |
| 51 | var capability: DeveloperServicesCapability { |
| 52 | let option: Components.Schemas.CapabilityOption.KeyPayload.Value1Payload = switch self { |
| 53 | case .complete: .completeProtection |
| 54 | case .unlessOpen: .protectedUnlessOpen |
| 55 | case .untilFirstAuth: .protectedUntilFirstUserAuth |
| 56 | } |
| 57 | return DeveloperServicesCapability( |
| 58 | .dataProtection, |
| 59 | isFree: true, |
| 60 | settings: [ |
| 61 | .init( |
| 62 | key: .init(.dataProtectionPermissionLevel), |
| 63 | options: [.init(key: .init(option))] |
| 64 | ) |
| 65 | ] |
| 66 | ) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // MARK: - Boolean Features |
| 71 | |
| 72 | // https://github.com/fastlane/fastlane/blob/master/spaceship/lib/spaceship/portal/app_service.rb |
| 73 | |
| 74 | extension AppGroupEntitlement: EntitlementWithCapability { |
| 75 | var capability: DeveloperServicesCapability { |
| 76 | DeveloperServicesCapability(.appGroups, isFree: true) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | extension AppleSignInEntitlement: EntitlementWithCapability { |
| 81 | var capability: DeveloperServicesCapability { |
| 82 | // A primary App ID: the app is its own Sign in with Apple group. |
| 83 | DeveloperServicesCapability( |
| 84 | .appleIdAuth, |
| 85 | isFree: false, |
| 86 | settings: [ |
| 87 | .init( |
| 88 | key: .init(.appleIdAuthAppConsent), |
| 89 | options: [.init(key: .init(.primaryAppConsent))] |
| 90 | ) |
| 91 | ] |
| 92 | ) |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | extension AssociatedDomainsEntitlement: EntitlementWithCapability { |
| 97 | var capability: DeveloperServicesCapability { |
| 98 | DeveloperServicesCapability(.associatedDomains, isFree: false) |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | extension HealthKitEntitlement: EntitlementWithCapability { |
| 103 | var capability: DeveloperServicesCapability { |
| 104 | DeveloperServicesCapability(.healthkit, isFree: true) |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | extension HomeKitEntitlement: EntitlementWithCapability { |
| 109 | var capability: DeveloperServicesCapability { |
| 110 | DeveloperServicesCapability(.homekit, isFree: true) |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | extension InterAppAudioEntitlement: EntitlementWithCapability { |
| 115 | var capability: DeveloperServicesCapability { |
| 116 | DeveloperServicesCapability(.interAppAudio, isFree: true) |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | extension MultipathEntitlement: EntitlementWithCapability { |
| 121 | var capability: DeveloperServicesCapability { |
| 122 | DeveloperServicesCapability(.multipath, isFree: false) |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | extension NetworkExtensionEntitlement: EntitlementWithCapability { |
| 127 | var capability: DeveloperServicesCapability { |
| 128 | DeveloperServicesCapability(.networkExtensions, isFree: false) |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | extension VPNConfigurationEntitlement: EntitlementWithCapability { |
| 133 | public var capability: DeveloperServicesCapability { |
| 134 | DeveloperServicesCapability(.personalVpn, isFree: false) |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | extension APSEnvironmentEntitlement: EntitlementWithCapability { |
| 139 | var capability: DeveloperServicesCapability { |
| 140 | DeveloperServicesCapability(.pushNotifications, isFree: false) |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | extension SiriKitEntitlement: EntitlementWithCapability { |
| 145 | var capability: DeveloperServicesCapability { |
| 146 | DeveloperServicesCapability(.sirikit, isFree: false) |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | extension WirelessAccessoryEntitlement: EntitlementWithCapability { |
| 151 | var capability: DeveloperServicesCapability { |
| 152 | DeveloperServicesCapability(.wirelessAccessoryConfiguration, isFree: true) |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | extension WiFiAwareEntitlement: EntitlementWithCapability { |
| 157 | var capability: DeveloperServicesCapability { |
| 158 | DeveloperServicesCapability(rawName: "WIFI_AWARE", isFree: false) |
| 159 | } |
| 160 | } |