kibana/x-pack/plugins/cases/server/scripts
Frank Hassanabad a398d467b8
[8.0] [Security Solutions] Removes tech debt of exporting all from linter rule for cases plugin in the common section (#120559)
* [Security Solutions] Removes tech debt of exporting all from linter rule for cases plugin in the common section (#120310)

See: https://github.com/elastic/kibana/issues/110903, https://github.com/elastic/kibana/issues/120234

This removes as many top level API `export *` spots from:
* `cases` plugin within the common section

as we can. This reduces the number of metrics and warning about undocumented functions and reduces the page load size from `cases/common/index.ts`. Look at the metrics from the build below and you will see drop off numbers across the board for required API documentation to the page load size.

In the file `cases/common/index.ts` I now put the advice of:

```
// Careful of exporting anything from this file as any file(s) you export here will cause your page bundle size to increase.
// If you're using functions/types/etc... internally or within integration tests it's best to import directly from their paths
// than expose the functions/types/etc... here. You should _only_ expose functions/types/etc... that need to be shared with other plugins here.

// When you do have to add things here you might want to consider creating a package such as kbn-cases-constants to share with
// other plugins instead as packages are easier to break down and you do not have to carry the cost of extra plugin weight on
// first download since the other plugins/areas of your code can directly pull from the package in their async imports.
// For example, constants below could eventually be in a "kbn-cases-constants" instead.
// See: https://docs.elastic.dev/kibana-dev-docs/key-concepts/platform-intro#public-plugin-api
```

Some of those that are exposed such as `throwErrors` might actually be small simple mistakes as `security_solution` is using it but it has a "copy" of the same utility within just its server section rather than within its common section. That can be done in a different cleanup PR and cases team can decide what to do moving forward with their API before or post 8.0.0 release.

For the metric increasing of:
| id | [before](f01106c100) | [after](f2e5d6a848) | diff |
| --- | --- | --- | --- |
| `cases` | 16 | 22 | +6 |

Running that suggestion:

```sh
node --max-old-space-size=6096 scripts/build_api_docs --plugin cases --stats exports
```

I see this:
<img width="1851" alt="Screen Shot 2021-12-03 at 9 30 45 AM" src="https://user-images.githubusercontent.com/1151048/144638952-43d50478-ea12-4ce1-8f73-585c735772b4.png">

I don't know if there is a way just yet to mark undocumented public API's but I don't feel concerned with it at the moment and if the case team wants to re-expose those or are going to support API's through documentation they can decide what to do. This PR is more about just removing as much as possible to start with and then go the other direction where the individual teams can decide what to expose and if the download weight is worth it or if it's just `export type` and holds no weight, etc...

* Updated staged files

* Fixed prettier issues
2021-12-06 18:54:44 -07:00
..
mock [RAC] [Cases] All cases table column design updates (#103544) 2021-06-29 13:53:56 -06:00
sub_cases [8.0] [Security Solutions] Removes tech debt of exporting all from linter rule for cases plugin in the common section (#120559) 2021-12-06 18:54:44 -07:00
check_env_variables.sh [Security Solution] [Cases] rename case dir/plugin/context/i18n to cases (#94149) 2021-03-10 08:58:51 -07:00
delete_cases.sh [Security Solution] [Cases] rename case dir/plugin/context/i18n to cases (#94149) 2021-03-10 08:58:51 -07:00
delete_comment.sh [Security Solution] [Cases] rename case dir/plugin/context/i18n to cases (#94149) 2021-03-10 08:58:51 -07:00
find_cases.sh [Security Solution] [Cases] rename case dir/plugin/context/i18n to cases (#94149) 2021-03-10 08:58:51 -07:00
find_cases_by_filter.sh [Security Solution] [Cases] rename case dir/plugin/context/i18n to cases (#94149) 2021-03-10 08:58:51 -07:00
find_cases_sort.sh [Security Solution] [Cases] rename case dir/plugin/context/i18n to cases (#94149) 2021-03-10 08:58:51 -07:00
generate_case_and_comment_data.sh [Security Solution] [Cases] rename case dir/plugin/context/i18n to cases (#94149) 2021-03-10 08:58:51 -07:00
generate_case_data.sh [Security Solution] [Cases] rename case dir/plugin/context/i18n to cases (#94149) 2021-03-10 08:58:51 -07:00
get_case.sh [Security Solution] [Cases] rename case dir/plugin/context/i18n to cases (#94149) 2021-03-10 08:58:51 -07:00
get_case_comments.sh [Security Solution] [Cases] rename case dir/plugin/context/i18n to cases (#94149) 2021-03-10 08:58:51 -07:00
get_comment.sh [Security Solution] [Cases] rename case dir/plugin/context/i18n to cases (#94149) 2021-03-10 08:58:51 -07:00
get_reporters.sh [Security Solution] [Cases] rename case dir/plugin/context/i18n to cases (#94149) 2021-03-10 08:58:51 -07:00
get_status.sh [Security Solution] [Cases] rename case dir/plugin/context/i18n to cases (#94149) 2021-03-10 08:58:51 -07:00
get_tags.sh [Security Solution] [Cases] rename case dir/plugin/context/i18n to cases (#94149) 2021-03-10 08:58:51 -07:00
hard_reset.sh [Security Solution] [Cases] rename case dir/plugin/context/i18n to cases (#94149) 2021-03-10 08:58:51 -07:00
patch_cases.sh [Security Solution] [Cases] rename case dir/plugin/context/i18n to cases (#94149) 2021-03-10 08:58:51 -07:00
patch_comment.sh [Security Solution] [Cases] rename case dir/plugin/context/i18n to cases (#94149) 2021-03-10 08:58:51 -07:00
post_case.sh [Security Solution] [Cases] rename case dir/plugin/context/i18n to cases (#94149) 2021-03-10 08:58:51 -07:00
post_comment.sh [Security Solution] [Cases] rename case dir/plugin/context/i18n to cases (#94149) 2021-03-10 08:58:51 -07:00
README.md [Security Solution] [Cases] rename case dir/plugin/context/i18n to cases (#94149) 2021-03-10 08:58:51 -07:00

README.md for developers working on the Case API on how to get started using the CURL scripts in the scripts folder.

The scripts rely on CURL and jq:

Install curl and jq

brew update
brew install curl
brew install jq

Open $HOME/.zshrc or ${HOME}.bashrc depending on your SHELL output from echo $SHELL and add these environment variables:

export ELASTICSEARCH_USERNAME=${user}
export ELASTICSEARCH_PASSWORD=${password}
export ELASTICSEARCH_URL=https://${ip}:9200
export KIBANA_URL=http://localhost:5601
export TASK_MANAGER_INDEX=.kibana-task-manager-${your user id}
export KIBANA_INDEX=.kibana-${your user id}

source $HOME/.zshrc or ${HOME}.bashrc to ensure variables are set:

source ~/.zshrc

Restart Kibana and ensure that you are using --no-base-path as changing the base path is a feature but will get in the way of the CURL scripts written as is.

Go to the scripts folder cd kibana/x-pack/plugins/cases/server/scripts and run:

./hard_reset.sh

which will:

  • Delete any existing cases you have
  • Delete any existing comments you have
  • Posts the sample case from ./mock/case/post_case.json
  • Posts the sample comment from ./mock/comment/post_comment.json to the new case

Now you can run

./find_cases.sh

You should see the new case created like so:

{
  "page": 1,
  "per_page": 20,
  "total": 1,
  "cases": [
    {
      "id": "2e0afbc0-658c-11ea-85c8-1d8f792cbc08",
      "version": "Wzc5NSwxXQ==",
      "comments": [],
      "comment_ids": [
        "2ecec0f0-658c-11ea-85c8-1d8f792cbc08"
      ],
      "created_at": "2020-03-14T00:38:53.004Z",
      "created_by": {
        "full_name": "Steph Milovic",
        "username": "smilovic"
      },
      "updated_at": null,
      "updated_by": null,
      "description": "This looks not so good",
      "title": "Bad meanie defacing data",
      "status": "open",
      "tags": [
        "defacement"
      ]
    }
  ],
  "count_open_cases": 1,
  "count_closed_cases": 1
}