import type { AxiosInstance } from 'contentful-sdk-core' ; import copy from 'fast-copy' ; import { SetOptional } from 'type-fest' ; import { GetSpaceParams , GetWebhookCallDetailsUrl , GetWebhookParams , QueryParams , } from '../../../common-types' ; import { CreateWebhooksProps , WebhookProps } from '../../../entities/webhook' ; import { RestEndpoint } from '../types' ; import * as raw from './raw' ; import { normalizeSelect } from './utils' ; const getBaseUrl = ( params ) => `/spaces/${ params . spaceId }/webhook_definitions` ; const getWebhookCallBaseUrl = ( params ) => `/spaces/${ params . spaceId }/webhooks` ; const getWebhookUrl = ( params ) => `${ getBaseUrl ( params ) }/${ params . webhookDefinitionId }` ; const getWebhookCallUrl = ( params ) => `${ getWebhookCallBaseUrl ( params ) }/${ params . webhookDefinitionId }/calls` ; const getWebhookCallDetailsUrl = ( params ) => `${ getWebhookCallBaseUrl ( params ) }/${ params . webhookDefinitionId }/calls/${ params . callId }` ; const getWebhookHealthUrl = ( params ) => `${ getWebhookCallBaseUrl ( params ) }/${ params . webhookDefinitionId }/health` ; export const get = ( http , params ) => { return raw . get ( http , getWebhookUrl ( params ) ) ; } ; export const getManyCallDetails = ( http , params ) => { return raw . get ( http , getWebhookCallUrl ( params ) , { params : normalizeSelect ( params . query ) , } ) ; } ; export const getCallDetails = ( http , params ) => { return raw . get ( http , getWebhookCallDetailsUrl ( params ) ) ; } ; export const getHealthStatus = ( http , params ) => { return raw . get ( http , getWebhookHealthUrl ( params ) ) ; } ; export const getMany = ( http , params ) => { return raw . get ( http , getBaseUrl ( params ) , { params : normalizeSelect ( params . query ) , } ) ; } ; export const create = ( http , params , rawData , headers ? ) => { const data = copy ( rawData ) ; return raw . post < WebhookProps > ( http , getBaseUrl ( params ) , data , { headers } ) ; } ; export const createWithId = ( http , params , rawData , headers ? ) => { const data = copy ( rawData ) ; return raw . put < WebhookProps > ( http , getWebhookUrl ( params ) , data , { headers } ) ; } ; export const update = async ( http , params , rawData , headers ? ) => { const data = copy ( rawData ) ; delete data . sys ; return raw . put ( http , getWebhookUrl ( params ) , data , { headers : { 'X-Contentful-Version' : rawData . sys . version ?? 0 , ... headers , } , } ) ; } ; export const del = ( http , params ) => { return raw . del ( http , getWebhookUrl ( params ) ) ; } ;