55 * 2.0.
66 */
77
8- import { http as httpService } from './http_service' ;
9- import { getSavedObjectsClient } from '../../../../kibana_services' ;
8+ import { getSavedObjectsClient , getHttp } from '../../../../kibana_services' ;
109import { INDEX_FEATURE_PATH , INDEX_SOURCE_API_PATH } from '../../../../../common' ;
1110
1211export const getExistingIndexNames = async ( ) => {
13- const indexes = await httpService ( {
14- url : `/api/index_management/indices` ,
12+ const indexes = await getHttp ( ) . fetch ( {
13+ path : `/api/index_management/indices` ,
1514 method : 'GET' ,
1615 } ) ;
1716 return indexes ? indexes . map ( ( { name } : { name : string } ) => name ) : [ ] ;
1817} ;
1918
2019export const createNewIndexAndPattern = async ( indexName : string ) => {
21- return await httpService ( {
22- url : `/${ INDEX_SOURCE_API_PATH } ` ,
20+ return await getHttp ( ) . fetch ( {
21+ path : `/${ INDEX_SOURCE_API_PATH } ` ,
2322 method : 'POST' ,
24- data : {
23+ body : convertObjectToBlob ( {
2524 index : indexName ,
2625 // Initially set to static mappings
2726 mappings : {
@@ -31,23 +30,27 @@ export const createNewIndexAndPattern = async (indexName: string) => {
3130 } ,
3231 } ,
3332 } ,
34- } ,
33+ } ) ,
3534 } ) ;
3635} ;
3736
3837export const addFeatureToIndex = async ( indexName : string , geometry : unknown ) => {
39- return await httpService ( {
40- url : `/${ INDEX_FEATURE_PATH } ` ,
38+ return await getHttp ( ) . fetch ( {
39+ path : `/${ INDEX_FEATURE_PATH } ` ,
4140 method : 'POST' ,
42- data : {
41+ body : convertObjectToBlob ( {
4342 index : indexName ,
4443 data : {
4544 coordinates : geometry ,
4645 } ,
47- } ,
46+ } ) ,
4847 } ) ;
4948} ;
5049
50+ const convertObjectToBlob = ( obj : unknown ) => {
51+ return new Blob ( [ JSON . stringify ( obj ) ] , { type : 'application/json' } ) ;
52+ } ;
53+
5154export const getExistingIndexPatternNames = async ( ) => {
5255 const indexPatterns = await getSavedObjectsClient ( )
5356 . find ( {
0 commit comments