diff --git a/packages/kbn-generate-csv-types/index.ts b/packages/kbn-generate-csv-types/index.ts index 865ac302e06b9..6c5134e1fff99 100644 --- a/packages/kbn-generate-csv-types/index.ts +++ b/packages/kbn-generate-csv-types/index.ts @@ -9,12 +9,20 @@ import { ByteSizeValue } from '@kbn/config-schema'; import type { SerializedSearchSourceFields } from '@kbn/data-plugin/public'; +/** + * @internal + * Needed to separate dependencies from reporting + */ export interface JobParams { searchSource: SerializedSearchSourceFields; columns?: string[]; browserTimezone?: string; } +/** + * @internal + * Needed to separate dependencies from reporting + */ export interface CsvConfig { checkForFormulas: boolean; escapeFormulaValues: boolean; @@ -25,3 +33,29 @@ export interface CsvConfig { size: number; }; } + +/** + * @internal + * Needed to separate dependencies from reporting + */ +export interface CancellationToken { + isCancelled: () => boolean; + cancel: () => void; +} + +/** + * @internal + * Needed to separate dependencies from reporting + */ +export interface TaskRunResult { + content_type: string; + csv_contains_formulas: boolean; + max_size_reached: boolean; + metrics: { + csv: { + rows: number; + }; + }; + warnings: unknown; + error_code: unknown; +} diff --git a/packages/kbn-generate-csv/src/constants.ts b/packages/kbn-generate-csv/src/constants.ts index cdaadf7451e37..01538035c9094 100644 --- a/packages/kbn-generate-csv/src/constants.ts +++ b/packages/kbn-generate-csv/src/constants.ts @@ -6,7 +6,12 @@ * Side Public License, v 1. */ +/** + * These can not be imported from reporting-common due to potential for circular dependency + */ export const CSV_BOM_CHARS = '\ufeff'; export const CONTENT_TYPE_CSV = 'text/csv'; export const UI_SETTINGS_CSV_SEPARATOR = 'csv:separator'; export const UI_SETTINGS_CSV_QUOTE_VALUES = 'csv:quoteValues'; +export const UI_SETTINGS_SEARCH_INCLUDE_FROZEN = 'search:includeFrozen'; +export const UI_SETTINGS_DATEFORMAT_TZ = 'dateFormat:tz'; diff --git a/packages/kbn-generate-csv/src/generate_csv.test.ts b/packages/kbn-generate-csv/src/generate_csv.test.ts index 52f15d6a82c49..6bfd567ea0424 100644 --- a/packages/kbn-generate-csv/src/generate_csv.test.ts +++ b/packages/kbn-generate-csv/src/generate_csv.test.ts @@ -24,14 +24,22 @@ import { identity, range } from 'lodash'; import * as Rx from 'rxjs'; import type { Writable } from 'stream'; import { CsvGenerator } from './generate_csv'; -import { CancellationToken, UI_SETTINGS_DATEFORMAT_TZ } from '@kbn/reporting-common'; -import { CsvConfig, JobParams } from '@kbn/generate-csv-types'; -import { UI_SETTINGS_CSV_QUOTE_VALUES, UI_SETTINGS_CSV_SEPARATOR } from './constants'; +import { CancellationToken, CsvConfig, JobParams } from '@kbn/generate-csv-types'; +import { + UI_SETTINGS_CSV_QUOTE_VALUES, + UI_SETTINGS_CSV_SEPARATOR, + UI_SETTINGS_DATEFORMAT_TZ, +} from './constants'; const createMockJob = (baseObj: any = {}): JobParams => ({ ...baseObj, }); +const createMockCancellationToken = (): CancellationToken => ({ + isCancelled: () => false, + cancel: jest.fn(), +}); + describe('CsvGenerator', () => { let mockEsClient: IScopedClusterClient; let mockDataClient: IScopedSearchClient; @@ -146,7 +154,7 @@ describe('CsvGenerator', () => { searchSourceStart: mockSearchSourceService, fieldFormatsRegistry: mockFieldFormatsRegistry, }, - new CancellationToken(), + createMockCancellationToken(), mockLogger, stream ); @@ -181,7 +189,7 @@ describe('CsvGenerator', () => { searchSourceStart: mockSearchSourceService, fieldFormatsRegistry: mockFieldFormatsRegistry, }, - new CancellationToken(), + createMockCancellationToken(), mockLogger, stream ); @@ -220,7 +228,7 @@ describe('CsvGenerator', () => { searchSourceStart: mockSearchSourceService, fieldFormatsRegistry: mockFieldFormatsRegistry, }, - new CancellationToken(), + createMockCancellationToken(), mockLogger, stream ); @@ -268,7 +276,7 @@ describe('CsvGenerator', () => { searchSourceStart: mockSearchSourceService, fieldFormatsRegistry: mockFieldFormatsRegistry, }, - new CancellationToken(), + createMockCancellationToken(), mockLogger, stream ); @@ -327,7 +335,7 @@ describe('CsvGenerator', () => { searchSourceStart: mockSearchSourceService, fieldFormatsRegistry: mockFieldFormatsRegistry, }, - new CancellationToken(), + createMockCancellationToken(), mockLogger, stream ); @@ -397,7 +405,7 @@ describe('CsvGenerator', () => { searchSourceStart: mockSearchSourceService, fieldFormatsRegistry: mockFieldFormatsRegistry, }, - new CancellationToken(), + createMockCancellationToken(), mockLogger, stream ); @@ -435,7 +443,7 @@ describe('CsvGenerator', () => { searchSourceStart: mockSearchSourceService, fieldFormatsRegistry: mockFieldFormatsRegistry, }, - new CancellationToken(), + createMockCancellationToken(), mockLogger, stream ); @@ -482,7 +490,7 @@ describe('CsvGenerator', () => { searchSourceStart: mockSearchSourceService, fieldFormatsRegistry: mockFieldFormatsRegistry, }, - new CancellationToken(), + createMockCancellationToken(), mockLogger, stream ); @@ -536,7 +544,7 @@ describe('CsvGenerator', () => { searchSourceStart: mockSearchSourceService, fieldFormatsRegistry: mockFieldFormatsRegistry, }, - new CancellationToken(), + createMockCancellationToken(), mockLogger, stream ); @@ -578,7 +586,7 @@ describe('CsvGenerator', () => { searchSourceStart: mockSearchSourceService, fieldFormatsRegistry: mockFieldFormatsRegistry, }, - new CancellationToken(), + createMockCancellationToken(), mockLogger, stream ); @@ -616,7 +624,7 @@ describe('CsvGenerator', () => { searchSourceStart: mockSearchSourceService, fieldFormatsRegistry: mockFieldFormatsRegistry, }, - new CancellationToken(), + createMockCancellationToken(), mockLogger, stream ); @@ -654,7 +662,7 @@ describe('CsvGenerator', () => { searchSourceStart: mockSearchSourceService, fieldFormatsRegistry: mockFieldFormatsRegistry, }, - new CancellationToken(), + createMockCancellationToken(), mockLogger, stream ); @@ -694,7 +702,7 @@ describe('CsvGenerator', () => { searchSourceStart: mockSearchSourceService, fieldFormatsRegistry: mockFieldFormatsRegistry, }, - new CancellationToken(), + createMockCancellationToken(), mockLogger, stream ); @@ -732,7 +740,7 @@ describe('CsvGenerator', () => { searchSourceStart: mockSearchSourceService, fieldFormatsRegistry: mockFieldFormatsRegistry, }, - new CancellationToken(), + createMockCancellationToken(), mockLogger, stream ); @@ -777,7 +785,7 @@ describe('CsvGenerator', () => { searchSourceStart: mockSearchSourceService, fieldFormatsRegistry: mockFieldFormatsRegistry, }, - new CancellationToken(), + createMockCancellationToken(), mockLogger, stream ); @@ -806,7 +814,7 @@ describe('CsvGenerator', () => { searchSourceStart: mockSearchSourceService, fieldFormatsRegistry: mockFieldFormatsRegistry, }, - new CancellationToken(), + createMockCancellationToken(), mockLogger, stream ); @@ -864,7 +872,7 @@ describe('CsvGenerator', () => { searchSourceStart: mockSearchSourceService, fieldFormatsRegistry: mockFieldFormatsRegistry, }, - new CancellationToken(), + createMockCancellationToken(), mockLogger, stream ); @@ -908,7 +916,7 @@ describe('CsvGenerator', () => { searchSourceStart: mockSearchSourceService, fieldFormatsRegistry: mockFieldFormatsRegistry, }, - new CancellationToken(), + createMockCancellationToken(), mockLogger, stream ); @@ -957,7 +965,7 @@ describe('CsvGenerator', () => { searchSourceStart: mockSearchSourceService, fieldFormatsRegistry: mockFieldFormatsRegistry, }, - new CancellationToken(), + createMockCancellationToken(), mockLogger, stream ); @@ -1016,7 +1024,7 @@ describe('CsvGenerator', () => { searchSourceStart: mockSearchSourceService, fieldFormatsRegistry: mockFieldFormatsRegistry, }, - new CancellationToken(), + createMockCancellationToken(), mockLogger, stream ); diff --git a/packages/kbn-generate-csv/src/generate_csv.ts b/packages/kbn-generate-csv/src/generate_csv.ts index 609844284995e..558cbd8100df5 100644 --- a/packages/kbn-generate-csv/src/generate_csv.ts +++ b/packages/kbn-generate-csv/src/generate_csv.ts @@ -6,10 +6,13 @@ * Side Public License, v 1. */ +import { lastValueFrom } from 'rxjs'; +import type { Writable } from 'stream'; + import { errors as esErrors, estypes } from '@elastic/elasticsearch'; import type { IScopedClusterClient, IUiSettingsClient, Logger } from '@kbn/core/server'; import type { ISearchSource, ISearchStartSearchSource } from '@kbn/data-plugin/common'; -import { cellHasFormulas, ES_SEARCH_STRATEGY, tabifyDocs } from '@kbn/data-plugin/common'; +import { ES_SEARCH_STRATEGY, cellHasFormulas, tabifyDocs } from '@kbn/data-plugin/common'; import type { IScopedSearchClient } from '@kbn/data-plugin/server'; import type { Datatable } from '@kbn/expressions-plugin/server'; import type { @@ -17,20 +20,12 @@ import type { FieldFormatConfig, IFieldFormatsRegistry, } from '@kbn/field-formats-plugin/common'; -import { lastValueFrom } from 'rxjs'; -import type { Writable } from 'stream'; -import { - CancellationToken, - byteSizeValueToNumber, - ReportingError, - AuthenticationExpiredError, -} from '@kbn/reporting-common'; -import { CsvConfig, JobParams } from '@kbn/generate-csv-types'; -import type { TaskRunResult } from '@kbn/reporting-export-types-helpers-public'; -import { MaxSizeStringBuilder } from './max_size_string_builder'; -import { i18nTexts } from './i18n_texts'; -import { CsvExportSettings, getExportSettings } from './get_export_settings'; + +import { CancellationToken, CsvConfig, JobParams, TaskRunResult } from '@kbn/generate-csv-types'; import { CONTENT_TYPE_CSV } from './constants'; +import { CsvExportSettings, getExportSettings } from './get_export_settings'; +import { i18nTexts } from './i18n_texts'; +import { MaxSizeStringBuilder } from './max_size_string_builder'; interface Clients { es: IScopedClusterClient; diff --git a/packages/kbn-generate-csv/src/get_export_settings.test.ts b/packages/kbn-generate-csv/src/get_export_settings.test.ts index 4afbeeabcdaa5..6d1834880a2b4 100644 --- a/packages/kbn-generate-csv/src/get_export_settings.test.ts +++ b/packages/kbn-generate-csv/src/get_export_settings.test.ts @@ -6,10 +6,6 @@ * Side Public License, v 1. */ -import { - UI_SETTINGS_SEARCH_INCLUDE_FROZEN, - UI_SETTINGS_DATEFORMAT_TZ, -} from '@kbn/reporting-common'; import { IUiSettingsClient } from '@kbn/core/server'; import { loggingSystemMock, @@ -18,7 +14,12 @@ import { } from '@kbn/core/server/mocks'; import { getExportSettings } from './get_export_settings'; import { CsvConfig } from '@kbn/generate-csv-types'; -import { UI_SETTINGS_CSV_QUOTE_VALUES, UI_SETTINGS_CSV_SEPARATOR } from './constants'; +import { + UI_SETTINGS_CSV_QUOTE_VALUES, + UI_SETTINGS_CSV_SEPARATOR, + UI_SETTINGS_DATEFORMAT_TZ, + UI_SETTINGS_SEARCH_INCLUDE_FROZEN, +} from './constants'; describe('getExportSettings', () => { let uiSettingsClient: IUiSettingsClient; diff --git a/packages/kbn-generate-csv/src/get_export_settings.ts b/packages/kbn-generate-csv/src/get_export_settings.ts index 46d31afaf9e4f..68d974b811378 100644 --- a/packages/kbn-generate-csv/src/get_export_settings.ts +++ b/packages/kbn-generate-csv/src/get_export_settings.ts @@ -10,14 +10,12 @@ import { ByteSizeValue } from '@kbn/config-schema'; import type { IUiSettingsClient, Logger } from '@kbn/core/server'; import { createEscapeValue } from '@kbn/data-plugin/common'; import { CsvConfig } from '@kbn/generate-csv-types'; -import { - UI_SETTINGS_DATEFORMAT_TZ, - UI_SETTINGS_SEARCH_INCLUDE_FROZEN, -} from '@kbn/reporting-common'; import { CSV_BOM_CHARS, UI_SETTINGS_CSV_QUOTE_VALUES, UI_SETTINGS_CSV_SEPARATOR, + UI_SETTINGS_DATEFORMAT_TZ, + UI_SETTINGS_SEARCH_INCLUDE_FROZEN, } from './constants'; export interface CsvExportSettings { diff --git a/packages/kbn-generate-csv/tsconfig.json b/packages/kbn-generate-csv/tsconfig.json index ccfeab0a04c0f..a66a8149968d0 100644 --- a/packages/kbn-generate-csv/tsconfig.json +++ b/packages/kbn-generate-csv/tsconfig.json @@ -21,10 +21,8 @@ "@kbn/data-plugin", "@kbn/expressions-plugin", "@kbn/field-formats-plugin", - "@kbn/reporting-common", "@kbn/config-schema", "@kbn/i18n", "@kbn/generate-csv-types", - "@kbn/reporting-export-types-helpers-public", ] } diff --git a/packages/kbn-reporting/export_types_helpers_server/get_full_redirect_app_url.test.ts b/packages/kbn-reporting/common/get_full_redirect_app_url.test.ts similarity index 95% rename from packages/kbn-reporting/export_types_helpers_server/get_full_redirect_app_url.test.ts rename to packages/kbn-reporting/common/get_full_redirect_app_url.test.ts index 5d15f373a42ec..64f2ba4452612 100644 --- a/packages/kbn-reporting/export_types_helpers_server/get_full_redirect_app_url.test.ts +++ b/packages/kbn-reporting/common/get_full_redirect_app_url.test.ts @@ -6,7 +6,6 @@ * Side Public License, v 1. */ -import { ReportingConfigType } from '@kbn/reporting-common'; import { getFullRedirectAppUrl } from './get_full_redirect_app_url'; describe('getFullRedirectAppUrl', () => { diff --git a/packages/kbn-reporting/export_types_helpers_server/get_full_redirect_app_url.ts b/packages/kbn-reporting/common/get_full_redirect_app_url.ts similarity index 78% rename from packages/kbn-reporting/export_types_helpers_server/get_full_redirect_app_url.ts rename to packages/kbn-reporting/common/get_full_redirect_app_url.ts index b0c030c88d627..1b53cee4c1e33 100644 --- a/packages/kbn-reporting/export_types_helpers_server/get_full_redirect_app_url.ts +++ b/packages/kbn-reporting/common/get_full_redirect_app_url.ts @@ -7,10 +7,8 @@ */ import { format } from 'url'; -import { getRedirectAppPath } from '@kbn/reporting-common/constants'; -import { ReportingConfigType } from '@kbn/reporting-common/schema'; -import { buildKibanaPath } from '@kbn/reporting-common/build_kibana_path'; -import { ReportingServerInfo } from './types'; +import { buildKibanaPath } from './build_kibana_path'; +import { getRedirectAppPath } from './constants'; export function getFullRedirectAppUrl( config: ReportingConfigType, diff --git a/packages/kbn-reporting/common/index.ts b/packages/kbn-reporting/common/index.ts index 268fce26be157..4574c435fc8a1 100644 --- a/packages/kbn-reporting/common/index.ts +++ b/packages/kbn-reporting/common/index.ts @@ -11,7 +11,6 @@ export { buildKibanaPath } from './build_kibana_path'; export * from './constants'; export * from './errors'; export * from './schema_utils'; -export * from './schema'; export * as jobTypes from './job_types'; export * from './report_types'; export type { diff --git a/packages/kbn-reporting/export_types_helpers_public/metrics.ts b/packages/kbn-reporting/common/types.ts similarity index 51% rename from packages/kbn-reporting/export_types_helpers_public/metrics.ts rename to packages/kbn-reporting/common/types.ts index a1ac55ddf6360..e102ea79ab29a 100644 --- a/packages/kbn-reporting/export_types_helpers_public/metrics.ts +++ b/packages/kbn-reporting/common/types.ts @@ -6,11 +6,7 @@ * Side Public License, v 1. */ -import type { PdfScreenshotResult, PngScreenshotResult } from '@kbn/screenshotting-plugin/server'; - -export type PngMetrics = PngScreenshotResult['metrics']; - -export type PdfMetrics = PdfScreenshotResult['metrics']; +import type { LocatorParams } from '.'; export interface CsvMetrics { rows: number; @@ -18,8 +14,8 @@ export interface CsvMetrics { export interface TaskRunMetrics { csv?: CsvMetrics; - png?: PngMetrics; - pdf?: PdfMetrics; + png?: unknown; + pdf?: unknown; } export interface TaskRunResult { @@ -38,3 +34,47 @@ export interface TaskRunResult { */ error_code?: string; } + +export interface ReportOutput extends TaskRunResult { + content: string | null; + size: number; +} + +/** + * @deprecated + */ +export interface BaseParams { + layout?: unknown; + objectType: string; + title: string; + browserTimezone: string; // to format dates in the user's time zone + version: string; // to handle any state migrations +} + +/** + * Report job parameters that an application must return from its + * getSharingData function. + */ +export type BaseParamsV2 = BaseParams & { + locatorParams: LocatorParams[]; +}; + +/** + * @deprecated + */ +export interface BasePayload extends BaseParams { + headers: string; + spaceId?: string; + isDeprecated?: boolean; +} + +export type JobId = string; + +/** + * Report job parameters, after they are processed in the request handler. + */ +export interface BasePayloadV2 extends BaseParamsV2 { + headers: string; + spaceId?: string; + isDeprecated?: boolean; +} diff --git a/packages/kbn-reporting/export_types/csv/csv_searchsource_immediate.ts b/packages/kbn-reporting/export_types/csv/csv_searchsource_immediate.ts index 05bfbf836a330..2a7a9efbf758a 100644 --- a/packages/kbn-reporting/export_types/csv/csv_searchsource_immediate.ts +++ b/packages/kbn-reporting/export_types/csv/csv_searchsource_immediate.ts @@ -28,7 +28,6 @@ import type { JobParamsDownloadCSV, } from '@kbn/reporting-export-types-helpers-server'; import { getFieldFormats, ExportType } from '@kbn/reporting-export-types-helpers-server'; -import type { TaskRunResult } from '@kbn/reporting-export-types-helpers-public'; type CsvSearchSourceImmediateExportTypeSetupDeps = BaseExportTypeSetupDeps; interface CsvSearchSourceImmediateExportTypeStartDeps extends BaseExportTypeStartDeps { diff --git a/packages/kbn-reporting/export_types/deprecated/printable_pdf.ts b/packages/kbn-reporting/export_types/deprecated/printable_pdf.ts index 3a90a8af24e1f..006cb75b90ff7 100644 --- a/packages/kbn-reporting/export_types/deprecated/printable_pdf.ts +++ b/packages/kbn-reporting/export_types/deprecated/printable_pdf.ts @@ -6,6 +6,11 @@ * Side Public License, v 1. */ +import apm from 'elastic-apm-node'; +import { Observable, fromEventPattern, lastValueFrom, of, throwError } from 'rxjs'; +import { catchError, map, mergeMap, takeUntil, tap } from 'rxjs/operators'; +import { Writable } from 'stream'; + import type { LicenseType } from '@kbn/licensing-plugin/server'; import { CancellationToken, @@ -18,23 +23,18 @@ import { REPORTING_REDIRECT_LOCATOR_STORE_KEY, REPORTING_TRANSACTION_TYPE, } from '@kbn/reporting-common'; -import { Writable } from 'stream'; -import apm from 'elastic-apm-node'; -import { catchError, map, mergeMap, takeUntil, tap } from 'rxjs/operators'; -import { fromEventPattern, lastValueFrom, Observable, of, throwError } from 'rxjs'; -import type { PdfScreenshotOptions, PdfScreenshotResult } from '@kbn/screenshotting-plugin/server'; -import { LayoutParams } from '@kbn/screenshotting-plugin/common'; +import { BaseParams, TaskRunResult } from '@kbn/reporting-common/types'; import { - decryptJobHeaders, ExportType, + TaskPayloadPDF, + decryptJobHeaders, generatePdfObservable, getCustomLogo, getFullUrls, validateUrls, - BaseParams, - TaskPayloadPDF, } from '@kbn/reporting-export-types-helpers-server'; -import type { TaskRunResult } from '@kbn/reporting-export-types-helpers-public'; +import { LayoutParams } from '@kbn/screenshotting-plugin/common'; +import type { PdfScreenshotOptions, PdfScreenshotResult } from '@kbn/screenshotting-plugin/server'; interface BaseParamsPDF { layout: LayoutParams; diff --git a/packages/kbn-reporting/export_types/png/png_v2.ts b/packages/kbn-reporting/export_types/png/png_v2.ts index 3e5112c736327..5cb6c8d74e41f 100644 --- a/packages/kbn-reporting/export_types/png/png_v2.ts +++ b/packages/kbn-reporting/export_types/png/png_v2.ts @@ -44,7 +44,6 @@ import { JobParamsPNGV2, TaskPayloadPNGV2, } from '@kbn/reporting-export-types-helpers-server'; -import type { TaskRunResult } from '@kbn/reporting-export-types-helpers-public'; export class PngExportType extends ExportType { id = PNG_REPORT_TYPE_V2; diff --git a/packages/kbn-reporting/export_types/printable_pdf_v2/printable_pdf_v2.ts b/packages/kbn-reporting/export_types/printable_pdf_v2/printable_pdf_v2.ts index b608bee49bd6e..1dac900cf1138 100644 --- a/packages/kbn-reporting/export_types/printable_pdf_v2/printable_pdf_v2.ts +++ b/packages/kbn-reporting/export_types/printable_pdf_v2/printable_pdf_v2.ts @@ -43,7 +43,6 @@ import { JobParamsPDFV2, TaskPayloadPDFV2, } from '@kbn/reporting-export-types-helpers-server'; -import type { TaskRunResult } from '@kbn/reporting-export-types-helpers-public'; import { UrlOrUrlWithContext } from '@kbn/screenshotting-plugin/server/screenshots'; export class PdfExportType extends ExportType { diff --git a/packages/kbn-reporting/export_types_helpers_public/constants.ts b/packages/kbn-reporting/export_types_helpers_public/constants.ts index 1f1afb8b2e7bb..47b078d84eb09 100644 --- a/packages/kbn-reporting/export_types_helpers_public/constants.ts +++ b/packages/kbn-reporting/export_types_helpers_public/constants.ts @@ -7,7 +7,6 @@ */ import { SerializableRecord } from '@kbn/utility-types'; -import type { BaseParams } from '@kbn/reporting-export-types-helpers-server'; export const CSV_SEARCHSOURCE_IMMEDIATE_TYPE = 'csv_searchsource_immediate'; // Licenses @@ -32,36 +31,3 @@ export interface LocatorParams

DownloadLink; - -type ManagementLink = string; -export type ManagementLinkFn = () => ManagementLink; diff --git a/packages/kbn-reporting/export_types_helpers_public/index.ts b/packages/kbn-reporting/export_types_helpers_public/index.ts index c380f375a5622..d8989abcc3d6f 100644 --- a/packages/kbn-reporting/export_types_helpers_public/index.ts +++ b/packages/kbn-reporting/export_types_helpers_public/index.ts @@ -7,4 +7,3 @@ */ export * from './constants'; -export * from './metrics'; diff --git a/packages/kbn-reporting/export_types_helpers_public/tsconfig.json b/packages/kbn-reporting/export_types_helpers_public/tsconfig.json index db8ec3225b6da..3bf28b2b7b04c 100644 --- a/packages/kbn-reporting/export_types_helpers_public/tsconfig.json +++ b/packages/kbn-reporting/export_types_helpers_public/tsconfig.json @@ -17,6 +17,5 @@ "kbn_references": [ "@kbn/screenshotting-plugin", "@kbn/utility-types", - "@kbn/reporting-export-types-helpers-server", ] } diff --git a/packages/kbn-reporting/export_types_helpers_server/export_type.ts b/packages/kbn-reporting/export_types_helpers_server/export_type.ts index 93934046a0562..828e7bae57cd3 100644 --- a/packages/kbn-reporting/export_types_helpers_server/export_type.ts +++ b/packages/kbn-reporting/export_types_helpers_server/export_type.ts @@ -25,7 +25,7 @@ import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common'; import type { SpacesPluginSetup } from '@kbn/spaces-plugin/server'; import type { IClusterClient } from '@kbn/core-elasticsearch-server'; import { CoreKibanaRequest } from '@kbn/core-http-router-server-internal'; -import { CreateJobFn, ReportingConfigType, ReportingServerInfo, RunTaskFn } from './types'; +import { CreateJobFn, ReportingServerInfo, RunTaskFn } from './types'; export interface BaseExportTypeSetupDeps { basePath: Pick; diff --git a/packages/kbn-reporting/export_types_helpers_server/generate_pdf.ts b/packages/kbn-reporting/export_types_helpers_server/generate_pdf.ts index 6659ae2ed58d8..5703e16e48abc 100644 --- a/packages/kbn-reporting/export_types_helpers_server/generate_pdf.ts +++ b/packages/kbn-reporting/export_types_helpers_server/generate_pdf.ts @@ -6,15 +6,15 @@ * Side Public License, v 1. */ -import type { PdfScreenshotOptions, PdfScreenshotResult } from '@kbn/screenshotting-plugin/server'; import { Observable } from 'rxjs'; import { mergeMap, tap } from 'rxjs/operators'; -import type { PdfMetrics } from '@kbn/reporting-export-types-helpers-public'; + +import type { PdfScreenshotOptions, PdfScreenshotResult } from '@kbn/screenshotting-plugin/server'; import { getTracker } from './pdf_tracker'; interface PdfResult { buffer: Uint8Array | null; - metrics?: PdfMetrics; + metrics?: PdfScreenshotResult['metrics']; warnings: string[]; } diff --git a/packages/kbn-reporting/export_types_helpers_server/generate_pdf_v2.ts b/packages/kbn-reporting/export_types_helpers_server/generate_pdf_v2.ts index c6efac063a2fe..d6a933c29abd4 100644 --- a/packages/kbn-reporting/export_types_helpers_server/generate_pdf_v2.ts +++ b/packages/kbn-reporting/export_types_helpers_server/generate_pdf_v2.ts @@ -10,15 +10,14 @@ import { mergeMap, tap } from 'rxjs/operators'; import type { PdfScreenshotOptions, PdfScreenshotResult } from '@kbn/screenshotting-plugin/server'; import { Observable } from 'rxjs'; import type { UrlOrUrlWithContext } from '@kbn/screenshotting-plugin/server/screenshots'; -import { LocatorParams, ReportingConfigType } from '@kbn/reporting-common'; -import type { PdfMetrics } from '@kbn/reporting-export-types-helpers-public'; +import { LocatorParams } from '@kbn/reporting-common'; import { ReportingServerInfo, TaskPayloadPDFV2 } from './types'; import { getTracker } from './pdf_tracker'; import { getFullRedirectAppUrl } from '.'; interface PdfResult { buffer: Uint8Array | null; - metrics?: PdfMetrics; + metrics?: PdfScreenshotResult['metrics']; warnings: string[]; } diff --git a/packages/kbn-reporting/export_types_helpers_server/generate_png.ts b/packages/kbn-reporting/export_types_helpers_server/generate_png.ts index e629170ee0072..d0ce9b9791690 100644 --- a/packages/kbn-reporting/export_types_helpers_server/generate_png.ts +++ b/packages/kbn-reporting/export_types_helpers_server/generate_png.ts @@ -7,16 +7,16 @@ */ import apm from 'elastic-apm-node'; -import type { Logger } from '@kbn/logging'; -import { finalize, map, tap } from 'rxjs/operators'; -import type { PngScreenshotOptions, PngScreenshotResult } from '@kbn/screenshotting-plugin/server'; import { Observable } from 'rxjs'; -import type { PngMetrics } from '@kbn/reporting-export-types-helpers-public'; +import { finalize, map, tap } from 'rxjs/operators'; + +import type { Logger } from '@kbn/logging'; import { REPORTING_TRANSACTION_TYPE } from '@kbn/reporting-common/constants'; +import type { PngScreenshotOptions, PngScreenshotResult } from '@kbn/screenshotting-plugin/server'; interface PngResult { buffer: Buffer; - metrics?: PngMetrics; + metrics?: PngScreenshotResult['metrics']; warnings: string[]; } diff --git a/packages/kbn-reporting/export_types_helpers_server/get_full_urls.test.ts b/packages/kbn-reporting/export_types_helpers_server/get_full_urls.test.ts index 96d74dcf838ac..228152016d5cb 100644 --- a/packages/kbn-reporting/export_types_helpers_server/get_full_urls.test.ts +++ b/packages/kbn-reporting/export_types_helpers_server/get_full_urls.test.ts @@ -6,7 +6,6 @@ * Side Public License, v 1. */ -import { ReportingConfigType } from '@kbn/reporting-common/schema'; import { TaskPayloadPDF, ReportingServerInfo } from './types'; import { getFullUrls } from './get_full_urls'; diff --git a/packages/kbn-reporting/export_types_helpers_server/get_full_urls.ts b/packages/kbn-reporting/export_types_helpers_server/get_full_urls.ts index bd4bd7f556b65..726377d08325c 100644 --- a/packages/kbn-reporting/export_types_helpers_server/get_full_urls.ts +++ b/packages/kbn-reporting/export_types_helpers_server/get_full_urls.ts @@ -12,7 +12,7 @@ import { UrlWithParsedQuery, UrlWithStringQuery, } from 'url'; -import { ReportingConfigType, ReportingServerInfo, TaskPayloadPDF } from './types'; +import { ReportingServerInfo, TaskPayloadPDF } from './types'; import { getAbsoluteUrlFactory } from './get_absolute_url'; import { validateUrls } from './validate_urls'; diff --git a/packages/kbn-reporting/export_types_helpers_server/tsconfig.json b/packages/kbn-reporting/export_types_helpers_server/tsconfig.json index fd9b2076c049e..e82c46d680444 100644 --- a/packages/kbn-reporting/export_types_helpers_server/tsconfig.json +++ b/packages/kbn-reporting/export_types_helpers_server/tsconfig.json @@ -36,6 +36,5 @@ "@kbn/core-http-request-handler-context-server", "@kbn/utility-types", "@kbn/config-schema", - "@kbn/reporting-export-types-helpers-public", ] } diff --git a/packages/kbn-reporting/export_types_helpers_server/types.ts b/packages/kbn-reporting/export_types_helpers_server/types.ts index b49bc13273429..f51e5c3ce53dc 100644 --- a/packages/kbn-reporting/export_types_helpers_server/types.ts +++ b/packages/kbn-reporting/export_types_helpers_server/types.ts @@ -7,59 +7,16 @@ */ import { Writable } from 'stream'; -import type { SerializedSearchSourceFields } from '@kbn/data-plugin/common'; +import type { + BaseParams, + BaseParamsV2, + BasePayload, + BasePayloadV2, + TaskRunResult, +} from '@kbn/reporting-common/types'; import type { CustomRequestHandlerContext } from '@kbn/core-http-request-handler-context-server'; import type { KibanaRequest } from '@kbn/core-http-server'; -import type { LocatorParams, ConfigSchema, CancellationToken } from '@kbn/reporting-common'; -import type { Ensure, SerializableRecord } from '@kbn/utility-types'; -import type { LayoutParams } from '@kbn/screenshotting-plugin/common'; -import type { TypeOf } from '@kbn/config-schema'; -import type { TaskRunResult } from '@kbn/reporting-export-types-helpers-public'; - -/** - * @deprecated - */ -export type BaseParams = Ensure< - { - layout?: LayoutParams; - objectType: string; - title: string; - browserTimezone: string; // to format dates in the user's time zone - version: string; // to handle any state migrations - }, - SerializableRecord ->; - -/** - * Report job parameters that an application must return from its - * getSharingData function. - */ -export type BaseParamsV2 = BaseParams & { - locatorParams: LocatorParams[]; -}; - -/** - * @deprecated - */ -export interface BasePayload extends BaseParams { - headers: string; - spaceId?: string; - isDeprecated?: boolean; -} - -export type JobId = string; - -/** - * Report job parameters, after they are processed in the request handler. - */ -export interface BasePayloadV2 extends BaseParamsV2 { - headers: string; - spaceId?: string; - isDeprecated?: boolean; -} - -// ExportType dependency types -export type ReportingConfigType = TypeOf; +import type { LocatorParams, CancellationToken } from '@kbn/reporting-common'; /** * @internal @@ -106,21 +63,25 @@ export type RunTaskFn = ( export interface JobParamsDownloadCSV { browserTimezone: string; title: string; - searchSource: SerializedSearchSourceFields; + searchSource: unknown; columns?: string[]; } +interface Layout { + id?: 'preserve_layout' | 'print' | 'canvas'; +} + /** * Structure of stored job data provided by create_job */ export interface TaskPayloadPDF extends BasePayload { - layout: LayoutParams; + layout: Layout; forceNow?: string; objects: Array<{ relativeUrl: string }>; } interface BaseParamsPNG { - layout: LayoutParams; + layout: Layout; forceNow?: string; relativeUrl: string; } @@ -135,7 +96,7 @@ export type JobParamsPNGDeprecated = BaseParamsPNG & BaseParams; export type TaskPayloadPNG = BaseParamsPNG & BasePayload; interface BaseParamsPDFV2 { - layout: LayoutParams; + layout: Layout; /** * This value is used to re-create the same visual state as when the report was requested as well as navigate to the correct page. @@ -150,14 +111,14 @@ export type JobAppParamsPDFV2 = Omit = { exposeToBrowser: { poll: true, roles: true, export_types: true, statefulSettings: true }, diff --git a/x-pack/plugins/reporting/server/config/schema.test.ts b/x-pack/plugins/reporting/server/config/schema.test.ts index 0814a435e88bc..f30be71db09ea 100644 --- a/x-pack/plugins/reporting/server/config/schema.test.ts +++ b/x-pack/plugins/reporting/server/config/schema.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { ConfigSchema } from '@kbn/reporting-common'; +import { ConfigSchema } from './schema'; describe('Reporting Config Schema', () => { it(`context {"dev":false,"dist":false} produces correct config`, () => { diff --git a/packages/kbn-reporting/common/schema.ts b/x-pack/plugins/reporting/server/config/schema.ts similarity index 96% rename from packages/kbn-reporting/common/schema.ts rename to x-pack/plugins/reporting/server/config/schema.ts index f7c910d9c425b..ff0cda89a693b 100644 --- a/packages/kbn-reporting/common/schema.ts +++ b/x-pack/plugins/reporting/server/config/schema.ts @@ -1,9 +1,8 @@ /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. */ import { ByteSizeValue, offeringBasedSchema, schema, TypeOf } from '@kbn/config-schema'; diff --git a/x-pack/plugins/reporting/server/lib/tasks/execute_report.test.ts b/x-pack/plugins/reporting/server/lib/tasks/execute_report.test.ts index 48729920b0bce..99a7b5adcc490 100644 --- a/x-pack/plugins/reporting/server/lib/tasks/execute_report.test.ts +++ b/x-pack/plugins/reporting/server/lib/tasks/execute_report.test.ts @@ -6,10 +6,11 @@ */ import { loggingSystemMock } from '@kbn/core/server/mocks'; -import { ExportType } from '@kbn/reporting-export-types-helpers-server'; -import { KibanaShuttingDownError } from '@kbn/generate-csv/src/errors'; +import { KibanaShuttingDownError } from '@kbn/reporting-common'; +import type { ExportType } from '@kbn/reporting-export-types-helpers-server'; import type { RunContext } from '@kbn/task-manager-plugin/server'; import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks'; + import { ExecuteReportTask } from '.'; import type { ReportingCore } from '../..'; import type { ReportingConfigType } from '../../config'; diff --git a/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts b/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts index 318fbec44a9b3..0fa21b17c6d64 100644 --- a/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts +++ b/x-pack/plugins/reporting/server/lib/tasks/execute_report.ts @@ -7,33 +7,34 @@ import { UpdateResponse } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import type { Logger } from '@kbn/core/server'; +import { + CancellationToken, + KibanaShuttingDownError, + QueueTimeoutError, + ReportingError, +} from '@kbn/reporting-common'; +import type { + RunContext, + TaskManagerStartContract, + TaskRunCreatorFunction, +} from '@kbn/task-manager-plugin/server'; import moment from 'moment'; import * as Rx from 'rxjs'; import { timeout } from 'rxjs/operators'; import { Writable } from 'stream'; import { finished } from 'stream/promises'; import { setTimeout } from 'timers/promises'; -import type { - RunContext, - TaskManagerStartContract, - TaskRunCreatorFunction, -} from '@kbn/task-manager-plugin/server'; -import { CancellationToken, TaskRunResult } from '@kbn/reporting-common'; -import { - QueueTimeoutError, - ReportingError, - KibanaShuttingDownError, -} from '@kbn/generate-csv/src/errors'; -import { mapToReportingError } from '../../../common/errors/map_to_reporting_error'; + +import { REPORTING_EXECUTE_TYPE, ReportTaskParams, ReportingTask, ReportingTaskStatus } from '.'; import { ExportTypesRegistry, getContentStream } from '..'; import type { ReportingCore } from '../..'; +import { mapToReportingError } from '../../../common/errors/map_to_reporting_error'; import { durationToNumber, numberToDuration } from '../../../common/schema_utils'; -import type { ReportOutput } from '../../../common/types'; +import type { ReportOutput, TaskRunResult } from '../../../common/types'; import type { ReportingConfigType } from '../../config'; import type { ReportDocument, ReportingStore } from '../store'; import { Report, SavedReport } from '../store'; import type { ReportFailedFields, ReportProcessingFields } from '../store/store'; -import { ReportingTask, ReportingTaskStatus, REPORTING_EXECUTE_TYPE, ReportTaskParams } from '.'; import { errorLogger } from './error_logger'; type CompletedReportOutput = Omit;