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 { HubTeamType } from "./types" ; import { IGroup } from "@esri/arcgis-rest-types" ; param { ICreateHubTeamsOptions } createHubTeamsOptions export function createHubTeams ( opts ) { const { title , types , hubRequestOptions } = opts ; const product = getHubProduct ( hubRequestOptions . portalSelf ) ; const subscriptionType = getSubscriptionType ( hubRequestOptions . portalSelf ) ; const teamsToCreate = getUserCreatableTeams ( hubRequestOptions . portalSelf . user , product , hubRequestOptions . portalSelf . currentVersion , subscriptionType ) . filter ( ( g ) => { return types . indexOf ( g . config . type ) > - 1 ; } ) ; const culture = getCulture ( hubRequestOptions ) ; const locale = convertToWellKnownLocale ( culture ) ; return fetchHubTranslation ( locale , hubRequestOptions . portalSelf ) . then ( ( translations ) => { return _createTeamGroups ( title , teamsToCreate , translations , hubRequestOptions ) ; } ) . catch ( ( ex ) => { throw Error ( `Error in team-utils::createHubTeams ${ ex }` ) ; } ) ; }