import { getProp , IDraft , IHubRequestOptions } from "@esri/hub-common" ; import { getItemResource } from "@esri/arcgis-rest-portal" ; import { _getMostRecentDraftName } from "./_get-most-recent-draft-name" ; import { upgradeDraftSchema } from "./upgrade-draft-schema" ; function isSiteDraft ( draft ) { return ( getProp ( draft , "data.values.capabilities" ) !== undefined && getProp ( draft , "data.values.theme" ) !== undefined ) ; } param { * } siteOrPageId param { * } hubRequestOptions export function fetchDraft ( siteOrPageId , hubRequestOptions ) { return _getMostRecentDraftName ( siteOrPageId , hubRequestOptions ) . then ( draftResourceName => { let ret = null ; if ( draftResourceName ) { ret = getItemResource ( siteOrPageId , { fileName : draftResourceName , readAs : "json" , authentication : hubRequestOptions . authentication , portal : hubRequestOptions . portal } ) ; } return ret ; } ) . then ( ( draft ) => { if ( draft && isSiteDraft ( draft ) ) { draft = upgradeDraftSchema ( draft ) ; } return draft ; } ) ; }