import { IModel , IHubUserRequestOptions , getModel , _unprotectAndRemoveItem , failSafe , } from "@esri/hub-common" ; import { unlinkPagesFromSite } from "./unlink-pages-from-site" ; import { _removeSiteGroups } from "./_remove-site-groups" ; import { _removeParentInitiative } from "./_remove-parent-initiative" ; import { _removeSiteDomains } from "./_remove-site-domains" ; import { _removeSiteFromIndex } from "./_remove-site-from-index" ; param { string param { IHubUserRequestOptions } hubRequestOptions export function removeSite ( idOrModel , hubRequestOptions ) { let modelPromise ; if ( typeof idOrModel === "string" ) { modelPromise = getModel ( idOrModel , hubRequestOptions ) ; } else { modelPromise = Promise . resolve ( idOrModel ) ; } let siteModel ; return modelPromise . then ( ( model ) => { siteModel = model ; return unlinkPagesFromSite ( siteModel , hubRequestOptions ) ; } ) . then ( ( ) => { const opts = Object . assign ( { id : siteModel . item . id , owner : siteModel . item . owner } , hubRequestOptions ) ; return _unprotectAndRemoveItem ( opts ) ; } ) . then ( ( ) => { return _removeSiteGroups ( siteModel , hubRequestOptions ) ; } ) . then ( ( ) => { return _removeParentInitiative ( siteModel , hubRequestOptions ) ; } ) . then ( ( ) => { return _removeSiteDomains ( siteModel . item . id , hubRequestOptions ) ; } ) . then ( ( ) => { return failSafe ( _removeSiteFromIndex , { success : true } ) ( siteModel , hubRequestOptions ) ; } ) . catch ( ( err ) => { throw Error ( `removeSite: Error removing site: ${ err }` ) ; } ) ; }