|
4 | 4 | CapabilityType,
|
5 | 5 | CapabilityTypeOption,
|
6 | 6 | } from '@expo/apple-utils';
|
7 |
| -import { JSONObject, JSONValue } from '@expo/json-file'; |
| 7 | +import { JSONObject } from '@expo/json-file'; |
8 | 8 | import getenv from 'getenv';
|
9 | 9 | import { inspect } from 'util';
|
10 | 10 |
|
@@ -87,102 +87,6 @@ interface CapabilitiesRequest {
|
87 | 87 | option: any;
|
88 | 88 | }
|
89 | 89 |
|
90 |
| -function shouldSkipPushNotificationsCapabilityUpdate( |
91 |
| - existing: BundleIdCapability, |
92 |
| - additionalOptions: { |
93 |
| - usesBroadcastPushNotifications: boolean; |
94 |
| - } |
95 |
| -): boolean { |
96 |
| - // For push notifications, we should always update the capability if |
97 |
| - // - settings are not defined in the existing capability, but usesBroadcastPushNotifications is enabled (we want to add settings for this capability) |
98 |
| - // - settings are defined in the existing capability, but usesBroadcastPushNotifications is disabled (we want to remove settings for this capability) |
99 |
| - const noSettingsAttributes = existing.attributes.settings == null; |
100 |
| - return !noSettingsAttributes === additionalOptions.usesBroadcastPushNotifications; |
101 |
| -} |
102 |
| - |
103 |
| -function shouldSkipIcloudCapabilityUpdate( |
104 |
| - existing: BundleIdCapability, |
105 |
| - newOption: CapabilityTypeOption |
106 |
| -): boolean { |
107 |
| - // For iCloud capabilities, we should skip if: |
108 |
| - // - the capability is already enabled and has the correct settings |
109 |
| - // - we want to enable it and it's already enabled with settings |
110 |
| - const existingEnabled = 'enabled' in existing.attributes && existing.attributes.enabled === true; |
111 |
| - const newEnabled = newOption === CapabilityTypeOption.ON; |
112 |
| - |
113 |
| - // If both are enabled and the existing one has settings, skip the update |
114 |
| - // the settings are defined for only a few capabilities: https://developer.apple.com/documentation/appstoreconnectapi/capabilitysetting |
115 |
| - if (existingEnabled && newEnabled && existing.attributes.settings) { |
116 |
| - return true; |
117 |
| - } |
118 |
| - |
119 |
| - // If the states don't match, we need to update |
120 |
| - return existingEnabled === newEnabled; |
121 |
| -} |
122 |
| - |
123 |
| -function shouldPerformRemoteCapabilitySetup( |
124 |
| - existingRemote: BundleIdCapability | null, |
125 |
| - staticCapabilityInfo: CapabilityClassifier, |
126 |
| - entitlementValue: JSONValue, |
127 |
| - entitlements: JSONObject, |
128 |
| - additionalOptions: { |
129 |
| - usesBroadcastPushNotifications: boolean; |
130 |
| - } |
131 |
| -): 'enable' | 'disable' | 'skip' { |
132 |
| - if (!existingRemote) { |
133 |
| - if (entitlementValue === false) { |
134 |
| - // the value represents a disabled capability (boolean false) |
135 |
| - // e.g. 'com.apple.developer.networking.wifi-info': false |
136 |
| - // the remote capability is *already disabled*, so we should skip it |
137 |
| - return 'skip'; |
138 |
| - } |
139 |
| - // a new capability not present remotely, so we want to create it |
140 |
| - return 'enable'; |
141 |
| - } |
142 |
| - if (existingRemote && entitlementValue === false) { |
143 |
| - return 'disable'; |
144 |
| - } |
145 |
| - |
146 |
| - // Only skip if the existing capability is a simple boolean value, |
147 |
| - // if it has more complex settings then we should update it (except for push notifications, iCloud and perhaps more). |
148 |
| - // If the `existing.attributes.settings` object is defined, then we can determine that it has extra configuration. |
149 |
| - // For push notifications, we should always update the capability if |
150 |
| - // - settings are not defined in the existing capability, but usesBroadcastPushNotifications is enabled (we want to add settings for this capability) |
151 |
| - // - settings are defined in the existing capability, but usesBroadcastPushNotifications is disabled (we want to remove settings for this capability) |
152 |
| - |
153 |
| - const isPushNotificationsCapability = |
154 |
| - staticCapabilityInfo.capability === CapabilityType.PUSH_NOTIFICATIONS; |
155 |
| - |
156 |
| - if (isPushNotificationsCapability) { |
157 |
| - return shouldSkipPushNotificationsCapabilityUpdate(existingRemote, additionalOptions) |
158 |
| - ? 'skip' |
159 |
| - : 'enable'; |
160 |
| - } |
161 |
| - |
162 |
| - const newValue = staticCapabilityInfo.getOptions( |
163 |
| - entitlementValue, |
164 |
| - entitlements, |
165 |
| - additionalOptions |
166 |
| - ); |
167 |
| - |
168 |
| - const needsSpecialHandling = |
169 |
| - staticCapabilityInfo.capability === CapabilityType.ICLOUD || |
170 |
| - staticCapabilityInfo.capability === CapabilityType.APPLE_ID_AUTH; |
171 |
| - if (needsSpecialHandling) { |
172 |
| - return shouldSkipIcloudCapabilityUpdate(existingRemote, newValue) ? 'skip' : 'enable'; |
173 |
| - } |
174 |
| - |
175 |
| - if ( |
176 |
| - staticCapabilityInfo.capability === CapabilityType.DATA_PROTECTION && |
177 |
| - existingRemote.attributes.settings?.[0].key === 'DATA_PROTECTION_PERMISSION_LEVEL' |
178 |
| - ) { |
179 |
| - const oldValue = existingRemote.attributes.settings[0]?.options?.[0]?.key; |
180 |
| - return oldValue === newValue ? 'skip' : 'enable'; |
181 |
| - } |
182 |
| - |
183 |
| - return existingRemote.attributes.settings === null ? 'skip' : 'enable'; |
184 |
| -} |
185 |
| - |
186 | 90 | function getCapabilitiesToEnable(
|
187 | 91 | currentRemoteCapabilities: BundleIdCapability[],
|
188 | 92 | entitlements: JSONObject,
|
@@ -216,27 +120,25 @@ function getCapabilitiesToEnable(
|
216 | 120 | );
|
217 | 121 | const existingRemote = existingIndex > -1 ? remainingCapabilities[existingIndex] : null;
|
218 | 122 |
|
219 |
| - const operation = shouldPerformRemoteCapabilitySetup( |
| 123 | + const operation = staticCapabilityInfo.getSyncOperation({ |
220 | 124 | existingRemote,
|
221 |
| - staticCapabilityInfo, |
222 |
| - value, |
223 | 125 | entitlements,
|
224 |
| - additionalOptions |
225 |
| - ); |
| 126 | + entitlementValue: value, |
| 127 | + additionalOptions, |
| 128 | + }); |
| 129 | + const { op } = operation; |
226 | 130 |
|
227 | 131 | if (Log.isDebug) {
|
228 |
| - Log.log(`Will ${operation} remote capability: ${key} (${staticCapabilityInfo.name}.`); |
| 132 | + Log.log(`Will ${op} remote capability: ${key} (${staticCapabilityInfo.name}.`); |
229 | 133 | }
|
230 |
| - if (operation === 'enable') { |
| 134 | + if (op === 'enable') { |
231 | 135 | enabledCapabilityNames.push(staticCapabilityInfo.name);
|
232 | 136 |
|
233 |
| - const option = staticCapabilityInfo.getOptions(value, entitlements, additionalOptions); |
234 |
| - |
235 | 137 | request.push({
|
236 | 138 | capabilityType: staticCapabilityInfo.capability,
|
237 |
| - option, |
| 139 | + option: operation.option, |
238 | 140 | });
|
239 |
| - } else if (operation === 'skip') { |
| 141 | + } else if (op === 'skip') { |
240 | 142 | // Remove the item from the list of capabilities so we don't disable it in the next step.
|
241 | 143 | remainingCapabilities.splice(existingIndex, 1);
|
242 | 144 | }
|
|
0 commit comments