contentful-management
Version:
Client for Contentful's Content Management API
38 lines (35 loc) • 1.1 kB
JavaScript
import copy from 'fast-copy';
import { toPlainObject, freezeSys } from 'contentful-sdk-core';
import enhanceWithMethods from '../enhance-with-methods.js';
/**
* @internal
*/
function createUploadApi(makeRequest) {
return {
delete: async function del() {
const raw = this.toPlainObject();
await makeRequest({
entityType: 'Upload',
action: 'delete',
params: {
spaceId: raw.sys.space.sys.id,
environmentId: raw.sys.id,
uploadId: raw.sys.id,
},
});
},
};
}
/**
* @internal
* @param {function} makeRequest - function to make requests via an adapter
* @param {object} data - Raw upload data
* @returns {Upload} Wrapped upload data
*/
function wrapUpload(makeRequest, data) {
const upload = toPlainObject(copy(data));
const uploadWithMethods = enhanceWithMethods(upload, createUploadApi(makeRequest));
return freezeSys(uploadWithMethods);
}
export { wrapUpload };
//# sourceMappingURL=upload.js.map