1import { ExpoConfig } from '@expo/config-types';
2
3import { createInfoPlistPluginWithPropertyGuard } from '../plugins/ios-plugins';
4import { InfoPlist } from './IosConfig.types';
5
6export const withUsesNonExemptEncryption = createInfoPlistPluginWithPropertyGuard(
7  setUsesNonExemptEncryption,
8  {
9    infoPlistProperty: 'ITSAppUsesNonExemptEncryption',
10    expoConfigProperty: 'ios.config.usesNonExemptEncryption',
11  },
12  'withUsesNonExemptEncryption'
13);
14
15export function getUsesNonExemptEncryption(config: Pick<ExpoConfig, 'ios'>) {
16  return config?.ios?.config?.usesNonExemptEncryption ?? null;
17}
18
19export function setUsesNonExemptEncryption(
20  config: Pick<ExpoConfig, 'ios'>,
21  { ITSAppUsesNonExemptEncryption, ...infoPlist }: InfoPlist
22): InfoPlist {
23  const usesNonExemptEncryption = getUsesNonExemptEncryption(config);
24
25  // Make no changes if the key is left blank
26  if (usesNonExemptEncryption === null) {
27    return infoPlist;
28  }
29
30  return {
31    ...infoPlist,
32    ITSAppUsesNonExemptEncryption: usesNonExemptEncryption,
33  };
34}
35