import { HttpSetup , SavedObjectsClientContract } from 'kibana/public' ; import { API_BASE_PATH } from '../../../common/constants' ; import { IIndexPattern } from '../../../../../../src/plugins/data/common' ; export class IndexService { async canDeleteIndex ( http ) { const privilege = await http . get < { hasAllPrivileges : boolean ; } > ( `${ API_BASE_PATH }privileges` ) ; if ( ! privilege ) { return false ; } return privilege . hasAllPrivileges ; } async indexPatternExists ( savedObjectsClient , indexName ) { const response = await savedObjectsClient . find < IIndexPattern > ( { type : 'index-pattern' , perPage : 1 , search : `"${ indexName }"` , searchFields : [ 'title' ] , fields : [ 'title' ] , } ) ; const ip = response . savedObjects . find ( ( obj ) => obj . attributes . title === indexName ) ; return ip !== undefined ; } } export const indexService = new IndexService ( ) ;