Skip to content

Commit

Permalink
Merge pull request #11 from tsullivan/reporting-packages
Browse files Browse the repository at this point in the history
fix some reporting-common package imports
  • Loading branch information
rshen91 authored Nov 9, 2023
2 parents b06aeac + 8c7a298 commit 6d07fbc
Show file tree
Hide file tree
Showing 42 changed files with 235 additions and 191 deletions.
26 changes: 0 additions & 26 deletions packages/kbn-generate-csv-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,3 @@ export interface CsvConfig {
size: number;
};
}

/**
* @internal
* Needed to separate dependencies from reporting
*/
export interface CancellationToken {
isCancelled: () => boolean;
cancel: () => void;
}

/**
* @internal
* Needed to separate dependencies from reporting
*/
export interface TaskRunResult {
content_type: string;
csv_contains_formulas: boolean;
max_size_reached: boolean;
metrics: {
csv: {
rows: number;
};
};
warnings: unknown;
error_code: unknown;
}
17 changes: 8 additions & 9 deletions packages/kbn-generate-csv/src/generate_csv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -20,25 +24,20 @@ 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 { CsvGenerator } from './generate_csv';
import { CancellationToken, CsvConfig, JobParams } from '@kbn/generate-csv-types';
import { CsvConfig, JobParams } from '@kbn/generate-csv-types';
import { CancellationToken } from '@kbn/reporting-common';
import {
UI_SETTINGS_CSV_QUOTE_VALUES,
UI_SETTINGS_CSV_SEPARATOR,
UI_SETTINGS_DATEFORMAT_TZ,
} from './constants';
import { CsvGenerator } from './generate_csv';

const createMockJob = (baseObj: any = {}): JobParams => ({
...baseObj,
});

const createMockCancellationToken = (): CancellationToken => ({
isCancelled: () => false,
cancel: jest.fn(),
});
const createMockCancellationToken = () => new CancellationToken();

