import { request , IRequestOptions } from "@esri/arcgis-rest-request" ; import { IItemUpdate } from "@esri/arcgis-rest-types" ; import { getPortalUrl } from "../util/get-portal-url" ; import { ICreateUpdateItemOptions , IMoveItemResponse , IItemInfoOptions , IItemResourceOptions , IItemInfoResponse , IItemResourceResponse , IUpdateItemResponse , serializeItem , determineOwner } from "./helpers" ; export interface IUpdateItemOptions extends ICreateUpdateItemOptions { item : IItemUpdate ; } export interface IMoveItemOptions extends ICreateUpdateItemOptions { /**
     * Alphanumeric id of item to be moved.
     */ itemId : string ; /**
     * Alphanumeric id of folder to house moved item. If null, empty, or "/", the destination is the
     * root folder.
     */ folderId ? : string ; } param requestOptions returns export function updateItem ( requestOptions ) { return determineOwner ( requestOptions ) . then ( owner => { const url = requestOptions . folderId ? `${ getPortalUrl ( requestOptions ) }/content/users/${ owner }/${ requestOptions . folderId }/items/${ requestOptions . item . id }/update` : `${ getPortalUrl ( requestOptions ) }/content/users/${ owner }/items/${ requestOptions . item . id }/update` ; requestOptions . params = { ... requestOptions . params , ... serializeItem ( requestOptions . item ) } ; return request ( url , requestOptions ) ; } ) ; } param requestOptions returns export function updateItemInfo ( requestOptions ) { return determineOwner ( requestOptions ) . then ( owner => { const url = `${ getPortalUrl ( requestOptions as IRequestOptions ) }/content/users/${ owner }/items/${ requestOptions . id }/updateinfo` ; requestOptions . params = { folderName : requestOptions . folderName , file : requestOptions . file , ... requestOptions . params } ; return request ( url , requestOptions ) ; } ) ; } param requestOptions returns export function updateItemResource ( requestOptions ) { return determineOwner ( requestOptions ) . then ( owner => { const url = `${ getPortalUrl ( requestOptions as IRequestOptions ) }/content/users/${ owner }/items/${ requestOptions . id }/updateResources` ; requestOptions . params = { file : requestOptions . resource , fileName : requestOptions . name , resourcesPrefix : requestOptions . prefix , text : requestOptions . content , ... requestOptions . params } ; if ( typeof requestOptions . private !== "undefined" ) { requestOptions . params . access = requestOptions . private ? "private" : "inherit" ; } return request ( url , requestOptions ) ; } ) ; } param requestOptions returns export function moveItem ( requestOptions ) { return determineOwner ( requestOptions ) . then ( owner => { const url = `${ getPortalUrl ( requestOptions ) }/content/users/${ owner }/items/${ requestOptions . itemId }/move` ; let folderId = requestOptions . folderId ; if ( ! folderId ) { folderId = "/" ; } requestOptions . params = { folder : folderId , ... requestOptions . params } ; return request ( url , requestOptions ) ; } ) ; }