UNPKG

contentful-management

Version:
40 lines (38 loc) 1.11 kB
import copy from 'fast-copy'; import { toPlainObject } from 'contentful-sdk-core'; import enhanceWithMethods from '../enhance-with-methods'; import { wrapCollection } from '../common-utils'; function createKeyApi(makeRequest) { const getParams = data => ({ organizationId: data.sys.organization.sys.id, appDefinitionId: data.sys.appDefinition.sys.id, fingerprint: data.sys.id }); return { delete: function del() { const self = this; return makeRequest({ entityType: 'AppKey', action: 'delete', params: getParams(self) }); } }; } /** * @private * @param http - HTTP client instance * @param data - Raw AppKey data * @return Wrapped AppKey data */ export function wrapAppKey(makeRequest, data) { const key = toPlainObject(copy(data)); return enhanceWithMethods(key, createKeyApi(makeRequest)); } /** * @private * @param makeRequest - function to make requests via an adapter * @param data - Raw App Key collection data * @return Wrapped App Key collection data */ export const wrapAppKeyCollection = wrapCollection(wrapAppKey);