import type { AxiosInstance } from 'contentful-sdk-core' ; import copy from 'fast-copy' ; import { SetOptional } from 'type-fest' ; import { CollectionProp , GetContentTypeParams , GetSpaceEnvironmentParams , QueryParams , } from '../../../common-types' ; import { ContentTypeProps , CreateContentTypeProps } from '../../../entities/content-type' ; import { RestEndpoint } from '../types' ; import * as raw from './raw' ; import { normalizeSelect } from './utils' ; const getBaseUrl = ( params ) => `/spaces/${ params . spaceId }/environments/${ params . environmentId }/content_types` ; const getContentTypeUrl = ( params ) => getBaseUrl ( params ) + `/${ params . contentTypeId }` ; export const get = ( http , params , headers ? ) => { return raw . get < ContentTypeProps > ( http , getContentTypeUrl ( params ) , { params : normalizeSelect ( params . query ) , headers , } ) ; } ; export const getMany = ( http , params , headers ? ) => { return raw . get < CollectionProp < ContentTypeProps > > ( http , getBaseUrl ( params ) , { params : params . query , headers , } ) ; } ; export const create = ( http , params , rawData , headers ? ) => { const data = copy ( rawData ) ; return raw . post < ContentTypeProps > ( http , getBaseUrl ( params ) , data , { headers } ) ; } ; export const createWithId = ( http , params , rawData , headers ? ) => { const data = copy ( rawData ) ; return raw . put < ContentTypeProps > ( http , getContentTypeUrl ( params ) , data , { headers } ) ; } ; export const update = ( http , params , rawData , headers ? ) => { const data = copy ( rawData ) ; delete data . sys ; return raw . put < ContentTypeProps > ( http , getContentTypeUrl ( params ) , data , { headers : { 'X-Contentful-Version' : rawData . sys . version ?? 0 , ... headers , } , } ) ; } ; export const del = ( http , params , headers ? ) => { return raw . del ( http , getContentTypeUrl ( params ) , { headers } ) ; } ; export const publish = ( http , params , rawData , headers ? ) => { return raw . put < ContentTypeProps > ( http , getContentTypeUrl ( params ) + '/published' , null , { headers : { 'X-Contentful-Version' : rawData . sys . version , ... headers , } , } ) ; } ; export const unpublish = ( http , params , headers ? ) => { return raw . del < ContentTypeProps > ( http , getContentTypeUrl ( params ) + '/published' , { headers } ) ; } ;