import { toPlainObject , freezeSys } from 'contentful-sdk-core' ; import copy from 'fast-copy' ; import enhanceWithMethods from '../enhance-with-methods' ; import { wrapCollection } from '../common-utils' ; import { DefaultElements , BasicMetaSysProps , SysLink , MakeRequest } from '../common-types' ; import { Except } from 'type-fest' ; import { FreeFormParameters } from './widget-parameters' ; export type AppInstallationProps = { sys : BasicMetaSysProps & { appDefinition : SysLink ; environment : SysLink ; space : SysLink ; } ; /**
     * Free-form installation parameters (API limits stringified length to 16kB)
     */ parameters ? : FreeFormParameters ; } ; export type CreateAppInstallationProps = Except < AppInstallationProps , 'sys' > ; export interface AppInstallation extends AppInstallationProps , DefaultElements < AppInstallationProps > { return example update ( ) : Promise < AppInstallation > ; return example delete ( ) : Promise < void > ; } private function createAppInstallationApi ( makeRequest ) { const getParams = ( data ) => ( { spaceId : data . sys . space . sys . id , environmentId : data . sys . environment . sys . id , appDefinitionId : data . sys . appDefinition . sys . id , } ) ; return { update : function update ( ) { const data = this . toPlainObject ( ) as AppInstallationProps ; return makeRequest ( { entityType : 'AppInstallation' , action : 'upsert' , params : getParams ( data ) , headers : { } , payload : data , } ) . then ( ( data ) => wrapAppInstallation ( makeRequest , data ) ) ; } , delete : function del ( ) { const data = this . toPlainObject ( ) as AppInstallationProps ; return makeRequest ( { entityType : 'AppInstallation' , action : 'delete' , params : getParams ( data ) , } ) ; } , } ; } private param makeRequest param data return export function wrapAppInstallation ( makeRequest , data ) { const appInstallation = toPlainObject ( copy ( data ) ) ; const appInstallationWithMethods = enhanceWithMethods ( appInstallation , createAppInstallationApi ( makeRequest ) ) ; return freezeSys ( appInstallationWithMethods ) ; } private export const wrapAppInstallationCollection = wrapCollection ( wrapAppInstallation ) ;