import copy from 'fast-copy' ; import { freezeSys , toPlainObject } from 'contentful-sdk-core' ; import enhanceWithMethods from '../enhance-with-methods' ; import { wrapCollection } from '../common-utils' ; import { SysLink , MetaSysProps , DefaultElements , MakeRequest } from '../common-types' ; export type SpaceMembershipProps = { sys : MetaSysProps & { space : SysLink ; user : SysLink ; } ; user : SysLink ; admin : boolean ; roles : SysLink [ ] ; } ; export type CreateSpaceMembershipProps = Omit < SpaceMembershipProps , 'sys' | 'user' > & { email : string ; } ; export interface SpaceMembership extends SpaceMembershipProps , DefaultElements < SpaceMembershipProps > { return example delete ( ) : Promise < void > ; return example update ( ) : Promise < SpaceMembership > ; } private function createSpaceMembershipApi ( makeRequest ) { const getParams = ( data ) => ( { spaceId : data . sys . space . sys . id , spaceMembershipId : data . sys . id , } ) ; return { update : function update ( ) { const data = this . toPlainObject ( ) as SpaceMembershipProps ; return makeRequest ( { entityType : 'SpaceMembership' , action : 'update' , params : getParams ( data ) , payload : data , } ) . then ( ( data ) => wrapSpaceMembership ( makeRequest , data ) ) ; } , delete : function del ( ) { const data = this . toPlainObject ( ) as SpaceMembershipProps ; return makeRequest ( { entityType : 'SpaceMembership' , action : 'delete' , params : getParams ( data ) , } ) ; } , } ; } private param makeRequest param data return export function wrapSpaceMembership ( makeRequest , data ) { const spaceMembership = toPlainObject ( copy ( data ) ) ; const spaceMembershipWithMethods = enhanceWithMethods ( spaceMembership , createSpaceMembershipApi ( makeRequest ) ) ; return freezeSys ( spaceMembershipWithMethods ) ; } private export const wrapSpaceMembershipCollection = wrapCollection ( wrapSpaceMembership ) ;