contentful-management
Version:
Client for Contentful's Content Management API
60 lines (57 loc) • 2.12 kB
JavaScript
import copy from 'fast-copy';
import { put, post, del as del$1, get as get$1 } from './raw.js';
const getBaseUrl = (params) => `/spaces/${params.spaceId}/environments/${params.environmentId}/experience_fragments/${params.experienceFragmentId}/optimization_variants`;
const getVariantUrl = (params) => `${getBaseUrl(params)}/${params.variantId}`;
const actionHeaders = (version, headers) => ({
'X-Contentful-Version': version,
...headers,
});
const getMany = (http, params, headers) => {
return get$1(http, getBaseUrl(params), {
params: params.query,
headers,
});
};
const get = (http, params, headers) => {
return get$1(http, getVariantUrl(params), { headers });
};
const create = (http, params, rawData, headers) => {
const data = copy(rawData);
return post(http, getBaseUrl(params), data, { headers });
};
const upsert = (http, params, rawData, headers) => {
const { sys, ...body } = copy(rawData);
return put(http, getVariantUrl(params), body, {
headers: {
...(sys?.version !== undefined && {
'X-Contentful-Version': sys.version,
}),
...headers,
},
});
};
const del = (http, params) => {
return del$1(http, getVariantUrl(params));
};
const publish = (http, params, headers) => {
return put(http, `${getVariantUrl(params)}/published`, null, {
headers: actionHeaders(params.version, headers),
});
};
const unpublish = (http, params, headers) => {
return del$1(http, `${getVariantUrl(params)}/published`, {
headers: actionHeaders(params.version, headers),
});
};
const archive = (http, params, headers) => {
return put(http, `${getVariantUrl(params)}/archived`, null, {
headers: actionHeaders(params.version, headers),
});
};
const unarchive = (http, params, headers) => {
return del$1(http, `${getVariantUrl(params)}/archived`, {
headers: actionHeaders(params.version, headers),
});
};
export { archive, create, del, get, getMany, publish, unarchive, unpublish, upsert };
//# sourceMappingURL=experience-fragment-variant.js.map