import { IModel , getModelFromOptions , withoutByProp , getWithDefault , maybePush , getProp , failSafeUpdate , failSafe , unshareItemFromGroups } from "@esri/hub-common" ; import { UserSession } from "@esri/arcgis-rest-auth" ; param { IUnlinkRequestOptions } unlinkRequestOptions export function unlinkSiteAndPage ( unlinkRequestOptions ) { let unshareGroups = [ ] ; const promises = [ ] ; let pageModel ; let siteModel ; const requestOptions = { authentication : unlinkRequestOptions . authentication } ; return Promise . all ( [ getModelFromOptions ( "page" , unlinkRequestOptions ) , getModelFromOptions ( "site" , unlinkRequestOptions ) ] ) . then ( models => { [ pageModel , siteModel ] = models ; if ( ! siteModel . isMissing ) { const pages = getWithDefault ( siteModel , "data.values.pages" , [ ] ) ; siteModel . data . values . pages = withoutByProp ( "id" , pageModel . item . id , pages ) ; unshareGroups = maybePush ( getProp ( siteModel , "item.properties.collaborationGroupId" ) , unshareGroups ) ; unshareGroups = maybePush ( getProp ( siteModel , "item.properties.contentGroupId" ) , unshareGroups ) ; promises . push ( failSafeUpdate ( siteModel , requestOptions ) ) ; } if ( ! pageModel . isMissing ) { const sites = getWithDefault ( pageModel , "data.values.sites" , [ ] ) ; pageModel . data . values . sites = withoutByProp ( "id" , siteModel . item . id , sites ) ; promises . push ( failSafeUpdate ( pageModel , requestOptions ) ) ; const failSafeUnshare = failSafe ( unshareItemFromGroups ) ; promises . push ( failSafeUnshare ( pageModel . item . id , unshareGroups , requestOptions ) ) ; } return Promise . all ( promises ) ; } ) . then ( ( ) => { return { pageModel , siteModel } ; } ) ; }