contentful-management
Version:
Client for Contentful's Content Management API
65 lines (62 loc) • 2.11 kB
JavaScript
import { toPlainObject, freezeSys } from 'contentful-sdk-core';
import enhanceWithMethods from '../enhance-with-methods.js';
import copy from 'fast-copy';
import { wrapCursorPaginatedCollection } from '../common-utils.js';
var ScopeValues;
(function (ScopeValues) {
ScopeValues["Read"] = "content_management_read";
ScopeValues["Manage"] = "content_management_manage";
})(ScopeValues || (ScopeValues = {}));
/**
* @internal
*/
function createOAuthApplicationApi(makeRequest, userId) {
const getParams = (data) => ({
userId,
oauthApplicationId: data.sys.id,
});
return {
/**
* Updates an OAuth application
* @returns Promise for the updated OAuth application
*/
async update() {
const raw = this.toPlainObject();
return makeRequest({
entityType: 'OAuthApplication',
action: 'update',
params: getParams(raw),
payload: raw,
});
},
/**
* Deletes an OAuth application
* @returns Promise for the deleted OAuth application
*/
async delete() {
const raw = this.toPlainObject();
return makeRequest({
entityType: 'OAuthApplication',
action: 'delete',
params: getParams(raw),
});
},
};
}
/**
* @internal
* @param makeRequest - function to make requests via an adapter
* @param data - Raw OAuth application data
* @returns Wrapped OAuth application data
*/
function wrapOAuthApplication(makeRequest, data, userId) {
const oauthApplication = toPlainObject(copy(data));
const oauthApplicationWithMethods = enhanceWithMethods(oauthApplication, createOAuthApplicationApi(makeRequest, userId));
return freezeSys(oauthApplicationWithMethods);
}
/**
* @internal
*/
const wrapOAuthApplicationCollection = wrapCursorPaginatedCollection(wrapOAuthApplication);
export { ScopeValues, wrapOAuthApplication, wrapOAuthApplicationCollection };
//# sourceMappingURL=oauth-application.js.map