UNPKG

contentful-management

Version:
62 lines (59 loc) 2.2 kB
import copy from 'fast-copy'; import { normalizeCursorPaginationResponse } from '../../../common-utils.mjs'; import { post, put, del as del$1, get as get$1 } from './raw.mjs'; import { normalizeSelect } from './utils.mjs'; const getBaseUrl = (params) => `/spaces/${params.spaceId}/environments/${params.environmentId}/content_types`; const getContentTypeUrl = (params) => getBaseUrl(params) + `/${params.contentTypeId}`; const get = (http, params, headers) => { return get$1(http, getContentTypeUrl(params), { params: normalizeSelect(params.query), headers, }); }; const getMany = (http, params, headers) => { return get$1(http, getBaseUrl(params), { params: params.query, headers, }); }; const getManyWithCursor = (http, params, headers) => { return get$1(http, getBaseUrl(params), { params: { cursor: true, ...(params.query ?? {}) }, headers, }) .then(normalizeCursorPaginationResponse); }; const create = (http, params, rawData, headers) => { const data = copy(rawData); return post(http, getBaseUrl(params), data, { headers }); }; const createWithId = (http, params, rawData, headers) => { const data = copy(rawData); return put(http, getContentTypeUrl(params), data, { headers }); }; const update = (http, params, rawData, headers) => { const data = copy(rawData); delete data.sys; return put(http, getContentTypeUrl(params), data, { headers: { 'X-Contentful-Version': rawData.sys.version ?? 0, ...headers, }, }); }; const del = (http, params, headers) => { return del$1(http, getContentTypeUrl(params), { headers }); }; const publish = (http, params, rawData, headers) => { return put(http, getContentTypeUrl(params) + '/published', null, { headers: { 'X-Contentful-Version': rawData.sys.version, ...headers, }, }); }; const unpublish = (http, params, headers) => { return del$1(http, getContentTypeUrl(params) + '/published', { headers }); }; export { create, createWithId, del, get, getMany, getManyWithCursor, publish, unpublish, update }; //# sourceMappingURL=content-type.mjs.map