import type { AxiosInstance } from 'contentful-sdk-core' ; import copy from 'fast-copy' ; import { OpPatch } from 'json-patch' ; import { SetOptional } from 'type-fest' ; import { CollectionProp , GetSpaceEnvironmentParams , KeyValueMap , QueryParams , } from '../../../common-types' ; import { CreateEntryProps , EntryProps , EntryReferenceProps } from '../../../entities/entry' ; import { RestEndpoint } from '../types' ; import * as raw from './raw' ; import { normalizeSelect } from './utils' ; export const get = < T extends KeyValueMap = KeyValueMap > ( http , params , rawData ? , headers ? ) => { return raw . get < EntryProps < T > > ( http , `/spaces/${ params . spaceId }/environments/${ params . environmentId }/entries/${ params . entryId }` , { params : normalizeSelect ( params . query ) , headers : { ... headers } , } ) ; } ; export const getMany = < T extends KeyValueMap = KeyValueMap > ( http , params ) => { return raw . get < CollectionProp < EntryProps < T > > > ( http , `/spaces/${ params . spaceId }/environments/${ params . environmentId }/entries` , { params : normalizeSelect ( params . query ) , } ) ; } ; export const patch = < T extends KeyValueMap = KeyValueMap > ( http , params , data , headers ? ) => { return raw . patch < EntryProps < T > > ( http , `/spaces/${ params . spaceId }/environments/${ params . environmentId }/entries/${ params . entryId }` , data , { headers : { 'X-Contentful-Version' : params . version , 'Content-Type' : 'application/json-patch+json' , ... headers , } , } ) ; } ; export const update = < T extends KeyValueMap = KeyValueMap > ( http , params , rawData , headers ? ) => { const data = copy ( rawData ) ; delete data . sys ; return raw . put < EntryProps < T > > ( http , `/spaces/${ params . spaceId }/environments/${ params . environmentId }/entries/${ params . entryId }` , data , { headers : { 'X-Contentful-Version' : rawData . sys . version ?? 0 , ... headers , } , } ) ; } ; export const del = ( http , params ) => { return raw . del ( http , `/spaces/${ params . spaceId }/environments/${ params . environmentId }/entries/${ params . entryId }` ) ; } ; export const publish = < T extends KeyValueMap = KeyValueMap > ( http , params , rawData ) => { return raw . put < EntryProps < T > > ( http , `/spaces/${ params . spaceId }/environments/${ params . environmentId }/entries/${ params . entryId }/published` , null , { headers : { 'X-Contentful-Version' : rawData . sys . version , } , } ) ; } ; export const unpublish = < T extends KeyValueMap = KeyValueMap > ( http , params ) => { return raw . del < EntryProps < T > > ( http , `/spaces/${ params . spaceId }/environments/${ params . environmentId }/entries/${ params . entryId }/published` ) ; } ; export const archive = < T extends KeyValueMap = KeyValueMap > ( http , params ) => { return raw . put < EntryProps < T > > ( http , `/spaces/${ params . spaceId }/environments/${ params . environmentId }/entries/${ params . entryId }/archived` ) ; } ; export const unarchive = < T extends KeyValueMap = KeyValueMap > ( http , params ) => { return raw . del < EntryProps < T > > ( http , `/spaces/${ params . spaceId }/environments/${ params . environmentId }/entries/${ params . entryId }/archived` ) ; } ; export const create = < T extends KeyValueMap = KeyValueMap > ( http , params , rawData ) => { const data = copy ( rawData ) ; return raw . post < EntryProps < T > > ( http , `/spaces/${ params . spaceId }/environments/${ params . environmentId }/entries` , data , { headers : { 'X-Contentful-Content-Type' : params . contentTypeId , } , } ) ; } ; export const createWithId = < T extends KeyValueMap = KeyValueMap > ( http , params , rawData ) => { const data = copy ( rawData ) ; return raw . put < EntryProps < T > > ( http , `/spaces/${ params . spaceId }/environments/${ params . environmentId }/entries/${ params . entryId }` , data , { headers : { 'X-Contentful-Content-Type' : params . contentTypeId , } , } ) ; } ; export const references = ( http , params ) : Promise < EntryReferenceProps > => { const { spaceId , environmentId , entryId , maxDepth , include } = params ; const level = include || maxDepth || 2 ; return raw . get < EntryReferenceProps > ( http , `/spaces/${ spaceId }/environments/${ environmentId }/entries/${ entryId }/references?include=${ level }` ) ; } ;