import { IModelTemplate , IHubRequestOptions , IInitiativeModelTemplate , without , interpolate , IInitiativeModel , getProp , IModel } from "@esri/hub-common" ; import { getInitiativeTemplate , addInitiative } from "@esri/hub-initiatives" ; import { shareItemWithGroup } from "@esri/arcgis-rest-portal" ; param { object } siteTemplate param { object } settings param { object } transforms param { IHubRequestOptions } private export function _createSiteInitiative ( siteTemplate , settings , transforms , hubRequestOptions ) { const cache = { } ; return getInitiativeTemplate ( siteTemplate , hubRequestOptions ) . then ( ( initiativeTemplate ) => { initiativeTemplate . item . url = settings . solution . url ; initiativeTemplate . item . title = settings . solution . title ; initiativeTemplate . item . owner = hubRequestOptions . authentication . username ; initiativeTemplate . item . typeKeywords = without ( initiativeTemplate . item . typeKeywords , "Hub Initiative Template" ) ; initiativeTemplate . item . type = "Hub Initiative" ; Object . assign ( initiativeTemplate . item . properties , settings . teams ) ; const initiativeModel = interpolate ( initiativeTemplate , settings , transforms ) ; return addInitiative ( initiativeModel , hubRequestOptions ) ; } ) . then ( ( model ) => { cache . model = model ; let sharePrms = Promise . resolve ( { success : true } ) ; const collabGroupId = getProp ( settings , "teams.collaborationGroupId" ) ; if ( collabGroupId ) { sharePrms = shareItemWithGroup ( { id : model . item . id , groupId : collabGroupId , authentication : hubRequestOptions . authentication , confirmItemControl : true } ) ; } return sharePrms ; } ) . then ( ( _ ) => { return cache . model ; } ) . catch ( ( ex ) => { throw Error ( `site-utils::_createSiteInitiative Error ${ ex }` ) ; } ) ; }