Skip to content

Commit

Permalink
Adds two more packages and moves files into the packages (#100375) (#…
Browse files Browse the repository at this point in the history
…100418)

## Summary

* Adds package `kbn-securitysolution-list-api`
* Adds package `kbn-securitysolution-list-hooks`
* Moves files into the packages
* Moves a few additional types into the other packages such as the `kbn-securitysolution-io-ts-types` package to remove more things from the shard_export/shared_import between lists and security solution
* Removes more duplicated code

### Checklist

- [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: Frank Hassanabad <frank.hassanabad@elastic.co>
  • Loading branch information
kibanamachine and FrankHassanabad authored May 20, 2021
1 parent 8ee9c3a commit 533d32f
Show file tree
Hide file tree
Showing 128 changed files with 1,658 additions and 506 deletions.
2 changes: 2 additions & 0 deletions docs/developer/getting-started/monorepo-packages.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ yarn kbn watch-bazel
- kbn/securitysolution-io-ts-list-types
- kbn/securitysolution-io-ts-types
- @kbn/securitysolution-io-ts-utils
- @kbn/securitysolution-list-api
- @kbn/securitysolution-list-hooks
- @kbn/securitysolution-list-utils
- @kbn/securitysolution-utils
- @kbn/server-http-tools
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@
"@kbn/securitysolution-io-ts-alerting-types": "link:bazel-bin/packages/kbn-securitysolution-io-ts-alerting-types/npm_module",
"@kbn/securitysolution-io-ts-list-types": "link:bazel-bin/packages/kbn-securitysolution-io-ts-list-types/npm_module",
"@kbn/securitysolution-io-ts-utils": "link:bazel-bin/packages/kbn-securitysolution-io-ts-utils/npm_module",
"@kbn/securitysolution-list-api": "link:bazel-bin/packages/kbn-securitysolution-list-api/npm_module",
"@kbn/securitysolution-list-hooks": "link:bazel-bin/packages/kbn-securitysolution-list-hooks/npm_module",
"@kbn/securitysolution-list-utils": "link:bazel-bin/packages/kbn-securitysolution-list-utils/npm_module",
"@kbn/securitysolution-utils": "link:bazel-bin/packages/kbn-securitysolution-utils/npm_module",
"@kbn/server-http-tools": "link:bazel-bin/packages/kbn-server-http-tools/npm_module",
Expand Down
4 changes: 3 additions & 1 deletion packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ filegroup(
"//packages/kbn-logging:build",
"//packages/kbn-plugin-generator:build",
"//packages/kbn-securitysolution-constants:build",
"//packages/kbn-securitysolution-list-utils:build",
"//packages/kbn-securitysolution-io-ts-types:build",
"//packages/kbn-securitysolution-io-ts-alerting-types:build",
"//packages/kbn-securitysolution-io-ts-list-types:build",
"//packages/kbn-securitysolution-io-ts-utils:build",
"//packages/kbn-securitysolution-list-api:build",
"//packages/kbn-securitysolution-list-hooks:build",
"//packages/kbn-securitysolution-list-utils:build",
"//packages/kbn-securitysolution-utils:build",
"//packages/kbn-securitysolution-es-utils:build",
"//packages/kbn-server-http-tools:build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './common';
export * from './constants';
export * from './request';
export * from './response';
export * from './typescript_types';
Original file line number Diff line number Diff line change
@@ -1,51 +1,47 @@
/*
* 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 {
CreateExceptionListItemSchema,
CreateExceptionListSchema,
ExceptionListItemSchema,
ExceptionListSchema,
ExceptionListType,
NamespaceType,
Page,
PerPage,
TotalOrUndefined,
UpdateExceptionListItemSchema,
UpdateExceptionListSchema,
} from '@kbn/securitysolution-io-ts-list-types';

import { HttpStart, NotificationsStart } from '../../../../../src/core/public';
import { NamespaceType } from '../common/default_namespace';
import { ExceptionListType } from '../common/exception_list';
import { Page } from '../common/page';
import { PerPage } from '../common/per_page';
import { TotalOrUndefined } from '../common/total';
import { CreateExceptionListItemSchema } from '../request/create_exception_list_item_schema';
import { CreateExceptionListSchema } from '../request/create_exception_list_schema';
import { UpdateExceptionListItemSchema } from '../request/update_exception_list_item_schema';
import { UpdateExceptionListSchema } from '../request/update_exception_list_schema';
import { ExceptionListItemSchema } from '../response/exception_list_item_schema';
import { ExceptionListSchema } from '../response/exception_list_schema';

// TODO: Replace these with kbn packaged versions once we have those available to us
// These originally came from this location below before moving them to this hacked "any" types:
// import { HttpStart, NotificationsStart } from '../../../../../src/core/public';
interface HttpStart {
fetch: <T>(...args: any) => any;
}
type NotificationsStart = any;

export interface FilterExceptionsOptions {
filter: string;
tags: string[];
}

export interface Pagination {
page: Page;
perPage: PerPage;
total: TotalOrUndefined;
export interface ExceptionListFilter {
name?: string | null;
list_id?: string | null;
created_by?: string | null;
type?: string | null;
tags?: string | null;
}

export type AddExceptionList = UpdateExceptionListSchema | CreateExceptionListSchema;

export interface PersistHookProps {
export interface UseExceptionListsProps {
errorMessage: string;
filterOptions?: ExceptionListFilter;
http: HttpStart;
onError: (arg: Error) => void;
}

export interface ExceptionList extends ExceptionListSchema {
totalItems: number;
}

export interface UseExceptionListItemsSuccess {
exceptions: ExceptionListItemSchema[];
pagination: Pagination;
namespaceTypes: NamespaceType[];
notifications: NotificationsStart;
pagination?: Pagination;
showTrustedApps: boolean;
}

export interface UseExceptionListProps {
Expand All @@ -60,27 +56,9 @@ export interface UseExceptionListProps {
onSuccess?: (arg: UseExceptionListItemsSuccess) => void;
}

export interface ExceptionListIdentifiers {
id: string;
listId: string;
namespaceType: NamespaceType;
type: ExceptionListType;
}

export interface ApiCallByListIdProps {
http: HttpStart;
listIds: string[];
namespaceTypes: NamespaceType[];
filterOptions: FilterExceptionsOptions[];
pagination: Partial<Pagination>;
signal: AbortSignal;
}

export interface ApiCallByIdProps {
http: HttpStart;
id: string;
namespaceType: NamespaceType;
signal: AbortSignal;
export interface FilterExceptionsOptions {
filter: string;
tags: string[];
}

export interface ApiCallMemoProps {
Expand All @@ -101,6 +79,24 @@ export interface ApiListExportProps {
onSuccess: (blob: Blob) => void;
}

export interface Pagination {
page: Page;
perPage: PerPage;
total: TotalOrUndefined;
}

export interface UseExceptionListItemsSuccess {
exceptions: ExceptionListItemSchema[];
pagination: Pagination;
}

export interface ExceptionListIdentifiers {
id: string;
listId: string;
namespaceType: NamespaceType;
type: ExceptionListType;
}

export interface ApiCallFindListsItemsMemoProps {
lists: ExceptionListIdentifiers[];
filterOptions: FilterExceptionsOptions[];
Expand All @@ -110,40 +106,29 @@ export interface ApiCallFindListsItemsMemoProps {
onError: (arg: string[]) => void;
onSuccess: (arg: UseExceptionListItemsSuccess) => void;
}
export interface ApiCallFetchExceptionListsProps {

export interface ExportExceptionListProps {
http: HttpStart;
namespaceTypes: string;
pagination: Partial<Pagination>;
filters: string;
id: string;
listId: string;
namespaceType: NamespaceType;
signal: AbortSignal;
}

export interface UseExceptionListsSuccess {
exceptions: ExceptionListSchema[];
pagination: Pagination;
}

export interface ExceptionListFilter {
name?: string | null;
list_id?: string | null;
created_by?: string | null;
type?: string | null;
tags?: string | null;
export interface AddEndpointExceptionListProps {
http: HttpStart;
signal: AbortSignal;
}

export interface UseExceptionListsProps {
errorMessage: string;
filterOptions?: ExceptionListFilter;
export interface UpdateExceptionListItemProps {
http: HttpStart;
namespaceTypes: NamespaceType[];
notifications: NotificationsStart;
pagination?: Pagination;
showTrustedApps: boolean;
listItem: UpdateExceptionListItemSchema;
signal: AbortSignal;
}

export interface AddExceptionListProps {
export interface UpdateExceptionListProps {
http: HttpStart;
list: CreateExceptionListSchema;
list: UpdateExceptionListSchema;
signal: AbortSignal;
}

Expand All @@ -153,27 +138,48 @@ export interface AddExceptionListItemProps {
signal: AbortSignal;
}

export interface UpdateExceptionListProps {
export interface AddExceptionListProps {
http: HttpStart;
list: UpdateExceptionListSchema;
list: CreateExceptionListSchema;
signal: AbortSignal;
}

export interface UpdateExceptionListItemProps {
http: HttpStart;
listItem: UpdateExceptionListItemSchema;
signal: AbortSignal;
export interface UseExceptionListsSuccess {
exceptions: ExceptionListSchema[];
pagination: Pagination;
}

export interface AddEndpointExceptionListProps {
export interface ApiCallFetchExceptionListsProps {
http: HttpStart;
namespaceTypes: string;
pagination: Partial<Pagination>;
filters: string;
signal: AbortSignal;
}

export interface ExportExceptionListProps {
export interface ApiCallByIdProps {
http: HttpStart;
id: string;
listId: string;
namespaceType: NamespaceType;
signal: AbortSignal;
}

export interface ApiCallByListIdProps {
http: HttpStart;
listIds: string[];
namespaceTypes: NamespaceType[];
filterOptions: FilterExceptionsOptions[];
pagination: Partial<Pagination>;
signal: AbortSignal;
}

export type AddExceptionList = UpdateExceptionListSchema | CreateExceptionListSchema;

export interface PersistHookProps {
http: HttpStart;
onError: (arg: Error) => void;
}

export interface ExceptionList extends ExceptionListSchema {
totalItems: number;
}
88 changes: 88 additions & 0 deletions packages/kbn-securitysolution-list-api/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library", "pkg_npm")

PKG_BASE_NAME = "kbn-securitysolution-list-api"

PKG_REQUIRE_NAME = "@kbn/securitysolution-list-api"

SOURCE_FILES = glob(
[
"src/**/*.ts",
],
exclude = [
"**/*.test.*",
"**/*.mock.*",
],
)

