import { IModel , IHubRequestOptions , failSafe } from "@esri/hub-common" ; import { shareItemWithGroup , ISharingResponse } from "@esri/arcgis-rest-portal" ; import { _getSecondPassSharingOptions } from "./_get-second-pass-sharing-options" ; import { _getSharingEligibleModels } from "./_get-sharing-eligible-models" ; param { object } siteModel param { Array } solutionModels param { IHubRequestOptions } hubRequestOptions private export function _shareItemsToSiteGroups ( siteModel , solutionModels , hubRequestOptions ) { console . info ( `DEPRECATED: _shareItemsToSiteGroups will be removed at v10.0.0. Use shareItemsToSiteGroups instead.` ) ; return shareItemsToSiteGroups ( siteModel , solutionModels , hubRequestOptions ) ; } param { object } siteModel param { Array } solutionModels param { IHubRequestOptions } hubRequestOptions exported export function shareItemsToSiteGroups ( siteModel , solutionModels , hubRequestOptions ) { const failSafeShare = failSafe ( shareItemWithGroup , { success : true } ) ; const groupsToShareTo = _getSecondPassSharingOptions ( siteModel ) ; return _getSharingEligibleModels ( siteModel , solutionModels , hubRequestOptions ) . then ( ( eligibleModels ) => Promise . all ( eligibleModels . reduce ( ( acc , m ) => { const itemSharePromises = groupsToShareTo . map ( ( g ) => { const opts = { id : m . item . id , groupId : g . id , confirmItemControl : g . confirmItemControl , authentication : hubRequestOptions . authentication , } ; return failSafeShare ( opts ) as Promise < ISharingResponse > ; } ) ; return acc . concat ( itemSharePromises ) ; } , [ ] ) ) ) ; }