contentful-management
Version:
Client for Contentful's Content Management API
55 lines (52 loc) • 1.65 kB
JavaScript
import { toPlainObject, freezeSys } from 'contentful-sdk-core';
import copy from 'fast-copy';
import { wrapCollection } from '../common-utils.js';
import enhanceWithMethods from '../enhance-with-methods.js';
/**
* @internal
*/
function createApiKeyApi(makeRequest) {
const getParams = (data) => ({
spaceId: data.sys.space?.sys.id ?? '',
apiKeyId: data.sys.id,
});
return {
update: function update() {
const self = this;
return makeRequest({
entityType: 'ApiKey',
action: 'update',
params: getParams(self),
payload: self,
headers: {},
}).then((data) => wrapApiKey(makeRequest, data));
},
delete: function del() {
const self = this;
return makeRequest({
entityType: 'ApiKey',
action: 'delete',
params: getParams(self),
});
},
};
}
/**
* @internal
* @param makeRequest - function to make requests via an adapter
* @param data - Raw api key data
*/
function wrapApiKey(makeRequest, data) {
const apiKey = toPlainObject(copy(data));
const apiKeyWithMethods = enhanceWithMethods(apiKey, createApiKeyApi(makeRequest));
return freezeSys(apiKeyWithMethods);
}
/**
* @internal
* @param makeRequest - function to make requests via an adapter
* @param data - Raw api key collection data
* @returns Wrapped api key collection data
*/
const wrapApiKeyCollection = wrapCollection(wrapApiKey);
export { wrapApiKey, wrapApiKeyCollection };
//# sourceMappingURL=api-key.js.map