Reporting packages for export types (#162845)

## Summary
This PR refactors the export type classes into their own packages to be
then instantiated in the reporting plugin. This will reduce bloat in the
central reporting plugin.

**Main packages**
- `kbn/reporting-export-types-{png,pdf,csv}` are server packages with
export type declarations
- `kbn/reporting-export-types-{png,pdf,csv}-common` are shared common
packages with type declarations and constants

**Other changes**
 - Remove `reporting.getScreenshots()`
 - Remove duplicated `schema_utils.ts`
 - Consolidate `JOB_STATUS` declaration as an enum

<img width="1063" alt="image"
src="bced8321-93c5-4ebd-b31e-1fd946166241">

### Checklist

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Timothy Sullivan <tsullivan@elastic.co>
This commit is contained in:
Rachel Shen 2023-11-15 10:48:00 -07:00 committed by GitHub
parent 0c4d3cc762
commit 4a0b967e38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
263 changed files with 2122 additions and 1630 deletions

10
.github/CODEOWNERS vendored
View file

@ -419,7 +419,6 @@ x-pack/examples/gen_ai_streaming_response_example @elastic/response-ops
packages/kbn-generate @elastic/kibana-operations
packages/kbn-generate-console-definitions @elastic/platform-deployment-management
packages/kbn-generate-csv @elastic/appex-sharedux
packages/kbn-generate-csv-types @elastic/appex-sharedux
packages/kbn-get-repo-files @elastic/kibana-operations
x-pack/plugins/global_search_bar @elastic/appex-sharedux
x-pack/plugins/global_search @elastic/appex-sharedux
@ -593,7 +592,16 @@ packages/kbn-repo-source-classifier @elastic/kibana-operations
packages/kbn-repo-source-classifier-cli @elastic/kibana-operations
packages/kbn-reporting/common @elastic/appex-sharedux
x-pack/examples/reporting_example @elastic/appex-sharedux
packages/kbn-reporting/export_types/csv @elastic/appex-sharedux
packages/kbn-reporting/export_types/csv_common @elastic/appex-sharedux
packages/kbn-reporting/export_types/pdf @elastic/appex-sharedux
packages/kbn-reporting/export_types/pdf_common @elastic/appex-sharedux
packages/kbn-reporting/export_types/png @elastic/appex-sharedux
packages/kbn-reporting/export_types/png_common @elastic/appex-sharedux
packages/kbn-reporting/mocks_server @elastic/appex-sharedux
x-pack/plugins/reporting @elastic/appex-sharedux
packages/kbn-reporting/public @elastic/appex-sharedux
packages/kbn-reporting/server @elastic/appex-sharedux
packages/kbn-resizable-layout @elastic/kibana-data-discovery
examples/resizable_layout_examples @elastic/kibana-data-discovery
x-pack/test/plugin_functional/plugins/resolver_test @elastic/security-solution

View file

@ -90,7 +90,7 @@
"randomSampling": "x-pack/packages/kbn-random-sampling",
"reactPackages": "packages/react",
"textBasedEditor": "packages/kbn-text-based-editor",
"reporting": "packages/kbn-reporting/common",
"reporting": "packages/kbn-reporting",
"savedObjects": "src/plugins/saved_objects",
"savedObjectsFinder": "src/plugins/saved_objects_finder",
"savedObjectsManagement": "src/plugins/saved_objects_management",

View file

@ -450,7 +450,6 @@
"@kbn/gen-ai-streaming-response-example-plugin": "link:x-pack/examples/gen_ai_streaming_response_example",
"@kbn/generate-console-definitions": "link:packages/kbn-generate-console-definitions",
"@kbn/generate-csv": "link:packages/kbn-generate-csv",
"@kbn/generate-csv-types": "link:packages/kbn-generate-csv-types",
"@kbn/global-search-bar-plugin": "link:x-pack/plugins/global_search_bar",
"@kbn/global-search-plugin": "link:x-pack/plugins/global_search",
"@kbn/global-search-providers-plugin": "link:x-pack/plugins/global_search_providers",
@ -597,7 +596,16 @@
"@kbn/repo-packages": "link:packages/kbn-repo-packages",
"@kbn/reporting-common": "link:packages/kbn-reporting/common",
"@kbn/reporting-example-plugin": "link:x-pack/examples/reporting_example",
"@kbn/reporting-export-types-csv": "link:packages/kbn-reporting/export_types/csv",
"@kbn/reporting-export-types-csv-common": "link:packages/kbn-reporting/export_types/csv_common",
"@kbn/reporting-export-types-pdf": "link:packages/kbn-reporting/export_types/pdf",
"@kbn/reporting-export-types-pdf-common": "link:packages/kbn-reporting/export_types/pdf_common",
"@kbn/reporting-export-types-png": "link:packages/kbn-reporting/export_types/png",
"@kbn/reporting-export-types-png-common": "link:packages/kbn-reporting/export_types/png_common",
"@kbn/reporting-mocks-server": "link:packages/kbn-reporting/mocks_server",
"@kbn/reporting-plugin": "link:x-pack/plugins/reporting",
"@kbn/reporting-public": "link:packages/kbn-reporting/public",
"@kbn/reporting-server": "link:packages/kbn-reporting/server",
"@kbn/resizable-layout": "link:packages/kbn-resizable-layout",
"@kbn/resizable-layout-examples-plugin": "link:examples/resizable_layout_examples",
"@kbn/resolver-test-plugin": "link:x-pack/test/plugin_functional/plugins/resolver_test",

View file

@ -1,3 +0,0 @@
# @kbn/generate-csv-types
This package includes interfaces specific to the @kbn/generate-csv package.

View file

@ -1,5 +1,5 @@
{
"type": "shared-common",
"type": "shared-server",
"id": "@kbn/generate-csv",
"owner": "@elastic/appex-sharedux"
}

View file

@ -10,3 +10,5 @@ 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';

View file

@ -6,6 +6,10 @@
* Side Public License, v 1.
*/
import { identity, range } from 'lodash';
import * as Rx from 'rxjs';
import type { Writable } from 'stream';
import { errors as esErrors, estypes } from '@elastic/elasticsearch';
import type { SearchResponse } from '@elastic/elasticsearch/lib/api/types';
import type { IScopedClusterClient, IUiSettingsClient, Logger } from '@kbn/core/server';
@ -20,22 +24,24 @@ import { searchSourceInstanceMock } from '@kbn/data-plugin/common/search/search_
import { IScopedSearchClient } from '@kbn/data-plugin/server';
import { dataPluginMock } from '@kbn/data-plugin/server/mocks';
import { FieldFormatsRegistry } from '@kbn/field-formats-plugin/common';
import { identity, range } from 'lodash';
import * as Rx from 'rxjs';
import type { Writable } from 'stream';
import { CancellationToken } from '@kbn/reporting-common';
import type { ReportingConfigType } from '@kbn/reporting-server';
import { JobParamsCSV } from '@kbn/reporting-export-types-csv-common';
import {
UI_SETTINGS_CSV_QUOTE_VALUES,
UI_SETTINGS_CSV_SEPARATOR,
UI_SETTINGS_DATEFORMAT_TZ,
} from './constants';
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';
const createMockJob = (baseObj: any = {}): JobParams => ({
const createMockJob = (baseObj: any = {}): JobParamsCSV => ({
...baseObj,
});
describe('CsvGenerator', () => {
let mockEsClient: IScopedClusterClient;
let mockDataClient: IScopedSearchClient;
let mockConfig: CsvConfig;
let mockConfig: ReportingConfigType['csv'];
let mockLogger: jest.Mocked<Logger>;
let uiSettingsClient: IUiSettingsClient;
let stream: jest.Mocked<Writable>;
@ -111,6 +117,7 @@ describe('CsvGenerator', () => {
maxSizeBytes: 180000,
useByteOrderMarkEncoding: false,
scroll: { size: 500, duration: '30s' },
enablePanelActionDownload: true,
};
searchSourceMock.getField = jest.fn((key: string) => {
@ -237,6 +244,7 @@ describe('CsvGenerator', () => {
maxSizeBytes: TEST_MAX_SIZE,
useByteOrderMarkEncoding: false,
scroll: { size: 500, duration: '30s' },
enablePanelActionDownload: true,
};
mockDataClient.search = jest.fn().mockImplementation(() =>
@ -750,6 +758,7 @@ describe('CsvGenerator', () => {
maxSizeBytes: 180000,
useByteOrderMarkEncoding: false,
scroll: { size: 500, duration: '30s' },
enablePanelActionDownload: true,
};
mockDataClient.search = jest.fn().mockImplementation(() =>
Rx.of({

View file

@ -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,20 @@ import type {
FieldFormatConfig,
IFieldFormatsRegistry,
} from '@kbn/field-formats-plugin/common';
import { lastValueFrom } from 'rxjs';
import type { Writable } from 'stream';
import {
CancellationToken,
AuthenticationExpiredError,
CancellationToken,
ReportingError,
TaskRunResult,
byteSizeValueToNumber,
} from '@kbn/reporting-common';
import { CsvConfig, JobParams } from '@kbn/generate-csv-types';
import { MaxSizeStringBuilder } from './max_size_string_builder';
import { i18nTexts } from './i18n_texts';
import { CsvExportSettings, getExportSettings } from './get_export_settings';
import type { TaskRunResult } from '@kbn/reporting-common/types';
import type { ReportingConfigType } from '@kbn/reporting-server';
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';
import { JobParamsCSV } from '../types';
interface Clients {
es: IScopedClusterClient;
@ -49,8 +52,8 @@ export class CsvGenerator {
private csvRowCount = 0;
constructor(
private job: Omit<JobParams, 'version'>,
private config: CsvConfig,
private job: Omit<JobParamsCSV, 'version'>,
private config: ReportingConfigType['csv'],
private clients: Clients,
private dependencies: Dependencies,
private cancellationToken: CancellationToken,

View file

@ -6,28 +6,31 @@
* 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 type { IUiSettingsClient } from '@kbn/core/server';
import {
loggingSystemMock,
savedObjectsClientMock,
uiSettingsServiceMock,
} from '@kbn/core/server/mocks';
import type { ReportingConfigType } from '@kbn/reporting-server';
import {
UI_SETTINGS_CSV_QUOTE_VALUES,
UI_SETTINGS_CSV_SEPARATOR,
UI_SETTINGS_DATEFORMAT_TZ,
UI_SETTINGS_SEARCH_INCLUDE_FROZEN,
} from './constants';
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';
describe('getExportSettings', () => {
let uiSettingsClient: IUiSettingsClient;
const config: CsvConfig = {
const config: ReportingConfigType['csv'] = {
checkForFormulas: true,
escapeFormulaValues: false,
maxSizeBytes: 180000,
scroll: { size: 500, duration: '30s' },
useByteOrderMarkEncoding: false,
enablePanelActionDownload: true,
};
const logger = loggingSystemMock.createLogger();

View file

@ -6,18 +6,16 @@
* Side Public License, v 1.
*/
import { ByteSizeValue } from '@kbn/config-schema';
import type { 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 type { ReportingConfigType } from '@kbn/reporting-server';
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 {
@ -37,7 +35,7 @@ export interface CsvExportSettings {
export const getExportSettings = async (
client: IUiSettingsClient,
config: CsvConfig,
config: ReportingConfigType['csv'],
timezone: string | undefined,
logger: Logger
): Promise<CsvExportSettings> => {

View file

@ -21,9 +21,10 @@
"@kbn/data-plugin",
"@kbn/expressions-plugin",
"@kbn/field-formats-plugin",
"@kbn/reporting-common",
"@kbn/config-schema",
"@kbn/i18n",
"@kbn/generate-csv-types",
"@kbn/reporting-common",
"@kbn/reporting-server",
"@kbn/reporting-export-types-csv-common",
]
}

View file

@ -6,22 +6,13 @@
* Side Public License, v 1.
*/
import { ByteSizeValue } from '@kbn/config-schema';
import type { SerializedSearchSourceFields } from '@kbn/data-plugin/public';
export interface JobParams {
/**
* Duplicated from @kbn/reporting-export-types-csv-common to reduce dependencies
*/
export interface JobParamsCSV {
browserTimezone?: string;
searchSource: SerializedSearchSourceFields;
columns?: string[];
browserTimezone?: string;
}
export interface CsvConfig {
checkForFormulas: boolean;
escapeFormulaValues: boolean;
maxSizeBytes: number | ByteSizeValue;
useByteOrderMarkEncoding: boolean;
scroll: {
duration: string;
size: number;
};
}

View file

@ -2,4 +2,4 @@
Removes any circular dependency from the reporting plugin and the @kbn/generate-csv package.
This package includes the `CancellationToken` class, schema utils, constants, errors that extend `ReportingError`, and metrics such as `TaskRunResult`. p
This package includes the `CancellationToken` class, schema utils, constants, errors that extend `ReportingError`, and metrics such as `TaskRunResult`. This package is shared-common vs specifically server or browser. The `@kbn/reporting-server` package has the server side helpers.

View file

@ -1,8 +1,9 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
interface Args {

View file

@ -5,7 +5,74 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
export const PLUGIN_ID = 'reporting';
export const ALLOWED_JOB_CONTENT_TYPES = [
'application/json',
'application/pdf',
'text/csv',
'image/png',
'text/plain',
];
// APM
export const REPORTING_TRANSACTION_TYPE = PLUGIN_ID;
export const REPORTING_REDIRECT_LOCATOR_STORE_KEY = '__REPORTING_REDIRECT_LOCATOR_STORE_KEY__';
export const UI_SETTINGS_SEARCH_INCLUDE_FROZEN = 'search:includeFrozen';
export const UI_SETTINGS_CUSTOM_PDF_LOGO = 'xpackReporting:customPdfLogo';
export const UI_SETTINGS_DATEFORMAT_TZ = 'dateFormat:tz';
export const CSV_REPORTING_ACTION = 'downloadCsvReport';
// Licenses
export const LICENSE_TYPE_TRIAL = 'trial' as const;
export const LICENSE_TYPE_BASIC = 'basic' as const;
export const LICENSE_TYPE_CLOUD_STANDARD = 'standard' as const;
export const LICENSE_TYPE_GOLD = 'gold' as const;
export const LICENSE_TYPE_PLATINUM = 'platinum' as const;
export const LICENSE_TYPE_ENTERPRISE = 'enterprise' as const;
export const REPORTING_SYSTEM_INDEX = '.reporting';
export const JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY =
'xpack.reporting.jobCompletionNotifications';
/**
* A way to get the client side route for the reporting redirect app.
*
* TODO: Add a job ID and a locator to use so that we can redirect without expecting state to
* be injected to the page
*/
export const getRedirectAppPath = () => {
return '/app/reportingRedirect';
};
export const ILM_POLICY_NAME = 'kibana-reporting';
// Usage counter types
export const API_USAGE_COUNTER_TYPE = 'reportingApi';
export const API_USAGE_ERROR_TYPE = 'reportingApiError';
// Management UI route
export const REPORTING_MANAGEMENT_HOME = '/app/management/insightsAndAlerting/reporting';
/*
* JobStatus:
* - Begins as 'pending'
* - Changes to 'processing` when the job is claimed
* - Then 'completed' | 'failed' when execution is done
* If the job needs a retry, it reverts back to 'pending'.
*/
export enum JOB_STATUS {
PENDING = 'pending',
PROCESSING = 'processing',
COMPLETED = 'completed',
FAILED = 'failed',
WARNINGS = 'completed_with_warnings',
}
// Job params require a `version` field as of 7.15.0. For older jobs set with
// automation that have no version value in the job params, we assume the
// intended version is 7.14.0
export const UNVERSIONED_VERSION = '7.14.0';

View file

@ -6,8 +6,9 @@
* Side Public License, v 1.
*/
export { CancellationToken } from './cancellation_token';
export type { TaskRunMetrics, CsvMetrics, TaskRunResult } from './metrics';
export * from './errors';
export * from './constants';
export * from './errors';
export * from './schema_utils';
export { CancellationToken } from './cancellation_token';
export { buildKibanaPath } from './build_kibana_path';

View file

@ -1,5 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/reporting-common",
"owner": "@elastic/appex-sharedux"
"owner": "@elastic/appex-sharedux",
}

View file

@ -1,40 +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
* 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.
*/
import type { PdfScreenshotResult, PngScreenshotResult } from '@kbn/screenshotting-plugin/server';
export type PngMetrics = PngScreenshotResult['metrics'];
export type PdfMetrics = PdfScreenshotResult['metrics'];
export interface CsvMetrics {
rows: number;
}
export interface TaskRunMetrics {
csv?: CsvMetrics;
png?: PngMetrics;
pdf?: PdfMetrics;
}
export interface TaskRunResult {
content_type: string | null;
csv_contains_formulas?: boolean;
max_size_reached?: boolean;
warnings?: string[];
metrics?: TaskRunMetrics;
/**
* When running a report task we may finish with warnings that were triggered
* by an error. We can pass the error code via the task run result to the
* task runner so that it can be recorded for telemetry.
*
* Alternatively, this field can be populated in the event that the task does
* not complete in the task runner's error handler.
*/
error_code?: string;
}

View file

@ -5,7 +5,6 @@
"types": [
"jest",
"node",
"react"
]
},
"include": [
@ -16,8 +15,9 @@
"target/**/*"
],
"kbn_references": [
"@kbn/i18n",
"@kbn/screenshotting-plugin",
"@kbn/config-schema",
"@kbn/utility-types",
"@kbn/screenshotting-plugin",
"@kbn/i18n",
]
}

View file

@ -1,37 +1,45 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import { TaskRunMetrics, TaskRunResult } from '@kbn/reporting-common';
import type { PdfScreenshotResult, PngScreenshotResult } from '@kbn/screenshotting-plugin/server';
import type { BaseParams, BaseParamsV2, BasePayload, BasePayloadV2, JobId } from './base';
import type {
LayoutParams,
PerformanceMetrics as ScreenshotMetrics,
} from '@kbn/screenshotting-plugin/common';
import { JOB_STATUS } from './constants';
import type { LocatorParams } from './url';
export type {
JobParamsCsvFromSavedObject,
TaskPayloadCsvFromSavedObject,
} from './export_types/csv_v2';
export type { JobParamsPNGDeprecated } from './export_types/png';
export type { JobParamsPNGV2 } from './export_types/png_v2';
export type { JobAppParamsPDF, JobParamsPDFDeprecated } from './export_types/printable_pdf';
export type { JobAppParamsPDFV2, JobParamsPDFV2 } from './export_types/printable_pdf_v2';
export type {
DownloadReportFn,
IlmPolicyMigrationStatus,
IlmPolicyStatusResponse,
LocatorParams,
ManagementLinkFn,
UrlOrUrlLocatorTuple,
} from './url';
export type { JobId, BaseParams, BaseParamsV2, BasePayload, BasePayloadV2 };
export * from './url';
export interface ReportDocumentHead {
_id: string;
_index: string;
_seq_no: number;
_primary_term: number;
export interface CsvMetrics {
rows: number;
}
export interface TaskRunMetrics {
csv?: CsvMetrics;
png?: ScreenshotMetrics;
pdf?: ScreenshotMetrics & { pages?: number };
}
export interface TaskRunResult {
content_type: string | null;
csv_contains_formulas?: boolean;
max_size_reached?: boolean;
warnings?: string[];
metrics?: TaskRunMetrics;
/**
* When running a report task we may finish with warnings that were triggered
* by an error. We can pass the error code via the task run result to the
* task runner so that it can be recorded for telemetry.
*
* Alternatively, this field can be populated in the event that the task does
* not complete in the task runner's error handler.
*/
error_code?: string;
}
export interface ReportOutput extends TaskRunResult {
@ -39,9 +47,66 @@ export interface ReportOutput extends TaskRunResult {
size: number;
}
export type PngMetrics = PngScreenshotResult['metrics'];
/**
* @deprecated
*/
export interface BaseParams {
layout?: LayoutParams;
objectType: string;
title: string;
browserTimezone: string; // to format dates in the user's time zone
version: string; // to handle any state migrations
}
export type PdfMetrics = PdfScreenshotResult['metrics'];
/**
* 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;
}
export interface ReportingServerInfo {
basePath: string;
protocol: string;
hostname: string;
port: number;
name: string;
uuid: string;
}
export type IlmPolicyMigrationStatus = 'policy-not-found' | 'indices-not-managed-by-policy' | 'ok';
export interface IlmPolicyStatusResponse {
status: IlmPolicyMigrationStatus;
}
export interface ReportDocumentHead {
_id: string;
_index: string;
_seq_no: number;
_primary_term: number;
}
export interface ReportFields {
queue_time_ms?: number[]; // runtime field: started_at - created_at
@ -65,7 +130,7 @@ export interface ReportSource {
migration_version: string; // for reminding the user to update their POST URL
attempts: number; // initially populated as 0
created_at: string; // timestamp in UTC
status: JobStatus;
status: JOB_STATUS;
/*
* `output` is only populated if the report job is completed or failed.
@ -93,20 +158,6 @@ export interface ReportDocument extends ReportDocumentHead {
_source: ReportSource;
}
/*
* JobStatus:
* - Begins as 'pending'
* - Changes to 'processing` when the job is claimed
* - Then 'completed' | 'failed' when execution is done
* If the job needs a retry, it reverts back to 'pending'.
*/
export type JobStatus =
| 'completed' // Report was successful
| 'completed_with_warnings' // The download available for troubleshooting - it **should** show a meaningful error
| 'pending' // Report job is waiting to be claimed
| 'processing' // Report job has been claimed and is executing
| 'failed'; // Report was not successful, and all retries are done. Nothing to download.
/*
* Info API response: to avoid unnecessary large payloads on a network, the
* report query results do not include `payload.headers` or `output.content`,
@ -132,19 +183,3 @@ export interface LicenseCheckResults {
showLinks: boolean;
message: string;
}
/* Notifier Toasts */
export interface JobSummary {
id: JobId;
status: JobStatus;
jobtype: ReportSource['jobtype'];
title: ReportSource['payload']['title'];
errorCode?: ReportOutput['error_code'];
maxSizeReached: TaskRunResult['max_size_reached'];
csvContainsFormulas: TaskRunResult['csv_contains_formulas'];
}
export interface JobSummarySet {
completed: JobSummary[];
failed: JobSummary[];
}

View file

@ -1,12 +1,13 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import type { SerializableRecord } from '@kbn/utility-types';
import type { JobId } from './base';
import type { JobId } from './types';
type DownloadLink = string;
export type DownloadReportFn = (jobId: JobId) => DownloadLink;

View file

@ -0,0 +1,4 @@
@kbn/reporting-export-types-csv
This package originally was part of the reporting plugin. It is now extracted into its own package that includes the csv export classes that are then used in the reporting plugin.

View file

@ -1,8 +1,9 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
jest.mock('@kbn/generate-csv', () => ({
@ -19,23 +20,27 @@ jest.mock('@kbn/generate-csv', () => ({
import nodeCrypto from '@elastic/node-crypto';
import { coreMock, elasticsearchServiceMock, loggingSystemMock } from '@kbn/core/server/mocks';
import { Writable } from 'stream';
import { ReportingCore } from '../..';
import { CancellationToken } from '@kbn/reporting-common';
import { createMockConfigSchema, createMockReportingCore } from '../../test_helpers';
import { CsvSearchSourceExportType } from './csv_searchsource';
import { discoverPluginMock } from '@kbn/discover-plugin/server/mocks';
import { createFieldFormatsStartMock } from '@kbn/field-formats-plugin/server/mocks';
import { dataPluginMock } from '@kbn/data-plugin/server/mocks';
import { createMockScreenshottingStart } from '@kbn/screenshotting-plugin/server/mock';
import { setFieldFormats } from '@kbn/reporting-server';
import { createMockConfigSchema } from '@kbn/reporting-mocks-server';
import { CsvSearchSourceExportType } from '.';
const mockLogger = loggingSystemMock.createLogger();
const encryptionKey = 'tetkey';
const headers = { sid: 'cooltestheaders' };
let encryptedHeaders: string;
let mockReportingCore: ReportingCore;
let stream: jest.Mocked<Writable>;
let mockCsvSearchSourceExportType: CsvSearchSourceExportType;
beforeAll(async () => {
// use fieldFormats plugin for csv formats
// normally, this is done in the Reporting plugin
setFieldFormats(createFieldFormatsStartMock());
const crypto = nodeCrypto({ encryptionKey });
encryptedHeaders = await crypto.encrypt(headers);
@ -52,8 +57,6 @@ beforeAll(async () => {
const mockCoreStart = coreMock.createStart();
const context = coreMock.createPluginInitializerContext(configType);
mockReportingCore = await createMockReportingCore(configType);
mockCsvSearchSourceExportType = new CsvSearchSourceExportType(
mockCoreSetup,
configType,
@ -71,8 +74,6 @@ beforeAll(async () => {
uiSettings: mockCoreStart.uiSettings,
discover: discoverPluginMock.createStartContract(),
data: dataPluginMock.createStartContract(),
screenshotting: createMockScreenshottingStart(),
reporting: mockReportingCore.getContract(),
});
});
@ -96,9 +97,9 @@ test('gets the csv content from job parameters', async () => {
);
expect(payload).toMatchInlineSnapshot(`
Object {
"content_type": "text/csv",
"size": 123,
}
`);
Object {
"content_type": "text/csv",
"size": 123,
}
`);
});

View file

@ -1,33 +1,43 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import { DataPluginStart } from '@kbn/data-plugin/server/plugin';
import { DiscoverServerPluginStart } from '@kbn/discover-plugin/server';
import { CsvGenerator } from '@kbn/generate-csv';
import { CancellationToken } from '@kbn/reporting-common';
import { Writable } from 'stream';
import type { DataPluginStart } from '@kbn/data-plugin/server/plugin';
import type { DiscoverServerPluginStart } from '@kbn/discover-plugin/server';
import { CsvGenerator } from '@kbn/generate-csv';
import {
CSV_JOB_TYPE,
CancellationToken,
LICENSE_TYPE_BASIC,
LICENSE_TYPE_CLOUD_STANDARD,
LICENSE_TYPE_ENTERPRISE,
LICENSE_TYPE_GOLD,
LICENSE_TYPE_PLATINUM,
LICENSE_TYPE_TRIAL,
} from '../../../common/constants';
import { getFieldFormats } from '../../services';
import { ExportType, BaseExportTypeSetupDeps, BaseExportTypeStartDeps } from '../common';
import { decryptJobHeaders } from '../common/decrypt_job_headers';
import { JobParamsCSV, TaskPayloadCSV } from './types';
} from '@kbn/reporting-common';
import {
CSV_JOB_TYPE,
CSV_REPORT_TYPE,
JobParamsCSV,
TaskPayloadCSV,
} from '@kbn/reporting-export-types-csv-common';
import {
BaseExportTypeSetupDeps,
BaseExportTypeStartDeps,
ExportType,
decryptJobHeaders,
getFieldFormats,
} from '@kbn/reporting-server';
type CsvSearchSourceExportTypeSetupDeps = BaseExportTypeSetupDeps;
interface CsvSearchSourceExportTypeStartDeps extends BaseExportTypeStartDeps {
discover: DiscoverServerPluginStart;
data: DataPluginStart;
discover: DiscoverServerPluginStart;
}
export class CsvSearchSourceExportType extends ExportType<
@ -36,7 +46,7 @@ export class CsvSearchSourceExportType extends ExportType<
CsvSearchSourceExportTypeSetupDeps,
CsvSearchSourceExportTypeStartDeps
> {
id = 'csv_searchsource';
id = CSV_REPORT_TYPE;
name = CSV_JOB_TYPE;
jobType = CSV_JOB_TYPE;
jobContentEncoding = 'base64' as const;

View file

@ -1,33 +1,35 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import { Writable } from 'stream';
import { KibanaRequest } from '@kbn/core-http-server';
import { DataPluginStart } from '@kbn/data-plugin/server/plugin';
import { DiscoverServerPluginStart } from '@kbn/discover-plugin/server';
import { CsvGenerator } from '@kbn/generate-csv';
import { CancellationToken, TaskRunResult } from '@kbn/reporting-common';
import { Writable } from 'stream';
import {
ExportType,
BaseExportTypeSetupDeps,
BaseExportTypeStartDeps,
} from '../common/export_type';
import {
CSV_SEARCHSOURCE_IMMEDIATE_TYPE,
CancellationToken,
LICENSE_TYPE_BASIC,
LICENSE_TYPE_CLOUD_STANDARD,
LICENSE_TYPE_ENTERPRISE,
LICENSE_TYPE_GOLD,
LICENSE_TYPE_PLATINUM,
LICENSE_TYPE_TRIAL,
} from '../../../common/constants';
import { getFieldFormats } from '../../services';
import { ReportingRequestHandlerContext } from '../../types';
import { JobParamsDownloadCSV } from './types';
} from '@kbn/reporting-common';
import type { TaskRunResult } from '@kbn/reporting-common/types';
import {
CSV_SEARCHSOURCE_IMMEDIATE_TYPE,
JobParamsDownloadCSV,
} from '@kbn/reporting-export-types-csv-common';
import type { BaseExportTypeSetupDeps, BaseExportTypeStartDeps } from '@kbn/reporting-server';
import { ExportType, getFieldFormats } from '@kbn/reporting-server';
import { ReportingRequestHandlerContext } from './types';
type CsvSearchSourceImmediateExportTypeSetupDeps = BaseExportTypeSetupDeps;
interface CsvSearchSourceImmediateExportTypeStartDeps extends BaseExportTypeStartDeps {

View file

@ -1,33 +1,44 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import Boom from '@hapi/boom';
import { KibanaRequest } from '@kbn/core/server';
import { DiscoverServerPluginStart } from '@kbn/discover-plugin/server';
import { DataPluginStart } from '@kbn/data-plugin/server/plugin';
import { CsvGenerator } from '@kbn/generate-csv';
import { Writable } from 'stream';
import { CancellationToken } from '@kbn/reporting-common';
import { JobParamsCsvFromSavedObject, TaskPayloadCsvFromSavedObject } from '../../../common/types';
import type { KibanaRequest } from '@kbn/core/server';
import type { DataPluginStart } from '@kbn/data-plugin/server/plugin';
import type { DiscoverServerPluginStart } from '@kbn/discover-plugin/server';
import { CsvGenerator } from '@kbn/generate-csv';
import {
CSV_REPORT_TYPE_V2,
CancellationToken,
LICENSE_TYPE_BASIC,
LICENSE_TYPE_CLOUD_STANDARD,
LICENSE_TYPE_ENTERPRISE,
LICENSE_TYPE_GOLD,
LICENSE_TYPE_PLATINUM,
LICENSE_TYPE_TRIAL,
} from '../../../common/constants';
import { ExportType, BaseExportTypeSetupDeps, BaseExportTypeStartDeps } from '../common';
import { ReportingRequestHandlerContext } from '../../types';
import { getFieldFormats } from '../../services';
import { decryptJobHeaders } from '../common/decrypt_job_headers';
} from '@kbn/reporting-common';
import {
CSV_REPORT_TYPE_V2,
JobParamsCsvFromSavedObject,
TaskPayloadCsvFromSavedObject,
} from '@kbn/reporting-export-types-csv-common';
import {
ExportType,
decryptJobHeaders,
getFieldFormats,
type BaseExportTypeSetupDeps,
type BaseExportTypeStartDeps,
} from '@kbn/reporting-server';
import { ReportingRequestHandlerContext } from './types';
type CsvV2ExportTypeSetupDeps = BaseExportTypeSetupDeps;
export interface CsvV2ExportTypeStartDeps extends BaseExportTypeStartDeps {
discover: DiscoverServerPluginStart;
data: DataPluginStart;
@ -55,8 +66,7 @@ export class CsvV2ExportType extends ExportType<
constructor(...args: ConstructorParameters<typeof ExportType>) {
super(...args);
const logger = args[2];
this.logger = logger.get('csv-export-v2');
this.logger = this.logger.get('csv-export-v2');
}
public createJob = async (

View file

@ -0,0 +1,11 @@
/*
* 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.
*/
export { CsvSearchSourceExportType } from './csv_searchsource';
export { CsvV2ExportType } from './csv_v2';
export { CsvSearchSourceImmediateExportType } from './csv_searchsource_immediate';

View file

@ -0,0 +1,13 @@
/*
* 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.
*/
module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../../../..',
roots: ['<rootDir>/packages/kbn-reporting/export_types/csv'],
};

View file

@ -0,0 +1,5 @@
{
"type": "shared-server",
"id": "@kbn/reporting-export-types-csv",
"owner": "@elastic/appex-sharedux"
}

View file

@ -0,0 +1,6 @@
{
"name": "@kbn/reporting-export-types-csv",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0"
}

View file

@ -0,0 +1,31 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node",
"react"
]
},
"include": [
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/core",
"@kbn/reporting-common",
"@kbn/discover-plugin",
"@kbn/data-plugin",
"@kbn/generate-csv",
"@kbn/core-http-server",
"@kbn/reporting-server",
"@kbn/reporting-export-types-csv-common",
"@kbn/reporting-mocks-server",
"@kbn/core-http-request-handler-context-server",
"@kbn/field-formats-plugin",
]
}

View file

@ -0,0 +1,18 @@
/*
* 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.
*/
import type { CustomRequestHandlerContext } from '@kbn/core-http-request-handler-context-server';
import { ReportingServerPluginSetup } from '@kbn/reporting-server';
/**
* Needed because of CsvSearchSourceImmediateExportType
* @internal
*/
export type ReportingRequestHandlerContext = CustomRequestHandlerContext<{
reporting: ReportingServerPluginSetup | null;
}>;

View file

@ -0,0 +1,3 @@
# @kbn/reporting-export-types-csv-common
Empty package generated by @kbn/generate

View file

@ -0,0 +1,13 @@
/*
* 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.
*/
export const CSV_JOB_TYPE = 'csv_searchsource';
export const CSV_REPORT_TYPE = 'csv_searchsource';
export const CSV_JOB_TYPE_V2 = 'csv_v2';
export const CSV_REPORT_TYPE_V2 = 'csv_v2';

View file

@ -0,0 +1,53 @@
/*
* 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.
*/
import type { SerializedSearchSourceFields } from '@kbn/data-plugin/public';
import type {
BaseParams,
BaseParamsV2,
BasePayload,
BasePayloadV2,
} from '@kbn/reporting-common/types';
export * from './constants';
export interface JobParamsDownloadCSV {
browserTimezone: string;
title: string;
searchSource: SerializedSearchSourceFields;
columns?: string[];
}
interface BaseParamsCSV {
searchSource: SerializedSearchSourceFields;
columns?: string[];
}
export type JobParamsCSV = BaseParamsCSV & BaseParams;
export type TaskPayloadCSV = BaseParamsCSV & BasePayload;
interface CsvFromSavedObjectBase {
objectType: 'search';
}
/**
* Makes title optional, as it can be derived from the saved search object
*/
export type JobParamsCsvFromSavedObject = CsvFromSavedObjectBase &
Omit<BaseParamsV2, 'title'> & { title?: string };
export type TaskPayloadCsvFromSavedObject = CsvFromSavedObjectBase & BasePayloadV2;
export const CSV_REPORTING_ACTION = 'downloadCsvReport';
export const CSV_SEARCHSOURCE_IMMEDIATE_TYPE = 'csv_searchsource_immediate';
// This is deprecated because it lacks support for runtime fields
// but the extension points are still needed for pre-existing scripted automation, until 8.0
export const CSV_REPORT_TYPE_DEPRECATED = 'CSV';
export const CSV_JOB_TYPE_DEPRECATED = 'csv';

View file

@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/reporting-export-types-csv-common",
"owner": "@elastic/appex-sharedux"
}

View file

@ -0,0 +1,6 @@
{
"name": "@kbn/reporting-export-types-csv-common",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0"
}

View file

@ -1,5 +1,5 @@
{
"extends": "../../tsconfig.base.json",
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
@ -14,7 +14,7 @@
"target/**/*"
],
"kbn_references": [
"@kbn/config-schema",
"@kbn/data-plugin",
"@kbn/reporting-common",
]
}

View file

@ -1,29 +1,29 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import * as Rx from 'rxjs';
import { Observable } from 'rxjs';
import { mergeMap, tap } from 'rxjs/operators';
import { PdfScreenshotResult } from '@kbn/screenshotting-plugin/server';
import { PdfScreenshotOptions } from '../../../types';
import type { PdfMetrics } from '../../../../common/types';
import { getTracker } from '../../common/pdf_tracker';
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[];
}
type GetScreenshotsFn = (options: PdfScreenshotOptions) => Rx.Observable<PdfScreenshotResult>;
type GetScreenshotsFn = (options: PdfScreenshotOptions) => Observable<PdfScreenshotResult>;
export function generatePdfObservable(
getScreenshots: GetScreenshotsFn,
options: PdfScreenshotOptions
): Rx.Observable<PdfResult> {
): Observable<PdfResult> {
const tracker = getTracker();
tracker.startScreenshots();

View file

@ -1,37 +1,38 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import * as Rx from 'rxjs';
import { Observable } from 'rxjs';
import { mergeMap, tap } from 'rxjs/operators';
import { PdfScreenshotResult } from '@kbn/screenshotting-plugin/server';
import { TaskPayloadPDFV2 } from '../../../../common/types/export_types/printable_pdf_v2';
import { ReportingServerInfo } from '../../../core';
import { ReportingConfigType } from '../../../config';
import type { LocatorParams, PdfMetrics, UrlOrUrlLocatorTuple } from '../../../../common/types';
import type { PdfScreenshotOptions } from '../../../types';
import { getFullRedirectAppUrl } from '../../common/v2/get_full_redirect_app_url';
import { getTracker } from '../../common/pdf_tracker';
import type { LocatorParams, ReportingServerInfo } from '@kbn/reporting-common/types';
import type { TaskPayloadPDFV2 } from '@kbn/reporting-export-types-pdf-common';
import type { PdfScreenshotOptions, PdfScreenshotResult } from '@kbn/screenshotting-plugin/server';
import type { UrlOrUrlWithContext } from '@kbn/screenshotting-plugin/server/screenshots';
import { type ReportingConfigType, getFullRedirectAppUrl } from '@kbn/reporting-server';
import { getTracker } from './pdf_tracker';
interface PdfResult {
buffer: Uint8Array | null;
metrics?: PdfMetrics;
metrics?: PdfScreenshotResult['metrics'];
warnings: string[];
}
type GetScreenshotsFn = (options: PdfScreenshotOptions) => Rx.Observable<PdfScreenshotResult>;
type GetScreenshotsFn = (options: PdfScreenshotOptions) => Observable<PdfScreenshotResult>;
export function generatePdfObservable(
export function generatePdfObservableV2(
config: ReportingConfigType,
serverInfo: ReportingServerInfo,
getScreenshots: GetScreenshotsFn,
job: TaskPayloadPDFV2,
locatorParams: LocatorParams[],
options: Omit<PdfScreenshotOptions, 'urls'>
): Rx.Observable<PdfResult> {
): Observable<PdfResult> {
const tracker = getTracker();
tracker.startScreenshots();
@ -41,7 +42,8 @@ export function generatePdfObservable(
const urls = locatorParams.map((locator) => [
getFullRedirectAppUrl(config, serverInfo, job.spaceId, job.forceNow),
locator,
]) as UrlOrUrlLocatorTuple[];
]) as unknown as UrlOrUrlWithContext[];
const screenshots$ = getScreenshots({ ...options, urls }).pipe(
tap(({ metrics }) => {
if (metrics.cpu) {

View file

@ -1,8 +1,9 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import { getAbsoluteUrlFactory } from './get_absolute_url';

View file

@ -1,8 +1,9 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import url from 'url';

View file

@ -1,8 +1,9 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import { coreMock, httpServerMock } from '@kbn/core/server/mocks';

View file

@ -1,8 +1,9 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import type { Headers, IUiSettingsClient } from '@kbn/core/server';

View file

@ -1,17 +1,19 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import { ReportingServerInfo } from '../../core';
import { TaskPayloadPDF } from '../printable_pdf/types';
import type { ReportingServerInfo } from '@kbn/reporting-common/types';
import type { TaskPayloadPDF } from '@kbn/reporting-export-types-pdf-common';
import { createMockConfigSchema } from '@kbn/reporting-mocks-server';
import { getFullUrls } from './get_full_urls';
import { ReportingConfigType } from '../../config';
const getMockJob = (base: object) => base as TaskPayloadPDF;
const mockConfig = { kibanaServer: {} } as unknown as ReportingConfigType;
const mockConfig = createMockConfigSchema();
const mockServerInfo: ReportingServerInfo = {
hostname: 'localhost',
protocol: 'http',

View file

@ -1,8 +1,9 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import {
@ -11,9 +12,11 @@ import {
UrlWithParsedQuery,
UrlWithStringQuery,
} from 'url';
import { ReportingConfigType } from '../../config';
import { ReportingServerInfo } from '../../core';
import { TaskPayloadPDF } from '../printable_pdf/types';
import type { ReportingServerInfo } from '@kbn/reporting-common/types';
import type { TaskPayloadPDF } from '@kbn/reporting-export-types-pdf-common';
import type { ReportingConfigType } from '@kbn/reporting-server';
import { getAbsoluteUrlFactory } from './get_absolute_url';
import { validateUrls } from './validate_urls';
@ -44,7 +47,7 @@ export function getFullUrls(
validateUrls(relativeUrls);
const urls = relativeUrls.map((relativeUrl) => {
const parsedRelative: UrlWithStringQuery = urlParse(relativeUrl); // FIXME: '(urlStr: string): UrlWithStringQuery' is deprecated
const parsedRelative: UrlWithStringQuery = urlParse(relativeUrl);
const jobUrl = getAbsoluteUrl({
path: parsedRelative.pathname === null ? undefined : parsedRelative.pathname,
hash: parsedRelative.hash === null ? undefined : parsedRelative.hash,

View file

@ -0,0 +1,10 @@
/*
* 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.
*/
export { PdfExportType } from './printable_pdf_v2';
export { PdfV1ExportType } from './printable_pdf';

View file

@ -0,0 +1,13 @@
/*
* 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.
*/
module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../../../..',
roots: ['<rootDir>/packages/kbn-reporting/export_types/pdf'],
};

View file

@ -0,0 +1,5 @@
{
"type": "shared-server",
"id": "@kbn/reporting-export-types-pdf",
"owner": "@elastic/appex-sharedux"
}

View file

@ -0,0 +1,6 @@
{
"name": "@kbn/reporting-export-types-pdf",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0"
}

View file

@ -1,8 +1,9 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import apm from 'elastic-apm-node';

View file

@ -1,31 +1,31 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import * as Rx from 'rxjs';
import { coreMock, elasticsearchServiceMock, loggingSystemMock } from '@kbn/core/server/mocks';
import { of } from 'rxjs';
import { Writable } from 'stream';
import { CancellationToken } from '@kbn/reporting-common';
import { generatePdfObservable } from './lib/generate_pdf';
import { cryptoFactory } from '../../lib/crypto';
import { TaskPayloadPDF } from './types';
import { PdfV1ExportType } from './printable_pdf';
import { ScreenshottingStart } from '@kbn/screenshotting-plugin/server';
import { createMockConfigSchema, createMockReportingCore } from '../../test_helpers';
jest.mock('./lib/generate_pdf');
import { coreMock, elasticsearchServiceMock, loggingSystemMock } from '@kbn/core/server/mocks';
import { CancellationToken } from '@kbn/reporting-common';
import { TaskPayloadPDF } from '@kbn/reporting-export-types-pdf-common';
import { createMockConfigSchema } from '@kbn/reporting-mocks-server';
import { cryptoFactory } from '@kbn/reporting-server';
import { ScreenshottingStart } from '@kbn/screenshotting-plugin/server';
import { PdfV1ExportType } from '.';
import { generatePdfObservable } from './generate_pdf';
jest.mock('./generate_pdf');
let content: string;
let mockPdfExportType: PdfV1ExportType;
let stream: jest.Mocked<Writable>;
const cancellationToken = {
on: jest.fn(),
} as unknown as CancellationToken;
const cancellationToken = new CancellationToken();
const mockLogger = loggingSystemMock.createLogger();
const mockEncryptionKey = 'testencryptionkey';
@ -44,7 +44,6 @@ beforeEach(async () => {
const mockCoreSetup = coreMock.createSetup();
const mockCoreStart = coreMock.createStart();
const mockReportingCore = await createMockReportingCore(createMockConfigSchema());
mockPdfExportType = new PdfV1ExportType(mockCoreSetup, configType, mockLogger, context);
@ -56,7 +55,6 @@ beforeEach(async () => {
savedObjects: mockCoreStart.savedObjects,
uiSettings: mockCoreStart.uiSettings,
screenshotting: {} as unknown as ScreenshottingStart,
reporting: mockReportingCore.getContract(),
});
});
@ -64,7 +62,7 @@ afterEach(() => (generatePdfObservable as jest.Mock).mockReset());
test(`passes browserTimezone to generatePdf`, async () => {
const encryptedHeaders = await encryptHeaders({});
(generatePdfObservable as jest.Mock).mockReturnValue(Rx.of({ buffer: Buffer.from('') }));
(generatePdfObservable as jest.Mock).mockReturnValue(of({ buffer: Buffer.from('') }));
const browserTimezone = 'UTC';
await mockPdfExportType.runTask(
@ -87,7 +85,7 @@ test(`passes browserTimezone to generatePdf`, async () => {
test(`returns content_type of application/pdf`, async () => {
const encryptedHeaders = await encryptHeaders({});
(generatePdfObservable as jest.Mock).mockReturnValue(Rx.of({ buffer: Buffer.from('') }));
(generatePdfObservable as jest.Mock).mockReturnValue(of({ buffer: Buffer.from('') }));
const { content_type: contentType } = await mockPdfExportType.runTask(
'pdfJobId',
@ -100,7 +98,7 @@ test(`returns content_type of application/pdf`, async () => {
test(`returns content of generatePdf getBuffer base64 encoded`, async () => {
const testContent = 'test content';
(generatePdfObservable as jest.Mock).mockReturnValue(Rx.of({ buffer: Buffer.from(testContent) }));
(generatePdfObservable as jest.Mock).mockReturnValue(of({ buffer: Buffer.from(testContent) }));
const encryptedHeaders = await encryptHeaders({});
await mockPdfExportType.runTask(

View file

@ -1,30 +1,42 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import { LicenseType } from '@kbn/licensing-plugin/server';
import { CancellationToken, TaskRunResult } from '@kbn/reporting-common';
import { Writable } from 'stream';
import apm from 'elastic-apm-node';
import { Observable, fromEventPattern, lastValueFrom, of, throwError } from 'rxjs';
import { catchError, map, mergeMap, takeUntil, tap } from 'rxjs/operators';
import { fromEventPattern, lastValueFrom, Observable, of, throwError } from 'rxjs';
import { JobParamsPDFDeprecated } from '../../../common/types';
import { Writable } from 'stream';
import type { LicenseType } from '@kbn/licensing-plugin/server';
import {
CancellationToken,
LICENSE_TYPE_CLOUD_STANDARD,
LICENSE_TYPE_ENTERPRISE,
LICENSE_TYPE_GOLD,
LICENSE_TYPE_PLATINUM,
LICENSE_TYPE_TRIAL,
PDF_JOB_TYPE,
REPORTING_TRANSACTION_TYPE,
} from '../../../common/constants';
import { decryptJobHeaders, ExportType, getCustomLogo, getFullUrls, validateUrls } from '../common';
import { TaskPayloadPDF } from './types';
import { generatePdfObservable } from './lib/generate_pdf';
} from '@kbn/reporting-common';
import { TaskRunResult } from '@kbn/reporting-common/types';
import {
JobParamsPDFDeprecated,
PDF_JOB_TYPE,
TaskPayloadPDF,
} from '@kbn/reporting-export-types-pdf-common';
import { ExportType, decryptJobHeaders } from '@kbn/reporting-server';
import { generatePdfObservable } from './generate_pdf';
import { validateUrls } from './validate_urls';
import { getCustomLogo } from './get_custom_logo';
import { getFullUrls } from './get_full_urls';
/**
* @deprecated
*/
export class PdfV1ExportType extends ExportType<JobParamsPDFDeprecated, TaskPayloadPDF> {
id = 'printablePdf';
name = 'PDF';
@ -83,9 +95,19 @@ export class PdfV1ExportType extends ExportType<JobParamsPDFDeprecated, TaskPayl
apmGetAssets?.end();
apmGeneratePdf = apmTrans.startSpan('generate-pdf-pipeline', 'execute');
// make a new function that will call reporting.getScreenshots
const snapshotFn = () =>
this.startDeps.reporting.getScreenshots!({
return generatePdfObservable(
() =>
this.startDeps.screenshotting!.getScreenshots({
format: 'pdf',
title,
logo,
urls,
browserTimezone,
headers,
layout,
}),
{
format: 'pdf',
title,
logo,
@ -93,16 +115,8 @@ export class PdfV1ExportType extends ExportType<JobParamsPDFDeprecated, TaskPayl
browserTimezone,
headers,
layout,
});
return generatePdfObservable(snapshotFn, {
format: 'pdf',
title,
logo,
urls,
browserTimezone,
headers,
layout,
});
}
);
}),
tap(({ buffer }) => {
apmGeneratePdf?.end();

View file

@ -1,32 +1,32 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
jest.mock('./lib/generate_pdf');
import { of } from 'rxjs';
import type { Writable } from 'stream';
import { coreMock, elasticsearchServiceMock, loggingSystemMock } from '@kbn/core/server/mocks';
import { CancellationToken } from '@kbn/reporting-common';
import type { LocatorParams } from '@kbn/reporting-common/types';
import type { TaskPayloadPDFV2 } from '@kbn/reporting-export-types-pdf-common';
import { createMockConfigSchema } from '@kbn/reporting-mocks-server';
import { cryptoFactory } from '@kbn/reporting-server';
import type { ScreenshottingStart } from '@kbn/screenshotting-plugin/server';
import * as Rx from 'rxjs';
import type { Writable } from 'stream';
import { PdfExportType } from '.';
import type { LocatorParams } from '../../../common';
import type { TaskPayloadPDFV2 } from '../../../common/types/export_types/printable_pdf_v2';
import { cryptoFactory } from '../../lib';
import { generatePdfObservable } from './lib/generate_pdf';
import { createMockConfigSchema, createMockReportingCore } from '../../test_helpers';
import { generatePdfObservableV2 } from './generate_pdf_v2';
jest.mock('./generate_pdf_v2');
let content: string;
let mockPdfExportType: PdfExportType;
let stream: jest.Mocked<Writable>;
const cancellationToken = {
on: jest.fn(),
} as unknown as CancellationToken;
const cancellationToken = new CancellationToken();
const mockLogger = loggingSystemMock.createLogger();
const mockEncryptionKey = 'testencryptionkey';
@ -50,8 +50,6 @@ beforeEach(async () => {
const mockCoreSetup = coreMock.createSetup();
const mockCoreStart = coreMock.createStart();
const mockReportingCore = await createMockReportingCore(createMockConfigSchema());
mockPdfExportType = new PdfExportType(mockCoreSetup, configType, mockLogger, context);
mockPdfExportType.setup({
@ -62,15 +60,14 @@ beforeEach(async () => {
savedObjects: mockCoreStart.savedObjects,
uiSettings: mockCoreStart.uiSettings,
screenshotting: {} as unknown as ScreenshottingStart,
reporting: mockReportingCore.getContract(),
});
});
afterEach(() => (generatePdfObservable as jest.Mock).mockReset());
afterEach(() => (generatePdfObservableV2 as jest.Mock).mockReset());
test(`passes browserTimezone to generatePdf`, async () => {
const encryptedHeaders = await encryptHeaders({});
(generatePdfObservable as jest.Mock).mockReturnValue(Rx.of(Buffer.from('')));
(generatePdfObservableV2 as jest.Mock).mockReturnValue(of(Buffer.from('')));
const browserTimezone = 'UTC';
await mockPdfExportType.runTask(
@ -86,7 +83,7 @@ test(`passes browserTimezone to generatePdf`, async () => {
stream
);
expect(generatePdfObservable).toHaveBeenCalledWith(
expect(generatePdfObservableV2).toHaveBeenCalledWith(
expect.anything(),
expect.anything(),
expect.anything(),
@ -99,7 +96,7 @@ test(`passes browserTimezone to generatePdf`, async () => {
test(`returns content_type of application/pdf`, async () => {
const encryptedHeaders = await encryptHeaders({});
(generatePdfObservable as jest.Mock).mockReturnValue(Rx.of({ buffer: Buffer.from('') }));
(generatePdfObservableV2 as jest.Mock).mockReturnValue(of({ buffer: Buffer.from('') }));
const { content_type: contentType } = await mockPdfExportType.runTask(
'pdfJobId',
@ -112,7 +109,7 @@ test(`returns content_type of application/pdf`, async () => {
test(`returns content of generatePdf getBuffer base64 encoded`, async () => {
const testContent = 'test content';
(generatePdfObservable as jest.Mock).mockReturnValue(Rx.of({ buffer: Buffer.from(testContent) }));
(generatePdfObservableV2 as jest.Mock).mockReturnValue(of({ buffer: Buffer.from(testContent) }));
const encryptedHeaders = await encryptHeaders({});
await mockPdfExportType.runTask(

View file

@ -1,31 +1,38 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import { Headers } from '@kbn/core/server';
import { CancellationToken, TaskRunResult } from '@kbn/reporting-common';
import apm from 'elastic-apm-node';
import * as Rx from 'rxjs';
import { catchError, map, mergeMap, takeUntil, tap } from 'rxjs';
import { catchError, map, mergeMap, of, takeUntil, tap } from 'rxjs';
import { Writable } from 'stream';
import { Headers } from '@kbn/core/server';
import {
CancellationToken,
LICENSE_TYPE_CLOUD_STANDARD,
LICENSE_TYPE_ENTERPRISE,
LICENSE_TYPE_GOLD,
LICENSE_TYPE_PLATINUM,
LICENSE_TYPE_TRIAL,
REPORTING_REDIRECT_LOCATOR_STORE_KEY,
REPORTING_TRANSACTION_TYPE,
} from '@kbn/reporting-common';
import type { TaskRunResult, UrlOrUrlLocatorTuple } from '@kbn/reporting-common/types';
import {
JobParamsPDFV2,
PDF_JOB_TYPE_V2,
PDF_REPORT_TYPE_V2,
REPORTING_TRANSACTION_TYPE,
} from '../../../common/constants';
import { JobParamsPDFV2, UrlOrUrlLocatorTuple } from '../../../common/types';
import { TaskPayloadPDFV2 } from '../../../common/types/export_types/printable_pdf_v2';
import { decryptJobHeaders, ExportType, getCustomLogo } from '../common';
import { getFullRedirectAppUrl } from '../common/v2/get_full_redirect_app_url';
import { generatePdfObservable } from './lib/generate_pdf';
TaskPayloadPDFV2,
} from '@kbn/reporting-export-types-pdf-common';
import { decryptJobHeaders, getFullRedirectAppUrl, ExportType } from '@kbn/reporting-server';
import { generatePdfObservableV2 } from './generate_pdf_v2';
import { getCustomLogo } from './get_custom_logo';
export class PdfExportType extends ExportType<JobParamsPDFV2, TaskPayloadPDFV2> {
id = PDF_REPORT_TYPE_V2;
@ -79,7 +86,7 @@ export class PdfExportType extends ExportType<JobParamsPDFV2, TaskPayloadPDFV2>
let apmGeneratePdf: { end: () => void } | null | undefined;
const { encryptionKey } = this.config;
const process$: Rx.Observable<TaskRunResult> = Rx.of(1).pipe(
const process$: Rx.Observable<TaskRunResult> = of(1).pipe(
mergeMap(() => decryptJobHeaders(encryptionKey, payload.headers, jobLogger)),
mergeMap(async (headers: Headers) => {
const fakeRequest = this.getFakeRequest(headers, payload.spaceId, jobLogger);
@ -98,24 +105,29 @@ export class PdfExportType extends ExportType<JobParamsPDFV2, TaskPayloadPDFV2>
payload.forceNow
),
locator,
]) as unknown as UrlOrUrlLocatorTuple[];
]);
}
apmGetAssets?.end();
apmGeneratePdf = apmTrans.startSpan('generate-pdf-pipeline', 'execute');
return generatePdfObservable(
return generatePdfObservableV2(
this.config,
this.getServerInfo(),
() =>
this.startDeps.reporting.getScreenshots!({
this.startDeps.screenshotting!.getScreenshots({
format: 'pdf',
title,
logo,
browserTimezone,
headers,
layout,
urls,
urls: urls.map((url) =>
typeof url === 'string'
? url
: [url[0], { [REPORTING_REDIRECT_LOCATOR_STORE_KEY]: url[1] }]
),
}),
payload,
locatorParams,

View file

@ -0,0 +1,26 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node",
]
},
"include": [
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/core",
"@kbn/reporting-common",
"@kbn/screenshotting-plugin",
"@kbn/reporting-server",
"@kbn/licensing-plugin",
"@kbn/reporting-export-types-pdf-common",
"@kbn/reporting-mocks-server",
]
}

View file

@ -1,8 +1,9 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import { validateUrls } from './validate_urls';

View file

@ -1,8 +1,9 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import { parse } from 'url';

View file

@ -0,0 +1,3 @@
# @kbn/reporting-export-types-pdf-common
Empty package generated by @kbn/generate

View file

@ -0,0 +1,13 @@
/*
* 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.
*/
export const PDF_JOB_TYPE = 'printable_pdf';
export const PDF_JOB_TYPE_V2 = 'printable_pdf_v2';
export const PDF_REPORT_TYPE = 'printablePdf';
export const PDF_REPORT_TYPE_V2 = 'printablePdfV2';

View file

@ -0,0 +1,64 @@
/*
* 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.
*/
import type { BaseParams, BasePayload, LocatorParams } from '@kbn/reporting-common/types';
import { LayoutParams } from '@kbn/screenshotting-plugin/common';
export * from './constants';
/**
* Structure of stored job data provided by create_job
*/
export interface TaskPayloadPDF extends BasePayload {
layout: LayoutParams;
forceNow?: string;
objects: Array<{ relativeUrl: string }>;
}
interface BaseParamsPDFV2 {
layout: LayoutParams;
/**
* 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.
*/
locatorParams: LocatorParams[];
}
// Job params: structure of incoming user request data, after being parsed from RISON
export type JobParamsPDFV2 = BaseParamsPDFV2 & BaseParams;
/**
* Public-facing interface
* Apps should use this interface to build job params.
* browserTimezone and version is provided by Reporting
* @public
*/
export type JobAppParamsPDFV2 = Omit<JobParamsPDFV2, 'browserTimezone' | 'version'>;
// Job payload: structure of stored job data provided by create_job
export interface TaskPayloadPDFV2 extends BasePayload, BaseParamsPDFV2 {
layout: LayoutParams;
/**
* The value of forceNow is injected server-side every time a given report is generated.
*/
forceNow: string;
}
/**
* @deprecated
*/
interface BaseParamsPDF {
layout: LayoutParams;
relativeUrls: string[];
isDeprecated?: boolean;
}
/**
* @deprecated
*/
export type JobParamsPDFDeprecated = BaseParamsPDF & BaseParams;

View file

@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/reporting-export-types-pdf-common",
"owner": "@elastic/appex-sharedux"
}

View file

@ -0,0 +1,6 @@
{
"name": "@kbn/reporting-export-types-pdf-common",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0"
}

View file

@ -0,0 +1,20 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/screenshotting-plugin",
"@kbn/reporting-common",
]
}

View file

@ -1,32 +1,32 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import apm from 'elastic-apm-node';
import type { Logger } from '@kbn/core/server';
import * as Rx from 'rxjs';
import { Observable } from 'rxjs';
import { finalize, map, tap } from 'rxjs/operators';
import { PngScreenshotResult } from '@kbn/screenshotting-plugin/server';
import { REPORTING_TRANSACTION_TYPE } from '../../../common/constants';
import type { PngMetrics } from '../../../common/types';
import type { PngScreenshotOptions } from '../../types';
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[];
}
type GetScreenshotsFn = (options: PngScreenshotOptions) => Rx.Observable<PngScreenshotResult>;
type GetScreenshotsFn = (options: PngScreenshotOptions) => Observable<PngScreenshotResult>;
export function generatePngObservable(
getScreenshots: GetScreenshotsFn,
logger: Logger,
options: Omit<PngScreenshotOptions, 'format'>
): Rx.Observable<PngResult> {
): Observable<PngResult> {
const apmTrans = apm.startTransaction('generate-png', REPORTING_TRANSACTION_TYPE);
if (!options.layout?.dimensions) {
throw new Error(`LayoutParams.Dimensions is undefined.`);

View file

@ -1,8 +1,9 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
export { PngExportType } from './png_v2';

View file

@ -0,0 +1,13 @@
/*
* 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.
*/
module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../../../..',
roots: ['<rootDir>/packages/kbn-reporting/export_types/png'],
};

View file

@ -0,0 +1,5 @@
{
"type": "shared-server",
"id": "@kbn/reporting-export-types-png",
"owner": "@elastic/appex-sharedux"
}

View file

@ -0,0 +1,6 @@
{
"name": "@kbn/reporting-export-types-png",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0"
}

View file

@ -1,34 +1,32 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import * as Rx from 'rxjs';
import { coreMock, elasticsearchServiceMock, loggingSystemMock } from '@kbn/core/server/mocks';
import { Writable } from 'stream';
import { CancellationToken } from '@kbn/reporting-common';
import { ScreenshottingStart } from '@kbn/screenshotting-plugin/server';
import { ReportingCore } from '../..';
import { LocatorParams } from '../../../common/types';
import { cryptoFactory } from '../../lib';
import { createMockConfigSchema, createMockReportingCore } from '../../test_helpers';
import { generatePngObservable } from '../common';
import { TaskPayloadPNGV2 } from './types';
import { PngExportType } from './png_v2';
jest.mock('../common/generate_png');
import { coreMock, elasticsearchServiceMock, loggingSystemMock } from '@kbn/core/server/mocks';
import { CancellationToken } from '@kbn/reporting-common';
import type { LocatorParams } from '@kbn/reporting-common/types';
import type { TaskPayloadPNGV2 } from '@kbn/reporting-export-types-png-common';
import { createMockConfigSchema } from '@kbn/reporting-mocks-server';
import { cryptoFactory } from '@kbn/reporting-server';
import type { ScreenshottingStart } from '@kbn/screenshotting-plugin/server';
import { PngExportType } from '.';
import { generatePngObservable } from './generate_png';
jest.mock('./generate_png');
let content: string;
let mockReportingCore: ReportingCore;
let mockPngExportType: PngExportType;
let stream: jest.Mocked<Writable>;
const cancellationToken = {
on: jest.fn(),
} as unknown as CancellationToken;
const cancellationToken = new CancellationToken();
const mockLogger = loggingSystemMock.createLogger();
const mockEncryptionKey = 'abcabcsecuresecret';
@ -51,7 +49,6 @@ beforeEach(async () => {
},
});
mockReportingCore = await createMockReportingCore(configType);
const context = coreMock.createPluginInitializerContext(configType);
const mockCoreSetup = coreMock.createSetup();
@ -66,7 +63,6 @@ beforeEach(async () => {
uiSettings: mockCoreStart.uiSettings,
screenshotting: {} as unknown as ScreenshottingStart,
esClient: elasticsearchServiceMock.createClusterClient(),
reporting: mockReportingCore.getContract(),
});
});
@ -81,7 +77,7 @@ test(`passes browserTimezone to generatePng`, async () => {
'pngJobId',
getBasePayload({
forceNow: 'test',
locatorParams: [{ version: 'test', id: 'test', params: {} }] as LocatorParams[],
locatorParams: [],
browserTimezone,
headers: encryptedHeaders,
}),
@ -93,14 +89,9 @@ test(`passes browserTimezone to generatePng`, async () => {
expect.anything(),
expect.anything(),
expect.objectContaining({
urls: [
[
'http://localhost:80/mock-server-basepath/app/reportingRedirect?forceNow=test',
{ id: 'test', params: {}, version: 'test' },
],
],
browserTimezone: 'UTC',
headers: {},
layout: { id: 'preserve_layout' },
})
);
});

View file

@ -1,13 +1,12 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import apm from 'elastic-apm-node';
import { LicenseType } from '@kbn/licensing-plugin/server';
import { CancellationToken, TaskRunResult } from '@kbn/reporting-common';
import { Writable } from 'stream';
import {
finalize,
fromEventPattern,
@ -19,21 +18,29 @@ import {
takeUntil,
tap,
} from 'rxjs';
import { SerializableRecord } from '@kbn/utility-types';
import { LocatorParams } from '../../../common';
import { Writable } from 'stream';
import type { LicenseType } from '@kbn/licensing-plugin/server';
import {
CancellationToken,
LICENSE_TYPE_CLOUD_STANDARD,
LICENSE_TYPE_ENTERPRISE,
LICENSE_TYPE_GOLD,
LICENSE_TYPE_PLATINUM,
LICENSE_TYPE_TRIAL,
REPORTING_REDIRECT_LOCATOR_STORE_KEY,
REPORTING_TRANSACTION_TYPE,
} from '@kbn/reporting-common';
import type { TaskRunResult } from '@kbn/reporting-common/types';
import {
JobParamsPNGV2,
PNG_JOB_TYPE_V2,
PNG_REPORT_TYPE_V2,
REPORTING_TRANSACTION_TYPE,
} from '../../../common/constants';
import { decryptJobHeaders, ExportType, generatePngObservable } from '../common';
import { JobParamsPNGV2, TaskPayloadPNGV2 } from './types';
import { getFullRedirectAppUrl } from '../common/v2/get_full_redirect_app_url';
TaskPayloadPNGV2,
} from '@kbn/reporting-export-types-png-common';
import { decryptJobHeaders, getFullRedirectAppUrl, ExportType } from '@kbn/reporting-server';
import { generatePngObservable } from './generate_png';
export class PngExportType extends ExportType<JobParamsPNGV2, TaskPayloadPNGV2> {
id = PNG_REPORT_TYPE_V2;
@ -61,7 +68,7 @@ export class PngExportType extends ExportType<JobParamsPNGV2, TaskPayloadPNGV2>
public createJob = async ({ locatorParams, ...jobParams }: JobParamsPNGV2) => {
return {
...jobParams,
locatorParams: [locatorParams] as unknown as LocatorParams<SerializableRecord>,
locatorParams: [locatorParams],
isDeprecated: false,
browserTimezone: jobParams.browserTimezone,
forceNow: new Date().toISOString(),
@ -104,18 +111,17 @@ export class PngExportType extends ExportType<JobParamsPNGV2, TaskPayloadPNGV2>
return generatePngObservable(
() =>
this.startDeps.reporting.getScreenshots!({
this.startDeps.screenshotting!.getScreenshots({
format: 'png',
headers,
layout: { ...payload.layout, id: 'preserve_layout' },
urls: [[url, locatorParams]],
urls: [[url, { [REPORTING_REDIRECT_LOCATOR_STORE_KEY]: locatorParams }]],
}),
jobLogger,
{
headers,
browserTimezone: payload.browserTimezone,
layout: { ...payload.layout, id: 'preserve_layout' },
urls: [[url, locatorParams]],
}
);
}),

View file

@ -0,0 +1,28 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node",
"react"
]
},
"include": [
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/reporting-common",
"@kbn/licensing-plugin",
"@kbn/screenshotting-plugin",
"@kbn/reporting-server",
"@kbn/reporting-export-types-png-common",
"@kbn/core",
"@kbn/reporting-mocks-server",
"@kbn/logging",
]
}

View file

@ -0,0 +1,3 @@
# @kbn/reporting-export-types-png-common
Empty package generated by @kbn/generate

View file

@ -0,0 +1,13 @@
/*
* 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.
*/
export const PNG_REPORT_TYPE = 'PNG';
export const PNG_REPORT_TYPE_V2 = 'pngV2';
export const PNG_JOB_TYPE = 'PNG';
export const PNG_JOB_TYPE_V2 = 'PNGV2';

View file

@ -1,15 +1,27 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import type { LayoutParams } from '@kbn/screenshotting-plugin/common';
import type { LocatorParams } from '../url';
import type { BaseParams, BasePayload } from '../base';
import type { BaseParams, BasePayload, LocatorParams } from '@kbn/reporting-common/types';
import { LayoutParams } from '@kbn/screenshotting-plugin/common';
export * from './constants';
interface BaseParamsPNG {
layout: LayoutParams;
forceNow?: string;
relativeUrl: string;
}
export type JobParamsPNGDeprecated = BaseParamsPNG & BaseParams;
// Job payload: structure of stored job data provided by create_job
export type TaskPayloadPNG = BaseParamsPNG & BasePayload;
// Job params: structure of incoming user request data
export interface JobParamsPNGV2 extends BaseParams {
layout: LayoutParams;
/**

View file

@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/reporting-export-types-png-common",
"owner": "@elastic/appex-sharedux"
}

View file

@ -0,0 +1,6 @@
{
"name": "@kbn/reporting-export-types-png-common",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0"
}

View file

@ -0,0 +1,20 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/screenshotting-plugin",
"@kbn/reporting-common",
]
}

View file

@ -0,0 +1,3 @@
# @kbn/reporting-mocks-server
Empty package generated by @kbn/generate

View file

@ -0,0 +1,48 @@
/*
* 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.
*/
import type { DeepPartial } from 'utility-types';
import type { ReportingConfigType } from '@kbn/reporting-server';
export const createMockConfigSchema = (
overrides: DeepPartial<ReportingConfigType> = {}
): ReportingConfigType => {
// deeply merge the defaults and the provided partial schema
return {
index: '.reporting',
encryptionKey: 'cool-encryption-key-where-did-you-find-it',
...overrides,
kibanaServer: {
hostname: 'localhost',
...overrides.kibanaServer,
},
queue: {
indexInterval: 'week',
pollEnabled: true,
pollInterval: 3000,
timeout: 120000,
...overrides.queue,
},
csv: {
scroll: { size: 500, duration: '30s' },
...overrides.csv,
},
roles: {
enabled: false,
...overrides.roles,
},
capture: { maxAttempts: 1 },
export_types: {
pdf: { enabled: true },
png: { enabled: true },
csv: { enabled: true },
...overrides.export_types,
},
statefulSettings: { enabled: true },
} as ReportingConfigType;
};

View file

@ -0,0 +1,13 @@
/*
* 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.
*/
module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../../..',
roots: ['<rootDir>/packages/kbn-reporting/mocks_server'],
};

View file

@ -1,5 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/generate-csv-types",
"id": "@kbn/reporting-mocks-server",
"owner": "@elastic/appex-sharedux"
}

View file

@ -0,0 +1,6 @@
{
"name": "@kbn/reporting-mocks-server",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0"
}

View file

@ -0,0 +1,19 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/reporting-server",
]
}

View file

@ -0,0 +1,3 @@
# @kbn/reporting-public
Empty package generated by @kbn/generate

View file

@ -0,0 +1,9 @@
/*
* 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.
*/
export type { ClientConfigType } from './types';

View file

@ -0,0 +1,13 @@
/*
* 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.
*/
module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../../..',
roots: ['<rootDir>/packages/kbn-reporting/public'],
};

View file

@ -0,0 +1,5 @@
{
"type": "shared-browser",
"id": "@kbn/reporting-public",
"owner": "@elastic/appex-sharedux"
}

View file

@ -1,5 +1,5 @@
{
"name": "@kbn/generate-csv-types",
"name": "@kbn/reporting-public",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0"

View file

@ -0,0 +1,17 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts",
],
"exclude": [
"target/**/*"
],
"kbn_references": []
}

View file

@ -0,0 +1,14 @@
/*
* 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.
*/
export interface ClientConfigType {
poll: { jobsRefresh: { interval: number; intervalErrorMultiplier: number } };
roles: { enabled: boolean };
export_types: { pdf: { enabled: boolean }; png: { enabled: boolean }; csv: { enabled: boolean } };
statefulSettings: { enabled: boolean };
}

View file

@ -1,11 +1,12 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import { ConfigSchema } from './schema';
import { ConfigSchema } from './config_schema';
describe('Reporting Config Schema', () => {
it(`context {"dev":false,"dist":false} produces correct config`, () => {

View file

@ -1,11 +1,12 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import { ByteSizeValue, offeringBasedSchema, schema, TypeOf } from '@kbn/config-schema';
import { ByteSizeValue, offeringBasedSchema, schema } from '@kbn/config-schema';
import ipaddr from 'ipaddr.js';
import { sum } from 'lodash';
import moment from 'moment';
@ -147,5 +148,3 @@ export const ConfigSchema = schema.object({
export_types: ExportTypeSchema,
statefulSettings: SettingsSchema,
});
export type ReportingConfigType = TypeOf<typeof ConfigSchema>;

View file

@ -1,8 +1,9 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import nodeCrypto from '@elastic/node-crypto';

View file

@ -1,13 +1,13 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import { loggingSystemMock } from '@kbn/core/server/mocks';
import { cryptoFactory } from '../../lib';
import { decryptJobHeaders } from '.';
import { cryptoFactory, decryptJobHeaders } from '.';
const logger = loggingSystemMock.createLogger();

View file

@ -1,13 +1,14 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import { i18n } from '@kbn/i18n';
import type { Logger } from '@kbn/core/server';
import { cryptoFactory } from '../../lib';
import { cryptoFactory } from './crypto';
export const decryptJobHeaders = async (
encryptionKey: string | undefined,
@ -17,7 +18,7 @@ export const decryptJobHeaders = async (
try {
if (typeof headers !== 'string') {
throw new Error(
i18n.translate('xpack.reporting.exportTypes.common.missingJobHeadersErrorMessage', {
i18n.translate('reporting.commonExportTypesHelpers.missingJobHeadersErrorMessage', {
defaultMessage: 'Job headers are missing',
})
);
@ -30,7 +31,7 @@ export const decryptJobHeaders = async (
throw new Error(
i18n.translate(
'xpack.reporting.exportTypes.common.failedToDecryptReportJobDataErrorMessage',
'reporting.commonExportTypesHelpers.failedToDecryptReportJobDataErrorMessage',
{
defaultMessage:
'Failed to decrypt report job data. Please ensure that {encryptionKey} is set and re-generate this report. {err}',

View file

@ -1,32 +1,34 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import {
IBasePath,
Headers,
Logger,
CoreKibanaRequest,
CoreSetup,
import type { IClusterClient } from '@kbn/core-elasticsearch-server';
import { CoreKibanaRequest } from '@kbn/core-http-router-server-internal';
import type {
FakeRawRequest,
Headers,
HttpServiceSetup,
IBasePath,
KibanaRequest,
PluginInitializerContext,
SavedObjectsClientContract,
SavedObjectsServiceStart,
UiSettingsServiceStart,
IClusterClient,
} from '@kbn/core/server';
import { LicenseType } from '@kbn/licensing-plugin/common/types';
import { ScreenshottingStart } from '@kbn/screenshotting-plugin/server';
} from '@kbn/core-http-server';
import type { CoreSetup } from '@kbn/core-lifecycle-server';
import type { PluginInitializerContext } from '@kbn/core-plugins-server';
import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server';
import type { SavedObjectsServiceStart } from '@kbn/core-saved-objects-server';
import type { UiSettingsServiceStart } from '@kbn/core-ui-settings-server';
import type { LicenseType } from '@kbn/licensing-plugin/common/types';
import type { Logger } from '@kbn/logging';
import type { ReportingServerInfo } from '@kbn/reporting-common/types';
import type { ScreenshottingStart } from '@kbn/screenshotting-plugin/server';
import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common';
import { SpacesPluginSetup } from '@kbn/spaces-plugin/server';
import { ReportingConfigType } from '../../config';
import { ReportingServerInfo } from '../../core';
import { CreateJobFn, ReportingStart, RunTaskFn } from '../../types';
import type { SpacesPluginSetup } from '@kbn/spaces-plugin/server';
import type { CreateJobFn, RunTaskFn } from './types';
import type { ReportingConfigType } from '.';
export interface BaseExportTypeSetupDeps {
basePath: Pick<IBasePath, 'set'>;
@ -38,7 +40,6 @@ export interface BaseExportTypeStartDeps {
uiSettings: UiSettingsServiceStart;
esClient: IClusterClient;
screenshotting?: ScreenshottingStart;
reporting: ReportingStart;
}
export abstract class ExportType<
@ -84,6 +85,20 @@ export abstract class ExportType<
return savedObjects.getScopedClient(request) as SavedObjectsClientContract;
}
private getSpaceId(request: KibanaRequest, logger = this.logger): string | undefined {
const spacesService = this.setupDeps.spaces?.spacesService;
if (spacesService) {
const spaceId = spacesService?.getSpaceId(request);
if (spaceId !== DEFAULT_SPACE_ID) {
logger.info(`Request uses Space ID: ${spaceId}`);
return spaceId;
} else {
logger.debug(`Request uses default Space`);
}
}
}
// needed to be protected vs private for the csv search source immediate export type
protected getUiSettingsServiceFactory(savedObjectsClient: SavedObjectsClientContract) {
const { uiSettings: uiSettingsService } = this.startDeps;
@ -93,7 +108,7 @@ export abstract class ExportType<
protected async getUiSettingsClient(request: KibanaRequest, logger = this.logger) {
const spacesService = this.setupDeps.spaces?.spacesService;
const spaceId = this.startDeps.reporting.getSpaceId(request, logger);
const spaceId = this.getSpaceId(request, logger);
if (spacesService && spaceId) {
logger.info(`Creating UI Settings Client for space: ${spaceId}`);

View file

@ -1,11 +1,12 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import { ReportingConfigType } from '../../../config';
import type { ReportingConfigType } from '.';
import { getFullRedirectAppUrl } from './get_full_redirect_app_url';
describe('getFullRedirectAppUrl', () => {

View file

@ -1,15 +1,16 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
* 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.
*/
import { format } from 'url';
import { ReportingServerInfo } from '../../../core';
import { ReportingConfigType } from '../../../config';
import { buildKibanaPath } from '../../../../common/build_kibana_path';
import { getRedirectAppPath } from '../../../../common/constants';
import { buildKibanaPath, getRedirectAppPath } from '@kbn/reporting-common';
import type { ReportingServerInfo } from '@kbn/reporting-common/types';
import type { ReportingConfigType } from '.';
export function getFullRedirectAppUrl(
config: ReportingConfigType,

Some files were not shown because too many files have changed in this diff Show more