UNPKG

contentful-management

Version:
55 lines (52 loc) 1.52 kB
import { toPlainObject, freezeSys } from 'contentful-sdk-core'; import copy from 'fast-copy'; import { wrapCollection } from '../common-utils.mjs'; import enhanceWithMethods from '../enhance-with-methods.mjs'; /** * @internal */ function createTagApi(makeRequest) { const getParams = (tag) => ({ spaceId: tag.sys.space.sys.id, environmentId: tag.sys.environment.sys.id, tagId: tag.sys.id, }); return { update: function () { const raw = this.toPlainObject(); return makeRequest({ entityType: 'Tag', action: 'update', params: getParams(raw), payload: raw, }).then((data) => wrapTag(makeRequest, data)); }, delete: function () { const raw = this.toPlainObject(); return makeRequest({ entityType: 'Tag', action: 'delete', params: { ...getParams(raw), version: raw.sys.version, }, }).then(() => { // noop }); }, }; } /** * @internal */ function wrapTag(makeRequest, data) { const tag = toPlainObject(copy(data)); const tagWithMethods = enhanceWithMethods(tag, createTagApi(makeRequest)); return freezeSys(tagWithMethods); } /** * @internal */ const wrapTagCollection = wrapCollection(wrapTag); export { wrapTag, wrapTagCollection }; //# sourceMappingURL=tag.mjs.map