describe('CsvGenerator', () => {
let mockEsClient: IScopedClusterClient;
Expand Down
9 changes: 8 additions & 1 deletion packages/kbn-generate-csv/src/generate_csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ import type {
FieldFormatConfig,
IFieldFormatsRegistry,
} from '@kbn/field-formats-plugin/common';
import { CsvConfig, JobParams } from '@kbn/generate-csv-types';
import type { TaskRunResult } from '@kbn/reporting-common/types';
import {
AuthenticationExpiredError,
CancellationToken,
ReportingError,
byteSizeValueToNumber,
} from '@kbn/reporting-common';

import { CancellationToken, CsvConfig, JobParams, TaskRunResult } from '@kbn/generate-csv-types';
import { CONTENT_TYPE_CSV } from './constants';
import { CsvExportSettings, getExportSettings } from './get_export_settings';
import { i18nTexts } from './i18n_texts';
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-generate-csv/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
"@kbn/config-schema",
"@kbn/i18n",
"@kbn/generate-csv-types",
"@kbn/reporting-common",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { getFullRedirectAppUrl } from './get_full_redirect_app_url';
import { ReportingConfigType } from './types';

describe('getFullRedirectAppUrl', () => {
const mockConfig = { kibanaServer: {} } as unknown as ReportingConfigType;
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-reporting/common/get_full_redirect_app_url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { format } from 'url';
import { buildKibanaPath } from './build_kibana_path';
import { getRedirectAppPath } from './constants';
import { ReportingConfigType, ReportingServerInfo } from './types';

export function getFullRedirectAppUrl(
config: ReportingConfigType,
Expand Down
14 changes: 5 additions & 9 deletions packages/kbn-reporting/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@
* Side Public License, v 1.
*/

export { CancellationToken } from './cancellation_token';
export { buildKibanaPath } from './build_kibana_path';
export * from './constants';
export * from './errors';
export * from './schema_utils';
export * as jobTypes from './job_types';
export * from './report_types';
export type {
LocatorParams,
UrlOrUrlLocatorTuple,
IlmPolicyStatusResponse,
ManagementLinkFn,
} from './url';
export * from './schema_utils';

export { buildKibanaPath } from './build_kibana_path';
export { CancellationToken } from './cancellation_token';
export { getFullRedirectAppUrl } from './get_full_redirect_app_url';
1 change: 1 addition & 0 deletions packages/kbn-reporting/common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"kbn_references": [
"@kbn/config-schema",
"@kbn/utility-types",
"@kbn/screenshotting-plugin",
"@kbn/i18n",
]
}
41 changes: 37 additions & 4 deletions packages/kbn-reporting/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@
* Side Public License, v 1.
*/

import type { LocatorParams } from '.';
import { LayoutParams } from '@kbn/screenshotting-plugin/common';
import type { PerformanceMetrics as ScreenshotMetrics } from '@kbn/screenshotting-plugin/common/types';
import type { ByteSizeValue } from '@kbn/config-schema';
import type { LocatorParams } from './url';

export * from './url';

export interface CsvMetrics {
rows: number;
}

export interface TaskRunMetrics {
csv?: CsvMetrics;
png?: unknown;
pdf?: unknown;
png?: ScreenshotMetrics;
pdf?: ScreenshotMetrics & { pages?: number };
}

export interface TaskRunResult {
Expand Down Expand Up @@ -44,7 +49,7 @@ export interface ReportOutput extends TaskRunResult {
* @deprecated
*/
export interface BaseParams {
layout?: unknown;
layout?: LayoutParams;
objectType: string;
title: string;
browserTimezone: string; // to format dates in the user's time zone
Expand Down Expand Up @@ -78,3 +83,31 @@ export interface BasePayloadV2 extends BaseParamsV2 {
spaceId?: string;
isDeprecated?: boolean;
}

export interface ReportingConfigType {
encryptionKey?: string;
kibanaServer: {
protocol?: string;
hostname?: string;
port?: number;
};
csv: {
checkForFormulas: boolean;
escapeFormulaValues: boolean;
useByteOrderMarkEncoding: boolean;
maxSizeBytes: number | ByteSizeValue;
scroll: {
duration: string;
size: number;
};
};
}

export interface ReportingServerInfo {
basePath: string;
protocol: string;
hostname: string;
port: number;
name: string;
uuid: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* 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';
Expand All @@ -20,14 +22,14 @@ import {
LICENSE_TYPE_PLATINUM,
LICENSE_TYPE_TRIAL,
} from '@kbn/reporting-common';
import { Writable } from 'stream';
import type { TaskRunResult } from '@kbn/reporting-common/types';
import type {
BaseExportTypeSetupDeps,
BaseExportTypeStartDeps,
ReportingRequestHandlerContext,
JobParamsDownloadCSV,
ReportingRequestHandlerContext,
} from '@kbn/reporting-export-types-helpers-server';
import { getFieldFormats, ExportType } from '@kbn/reporting-export-types-helpers-server';
import { ExportType, getFieldFormats } from '@kbn/reporting-export-types-helpers-server';

type CsvSearchSourceImmediateExportTypeSetupDeps = BaseExportTypeSetupDeps;
interface CsvSearchSourceImmediateExportTypeStartDeps extends BaseExportTypeStartDeps {
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-reporting/export_types/deprecated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
*/

export { PdfV1ExportType } from './printable_pdf';
export type { JobParamsPDFDeprecated } from './printable_pdf';
39 changes: 20 additions & 19 deletions packages/kbn-reporting/export_types/png/png_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,6 @@
*/

import apm from 'elastic-apm-node';
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,
LocatorParams,
PNG_JOB_TYPE_V2,
REPORTING_TRANSACTION_TYPE,
REPORTING_REDIRECT_LOCATOR_STORE_KEY,
} from '@kbn/reporting-common';
import { Writable } from 'stream';
import {
finalize,
fromEventPattern,
Expand All @@ -32,18 +18,33 @@ import {
takeUntil,
tap,
} from 'rxjs';
import { SerializableRecord } from '@kbn/utility-types';
import { PNG_REPORT_TYPE_V2 } from '@kbn/reporting-common/report_types';
import type { PngScreenshotOptions, PngScreenshotResult } from '@kbn/screenshotting-plugin/server';
import type { Context } from '@kbn/screenshotting-plugin/server/browsers';
import { Writable } from 'stream';

import type { LicenseType } from '@kbn/licensing-plugin/server';
import {
CancellationToken,
getFullRedirectAppUrl,
LICENSE_TYPE_CLOUD_STANDARD,
LICENSE_TYPE_ENTERPRISE,
LICENSE_TYPE_GOLD,
LICENSE_TYPE_PLATINUM,
LICENSE_TYPE_TRIAL,
PNG_JOB_TYPE_V2,
PNG_REPORT_TYPE_V2,
REPORTING_REDIRECT_LOCATOR_STORE_KEY,
REPORTING_TRANSACTION_TYPE,
} from '@kbn/reporting-common';
import type { LocatorParams, TaskRunResult } from '@kbn/reporting-common/types';
import {
decryptJobHeaders,
ExportType,
getFullRedirectAppUrl,
generatePngObservable,
JobParamsPNGV2,
TaskPayloadPNGV2,
} from '@kbn/reporting-export-types-helpers-server';
import type { PngScreenshotOptions, PngScreenshotResult } from '@kbn/screenshotting-plugin/server';
import type { Context } from '@kbn/screenshotting-plugin/server/browsers';
import { SerializableRecord } from '@kbn/utility-types';

export class PngExportType extends ExportType<JobParamsPNGV2, TaskPayloadPNGV2> {
id = PNG_REPORT_TYPE_V2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Side Public License, v 1.
*/

import { Headers } from '@kbn/core/server';
import apm from 'elastic-apm-node';
import {
catchError,
Expand All @@ -21,28 +20,31 @@ import {
throwError,
} from 'rxjs';
import { Writable } from 'stream';

import { Headers } from '@kbn/core/server';
import type { TaskRunResult } from '@kbn/reporting-common/types';
import {
PDF_REPORT_TYPE_V2,
PDF_JOB_TYPE_V2,
LICENSE_TYPE_TRIAL,
CancellationToken,
getFullRedirectAppUrl,
LICENSE_TYPE_CLOUD_STANDARD,
LICENSE_TYPE_ENTERPRISE,
LICENSE_TYPE_GOLD,
LICENSE_TYPE_PLATINUM,
LICENSE_TYPE_ENTERPRISE,
REPORTING_TRANSACTION_TYPE,
CancellationToken,
LICENSE_TYPE_TRIAL,
PDF_JOB_TYPE_V2,
PDF_REPORT_TYPE_V2,
REPORTING_REDIRECT_LOCATOR_STORE_KEY,
REPORTING_TRANSACTION_TYPE,
} from '@kbn/reporting-common';
import type { PdfScreenshotOptions, PdfScreenshotResult } from '@kbn/screenshotting-plugin/server';
import {
generatePdfObservableV2,
decryptJobHeaders,
getCustomLogo,
getFullRedirectAppUrl,
ExportType,
generatePdfObservableV2,
getCustomLogo,
JobParamsPDFV2,
TaskPayloadPDFV2,
} from '@kbn/reporting-export-types-helpers-server';
import type { PdfScreenshotOptions, PdfScreenshotResult } from '@kbn/screenshotting-plugin/server';
import { UrlOrUrlWithContext } from '@kbn/screenshotting-plugin/server/screenshots';

export class PdfExportType extends ExportType<JobParamsPDFV2, TaskPayloadPDFV2> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,28 @@
* Side Public License, v 1.
*/

import type { IClusterClient } from '@kbn/core-elasticsearch-server';
import { CoreKibanaRequest } from '@kbn/core-http-router-server-internal';
import type {
FakeRawRequest,
Headers,
HttpServiceSetup,
IBasePath,
KibanaRequest,
Headers,
} from '@kbn/core-http-server';
import type { Logger } from '@kbn/logging';
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 { ReportingConfigType, ReportingServerInfo } from '@kbn/reporting-common/types';
import type { ScreenshottingStart } from '@kbn/screenshotting-plugin/server';
import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common';
import type { SpacesPluginSetup } from '@kbn/spaces-plugin/server';
import type { IClusterClient } from '@kbn/core-elasticsearch-server';
import { CoreKibanaRequest } from '@kbn/core-http-router-server-internal';
import { CreateJobFn, ReportingServerInfo, RunTaskFn } from './types';

import { CreateJobFn, RunTaskFn } from './types';

export interface BaseExportTypeSetupDeps {
basePath: Pick<IBasePath, 'set'>;
Expand Down
Loading

0 comments on commit 6d07fbc

Please sign in to comment.