1import { ExpoConfig } from 'expo/config';
2import { ConfigPlugin, InfoPlist, withInfoPlist } from 'expo/config-plugins';
3
4export const withBranchIOS: ConfigPlugin = (config) => {
5  return withInfoPlist(config, (config) => {
6    config.modResults = setBranchApiKey(config, config.modResults);
7    return config;
8  });
9};
10
11export function getBranchApiKey(config: Pick<ExpoConfig, 'ios'>) {
12  return config.ios?.config?.branch?.apiKey ?? null;
13}
14
15export function setBranchApiKey(config: Pick<ExpoConfig, 'ios'>, infoPlist: InfoPlist): InfoPlist {
16  const apiKey = getBranchApiKey(config);
17
18  if (apiKey === null) {
19    return infoPlist;
20  }
21
22  return {
23    ...infoPlist,
24    branch_key: {
25      live: apiKey,
26    },
27  };
28}
29