import { IModel , IHubRequestOptions , objectToJsonBlob , getProp , buildDraft , } from "@esri/hub-common" ; import { _includeListFromItemType } from "./_include-list-from-item-type" ; import { deleteDraft } from "./delete-draft" ; import { addItemResource } from "@esri/arcgis-rest-portal" ; param { * } siteOrPageModel param { * } hubRequestOptions export function saveDraft ( siteOrPageModel , hubRequestOptions ) { const includeList = _includeListFromItemType ( siteOrPageModel . item ) ; const draft = buildDraft ( siteOrPageModel , includeList ) ; const draftBlob = objectToJsonBlob ( draft ) ; const draftName = `draft-${ Date . now ( ) }.json` ; const itemId = getProp ( siteOrPageModel , "item.id" ) ; return deleteDraft ( siteOrPageModel , hubRequestOptions ) . then ( ( _ ) => addItemResource ( { id : itemId , owner : getProp ( siteOrPageModel , "item.owner" ) , resource : draftBlob , name : draftName , private : false , portal : hubRequestOptions . portal , authentication : hubRequestOptions . authentication , } ) ) . then ( ( _ ) => draft ) ; }