import { MakeRequest , QueryOptions } from './common-types' ; import entities from './entities' ; import { CreateAppBundleProps } from './entities/app-bundle' ; import { AppDefinitionProps , wrapAppDefinition } from './entities/app-definition' ; private export type ContentfulAppDefinitionAPI = ReturnType < typeof createAppDefinitionApi > ; private export default function createAppDefinitionApi ( makeRequest ) { const { wrapAppBundle , wrapAppBundleCollection } = entities . appBundle ; const getParams = ( data ) => ( { appDefinitionId : data . sys . id , organizationId : data . sys . organization . sys . id , } ) ; return { return example update : function update ( ) { const data = this . toPlainObject ( ) as AppDefinitionProps ; return makeRequest ( { entityType : 'AppDefinition' , action : 'update' , params : getParams ( data ) , headers : { } , payload : data , } ) . then ( ( data ) => wrapAppDefinition ( makeRequest , data ) ) ; } , return example delete : function del ( ) { const data = this . toPlainObject ( ) as AppDefinitionProps ; return makeRequest ( { entityType : 'AppDefinition' , action : 'delete' , params : getParams ( data ) , } ) ; } , param id return example getAppBundle ( id ) { const raw = this . toPlainObject ( ) as AppDefinitionProps ; return makeRequest ( { entityType : 'AppBundle' , action : 'get' , params : { appBundleId : id , appDefinitionId : raw . sys . id , organizationId : raw . sys . organization . sys . id , } , } ) . then ( ( data ) => wrapAppBundle ( makeRequest , data ) ) ; } , return example getAppBundles ( query = { } ) { const raw = this . toPlainObject ( ) as AppDefinitionProps ; return makeRequest ( { entityType : 'AppBundle' , action : 'getMany' , params : { organizationId : raw . sys . organization . sys . id , appDefinitionId : raw . sys . id , query } , } ) . then ( ( data ) => wrapAppBundleCollection ( makeRequest , data ) ) ; } , param Object return example createAppBundle ( data ) { const raw = this . toPlainObject ( ) as AppDefinitionProps ; return makeRequest ( { entityType : 'AppBundle' , action : 'create' , params : { appDefinitionId : raw . sys . id , organizationId : raw . sys . organization . sys . id , } , payload : data , } ) . then ( ( data ) => wrapAppBundle ( makeRequest , data ) ) ; } , } ; }