import { IModel , getModel , mapBy , getWithDefault , failSafe , unprotectModel , } from "@esri/hub-common" ; import { unlinkSiteAndPage } from "../unlink-site-and-page" ; import { IUserItemOptions , removeItem } from "@esri/arcgis-rest-portal" ; import { IUserRequestOptions } from "@esri/arcgis-rest-auth" ; param { Object | String } idOrModel param { IRequestOptions } requestOptions export function removePage ( idOrModel , requestOptions ) { let modelPromise = Promise . resolve ( idOrModel ) ; if ( typeof idOrModel === "string" ) { modelPromise = getModel ( idOrModel , requestOptions ) ; } let pageModel ; return modelPromise . then ( ( model ) => { pageModel = model as IModel ; const linkedSites = mapBy ( "id" , getWithDefault ( pageModel , "data.values.sites" , [ ] ) ) ; const failSafeUnlink = failSafe ( unlinkSiteAndPage ) ; return Promise . all ( linkedSites . map ( ( siteId ) => { const opts = Object . assign ( { pageModel , siteId , } , requestOptions ) ; return failSafeUnlink ( opts ) ; } ) ) ; } ) . then ( ( ) => { return unprotectModel ( pageModel , requestOptions ) ; } ) . then ( ( ) => { const opts = Object . assign ( { id : pageModel . item . id } , requestOptions ) ; return removeItem ( opts ) ; } ) ; }