import { HubTeamType , TEAMTYPES } from "./types" ; import { IHubRequestOptions , getHubProduct , getCulture , convertToWellKnownLocale , fetchHubTranslation , getSubscriptionType , } from "@esri/hub-common" ; import { getUserCreatableTeams } from "./utils/get-user-creatable-teams" ; import { _createTeamGroups } from "./utils/_create-team-groups" ; import { IGroup } from "@esri/arcgis-rest-types" ; param { ICreateHubTeamOptions } createHubTeamOptions export function createHubTeam ( opts ) { const { title , type , props , hubRequestOptions } = opts ; if ( TEAMTYPES . indexOf ( type ) === - 1 ) { throw new Error ( `createHubTeam was passed ${ type } which is not a valid type of team. Please send one of: ${ TEAMTYPES . join ( "," ) }` ) ; } const portalSelf = hubRequestOptions . portalSelf ; const product = getHubProduct ( portalSelf ) ; const subscriptionType = getSubscriptionType ( portalSelf ) ; const groupsToCreate = getUserCreatableTeams ( portalSelf . user , product , portalSelf . currentVersion , subscriptionType ) . filter ( ( g ) => { return g . config . type === type ; } ) . map ( ( grp ) => { if ( grp . config . type === "team" ) { return Object . assign ( { } , grp , props ) ; } else { return grp ; } } ) ; const culture = getCulture ( hubRequestOptions ) ; const locale = convertToWellKnownLocale ( culture ) ; return fetchHubTranslation ( locale , hubRequestOptions . portalSelf ) . then ( ( translations ) => { return _createTeamGroups ( title , groupsToCreate , translations , hubRequestOptions ) ; } ) . catch ( ( ex ) => { throw Error ( `Error in team-utils::createHubTeam ${ ex }` ) ; } ) ; }