import { request } from "@esri/arcgis-rest-request" ; import { determineOwner , IUserItemOptions } from './helpers' ; import { getPortalUrl } from "../util/get-portal-url" ; import { ISpatialReference } from '@esri/arcgis-rest-types' ; type ExportFormat = 'Shapefile' | 'CSV' | 'File Geodatabase' | 'Feature Collection' | 'GeoJson' | 'Scene Package' | 'KML' | 'Excel' ; export interface IExportLayerInfo { id : number ; where ? : string ; includeGeometry ? : boolean ; xColumnName ? : string ; yColumnName ? : string ; } export interface IExportParameters { layers ? : IExportLayerInfo [ ] ; targetSR ? : ISpatialReference | string ; } export interface IExportItemRequestOptions extends IUserItemOptions { title ? : string ; exportFormat : ExportFormat ; exportParameters ? : IExportParameters ; } export interface IExportItemResponse { type : string ; size : number ; jobId : string ; exportItemId : string ; serviceItemId : string ; exportFormat : ExportFormat ; } param requestOptions returns export const exportItem = ( requestOptions ) : Promise < IExportItemResponse > => { const { authentication , id : itemId , title , exportFormat , exportParameters } = requestOptions ; return determineOwner ( requestOptions ) . then ( owner => `${ getPortalUrl ( requestOptions ) }/content/users/${ owner }/export` ) . then ( url => request ( url , { httpMethod : 'POST' , authentication , params : { itemId , title , exportFormat , exportParameters } } ) ) ; } ;