SRCS = SOURCE_FILES

filegroup(
name = "srcs",
srcs = SRCS,
)

NPM_MODULE_EXTRA_FILES = [
"package.json",
"README.md",
]

SRC_DEPS = [
"//packages/kbn-securitysolution-io-ts-utils",
"//packages/kbn-securitysolution-io-ts-list-types",
"@npm//fp-ts",
"@npm//io-ts",
"@npm//tslib",
]

TYPES_DEPS = [
"@npm//@types/jest",
"@npm//@types/node",
]

DEPS = SRC_DEPS + TYPES_DEPS

ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig.base.json",
],
)

ts_project(
name = "tsc",
srcs = SRCS,
args = ["--pretty"],
declaration = True,
declaration_map = True,
incremental = True,
out_dir = "target",
root_dir = "src",
source_map = True,
tsconfig = ":tsconfig",
deps = DEPS,
)

js_library(
name = PKG_BASE_NAME,
package_name = PKG_REQUIRE_NAME,
srcs = NPM_MODULE_EXTRA_FILES,
visibility = ["//visibility:public"],
deps = [":tsc"] + DEPS,
)

pkg_npm(
name = "npm_module",
deps = [
":%s" % PKG_BASE_NAME,
],
)

filegroup(
name = "build",
srcs = [
":npm_module",
],
visibility = ["//visibility:public"],
)
4 changes: 4 additions & 0 deletions packages/kbn-securitysolution-list-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# kbn-securitysolution-list-api

This is where the REST API for the list plugin lives

Loading

0 comments on commit 533d32f

Please sign in to comment.