[Cases] Remove fields param from the bulk get cases internal API#156366
[Cases] Remove fields param from the bulk get cases internal API#156366cnasikas merged 8 commits intoelastic:mainfrom
fields param from the bulk get cases internal API#156366Conversation
fields param from the bulk get cases internal API
|
Pinging @elastic/response-ops (Team:ResponseOps) |
|
Pinging @elastic/response-ops-cases (Feature:Cases) |
| ) => { | ||
| export const decodeCasesBulkGetResponse = (res: CasesBulkGetResponse) => { | ||
| const fields = Object.keys(CasesBulkGetResponseFieldsRt.props); | ||
| const typeToDecode = getTypeForCertainFieldsFromArray(CasesRt, fields); |
There was a problem hiding this comment.
This feels a bit overly complicated. If we always return the same fields and we already have their types we don't need to generate fields and then create typeToDecode we might as well store that in a const and do away with the extra logic.
There was a problem hiding this comment.
I think something like rt.array(CasesBulkGetResponseFieldsRt).decode(res.cases) might work here.
| await bulkGetCases({ http, params: { ids: ['test'], fields: ['title'] } }); | ||
| await bulkGetCases({ http, params: { ids: ['test'] } }); | ||
| expect(http.post).toHaveBeenCalledWith('/internal/cases/_bulk_get', { | ||
| body: '{"ids":["test"],"fields":["title"]}', |
There was a problem hiding this comment.
,"fields":["title"] This test still passes?
There was a problem hiding this comment.
They shouldn't 🙂. I missed that.
| totalAlerts: alerts, | ||
| }); | ||
|
|
||
| if (!fields?.length) { |
There was a problem hiding this comment.
Do we still need this? fields is always defined.
x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_get_cases.ts
Show resolved
Hide resolved
js-jankisalvi
left a comment
There was a problem hiding this comment.
looks good 👍 one minor question.
| pipe(typeToDecode.decode(res.cases), fold(throwErrors(createToasterPlainError), identity)); | ||
| export const decodeCasesBulkGetResponse = (res: CasesBulkGetResponse) => { | ||
| pipe( | ||
| CasesBulkGetResponseFieldsRt.decode(res.cases), |
There was a problem hiding this comment.
Doesn't CasesBulkGetResponseFieldsRt attribute types need to be verified with excess?
There was a problem hiding this comment.
This is a good question. We only care about excess parameters coming from external requests to our APIs. For responses, it is ok to not check about them. In the serverless world, we should use strict and remove any fields we do not recognize.
| pipe(typeToDecode.decode(res.cases), fold(throwErrors(createToasterPlainError), identity)); | ||
| export const decodeCasesBulkGetResponse = (res: CasesBulkGetResponse) => { | ||
| pipe( | ||
| CasesBulkGetResponseRt.props.cases.decode(res.cases), |
There was a problem hiding this comment.
Do we want to use the entire CasesBulkGetResponseRt for this? We probably want to know if the errors are formatted correctly right?
There was a problem hiding this comment.
Correct! Before it was not possible because I was constructing the type dynamically.
| const casesToReturn = CasesBulkGetResponseRt.props.cases.encode(flattenedCases); | ||
| const errors = constructErrors(soBulkGetErrors, unauthorizedCases); | ||
|
|
||
| return { cases: casesToReturn, errors }; |
There was a problem hiding this comment.
Should we encode the entire response?
💚 Build Succeeded
Metrics [docs]Async chunks
Page load bundle
Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @cnasikas |
Summary
This PR removes the
fieldsparameter from the bulk get cases internal API. It also returns a subset of the cases attributes.Fixes: #156364
Checklist
Delete any items that are not applicable to this PR.
For maintainers