import { BaseResource , BaseResourceOptions } from '@gitbeaker/requester-utils' ; import { BaseRequestOptions , endpoint , PaginatedRequestOptions , RequestHelper , Sudo , } from '../infrastructure' ; import { AccessLevel } from './ResourceAccessRequests' ; export interface IncludeInherited { includeInherited ? : boolean ; } export interface MemberSchema extends Record < string , unknown > { id : number ; username : string ; name : string ; state : string ; avatar_url : string ; web_url : string ; expires_at : string ; access_level : AccessLevel ; email : string ; group_saml_identity : { extern_uid : string ; provider : string ; saml_provider_id : number ; } ; } export class ResourceMembers < C extends boolean = false > extends BaseResource < C > { constructor ( resourceType , options ) { super ( { prefixUrl : resourceType , ... options } ) ; } add ( resourceId , userId , accessLevel , options ? ) { return RequestHelper . post < MemberSchema > ( ) ( this , endpoint `${ resourceId }/members` , { userId : String ( userId ) , accessLevel , ... options , } ) ; } all ( resourceId , { includeInherited , ... options } = { } ) { const rId = encodeURIComponent ( resourceId ) ; const url = [ rId , 'members' ] ; if ( includeInherited ) url . push ( 'all' ) ; return RequestHelper . get < MemberSchema [ ] > ( ) ( this , url . join ( '/' ) , options ) ; } edit ( resourceId , userId , accessLevel , options ? ) { return RequestHelper . put < MemberSchema > ( ) ( this , endpoint `${ resourceId }/members/${ userId }` , { accessLevel , ... options , } ) ; } show ( resourceId , userId , { includeInherited , ... options } = { } ) { const [ rId , uId ] = [ resourceId , userId ] . map ( encodeURIComponent ) ; const url = [ rId , 'members' ] ; if ( includeInherited ) url . push ( 'all' ) ; url . push ( uId ) ; return RequestHelper . get < MemberSchema > ( ) ( this , url . join ( '/' ) , options as Record < string , unknown > ) ; } remove ( resourceId , userId , options ? ) { return RequestHelper . del ( ) ( this , endpoint `${ resourceId }/members/${ userId }` , options ) ; } }