contentful-management
Version:
Client for Contentful's Content Management API
54 lines (51 loc) • 1.86 kB
JavaScript
import copy from 'fast-copy';
import { post, put, del as del$1, get as get$1 } from './raw.js';
import { normalizeSelect } from './utils.js';
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 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, publish, unpublish, update };
//# sourceMappingURL=content-type.js.map