mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Use target_web
to ensure browser compatibility (#130874)
This commit is contained in:
parent
af8810fede
commit
f7a1739dc0
47 changed files with 256 additions and 62 deletions
|
@ -62,6 +62,13 @@ jsts_transpiler(
|
|||
build_pkg_name = package_name(),
|
||||
)
|
||||
|
||||
jsts_transpiler(
|
||||
name = "target_web",
|
||||
srcs = SRCS,
|
||||
build_pkg_name = package_name(),
|
||||
web = True,
|
||||
)
|
||||
|
||||
ts_config(
|
||||
name = "tsconfig",
|
||||
src = "tsconfig.json",
|
||||
|
@ -86,7 +93,7 @@ ts_project(
|
|||
js_library(
|
||||
name = PKG_DIRNAME,
|
||||
srcs = NPM_MODULE_EXTRA_FILES,
|
||||
deps = RUNTIME_DEPS + [":target_node"],
|
||||
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
|
||||
package_name = PKG_REQUIRE_NAME,
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
"name": "@kbn/analytics-client",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"browser": "./target_web/index.js",
|
||||
"main": "./target_node/index.js",
|
||||
"license": "SSPL-1.0 OR Elastic License 2.0"
|
||||
}
|
||||
|
|
|
@ -62,6 +62,13 @@ jsts_transpiler(
|
|||
build_pkg_name = package_name(),
|
||||
)
|
||||
|
||||
jsts_transpiler(
|
||||
name = "target_web",
|
||||
srcs = SRCS,
|
||||
build_pkg_name = package_name(),
|
||||
web = True,
|
||||
)
|
||||
|
||||
ts_config(
|
||||
name = "tsconfig",
|
||||
src = "tsconfig.json",
|
||||
|
@ -86,7 +93,7 @@ ts_project(
|
|||
js_library(
|
||||
name = PKG_DIRNAME,
|
||||
srcs = NPM_MODULE_EXTRA_FILES,
|
||||
deps = RUNTIME_DEPS + [":target_node"],
|
||||
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
|
||||
package_name = PKG_REQUIRE_NAME,
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
"name": "@kbn/analytics-shippers-fullstory",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"browser": "./target_web/index.js",
|
||||
"main": "./target_node/index.js",
|
||||
"license": "SSPL-1.0 OR Elastic License 2.0"
|
||||
}
|
||||
|
|
|
@ -52,6 +52,19 @@ jsts_transpiler(
|
|||
build_pkg_name = package_name(),
|
||||
)
|
||||
|
||||
jsts_transpiler(
|
||||
name = "target_web",
|
||||
srcs = SRCS,
|
||||
additional_args = [
|
||||
"--copy-files",
|
||||
"--ignore",
|
||||
"**/*/src/ace/modes/x_json/worker/x_json.ace.worker.js",
|
||||
"--quiet"
|
||||
],
|
||||
build_pkg_name = package_name(),
|
||||
web = True,
|
||||
)
|
||||
|
||||
ts_config(
|
||||
name = "tsconfig",
|
||||
src = "tsconfig.json",
|
||||
|
@ -77,7 +90,7 @@ ts_project(
|
|||
js_library(
|
||||
name = PKG_BASE_NAME,
|
||||
srcs = NPM_MODULE_EXTRA_FILES,
|
||||
deps = RUNTIME_DEPS + [":target_node"],
|
||||
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
|
||||
package_name = PKG_REQUIRE_NAME,
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
"name": "@kbn/ace",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"browser": "./target_web/index.js",
|
||||
"main": "./target_node/index.js",
|
||||
"license": "SSPL-1.0 OR Elastic License 2.0"
|
||||
}
|
||||
|
|
|
@ -45,6 +45,13 @@ jsts_transpiler(
|
|||
build_pkg_name = package_name(),
|
||||
)
|
||||
|
||||
jsts_transpiler(
|
||||
name = "target_web",
|
||||
srcs = SRCS,
|
||||
build_pkg_name = package_name(),
|
||||
web = True,
|
||||
)
|
||||
|
||||
ts_config(
|
||||
name = "tsconfig",
|
||||
src = "tsconfig.json",
|
||||
|
@ -69,7 +76,7 @@ ts_project(
|
|||
js_library(
|
||||
name = PKG_BASE_NAME,
|
||||
srcs = NPM_MODULE_EXTRA_FILES,
|
||||
deps = RUNTIME_DEPS + [":target_node"],
|
||||
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
|
||||
package_name = PKG_REQUIRE_NAME,
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"name": "@kbn/doc-links",
|
||||
"browser": "./target_web/index.js",
|
||||
"main": "./target_node/index.js",
|
||||
"version": "1.0.0",
|
||||
"license": "SSPL-1.0 OR Elastic License 2.0",
|
||||
|
|
|
@ -43,10 +43,17 @@ TYPES_DEPS = [
|
|||
]
|
||||
|
||||
jsts_transpiler(
|
||||
name = "target_node",
|
||||
srcs = SRCS,
|
||||
build_pkg_name = package_name(),
|
||||
)
|
||||
name = "target_node",
|
||||
srcs = SRCS,
|
||||
build_pkg_name = package_name(),
|
||||
)
|
||||
|
||||
jsts_transpiler(
|
||||
name = "target_web",
|
||||
srcs = SRCS,
|
||||
build_pkg_name = package_name(),
|
||||
web = True,
|
||||
)
|
||||
|
||||
ts_config(
|
||||
name = "tsconfig",
|
||||
|
@ -72,7 +79,7 @@ ts_project(
|
|||
js_library(
|
||||
name = PKG_BASE_NAME,
|
||||
srcs = NPM_MODULE_EXTRA_FILES,
|
||||
deps = RUNTIME_DEPS + [":target_node"],
|
||||
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
|
||||
package_name = PKG_REQUIRE_NAME,
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
|
|
@ -3,5 +3,6 @@
|
|||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"license": "SSPL-1.0 OR Elastic License 2.0",
|
||||
"browser": "./target_web/index.js",
|
||||
"main": "./target_node/index.js"
|
||||
}
|
||||
|
|
|
@ -42,6 +42,13 @@ jsts_transpiler(
|
|||
build_pkg_name = package_name(),
|
||||
)
|
||||
|
||||
jsts_transpiler(
|
||||
name = "target_web",
|
||||
srcs = SRCS,
|
||||
build_pkg_name = package_name(),
|
||||
web = True,
|
||||
)
|
||||
|
||||
peggy(
|
||||
name = "grammar",
|
||||
data = [
|
||||
|
@ -82,7 +89,7 @@ ts_project(
|
|||
js_library(
|
||||
name = PKG_BASE_NAME,
|
||||
srcs = NPM_MODULE_EXTRA_FILES + [":grammar"],
|
||||
deps = RUNTIME_DEPS + [":target_node"],
|
||||
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
|
||||
package_name = PKG_REQUIRE_NAME,
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"name": "@kbn/interpreter",
|
||||
"author": "App Services",
|
||||
"browser": "./target_web/index.js",
|
||||
"main": "./target_node/index.js",
|
||||
"version": "1.0.0",
|
||||
"license": "SSPL-1.0 OR Elastic License 2.0",
|
||||
|
|
|
@ -49,6 +49,13 @@ jsts_transpiler(
|
|||
build_pkg_name = package_name(),
|
||||
)
|
||||
|
||||
jsts_transpiler(
|
||||
name = "target_web",
|
||||
srcs = SRCS,
|
||||
build_pkg_name = package_name(),
|
||||
web = True,
|
||||
)
|
||||
|
||||
ts_config(
|
||||
name = "tsconfig",
|
||||
src = "tsconfig.json",
|
||||
|
@ -73,7 +80,7 @@ ts_project(
|
|||
js_library(
|
||||
name = PKG_BASE_NAME,
|
||||
srcs = NPM_MODULE_EXTRA_FILES,
|
||||
deps = RUNTIME_DEPS + [":target_node"],
|
||||
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
|
||||
package_name = PKG_REQUIRE_NAME,
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"name": "@kbn/io-ts-utils",
|
||||
"browser": "./target_web/index.js",
|
||||
"main": "./target_node/index.js",
|
||||
"version": "1.0.0",
|
||||
"license": "SSPL-1.0 OR Elastic License 2.0",
|
||||
|
|
|
@ -45,6 +45,13 @@ jsts_transpiler(
|
|||
build_pkg_name = package_name(),
|
||||
)
|
||||
|
||||
jsts_transpiler(
|
||||
name = "target_web",
|
||||
srcs = SRCS,
|
||||
build_pkg_name = package_name(),
|
||||
web = True,
|
||||
)
|
||||
|
||||
ts_config(
|
||||
name = "tsconfig",
|
||||
src = "tsconfig.json",
|
||||
|
@ -69,7 +76,7 @@ ts_project(
|
|||
js_library(
|
||||
name = PKG_BASE_NAME,
|
||||
srcs = NPM_MODULE_EXTRA_FILES,
|
||||
deps = RUNTIME_DEPS + [":target_node"],
|
||||
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
|
||||
package_name = PKG_REQUIRE_NAME,
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
|
|
@ -3,5 +3,6 @@
|
|||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"license": "SSPL-1.0 OR Elastic License 2.0",
|
||||
"browser": "./target_web/index.js",
|
||||
"main": "./target_node/index.js"
|
||||
}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* 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 Path from 'path';
|
||||
|
||||
import { run } from '@kbn/dev-utils';
|
||||
import { REPO_ROOT } from '@kbn/utils';
|
||||
|
||||
import { OptimizerConfig } from '../optimizer';
|
||||
import { parseStats } from './parse_stats';
|
||||
|
||||
/**
|
||||
* Analyzes the bundle dependencies to find any imports using the `@kbn/<package_name>/target_node` build target.
|
||||
*
|
||||
* We should aim for those packages to be imported using the `@kbn/<package_name>/target_web` build because it's optimized
|
||||
* for browser compatibility.
|
||||
*
|
||||
* This utility also helps identify when code that should only run in the server is leaked into the browser.
|
||||
*/
|
||||
export async function runFindTargetNodeImportsCli() {
|
||||
run(async ({ log }) => {
|
||||
const config = OptimizerConfig.create({
|
||||
includeCoreBundle: true,
|
||||
repoRoot: REPO_ROOT,
|
||||
});
|
||||
|
||||
const paths = config.bundles.map((b) => Path.resolve(b.outputDir, 'stats.json'));
|
||||
|
||||
log.info('analyzing', paths.length, 'stats files');
|
||||
log.verbose(paths);
|
||||
|
||||
const imports = new Set();
|
||||
for (const path of paths) {
|
||||
const stats = parseStats(path);
|
||||
|
||||
for (const module of stats.modules) {
|
||||
if (module.name.includes('/target_node/')) {
|
||||
const [, cleanName] = /\/((?:kbn-|@kbn\/).+)\/target_node/.exec(module.name) ?? [];
|
||||
imports.add(cleanName || module.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.success('found', imports.size, '@kbn/*/target_node imports in entry bundles and chunks');
|
||||
log.write(
|
||||
Array.from(imports, (i) => `'${i}',`)
|
||||
.sort()
|
||||
.join('\n')
|
||||
);
|
||||
});
|
||||
}
|
|
@ -8,3 +8,4 @@
|
|||
|
||||
export * from './find_babel_runtime_helpers_in_entry_bundles';
|
||||
export * from './find_node_libs_browser_polyfills_in_entry_bundles';
|
||||
export * from './find_target_node_imports';
|
|
@ -14,4 +14,4 @@ export * from './node';
|
|||
export * from './limits';
|
||||
export * from './cli';
|
||||
export * from './report_optimizer_timings';
|
||||
export * from './babel_runtime_helpers';
|
||||
export * from './audit_bundle_dependencies';
|
||||
|
|
|
@ -14,7 +14,10 @@ import { ascending } from '../common';
|
|||
export async function getOptimizerBuiltPaths() {
|
||||
return (
|
||||
await globby(
|
||||
['**/*', '!**/{__fixtures__,__snapshots__,integration_tests,babel_runtime_helpers,node}/**'],
|
||||
[
|
||||
'**/*',
|
||||
'!**/{__fixtures__,__snapshots__,integration_tests,audit_bundle_dependencies,node}/**',
|
||||
],
|
||||
{
|
||||
cwd: Path.resolve(__dirname, '../'),
|
||||
absolute: true,
|
||||
|
|
|
@ -44,6 +44,13 @@ jsts_transpiler(
|
|||
build_pkg_name = package_name(),
|
||||
)
|
||||
|
||||
jsts_transpiler(
|
||||
name = "target_web",
|
||||
srcs = SRCS,
|
||||
build_pkg_name = package_name(),
|
||||
web = True,
|
||||
)
|
||||
|
||||
ts_config(
|
||||
name = "tsconfig",
|
||||
src = "tsconfig.json",
|
||||
|
@ -69,7 +76,7 @@ ts_project(
|
|||
js_library(
|
||||
name = PKG_BASE_NAME,
|
||||
srcs = NPM_MODULE_EXTRA_FILES,
|
||||
deps = RUNTIME_DEPS + [":target_node"],
|
||||
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
|
||||
package_name = PKG_REQUIRE_NAME,
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"name": "@kbn/rule-data-utils",
|
||||
"browser": "./target_web/index.js",
|
||||
"main": "./target_node/index.js",
|
||||
"version": "1.0.0",
|
||||
"license": "SSPL-1.0 OR Elastic License 2.0",
|
||||
|
|
|
@ -47,6 +47,13 @@ jsts_transpiler(
|
|||
build_pkg_name = package_name(),
|
||||
)
|
||||
|
||||
jsts_transpiler(
|
||||
name = "target_web",
|
||||
srcs = SRCS,
|
||||
build_pkg_name = package_name(),
|
||||
web = True,
|
||||
)
|
||||
|
||||
ts_config(
|
||||
name = "tsconfig",
|
||||
src = "tsconfig.json",
|
||||
|
@ -71,7 +78,7 @@ ts_project(
|
|||
js_library(
|
||||
name = PKG_BASE_NAME,
|
||||
srcs = NPM_MODULE_EXTRA_FILES,
|
||||
deps = RUNTIME_DEPS + [":target_node"],
|
||||
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
|
||||
package_name = PKG_REQUIRE_NAME,
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
"version": "1.0.0",
|
||||
"description": "security solution rule utilities to use across plugins",
|
||||
"license": "SSPL-1.0 OR Elastic License 2.0",
|
||||
"browser": "./target_web/index.js",
|
||||
"main": "./target_node/index.js",
|
||||
"private": true
|
||||
}
|
||||
|
|
|
@ -47,6 +47,13 @@ jsts_transpiler(
|
|||
build_pkg_name = package_name(),
|
||||
)
|
||||
|
||||
jsts_transpiler(
|
||||
name = "target_web",
|
||||
srcs = SRCS,
|
||||
build_pkg_name = package_name(),
|
||||
web = True,
|
||||
)
|
||||
|
||||
ts_config(
|
||||
name = "tsconfig",
|
||||
src = "tsconfig.json",
|
||||
|
@ -71,7 +78,7 @@ ts_project(
|
|||
js_library(
|
||||
name = PKG_BASE_NAME,
|
||||
srcs = NPM_MODULE_EXTRA_FILES,
|
||||
deps = RUNTIME_DEPS + [":target_node"],
|
||||
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
|
||||
package_name = PKG_REQUIRE_NAME,
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
"version": "1.0.0",
|
||||
"description": "security solution utilities to use across plugins such lists, security_solution, cases, etc...",
|
||||
"license": "SSPL-1.0 OR Elastic License 2.0",
|
||||
"browser": "./target_web/index.js",
|
||||
"main": "./target_node/index.js",
|
||||
"private": true
|
||||
}
|
||||
|
|
|
@ -52,6 +52,17 @@ jsts_transpiler(
|
|||
build_pkg_name = package_name(),
|
||||
)
|
||||
|
||||
jsts_transpiler(
|
||||
name = "target_web",
|
||||
srcs = [
|
||||
"src/web_index.ts",
|
||||
"src/format_request.ts",
|
||||
"src/parse_endpoint.ts",
|
||||
],
|
||||
build_pkg_name = package_name(),
|
||||
web = True,
|
||||
)
|
||||
|
||||
ts_config(
|
||||
name = "tsconfig",
|
||||
src = "tsconfig.json",
|
||||
|
@ -76,7 +87,7 @@ ts_project(
|
|||
js_library(
|
||||
name = PKG_BASE_NAME,
|
||||
srcs = NPM_MODULE_EXTRA_FILES,
|
||||
deps = RUNTIME_DEPS + [":target_node"],
|
||||
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
|
||||
package_name = PKG_REQUIRE_NAME,
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
|
|
@ -5,3 +5,11 @@ Utility functions for creating a typed server route repository, and a typed clie
|
|||
## Usage
|
||||
|
||||
TBD
|
||||
|
||||
## Server vs. Browser entry points
|
||||
|
||||
This package exposes utils that can be used on both: the server and the browser.
|
||||
However, importing the package might bring in server-only code, affecting the bundle size.
|
||||
To avoid this, the package exposes 2 entry points: [`index.js`](./src/index.ts) and [`web_index.js`](./src/web_index.ts).
|
||||
|
||||
When adding utilities to this package, please make sure to update the entry points accordingly and the [BUILD.bazel](./BUILD.bazel)'s `target_web` target build to include all the necessary files.
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"name": "@kbn/server-route-repository",
|
||||
"browser": "./target_web/web_index.js",
|
||||
"main": "./target_node/index.js",
|
||||
"version": "1.0.0",
|
||||
"license": "SSPL-1.0 OR Elastic License 2.0",
|
||||
|
|
21
packages/kbn-server-route-repository/src/web_index.ts
Normal file
21
packages/kbn-server-route-repository/src/web_index.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* 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 { formatRequest } from './format_request';
|
||||
export { parseEndpoint } from './parse_endpoint';
|
||||
export type {
|
||||
RouteRepositoryClient,
|
||||
ReturnOf,
|
||||
EndpointOf,
|
||||
ClientRequestParamsOf,
|
||||
DecodedRequestParamsOf,
|
||||
ServerRouteRepository,
|
||||
ServerRoute,
|
||||
RouteParamsRT,
|
||||
RouteState,
|
||||
} from './typings';
|
10
scripts/find_target_node_imports_in_bundles.js
Normal file
10
scripts/find_target_node_imports_in_bundles.js
Normal 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.
|
||||
*/
|
||||
|
||||
require('../src/setup_node_env/no_transpilation');
|
||||
require('@kbn/optimizer').runFindTargetNodeImportsCli();
|
|
@ -8,16 +8,11 @@
|
|||
import { CoreSetup, CoreStart } from '@kbn/core/public';
|
||||
import type {
|
||||
ClientRequestParamsOf,
|
||||
formatRequest as formatRequestType,
|
||||
ReturnOf,
|
||||
RouteRepositoryClient,
|
||||
ServerRouteRepository,
|
||||
} from '@kbn/server-route-repository';
|
||||
// @ts-expect-error cannot find module or correspondent type declarations
|
||||
// The code and types are at separated folders on @kbn/server-route-repository
|
||||
// so in order to do targeted imports they must me imported separately, and
|
||||
// an error is expected here
|
||||
import { formatRequest } from '@kbn/server-route-repository/target_node/format_request';
|
||||
import { formatRequest } from '@kbn/server-route-repository';
|
||||
import { InspectResponse } from '@kbn/observability-plugin/typings/common';
|
||||
import { FetchOptions } from '../../../common/fetch_options';
|
||||
import { CallApi, callApi } from './call_api';
|
||||
|
@ -73,10 +68,7 @@ export function createCallApmApi(core: CoreStart | CoreSetup) {
|
|||
params?: Partial<Record<string, any>>;
|
||||
};
|
||||
|
||||
const { method, pathname } = formatRequest(
|
||||
endpoint,
|
||||
params?.path
|
||||
) as ReturnType<typeof formatRequestType>;
|
||||
const { method, pathname } = formatRequest(endpoint, params?.path);
|
||||
|
||||
return callApi(core, {
|
||||
...options,
|
||||
|
|
|
@ -33,3 +33,5 @@ export const INTERNAL_FEATURE_FLAGS = {
|
|||
showRisksMock: false,
|
||||
showFindingsGroupBy: false,
|
||||
} as const;
|
||||
|
||||
export const cspRuleAssetSavedObjectType = 'csp_rule';
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
*/
|
||||
import { schema as rt, TypeOf } from '@kbn/config-schema';
|
||||
|
||||
export const cspRuleAssetSavedObjectType = 'csp_rule';
|
||||
|
||||
// TODO: needs to be shared with cloudbeat
|
||||
export const cspRuleSchema = rt.object({
|
||||
id: rt.string(),
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { useQuery } from 'react-query';
|
||||
import type { ListResult } from '@kbn/fleet-plugin/common';
|
||||
import { BENCHMARKS_ROUTE_PATH } from '../../../common/constants';
|
||||
import { BenchmarksQuerySchema } from '../../../common/schemas/benchmark';
|
||||
import type { BenchmarksQuerySchema } from '../../../common/schemas/benchmark';
|
||||
import { useKibana } from '../../common/hooks/use_kibana';
|
||||
import type { Benchmark } from '../../../common/types';
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ import {
|
|||
import { useParams } from 'react-router-dom';
|
||||
import { FormattedMessage } from '@kbn/i18n-react';
|
||||
import { pagePathGetters } from '@kbn/fleet-plugin/public';
|
||||
import { cspRuleAssetSavedObjectType } from '../../../common/schemas/csp_rule';
|
||||
import { cspRuleAssetSavedObjectType } from '../../../common/constants';
|
||||
import { extractErrorMessage, isNonNullable } from '../../../common/utils/helpers';
|
||||
import { RulesTable } from './rules_table';
|
||||
import { RulesBottomBar } from './rules_bottom_bar';
|
||||
|
|
|
@ -7,8 +7,11 @@
|
|||
import { useQuery, useMutation, useQueryClient } from 'react-query';
|
||||
import { FunctionKeys } from 'utility-types';
|
||||
import type { SavedObjectsFindOptions, SimpleSavedObject } from '@kbn/core/public';
|
||||
import { UPDATE_RULES_CONFIG_ROUTE_PATH } from '../../../common/constants';
|
||||
import { cspRuleAssetSavedObjectType, type CspRuleSchema } from '../../../common/schemas/csp_rule';
|
||||
import {
|
||||
UPDATE_RULES_CONFIG_ROUTE_PATH,
|
||||
cspRuleAssetSavedObjectType,
|
||||
} from '../../../common/constants';
|
||||
import type { CspRuleSchema } from '../../../common/schemas/csp_rule';
|
||||
import { useKibana } from '../../common/hooks/use_kibana';
|
||||
import { UPDATE_FAILED } from './translations';
|
||||
|
||||
|
|
|
@ -17,8 +17,11 @@ import {
|
|||
cloudSecurityPostureRuleTemplateSavedObjectType,
|
||||
CloudSecurityPostureRuleTemplateSchema,
|
||||
} from '../../common/schemas/csp_rule_template';
|
||||
import { CLOUD_SECURITY_POSTURE_PACKAGE_NAME } from '../../common/constants';
|
||||
import { CspRuleSchema, cspRuleAssetSavedObjectType } from '../../common/schemas/csp_rule';
|
||||
import {
|
||||
CLOUD_SECURITY_POSTURE_PACKAGE_NAME,
|
||||
cspRuleAssetSavedObjectType,
|
||||
} from '../../common/constants';
|
||||
import { CspRuleSchema } from '../../common/schemas/csp_rule';
|
||||
|
||||
type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends ReadonlyArray<
|
||||
infer ElementType
|
||||
|
|
|
@ -19,10 +19,11 @@ import type {
|
|||
AgentPolicy,
|
||||
ListResult,
|
||||
} from '@kbn/fleet-plugin/common';
|
||||
import { cspRuleAssetSavedObjectType, CspRuleSchema } from '../../../common/schemas/csp_rule';
|
||||
import { CspRuleSchema } from '../../../common/schemas/csp_rule';
|
||||
import {
|
||||
BENCHMARKS_ROUTE_PATH,
|
||||
CLOUD_SECURITY_POSTURE_PACKAGE_NAME,
|
||||
cspRuleAssetSavedObjectType,
|
||||
} from '../../../common/constants';
|
||||
import {
|
||||
BENCHMARK_PACKAGE_POLICY_PREFIX,
|
||||
|
|
|
@ -26,7 +26,9 @@ import { CspAppContext } from '../../plugin';
|
|||
import { createPackagePolicyMock } from '@kbn/fleet-plugin/common/mocks';
|
||||
import { createPackagePolicyServiceMock } from '@kbn/fleet-plugin/server/mocks';
|
||||
|
||||
import { cspRuleAssetSavedObjectType, CspRuleSchema } from '../../../common/schemas/csp_rule';
|
||||
import { cspRuleAssetSavedObjectType } from '../../../common/constants';
|
||||
import { CspRuleSchema } from '../../../common/schemas/csp_rule';
|
||||
|
||||
import {
|
||||
ElasticsearchClient,
|
||||
KibanaRequest,
|
||||
|
|
|
@ -20,9 +20,12 @@ import { PackagePolicy, PackagePolicyConfigRecord } from '@kbn/fleet-plugin/comm
|
|||
import { PackagePolicyServiceInterface } from '@kbn/fleet-plugin/server';
|
||||
import { CspAppContext } from '../../plugin';
|
||||
import { CspRulesConfigSchema } from '../../../common/schemas/csp_configuration';
|
||||
import { CspRuleSchema, cspRuleAssetSavedObjectType } from '../../../common/schemas/csp_rule';
|
||||
import { UPDATE_RULES_CONFIG_ROUTE_PATH } from '../../../common/constants';
|
||||
import { CLOUD_SECURITY_POSTURE_PACKAGE_NAME } from '../../../common/constants';
|
||||
import { CspRuleSchema } from '../../../common/schemas/csp_rule';
|
||||
import {
|
||||
CLOUD_SECURITY_POSTURE_PACKAGE_NAME,
|
||||
UPDATE_RULES_CONFIG_ROUTE_PATH,
|
||||
cspRuleAssetSavedObjectType,
|
||||
} from '../../../common/constants';
|
||||
import { CspRouter } from '../../types';
|
||||
|
||||
export const getPackagePolicy = async (
|
||||
|
|
|
@ -7,11 +7,8 @@
|
|||
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import type { SavedObjectsType, SavedObjectsValidationMap } from '@kbn/core/server';
|
||||
import {
|
||||
type CspRuleSchema,
|
||||
cspRuleSchema,
|
||||
cspRuleAssetSavedObjectType,
|
||||
} from '../../common/schemas/csp_rule';
|
||||
import { cspRuleAssetSavedObjectType } from '../../common/constants';
|
||||
import { type CspRuleSchema, cspRuleSchema } from '../../common/schemas/csp_rule';
|
||||
|
||||
const validationMap: SavedObjectsValidationMap = {
|
||||
'1.0.0': cspRuleSchema,
|
||||
|
|
|
@ -5,9 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
// @ts-expect-error
|
||||
import { formatRequest } from '@kbn/server-route-repository/target_node/format_request';
|
||||
import type { formatRequest as formatRequestType } from '@kbn/server-route-repository/target_types/format_request';
|
||||
import { formatRequest } from '@kbn/server-route-repository';
|
||||
import type { HttpSetup } from '@kbn/core/public';
|
||||
import type { AbstractObservabilityClient, ObservabilityClient } from './types';
|
||||
|
||||
|
@ -19,9 +17,7 @@ export function createCallObservabilityApi(http: HttpSetup) {
|
|||
const client: AbstractObservabilityClient = (endpoint, options) => {
|
||||
const { params: { path, body, query } = {}, ...rest } = options;
|
||||
|
||||
const { method, pathname } = formatRequest(endpoint, path) as ReturnType<
|
||||
typeof formatRequestType
|
||||
>;
|
||||
const { method, pathname } = formatRequest(endpoint, path);
|
||||
|
||||
return http[method](pathname, {
|
||||
...rest,
|
||||
|
|
|
@ -8,16 +8,11 @@
|
|||
import { CoreSetup, CoreStart } from '@kbn/core/public';
|
||||
import type {
|
||||
ClientRequestParamsOf,
|
||||
formatRequest as formatRequestType,
|
||||
ReturnOf,
|
||||
RouteRepositoryClient,
|
||||
ServerRouteRepository,
|
||||
} from '@kbn/server-route-repository';
|
||||
// @ts-expect-error cannot find module or correspondent type declarations
|
||||
// The code and types are at separated folders on @kbn/server-route-repository
|
||||
// so in order to do targeted imports they must me imported separately, and
|
||||
// an error is expected here
|
||||
import { formatRequest } from '@kbn/server-route-repository/target_node/format_request';
|
||||
import { formatRequest } from '@kbn/server-route-repository';
|
||||
import type {
|
||||
APMServerRouteRepository,
|
||||
APIEndpoint,
|
||||
|
@ -73,10 +68,7 @@ export function createCallApmApi(core: CoreStart | CoreSetup) {
|
|||
params?: Partial<Record<string, any>>;
|
||||
};
|
||||
|
||||
const { method, pathname } = formatRequest(
|
||||
endpoint,
|
||||
params?.path
|
||||
) as ReturnType<typeof formatRequestType>;
|
||||
const { method, pathname } = formatRequest(endpoint, params?.path);
|
||||
|
||||
return callApi(core, {
|
||||
...options,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue