@@ -31,38 +31,29 @@ const Mocks = require("./Mocks");
3131const Routes = require ( "./Routes" ) ;
3232const RoutesVariants = require ( "./RoutesVariants" ) ;
3333
34- const {
35- ADMIN_API_PATH_OPTION ,
36- ADMIN_API_DEPRECATED_PATHS_OPTION ,
37- PLUGIN_NAME ,
38- } = require ( "./constants" ) ;
34+ const { ADMIN_API_PATH_OPTION , PLUGIN_NAME } = require ( "./constants" ) ;
3935
4036class Plugin {
41- constructor ( core ) {
37+ constructor ( core , { addAlert } ) {
4238 this . _core = core ;
4339 this . _tracer = core . tracer ;
4440 this . _settings = this . _core . settings ;
45- this . _deprecatedApi = new DeprecatedApi ( core ) ;
41+
42+ this . _legacyApi = new DeprecatedApi ( core , { addAlert } ) ;
4643 this . _settingsApi = new Settings ( this . _core ) ;
4744 this . _mocksApi = new Mocks ( this . _core ) ;
4845 this . _alertsApi = new Alerts ( this . _core ) ;
4946 this . _aboutApi = new About ( this . _core ) ;
5047 this . _routesApi = new Routes ( this . _core ) ;
5148 this . _routesVariantsApi = new RoutesVariants ( this . _core ) ;
49+
5250 core . addSetting ( {
5351 name : ADMIN_API_PATH_OPTION ,
5452 type : "string" ,
5553 description : `Api path for ${ PLUGIN_NAME } ` ,
5654 default : DEFAULT_BASE_PATH ,
5755 } ) ;
5856
59- core . addSetting ( {
60- name : ADMIN_API_DEPRECATED_PATHS_OPTION ,
61- type : "boolean" ,
62- description : `Disable deprecated paths of ${ PLUGIN_NAME } ` ,
63- default : true ,
64- } ) ;
65-
6657 this . _onChangeSettings = this . _onChangeSettings . bind ( this ) ;
6758 }
6859
@@ -71,21 +62,19 @@ class Plugin {
7162 }
7263
7364 init ( ) {
74- this . _deprecatedApi . init ( ) ;
65+ this . _legacyApi . init ( ) ;
7566 this . _initRouter ( ) ;
7667 }
7768
7869 start ( ) {
7970 this . _stopListeningOnChangeSettings = this . _core . onChangeSettings ( this . _onChangeSettings ) ;
80- this . _addDeprecatedRouter ( ) ;
8171 this . _addRouter ( ) ;
8272 }
8373
8474 stop ( ) {
8575 if ( this . _stopListeningOnChangeSettings ) {
8676 this . _stopListeningOnChangeSettings ( ) ;
8777 }
88- this . _removeDeprecatedRouter ( ) ;
8978 this . _removeRouter ( ) ;
9079 }
9180
@@ -97,24 +86,7 @@ class Plugin {
9786 this . _router . use ( MOCKS , this . _mocksApi . router ) ;
9887 this . _router . use ( ROUTES , this . _routesApi . router ) ;
9988 this . _router . use ( ROUTES_VARIANTS , this . _routesVariantsApi . router ) ;
100- }
101-
102- _addDeprecatedRouter ( ) {
103- this . _removeDeprecatedRouter ( ) ;
104- if (
105- this . _settings . get ( ADMIN_API_DEPRECATED_PATHS_OPTION ) === true &&
106- ! this . _addedDeprecatedRouter
107- ) {
108- this . _core . addRouter ( LEGACY , this . _deprecatedApi . router ) ;
109- this . _addedDeprecatedRouter = true ;
110- }
111- }
112-
113- _removeDeprecatedRouter ( ) {
114- if ( this . _addedDeprecatedRouter ) {
115- this . _core . removeRouter ( LEGACY , this . _deprecatedApi . router ) ;
116- this . _addedDeprecatedRouter = false ;
117- }
89+ this . _router . use ( LEGACY , this . _legacyApi . router ) ;
11890 }
11991
12092 _addRouter ( ) {
@@ -131,9 +103,6 @@ class Plugin {
131103 }
132104
133105 _onChangeSettings ( newSettings ) {
134- if ( newSettings . hasOwnProperty ( ADMIN_API_DEPRECATED_PATHS_OPTION ) ) {
135- this . _addDeprecatedRouter ( ) ;
136- }
137106 if ( newSettings . hasOwnProperty ( ADMIN_API_PATH_OPTION ) ) {
138107 this . _addRouter ( ) ;
139108 }
0 commit comments