UNPKG

contentful-management

Version:
54 lines (51 loc) 1.78 kB
import { toPlainObject, freezeSys } from 'contentful-sdk-core'; import copy from 'fast-copy'; import enhanceWithMethods from '../enhance-with-methods.js'; import { wrapCollection } from '../common-utils.js'; /** * @internal */ function createAppInstallationApi(makeRequest) { const getParams = (data) => ({ spaceId: data.sys.space.sys.id, environmentId: data.sys.environment.sys.id, appDefinitionId: data.sys.appDefinition.sys.id, }); return { update: function update() { const data = this.toPlainObject(); return makeRequest({ entityType: 'AppInstallation', action: 'upsert', params: getParams(data), headers: {}, payload: data, }).then((data) => wrapAppInstallation(makeRequest, data)); }, delete: function del() { const data = this.toPlainObject(); return makeRequest({ entityType: 'AppInstallation', action: 'delete', params: getParams(data), }); }, }; } /** * @internal * @param makeRequest - function to make requests via an adapter * @param data - Raw App Installation data * @returns Wrapped App installation data */ function wrapAppInstallation(makeRequest, data) { const appInstallation = toPlainObject(copy(data)); const appInstallationWithMethods = enhanceWithMethods(appInstallation, createAppInstallationApi(makeRequest)); return freezeSys(appInstallationWithMethods); } /** * @internal */ const wrapAppInstallationCollection = wrapCollection(wrapAppInstallation); export { wrapAppInstallation, wrapAppInstallationCollection }; //# sourceMappingURL=app-installation.js.map