-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Cases] Remove fields
param from the bulk get cases internal API
#156366
Conversation
fields
param from the bulk get cases internal API
Pinging @elastic/response-ops (Team:ResponseOps) |
Pinging @elastic/response-ops-cases (Feature:Cases) |
fields?: string[] | ||
) => { | ||
export const decodeCasesBulkGetResponse = (res: CasesBulkGetResponse) => { | ||
const fields = Object.keys(CasesBulkGetResponseFieldsRt.props); | ||
const typeToDecode = getTypeForCertainFieldsFromArray(CasesRt, fields); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think something like rt.array(CasesBulkGetResponseFieldsRt).decode(res.cases)
might work here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point!
@@ -68,7 +61,7 @@ describe('api', () => { | |||
}); | |||
|
|||
it('should have been called with the correct path', async () => { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
,"fields":["title"]
This test still passes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They shouldn't 🙂. I missed that.
alerts: 0, | ||
userComments: 0, | ||
}; | ||
|
||
const flattenedCase = flattenCaseSavedObject({ | ||
savedObject: theCase, | ||
totalComment: userComments, | ||
totalAlerts: alerts, | ||
}); | ||
|
||
if (!fields?.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this? fields
is always defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you are right.
x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_get_cases.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't CasesBulkGetResponseFieldsRt
attribute types need to be verified with excess
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work 👍
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct! Before it was not possible because I was constructing the type dynamically.
const typeToEncode = getTypeForCertainFieldsFromArray(CasesRt, fields); | ||
const casesToReturn = typeToEncode.encode(flattenedCases); | ||
|
||
const casesToReturn = CasesBulkGetResponseRt.props.cases.encode(flattenedCases); | ||
const errors = constructErrors(soBulkGetErrors, unauthorizedCases); | ||
|
||
return { cases: casesToReturn, errors }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we encode the entire response?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again correct!
💚 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
fields
parameter 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