import Debug from 'debug' ; import { ConfigPlugin } from '../Plugin.types' ; import { withInfoPlist } from '../plugins/ios-plugins' ; import { InfoPlist } from './IosConfig.types' ; const debug = Debug ( 'expo:config-plugins:ios:permissions' ) ; export function applyPermissions < Defaults extends Record < string , string > = Record < string , string > > ( defaults , permissions , infoPlist ) { const entries = Object . entries ( defaults ) ; if ( entries . length === 0 ) { debug ( `No defaults provided: ${ JSON . stringify ( permissions ) }` ) ; } for ( const [ permission , description ] of entries ) { if ( permissions [ permission ] === false ) { debug ( `Deleting "${ permission }"` ) ; delete infoPlist [ permission ] ; } else { infoPlist [ permission ] = permissions [ permission ] || infoPlist [ permission ] || description ; debug ( `Setting "${ permission }" to "${ infoPlist [ permission ] }"` ) ; } } return infoPlist ; } param action export function createPermissionsPlugin < Defaults extends Record < string , string > = Record < string , string > > ( defaults , name ? ) { const withIosPermissions = ( config , permissions ) => withInfoPlist ( config , async ( config ) => { config . modResults = applyPermissions ( defaults , permissions , config . modResults ) ; return config ; } ) ; if ( name ) { Object . defineProperty ( withIosPermissions , 'name' , { value : name } ) ; } return withIosPermissions ; }