UNPKG

contentful-management

Version:
62 lines (60 loc) 1.82 kB
import { freezeSys, toPlainObject } from 'contentful-sdk-core'; import enhanceWithMethods from '../enhance-with-methods'; import copy from 'fast-copy'; import { wrapCursorPaginatedCollection } from '../common-utils'; export let ScopeValues = /*#__PURE__*/function (ScopeValues) { ScopeValues["Read"] = "content_management_read"; ScopeValues["Manage"] = "content_management_manage"; return ScopeValues; }({}); /** * @private */ function createOAuthApplicationApi(makeRequest, userId) { const getParams = data => ({ userId, oauthApplicationId: data.sys.id }); return { /** * Updates an OAuth application * @return 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 * @return Promise for the deleted OAuth application */ async delete() { const raw = this.toPlainObject(); return makeRequest({ entityType: 'OAuthApplication', action: 'delete', params: getParams(raw) }); } }; } /** * @private * @param makeRequest - function to make requests via an adapter * @param data - Raw OAuth application data * @return Wrapped OAuth application data */ export function wrapOAuthApplication(makeRequest, data, userId) { const oauthApplication = toPlainObject(copy(data)); const oauthApplicationWithMethods = enhanceWithMethods(oauthApplication, createOAuthApplicationApi(makeRequest, userId)); return freezeSys(oauthApplicationWithMethods); } /** * @private */ export const wrapOAuthApplicationCollection = wrapCursorPaginatedCollection(wrapOAuthApplication);