import { IAuthenticationManager } from "@esri/arcgis-rest-request" ; import { IAddOrInviteContext , IAddOrInviteEmail , IAddOrInviteToTeamResult , IUserWithOrgType , IUserOrgRelationship , } from "./types" ; import { addOrInviteCommunityUsers , addOrInviteOrgUsers , addOrInviteWorldUsers , addOrInvitePartneredUsers , addOrInviteCollaborationCoordinators , groupUsersByOrgRelationship , } from "./utils" ; export param { string } groupId param { IUserWithOrgType [ ] } users param { IAuthenticationManager } primaryRO param { boolean } canAutoAddUser param { boolean } addUserAsGroupAdmin param { IAddOrInviteEmail } email return { IAddOrInviteToTeamResult } export async function addOrInviteUsersToTeam ( groupId , users , primaryRO , canAutoAddUser , addUserAsGroupAdmin , email ) { const parsedUsers = groupUsersByOrgRelationship ( users ) ; const inputParams = { groupId , primaryRO , allUsers : users , canAutoAddUser , addUserAsGroupAdmin , email , } ; const context = Object . assign ( inputParams , parsedUsers ) ; const result = { community : await addOrInviteCommunityUsers ( context ) , org : await addOrInviteOrgUsers ( context ) , world : await addOrInviteWorldUsers ( context ) , partnered : await addOrInvitePartneredUsers ( context ) , collaborationCoordinator : await addOrInviteCollaborationCoordinators ( context ) , notAdded : [ ] , notInvited : [ ] , notEmailed : [ ] , errors : [ ] , groupId , } ; result . notAdded = [ ... result . community . notAdded , ... result . org . notAdded , ... result . world . notAdded , ] ; result . notInvited = [ ... result . community . notInvited , ... result . org . notInvited , ... result . world . notInvited , ] ; result . notEmailed = [ ... result . community . notEmailed , ... result . org . notEmailed , ... result . world . notEmailed , ] ; result . errors = [ ... result . community . errors , ... result . org . errors , ... result . world . errors , ] ; return result ; }