diff --git a/x-pack/legacy/plugins/reporting/common/get_absolute_url.ts b/x-pack/legacy/plugins/reporting/common/get_absolute_url.ts index 0e350cb1ec011..f996a49e5eadc 100644 --- a/x-pack/legacy/plugins/reporting/common/get_absolute_url.ts +++ b/x-pack/legacy/plugins/reporting/common/get_absolute_url.ts @@ -5,7 +5,13 @@ */ import url from 'url'; -import { AbsoluteURLFactoryOptions } from '../types'; + +interface AbsoluteURLFactoryOptions { + defaultBasePath: string; + protocol: string; + hostname: string; + port: string | number; +} export const getAbsoluteUrlFactory = ({ protocol, diff --git a/x-pack/legacy/plugins/reporting/export_types/common/constants.ts b/x-pack/legacy/plugins/reporting/export_types/common/constants.ts index 6c56c269017e2..76fab923978f8 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/constants.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/constants.ts @@ -4,9 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -export const LayoutTypes = { - PRESERVE_LAYOUT: 'preserve_layout', - PRINT: 'print', -}; - export const DEFAULT_PAGELOAD_SELECTOR = '.application'; diff --git a/x-pack/legacy/plugins/reporting/export_types/common/execute_job/decrypt_job_headers.test.ts b/x-pack/legacy/plugins/reporting/export_types/common/execute_job/decrypt_job_headers.test.ts index 9085fb3cbc876..fe3ac16b79fe0 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/execute_job/decrypt_job_headers.test.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/execute_job/decrypt_job_headers.test.ts @@ -4,8 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { cryptoFactory } from '../../../server/lib/crypto'; -import { Logger } from '../../../types'; +import { cryptoFactory, LevelLogger } from '../../../server/lib'; import { decryptJobHeaders } from './decrypt_job_headers'; const encryptHeaders = async (encryptionKey: string, headers: Record) => { @@ -23,7 +22,7 @@ describe('headers', () => { }, logger: ({ error: jest.fn(), - } as unknown) as Logger, + } as unknown) as LevelLogger, }); await expect(getDecryptedHeaders()).rejects.toMatchInlineSnapshot( `[Error: Failed to decrypt report job data. Please ensure that xpack.reporting.encryptionKey is set and re-generate this report. Error: Invalid IV length]` @@ -44,7 +43,7 @@ describe('headers', () => { type: 'csv', headers: encryptedHeaders, }, - logger: {} as Logger, + logger: {} as LevelLogger, }); expect(decryptedHeaders).toEqual(headers); }); diff --git a/x-pack/legacy/plugins/reporting/export_types/common/execute_job/decrypt_job_headers.ts b/x-pack/legacy/plugins/reporting/export_types/common/execute_job/decrypt_job_headers.ts index 0436f5d5bc843..a13c1fa2a9efb 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/execute_job/decrypt_job_headers.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/execute_job/decrypt_job_headers.ts @@ -5,8 +5,7 @@ */ import { i18n } from '@kbn/i18n'; -import { cryptoFactory } from '../../../server/lib/crypto'; -import { Logger } from '../../../types'; +import { cryptoFactory, LevelLogger } from '../../../server/lib'; interface HasEncryptedHeaders { headers?: string; @@ -23,7 +22,7 @@ export const decryptJobHeaders = async < }: { encryptionKey?: string; job: JobDocPayloadType; - logger: Logger; + logger: LevelLogger; }): Promise> => { try { if (typeof job.headers !== 'string') { diff --git a/x-pack/legacy/plugins/reporting/export_types/common/execute_job/get_conditional_headers.test.ts b/x-pack/legacy/plugins/reporting/export_types/common/execute_job/get_conditional_headers.test.ts index 5f5fc94eee830..c09cc8314374e 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/execute_job/get_conditional_headers.test.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/execute_job/get_conditional_headers.test.ts @@ -5,9 +5,9 @@ */ import sinon from 'sinon'; +import { ReportingConfig, ReportingCore } from '../../../server'; +import { JobDocPayload } from '../../../server/types'; import { createMockReportingCore } from '../../../test_helpers'; -import { ReportingConfig, ReportingCore } from '../../../server/types'; -import { JobDocPayload } from '../../../types'; import { JobDocPayloadPDF } from '../../printable_pdf/types'; import { getConditionalHeaders, getCustomLogo } from './index'; diff --git a/x-pack/legacy/plugins/reporting/export_types/common/execute_job/get_conditional_headers.ts b/x-pack/legacy/plugins/reporting/export_types/common/execute_job/get_conditional_headers.ts index bd7999d697ca9..808d5db5c57d5 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/execute_job/get_conditional_headers.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/execute_job/get_conditional_headers.ts @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import { ReportingConfig } from '../../../server/types'; -import { ConditionalHeaders } from '../../../types'; +import { ReportingConfig } from '../../../server'; +import { ConditionalHeaders } from '../../../server/types'; export const getConditionalHeaders = ({ config, diff --git a/x-pack/legacy/plugins/reporting/export_types/common/execute_job/get_custom_logo.ts b/x-pack/legacy/plugins/reporting/export_types/common/execute_job/get_custom_logo.ts index a13f992e7867c..777de317af41e 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/execute_job/get_custom_logo.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/execute_job/get_custom_logo.ts @@ -5,8 +5,8 @@ */ import { UI_SETTINGS_CUSTOM_PDF_LOGO } from '../../../common/constants'; -import { ReportingConfig, ReportingCore } from '../../../server/types'; -import { ConditionalHeaders } from '../../../types'; +import { ReportingConfig, ReportingCore } from '../../../server'; +import { ConditionalHeaders } from '../../../server/types'; import { JobDocPayloadPDF } from '../../printable_pdf/types'; // Logo is PDF only export const getCustomLogo = async ({ diff --git a/x-pack/legacy/plugins/reporting/export_types/common/execute_job/get_full_urls.ts b/x-pack/legacy/plugins/reporting/export_types/common/execute_job/get_full_urls.ts index c4b6f31019fdf..59cb7ce14ca2d 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/execute_job/get_full_urls.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/execute_job/get_full_urls.ts @@ -12,7 +12,7 @@ import { } from 'url'; import { getAbsoluteUrlFactory } from '../../../common/get_absolute_url'; import { validateUrls } from '../../../common/validate_urls'; -import { ReportingConfig } from '../../../server/types'; +import { ReportingConfig } from '../../../server'; import { JobDocPayloadPNG } from '../../png/types'; import { JobDocPayloadPDF } from '../../printable_pdf/types'; diff --git a/x-pack/legacy/plugins/reporting/export_types/common/layouts/create_layout.ts b/x-pack/legacy/plugins/reporting/export_types/common/layouts/create_layout.ts index 07fceb603e451..d33760fcb4f89 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/layouts/create_layout.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/layouts/create_layout.ts @@ -5,8 +5,8 @@ */ import { CaptureConfig } from '../../../server/types'; -import { LayoutTypes } from '../constants'; -import { Layout, LayoutParams } from './layout'; +import { LayoutParams, LayoutTypes } from './'; +import { Layout } from './layout'; import { PreserveLayout } from './preserve_layout'; import { PrintLayout } from './print_layout'; diff --git a/x-pack/legacy/plugins/reporting/export_types/common/layouts/index.ts b/x-pack/legacy/plugins/reporting/export_types/common/layouts/index.ts index fd35485779ba0..993b8f6cdc9ab 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/layouts/index.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/layouts/index.ts @@ -4,6 +4,63 @@ * you may not use this file except in compliance with the Elastic License. */ +import { HeadlessChromiumDriver } from '../../../server/browsers'; +import { LevelLogger } from '../../../server/lib'; +import { Layout } from './layout'; + export { createLayout } from './create_layout'; -export { PrintLayout } from './print_layout'; +export { Layout } from './layout'; export { PreserveLayout } from './preserve_layout'; +export { PrintLayout } from './print_layout'; + +export const LayoutTypes = { + PRESERVE_LAYOUT: 'preserve_layout', + PRINT: 'print', +}; + +export const getDefaultLayoutSelectors = (): LayoutSelectorDictionary => ({ + screenshot: '[data-shared-items-container]', + renderComplete: '[data-shared-item]', + itemsCountAttribute: 'data-shared-items-count', + timefilterDurationAttribute: 'data-shared-timefilter-duration', +}); + +export interface PageSizeParams { + pageMarginTop: number; + pageMarginBottom: number; + pageMarginWidth: number; + tableBorderWidth: number; + headingHeight: number; + subheadingHeight: number; +} + +export interface LayoutSelectorDictionary { + screenshot: string; + renderComplete: string; + itemsCountAttribute: string; + timefilterDurationAttribute: string; +} + +export interface PdfImageSize { + width: number; + height?: number; +} + +export interface Size { + width: number; + height: number; +} + +export interface LayoutParams { + id: string; + dimensions: Size; +} + +interface LayoutSelectors { + // Fields that are not part of Layout: the instances + // independently implement these fields on their own + selectors: LayoutSelectorDictionary; + positionElements?: (browser: HeadlessChromiumDriver, logger: LevelLogger) => Promise; +} + +export type LayoutInstance = Layout & LayoutSelectors & Size; diff --git a/x-pack/legacy/plugins/reporting/export_types/common/layouts/layout.ts b/x-pack/legacy/plugins/reporting/export_types/common/layouts/layout.ts index 5cd2f3e636a93..433edb35df4cd 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/layouts/layout.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/layouts/layout.ts @@ -4,8 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { HeadlessChromiumDriver } from '../../../server/browsers/chromium/driver'; -import { LevelLogger } from '../../../server/lib'; +import { PageSizeParams, PdfImageSize, Size } from './'; export interface ViewZoomWidthHeight { zoom: number; @@ -13,34 +12,6 @@ export interface ViewZoomWidthHeight { height: number; } -export interface PageSizeParams { - pageMarginTop: number; - pageMarginBottom: number; - pageMarginWidth: number; - tableBorderWidth: number; - headingHeight: number; - subheadingHeight: number; -} - -export interface LayoutSelectorDictionary { - screenshot: string; - renderComplete: string; - itemsCountAttribute: string; - timefilterDurationAttribute: string; -} - -export interface PdfImageSize { - width: number; - height?: number; -} - -export const getDefaultLayoutSelectors = (): LayoutSelectorDictionary => ({ - screenshot: '[data-shared-items-container]', - renderComplete: '[data-shared-item]', - itemsCountAttribute: 'data-shared-items-count', - timefilterDurationAttribute: 'data-shared-timefilter-duration', -}); - export abstract class Layout { public id: string = ''; @@ -62,22 +33,3 @@ export abstract class Layout { public abstract getCssOverridesPath(): string; } - -export interface Size { - width: number; - height: number; -} - -export interface LayoutParams { - id: string; - dimensions: Size; -} - -interface LayoutSelectors { - // Fields that are not part of Layout: the instances - // independently implement these fields on their own - selectors: LayoutSelectorDictionary; - positionElements?: (browser: HeadlessChromiumDriver, logger: LevelLogger) => Promise; -} - -export type LayoutInstance = Layout & LayoutSelectors & Size; diff --git a/x-pack/legacy/plugins/reporting/export_types/common/layouts/preserve_layout.ts b/x-pack/legacy/plugins/reporting/export_types/common/layouts/preserve_layout.ts index 07dbba7d25883..9041055ddce2d 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/layouts/preserve_layout.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/layouts/preserve_layout.ts @@ -3,15 +3,16 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ + import path from 'path'; -import { LayoutTypes } from '../constants'; import { getDefaultLayoutSelectors, Layout, LayoutSelectorDictionary, + LayoutTypes, PageSizeParams, Size, -} from './layout'; +} from './'; // We use a zoom of two to bump up the resolution of the screenshot a bit. const ZOOM: number = 2; diff --git a/x-pack/legacy/plugins/reporting/export_types/common/layouts/print_layout.ts b/x-pack/legacy/plugins/reporting/export_types/common/layouts/print_layout.ts index f6974379253fb..759f07a33e2b6 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/layouts/print_layout.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/layouts/print_layout.ts @@ -6,11 +6,11 @@ import path from 'path'; import { EvaluateFn, SerializableOrJSHandle } from 'puppeteer'; -import { HeadlessChromiumDriver } from '../../../server/browsers'; import { LevelLogger } from '../../../server/lib'; +import { HeadlessChromiumDriver } from '../../../server/browsers'; import { CaptureConfig } from '../../../server/types'; -import { LayoutTypes } from '../constants'; -import { getDefaultLayoutSelectors, Layout, LayoutSelectorDictionary, Size } from './layout'; +import { getDefaultLayoutSelectors, LayoutSelectorDictionary, Size, LayoutTypes } from './'; +import { Layout } from './layout'; export class PrintLayout extends Layout { public readonly selectors: LayoutSelectorDictionary = { diff --git a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/get_element_position_data.ts b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/get_element_position_data.ts index 3999393600e48..d02e852a3c1b6 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/get_element_position_data.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/get_element_position_data.ts @@ -5,16 +5,16 @@ */ import { i18n } from '@kbn/i18n'; -import { HeadlessChromiumDriver as HeadlessBrowser } from '../../../../server/browsers'; -import { LevelLogger as Logger, startTrace } from '../../../../server/lib'; -import { LayoutInstance } from '../../layouts/layout'; +import { HeadlessChromiumDriver } from '../../../../server/browsers'; +import { LevelLogger, startTrace } from '../../../../server/lib'; +import { AttributesMap, ElementsPositionAndAttribute } from '../../../../server/types'; +import { LayoutInstance } from '../../layouts'; import { CONTEXT_ELEMENTATTRIBUTES } from './constants'; -import { AttributesMap, ElementsPositionAndAttribute } from './types'; export const getElementPositionAndAttributes = async ( - browser: HeadlessBrowser, + browser: HeadlessChromiumDriver, layout: LayoutInstance, - logger: Logger + logger: LevelLogger ): Promise => { const endTrace = startTrace('get_element_position_data', 'read'); const { screenshot: screenshotSelector } = layout.selectors; // data-shared-items-container diff --git a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/get_number_of_items.ts b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/get_number_of_items.ts index d0c1a2a3ce672..9e446f499ab3a 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/get_number_of_items.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/get_number_of_items.ts @@ -5,15 +5,15 @@ */ import { i18n } from '@kbn/i18n'; -import { HeadlessChromiumDriver as HeadlessBrowser } from '../../../../server/browsers'; import { LevelLogger, startTrace } from '../../../../server/lib'; +import { HeadlessChromiumDriver } from '../../../../server/browsers'; import { CaptureConfig } from '../../../../server/types'; -import { LayoutInstance } from '../../layouts/layout'; +import { LayoutInstance } from '../../layouts'; import { CONTEXT_GETNUMBEROFITEMS, CONTEXT_READMETADATA } from './constants'; export const getNumberOfItems = async ( captureConfig: CaptureConfig, - browser: HeadlessBrowser, + browser: HeadlessChromiumDriver, layout: LayoutInstance, logger: LevelLogger ): Promise => { diff --git a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/get_screenshots.ts b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/get_screenshots.ts index bc9e17854b27d..578a4dd0b975c 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/get_screenshots.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/get_screenshots.ts @@ -5,12 +5,12 @@ */ import { i18n } from '@kbn/i18n'; -import { HeadlessChromiumDriver as HeadlessBrowser } from '../../../../server/browsers'; +import { HeadlessChromiumDriver } from '../../../../server/browsers'; import { LevelLogger, startTrace } from '../../../../server/lib'; -import { Screenshot, ElementsPositionAndAttribute } from './types'; +import { ElementsPositionAndAttribute, Screenshot } from '../../../../server/types'; export const getScreenshots = async ( - browser: HeadlessBrowser, + browser: HeadlessChromiumDriver, elementsPositionAndAttributes: ElementsPositionAndAttribute[], logger: LevelLogger ): Promise => { diff --git a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/get_time_range.ts b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/get_time_range.ts index bcd4cf9000df4..7bdb38298c383 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/get_time_range.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/get_time_range.ts @@ -4,21 +4,20 @@ * you may not use this file except in compliance with the Elastic License. */ -import { HeadlessChromiumDriver as HeadlessBrowser } from '../../../../server/browsers'; import { LevelLogger, startTrace } from '../../../../server/lib'; -import { LayoutInstance } from '../../layouts/layout'; +import { HeadlessChromiumDriver } from '../../../../server/browsers'; +import { LayoutInstance } from '../../layouts'; import { CONTEXT_GETTIMERANGE } from './constants'; -import { TimeRange } from './types'; export const getTimeRange = async ( - browser: HeadlessBrowser, + browser: HeadlessChromiumDriver, layout: LayoutInstance, logger: LevelLogger -): Promise => { +): Promise => { const endTrace = startTrace('get_time_range', 'read'); logger.debug('getting timeRange'); - const timeRange: TimeRange | null = await browser.evaluate( + const timeRange = await browser.evaluate( { fn: durationAttribute => { const durationElement = document.querySelector(`[${durationAttribute}]`); @@ -32,7 +31,7 @@ export const getTimeRange = async ( return null; } - return { duration }; + return duration; // user-friendly date string }, args: [layout.selectors.timefilterDurationAttribute], }, @@ -41,7 +40,7 @@ export const getTimeRange = async ( ); if (timeRange) { - logger.info(`timeRange: ${timeRange.duration}`); + logger.info(`timeRange: ${timeRange}`); } else { logger.debug('no timeRange'); } diff --git a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/index.ts b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/index.ts index 0d75b067fbe63..5a04f1a497abf 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/index.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/index.ts @@ -4,4 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -export { screenshotsObservableFactory, ScreenshotsObservableFn } from './observable'; +export { screenshotsObservableFactory } from './observable'; diff --git a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/inject_css.ts b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/inject_css.ts index 40bb84870b16d..dae6f3cc6350f 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/inject_css.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/inject_css.ts @@ -7,15 +7,15 @@ import { i18n } from '@kbn/i18n'; import fs from 'fs'; import { promisify } from 'util'; -import { HeadlessChromiumDriver as HeadlessBrowser } from '../../../../server/browsers'; import { LevelLogger, startTrace } from '../../../../server/lib'; +import { HeadlessChromiumDriver } from '../../../../server/browsers'; import { Layout } from '../../layouts/layout'; import { CONTEXT_INJECTCSS } from './constants'; const fsp = { readFile: promisify(fs.readFile) }; export const injectCustomCss = async ( - browser: HeadlessBrowser, + browser: HeadlessChromiumDriver, layout: Layout, logger: LevelLogger ): Promise => { diff --git a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/observable.test.ts b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/observable.test.ts index 796bccb360ebd..cc8b438310430 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/observable.test.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/observable.test.ts @@ -18,13 +18,16 @@ jest.mock('../../../../server/browsers/chromium/puppeteer', () => ({ import * as Rx from 'rxjs'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { loggingServiceMock } from '../../../../../../../../src/core/server/mocks'; +import { HeadlessChromiumDriver } from '../../../../server/browsers'; import { LevelLogger } from '../../../../server/lib'; +import { + CaptureConfig, + ConditionalHeaders, + ElementsPositionAndAttribute, +} from '../../../../server/types'; import { createMockBrowserDriverFactory, createMockLayoutInstance } from '../../../../test_helpers'; -import { ConditionalHeaders, HeadlessChromiumDriver } from '../../../../types'; -import { CaptureConfig } from '../../../../server/types'; import * as contexts from './constants'; import { screenshotsObservableFactory } from './observable'; -import { ElementsPositionAndAttribute } from './types'; /* * Mocks diff --git a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/observable.ts b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/observable.ts index 282490a28d591..de27d5ad30014 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/observable.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/observable.ts @@ -16,29 +16,32 @@ import { tap, toArray, } from 'rxjs/operators'; -import { CaptureConfig } from '../../../../server/types'; +import { HeadlessChromiumDriverFactory } from '../../../../server/browsers'; +import { + CaptureConfig, + ElementsPositionAndAttribute, + ScreenshotObservableOpts, + ScreenshotResults, + ScreenshotsObservableFn, +} from '../../../../server/types'; import { DEFAULT_PAGELOAD_SELECTOR } from '../../constants'; -import { HeadlessChromiumDriverFactory } from '../../../../types'; import { getElementPositionAndAttributes } from './get_element_position_data'; import { getNumberOfItems } from './get_number_of_items'; import { getScreenshots } from './get_screenshots'; import { getTimeRange } from './get_time_range'; import { injectCustomCss } from './inject_css'; import { openUrl } from './open_url'; -import { ScreenSetupData, ScreenshotObservableOpts, ScreenshotResults } from './types'; import { waitForRenderComplete } from './wait_for_render'; import { waitForVisualizations } from './wait_for_visualizations'; const DEFAULT_SCREENSHOT_CLIP_HEIGHT = 1200; const DEFAULT_SCREENSHOT_CLIP_WIDTH = 1800; -export type ScreenshotsObservableFn = ({ - logger, - urls, - conditionalHeaders, - layout, - browserTimezone, -}: ScreenshotObservableOpts) => Rx.Observable; +interface ScreenSetupData { + elementsPositionAndAttributes: ElementsPositionAndAttribute[] | null; + timeRange: string | null; + error?: Error; +} export function screenshotsObservableFactory( captureConfig: CaptureConfig, diff --git a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/open_url.ts b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/open_url.ts index a0708b7dba36b..3cf962b8178fd 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/open_url.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/open_url.ts @@ -5,14 +5,13 @@ */ import { i18n } from '@kbn/i18n'; -import { HeadlessChromiumDriver as HeadlessBrowser } from '../../../../server/browsers'; +import { HeadlessChromiumDriver } from '../../../../server/browsers'; import { LevelLogger, startTrace } from '../../../../server/lib'; -import { CaptureConfig } from '../../../../server/types'; -import { ConditionalHeaders } from '../../../../types'; +import { CaptureConfig, ConditionalHeaders } from '../../../../server/types'; export const openUrl = async ( captureConfig: CaptureConfig, - browser: HeadlessBrowser, + browser: HeadlessChromiumDriver, url: string, pageLoadSelector: string, conditionalHeaders: ConditionalHeaders, diff --git a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/types.ts b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/types.ts deleted file mode 100644 index 13ddf5eb74fcf..0000000000000 --- a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/types.ts +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { LevelLogger } from '../../../../server/lib'; -import { ConditionalHeaders, ElementPosition } from '../../../../types'; -import { LayoutInstance } from '../../layouts/layout'; - -export interface ScreenshotObservableOpts { - logger: LevelLogger; - urls: string[]; - conditionalHeaders: ConditionalHeaders; - layout: LayoutInstance; - browserTimezone: string; -} - -export interface TimeRange { - duration: string; -} - -export interface AttributesMap { - [key: string]: any; -} - -export interface ElementsPositionAndAttribute { - position: ElementPosition; - attributes: AttributesMap; -} - -export interface Screenshot { - base64EncodedData: string; - title: string; - description: string; -} - -export interface ScreenSetupData { - elementsPositionAndAttributes: ElementsPositionAndAttribute[] | null; - timeRange: TimeRange | null; - error?: Error; -} - -export interface ScreenshotResults { - timeRange: TimeRange | null; - screenshots: Screenshot[]; - error?: Error; - elementsPositionAndAttributes?: ElementsPositionAndAttribute[]; // NOTE: for testing -} diff --git a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/wait_for_render.ts b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/wait_for_render.ts index fe92fbc9077e6..0e02fa2dacfad 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/wait_for_render.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/wait_for_render.ts @@ -5,15 +5,15 @@ */ import { i18n } from '@kbn/i18n'; -import { HeadlessChromiumDriver as HeadlessBrowser } from '../../../../server/browsers'; import { LevelLogger, startTrace } from '../../../../server/lib'; +import { HeadlessChromiumDriver } from '../../../../server/browsers'; import { CaptureConfig } from '../../../../server/types'; -import { LayoutInstance } from '../../layouts/layout'; +import { LayoutInstance } from '../../layouts'; import { CONTEXT_WAITFORRENDER } from './constants'; export const waitForRenderComplete = async ( captureConfig: CaptureConfig, - browser: HeadlessBrowser, + browser: HeadlessChromiumDriver, layout: LayoutInstance, logger: LevelLogger ) => { diff --git a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/wait_for_visualizations.ts b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/wait_for_visualizations.ts index d456c4089ecee..ff84d06956dbc 100644 --- a/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/wait_for_visualizations.ts +++ b/x-pack/legacy/plugins/reporting/export_types/common/lib/screenshots/wait_for_visualizations.ts @@ -5,10 +5,10 @@ */ import { i18n } from '@kbn/i18n'; -import { HeadlessChromiumDriver as HeadlessBrowser } from '../../../../server/browsers'; import { LevelLogger, startTrace } from '../../../../server/lib'; +import { HeadlessChromiumDriver } from '../../../../server/browsers'; import { CaptureConfig } from '../../../../server/types'; -import { LayoutInstance } from '../../layouts/layout'; +import { LayoutInstance } from '../../layouts'; import { CONTEXT_WAITFORELEMENTSTOBEINDOM } from './constants'; type SelectorArgs = Record; @@ -24,7 +24,7 @@ const getCompletedItemsCount = ({ renderCompleteSelector }: SelectorArgs) => { */ export const waitForVisualizations = async ( captureConfig: CaptureConfig, - browser: HeadlessBrowser, + browser: HeadlessChromiumDriver, itemsCount: number, layout: LayoutInstance, logger: LevelLogger diff --git a/x-pack/legacy/plugins/reporting/export_types/csv/index.ts b/x-pack/legacy/plugins/reporting/export_types/csv/index.ts index 942cb954785ac..cdb4c36dba3df 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv/index.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv/index.ts @@ -6,18 +6,22 @@ import { CSV_JOB_TYPE as jobType, - LICENSE_TYPE_TRIAL, LICENSE_TYPE_BASIC, - LICENSE_TYPE_STANDARD, + LICENSE_TYPE_ENTERPRISE, LICENSE_TYPE_GOLD, LICENSE_TYPE_PLATINUM, - LICENSE_TYPE_ENTERPRISE, + LICENSE_TYPE_STANDARD, + LICENSE_TYPE_TRIAL, } from '../../common/constants'; -import { ExportTypeDefinition, ESQueueCreateJobFn, ESQueueWorkerExecuteFn } from '../../types'; +import { + ESQueueCreateJobFn, + ESQueueWorkerExecuteFn, + ExportTypeDefinition, +} from '../../server/types'; import { metadata } from './metadata'; import { createJobFactory } from './server/create_job'; import { executeJobFactory } from './server/execute_job'; -import { JobParamsDiscoverCsv, JobDocPayloadDiscoverCsv } from './types'; +import { JobDocPayloadDiscoverCsv, JobParamsDiscoverCsv } from './types'; export const getExportType = (): ExportTypeDefinition< JobParamsDiscoverCsv, diff --git a/x-pack/legacy/plugins/reporting/export_types/csv/server/create_job.ts b/x-pack/legacy/plugins/reporting/export_types/csv/server/create_job.ts index 0e704a041452a..8320cd05aa2e7 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv/server/create_job.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv/server/create_job.ts @@ -5,13 +5,13 @@ */ import { ReportingCore } from '../../../server'; -import { cryptoFactory } from '../../../server/lib/crypto'; +import { cryptoFactory } from '../../../server/lib'; import { ConditionalHeaders, CreateJobFactory, ESQueueCreateJobFn, RequestFacade, -} from '../../../types'; +} from '../../../server/types'; import { JobParamsDiscoverCsv } from '../types'; export const createJobFactory: CreateJobFactory new Promise(resolve => setTimeout(() => resolve(), ms)); @@ -65,6 +65,7 @@ describe('CSV Execute Job', function() { beforeEach(async function() { configGetStub = sinon.stub(); + configGetStub.withArgs('index').returns('.reporting-foo-test'); configGetStub.withArgs('encryptionKey').returns(encryptionKey); configGetStub.withArgs('csv', 'maxSizeBytes').returns(1024 * 1000); // 1mB configGetStub.withArgs('csv', 'scroll').returns({}); diff --git a/x-pack/legacy/plugins/reporting/export_types/csv/server/execute_job.ts b/x-pack/legacy/plugins/reporting/export_types/csv/server/execute_job.ts index dbe305bc452db..7d95c45d5d233 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv/server/execute_job.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv/server/execute_job.ts @@ -7,18 +7,18 @@ import { i18n } from '@kbn/i18n'; import Hapi from 'hapi'; import { IUiSettingsClient, KibanaRequest } from '../../../../../../../src/core/server'; -import { CSV_JOB_TYPE, CSV_BOM_CHARS } from '../../../common/constants'; -import { ReportingCore } from '../../../server/core'; -import { cryptoFactory } from '../../../server/lib'; +import { CSV_BOM_CHARS, CSV_JOB_TYPE } from '../../../common/constants'; +import { ReportingCore } from '../../../server'; +import { cryptoFactory, LevelLogger } from '../../../server/lib'; import { getFieldFormats } from '../../../server/services'; -import { ESQueueWorkerExecuteFn, ExecuteJobFactory, Logger } from '../../../types'; +import { ESQueueWorkerExecuteFn, ExecuteJobFactory } from '../../../server/types'; import { JobDocPayloadDiscoverCsv } from '../types'; import { fieldFormatMapFactory } from './lib/field_format_map'; import { createGenerateCsv } from './lib/generate_csv'; export const executeJobFactory: ExecuteJobFactory> = async function executeJobFactoryFn(reporting: ReportingCore, parentLogger: Logger) { +>> = async function executeJobFactoryFn(reporting: ReportingCore, parentLogger: LevelLogger) { const config = reporting.getConfig(); const crypto = cryptoFactory(config.get('encryptionKey')); const logger = parentLogger.clone([CSV_JOB_TYPE, 'execute-job']); diff --git a/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/escape_value.ts b/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/escape_value.ts index 60e75d74b2f98..344091ee18268 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/escape_value.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/escape_value.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { RawValue } from './types'; +import { RawValue } from '../../types'; import { cellHasFormulas } from './cell_has_formula'; const nonAlphaNumRE = /[^a-zA-Z0-9]/; diff --git a/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/field_format_map.ts b/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/field_format_map.ts index dac963635c469..e1459e195d9f6 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/field_format_map.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/field_format_map.ts @@ -9,7 +9,15 @@ import { FieldFormatConfig, IFieldFormatsRegistry, } from '../../../../../../../../src/plugins/data/server'; -import { IndexPatternSavedObject } from '../../../../types'; + +interface IndexPatternSavedObject { + attributes: { + fieldFormatMap: string; + }; + id: string; + type: string; + version: string; +} /** * Create a map of FieldFormat instances for index pattern fields diff --git a/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/format_csv_values.ts b/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/format_csv_values.ts index 0bcf0fc31beae..35093f45fdd5b 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/format_csv_values.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/format_csv_values.ts @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import { isObject, isNull, isUndefined } from 'lodash'; -import { RawValue } from './types'; +import { isNull, isObject, isUndefined } from 'lodash'; +import { RawValue } from '../../types'; export function createFormatCsvValues( escapeValue: (value: RawValue, index: number, array: RawValue[]) => string, diff --git a/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/generate_csv.ts b/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/generate_csv.ts index c7996ebf832a1..a8fdd8d1a5bbc 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/generate_csv.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/generate_csv.ts @@ -5,7 +5,7 @@ */ import { i18n } from '@kbn/i18n'; -import { Logger } from '../../../../types'; +import { LevelLogger } from '../../../../server/lib'; import { GenerateCsvParams, SavedSearchGeneratorResult } from '../../types'; import { createFlattenHit } from './flatten_hit'; import { createFormatCsvValues } from './format_csv_values'; @@ -14,7 +14,7 @@ import { createHitIterator } from './hit_iterator'; import { MaxSizeStringBuilder } from './max_size_string_builder'; import { checkIfRowsHaveFormulas } from './check_cells_for_formulas'; -export function createGenerateCsv(logger: Logger) { +export function createGenerateCsv(logger: LevelLogger) { const hitIterator = createHitIterator(logger); return async function generateCsv({ diff --git a/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/hit_iterator.test.ts b/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/hit_iterator.test.ts index a9f0015e49360..905d9cd68b128 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/hit_iterator.test.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/hit_iterator.test.ts @@ -6,16 +6,16 @@ import expect from '@kbn/expect'; import sinon from 'sinon'; -import { CancellationToken } from '../../../../common/cancellation_token'; +import { CancellationToken } from '../../../../../../../plugins/reporting/common'; +import { LevelLogger } from '../../../../server/lib'; import { ScrollConfig } from '../../../../server/types'; -import { Logger } from '../../../../types'; import { createHitIterator } from './hit_iterator'; const mockLogger = { error: new Function(), debug: new Function(), warning: new Function(), -} as Logger; +} as LevelLogger; const debugLogStub = sinon.stub(mockLogger, 'debug'); const warnLogStub = sinon.stub(mockLogger, 'warning'); const errorLogStub = sinon.stub(mockLogger, 'error'); diff --git a/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/hit_iterator.ts b/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/hit_iterator.ts index 2ca19dd07a627..803161910443e 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/hit_iterator.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/hit_iterator.ts @@ -6,8 +6,9 @@ import { i18n } from '@kbn/i18n'; import { SearchParams, SearchResponse } from 'elasticsearch'; +import { CancellationToken } from '../../../../../../../plugins/reporting/common'; +import { LevelLogger } from '../../../../server/lib'; import { ScrollConfig } from '../../../../server/types'; -import { CancellationToken, Logger } from '../../../../types'; async function parseResponse(request: SearchResponse) { const response = await request; @@ -35,7 +36,7 @@ async function parseResponse(request: SearchResponse) { }; } -export function createHitIterator(logger: Logger) { +export function createHitIterator(logger: LevelLogger) { return async function* hitIterator( scrollSettings: ScrollConfig, callEndpoint: Function, diff --git a/x-pack/legacy/plugins/reporting/export_types/csv/types.d.ts b/x-pack/legacy/plugins/reporting/export_types/csv/types.d.ts index 40a42db352635..0f6223d8553de 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv/types.d.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv/types.d.ts @@ -4,9 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -import { CancellationToken } from '../../common/cancellation_token'; -import { ScrollConfig } from '../../server/types'; -import { JobDocPayload, JobParamPostPayload } from '../../types'; +import { CancellationToken } from '../../../../../plugins/reporting/common'; +import { JobDocPayload, JobParamPostPayload, ScrollConfig } from '../../server/types'; + +export type RawValue = string | object | null | undefined; interface DocValueField { field: string; diff --git a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/index.ts b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/index.ts index 606630944c604..570b91600cbe0 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/index.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/index.ts @@ -6,25 +6,25 @@ import { CSV_FROM_SAVEDOBJECT_JOB_TYPE, - LICENSE_TYPE_TRIAL, LICENSE_TYPE_BASIC, - LICENSE_TYPE_STANDARD, + LICENSE_TYPE_ENTERPRISE, LICENSE_TYPE_GOLD, LICENSE_TYPE_PLATINUM, - LICENSE_TYPE_ENTERPRISE, + LICENSE_TYPE_STANDARD, + LICENSE_TYPE_TRIAL, } from '../../common/constants'; -import { ExportTypeDefinition, ImmediateCreateJobFn, ImmediateExecuteFn } from '../../types'; -import { createJobFactory } from './server/create_job'; -import { executeJobFactory } from './server/execute_job'; +import { ExportTypeDefinition } from '../../server/types'; import { metadata } from './metadata'; +import { createJobFactory, ImmediateCreateJobFn } from './server/create_job'; +import { executeJobFactory, ImmediateExecuteFn } from './server/execute_job'; import { JobParamsPanelCsv } from './types'; /* * These functions are exported to share with the API route handler that * generates csv from saved object immediately on request. */ -export { executeJobFactory } from './server/execute_job'; export { createJobFactory } from './server/create_job'; +export { executeJobFactory } from './server/execute_job'; export const getExportType = (): ExportTypeDefinition< JobParamsPanelCsv, diff --git a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/create_job/create_job.ts b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/create_job/create_job.ts index 8e0376a190267..ed0e17454260f 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/create_job/create_job.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/create_job/create_job.ts @@ -8,8 +8,8 @@ import { notFound, notImplemented } from 'boom'; import { get } from 'lodash'; import { CSV_FROM_SAVEDOBJECT_JOB_TYPE } from '../../../../common/constants'; import { ReportingCore } from '../../../../server'; -import { cryptoFactory } from '../../../../server/lib'; -import { CreateJobFactory, ImmediateCreateJobFn, Logger, RequestFacade } from '../../../../types'; +import { cryptoFactory, LevelLogger } from '../../../../server/lib'; +import { CreateJobFactory, RequestFacade, TimeRangeParams } from '../../../../server/types'; import { JobDocPayloadPanelCsv, JobParamsPanelCsv, @@ -17,11 +17,20 @@ import { SavedObjectServiceError, SavedSearchObjectAttributesJSON, SearchPanel, - TimeRangeParams, VisObjectAttributesJSON, } from '../../types'; import { createJobSearch } from './create_job_search'; +export type ImmediateCreateJobFn = ( + jobParams: JobParamsType, + headers: Record, + req: RequestFacade +) => Promise<{ + type: string | null; + title: string; + jobParams: JobParamsType; +}>; + interface VisData { title: string; visType: string; @@ -30,7 +39,7 @@ interface VisData { export const createJobFactory: CreateJobFactory> = function createJobFactoryFn(reporting: ReportingCore, parentLogger: Logger) { +>> = function createJobFactoryFn(reporting: ReportingCore, parentLogger: LevelLogger) { const config = reporting.getConfig(); const crypto = cryptoFactory(config.get('encryptionKey')); const logger = parentLogger.clone([CSV_FROM_SAVEDOBJECT_JOB_TYPE, 'create-job']); diff --git a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/create_job/create_job_search.ts b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/create_job/create_job_search.ts index 69ffce57489b1..19204ef81c5eb 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/create_job/create_job_search.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/create_job/create_job_search.ts @@ -4,12 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ +import { TimeRangeParams } from '../../../../server/types'; import { SavedObjectMeta, SavedObjectReference, SavedSearchObjectAttributes, SearchPanel, - TimeRangeParams, } from '../../types'; interface SearchPanelData { diff --git a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/create_job/index.ts b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/create_job/index.ts index e129e3e5f47ec..a3674d69ae6a5 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/create_job/index.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/create_job/index.ts @@ -4,4 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -export { createJobFactory } from './create_job'; +export { createJobFactory, ImmediateCreateJobFn } from './create_job'; diff --git a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/execute_job.ts b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/execute_job.ts index 8efcdc3bd9f30..5761a98ed160c 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/execute_job.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/execute_job.ts @@ -7,21 +7,30 @@ import { i18n } from '@kbn/i18n'; import { CONTENT_TYPE_CSV, CSV_FROM_SAVEDOBJECT_JOB_TYPE } from '../../../common/constants'; import { ReportingCore } from '../../../server'; -import { cryptoFactory } from '../../../server/lib'; +import { cryptoFactory, LevelLogger } from '../../../server/lib'; import { ExecuteJobFactory, - ImmediateExecuteFn, JobDocOutput, - Logger, + JobDocPayload, RequestFacade, -} from '../../../types'; +} from '../../../server/types'; import { CsvResultFromSearch } from '../../csv/types'; import { FakeRequest, JobDocPayloadPanelCsv, JobParamsPanelCsv, SearchPanel } from '../types'; import { createGenerateCsv } from './lib'; +/* + * ImmediateExecuteFn receives the job doc payload because the payload was + * generated in the CreateFn + */ +export type ImmediateExecuteFn = ( + jobId: null, + job: JobDocPayload, + request: RequestFacade +) => Promise; + export const executeJobFactory: ExecuteJobFactory> = async function executeJobFactoryFn(reporting: ReportingCore, parentLogger: Logger) { +>> = async function executeJobFactoryFn(reporting: ReportingCore, parentLogger: LevelLogger) { const config = reporting.getConfig(); const crypto = cryptoFactory(config.get('encryptionKey')); const logger = parentLogger.clone([CSV_FROM_SAVEDOBJECT_JOB_TYPE, 'execute-job']); diff --git a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/generate_csv.ts b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/generate_csv.ts index c81060d8ca05d..8dcdee7ef24c1 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/generate_csv.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/generate_csv.ts @@ -5,12 +5,13 @@ */ import { badRequest } from 'boom'; -import { ReportingCore } from '../../../../server/types'; -import { Logger, RequestFacade } from '../../../../types'; +import { ReportingCore } from '../../../../server'; +import { LevelLogger } from '../../../../server/lib'; +import { RequestFacade } from '../../../../server/types'; import { FakeRequest, JobParamsPanelCsv, SearchPanel, VisPanel } from '../../types'; import { generateCsvSearch } from './generate_csv_search'; -export function createGenerateCsv(reporting: ReportingCore, logger: Logger) { +export function createGenerateCsv(reporting: ReportingCore, logger: LevelLogger) { return async function generateCsv( request: RequestFacade | FakeRequest, visType: string, diff --git a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/generate_csv_search.ts b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/generate_csv_search.ts index 2611b74c83de9..506208e4e1aad 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/generate_csv_search.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/generate_csv_search.ts @@ -11,13 +11,11 @@ import { Filter, IIndexPattern, Query, - // Reporting uses an unconventional directory structure so the linter marks this as a violation, server files should - // be moved under reporting/server/ - // eslint-disable-next-line @kbn/eslint/no-restricted-paths } from '../../../../../../../../src/plugins/data/server'; -import { CancellationToken } from '../../../../common/cancellation_token'; +import { CancellationToken } from '../../../../../../../plugins/reporting/common'; import { ReportingCore } from '../../../../server'; -import { Logger, RequestFacade } from '../../../../types'; +import { LevelLogger } from '../../../../server/lib'; +import { RequestFacade } from '../../../../server/types'; import { createGenerateCsv } from '../../../csv/server/lib/generate_csv'; import { CsvResultFromSearch, @@ -58,7 +56,7 @@ const getUiSettings = async (config: IUiSettingsClient) => { export async function generateCsvSearch( req: RequestFacade, reporting: ReportingCore, - logger: Logger, + logger: LevelLogger, searchPanel: SearchPanel, jobParams: JobParamsDiscoverCsv ): Promise { diff --git a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/get_filters.test.ts b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/get_filters.test.ts index 1acb269e75493..110ce91ddfd79 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/get_filters.test.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/get_filters.test.ts @@ -4,12 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - QueryFilter, - SavedSearchObjectAttributes, - SearchSourceFilter, - TimeRangeParams, -} from '../../types'; +import { TimeRangeParams } from '../../../../server/types'; +import { QueryFilter, SavedSearchObjectAttributes, SearchSourceFilter } from '../../types'; import { getFilters } from './get_filters'; interface Args { diff --git a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/get_filters.ts b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/get_filters.ts index 0e510eeb4073b..071427f4dab64 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/get_filters.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/get_filters.ts @@ -6,14 +6,8 @@ import { badRequest } from 'boom'; import moment from 'moment-timezone'; - -import { - Filter, - QueryFilter, - SavedSearchObjectAttributes, - SearchSourceFilter, - TimeRangeParams, -} from '../../types'; +import { TimeRangeParams } from '../../../../server/types'; +import { Filter, QueryFilter, SavedSearchObjectAttributes, SearchSourceFilter } from '../../types'; export function getFilters( indexPatternId: string, diff --git a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/get_job_params_from_request.ts b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/get_job_params_from_request.ts index 8e5440b700d1e..57d74ee0e1383 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/get_job_params_from_request.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/server/lib/get_job_params_from_request.ts @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import { RequestFacade } from '../../../../types'; -import { JobParamsPostPayloadPanelCsv, JobParamsPanelCsv } from '../../types'; +import { RequestFacade } from '../../../../server/types'; +import { JobParamsPanelCsv, JobParamsPostPayloadPanelCsv } from '../../types'; export function getJobParamsFromRequest( request: RequestFacade, diff --git a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/types.d.ts b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/types.d.ts index ab14d2dd8a660..f838268078503 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/types.d.ts +++ b/x-pack/legacy/plugins/reporting/export_types/csv_from_savedobject/types.d.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { JobDocPayload, JobParamPostPayload } from '../../types'; +import { JobDocPayload, JobParamPostPayload, TimeRangeParams } from '../../server/types'; export interface FakeRequest { headers: Record; @@ -114,12 +114,6 @@ export interface IndexPatternSavedObject { }; } -export interface TimeRangeParams { - timezone: string; - min: Date | string | number; - max: Date | string | number; -} - export interface VisPanel { indexPatternSavedObjectId?: string; savedSearchObjectId?: string; diff --git a/x-pack/legacy/plugins/reporting/export_types/png/index.ts b/x-pack/legacy/plugins/reporting/export_types/png/index.ts index b6206a8bf9599..04f56185d4910 100644 --- a/x-pack/legacy/plugins/reporting/export_types/png/index.ts +++ b/x-pack/legacy/plugins/reporting/export_types/png/index.ts @@ -5,18 +5,22 @@ */ import { - PNG_JOB_TYPE as jobType, - LICENSE_TYPE_TRIAL, - LICENSE_TYPE_STANDARD, + LICENSE_TYPE_ENTERPRISE, LICENSE_TYPE_GOLD, LICENSE_TYPE_PLATINUM, - LICENSE_TYPE_ENTERPRISE, + LICENSE_TYPE_STANDARD, + LICENSE_TYPE_TRIAL, + PNG_JOB_TYPE as jobType, } from '../../common/constants'; -import { ExportTypeDefinition, ESQueueCreateJobFn, ESQueueWorkerExecuteFn } from '../../types'; +import { + ESQueueCreateJobFn, + ESQueueWorkerExecuteFn, + ExportTypeDefinition, +} from '../../server/types'; +import { metadata } from './metadata'; import { createJobFactory } from './server/create_job'; import { executeJobFactory } from './server/execute_job'; -import { metadata } from './metadata'; -import { JobParamsPNG, JobDocPayloadPNG } from './types'; +import { JobDocPayloadPNG, JobParamsPNG } from './types'; export const getExportType = (): ExportTypeDefinition< JobParamsPNG, diff --git a/x-pack/legacy/plugins/reporting/export_types/png/server/create_job/index.ts b/x-pack/legacy/plugins/reporting/export_types/png/server/create_job/index.ts index 1f834bde88a2d..b19513de29eee 100644 --- a/x-pack/legacy/plugins/reporting/export_types/png/server/create_job/index.ts +++ b/x-pack/legacy/plugins/reporting/export_types/png/server/create_job/index.ts @@ -6,13 +6,13 @@ import { validateUrls } from '../../../../common/validate_urls'; import { ReportingCore } from '../../../../server'; -import { cryptoFactory } from '../../../../server/lib/crypto'; +import { cryptoFactory } from '../../../../server/lib'; import { ConditionalHeaders, CreateJobFactory, ESQueueCreateJobFn, RequestFacade, -} from '../../../../types'; +} from '../../../../server/types'; import { JobParamsPNG } from '../../types'; export const createJobFactory: CreateJobFactory { const executeJob = await executeJobFactory(mockReporting, getMockLogger()); const encryptedHeaders = await encryptHeaders({}); - const generatePngObservable = (await generatePngObservableFactory(mockReporting)) as jest.Mock; - generatePngObservable.mockReturnValue(Rx.of('foo')); + const generatePngObservable = await generatePngObservableFactory(mockReporting); + (generatePngObservable as jest.Mock).mockReturnValue(Rx.of('foo')); const { content_type: contentType } = await executeJob( 'pngJobId', @@ -138,9 +137,8 @@ test(`returns content_type of application/png`, async () => { test(`returns content of generatePng getBuffer base64 encoded`, async () => { const testContent = 'raw string from get_screenhots'; - - const generatePngObservable = (await generatePngObservableFactory(mockReporting)) as jest.Mock; - generatePngObservable.mockReturnValue(Rx.of({ base64: testContent })); + const generatePngObservable = await generatePngObservableFactory(mockReporting); + (generatePngObservable as jest.Mock).mockReturnValue(Rx.of({ base64: testContent })); const executeJob = await executeJobFactory(mockReporting, getMockLogger()); const encryptedHeaders = await encryptHeaders({}); diff --git a/x-pack/legacy/plugins/reporting/export_types/png/server/execute_job/index.ts b/x-pack/legacy/plugins/reporting/export_types/png/server/execute_job/index.ts index 88c2d8a9fe4bb..c1a2c12cd9f82 100644 --- a/x-pack/legacy/plugins/reporting/export_types/png/server/execute_job/index.ts +++ b/x-pack/legacy/plugins/reporting/export_types/png/server/execute_job/index.ts @@ -9,7 +9,8 @@ import * as Rx from 'rxjs'; import { catchError, map, mergeMap, takeUntil } from 'rxjs/operators'; import { PNG_JOB_TYPE } from '../../../../common/constants'; import { ReportingCore } from '../../../../server'; -import { ESQueueWorkerExecuteFn, ExecuteJobFactory, JobDocOutput, Logger } from '../../../../types'; +import { LevelLogger } from '../../../../server/lib'; +import { ESQueueWorkerExecuteFn, ExecuteJobFactory, JobDocOutput } from '../../../../server/types'; import { decryptJobHeaders, getConditionalHeaders, @@ -23,7 +24,7 @@ type QueuedPngExecutorFactory = ExecuteJobFactory ({ generatePdfObservableFactory: jest.fn() })); + import * as Rx from 'rxjs'; -import { createMockReportingCore } from '../../../../test_helpers'; -import { cryptoFactory } from '../../../../server/lib/crypto'; -import { LevelLogger } from '../../../../server/lib'; -import { CancellationToken } from '../../../../types'; +import { CancellationToken } from '../../../../../../../plugins/reporting/common'; import { ReportingCore } from '../../../../server'; -import { generatePdfObservableFactory } from '../lib/generate_pdf'; +import { cryptoFactory, LevelLogger } from '../../../../server/lib'; +import { createMockReportingCore } from '../../../../test_helpers'; import { JobDocPayloadPDF } from '../../types'; +import { generatePdfObservableFactory } from '../lib/generate_pdf'; import { executeJobFactory } from './index'; -jest.mock('../lib/generate_pdf', () => ({ generatePdfObservableFactory: jest.fn() })); - let mockReporting: ReportingCore; const cancellationToken = ({ @@ -44,6 +43,7 @@ beforeEach(async () => { 'server.basePath': '/sbp', }; const reportingConfig = { + index: '.reports-test', encryptionKey: mockEncryptionKey, 'kibanaServer.hostname': 'localhost', 'kibanaServer.port': 5601, diff --git a/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/execute_job/index.ts b/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/execute_job/index.ts index 5aad66c53a998..619e3e9db70ad 100644 --- a/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/execute_job/index.ts +++ b/x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/execute_job/index.ts @@ -9,7 +9,8 @@ import * as Rx from 'rxjs'; import { catchError, map, mergeMap, takeUntil } from 'rxjs/operators'; import { PDF_JOB_TYPE } from '../../../../common/constants'; import { ReportingCore } from '../../../../server'; -import { ESQueueWorkerExecuteFn, ExecuteJobFactory, JobDocOutput, Logger } from '../../../../types'; +import { LevelLogger } from '../../../../server/lib'; +import { ESQueueWorkerExecuteFn, ExecuteJobFactory, JobDocOutput } from '../../../../server/types'; import { decryptJobHeaders, getConditionalHeaders, @@ -24,7 +25,7 @@ type QueuedPdfExecutorFactory = ExecuteJobFactory { const grouped = groupBy(urlScreenshots.map(u => u.timeRange)); @@ -62,7 +60,7 @@ export async function generatePdfObservableFactory(reporting: ReportingCore) { const pdfOutput = pdf.create(layout, logo); if (title) { const timeRange = getTimeRange(results); - title += timeRange ? ` - ${timeRange.duration}` : ''; + title += timeRange ? ` - ${timeRange}` : ''; pdfOutput.setTitle(title); } tracker.endSetup(); diff --git a/x-pack/legacy/plugins/reporting/export_types/printable_pdf/types.d.ts b/x-pack/legacy/plugins/reporting/export_types/printable_pdf/types.d.ts index e8dd3c5207d92..0df01fdc16d1c 100644 --- a/x-pack/legacy/plugins/reporting/export_types/printable_pdf/types.d.ts +++ b/x-pack/legacy/plugins/reporting/export_types/printable_pdf/types.d.ts @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import { JobDocPayload } from '../../types'; -import { LayoutInstance, LayoutParams } from '../common/layouts/layout'; +import { JobDocPayload } from '../../server/types'; +import { LayoutInstance, LayoutParams } from '../common/layouts'; // Job params: structure of incoming user request data, after being parsed from RISON export interface JobParamsPDF { diff --git a/x-pack/legacy/plugins/reporting/index.ts b/x-pack/legacy/plugins/reporting/index.ts index fb95e2c2edc24..1ae971b6566b0 100644 --- a/x-pack/legacy/plugins/reporting/index.ts +++ b/x-pack/legacy/plugins/reporting/index.ts @@ -9,7 +9,8 @@ import { Legacy } from 'kibana'; import { resolve } from 'path'; import { PLUGIN_ID, UI_SETTINGS_CUSTOM_PDF_LOGO } from './common/constants'; import { legacyInit } from './server/legacy'; -import { ReportingPluginSpecOptions } from './types'; + +export type ReportingPluginSpecOptions = Legacy.PluginSpecOptions; const kbToBase64Length = (kb: number) => Math.floor((kb * 1024 * 8) / 6); diff --git a/x-pack/legacy/plugins/reporting/server/browsers/chromium/driver/chromium_driver.ts b/x-pack/legacy/plugins/reporting/server/browsers/chromium/driver/chromium_driver.ts index dd20e849d97a9..3dce8bf4e6819 100644 --- a/x-pack/legacy/plugins/reporting/server/browsers/chromium/driver/chromium_driver.ts +++ b/x-pack/legacy/plugins/reporting/server/browsers/chromium/driver/chromium_driver.ts @@ -7,18 +7,12 @@ import { i18n } from '@kbn/i18n'; import { map, trunc } from 'lodash'; import open from 'opn'; -import { ElementHandle, EvaluateFn, Page, SerializableOrJSHandle, Response } from 'puppeteer'; +import { ElementHandle, EvaluateFn, Page, Response, SerializableOrJSHandle } from 'puppeteer'; import { parse as parseUrl } from 'url'; import { ViewZoomWidthHeight } from '../../../../export_types/common/layouts/layout'; -import { LevelLogger } from '../../../../server/lib'; -import { - ConditionalHeaders, - ConditionalHeadersConditions, - ElementPosition, - InterceptedRequest, - NetworkPolicy, -} from '../../../../types'; -import { allowRequest } from '../../network_policy'; +import { LevelLogger } from '../../../lib'; +import { ConditionalHeaders, ElementPosition } from '../../../types'; +import { allowRequest, NetworkPolicy } from '../../network_policy'; export interface ChromiumDriverOptions { inspect: boolean; @@ -38,6 +32,23 @@ interface EvaluateMetaOpts { context: string; } +type ConditionalHeadersConditions = ConditionalHeaders['conditions']; + +interface InterceptedRequest { + requestId: string; + request: { + url: string; + method: string; + headers: { + [key: string]: string; + }; + initialPriority: string; + referrerPolicy: string; + }; + frameId: string; + resourceType: string; +} + const WAIT_FOR_DELAY_MS: number = 100; export class HeadlessChromiumDriver { diff --git a/x-pack/legacy/plugins/reporting/server/browsers/chromium/driver_factory/index.ts b/x-pack/legacy/plugins/reporting/server/browsers/chromium/driver_factory/index.ts index cb228150efbcd..3189b262ea1bd 100644 --- a/x-pack/legacy/plugins/reporting/server/browsers/chromium/driver_factory/index.ts +++ b/x-pack/legacy/plugins/reporting/server/browsers/chromium/driver_factory/index.ts @@ -21,7 +21,7 @@ import { InnerSubscriber } from 'rxjs/internal/InnerSubscriber'; import { ignoreElements, map, mergeMap, tap } from 'rxjs/operators'; import { BROWSER_TYPE } from '../../../../common/constants'; import { CaptureConfig } from '../../../../server/types'; -import { LevelLogger as Logger } from '../../../lib/level_logger'; +import { LevelLogger } from '../../../lib'; import { safeChildProcess } from '../../safe_child_process'; import { HeadlessChromiumDriver } from '../driver'; import { getChromeLogLocation } from '../paths'; @@ -39,7 +39,7 @@ export class HeadlessChromiumDriverFactory { private userDataDir: string; private getChromiumArgs: (viewport: ViewportConfig) => string[]; - constructor(binaryPath: binaryPath, logger: Logger, captureConfig: CaptureConfig) { + constructor(binaryPath: binaryPath, logger: LevelLogger, captureConfig: CaptureConfig) { this.binaryPath = binaryPath; this.captureConfig = captureConfig; this.browserConfig = captureConfig.browser.chromium; @@ -56,7 +56,7 @@ export class HeadlessChromiumDriverFactory { type = BROWSER_TYPE; - test(logger: Logger) { + test(logger: LevelLogger) { const chromiumArgs = args({ userDataDir: this.userDataDir, viewport: { width: 800, height: 600 }, @@ -84,7 +84,7 @@ export class HeadlessChromiumDriverFactory { */ createPage( { viewport, browserTimezone }: { viewport: ViewportConfig; browserTimezone: string }, - pLogger: Logger + pLogger: LevelLogger ): Rx.Observable<{ driver: HeadlessChromiumDriver; exit$: Rx.Observable }> { return Rx.Observable.create(async (observer: InnerSubscriber) => { const logger = pLogger.clone(['browser-driver']); @@ -172,7 +172,7 @@ export class HeadlessChromiumDriverFactory { }); } - getBrowserLogger(page: Page, logger: Logger): Rx.Observable { + getBrowserLogger(page: Page, logger: LevelLogger): Rx.Observable { const consoleMessages$ = Rx.fromEvent(page, 'console').pipe( map(line => { if (line.type() === 'error') { @@ -197,7 +197,7 @@ export class HeadlessChromiumDriverFactory { return Rx.merge(consoleMessages$, pageRequestFailed$); } - getProcessLogger(browser: Browser, logger: Logger): Rx.Observable { + getProcessLogger(browser: Browser, logger: LevelLogger): Rx.Observable { const childProcess = browser.process(); // NOTE: The browser driver can not observe stdout and stderr of the child process // Puppeteer doesn't give a handle to the original ChildProcess object diff --git a/x-pack/legacy/plugins/reporting/server/browsers/create_browser_driver_factory.ts b/x-pack/legacy/plugins/reporting/server/browsers/create_browser_driver_factory.ts index af3b86919dc50..7b4407890652c 100644 --- a/x-pack/legacy/plugins/reporting/server/browsers/create_browser_driver_factory.ts +++ b/x-pack/legacy/plugins/reporting/server/browsers/create_browser_driver_factory.ts @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Logger } from '../../types'; -import { ReportingConfig } from '../types'; +import { ReportingConfig } from '../'; +import { LevelLogger } from '../lib'; import { HeadlessChromiumDriverFactory } from './chromium/driver_factory'; import { ensureBrowserDownloaded } from './download'; import { chromium } from './index'; @@ -13,7 +13,7 @@ import { installBrowser } from './install'; export async function createBrowserDriverFactory( config: ReportingConfig, - logger: Logger + logger: LevelLogger ): Promise { const captureConfig = config.get('capture'); const browserConfig = captureConfig.browser.chromium; diff --git a/x-pack/legacy/plugins/reporting/server/browsers/download/ensure_downloaded.ts b/x-pack/legacy/plugins/reporting/server/browsers/download/ensure_downloaded.ts index 3697c4b86ce3c..1170e53669e33 100644 --- a/x-pack/legacy/plugins/reporting/server/browsers/download/ensure_downloaded.ts +++ b/x-pack/legacy/plugins/reporting/server/browsers/download/ensure_downloaded.ts @@ -6,9 +6,8 @@ import { existsSync } from 'fs'; import { resolve as resolvePath } from 'path'; +import { BrowserDownload, chromium } from '../'; import { BROWSER_TYPE } from '../../../common/constants'; -import { chromium } from '../index'; -import { BrowserDownload } from '../types'; import { md5 } from './checksum'; import { clean } from './clean'; import { download } from './download'; diff --git a/x-pack/legacy/plugins/reporting/server/browsers/index.ts b/x-pack/legacy/plugins/reporting/server/browsers/index.ts index 7f902c84308f6..7f6e40fb433b6 100644 --- a/x-pack/legacy/plugins/reporting/server/browsers/index.ts +++ b/x-pack/legacy/plugins/reporting/server/browsers/index.ts @@ -16,3 +16,17 @@ export const chromium = { paths: chromiumDefinition.paths, createDriverFactory: chromiumDefinition.createDriverFactory, }; + +export interface BrowserDownload { + paths: { + archivesPath: string; + baseUrl: string; + packages: Array<{ + archiveChecksum: string; + archiveFilename: string; + binaryChecksum: string; + binaryRelativePath: string; + platforms: string[]; + }>; + }; +} diff --git a/x-pack/legacy/plugins/reporting/server/browsers/install.ts b/x-pack/legacy/plugins/reporting/server/browsers/install.ts index 6f099c36e69f2..01526af307022 100644 --- a/x-pack/legacy/plugins/reporting/server/browsers/install.ts +++ b/x-pack/legacy/plugins/reporting/server/browsers/install.ts @@ -7,12 +7,12 @@ import fs from 'fs'; import path from 'path'; import { promisify } from 'util'; -import { LevelLogger as Logger } from '../lib/level_logger'; -// @ts-ignore -import { extract } from './extract'; +import { LevelLogger } from '../lib'; +import { BrowserDownload } from './'; // @ts-ignore import { md5 } from './download/checksum'; -import { BrowserDownload } from './types'; +// @ts-ignore +import { extract } from './extract'; const chmod = promisify(fs.chmod); @@ -28,7 +28,7 @@ interface PathResponse { * archive. If there is an error extracting the archive an `ExtractError` is thrown */ export async function installBrowser( - logger: Logger, + logger: LevelLogger, browser: BrowserDownload, installsPath: string ): Promise { diff --git a/x-pack/legacy/plugins/reporting/server/browsers/network_policy.ts b/x-pack/legacy/plugins/reporting/server/browsers/network_policy.ts index 9714c5965a5db..158362cee3c7e 100644 --- a/x-pack/legacy/plugins/reporting/server/browsers/network_policy.ts +++ b/x-pack/legacy/plugins/reporting/server/browsers/network_policy.ts @@ -6,7 +6,17 @@ import * as _ from 'lodash'; import { parse } from 'url'; -import { NetworkPolicyRule } from '../../types'; + +interface NetworkPolicyRule { + allow: boolean; + protocol?: string; + host?: string; +} + +export interface NetworkPolicy { + enabled: boolean; + rules: NetworkPolicyRule[]; +} const isHostMatch = (actualHost: string, ruleHost: string) => { const hostParts = actualHost.split('.').reverse(); diff --git a/x-pack/legacy/plugins/reporting/server/browsers/safe_child_process.ts b/x-pack/legacy/plugins/reporting/server/browsers/safe_child_process.ts index e22d3662a33b4..6f86a62c21575 100644 --- a/x-pack/legacy/plugins/reporting/server/browsers/safe_child_process.ts +++ b/x-pack/legacy/plugins/reporting/server/browsers/safe_child_process.ts @@ -6,7 +6,7 @@ import * as Rx from 'rxjs'; import { take, share, mapTo, delay, tap } from 'rxjs/operators'; -import { Logger } from '../../types'; +import { LevelLogger } from '../lib'; interface IChild { kill: (signal: string) => Promise; @@ -15,7 +15,7 @@ interface IChild { // Our process can get sent various signals, and when these occur we wish to // kill the subprocess and then kill our process as long as the observer isn't cancelled export function safeChildProcess( - logger: Logger, + logger: LevelLogger, childProcess: IChild ): { terminate$: Rx.Observable } { const ownTerminateSignal$ = Rx.merge( diff --git a/x-pack/legacy/plugins/reporting/server/browsers/types.d.ts b/x-pack/legacy/plugins/reporting/server/browsers/types.d.ts deleted file mode 100644 index f096073ec2f5f..0000000000000 --- a/x-pack/legacy/plugins/reporting/server/browsers/types.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -export interface BrowserDownload { - paths: { - archivesPath: string; - baseUrl: string; - packages: Array<{ - archiveChecksum: string; - archiveFilename: string; - binaryChecksum: string; - binaryRelativePath: string; - platforms: string[]; - }>; - }; -} diff --git a/x-pack/legacy/plugins/reporting/server/config/index.ts b/x-pack/legacy/plugins/reporting/server/config/index.ts index c6b915be3a94a..3ec5aab4d451b 100644 --- a/x-pack/legacy/plugins/reporting/server/config/index.ts +++ b/x-pack/legacy/plugins/reporting/server/config/index.ts @@ -5,10 +5,9 @@ */ import { Legacy } from 'kibana'; -import { CoreSetup } from 'src/core/server'; import { get } from 'lodash'; +import { CoreSetup } from 'src/core/server'; import { ConfigType as ReportingConfigType } from '../../../../../plugins/reporting/server'; -export { ReportingConfigType }; // make config.get() aware of the value type it returns interface Config { @@ -85,3 +84,5 @@ export const buildConfig = ( }, }; }; + +export { ReportingConfigType }; diff --git a/x-pack/legacy/plugins/reporting/server/core.ts b/x-pack/legacy/plugins/reporting/server/core.ts index 0b243f13adb80..8fb948a253c16 100644 --- a/x-pack/legacy/plugins/reporting/server/core.ts +++ b/x-pack/legacy/plugins/reporting/server/core.ts @@ -8,26 +8,25 @@ import * as Rx from 'rxjs'; import { first, mapTo } from 'rxjs/operators'; import { ElasticsearchServiceSetup, - IUiSettingsClient, KibanaRequest, SavedObjectsClient, SavedObjectsServiceStart, UiSettingsServiceStart, } from 'src/core/server'; +import { ReportingPluginSpecOptions } from '../'; // @ts-ignore no module definition import { mirrorPluginStatus } from '../../../server/lib/mirror_plugin_status'; import { XPackMainPlugin } from '../../xpack_main/server/xpack_main'; import { PLUGIN_ID } from '../common/constants'; -import { EnqueueJobFn, ESQueueInstance, ReportingPluginSpecOptions, ServerFacade } from '../types'; +import { screenshotsObservableFactory } from '../export_types/common/lib/screenshots'; +import { ServerFacade } from '../server/types'; +import { ReportingConfig } from './'; import { HeadlessChromiumDriverFactory } from './browsers/chromium/driver_factory'; -import { ReportingConfig, ReportingConfigType } from './config'; import { checkLicenseFactory, getExportTypesRegistry, LevelLogger } from './lib'; +import { ESQueueInstance } from './lib/create_queue'; +import { EnqueueJobFn } from './lib/enqueue_job'; import { registerRoutes } from './routes'; import { ReportingSetupDeps } from './types'; -import { - screenshotsObservableFactory, - ScreenshotsObservableFn, -} from '../export_types/common/lib/screenshots'; interface ReportingInternalSetup { browserDriverFactory: HeadlessChromiumDriverFactory; @@ -40,8 +39,6 @@ interface ReportingInternalStart { uiSettings: UiSettingsServiceStart; } -export { ReportingConfig, ReportingConfigType }; - export class ReportingCore { private pluginSetupDeps?: ReportingInternalSetup; private pluginStartDeps?: ReportingInternalStart; @@ -91,18 +88,18 @@ export class ReportingCore { return this.exportTypesRegistry; } - public async getEsqueue(): Promise { + public async getEsqueue() { return (await this.getPluginStartDeps()).esqueue; } - public async getEnqueueJob(): Promise { + public async getEnqueueJob() { return (await this.getPluginStartDeps()).enqueueJob; } - public getConfig(): ReportingConfig { + public getConfig() { return this.config; } - public async getScreenshotsObservable(): Promise { + public async getScreenshotsObservable() { const { browserDriverFactory } = await this.getPluginSetupDeps(); return screenshotsObservableFactory(this.config.get('capture'), browserDriverFactory); } @@ -110,32 +107,30 @@ export class ReportingCore { /* * Outside dependencies */ - private async getPluginSetupDeps(): Promise { + private async getPluginSetupDeps() { if (this.pluginSetupDeps) { return this.pluginSetupDeps; } return await this.pluginSetup$.pipe(first()).toPromise(); } - private async getPluginStartDeps(): Promise { + private async getPluginStartDeps() { if (this.pluginStartDeps) { return this.pluginStartDeps; } return await this.pluginStart$.pipe(first()).toPromise(); } - public async getElasticsearchService(): Promise { + public async getElasticsearchService() { return (await this.getPluginSetupDeps()).elasticsearch; } - public async getSavedObjectsClient(fakeRequest: KibanaRequest): Promise { + public async getSavedObjectsClient(fakeRequest: KibanaRequest) { const { savedObjects } = await this.getPluginStartDeps(); return savedObjects.getScopedClient(fakeRequest) as SavedObjectsClient; } - public async getUiSettingsServiceFactory( - savedObjectsClient: SavedObjectsClient - ): Promise { + public async getUiSettingsServiceFactory(savedObjectsClient: SavedObjectsClient) { const { uiSettings: uiSettingsService } = await this.getPluginStartDeps(); const scopedUiSettingsService = uiSettingsService.asScopedToClient(savedObjectsClient); return scopedUiSettingsService; diff --git a/x-pack/legacy/plugins/reporting/server/index.ts b/x-pack/legacy/plugins/reporting/server/index.ts index 4288a37fe6adc..2388eac48f8cc 100644 --- a/x-pack/legacy/plugins/reporting/server/index.ts +++ b/x-pack/legacy/plugins/reporting/server/index.ts @@ -5,8 +5,9 @@ */ import { PluginInitializerContext } from 'src/core/server'; +import { ReportingConfig } from './config'; +import { ReportingCore } from './core'; import { ReportingPlugin as Plugin } from './plugin'; -import { ReportingConfig, ReportingCore } from './core'; export const plugin = (context: PluginInitializerContext, config: ReportingConfig) => { return new Plugin(context, config); @@ -14,5 +15,3 @@ export const plugin = (context: PluginInitializerContext, config: ReportingConfi export { ReportingPlugin } from './plugin'; export { ReportingConfig, ReportingCore }; - -export { PreserveLayout, PrintLayout } from '../export_types/common/layouts'; diff --git a/x-pack/legacy/plugins/reporting/server/legacy.ts b/x-pack/legacy/plugins/reporting/server/legacy.ts index d044dc866ed0e..87ffe75e454b1 100644 --- a/x-pack/legacy/plugins/reporting/server/legacy.ts +++ b/x-pack/legacy/plugins/reporting/server/legacy.ts @@ -7,9 +7,9 @@ import { Legacy } from 'kibana'; import { take } from 'rxjs/operators'; import { PluginInitializerContext } from 'src/core/server'; +import { ReportingPluginSpecOptions } from '../'; import { PluginsSetup } from '../../../../plugins/reporting/server'; import { SecurityPluginSetup } from '../../../../plugins/security/server'; -import { ReportingPluginSpecOptions } from '../types'; import { buildConfig } from './config'; import { plugin } from './index'; import { LegacySetup, ReportingStartDeps } from './types'; diff --git a/x-pack/legacy/plugins/reporting/server/lib/check_license.ts b/x-pack/legacy/plugins/reporting/server/lib/check_license.ts index 02e1196f1d00d..b25021c2ed09b 100644 --- a/x-pack/legacy/plugins/reporting/server/lib/check_license.ts +++ b/x-pack/legacy/plugins/reporting/server/lib/check_license.ts @@ -6,7 +6,8 @@ import { XPackInfo } from '../../../xpack_main/server/lib/xpack_info'; import { XPackInfoLicense } from '../../../xpack_main/server/lib/xpack_info_license'; -import { ExportTypesRegistry, ExportTypeDefinition } from '../../types'; +import { ExportTypeDefinition } from '../types'; +import { ExportTypesRegistry } from './export_types_registry'; interface LicenseCheckResult { showLinks: boolean; diff --git a/x-pack/legacy/plugins/reporting/server/lib/create_queue.ts b/x-pack/legacy/plugins/reporting/server/lib/create_queue.ts index 560cc943ed45e..2cac4bd654487 100644 --- a/x-pack/legacy/plugins/reporting/server/lib/create_queue.ts +++ b/x-pack/legacy/plugins/reporting/server/lib/create_queue.ts @@ -4,16 +4,42 @@ * you may not use this file except in compliance with the Elastic License. */ -import { ESQueueInstance, Logger } from '../../types'; import { ReportingCore } from '../core'; +import { JobDocOutput, JobSource } from '../types'; import { createTaggedLogger } from './create_tagged_logger'; // TODO remove createTaggedLogger once esqueue is removed import { createWorkerFactory } from './create_worker'; +import { Job } from './enqueue_job'; // @ts-ignore import { Esqueue } from './esqueue'; +import { LevelLogger } from './level_logger'; + +interface ESQueueWorker { + on: (event: string, handler: any) => void; +} + +export interface ESQueueInstance { + addJob: (type: string, payload: unknown, options: object) => Job; + registerWorker: ( + pluginId: string, + workerFn: GenericWorkerFn, + workerOptions: { + kibanaName: string; + kibanaId: string; + interval: number; + intervalErrorMultiplier: number; + } + ) => ESQueueWorker; +} + +// GenericWorkerFn is a generic for ImmediateExecuteFn | ESQueueWorkerExecuteFn, +type GenericWorkerFn = ( + jobSource: JobSource, + ...workerRestArgs: any[] +) => void | Promise; export async function createQueueFactory( reporting: ReportingCore, - logger: Logger + logger: LevelLogger ): Promise { const config = reporting.getConfig(); const queueIndexInterval = config.get('queue', 'indexInterval'); diff --git a/x-pack/legacy/plugins/reporting/server/lib/create_tagged_logger.ts b/x-pack/legacy/plugins/reporting/server/lib/create_tagged_logger.ts index 97b34dfe40830..aaed46e629ccc 100644 --- a/x-pack/legacy/plugins/reporting/server/lib/create_tagged_logger.ts +++ b/x-pack/legacy/plugins/reporting/server/lib/create_tagged_logger.ts @@ -4,9 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Logger } from '../../types'; +import { LevelLogger } from './level_logger'; -export function createTaggedLogger(logger: Logger, tags: string[]) { +export function createTaggedLogger(logger: LevelLogger, tags: string[]) { return (msg: string, additionalTags = []) => { const allTags = [...tags, ...additionalTags]; diff --git a/x-pack/legacy/plugins/reporting/server/lib/create_worker.test.ts b/x-pack/legacy/plugins/reporting/server/lib/create_worker.test.ts index ad8db3201844e..1193091075e3e 100644 --- a/x-pack/legacy/plugins/reporting/server/lib/create_worker.test.ts +++ b/x-pack/legacy/plugins/reporting/server/lib/create_worker.test.ts @@ -5,7 +5,7 @@ */ import * as sinon from 'sinon'; -import { ReportingConfig, ReportingCore } from '../../server/types'; +import { ReportingConfig, ReportingCore } from '../../server'; import { createMockReportingCore } from '../../test_helpers'; import { createWorkerFactory } from './create_worker'; // @ts-ignore diff --git a/x-pack/legacy/plugins/reporting/server/lib/create_worker.ts b/x-pack/legacy/plugins/reporting/server/lib/create_worker.ts index ad0f05c02a1f4..57bd61aee7195 100644 --- a/x-pack/legacy/plugins/reporting/server/lib/create_worker.ts +++ b/x-pack/legacy/plugins/reporting/server/lib/create_worker.ts @@ -4,20 +4,16 @@ * you may not use this file except in compliance with the Elastic License. */ -import { CancellationToken } from '../../common/cancellation_token'; +import { CancellationToken } from '../../../../../plugins/reporting/common'; import { PLUGIN_ID } from '../../common/constants'; -import { ReportingCore } from '../../server/types'; -import { - ESQueueInstance, - ESQueueWorkerExecuteFn, - ExportTypeDefinition, - JobSource, - Logger, -} from '../../types'; +import { ReportingCore } from '../../server'; +import { LevelLogger } from '../../server/lib'; +import { ESQueueWorkerExecuteFn, ExportTypeDefinition, JobSource } from '../../server/types'; +import { ESQueueInstance } from './create_queue'; // @ts-ignore untyped dependency import { events as esqueueEvents } from './esqueue'; -export function createWorkerFactory(reporting: ReportingCore, logger: Logger) { +export function createWorkerFactory(reporting: ReportingCore, logger: LevelLogger) { const config = reporting.getConfig(); const queueConfig = config.get('queue'); const kibanaName = config.kbnConfig.get('server', 'name'); diff --git a/x-pack/legacy/plugins/reporting/server/lib/enqueue_job.ts b/x-pack/legacy/plugins/reporting/server/lib/enqueue_job.ts index 8f33d9b73566c..8ffb99f7a14c8 100644 --- a/x-pack/legacy/plugins/reporting/server/lib/enqueue_job.ts +++ b/x-pack/legacy/plugins/reporting/server/lib/enqueue_job.ts @@ -4,18 +4,13 @@ * you may not use this file except in compliance with the Elastic License. */ +import { EventEmitter } from 'events'; import { get } from 'lodash'; -import { - ConditionalHeaders, - EnqueueJobFn, - ESQueueCreateJobFn, - Job, - Logger, - RequestFacade, -} from '../../types'; +import { ConditionalHeaders, ESQueueCreateJobFn, RequestFacade } from '../../server/types'; import { ReportingCore } from '../core'; // @ts-ignore import { events as esqueueEvents } from './esqueue'; +import { LevelLogger } from './level_logger'; interface ConfirmedJob { id: string; @@ -24,7 +19,25 @@ interface ConfirmedJob { _primary_term: number; } -export function enqueueJobFactory(reporting: ReportingCore, parentLogger: Logger): EnqueueJobFn { +export type Job = EventEmitter & { + id: string; + toJSON: () => { + id: string; + }; +}; + +export type EnqueueJobFn = ( + exportTypeId: string, + jobParams: JobParamsType, + user: string, + headers: Record, + request: RequestFacade +) => Promise; + +export function enqueueJobFactory( + reporting: ReportingCore, + parentLogger: LevelLogger +): EnqueueJobFn { const config = reporting.getConfig(); const queueTimeout = config.get('queue', 'timeout'); const browserType = config.get('capture', 'browser', 'type'); diff --git a/x-pack/legacy/plugins/reporting/server/lib/esqueue/__tests__/helpers/cancellation_token.js b/x-pack/legacy/plugins/reporting/server/lib/esqueue/__tests__/helpers/cancellation_token.js deleted file mode 100644 index 4b77b936db8a8..0000000000000 --- a/x-pack/legacy/plugins/reporting/server/lib/esqueue/__tests__/helpers/cancellation_token.js +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import expect from '@kbn/expect'; -import sinon from 'sinon'; -import { CancellationToken } from '../../../../../common/cancellation_token'; - -describe('CancellationToken', function() { - let cancellationToken; - beforeEach(function() { - cancellationToken = new CancellationToken(); - }); - - describe('on', function() { - [true, null, undefined, 1, 'string', {}, []].forEach(function(value) { - it(`should throw an Error if value is ${value}`, function() { - expect(cancellationToken.on) - .withArgs(value) - .to.throwError(); - }); - }); - - it('accepts a function', function() { - expect(cancellationToken.on) - .withArgs(function() {}) - .not.to.throwError(); - }); - - it(`calls function if cancel has previously been called`, function() { - const spy = sinon.spy(); - cancellationToken.cancel(); - cancellationToken.on(spy); - expect(spy.calledOnce).to.be(true); - }); - }); - - describe('cancel', function() { - it('should be a function accepting no parameters', function() { - expect(cancellationToken.cancel) - .withArgs() - .to.not.throwError(); - }); - - it('should call a single callback', function() { - const spy = sinon.spy(); - cancellationToken.on(spy); - cancellationToken.cancel(); - expect(spy.calledOnce).to.be(true); - }); - - it('should call two callbacks', function() { - const spy1 = sinon.spy(); - const spy2 = sinon.spy(); - cancellationToken.on(spy1); - cancellationToken.on(spy2); - cancellationToken.cancel(); - expect(spy1.calledOnce).to.be(true); - expect(spy2.calledOnce).to.be(true); - }); - }); - - describe('isCancelled', function() { - it('should default to false', function() { - expect(cancellationToken.isCancelled()).to.be(false); - }); - - it('should switch to true after call to cancel', function() { - cancellationToken.cancel(); - expect(cancellationToken.isCancelled()).to.be(true); - }); - }); -}); diff --git a/x-pack/legacy/plugins/reporting/server/lib/esqueue/worker.js b/x-pack/legacy/plugins/reporting/server/lib/esqueue/worker.js index ab0bb6740f078..17a7fd0e9a26f 100644 --- a/x-pack/legacy/plugins/reporting/server/lib/esqueue/worker.js +++ b/x-pack/legacy/plugins/reporting/server/lib/esqueue/worker.js @@ -5,12 +5,12 @@ */ import events from 'events'; -import Puid from 'puid'; import moment from 'moment'; -import { constants } from './constants'; -import { WorkerTimeoutError, UnspecifiedWorkerError } from './helpers/errors'; -import { CancellationToken } from '../../../common/cancellation_token'; +import Puid from 'puid'; +import { CancellationToken } from '../../../../../../plugins/reporting/common'; import { Poller } from '../../../../../common/poller'; +import { constants } from './constants'; +import { UnspecifiedWorkerError, WorkerTimeoutError } from './helpers/errors'; const puid = new Puid(); diff --git a/x-pack/legacy/plugins/reporting/server/lib/export_types_registry.ts b/x-pack/legacy/plugins/reporting/server/lib/export_types_registry.ts index d553cc07ae3ef..ecaabb305e23e 100644 --- a/x-pack/legacy/plugins/reporting/server/lib/export_types_registry.ts +++ b/x-pack/legacy/plugins/reporting/server/lib/export_types_registry.ts @@ -4,13 +4,13 @@ * you may not use this file except in compliance with the Elastic License. */ -import memoizeOne from 'memoize-one'; import { isString } from 'lodash'; +import memoizeOne from 'memoize-one'; import { getExportType as getTypeCsv } from '../../export_types/csv'; import { getExportType as getTypeCsvFromSavedObject } from '../../export_types/csv_from_savedobject'; import { getExportType as getTypePng } from '../../export_types/png'; import { getExportType as getTypePrintablePdf } from '../../export_types/printable_pdf'; -import { ExportTypeDefinition } from '../../types'; +import { ExportTypeDefinition } from '../types'; type GetCallbackFn = ( item: ExportTypeDefinition diff --git a/x-pack/legacy/plugins/reporting/server/lib/get_user.ts b/x-pack/legacy/plugins/reporting/server/lib/get_user.ts index 5e73fe77ecb79..8e8b1c83d5a40 100644 --- a/x-pack/legacy/plugins/reporting/server/lib/get_user.ts +++ b/x-pack/legacy/plugins/reporting/server/lib/get_user.ts @@ -6,10 +6,10 @@ import { Legacy } from 'kibana'; import { KibanaRequest } from '../../../../../../src/core/server'; -import { Logger } from '../../types'; import { ReportingSetupDeps } from '../types'; +import { LevelLogger } from './level_logger'; -export function getUserFactory(security: ReportingSetupDeps['security'], logger: Logger) { +export function getUserFactory(security: ReportingSetupDeps['security'], logger: LevelLogger) { /* * Legacy.Request because this is called from routing middleware */ diff --git a/x-pack/legacy/plugins/reporting/server/lib/jobs_query.ts b/x-pack/legacy/plugins/reporting/server/lib/jobs_query.ts index 0affc111c1368..e0c9fc05ea2b4 100644 --- a/x-pack/legacy/plugins/reporting/server/lib/jobs_query.ts +++ b/x-pack/legacy/plugins/reporting/server/lib/jobs_query.ts @@ -9,8 +9,8 @@ import Boom from 'boom'; import { errors as elasticsearchErrors } from 'elasticsearch'; import { ElasticsearchServiceSetup } from 'kibana/server'; import { get } from 'lodash'; -import { JobSource } from '../../types'; -import { ReportingConfig } from '../types'; +import { ReportingConfig } from '../'; +import { JobSource } from '../types'; const esErrors = elasticsearchErrors as Record; const defaultSize = 10; diff --git a/x-pack/legacy/plugins/reporting/server/lib/once_per_server.ts b/x-pack/legacy/plugins/reporting/server/lib/once_per_server.ts deleted file mode 100644 index ae3636079a9bb..0000000000000 --- a/x-pack/legacy/plugins/reporting/server/lib/once_per_server.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { memoize, MemoizedFunction } from 'lodash'; -import { ServerFacade } from '../../types'; - -type ServerFn = (server: ServerFacade) => any; -type Memo = ((server: ServerFacade) => any) & MemoizedFunction; - -/** - * allow this function to be called multiple times, but - * ensure that it only received one argument, the server, - * and cache the return value so that subsequent calls get - * the exact same value. - * - * This is intended to be used by service factories like getObjectQueueFactory - * - * @param {Function} fn - the factory function - * @return {any} - */ -export function oncePerServer(fn: ServerFn) { - const memoized: Memo = memoize(function(server: ServerFacade) { - if (arguments.length !== 1) { - throw new TypeError('This function expects to be called with a single argument'); - } - - // @ts-ignore - return fn.call(this, server); - }); - - // @ts-ignore - // Type 'WeakMap' is not assignable to type 'MapCache - - // use a weak map a the cache so that: - // 1. return values mapped to the actual server instance - // 2. return value lifecycle matches that of the server - memoized.cache = new WeakMap(); - - return memoized; -} diff --git a/x-pack/legacy/plugins/reporting/server/lib/validate/index.ts b/x-pack/legacy/plugins/reporting/server/lib/validate/index.ts index 85d9f727d7fa7..404cbcda31a09 100644 --- a/x-pack/legacy/plugins/reporting/server/lib/validate/index.ts +++ b/x-pack/legacy/plugins/reporting/server/lib/validate/index.ts @@ -6,9 +6,9 @@ import { i18n } from '@kbn/i18n'; import { ElasticsearchServiceSetup } from 'kibana/server'; -import { Logger } from '../../../types'; +import { ReportingConfig } from '../../'; +import { LevelLogger } from '../../lib'; import { HeadlessChromiumDriverFactory } from '../../browsers/chromium/driver_factory'; -import { ReportingConfig } from '../../types'; import { validateBrowser } from './validate_browser'; import { validateMaxContentLength } from './validate_max_content_length'; @@ -16,7 +16,7 @@ export async function runValidations( config: ReportingConfig, elasticsearch: ElasticsearchServiceSetup, browserFactory: HeadlessChromiumDriverFactory, - logger: Logger + logger: LevelLogger ) { try { await Promise.all([ diff --git a/x-pack/legacy/plugins/reporting/server/lib/validate/validate_browser.ts b/x-pack/legacy/plugins/reporting/server/lib/validate/validate_browser.ts index d6512d5eb718b..d29aa522dad90 100644 --- a/x-pack/legacy/plugins/reporting/server/lib/validate/validate_browser.ts +++ b/x-pack/legacy/plugins/reporting/server/lib/validate/validate_browser.ts @@ -6,8 +6,8 @@ import { Browser } from 'puppeteer'; import { BROWSER_TYPE } from '../../../common/constants'; -import { Logger } from '../../../types'; import { HeadlessChromiumDriverFactory } from '../../browsers/chromium/driver_factory'; +import { LevelLogger } from '../'; /* * Validate the Reporting headless browser can launch, and that it can connect @@ -15,7 +15,7 @@ import { HeadlessChromiumDriverFactory } from '../../browsers/chromium/driver_fa */ export const validateBrowser = async ( browserFactory: HeadlessChromiumDriverFactory, - logger: Logger + logger: LevelLogger ) => { if (browserFactory.type === BROWSER_TYPE) { return browserFactory.test(logger).then((browser: Browser | null) => { diff --git a/x-pack/legacy/plugins/reporting/server/lib/validate/validate_max_content_length.ts b/x-pack/legacy/plugins/reporting/server/lib/validate/validate_max_content_length.ts index a20905ba093d4..f6acf72612e01 100644 --- a/x-pack/legacy/plugins/reporting/server/lib/validate/validate_max_content_length.ts +++ b/x-pack/legacy/plugins/reporting/server/lib/validate/validate_max_content_length.ts @@ -7,8 +7,8 @@ import numeral from '@elastic/numeral'; import { ElasticsearchServiceSetup } from 'kibana/server'; import { defaults, get } from 'lodash'; -import { Logger } from '../../../types'; -import { ReportingConfig } from '../../types'; +import { ReportingConfig } from '../../'; +import { LevelLogger } from '../../lib'; const KIBANA_MAX_SIZE_BYTES_PATH = 'csv.maxSizeBytes'; const ES_MAX_SIZE_BYTES_PATH = 'http.max_content_length'; @@ -16,7 +16,7 @@ const ES_MAX_SIZE_BYTES_PATH = 'http.max_content_length'; export async function validateMaxContentLength( config: ReportingConfig, elasticsearch: ElasticsearchServiceSetup, - logger: Logger + logger: LevelLogger ) { const { callAsInternalUser } = elasticsearch.dataClient; diff --git a/x-pack/legacy/plugins/reporting/server/plugin.ts b/x-pack/legacy/plugins/reporting/server/plugin.ts index e0fa99106a93e..78c2ce5b9b106 100644 --- a/x-pack/legacy/plugins/reporting/server/plugin.ts +++ b/x-pack/legacy/plugins/reporting/server/plugin.ts @@ -6,7 +6,8 @@ import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from 'src/core/server'; import { createBrowserDriverFactory } from './browsers'; -import { ReportingCore, ReportingConfig } from './core'; +import { ReportingConfig } from './config'; +import { ReportingCore } from './core'; import { createQueueFactory, enqueueJobFactory, LevelLogger, runValidations } from './lib'; import { setFieldFormats } from './services'; import { ReportingSetup, ReportingSetupDeps, ReportingStart, ReportingStartDeps } from './types'; diff --git a/x-pack/legacy/plugins/reporting/server/routes/generate_from_jobparams.ts b/x-pack/legacy/plugins/reporting/server/routes/generate_from_jobparams.ts index 6b4f5dbd9203a..70a1a32e76a65 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/generate_from_jobparams.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/generate_from_jobparams.ts @@ -8,16 +8,17 @@ import boom from 'boom'; import Joi from 'joi'; import { Legacy } from 'kibana'; import rison from 'rison-node'; +import { ReportingCore } from '../'; import { API_BASE_URL } from '../../common/constants'; -import { Logger, ReportingResponseToolkit, ServerFacade } from '../../types'; -import { ReportingCore, ReportingSetupDeps } from '../types'; +import { LevelLogger as Logger } from '../lib'; +import { ReportingSetupDeps, ServerFacade } from '../types'; import { makeRequestFacade } from './lib/make_request_facade'; import { GetRouteConfigFactoryFn, getRouteConfigFactoryReportingPre, RouteConfigFactory, } from './lib/route_config_factories'; -import { HandlerErrorFunction, HandlerFunction } from './types'; +import { HandlerErrorFunction, HandlerFunction, ReportingResponseToolkit } from './types'; const BASE_GENERATE = `${API_BASE_URL}/generate`; diff --git a/x-pack/legacy/plugins/reporting/server/routes/generate_from_savedobject.ts b/x-pack/legacy/plugins/reporting/server/routes/generate_from_savedobject.ts index 830953d532243..03a893d1abeb4 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/generate_from_savedobject.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/generate_from_savedobject.ts @@ -6,13 +6,19 @@ import { Legacy } from 'kibana'; import { get } from 'lodash'; +import { ReportingCore } from '../'; import { API_BASE_GENERATE_V1, CSV_FROM_SAVEDOBJECT_JOB_TYPE } from '../../common/constants'; import { getJobParamsFromRequest } from '../../export_types/csv_from_savedobject/server/lib/get_job_params_from_request'; -import { Logger, ReportingResponseToolkit, ServerFacade } from '../../types'; -import { ReportingCore, ReportingSetupDeps } from '../types'; +import { LevelLogger as Logger } from '../lib'; +import { ReportingSetupDeps, ServerFacade } from '../types'; import { makeRequestFacade } from './lib/make_request_facade'; import { getRouteOptionsCsv } from './lib/route_config_factories'; -import { HandlerErrorFunction, HandlerFunction, QueuedJobPayload } from './types'; +import { + HandlerErrorFunction, + HandlerFunction, + QueuedJobPayload, + ReportingResponseToolkit, +} from './types'; /* * This function registers API Endpoints for queuing Reporting jobs. The API inputs are: diff --git a/x-pack/legacy/plugins/reporting/server/routes/generate_from_savedobject_immediate.ts b/x-pack/legacy/plugins/reporting/server/routes/generate_from_savedobject_immediate.ts index 519e49f56c377..22aebb05cdf49 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/generate_from_savedobject_immediate.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/generate_from_savedobject_immediate.ts @@ -4,21 +4,22 @@ * you may not use this file except in compliance with the Elastic License. */ +import { ResponseObject } from 'hapi'; import { Legacy } from 'kibana'; +import { ReportingCore } from '../'; import { API_BASE_GENERATE_V1 } from '../../common/constants'; import { createJobFactory, executeJobFactory } from '../../export_types/csv_from_savedobject'; import { getJobParamsFromRequest } from '../../export_types/csv_from_savedobject/server/lib/get_job_params_from_request'; import { JobDocPayloadPanelCsv } from '../../export_types/csv_from_savedobject/types'; -import { - JobDocOutput, - Logger, - ReportingResponseToolkit, - ResponseFacade, - ServerFacade, -} from '../../types'; -import { ReportingCore, ReportingSetupDeps } from '../types'; +import { LevelLogger as Logger } from '../lib'; +import { JobDocOutput, ReportingSetupDeps, ServerFacade } from '../types'; import { makeRequestFacade } from './lib/make_request_facade'; import { getRouteOptionsCsv } from './lib/route_config_factories'; +import { ReportingResponseToolkit } from './types'; + +type ResponseFacade = ResponseObject & { + isBoom: boolean; +}; /* * This function registers API Endpoints for immediate Reporting jobs. The API inputs are: diff --git a/x-pack/legacy/plugins/reporting/server/routes/generation.test.ts b/x-pack/legacy/plugins/reporting/server/routes/generation.test.ts index 8e54feac3c8a6..74401f8228f7d 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/generation.test.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/generation.test.ts @@ -5,9 +5,11 @@ */ import Hapi from 'hapi'; +import { ReportingConfig, ReportingCore } from '../'; import { createMockReportingCore } from '../../test_helpers'; -import { Logger, ServerFacade } from '../../types'; -import { ReportingConfig, ReportingCore, ReportingSetupDeps } from '../types'; +import { LevelLogger as Logger } from '../lib'; +import { ReportingSetupDeps, ServerFacade } from '../types'; +import { registerJobGenerationRoutes } from './generation'; jest.mock('./lib/authorized_user_pre_routing', () => ({ authorizedUserPreRoutingFactory: () => () => ({}), @@ -18,8 +20,6 @@ jest.mock('./lib/reporting_feature_pre_routing', () => ({ }), })); -import { registerJobGenerationRoutes } from './generation'; - let mockServer: Hapi.Server; let mockReportingPlugin: ReportingCore; let mockReportingConfig: ReportingConfig; diff --git a/x-pack/legacy/plugins/reporting/server/routes/generation.ts b/x-pack/legacy/plugins/reporting/server/routes/generation.ts index 1c6129313db4b..56faa37d5fcbd 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/generation.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/generation.ts @@ -7,13 +7,15 @@ import boom from 'boom'; import { errors as elasticsearchErrors } from 'elasticsearch'; import { Legacy } from 'kibana'; +import { ReportingCore } from '../'; import { API_BASE_URL } from '../../common/constants'; -import { Logger, ReportingResponseToolkit, ServerFacade } from '../../types'; -import { ReportingCore, ReportingSetupDeps } from '../types'; +import { LevelLogger as Logger } from '../lib'; +import { ReportingSetupDeps, ServerFacade } from '../types'; import { registerGenerateFromJobParams } from './generate_from_jobparams'; import { registerGenerateCsvFromSavedObject } from './generate_from_savedobject'; import { registerGenerateCsvFromSavedObjectImmediate } from './generate_from_savedobject_immediate'; import { makeRequestFacade } from './lib/make_request_facade'; +import { ReportingResponseToolkit } from './types'; const esErrors = elasticsearchErrors as Record; diff --git a/x-pack/legacy/plugins/reporting/server/routes/index.ts b/x-pack/legacy/plugins/reporting/server/routes/index.ts index 610ab4907d369..556f4e12b077e 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/index.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/index.ts @@ -4,8 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Logger, ServerFacade } from '../../types'; -import { ReportingCore, ReportingSetupDeps } from '../types'; +import { ReportingCore } from '../'; +import { LevelLogger as Logger } from '../lib'; +import { ReportingSetupDeps, ServerFacade } from '../types'; import { registerJobGenerationRoutes } from './generation'; import { registerJobInfoRoutes } from './jobs'; diff --git a/x-pack/legacy/plugins/reporting/server/routes/jobs.test.ts b/x-pack/legacy/plugins/reporting/server/routes/jobs.test.ts index 5c58a7dfa0110..4f597bcee858e 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/jobs.test.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/jobs.test.ts @@ -5,11 +5,12 @@ */ import Hapi from 'hapi'; +import { ReportingConfig, ReportingCore } from '../'; +import { LevelLogger } from '../lib'; import { createMockReportingCore } from '../../test_helpers'; -import { ExportTypeDefinition } from '../../types'; import { ExportTypesRegistry } from '../lib/export_types_registry'; -import { LevelLogger } from '../lib/level_logger'; -import { ReportingConfig, ReportingCore, ReportingSetupDeps } from '../types'; +import { ExportTypeDefinition, ReportingSetupDeps } from '../types'; +import { registerJobInfoRoutes } from './jobs'; jest.mock('./lib/authorized_user_pre_routing', () => ({ authorizedUserPreRoutingFactory: () => () => ({}), @@ -20,8 +21,6 @@ jest.mock('./lib/reporting_feature_pre_routing', () => ({ }), })); -import { registerJobInfoRoutes } from './jobs'; - let mockServer: any; let exportTypesRegistry: ExportTypesRegistry; let mockReportingPlugin: ReportingCore; diff --git a/x-pack/legacy/plugins/reporting/server/routes/jobs.ts b/x-pack/legacy/plugins/reporting/server/routes/jobs.ts index f6f98b2377db6..59090961998af 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/jobs.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/jobs.ts @@ -7,17 +7,11 @@ import Boom from 'boom'; import { ResponseObject } from 'hapi'; import { Legacy } from 'kibana'; +import { ReportingCore } from '../'; import { API_BASE_URL } from '../../common/constants'; -import { - JobDocOutput, - JobSource, - ListQuery, - Logger, - ReportingResponseToolkit, - ServerFacade, -} from '../../types'; +import { LevelLogger as Logger } from '../lib'; import { jobsQueryFactory } from '../lib/jobs_query'; -import { ReportingCore, ReportingSetupDeps } from '../types'; +import { JobDocOutput, JobSource, ReportingSetupDeps, ServerFacade } from '../types'; import { deleteJobResponseHandlerFactory, downloadJobResponseHandlerFactory, @@ -28,7 +22,13 @@ import { getRouteConfigFactoryDownloadPre, getRouteConfigFactoryManagementPre, } from './lib/route_config_factories'; +import { ReportingResponseToolkit } from './types'; +interface ListQuery { + page: string; + size: string; + ids?: string; // optional field forbids us from extending RequestQuery +} const MAIN_ENTRY = `${API_BASE_URL}/jobs`; function isResponse(response: Boom | ResponseObject): response is ResponseObject { diff --git a/x-pack/legacy/plugins/reporting/server/routes/lib/authorized_user_pre_routing.ts b/x-pack/legacy/plugins/reporting/server/routes/lib/authorized_user_pre_routing.ts index 1ca28ca62a7f2..0d297a60a3559 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/lib/authorized_user_pre_routing.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/lib/authorized_user_pre_routing.ts @@ -8,9 +8,9 @@ import Boom from 'boom'; import { Legacy } from 'kibana'; import { AuthenticatedUser } from '../../../../../../plugins/security/server'; import { ReportingConfig } from '../../../server'; -import { Logger } from '../../../types'; +import { LevelLogger as Logger } from '../../../server/lib'; +import { ReportingSetupDeps } from '../../../server/types'; import { getUserFactory } from '../../lib/get_user'; -import { ReportingSetupDeps } from '../../types'; const superuserRole = 'superuser'; diff --git a/x-pack/legacy/plugins/reporting/server/routes/lib/get_document_payload.ts b/x-pack/legacy/plugins/reporting/server/routes/lib/get_document_payload.ts index c243d0b4266ea..6a228c1915615 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/lib/get_document_payload.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/lib/get_document_payload.ts @@ -8,8 +8,9 @@ import contentDisposition from 'content-disposition'; import * as _ from 'lodash'; import { CSV_JOB_TYPE } from '../../../common/constants'; -import { ExportTypeDefinition, ExportTypesRegistry, JobDocOutput, JobSource } from '../../../types'; import { statuses } from '../../lib/esqueue/constants/statuses'; +import { ExportTypesRegistry } from '../../lib/export_types_registry'; +import { ExportTypeDefinition, JobDocOutput, JobSource } from '../../types'; interface ICustomHeaders { [x: string]: any; diff --git a/x-pack/legacy/plugins/reporting/server/routes/lib/job_response_handler.ts b/x-pack/legacy/plugins/reporting/server/routes/lib/job_response_handler.ts index e7e7c866db96a..59aa7d904dcf4 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/lib/job_response_handler.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/lib/job_response_handler.ts @@ -7,10 +7,10 @@ import Boom from 'boom'; import { ResponseToolkit } from 'hapi'; import { ElasticsearchServiceSetup } from 'kibana/server'; +import { ReportingConfig } from '../../'; import { WHITELISTED_JOB_CONTENT_TYPES } from '../../../common/constants'; -import { ExportTypesRegistry } from '../../../types'; +import { ExportTypesRegistry } from '../../lib/export_types_registry'; import { jobsQueryFactory } from '../../lib/jobs_query'; -import { ReportingConfig } from '../../types'; import { getDocumentPayloadFactory } from './get_document_payload'; interface JobResponseHandlerParams { diff --git a/x-pack/legacy/plugins/reporting/server/routes/lib/make_request_facade.ts b/x-pack/legacy/plugins/reporting/server/routes/lib/make_request_facade.ts index fb8a2dbbff17b..5dd62711f2565 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/lib/make_request_facade.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/lib/make_request_facade.ts @@ -11,7 +11,7 @@ import { ReportingRequestPayload, ReportingRequestPre, ReportingRequestQuery, -} from '../../../types'; +} from '../../../server/types'; export function makeRequestFacade(request: Legacy.Request): RequestFacade { // This condition is for unit tests diff --git a/x-pack/legacy/plugins/reporting/server/routes/lib/reporting_feature_pre_routing.ts b/x-pack/legacy/plugins/reporting/server/routes/lib/reporting_feature_pre_routing.ts index 8a79566aafae2..f9c7571e25bac 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/lib/reporting_feature_pre_routing.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/lib/reporting_feature_pre_routing.ts @@ -6,8 +6,9 @@ import Boom from 'boom'; import { Legacy } from 'kibana'; -import { Logger } from '../../../types'; -import { ReportingConfig, ReportingSetupDeps } from '../../types'; +import { ReportingConfig } from '../../'; +import { LevelLogger as Logger } from '../../lib'; +import { ReportingSetupDeps } from '../../types'; export type GetReportingFeatureIdFn = (request: Legacy.Request) => string; diff --git a/x-pack/legacy/plugins/reporting/server/routes/lib/route_config_factories.ts b/x-pack/legacy/plugins/reporting/server/routes/lib/route_config_factories.ts index 06f7efaa9dcbb..0ee9db4678684 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/lib/route_config_factories.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/lib/route_config_factories.ts @@ -5,9 +5,10 @@ */ import Joi from 'joi'; +import { ReportingConfig } from '../../'; +import { LevelLogger as Logger } from '../../lib'; import { CSV_FROM_SAVEDOBJECT_JOB_TYPE } from '../../../common/constants'; -import { Logger } from '../../../types'; -import { ReportingConfig, ReportingSetupDeps } from '../../types'; +import { ReportingSetupDeps } from '../../types'; import { authorizedUserPreRoutingFactory } from './authorized_user_pre_routing'; import { GetReportingFeatureIdFn, diff --git a/x-pack/legacy/plugins/reporting/server/routes/types.d.ts b/x-pack/legacy/plugins/reporting/server/routes/types.d.ts index 28862a765d666..2ebe1ada418dc 100644 --- a/x-pack/legacy/plugins/reporting/server/routes/types.d.ts +++ b/x-pack/legacy/plugins/reporting/server/routes/types.d.ts @@ -5,7 +5,7 @@ */ import { Legacy } from 'kibana'; -import { JobDocPayload, ReportingResponseToolkit } from '../../types'; +import { JobDocPayload } from '../types'; export type HandlerFunction = ( exportType: string, @@ -24,3 +24,5 @@ export interface QueuedJobPayload { }; }; } + +export type ReportingResponseToolkit = Legacy.ResponseToolkit; diff --git a/x-pack/legacy/plugins/reporting/server/types.d.ts b/x-pack/legacy/plugins/reporting/server/types.d.ts deleted file mode 100644 index fb77eae4e7eea..0000000000000 --- a/x-pack/legacy/plugins/reporting/server/types.d.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { Legacy } from 'kibana'; -import { ElasticsearchServiceSetup } from 'src/core/server'; -import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; -import { PluginStart as DataPluginStart } from '../../../../../src/plugins/data/server'; -import { SecurityPluginSetup } from '../../../../plugins/security/server'; -import { XPackMainPlugin } from '../../xpack_main/server/xpack_main'; -import { ReportingPluginSpecOptions } from '../types'; -import { ReportingConfigType } from './core'; - -export interface ReportingSetupDeps { - elasticsearch: ElasticsearchServiceSetup; - security: SecurityPluginSetup; - usageCollection?: UsageCollectionSetup; - __LEGACY: LegacySetup; -} - -export interface ReportingStartDeps { - data: DataPluginStart; - __LEGACY: LegacySetup; -} - -export type ReportingSetup = object; - -export type ReportingStart = object; - -export interface LegacySetup { - plugins: { - xpack_main: XPackMainPlugin & { - status?: any; - }; - reporting: ReportingPluginSpecOptions; - }; - route: Legacy.Server['route']; -} - -export { ReportingConfig, ReportingConfigType, ReportingCore } from './core'; - -export type CaptureConfig = ReportingConfigType['capture']; -export type ScrollConfig = ReportingConfigType['csv']['scroll']; diff --git a/x-pack/legacy/plugins/reporting/server/types.ts b/x-pack/legacy/plugins/reporting/server/types.ts new file mode 100644 index 0000000000000..1417f1d7b50cb --- /dev/null +++ b/x-pack/legacy/plugins/reporting/server/types.ts @@ -0,0 +1,243 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { Legacy } from 'kibana'; +import { ElasticsearchServiceSetup } from 'kibana/server'; +import * as Rx from 'rxjs'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { DataPluginStart } from 'src/plugins/data/server/plugin'; +import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; +import { ReportingPluginSpecOptions } from '../'; +import { CancellationToken } from '../../../../plugins/reporting/common'; +import { JobStatus } from '../../../../plugins/reporting/common/types'; +import { SecurityPluginSetup } from '../../../../plugins/security/server'; +import { XPackMainPlugin } from '../../xpack_main/server/xpack_main'; +import { LayoutInstance } from '../export_types/common/layouts'; +import { ReportingConfigType } from './config'; +import { ReportingCore } from './core'; +import { LevelLogger } from './lib'; + +/* + * Routing / API types + */ + +interface ListQuery { + page: string; + size: string; + ids?: string; // optional field forbids us from extending RequestQuery +} + +interface GenerateQuery { + jobParams: string; +} + +export type ReportingRequestQuery = ListQuery | GenerateQuery; + +export interface ReportingRequestPre { + management: { + jobTypes: any; + }; + user: string; +} + +// generate a report with unparsed jobParams +export interface GenerateExportTypePayload { + jobParams: string; +} + +export type ReportingRequestPayload = GenerateExportTypePayload | JobParamPostPayload; + +export interface TimeRangeParams { + timezone: string; + min: Date | string | number; + max: Date | string | number; +} + +export interface JobParamPostPayload { + timerange: TimeRangeParams; +} + +export interface JobDocPayload { + headers?: string; // serialized encrypted headers + jobParams: JobParamsType; + title: string; + type: string | null; +} + +export interface JobSource { + _id: string; + _index: string; + _source: { + jobtype: string; + output: JobDocOutput; + payload: JobDocPayload; + status: JobStatus; + }; +} + +export interface JobDocOutput { + content_type: string; + content: string | null; + size: number; + max_size_reached?: boolean; + warnings?: string[]; +} + +interface ConditionalHeadersConditions { + protocol: string; + hostname: string; + port: number; + basePath: string; +} + +export interface ConditionalHeaders { + headers: Record; + conditions: ConditionalHeadersConditions; +} + +/* + * Screenshots + */ + +export interface ScreenshotObservableOpts { + logger: LevelLogger; + urls: string[]; + conditionalHeaders: ConditionalHeaders; + layout: LayoutInstance; + browserTimezone: string; +} + +export interface AttributesMap { + [key: string]: any; +} + +export interface ElementPosition { + boundingClientRect: { + // modern browsers support x/y, but older ones don't + top: number; + left: number; + width: number; + height: number; + }; + scroll: { + x: number; + y: number; + }; +} + +export interface ElementsPositionAndAttribute { + position: ElementPosition; + attributes: AttributesMap; +} + +export interface Screenshot { + base64EncodedData: string; + title: string; + description: string; +} + +export interface ScreenshotResults { + timeRange: string | null; + screenshots: Screenshot[]; + error?: Error; + elementsPositionAndAttributes?: ElementsPositionAndAttribute[]; // NOTE: for testing +} + +export type ScreenshotsObservableFn = ({ + logger, + urls, + conditionalHeaders, + layout, + browserTimezone, +}: ScreenshotObservableOpts) => Rx.Observable; + +/* + * Plugin Contract + */ + +export interface ReportingSetupDeps { + elasticsearch: ElasticsearchServiceSetup; + security: SecurityPluginSetup; + usageCollection?: UsageCollectionSetup; + __LEGACY: LegacySetup; +} + +export interface ReportingStartDeps { + data: DataPluginStart; + __LEGACY: LegacySetup; +} + +export type ReportingStart = object; +export type ReportingSetup = object; + +export interface LegacySetup { + plugins: { + xpack_main: XPackMainPlugin & { + status?: any; + }; + reporting: ReportingPluginSpecOptions; + }; + route: Legacy.Server['route']; +} + +/* + * Internal Types + */ + +export interface RequestFacade { + getBasePath: Legacy.Request['getBasePath']; + getSavedObjectsClient: Legacy.Request['getSavedObjectsClient']; + headers: Legacy.Request['headers']; + params: Legacy.Request['params']; + payload: JobParamPostPayload | GenerateExportTypePayload; + query: ReportingRequestQuery; + route: Legacy.Request['route']; + pre: ReportingRequestPre; + getRawRequest: () => Legacy.Request; +} + +export type ESQueueCreateJobFn = ( + jobParams: JobParamsType, + headers: Record, + request: RequestFacade +) => Promise; + +export type ESQueueWorkerExecuteFn = ( + jobId: string, + job: JobDocPayloadType, + cancellationToken?: CancellationToken +) => Promise; + +export type ServerFacade = LegacySetup; + +export type CaptureConfig = ReportingConfigType['capture']; +export type ScrollConfig = ReportingConfigType['csv']['scroll']; + +export type CreateJobFactory = ( + reporting: ReportingCore, + logger: LevelLogger +) => CreateJobFnType; + +export type ExecuteJobFactory = ( + reporting: ReportingCore, + logger: LevelLogger +) => Promise; // FIXME: does not "need" to be async + +export interface ExportTypeDefinition< + JobParamsType, + CreateJobFnType, + JobPayloadType, + ExecuteJobFnType +> { + id: string; + name: string; + jobType: string; + jobContentEncoding?: string; + jobContentExtension: string; + createJobFactory: CreateJobFactory; + executeJobFactory: ExecuteJobFactory; + validLicenses: string[]; +} diff --git a/x-pack/legacy/plugins/reporting/server/usage/get_reporting_usage.ts b/x-pack/legacy/plugins/reporting/server/usage/get_reporting_usage.ts index eb907d52c5f96..6771d61bf263d 100644 --- a/x-pack/legacy/plugins/reporting/server/usage/get_reporting_usage.ts +++ b/x-pack/legacy/plugins/reporting/server/usage/get_reporting_usage.ts @@ -5,23 +5,24 @@ */ import { get } from 'lodash'; +import { CallCluster } from 'src/legacy/core_plugins/elasticsearch'; +import { ReportingConfig } from '../'; import { XPackMainPlugin } from '../../../xpack_main/server/xpack_main'; -import { ESCallCluster, ExportTypesRegistry } from '../../types'; -import { ReportingConfig } from '../types'; -import { decorateRangeStats } from './decorate_range_stats'; -import { getExportTypesHandler } from './get_export_type_handler'; +import { ExportTypesRegistry } from '../lib/export_types_registry'; import { AggregationResultBuckets, + AppCounts, FeatureAvailabilityMap, JobTypes, KeyCountBucket, + LayoutCounts, RangeStats, ReportingUsageType, SearchResponse, StatusByAppBucket, - AppCounts, - LayoutCounts, } from './types'; +import { decorateRangeStats } from './decorate_range_stats'; +import { getExportTypesHandler } from './get_export_type_handler'; type XPackInfo = XPackMainPlugin['info']; @@ -123,7 +124,7 @@ async function handleResponse(response: SearchResponse): Promise + fetch: (callCluster: CallCluster) => getReportingUsage(config, xpackMainInfo, callCluster, exportTypesRegistry), isReady, diff --git a/x-pack/legacy/plugins/reporting/server/usage/types.d.ts b/x-pack/legacy/plugins/reporting/server/usage/types.ts similarity index 65% rename from x-pack/legacy/plugins/reporting/server/usage/types.d.ts rename to x-pack/legacy/plugins/reporting/server/usage/types.ts index 4d7a1a33239b2..5430a1cfc33bd 100644 --- a/x-pack/legacy/plugins/reporting/server/usage/types.d.ts +++ b/x-pack/legacy/plugins/reporting/server/usage/types.ts @@ -107,3 +107,63 @@ export type ReportingUsageType = RangeStats & { export type ExportType = 'csv' | 'printable_pdf' | 'PNG'; export type FeatureAvailabilityMap = { [F in ExportType]: boolean }; + +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export interface KeyCountBucket { + key: string; + doc_count: number; +} + +export interface AggregationBuckets { + buckets: KeyCountBucket[]; +} + +export interface StatusByAppBucket { + key: string; + doc_count: number; + jobTypes: { + buckets: Array<{ + doc_count: number; + key: string; + appNames: AggregationBuckets; + }>; + }; +} + +export interface AggregationResultBuckets { + jobTypes: AggregationBuckets; + layoutTypes: { + doc_count: number; + pdf: AggregationBuckets; + }; + objectTypes: { + doc_count: number; + pdf: AggregationBuckets; + }; + statusTypes: AggregationBuckets; + statusByApp: { + buckets: StatusByAppBucket[]; + }; + doc_count: number; +} + +export interface SearchResponse { + aggregations: { + ranges: { + buckets: { + all: AggregationResultBuckets; + last7Days: AggregationResultBuckets; + }; + }; + }; +} + +export interface AvailableTotal { + available: boolean; + total: number; +} diff --git a/x-pack/legacy/plugins/reporting/test_helpers/create_mock_browserdriverfactory.ts b/x-pack/legacy/plugins/reporting/test_helpers/create_mock_browserdriverfactory.ts index aafe17d970187..260c94c31df1c 100644 --- a/x-pack/legacy/plugins/reporting/test_helpers/create_mock_browserdriverfactory.ts +++ b/x-pack/legacy/plugins/reporting/test_helpers/create_mock_browserdriverfactory.ts @@ -7,11 +7,10 @@ import { Page } from 'puppeteer'; import * as Rx from 'rxjs'; import * as contexts from '../export_types/common/lib/screenshots/constants'; -import { ElementsPositionAndAttribute } from '../export_types/common/lib/screenshots/types'; import { HeadlessChromiumDriver, HeadlessChromiumDriverFactory } from '../server/browsers'; import { createDriverFactory } from '../server/browsers/chromium'; -import { CaptureConfig } from '../server/types'; -import { Logger } from '../types'; +import { LevelLogger } from '../server/lib'; +import { CaptureConfig, ElementsPositionAndAttribute } from '../server/types'; interface CreateMockBrowserDriverFactoryOpts { evaluate: jest.Mock, any[]>; @@ -93,7 +92,7 @@ const defaultOpts: CreateMockBrowserDriverFactoryOpts = { }; export const createMockBrowserDriverFactory = async ( - logger: Logger, + logger: LevelLogger, opts: Partial = {} ): Promise => { const captureConfig: CaptureConfig = { diff --git a/x-pack/legacy/plugins/reporting/test_helpers/create_mock_layoutinstance.ts b/x-pack/legacy/plugins/reporting/test_helpers/create_mock_layoutinstance.ts index 81090e7616501..7f4330e7f6bc6 100644 --- a/x-pack/legacy/plugins/reporting/test_helpers/create_mock_layoutinstance.ts +++ b/x-pack/legacy/plugins/reporting/test_helpers/create_mock_layoutinstance.ts @@ -4,9 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { LayoutTypes } from '../export_types/common/constants'; -import { createLayout } from '../export_types/common/layouts'; -import { LayoutInstance } from '../export_types/common/layouts/layout'; +import { createLayout, LayoutInstance, LayoutTypes } from '../export_types/common/layouts'; import { CaptureConfig } from '../server/types'; export const createMockLayoutInstance = (captureConfig: CaptureConfig) => { diff --git a/x-pack/legacy/plugins/reporting/test_helpers/create_mock_reportingplugin.ts b/x-pack/legacy/plugins/reporting/test_helpers/create_mock_reportingplugin.ts index ec00023b4d449..274f7344c7261 100644 --- a/x-pack/legacy/plugins/reporting/test_helpers/create_mock_reportingplugin.ts +++ b/x-pack/legacy/plugins/reporting/test_helpers/create_mock_reportingplugin.ts @@ -15,7 +15,7 @@ jest.mock('../server/lib/validate'); import { EventEmitter } from 'events'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { coreMock } from 'src/core/server/mocks'; -import { ReportingPlugin, ReportingCore, ReportingConfig } from '../server'; +import { ReportingConfig, ReportingCore, ReportingPlugin } from '../server'; import { ReportingSetupDeps, ReportingStartDeps } from '../server/types'; const createMockSetupDeps = (setupMock?: any): ReportingSetupDeps => { diff --git a/x-pack/legacy/plugins/reporting/test_helpers/create_mock_server.ts b/x-pack/legacy/plugins/reporting/test_helpers/create_mock_server.ts index 531e1dcaf84e0..819636b714631 100644 --- a/x-pack/legacy/plugins/reporting/test_helpers/create_mock_server.ts +++ b/x-pack/legacy/plugins/reporting/test_helpers/create_mock_server.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { ServerFacade } from '../types'; +import { ServerFacade } from '../server/types'; export const createMockServer = (): ServerFacade => { const mockServer = {}; diff --git a/x-pack/legacy/plugins/reporting/types.d.ts b/x-pack/legacy/plugins/reporting/types.d.ts deleted file mode 100644 index 2e7da6663ab03..0000000000000 --- a/x-pack/legacy/plugins/reporting/types.d.ts +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { EventEmitter } from 'events'; -import { ResponseObject } from 'hapi'; -import { Legacy } from 'kibana'; -import { CallCluster } from '../../../../src/legacy/core_plugins/elasticsearch'; -import { JobStatus } from '../../../plugins/reporting'; // reporting new platform -import { CancellationToken } from './common/cancellation_token'; -import { ReportingCore } from './server/core'; -import { LevelLogger } from './server/lib/level_logger'; -import { LegacySetup } from './server/types'; - -export type Job = EventEmitter & { - id: string; - toJSON: () => { - id: string; - }; -}; - -export interface NetworkPolicyRule { - allow: boolean; - protocol?: string; - host?: string; -} - -export interface NetworkPolicy { - enabled: boolean; - rules: NetworkPolicyRule[]; -} - -export interface ListQuery { - page: string; - size: string; - ids?: string; // optional field forbids us from extending RequestQuery -} -interface GenerateQuery { - jobParams: string; -} -interface GenerateExportTypePayload { - jobParams: string; -} - -/* - * Legacy System - * TODO: move to server/types - */ - -export type ServerFacade = LegacySetup; - -export type ReportingPluginSpecOptions = Legacy.PluginSpecOptions; - -export type EnqueueJobFn = ( - exportTypeId: string, - jobParams: JobParamsType, - user: string, - headers: Record, - request: RequestFacade -) => Promise; - -export type ReportingRequestPayload = GenerateExportTypePayload | JobParamPostPayload; -export type ReportingRequestQuery = ListQuery | GenerateQuery; - -export interface ReportingRequestPre { - management: { - jobTypes: any; - }; - user: any; // TODO import AuthenticatedUser from security/server -} - -export interface RequestFacade { - getBasePath: Legacy.Request['getBasePath']; - getSavedObjectsClient: Legacy.Request['getSavedObjectsClient']; - headers: Legacy.Request['headers']; - params: Legacy.Request['params']; - payload: JobParamPostPayload | GenerateExportTypePayload; - query: ReportingRequestQuery; - route: Legacy.Request['route']; - pre: ReportingRequestPre; - getRawRequest: () => Legacy.Request; -} - -export type ResponseFacade = ResponseObject & { - isBoom: boolean; -}; - -export type ReportingResponseToolkit = Legacy.ResponseToolkit; - -export type ESCallCluster = CallCluster; - -export interface ElementPosition { - boundingClientRect: { - // modern browsers support x/y, but older ones don't - top: number; - left: number; - width: number; - height: number; - }; - scroll: { - x: number; - y: number; - }; -} - -export interface ConditionalHeaders { - headers: Record; - conditions: ConditionalHeadersConditions; -} - -export interface ConditionalHeadersConditions { - protocol: string; - hostname: string; - port: number; - basePath: string; -} - -export interface IndexPatternSavedObject { - attributes: { - fieldFormatMap: string; - }; - id: string; - type: string; - version: string; -} - -export interface TimeRangeParams { - timezone: string; - min: Date | string | number; - max: Date | string | number; -} - -// retain POST payload data, needed for async -export interface JobParamPostPayload { - timerange: TimeRangeParams; -} - -export interface JobDocPayload { - headers?: string; // serialized encrypted headers - jobParams: JobParamsType; - title: string; - type: string | null; -} - -export interface JobSource { - _id: string; - _index: string; - _source: { - jobtype: string; - output: JobDocOutput; - payload: JobDocPayload; - status: JobStatus; - }; -} - -export interface JobDocOutput { - content_type: string; - content: string | null; - size: number; - max_size_reached?: boolean; - warnings?: string[]; -} - -export interface ESQueueWorker { - on: (event: string, handler: any) => void; -} - -export type ESQueueCreateJobFn = ( - jobParams: JobParamsType, - headers: Record, - request: RequestFacade -) => Promise; - -export type ImmediateCreateJobFn = ( - jobParams: JobParamsType, - headers: Record, - req: RequestFacade -) => Promise<{ - type: string | null; - title: string; - jobParams: JobParamsType; -}>; - -export type ESQueueWorkerExecuteFn = ( - jobId: string, - job: JobDocPayloadType, - cancellationToken?: CancellationToken -) => Promise; - -/* - * ImmediateExecuteFn receives the job doc payload because the payload was - * generated in the CreateFn - */ -export type ImmediateExecuteFn = ( - jobId: null, - job: JobDocPayload, - request: RequestFacade -) => Promise; - -export interface ESQueueWorkerOptions { - kibanaName: string; - kibanaId: string; - interval: number; - intervalErrorMultiplier: number; -} - -// GenericWorkerFn is a generic for ImmediateExecuteFn | ESQueueWorkerExecuteFn, -type GenericWorkerFn = ( - jobSource: JobSource, - ...workerRestArgs: any[] -) => void | Promise; - -export interface ESQueueInstance { - addJob: (type: string, payload: unknown, options: object) => Job; - registerWorker: ( - pluginId: string, - workerFn: GenericWorkerFn, - workerOptions: ESQueueWorkerOptions - ) => ESQueueWorker; -} - -export type CreateJobFactory = ( - reporting: ReportingCore, - logger: LevelLogger -) => CreateJobFnType; -export type ExecuteJobFactory = ( - reporting: ReportingCore, - logger: LevelLogger -) => Promise; // FIXME: does not "need" to be async - -export interface ExportTypeDefinition< - JobParamsType, - CreateJobFnType, - JobPayloadType, - ExecuteJobFnType -> { - id: string; - name: string; - jobType: string; - jobContentEncoding?: string; - jobContentExtension: string; - createJobFactory: CreateJobFactory; - executeJobFactory: ExecuteJobFactory; - validLicenses: string[]; -} - -export { CancellationToken } from './common/cancellation_token'; - -export { HeadlessChromiumDriver, HeadlessChromiumDriverFactory } from './server/browsers'; - -export { ExportTypesRegistry } from './server/lib/export_types_registry'; -// Prefer to import this type using: `import { LevelLogger } from 'relative/path/server/lib';` -export { LevelLogger as Logger }; - -export interface AbsoluteURLFactoryOptions { - defaultBasePath: string; - protocol: string; - hostname: string; - port: string | number; -} - -export interface InterceptedRequest { - requestId: string; - request: { - url: string; - method: string; - headers: { - [key: string]: string; - }; - initialPriority: string; - referrerPolicy: string; - }; - frameId: string; - resourceType: string; -} diff --git a/x-pack/legacy/plugins/reporting/common/cancellation_token.test.ts b/x-pack/plugins/reporting/common/cancellation_token.test.ts similarity index 100% rename from x-pack/legacy/plugins/reporting/common/cancellation_token.test.ts rename to x-pack/plugins/reporting/common/cancellation_token.test.ts diff --git a/x-pack/legacy/plugins/reporting/common/cancellation_token.ts b/x-pack/plugins/reporting/common/cancellation_token.ts similarity index 100% rename from x-pack/legacy/plugins/reporting/common/cancellation_token.ts rename to x-pack/plugins/reporting/common/cancellation_token.ts diff --git a/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/types.d.ts b/x-pack/plugins/reporting/common/index.ts similarity index 80% rename from x-pack/legacy/plugins/reporting/export_types/csv/server/lib/types.d.ts rename to x-pack/plugins/reporting/common/index.ts index b4dc743664995..36c896fb4f7b8 100644 --- a/x-pack/legacy/plugins/reporting/export_types/csv/server/lib/types.d.ts +++ b/x-pack/plugins/reporting/common/index.ts @@ -4,4 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -export type RawValue = string | object | null | undefined; +export { CancellationToken } from './cancellation_token'; diff --git a/x-pack/plugins/reporting/common/poller.ts b/x-pack/plugins/reporting/common/poller.ts index 919d7273062a8..1aeaca001cf1e 100644 --- a/x-pack/plugins/reporting/common/poller.ts +++ b/x-pack/plugins/reporting/common/poller.ts @@ -5,7 +5,7 @@ */ import _ from 'lodash'; -import { PollerOptions } from '..'; +import { PollerOptions } from './types'; // @TODO Maybe move to observables someday export class Poller { diff --git a/x-pack/plugins/reporting/common/types.d.ts b/x-pack/plugins/reporting/common/types.d.ts deleted file mode 100644 index 7ab9a15e1773a..0000000000000 --- a/x-pack/plugins/reporting/common/types.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -export { ConfigType } from '../server/config'; diff --git a/x-pack/plugins/reporting/index.d.ts b/x-pack/plugins/reporting/common/types.ts similarity index 93% rename from x-pack/plugins/reporting/index.d.ts rename to x-pack/plugins/reporting/common/types.ts index 77faf837e6505..5b9ddfb1bbdea 100644 --- a/x-pack/plugins/reporting/index.d.ts +++ b/x-pack/plugins/reporting/common/types.ts @@ -4,6 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +export { ConfigType } from '../server/config'; + export type JobId = string; export type JobStatus = | 'completed' diff --git a/x-pack/plugins/reporting/public/components/job_download_button.tsx b/x-pack/plugins/reporting/public/components/job_download_button.tsx index 911a19c0176c2..7dff2cafa047b 100644 --- a/x-pack/plugins/reporting/public/components/job_download_button.tsx +++ b/x-pack/plugins/reporting/public/components/job_download_button.tsx @@ -4,10 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -import React from 'react'; import { EuiButton } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; -import { JobId, JobSummary } from '../../index.d'; +import React from 'react'; +import { JobId, JobSummary } from '../../common/types'; interface Props { getUrl: (jobId: JobId) => string; diff --git a/x-pack/plugins/reporting/public/components/job_failure.tsx b/x-pack/plugins/reporting/public/components/job_failure.tsx index 628ecb56b9c21..0da67ea367437 100644 --- a/x-pack/plugins/reporting/public/components/job_failure.tsx +++ b/x-pack/plugins/reporting/public/components/job_failure.tsx @@ -4,13 +4,13 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { Fragment } from 'react'; +import { EuiCallOut, EuiSpacer } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; -import { EuiCallOut, EuiSpacer } from '@elastic/eui'; +import React, { Fragment } from 'react'; import { ToastInput } from 'src/core/public'; import { toMountPoint } from '../../../../../src/plugins/kibana_react/public'; -import { JobSummary, ManagementLinkFn } from '../../index.d'; +import { JobSummary, ManagementLinkFn } from '../../common/types'; export const getFailureToast = ( errorText: string, diff --git a/x-pack/plugins/reporting/public/components/job_success.tsx b/x-pack/plugins/reporting/public/components/job_success.tsx index ad16a506aeb70..7f33321ee3645 100644 --- a/x-pack/plugins/reporting/public/components/job_success.tsx +++ b/x-pack/plugins/reporting/public/components/job_success.tsx @@ -4,11 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { Fragment } from 'react'; import { FormattedMessage } from '@kbn/i18n/react'; +import React, { Fragment } from 'react'; import { ToastInput } from 'src/core/public'; import { toMountPoint } from '../../../../../src/plugins/kibana_react/public'; -import { JobId, JobSummary } from '../../index.d'; +import { JobId, JobSummary } from '../../common/types'; import { DownloadButton } from './job_download_button'; import { ReportLink } from './report_link'; diff --git a/x-pack/plugins/reporting/public/components/job_warning_formulas.tsx b/x-pack/plugins/reporting/public/components/job_warning_formulas.tsx index 8717ae16d1ba1..e2afae1feaa01 100644 --- a/x-pack/plugins/reporting/public/components/job_warning_formulas.tsx +++ b/x-pack/plugins/reporting/public/components/job_warning_formulas.tsx @@ -4,11 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { Fragment } from 'react'; import { FormattedMessage } from '@kbn/i18n/react'; +import React, { Fragment } from 'react'; import { ToastInput } from 'src/core/public'; import { toMountPoint } from '../../../../../src/plugins/kibana_react/public'; -import { JobId, JobSummary } from '../../index.d'; +import { JobId, JobSummary } from '../../common/types'; import { DownloadButton } from './job_download_button'; import { ReportLink } from './report_link'; diff --git a/x-pack/plugins/reporting/public/components/job_warning_max_size.tsx b/x-pack/plugins/reporting/public/components/job_warning_max_size.tsx index 83fa129f0715a..6c0d6118dfff2 100644 --- a/x-pack/plugins/reporting/public/components/job_warning_max_size.tsx +++ b/x-pack/plugins/reporting/public/components/job_warning_max_size.tsx @@ -4,11 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { Fragment } from 'react'; import { FormattedMessage } from '@kbn/i18n/react'; +import React, { Fragment } from 'react'; import { ToastInput } from 'src/core/public'; import { toMountPoint } from '../../../../../src/plugins/kibana_react/public'; -import { JobId, JobSummary } from '../../index.d'; +import { JobId, JobSummary } from '../../common/types'; import { DownloadButton } from './job_download_button'; import { ReportLink } from './report_link'; diff --git a/x-pack/plugins/reporting/public/lib/license_check.ts b/x-pack/plugins/reporting/public/lib/license_check.ts index 0c16ead0b116d..bf4dfeeb8fe31 100644 --- a/x-pack/plugins/reporting/public/lib/license_check.ts +++ b/x-pack/plugins/reporting/public/lib/license_check.ts @@ -3,8 +3,9 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { LicenseCheckResults } from '../..'; + import { LicenseCheck } from '../../../licensing/public'; +import { LicenseCheckResults } from '../../common/types'; export const checkLicense = (checkResults: LicenseCheck): LicenseCheckResults => { switch (checkResults.state) { diff --git a/x-pack/plugins/reporting/public/lib/reporting_api_client.ts b/x-pack/plugins/reporting/public/lib/reporting_api_client.ts index b6c33860752d6..54bdc99532320 100644 --- a/x-pack/plugins/reporting/public/lib/reporting_api_client.ts +++ b/x-pack/plugins/reporting/public/lib/reporting_api_client.ts @@ -6,11 +6,10 @@ import { stringify } from 'query-string'; import rison from 'rison-node'; - import { HttpSetup } from 'src/core/public'; +import { JobId, SourceJob } from '../../common/types'; +import { API_BASE_GENERATE, API_LIST_URL, REPORTING_MANAGEMENT_HOME } from '../../constants'; import { add } from './job_completion_notifications'; -import { API_LIST_URL, API_BASE_GENERATE, REPORTING_MANAGEMENT_HOME } from '../../constants'; -import { JobId, SourceJob } from '../..'; export interface JobQueueEntry { _id: string; diff --git a/x-pack/plugins/reporting/public/lib/stream_handler.test.ts b/x-pack/plugins/reporting/public/lib/stream_handler.test.ts index 3a2c7de9ad0f0..96f284ae282b9 100644 --- a/x-pack/plugins/reporting/public/lib/stream_handler.test.ts +++ b/x-pack/plugins/reporting/public/lib/stream_handler.test.ts @@ -6,7 +6,7 @@ import sinon, { stub } from 'sinon'; import { NotificationsStart } from 'src/core/public'; -import { SourceJob, JobSummary } from '../../index.d'; +import { JobSummary, SourceJob } from '../../common/types'; import { ReportingAPIClient } from './reporting_api_client'; import { ReportingNotifierStreamHandler } from './stream_handler'; diff --git a/x-pack/plugins/reporting/public/lib/stream_handler.ts b/x-pack/plugins/reporting/public/lib/stream_handler.ts index eed6d5dd141e7..41e5353badfe5 100644 --- a/x-pack/plugins/reporting/public/lib/stream_handler.ts +++ b/x-pack/plugins/reporting/public/lib/stream_handler.ts @@ -8,13 +8,13 @@ import { i18n } from '@kbn/i18n'; import * as Rx from 'rxjs'; import { catchError, map } from 'rxjs/operators'; import { NotificationsSetup } from 'src/core/public'; +import { JobId, JobStatusBuckets, JobSummary, SourceJob } from '../../common/types'; import { JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY, JOB_STATUS_COMPLETED, JOB_STATUS_FAILED, JOB_STATUS_WARNINGS, } from '../../constants'; -import { JobId, JobStatusBuckets, JobSummary, SourceJob } from '../../index.d'; import { getFailureToast, getGeneralErrorToast, diff --git a/x-pack/plugins/reporting/public/plugin.tsx b/x-pack/plugins/reporting/public/plugin.tsx index f600b1ebbb96c..ac8ea661a21ab 100644 --- a/x-pack/plugins/reporting/public/plugin.tsx +++ b/x-pack/plugins/reporting/public/plugin.tsx @@ -18,16 +18,15 @@ import { PluginInitializerContext, } from 'src/core/public'; import { UiActionsSetup } from 'src/plugins/ui_actions/public'; -import { JobId, JobStatusBuckets } from '../'; -import { ManagementSetup, ManagementSectionId } from '../../../../src/plugins/management/public'; import { CONTEXT_MENU_TRIGGER } from '../../../../src/plugins/embeddable/public'; import { FeatureCatalogueCategory, HomePublicPluginSetup, } from '../../../../src/plugins/home/public'; +import { ManagementSectionId, ManagementSetup } from '../../../../src/plugins/management/public'; import { SharePluginSetup } from '../../../../src/plugins/share/public'; import { LicensingPluginSetup } from '../../licensing/public'; -import { ConfigType } from '../common/types'; +import { ConfigType, JobId, JobStatusBuckets } from '../common/types'; import { JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY } from '../constants'; import { getGeneralErrorToast } from './components'; import { ReportListing } from './components/report_listing'; diff --git a/x-pack/plugins/reporting/server/index.ts b/x-pack/plugins/reporting/server/index.ts index 2b1844cf2e10e..9d34eba70d0f4 100644 --- a/x-pack/plugins/reporting/server/index.ts +++ b/x-pack/plugins/reporting/server/index.ts @@ -7,8 +7,8 @@ import { PluginInitializerContext } from 'src/core/server'; import { ReportingPlugin } from './plugin'; -export { config, ConfigSchema } from './config'; -export { ConfigType, PluginsSetup } from './plugin'; +export { config, ConfigSchema, ConfigType } from './config'; +export { PluginsSetup } from './plugin'; export const plugin = (initializerContext: PluginInitializerContext) => new ReportingPlugin(initializerContext);