UNPKG

contentful-management

Version:
115 lines (112 loc) 4.73 kB
import copy from 'fast-copy'; import { put, post, del as del$1, get as get$2, patch as patch$2 } from './raw.js'; import { create as create$1, createWithId as createWithId$1, get as get$1, getMany as getMany$1, patch as patch$1, update as update$1 } from './release-entry.js'; import { normalizeSelect } from './utils.js'; const get = (http, params, rawData, headers) => { if (params.releaseId) { return get$1(http, params); } return get$2(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/entries/${params.entryId}`, { params: normalizeSelect(params.query), headers: { ...headers }, }); }; const getPublished = (http, params, rawData, headers) => { return get$2(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/public/entries`, { params: normalizeSelect(params.query), headers: { ...headers }, }); }; const getMany = (http, params, rawData, headers) => { if (params.releaseId) { return getMany$1(http, params); } return get$2(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/entries`, { params: normalizeSelect(params.query), headers: { ...headers }, }); }; const patch = (http, params, data, headers) => { if (params.releaseId) { return patch$1(http, params, data, headers ?? {}); } return patch$2(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/entries/${params.entryId}`, data, { headers: { 'X-Contentful-Version': params.version, 'Content-Type': 'application/json-patch+json', ...headers, }, }); }; const update = (http, params, rawData, headers) => { if (params.releaseId) { return update$1(http, params, rawData, headers ?? {}); } const data = copy(rawData); delete data.sys; return put(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/entries/${params.entryId}`, data, { headers: { 'X-Contentful-Version': rawData.sys.version ?? 0, ...headers, }, }); }; const del = (http, params) => { return del$1(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/entries/${params.entryId}`); }; const publish = (http, params, rawData) => { const payload = params.locales?.length ? { add: { fields: { '*': params.locales } } } : null; return put(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/entries/${params.entryId}/published`, payload, { headers: { 'X-Contentful-Version': rawData.sys.version, }, }); }; const unpublish = (http, params, rawData) => { if (params.locales?.length) { const payload = { remove: { fields: { '*': params.locales } } }; return put(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/entries/${params.entryId}/published`, payload, { headers: { 'X-Contentful-Version': rawData?.sys.version, }, }); } else { return del$1(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/entries/${params.entryId}/published`); } }; const archive = (http, params) => { return put(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/entries/${params.entryId}/archived`); }; const unarchive = (http, params) => { return del$1(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/entries/${params.entryId}/archived`); }; const create = (http, params, rawData) => { if (params.releaseId) { return create$1(http, params, rawData, {}); } const data = copy(rawData); return post(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/entries`, data, { headers: { 'X-Contentful-Content-Type': params.contentTypeId, }, }); }; const createWithId = (http, params, rawData) => { if (params.releaseId) { return createWithId$1(http, params, rawData, {}); } const data = copy(rawData); return put(http, `/spaces/${params.spaceId}/environments/${params.environmentId}/entries/${params.entryId}`, data, { headers: { 'X-Contentful-Content-Type': params.contentTypeId, }, }); }; const references = (http, params) => { const { spaceId, environmentId, entryId, include } = params; const level = include || 2; return get$2(http, `/spaces/${spaceId}/environments/${environmentId}/entries/${entryId}/references?include=${level}`); }; export { archive, create, createWithId, del, get, getMany, getPublished, patch, publish, references, unarchive, unpublish, update }; //# sourceMappingURL=entry.js.map