@@ -31,7 +31,11 @@ import { setupCapabilities } from './capabilities';
3131import { SpacesSavedObjectsService } from './saved_objects' ;
3232import { DefaultSpaceService } from './default_space' ;
3333import { SpacesLicenseService } from '../common/licensing' ;
34- import { SpacesClientRepositoryFactory , SpacesClientWrapper } from './lib/spaces_client' ;
34+ import {
35+ SpacesClientRepositoryFactory ,
36+ SpacesClientService ,
37+ SpacesClientWrapper ,
38+ } from './spaces_client' ;
3539
3640export interface PluginsSetup {
3741 features : FeaturesPluginSetup ;
@@ -65,6 +69,8 @@ export class Plugin {
6569
6670 private readonly spacesLicenseService = new SpacesLicenseService ( ) ;
6771
72+ private readonly spacesClientService : SpacesClientService ;
73+
6874 private readonly spacesService : SpacesService ;
6975
7076 private spacesServiceStart ?: SpacesServiceStart ;
@@ -75,23 +81,18 @@ export class Plugin {
7581 this . config$ = initializerContext . config . create < ConfigType > ( ) ;
7682 this . kibanaIndexConfig$ = initializerContext . config . legacy . globalConfig$ ;
7783 this . log = initializerContext . logger . get ( ) ;
78- this . spacesService = new SpacesService ( this . log ) ;
79- }
80-
81- public start ( core : CoreStart ) {
82- this . spacesServiceStart = this . spacesService . start ( core ) ;
83- return {
84- spacesService : this . spacesServiceStart ,
85- } ;
84+ this . spacesService = new SpacesService ( ) ;
85+ this . spacesClientService = new SpacesClientService ( ( message ) => this . log . debug ( message ) ) ;
8686 }
8787
8888 public async setup (
8989 core : CoreSetup < PluginsStart > ,
9090 plugins : PluginsSetup
9191 ) : Promise < SpacesPluginSetup > {
92+ const spacesClientSetup = this . spacesClientService . setup ( { config$ : this . config$ } ) ;
93+
9294 const spacesServiceSetup = this . spacesService . setup ( {
93- http : core . http ,
94- config$ : this . config$ ,
95+ basePath : core . http . basePath ,
9596 } ) ;
9697
9798 const getSpacesService = ( ) => {
@@ -139,12 +140,7 @@ export class Plugin {
139140 initSpacesRequestInterceptors ( {
140141 http : core . http ,
141142 log : this . log ,
142- getSpacesService : ( ) => {
143- if ( ! this . spacesServiceStart ) {
144- throw new Error ( 'Spaces Service is not yet initialized' ) ;
145- }
146- return this . spacesServiceStart ;
147- } ,
143+ getSpacesService,
148144 features : plugins . features ,
149145 } ) ;
150146
@@ -165,10 +161,21 @@ export class Plugin {
165161 }
166162
167163 return {
164+ spacesClient : spacesClientSetup ,
168165 spacesService : spacesServiceSetup ,
169- spacesClient : {
170- ...spacesServiceSetup . clientService ,
171- } ,
166+ } ;
167+ }
168+
169+ public start ( core : CoreStart ) {
170+ const spacesClientStart = this . spacesClientService . start ( core ) ;
171+
172+ this . spacesServiceStart = this . spacesService . start ( {
173+ basePath : core . http . basePath ,
174+ spacesClientService : spacesClientStart ,
175+ } ) ;
176+
177+ return {
178+ spacesService : this . spacesServiceStart ,
172179 } ;
173180 }
174181
0 commit comments