import { request , appendCustomParams } from "@esri/arcgis-rest-request" ; import { IItemAdd } from "@esri/arcgis-rest-types" ; import { getPortalUrl } from "../util/get-portal-url" ; import { IUserItemOptions , IUpdateItemResponse , determineOwner , IItemPartOptions , serializeItem } from "./helpers" ; export interface ICommitItemOptions extends IUserItemOptions { item : IItemAdd ; } param requestOptions returns export function addItemPart ( requestOptions ? ) { const partNum = requestOptions . partNum ; if ( ! Number . isInteger ( partNum ) || partNum < 1 || partNum > 10000 ) { return Promise . reject ( new Error ( 'The part number must be an integer between 1 to 10000, inclusive.' ) ) ; } return determineOwner ( requestOptions ) . then ( owner => { const url = `${ getPortalUrl ( requestOptions ) }/content/users/${ owner }/items/${ requestOptions . id }/addPart?partNum=${ partNum }` ; const options = appendCustomParams < IItemPartOptions > ( requestOptions , [ "file" ] , { params : { ... requestOptions . params } } ) ; return request ( url , options ) ; } ) ; } param requestOptions returns export function commitItemUpload ( requestOptions ? ) { return determineOwner ( requestOptions ) . then ( owner => { const url = `${ getPortalUrl ( requestOptions ) }/content/users/${ owner }/items/${ requestOptions . id }/commit` ; const options = appendCustomParams < ICommitItemOptions > ( requestOptions , [ ] , { params : { ... requestOptions . params , ... serializeItem ( requestOptions . item ) } } ) ; return request ( url , options ) ; } ) ; } param requestOptions returns export function cancelItemUpload ( requestOptions ? ) { return determineOwner ( requestOptions ) . then ( owner => { const url = `${ getPortalUrl ( requestOptions ) }/content/users/${ owner }/items/${ requestOptions . id }/cancel` ; return request ( url , requestOptions ) ; } ) ; }