diff --git a/x-pack/legacy/plugins/watcher/public/legacy.ts b/x-pack/legacy/plugins/watcher/public/legacy.ts index 786672964efce..403b88e159d64 100644 --- a/x-pack/legacy/plugins/watcher/public/legacy.ts +++ b/x-pack/legacy/plugins/watcher/public/legacy.ts @@ -10,7 +10,6 @@ import { i18n } from '@kbn/i18n'; /* Legacy UI imports */ import { npSetup, npStart } from 'ui/new_platform'; import routes from 'ui/routes'; -import { I18nContext } from 'ui/i18n'; import { management, MANAGEMENT_BREADCRUMB } from 'ui/management'; // @ts-ignore import { TimeBuckets } from 'ui/time_buckets'; @@ -63,7 +62,6 @@ routes.when('/management/elasticsearch/watcher/:param1?/:param2?/:param3?/:param ...(npSetup.plugins as typeof npSetup.plugins & { eui_utils: any }), __LEGACY: { MANAGEMENT_BREADCRUMB, - I18nContext, TimeBuckets, licenseStatus, }, diff --git a/x-pack/legacy/plugins/watcher/public/np_ready/application/boot.tsx b/x-pack/legacy/plugins/watcher/public/np_ready/application/boot.tsx index aeb0d1709b9f8..381bc9650a7d0 100644 --- a/x-pack/legacy/plugins/watcher/public/np_ready/application/boot.tsx +++ b/x-pack/legacy/plugins/watcher/public/np_ready/application/boot.tsx @@ -10,24 +10,24 @@ import { SavedObjectsClientContract } from 'src/core/public'; import { App, AppDeps } from './app'; import { setHttpClient, setSavedObjectsClient } from './lib/api'; -import { BootLegacyDependencies } from '../types'; +import { LegacyDependencies } from '../types'; interface BootDeps extends AppDeps { element: HTMLElement; savedObjects: SavedObjectsClientContract; - legacy: BootLegacyDependencies; + I18nContext: any; + legacy: LegacyDependencies; } export const boot = (bootDeps: BootDeps) => { - const { element, legacy, savedObjects, ...appDeps } = bootDeps; - const { I18nContext, ...appLegacyDeps } = legacy; + const { I18nContext, element, legacy, savedObjects, ...appDeps } = bootDeps; setHttpClient(appDeps.http); setSavedObjectsClient(savedObjects); render( - + , element ); diff --git a/x-pack/legacy/plugins/watcher/public/np_ready/plugin.ts b/x-pack/legacy/plugins/watcher/public/np_ready/plugin.ts index 592769b1cccb7..161de9b5fc060 100644 --- a/x-pack/legacy/plugins/watcher/public/np_ready/plugin.ts +++ b/x-pack/legacy/plugins/watcher/public/np_ready/plugin.ts @@ -6,10 +6,10 @@ import { Plugin, CoreSetup, CoreStart } from 'src/core/public'; -import { BootLegacyDependencies } from './types'; +import { LegacyDependencies } from './types'; interface LegacyPlugins { - __LEGACY: BootLegacyDependencies; + __LEGACY: LegacyDependencies; } export class WatcherUIPlugin implements Plugin { @@ -25,9 +25,10 @@ export class WatcherUIPlugin implements Plugin { core: { docLinks, chrome, - // Will be passed through in future, remove @ts-ignore when shim is removed or types are updated + // Waiting for types to be updated. // @ts-ignore savedObjects, + i18n: { Context: I18nContext }, }, }, { element } @@ -42,7 +43,8 @@ export class WatcherUIPlugin implements Plugin { docLinks, chrome, euiUtils, - savedObjects, + savedObjects: savedObjects.client, + I18nContext, legacy: { ...__LEGACY, }, diff --git a/x-pack/legacy/plugins/watcher/public/np_ready/types.ts b/x-pack/legacy/plugins/watcher/public/np_ready/types.ts index 78e8f762c9766..22109f99c2c48 100644 --- a/x-pack/legacy/plugins/watcher/public/np_ready/types.ts +++ b/x-pack/legacy/plugins/watcher/public/np_ready/types.ts @@ -9,7 +9,3 @@ export interface LegacyDependencies { TimeBuckets: any; licenseStatus: any; } - -export interface BootLegacyDependencies extends LegacyDependencies { - I18nContext: any; -} diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/plugin.ts b/x-pack/legacy/plugins/watcher/server/np_ready/plugin.ts index 7b36385117c21..1a0d4bbac9ff8 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/plugin.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/plugin.ts @@ -3,11 +3,10 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ - import { Plugin, CoreSetup } from 'src/core/server'; import { i18n } from '@kbn/i18n'; import { PLUGIN } from '../../common/constants'; -import { ServerShim, NPServer } from './types'; +import { ServerShim, RouteDependencies } from './types'; import { registerLicenseChecker } from '../../../../server/lib/register_license_checker'; import { registerSettingsRoutes } from './routes/api/settings'; @@ -21,7 +20,7 @@ import { registerLoadHistoryRoute } from './routes/api/register_load_history_rou export class WatcherServerPlugin implements Plugin { async setup({ http }: CoreSetup, { __LEGACY: serverShim }: { __LEGACY: ServerShim }) { const router = http.createRouter(); - const npServer: NPServer = { + const routeDependencies: RouteDependencies = { router, }; // Register license checker @@ -32,13 +31,13 @@ export class WatcherServerPlugin implements Plugin { PLUGIN.MINIMUM_LICENSE_REQUIRED ); - registerListFieldsRoute(npServer, serverShim); - registerLoadHistoryRoute(npServer, serverShim); - registerIndicesRoutes(npServer, serverShim); - registerLicenseRoutes(npServer, serverShim); - registerSettingsRoutes(npServer, serverShim); - registerWatchesRoutes(npServer, serverShim); - registerWatchRoutes(npServer, serverShim); + registerListFieldsRoute(routeDependencies, serverShim); + registerLoadHistoryRoute(routeDependencies, serverShim); + registerIndicesRoutes(routeDependencies, serverShim); + registerLicenseRoutes(routeDependencies, serverShim); + registerSettingsRoutes(routeDependencies, serverShim); + registerWatchesRoutes(routeDependencies, serverShim); + registerWatchRoutes(routeDependencies, serverShim); } start() {} stop() {} diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/indices/register_get_route.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/indices/register_get_route.ts index 979d2031b4a16..d98dd06189e9b 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/indices/register_get_route.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/indices/register_get_route.ts @@ -9,7 +9,7 @@ import { reduce, size } from 'lodash'; import { callWithRequestFactory } from '../../../lib/call_with_request_factory'; import { isEsErrorFactory } from '../../../lib/is_es_error_factory'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; -import { NPServer, ServerShim } from '../../../types'; +import { RouteDependencies, ServerShim } from '../../../types'; function getIndexNamesFromAliasesResponse(json: Record) { return reduce( @@ -60,7 +60,7 @@ function getIndices(callWithRequest: any, pattern: string, limit = 10) { }); } -export function registerGetRoute(server: NPServer, legacy: ServerShim) { +export function registerGetRoute(deps: RouteDependencies, legacy: ServerShim) { const isEsError = isEsErrorFactory(legacy); const handler: RequestHandler = async (ctx, request, response) => { const callWithRequest = callWithRequestFactory(legacy, request); @@ -80,7 +80,7 @@ export function registerGetRoute(server: NPServer, legacy: ServerShim) { } }; - server.router.post( + deps.router.post( { path: '/api/watcher/indices', validate: false, diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/indices/register_indices_routes.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/indices/register_indices_routes.ts index 00d391f09bf3c..647a85c311532 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/indices/register_indices_routes.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/indices/register_indices_routes.ts @@ -5,8 +5,8 @@ */ import { registerGetRoute } from './register_get_route'; -import { NPServer, ServerShim } from '../../../types'; +import { RouteDependencies, ServerShim } from '../../../types'; -export function registerIndicesRoutes(server: NPServer, legacy: ServerShim) { - registerGetRoute(server, legacy); +export function registerIndicesRoutes(deps: RouteDependencies, legacy: ServerShim) { + registerGetRoute(deps, legacy); } diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/license/register_license_routes.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/license/register_license_routes.ts index 8fe9da3e2659d..c5965d9315b01 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/license/register_license_routes.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/license/register_license_routes.ts @@ -5,8 +5,8 @@ */ import { registerRefreshRoute } from './register_refresh_route'; -import { NPServer, ServerShim } from '../../../types'; +import { RouteDependencies, ServerShim } from '../../../types'; -export function registerLicenseRoutes(server: NPServer, legacy: ServerShim) { - registerRefreshRoute(server, legacy); +export function registerLicenseRoutes(deps: RouteDependencies, legacy: ServerShim) { + registerRefreshRoute(deps, legacy); } diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/license/register_refresh_route.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/license/register_refresh_route.ts index 38d50db7a9eae..08f1f26a84a4f 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/license/register_refresh_route.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/license/register_refresh_route.ts @@ -6,7 +6,7 @@ import { RequestHandler } from 'src/core/server'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; -import { NPServer, ServerShim } from '../../../types'; +import { RouteDependencies, ServerShim } from '../../../types'; /* In order for the client to have the most up-to-date snapshot of the current license, @@ -14,12 +14,12 @@ it needs to make a round-trip to the kibana server. This refresh endpoint is pro for when the client needs to check the license, but doesn't need to pull data from the server for any reason, i.e., when adding a new watch. */ -export function registerRefreshRoute(server: NPServer, legacy: ServerShim) { +export function registerRefreshRoute(deps: RouteDependencies, legacy: ServerShim) { const handler: RequestHandler = (ctx, request, response) => { return response.ok({ body: { success: true } }); }; - server.router.get( + deps.router.get( { path: '/api/watcher/license/refresh', validate: false, diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/register_list_fields_route.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/register_list_fields_route.ts index bdb5bdbc65def..5b09585feee0a 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/register_list_fields_route.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/register_list_fields_route.ts @@ -10,7 +10,7 @@ import { isEsErrorFactory } from '../../lib/is_es_error_factory'; import { licensePreRoutingFactory } from '../../lib/license_pre_routing_factory'; // @ts-ignore import { Fields } from '../../models/fields'; -import { NPServer, ServerShim } from '../../types'; +import { RouteDependencies, ServerShim } from '../../types'; function fetchFields(callWithRequest: any, indexes: string[]) { const params = { @@ -24,7 +24,7 @@ function fetchFields(callWithRequest: any, indexes: string[]) { return callWithRequest('fieldCaps', params); } -export function registerListFieldsRoute(server: NPServer, legacy: ServerShim) { +export function registerListFieldsRoute(deps: RouteDependencies, legacy: ServerShim) { const isEsError = isEsErrorFactory(legacy); const handler: RequestHandler = async (ctx, request, response) => { @@ -52,7 +52,7 @@ export function registerListFieldsRoute(server: NPServer, legacy: ServerShim) { } }; - server.router.post( + deps.router.post( { path: '/api/watcher/fields', validate: false, diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/register_load_history_route.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/register_load_history_route.ts index 08d241f199cdd..b7780ab7e078b 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/register_load_history_route.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/register_load_history_route.ts @@ -11,7 +11,7 @@ import { callWithRequestFactory } from '../../lib/call_with_request_factory'; import { isEsErrorFactory } from '../../lib/is_es_error_factory'; import { INDEX_NAMES } from '../../../../common/constants'; import { licensePreRoutingFactory } from '../../lib/license_pre_routing_factory'; -import { NPServer, ServerShim } from '../../types'; +import { RouteDependencies, ServerShim } from '../../types'; // @ts-ignore import { WatchHistoryItem } from '../../models/watch_history_item'; @@ -28,7 +28,7 @@ function fetchHistoryItem(callWithRequest: any, watchHistoryItemId: string) { }); } -export function registerLoadHistoryRoute(server: NPServer, legacy: ServerShim) { +export function registerLoadHistoryRoute(deps: RouteDependencies, legacy: ServerShim) { const isEsError = isEsErrorFactory(legacy); const handler: RequestHandler = async (ctx, request, response) => { const callWithRequest = callWithRequestFactory(legacy, request); @@ -64,7 +64,7 @@ export function registerLoadHistoryRoute(server: NPServer, legacy: ServerShim) { } }; - server.router.get( + deps.router.get( { path: '/api/watcher/history/{id}', validate: { diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/settings/register_load_route.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/settings/register_load_route.ts index f209dfef27b87..d9aa3621451f2 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/settings/register_load_route.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/settings/register_load_route.ts @@ -10,7 +10,7 @@ import { isEsErrorFactory } from '../../../lib/is_es_error_factory'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; // @ts-ignore import { Settings } from '../../../models/settings'; -import { NPServer, ServerShim } from '../../../types'; +import { RouteDependencies, ServerShim } from '../../../types'; function fetchClusterSettings(callWithInternalUser: any) { return callWithInternalUser('cluster.getSettings', { @@ -19,7 +19,7 @@ function fetchClusterSettings(callWithInternalUser: any) { }); } -export function registerLoadRoute(server: NPServer, legacy: ServerShim) { +export function registerLoadRoute(deps: RouteDependencies, legacy: ServerShim) { const isEsError = isEsErrorFactory(legacy); const handler: RequestHandler = async (ctx, request, response) => { try { @@ -37,7 +37,7 @@ export function registerLoadRoute(server: NPServer, legacy: ServerShim) { }; const callWithInternalUser = callWithInternalUserFactory(legacy); - server.router.get( + deps.router.get( { path: '/api/watcher/settings', validate: false, diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/settings/register_settings_routes.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/settings/register_settings_routes.ts index 0dc01c4f68667..0b24ec0e90bd4 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/settings/register_settings_routes.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/settings/register_settings_routes.ts @@ -5,8 +5,8 @@ */ import { registerLoadRoute } from './register_load_route'; -import { NPServer, ServerShim } from '../../../types'; +import { RouteDependencies, ServerShim } from '../../../types'; -export function registerSettingsRoutes(server: NPServer, legacy: ServerShim) { - registerLoadRoute(server, legacy); +export function registerSettingsRoutes(deps: RouteDependencies, legacy: ServerShim) { + registerLoadRoute(deps, legacy); } diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/action/register_acknowledge_route.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/action/register_acknowledge_route.ts index 756986f13a2aa..7dd55d2012603 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/action/register_acknowledge_route.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/action/register_acknowledge_route.ts @@ -6,13 +6,13 @@ import { schema } from '@kbn/config-schema'; import { get } from 'lodash'; -import { RequestHandler } from 'kibana/server'; +import { RequestHandler } from 'src/core/server'; import { callWithRequestFactory } from '../../../../lib/call_with_request_factory'; import { isEsErrorFactory } from '../../../../lib/is_es_error_factory'; import { licensePreRoutingFactory } from '../../../../lib/license_pre_routing_factory'; // @ts-ignore import { WatchStatus } from '../../../../models/watch_status'; -import { NPServer, ServerShim } from '../../../../types'; +import { RouteDependencies, ServerShim } from '../../../../types'; function acknowledgeAction(callWithRequest: any, watchId: string, actionId: string) { return callWithRequest('watcher.ackWatch', { @@ -21,7 +21,7 @@ function acknowledgeAction(callWithRequest: any, watchId: string, actionId: stri }); } -export function registerAcknowledgeRoute(server: NPServer, legacy: ServerShim) { +export function registerAcknowledgeRoute(deps: RouteDependencies, legacy: ServerShim) { const isEsError = isEsErrorFactory(legacy); const handler: RequestHandler = async (ctx, request, response) => { const callWithRequest = callWithRequestFactory(legacy, request); @@ -51,7 +51,7 @@ export function registerAcknowledgeRoute(server: NPServer, legacy: ServerShim) { } }; - server.router.put( + deps.router.put( { path: '/api/watcher/watch/{watchId}/action/{actionId}/acknowledge', validate: { diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/action/register_action_routes.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/action/register_action_routes.ts index 875510628e09c..022c844867938 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/action/register_action_routes.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/action/register_action_routes.ts @@ -5,8 +5,8 @@ */ import { registerAcknowledgeRoute } from './register_acknowledge_route'; -import { NPServer, ServerShim } from '../../../../types'; +import { RouteDependencies, ServerShim } from '../../../../types'; -export function registerActionRoutes(server: NPServer, legacy: ServerShim) { +export function registerActionRoutes(server: RouteDependencies, legacy: ServerShim) { registerAcknowledgeRoute(server, legacy); } diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_activate_route.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_activate_route.ts index 21afb0118c09c..9e7cc78a4ab22 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_activate_route.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_activate_route.ts @@ -10,7 +10,7 @@ import { get } from 'lodash'; import { callWithRequestFactory } from '../../../lib/call_with_request_factory'; import { isEsErrorFactory } from '../../../lib/is_es_error_factory'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; -import { NPServer, ServerShim } from '../../../types'; +import { RouteDependencies, ServerShim } from '../../../types'; // @ts-ignore import { WatchStatus } from '../../../models/watch_status'; @@ -20,7 +20,7 @@ function activateWatch(callWithRequest: any, watchId: string) { }); } -export function registerActivateRoute(server: NPServer, legacy: ServerShim) { +export function registerActivateRoute(deps: RouteDependencies, legacy: ServerShim) { const isEsError = isEsErrorFactory(legacy); const handler: RequestHandler = async (ctx, request, response) => { const callWithRequest = callWithRequestFactory(legacy, request); @@ -53,7 +53,7 @@ export function registerActivateRoute(server: NPServer, legacy: ServerShim) { } }; - server.router.put( + deps.router.put( { path: '/api/watcher/watch/{watchId}/activate', validate: { diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_deactivate_route.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_deactivate_route.ts index e48e18fc0cdbe..6283d596d9bcb 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_deactivate_route.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_deactivate_route.ts @@ -4,12 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ import { schema } from '@kbn/config-schema'; -import { RequestHandler } from 'kibana/server'; +import { RequestHandler } from 'src/core/server'; import { get } from 'lodash'; import { callWithRequestFactory } from '../../../lib/call_with_request_factory'; import { isEsErrorFactory } from '../../../lib/is_es_error_factory'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; -import { NPServer, ServerShim } from '../../../types'; +import { RouteDependencies, ServerShim } from '../../../types'; // @ts-ignore import { WatchStatus } from '../../../models/watch_status'; @@ -19,7 +19,7 @@ function deactivateWatch(callWithRequest: any, watchId: string) { }); } -export function registerDeactivateRoute(server: NPServer, legacy: ServerShim) { +export function registerDeactivateRoute(deps: RouteDependencies, legacy: ServerShim) { const isEsError = isEsErrorFactory(legacy); const handler: RequestHandler = async (ctx, request, response) => { const callWithRequest = callWithRequestFactory(legacy, request); @@ -52,7 +52,7 @@ export function registerDeactivateRoute(server: NPServer, legacy: ServerShim) { } }; - server.router.put( + deps.router.put( { path: '/api/watcher/watch/{watchId}/deactivate', validate: { diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_delete_route.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_delete_route.ts index 239bddf051613..df2ced5931d51 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_delete_route.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_delete_route.ts @@ -5,11 +5,11 @@ */ import { schema } from '@kbn/config-schema'; -import { RequestHandler } from 'kibana/server'; +import { RequestHandler } from 'src/core/server'; import { callWithRequestFactory } from '../../../lib/call_with_request_factory'; import { isEsErrorFactory } from '../../../lib/is_es_error_factory'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; -import { NPServer, ServerShim } from '../../../types'; +import { RouteDependencies, ServerShim } from '../../../types'; function deleteWatch(callWithRequest: any, watchId: string) { return callWithRequest('watcher.deleteWatch', { @@ -17,7 +17,7 @@ function deleteWatch(callWithRequest: any, watchId: string) { }); } -export function registerDeleteRoute(server: NPServer, legacy: ServerShim) { +export function registerDeleteRoute(deps: RouteDependencies, legacy: ServerShim) { const isEsError = isEsErrorFactory(legacy); const handler: RequestHandler = async (ctx, request, response) => { const callWithRequest = callWithRequestFactory(legacy, request); @@ -39,7 +39,7 @@ export function registerDeleteRoute(server: NPServer, legacy: ServerShim) { } }; - server.router.delete( + deps.router.delete( { path: '/api/watcher/watch/{watchId}', validate: { diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_execute_route.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_execute_route.ts index 138fd9f10f76d..5e2912db81c6d 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_execute_route.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_execute_route.ts @@ -11,7 +11,7 @@ import { callWithRequestFactory } from '../../../lib/call_with_request_factory'; import { isEsErrorFactory } from '../../../lib/is_es_error_factory'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; -import { NPServer, ServerShim } from '../../../types'; +import { RouteDependencies, ServerShim } from '../../../types'; // @ts-ignore import { ExecuteDetails } from '../../../models/execute_details'; // @ts-ignore @@ -28,7 +28,7 @@ function executeWatch(callWithRequest: any, executeDetails: any, watchJson: any) }); } -export function registerExecuteRoute(server: NPServer, legacy: ServerShim) { +export function registerExecuteRoute(deps: RouteDependencies, legacy: ServerShim) { const isEsError = isEsErrorFactory(legacy); const handler: RequestHandler = async (ctx, request, response) => { const callWithRequest = callWithRequestFactory(legacy, request); @@ -64,7 +64,7 @@ export function registerExecuteRoute(server: NPServer, legacy: ServerShim) { } }; - server.router.put( + deps.router.put( { path: '/api/watcher/watch/execute', validate: { diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_history_route.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_history_route.ts index 9297f8e030adb..f18a3fedcca6e 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_history_route.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_history_route.ts @@ -12,7 +12,7 @@ import { fetchAllFromScroll } from '../../../lib/fetch_all_from_scroll'; import { INDEX_NAMES, ES_SCROLL_SETTINGS } from '../../../../../common/constants'; import { isEsErrorFactory } from '../../../lib/is_es_error_factory'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; -import { NPServer, ServerShim } from '../../../types'; +import { RouteDependencies, ServerShim } from '../../../types'; // @ts-ignore import { WatchHistoryItem } from '../../../models/watch_history_item'; @@ -42,7 +42,7 @@ function fetchHistoryItems(callWithRequest: any, watchId: any, startTime: any) { ); } -export function registerHistoryRoute(server: NPServer, legacy: ServerShim) { +export function registerHistoryRoute(deps: RouteDependencies, legacy: ServerShim) { const isEsError = isEsErrorFactory(legacy); const handler: RequestHandler = async (ctx, request, response) => { const callWithRequest = callWithRequestFactory(legacy, request); @@ -84,7 +84,7 @@ export function registerHistoryRoute(server: NPServer, legacy: ServerShim) { } }; - server.router.get( + deps.router.get( { path: '/api/watcher/watch/{watchId}/history', validate: { diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_load_route.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_load_route.ts index 2bb6a908806ed..3480f961f1683 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_load_route.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_load_route.ts @@ -12,7 +12,7 @@ import { isEsErrorFactory } from '../../../lib/is_es_error_factory'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; // @ts-ignore import { Watch } from '../../../models/watch'; -import { NPServer, ServerShim } from '../../../types'; +import { RouteDependencies, ServerShim } from '../../../types'; function fetchWatch(callWithRequest: any, watchId: string) { return callWithRequest('watcher.getWatch', { @@ -20,7 +20,7 @@ function fetchWatch(callWithRequest: any, watchId: string) { }); } -export function registerLoadRoute(server: NPServer, legacy: ServerShim) { +export function registerLoadRoute(deps: RouteDependencies, legacy: ServerShim) { const isEsError = isEsErrorFactory(legacy); const handler: RequestHandler = async (ctx, request, response) => { const callWithRequest = callWithRequestFactory(legacy, request); @@ -56,7 +56,7 @@ export function registerLoadRoute(server: NPServer, legacy: ServerShim) { return response.internalError({ body: e }); } }; - server.router.get( + deps.router.get( { path: '/api/watcher/watch/{id}', validate: { diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_save_route.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_save_route.ts index 23784b50e4af4..d9a5ad844d7d8 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_save_route.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_save_route.ts @@ -5,7 +5,7 @@ */ import { schema } from '@kbn/config-schema'; -import { RequestHandler } from 'kibana/server'; +import { RequestHandler } from 'src/core/server'; import { i18n } from '@kbn/i18n'; import { WATCH_TYPES } from '../../../../../common/constants'; import { @@ -15,7 +15,7 @@ import { import { callWithRequestFactory } from '../../../lib/call_with_request_factory'; import { isEsErrorFactory } from '../../../lib/is_es_error_factory'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; -import { NPServer, ServerShim } from '../../../types'; +import { RouteDependencies, ServerShim } from '../../../types'; function fetchWatch(callWithRequest: any, watchId: string) { return callWithRequest('watcher.getWatch', { @@ -30,7 +30,7 @@ function saveWatch(callWithRequest: any, id: string, body: any) { }); } -export function registerSaveRoute(server: NPServer, legacy: ServerShim) { +export function registerSaveRoute(deps: RouteDependencies, legacy: ServerShim) { const isEsError = isEsErrorFactory(legacy); const handler: RequestHandler = async (ctx, request, response) => { const callWithRequest = callWithRequestFactory(legacy, request); @@ -90,7 +90,7 @@ export function registerSaveRoute(server: NPServer, legacy: ServerShim) { } }; - server.router.put( + deps.router.put( { path: '/api/watcher/watch/{id}', validate: { diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_visualize_route.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_visualize_route.ts index 865f1d987b39d..b86dfcd1ea9a2 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_visualize_route.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_visualize_route.ts @@ -9,7 +9,7 @@ import { RequestHandler } from 'src/core/server'; import { callWithRequestFactory } from '../../../lib/call_with_request_factory'; import { isEsErrorFactory } from '../../../lib/is_es_error_factory'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; -import { NPServer, ServerShim } from '../../../types'; +import { RouteDependencies, ServerShim } from '../../../types'; // @ts-ignore import { Watch } from '../../../models/watch'; @@ -28,7 +28,7 @@ function fetchVisualizeData(callWithRequest: any, index: any, body: any) { return callWithRequest('search', params); } -export function registerVisualizeRoute(server: NPServer, legacy: ServerShim) { +export function registerVisualizeRoute(deps: RouteDependencies, legacy: ServerShim) { const isEsError = isEsErrorFactory(legacy); const handler: RequestHandler = async (ctx, request, response) => { const callWithRequest = callWithRequestFactory(legacy, request); @@ -56,7 +56,7 @@ export function registerVisualizeRoute(server: NPServer, legacy: ServerShim) { } }; - server.router.post( + deps.router.post( { path: '/api/watcher/watch/visualize', validate: { diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_watch_routes.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_watch_routes.ts index c3155fb82f290..5ecbf3e0d2b46 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_watch_routes.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watch/register_watch_routes.ts @@ -13,16 +13,16 @@ import { registerActivateRoute } from './register_activate_route'; import { registerDeactivateRoute } from './register_deactivate_route'; import { registerVisualizeRoute } from './register_visualize_route'; import { registerActionRoutes } from './action'; -import { NPServer, ServerShim } from '../../../types'; +import { RouteDependencies, ServerShim } from '../../../types'; -export function registerWatchRoutes(server: NPServer, legacy: ServerShim) { - registerDeleteRoute(server, legacy); - registerExecuteRoute(server, legacy); - registerLoadRoute(server, legacy); - registerSaveRoute(server, legacy); - registerHistoryRoute(server, legacy); - registerActivateRoute(server, legacy); - registerDeactivateRoute(server, legacy); - registerActionRoutes(server, legacy); - registerVisualizeRoute(server, legacy); +export function registerWatchRoutes(deps: RouteDependencies, legacy: ServerShim) { + registerDeleteRoute(deps, legacy); + registerExecuteRoute(deps, legacy); + registerLoadRoute(deps, legacy); + registerSaveRoute(deps, legacy); + registerHistoryRoute(deps, legacy); + registerActivateRoute(deps, legacy); + registerDeactivateRoute(deps, legacy); + registerActionRoutes(deps, legacy); + registerVisualizeRoute(deps, legacy); } diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watches/register_delete_route.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watches/register_delete_route.ts index 6a327e64f4765..c3b5f2b0e7334 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watches/register_delete_route.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watches/register_delete_route.ts @@ -8,7 +8,7 @@ import { schema } from '@kbn/config-schema'; import { RequestHandler } from 'src/core/server'; import { callWithRequestFactory } from '../../../lib/call_with_request_factory'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; -import { NPServer, ServerShim } from '../../../types'; +import { RouteDependencies, ServerShim } from '../../../types'; function deleteWatches(callWithRequest: any, watchIds: string[]) { const deletePromises = watchIds.map(watchId => { @@ -37,7 +37,7 @@ function deleteWatches(callWithRequest: any, watchIds: string[]) { }); } -export function registerDeleteRoute(server: NPServer, legacy: ServerShim) { +export function registerDeleteRoute(deps: RouteDependencies, legacy: ServerShim) { const handler: RequestHandler = async (ctx, request, response) => { const callWithRequest = callWithRequestFactory(legacy, request); @@ -49,7 +49,7 @@ export function registerDeleteRoute(server: NPServer, legacy: ServerShim) { } }; - server.router.post( + deps.router.post( { path: '/api/watcher/watches/delete', validate: { diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watches/register_list_route.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watches/register_list_route.ts index 7ac58ac27217f..8112603130ef4 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watches/register_list_route.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watches/register_list_route.ts @@ -11,7 +11,7 @@ import { fetchAllFromScroll } from '../../../lib/fetch_all_from_scroll'; import { INDEX_NAMES, ES_SCROLL_SETTINGS } from '../../../../../common/constants'; import { isEsErrorFactory } from '../../../lib/is_es_error_factory'; import { licensePreRoutingFactory } from '../../../lib/license_pre_routing_factory'; -import { NPServer, ServerShim } from '../../../types'; +import { RouteDependencies, ServerShim } from '../../../types'; // @ts-ignore import { Watch } from '../../../models/watch'; @@ -30,7 +30,7 @@ function fetchWatches(callWithRequest: any) { ); } -export function registerListRoute(server: NPServer, legacy: ServerShim) { +export function registerListRoute(deps: RouteDependencies, legacy: ServerShim) { const isEsError = isEsErrorFactory(legacy); const handler: RequestHandler = async (ctx, request, response) => { const callWithRequest = callWithRequestFactory(legacy, request); @@ -77,7 +77,7 @@ export function registerListRoute(server: NPServer, legacy: ServerShim) { } }; - server.router.get( + deps.router.get( { path: '/api/watcher/watches', validate: false, diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watches/register_watches_routes.ts b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watches/register_watches_routes.ts index fb530b8004408..dd5f55078e591 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watches/register_watches_routes.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/routes/api/watches/register_watches_routes.ts @@ -6,9 +6,9 @@ import { registerListRoute } from './register_list_route'; import { registerDeleteRoute } from './register_delete_route'; -import { NPServer, ServerShim } from '../../../types'; +import { RouteDependencies, ServerShim } from '../../../types'; -export function registerWatchesRoutes(server: NPServer, legacy: ServerShim) { - registerListRoute(server, legacy); - registerDeleteRoute(server, legacy); +export function registerWatchesRoutes(deps: RouteDependencies, legacy: ServerShim) { + registerListRoute(deps, legacy); + registerDeleteRoute(deps, legacy); } diff --git a/x-pack/legacy/plugins/watcher/server/np_ready/types.ts b/x-pack/legacy/plugins/watcher/server/np_ready/types.ts index 1981e9b03f321..d2d5d814d311c 100644 --- a/x-pack/legacy/plugins/watcher/server/np_ready/types.ts +++ b/x-pack/legacy/plugins/watcher/server/np_ready/types.ts @@ -17,6 +17,6 @@ export interface ServerShim { }; } -export interface NPServer { +export interface RouteDependencies { router: IRouter; }