-
Notifications
You must be signed in to change notification settings - Fork 13k
chore: api http router improvements #38227
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
base: develop
Are you sure you want to change the base?
Conversation
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
|
WalkthroughCentralizes request parsing into Router, makes payload extraction asynchronous and request-centric, integrates password redaction in logging, removes runtime Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Router
participant LoggerMiddleware as Logger
participant PayloadSvc as getRestPayload
participant Handler
Client->>Router: HTTP request
Router->>Router: async parse query + body → c.set('queryParams','bodyParams')
Router->>Logger: invoke logger middleware
Logger->>PayloadSvc: await getRestPayload(request)
PayloadSvc-->>Logger: payload | "{ payload: '[multipart/form-data]' }" | null
Logger->>Handler: call handler (context includes body/query and logs with redacted payload)
Handler-->>Client: response
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
12a4f8f to
b1b33d3
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #38227 +/- ##
===========================================
+ Coverage 70.73% 70.84% +0.10%
===========================================
Files 3158 3159 +1
Lines 109359 109383 +24
Branches 19695 19703 +8
===========================================
+ Hits 77358 77489 +131
+ Misses 29966 29869 -97
+ Partials 2035 2025 -10
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
packages/http-router/src/Router.ts
Outdated
| if (options.query) { | ||
| const validatorFn = options.query; | ||
| if (typeof options.query === 'function' && !validatorFn(queryParams)) { | ||
| if (typeof options.query === 'function' && !validatorFn(structuredClone(queryParams))) { |
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.
validatorFn mutates its input, which causes some weird behaviors that break tests. Cloning the input "solves" the issues, but defeats the purpose of removing the second calls to parseBodyParams and parseQueryParams.
I think it is valuable to actually take a look at the breaking tests and make the system adapt to the mutatons that happen in those validatorFn calls
dd78dad to
536fd45
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
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.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/rest-typings/src/v1/omnichannel.ts (1)
4502-4505: Type guard does not match schema nullability forcustomFieldId.The schema defines
customFieldIdwithnullable: trueand norequiredarray (making it optional), but the type guard narrows tocustomFieldId: string. After validation,customFieldIdcould benullor omitted (undefined), violating the type guard. Align the generic type tocustomFieldId?: string | nullto match the schema.Suggested fix
export const isPOSTLivechatSaveCustomFieldsParams = ajv.compile<{ - customFieldId: string; + customFieldId?: string | null; customFieldData: Omit<ILivechatCustomField, '_id' | '_updatedAt'> & { field: string }; }>(POSTLivechatSaveCustomFieldsSchema);
🤖 Fix all issues with AI agents
In `@packages/rest-typings/src/v1/omnichannel.ts`:
- Around line 4446-4457: Update the regex character classes to move the hyphen
to the end so they read `[0-9a-zA-Z_-]` for both customFieldId and
customFieldData.field to avoid creating an unintended range; also reconcile the
nullable mismatch by either removing `nullable: true` from the `customFieldId`
schema or updating the type guard that references `customFieldId` (the check
near the type guard around line ~4502) to accept `string | null` so schema and
runtime types match.
🧹 Nitpick comments (1)
packages/http-router/src/Router.ts (1)
157-175: AlignbodyParamstyping with possible JSON shapes.
request.raw.clone().json()can return arrays or primitives, but the context types areRecord<string, unknown>. Consider normalizing non‑object bodies to{}or widening the type so downstream code doesn’t rely on an incorrect shape.
536fd45 to
2186968
Compare
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 issues found across 9 files
|
While reviewing the Created CORE-1741 to track this separately. |
|
@ricardogarim are they really broken? I've found this test to validate it (should) be working: Rocket.Chat/apps/meteor/tests/end-to-end/api/incoming-integrations.ts Lines 343 to 366 in 0580cfc
|
|
@d-gubert maybe the Livechat changes could be in another PR? they look like regular changes not necessarily related to "api http router improments" |
We need to modify that endpoint, otherwise tests fail because of this #38227 (comment) I can make a much more contrived change just to make sure the tests are passing, then open a new PR with the appropriate changes to schemas and all. But the endpoint can't go unscathed 😛 |
|
Forgot to mention @sampaiodiego #38227 (comment) 😬 |
2186968 to
5ffad11
Compare
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.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/models/src/models/LivechatCustomField.ts (1)
52-75: Return value missing_idin update path.When updating an existing record (
_idis truthy), the returnedrecordobject lacks the_idproperty, which violates theILivechatCustomFieldreturn type. The insert path correctly assignsrecord._id = field, but the update path does not preserve the ID on the returned object.🐛 Proposed fix
async createOrUpdateCustomField( _id: string | null, field: string, label: ILivechatCustomField['label'], scope: ILivechatCustomField['scope'], visibility: ILivechatCustomField['visibility'], extraData: any, ) { const record = { label, scope, visibility, ...extraData, }; if (_id) { await this.updateOne({ _id }, { $set: record }); + record._id = _id; } else { record._id = field; await this.insertOne(record); } return record; }
🤖 Fix all issues with AI agents
In `@apps/meteor/app/api/server/router.ts`:
- Around line 44-49: The APIActionContext construction should defensively
default potentially-undefined context entries; update the code that builds
APIActionContext (the object with requestIp, urlParams, queryParams, bodyParams,
request) to use c.get('bodyParams') ?? {} and c.get('queryParams') ?? {} so
bodyParams and queryParams are always objects even if c.get(...) returns
undefined, keeping the existing fields (e.g., requestIp: c.get('remoteAddress')
and urlParams: req.param()) unchanged.
3ad9b41 to
5ffad11
Compare
Proposed changes (including videos or screenshots)
parseBodyParamsandparseQueryParamsinRocketChatAPIRouterpasswordfield when logging requestsIssue(s)
Steps to test or reproduce
Further comments
Summary by CodeRabbit
Security & Privacy
Bug Fixes & Improvements
✏️ Tip: You can customize this high-level summary in your review settings.