import { request } from "@esri/arcgis-rest-request" ; import { IGroup } from "@esri/arcgis-rest-types" ; import { IUserRequestOptions } from "@esri/arcgis-rest-auth" ; import { getPortalUrl } from "../util/get-portal-url" ; export interface IInvitation { id : string ; targetType : string ; targetId : string ; received : number ; accepted : boolean ; mustApprove : boolean ; email : string ; role : string ; type : string ; dateAccepted : number ; expiration : number ; created : number ; username : string ; fromUsername : { username : string ; fullname ? : string ; } ; group ? : IGroup ; groupId ? : string ; } export interface IInvitationResult { userInvitations : IInvitation [ ] ; } param requestOptions returns export function getUserInvitations ( requestOptions ) { let options = { httpMethod : "GET" } as IUserRequestOptions ; const username = encodeURIComponent ( requestOptions . authentication . username ) ; const portalUrl = getPortalUrl ( requestOptions ) ; const url = `${ portalUrl }/community/users/${ username }/invitations` ; options = { ... requestOptions , ... options } ; return request ( url , options ) ; } export interface IGetUserInvitationOptions extends IUserRequestOptions { invitationId : string ; } param requestOptions returns export function getUserInvitation ( requestOptions ) { const username = encodeURIComponent ( requestOptions . authentication . username ) ; const portalUrl = getPortalUrl ( requestOptions ) ; const url = `${ portalUrl }/community/users/${ username }/invitations/${ requestOptions . invitationId }` ; let options = { httpMethod : "GET" } as IGetUserInvitationOptions ; options = { ... requestOptions , ... options } ; return request ( url , options ) ; } param requestOptions returns export function acceptInvitation ( requestOptions ) { const username = encodeURIComponent ( requestOptions . authentication . username ) ; const portalUrl = getPortalUrl ( requestOptions ) ; const url = `${ portalUrl }/community/users/${ username }/invitations/${ requestOptions . invitationId }/accept` ; const options = { ... requestOptions } ; return request ( url , options ) ; } param requestOptions returns export function declineInvitation ( requestOptions ) { const username = encodeURIComponent ( requestOptions . authentication . username ) ; const portalUrl = getPortalUrl ( requestOptions ) ; const url = `${ portalUrl }/community/users/${ username }/invitations/${ requestOptions . invitationId }/decline` ; const options = { ... requestOptions } ; return request ( url , options ) ; }