import copy from 'fast-copy' ; import { freezeSys , toPlainObject } from 'contentful-sdk-core' ; import enhanceWithMethods from '../enhance-with-methods' ; import { wrapCollection } from '../common-utils' ; import { DefaultElements , BasicMetaSysProps , SysLink , MakeRequest } from '../common-types' ; export type ActionType = 'read' | 'create' | 'update' | 'delete' | 'publish' | 'unpublish' | 'archive' | 'unarchive' ; type ConditionType = 'and' | 'or' | 'not' | 'equals' ; export type ConstraintType = { [ key in ConditionType ] ? : ConstraintType [ ] | any ; } ; export type RoleProps = { sys : BasicMetaSysProps & { space : SysLink ; } ; name : string ; description ? : string ; /**
     * Permissions for application sections
     */ permissions : { ContentDelivery : string [ ] | string ; ContentModel : string [ ] ; EnvironmentAliases : string [ ] | string ; Environments : string [ ] | string ; Settings : string [ ] | string ; Tags : string [ ] | string ; } ; policies : { effect : string ; actions : ActionType [ ] | 'all' ; constraint : ConstraintType ; } [ ] ; } ; export type CreateRoleProps = Omit < RoleProps , 'sys' > ; export interface Role extends RoleProps , DefaultElements < RoleProps > { memberof func return { Promise } example delete ( ) : Promise < void > ; return example update ( ) : Promise < Role > ; } private function createRoleApi ( makeRequest ) { const getParams = ( data ) => ( { spaceId : data . sys . space . sys . id , roleId : data . sys . id , } ) ; return { update : function update ( ) { const data = this . toPlainObject ( ) as RoleProps ; return makeRequest ( { entityType : 'Role' , action : 'update' , params : getParams ( data ) , payload : data , } ) . then ( ( data ) => wrapRole ( makeRequest , data ) ) ; } , delete : function del ( ) { const data = this . toPlainObject ( ) as RoleProps ; return makeRequest ( { entityType : 'Role' , action : 'delete' , params : getParams ( data ) , } ) ; } , } ; } private param makeRequest param data return export function wrapRole ( makeRequest , data ) { const role = toPlainObject ( copy ( data ) ) ; const roleWithMethods = enhanceWithMethods ( role , createRoleApi ( makeRequest ) ) ; return freezeSys ( roleWithMethods ) ; } private export const wrapRoleCollection = wrapCollection ( wrapRole ) ;