-
Notifications
You must be signed in to change notification settings - Fork 13k
chore: Adds deprecation warning on livechat:returnAsInquiry with new endpoint replacing it
#36973
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
Conversation
|
Looks like this PR is ready to merge! 🎉 |
🦋 Changeset detectedLatest commit: 1037b2b The changes in this PR will be included in the next version bump. This PR includes changesets to release 42 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughAdds a POST REST endpoint Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant UI as Client UI
participant Hook as useReturnChatToQueueMutation
participant API as POST /v1/livechat/inquiries.returnAsInquiry
participant Handler as Server handler
participant Rooms as LivechatRooms
participant OC as Omnichannel
participant Logic as returnRoomAsInquiry
UI->>Hook: trigger(rid)
Hook->>API: POST { roomId, departmentId? }
API->>Handler: auth + permission (view-l-room)
Handler->>Rooms: findOneById(roomId)
Rooms-->>Handler: room or null
alt room found
Handler->>OC: isWithinMACLimit(room)
OC-->>Handler: allowed / denied
alt allowed
Handler->>Logic: returnRoomAsInquiry(room, departmentId?)
Logic-->>Handler: result (boolean)
Handler-->>API: 200 { success:true, result }
API-->>Hook: success
Hook-->>UI: invalidate caches / update UI
else MAC limit exceeded
Handler-->>API: 400 { success:false, error:"error-mac-limit-reached" }
API-->>Hook: error
end
else room not found
Handler-->>API: 400 { success:false, error:"error-room-not-found" }
API-->>Hook: error
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests
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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #36973 +/- ##
===========================================
- Coverage 67.38% 66.36% -1.03%
===========================================
Files 3328 3382 +54
Lines 113342 115594 +2252
Branches 20562 21203 +641
===========================================
+ Hits 76375 76713 +338
- Misses 34363 36274 +1911
- Partials 2604 2607 +3
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
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
🧹 Nitpick comments (5)
packages/rest-typings/src/v1/omnichannel.ts (1)
3392-3433: Schema/validators added—align naming and TS type with existing conventions.
- Naming: most validators use the
is*prefix (e.g.,isPOSTLivechatRoomsCloseAllSuccessResponse). Consider renaming the success validator for consistency.- Typing: include
success: truein the compile generic for better TS accuracy.Proposed tweak:
- export const POSTLivechatInquiriesReturnAsInquirySuccessResponse = ajv.compile<{ result: boolean }>( + export const isPOSTLivechatInquiriesReturnAsInquirySuccessResponse = ajv.compile<{ result: boolean; success: true }>( POSTLivechatInquiriesReturnAsInquirySuccessResponseSchema, );apps/meteor/client/views/room/HeaderV2/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts (1)
11-18: Return the boolean result so UIs can react (optional).Endpoint returns
{ result: boolean }. Exposing it lets consumers notify when nothing was returned to queue (result=false).-export const useReturnChatToQueueMutation = ( - options?: Omit<UseMutationOptions<void, Error, IRoom['_id']>, 'mutationFn'>, -): UseMutationResult<void, Error, IRoom['_id']> => { +export const useReturnChatToQueueMutation = ( + options?: Omit<UseMutationOptions<boolean, Error, IRoom['_id']>, 'mutationFn'>, +): UseMutationResult<boolean, Error, IRoom['_id']> => { const returnChatToQueue = useEndpoint('POST', '/v1/livechat/inquiries.returnAsInquiry'); … return useMutation({ mutationFn: async (rid) => { - await returnChatToQueue({ roomId: rid }); + const { result } = await returnChatToQueue({ roomId: rid }); + return result; },apps/meteor/client/views/room/Header/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts (1)
11-18: Mirror V2: surface the booleanresult(optional).Same rationale as V2 hook—bubble up the outcome for UX feedback.
- options?: Omit<UseMutationOptions<void, Error, IRoom['_id']>, 'mutationFn'>, -): UseMutationResult<void, Error, IRoom['_id']> => { + options?: Omit<UseMutationOptions<boolean, Error, IRoom['_id']>, 'mutationFn'>, +): UseMutationResult<boolean, Error, IRoom['_id']> => { … - await returnChatToQueue({ roomId: rid }); + const { result } = await returnChatToQueue({ roomId: rid }); + return result;apps/meteor/tests/end-to-end/api/livechat/05-inquiries.ts (1)
327-437: Good migration to REST; consider adding a couple of edge-case assertions.
- Add tests for MAC limit and on-hold rooms to cover the explicit failure branches (
mac-limit-reached,error-room-onHoldvia service).- Optional: also assert that the endpoint preserves HTTP 400 with those error keys.
I can draft these tests if helpful.
apps/meteor/app/livechat/imports/server/rest/inquiries.ts (1)
13-14: Validator import name consistency (if you adopt the rename).Update the imported success validator to
isPOSTLivechatInquiriesReturnAsInquirySuccessResponsefor consistency with other routes.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (6)
apps/meteor/app/livechat/imports/server/rest/inquiries.ts(2 hunks)apps/meteor/app/livechat/server/methods/returnAsInquiry.ts(2 hunks)apps/meteor/client/views/room/Header/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts(2 hunks)apps/meteor/client/views/room/HeaderV2/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts(2 hunks)apps/meteor/tests/end-to-end/api/livechat/05-inquiries.ts(7 hunks)packages/rest-typings/src/v1/omnichannel.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (5)
apps/meteor/tests/end-to-end/api/livechat/05-inquiries.ts (1)
apps/meteor/tests/data/api-data.ts (1)
credentials(39-42)
apps/meteor/client/views/room/HeaderV2/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts (1)
packages/ui-contexts/src/index.ts (1)
useEndpoint(32-32)
apps/meteor/app/livechat/imports/server/rest/inquiries.ts (7)
packages/rest-typings/src/v1/omnichannel.ts (2)
POSTLivechatInquiriesReturnAsInquirySuccessResponse(3430-3432)isPOSTLivechatInquiriesReturnAsInquiry(3412-3414)packages/rest-typings/src/v1/Ajv.ts (3)
validateBadRequestErrorResponse(46-46)validateUnauthorizedErrorResponse(69-69)validateForbiddenErrorResponse(92-92)packages/models/src/index.ts (1)
LivechatRooms(175-175)packages/core-services/src/index.ts (1)
Omnichannel(181-181)apps/meteor/app/livechat/server/lib/rooms.ts (1)
returnRoomAsInquiry(211-255)apps/meteor/app/api/server/ApiClass.ts (1)
ExtractRoutesFromAPI(73-77)packages/rest-typings/src/index.ts (1)
Endpoints(52-100)
apps/meteor/client/views/room/Header/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts (1)
packages/ui-contexts/src/index.ts (1)
useEndpoint(32-32)
packages/rest-typings/src/v1/omnichannel.ts (1)
packages/rest-typings/src/v1/Ajv.ts (1)
ajv(23-23)
🔇 Additional comments (2)
apps/meteor/app/livechat/server/methods/returnAsInquiry.ts (1)
8-8: Deprecation notice looks good—please confirm version and path.The logger call correctly points callers to the new REST endpoint. Double‑check that the deprecation version '8.0.0' aligns with your public deprecation policy and that the endpoint path is final.
Also applies to: 20-21
apps/meteor/tests/end-to-end/api/livechat/05-inquiries.ts (1)
515-519: Nice check on inquiry lastMessage after return.This verifies the queue UI stays accurate post-return. LGTM.
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: 2
🧹 Nitpick comments (12)
.changeset/calm-hounds-look.md (1)
6-6: Clarify replacement path and add removal timeline.Recommend referencing the full REST path with version prefix and stating the deprecation/removal plan to guide integrators.
Proposed wording tweak:
- “Adds deprecation warning for Meteor method livechat:returnAsInquiry. Use REST endpoint /v1/livechat/inquiries.returnAsInquiry instead. Deprecated in 8.0.0; planned removal in next major.”
apps/meteor/client/views/room/HeaderV2/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts (1)
11-18: Switch to REST endpoint looks good; consider surfacing the boolean result.Calling POST /v1/livechat/inquiries.returnAsInquiry with { roomId } is correct. Today the hook discards the endpoint’s { result: boolean }; if useful for UX (e.g., “no one serving” returns false), consider returning/forwarding it without changing the external signature (e.g., keep void but optionally let callers pass an onSuccess that inspects the response).
Also ensure the REST typings map includes this path (see comment on packages/rest-typings: add '/v1/livechat/inquiries.returnAsInquiry' to OmnichannelEndpoints).
apps/meteor/app/livechat/server/methods/returnAsInquiry.ts (1)
20-20: Deprecation logger placement is correct; align parameter naming for consistency.Positional args work, but the declared method type uses departmentID while the impl uses departmentId. Consider aligning to departmentId across types for consistency with REST.
Suggested type tweak (outside this hunk):
interface ServerMethods { 'livechat:returnAsInquiry'(rid: IRoom['_id'], departmentId?: ILivechatDepartment['_id']): boolean; }apps/meteor/client/views/room/Header/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts (1)
11-18: LGTM; keep both hook variants consistent and consider a shared constant for the path.Both Header and HeaderV2 now hit the same endpoint with the same payload—great. To avoid drift, consider a small constants module for '/v1/livechat/inquiries.returnAsInquiry'.
As above, verify the REST typings expose this path to preserve type safety.
packages/rest-typings/src/v1/omnichannel.ts (1)
3430-3432: Nit: align validator export naming with existing “is…” convention.Many validators use the is* prefix (e.g., isPOSTLivechatRoomsCloseAllSuccessResponse). Consider renaming to isPOSTLivechatInquiriesReturnAsInquirySuccessResponse for consistency. Non‑blocking.
-export const POSTLivechatInquiriesReturnAsInquirySuccessResponse = ajv.compile<{ result: boolean }>( +export const isPOSTLivechatInquiriesReturnAsInquirySuccessResponse = ajv.compile<{ result: boolean }>( POSTLivechatInquiriesReturnAsInquirySuccessResponseSchema, );apps/meteor/tests/end-to-end/api/livechat/05-inquiries.ts (2)
347-355: Avoid brittle assertion on full error message string.Asserting the exact i18n’d message can be flaky. Prefer checking status (403), success === false, and that error contains 'error-unauthorized'.
- expect(body.error).to.have.equal('User does not have the permissions required for this action [error-unauthorized]'); + expect(body).to.have.property('success', false); + expect(String(body.error)).to.include('error-unauthorized');
372-380: Minor: avoid relying on 'GENERAL' channel existence.In some environments 'GENERAL' may be renamed/absent. Consider creating a temp non‑livechat room for this check.
apps/meteor/app/livechat/imports/server/rest/inquiries.ts (5)
145-147: Use 403 for MAC/plan policy denial.Returning 400 for MAC limit muddies semantics. Prefer Forbidden (policy) to distinguish from client input errors.
- if (!(await Omnichannel.isWithinMACLimit(room))) { - return API.v1.failure('mac-limit-reached'); - } + if (!(await Omnichannel.isWithinMACLimit(room))) { + return API.v1.forbidden(); + }
134-135: Validate departmentId if provided.If departmentId is present, ensure it exists; otherwise callers get a “successful” 200 with later failures/side-effects.
const { roomId, departmentId } = this.bodyParams; + if (departmentId) { + const dep = await LivechatDepartment.findOneById(departmentId, { projection: { _id: 1 } }); + if (!dep) { + return API.v1.failure('invalid-department'); + } + }
149-152: Return deterministic errors instead of { result: false }.False conflates “no inquiry”, “already unassigned”, etc. Prefer explicit error for client handling.
- const result = await returnRoomAsInquiry(room, departmentId); - - return API.v1.success({ result }); + const result = await returnRoomAsInquiry(room, departmentId); + if (!result) { + return API.v1.failure('inquiry-not-found-or-already-unassigned'); + } + return API.v1.success({ result: true });
120-132: Align declared response schemas with actual error paths.returnRoomAsInquiry can throw (e.g., error-room-onHold, error-returning-inquiry). Ensure these map to 400/403/401 or declare 5xx in response, or catch and translate.
Would you like a patch that wraps returnRoomAsInquiry with try/catch and maps known Meteor.Error codes to the declared responses?
Also applies to: 149-152
155-160: Type augmentation placement: avoid duplicate interface merging.Placing the Endpoints augmentation here risks multiple merges if this file is imported in different server bundles. Consider centralizing augmentations (e.g., a single rest-typings augmentation module).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (7)
.changeset/calm-hounds-look.md(1 hunks)apps/meteor/app/livechat/imports/server/rest/inquiries.ts(2 hunks)apps/meteor/app/livechat/server/methods/returnAsInquiry.ts(2 hunks)apps/meteor/client/views/room/Header/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts(2 hunks)apps/meteor/client/views/room/HeaderV2/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts(2 hunks)apps/meteor/tests/end-to-end/api/livechat/05-inquiries.ts(7 hunks)packages/rest-typings/src/v1/omnichannel.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (5)
apps/meteor/client/views/room/Header/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts (1)
packages/ui-contexts/src/index.ts (1)
useEndpoint(32-32)
apps/meteor/client/views/room/HeaderV2/Omnichannel/QuickActions/hooks/useReturnChatToQueueMutation.ts (1)
packages/ui-contexts/src/index.ts (1)
useEndpoint(32-32)
apps/meteor/app/livechat/imports/server/rest/inquiries.ts (7)
packages/rest-typings/src/v1/omnichannel.ts (2)
POSTLivechatInquiriesReturnAsInquirySuccessResponse(3430-3432)isPOSTLivechatInquiriesReturnAsInquiry(3412-3414)packages/rest-typings/src/v1/Ajv.ts (3)
validateBadRequestErrorResponse(46-46)validateUnauthorizedErrorResponse(69-69)validateForbiddenErrorResponse(92-92)packages/models/src/index.ts (1)
LivechatRooms(175-175)packages/core-services/src/index.ts (1)
Omnichannel(181-181)apps/meteor/app/livechat/server/lib/rooms.ts (1)
returnRoomAsInquiry(211-255)apps/meteor/app/api/server/ApiClass.ts (1)
ExtractRoutesFromAPI(73-77)packages/rest-typings/src/index.ts (1)
Endpoints(52-100)
packages/rest-typings/src/v1/omnichannel.ts (1)
packages/rest-typings/src/v1/Ajv.ts (1)
ajv(23-23)
apps/meteor/tests/end-to-end/api/livechat/05-inquiries.ts (1)
apps/meteor/tests/data/api-data.ts (1)
credentials(39-42)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: 📦 Meteor Build - coverage
- GitHub Check: CodeQL-Build
🔇 Additional comments (8)
apps/meteor/app/livechat/server/methods/returnAsInquiry.ts (1)
8-8: Import LGTM.Deprecation logger import path and usage match existing patterns.
apps/meteor/tests/end-to-end/api/livechat/05-inquiries.ts (6)
7-7: Import update LGTM.Using shared credentials import is consistent with other suites.
22-22: Sleep utility import LGTM.
359-369: Invalid room case assertions LGTM.Status 400 with error 'invalid-room' matches the new endpoint contract.
406-415: “No one serving” path LGTM.Asserting 200 with { success: true, result: false } matches the intended semantics.
429-437: Happy path LGTM.Checks for { success: true, result: true } after returning to queue are appropriate.
516-519: Message-updated flow LGTM.Endpoint call integrated into the existing “keep inquiry last message updated” test without changing semantics.
apps/meteor/app/livechat/imports/server/rest/inquiries.ts (1)
1-14: Imports/typings look consistent.New imports (LivechatRooms, Omnichannel, validators, ExtractRoutesFromAPI) align with usage.
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: 0
♻️ Duplicate comments (3)
apps/meteor/app/livechat/imports/server/rest/inquiries.ts (3)
152-159: Harden Meteor error mapping.Use
error.error || error.reason || error.messageto avoid empty messages whenreasonisn’t set.- } catch (error) { - if (error instanceof Meteor.Error) { - return API.v1.failure(error.reason); - } - - return API.v1.failure('error-returning-inquiry'); - } + } catch (error) { + if (error instanceof Meteor.Error) { + const reason = (error as any).error || (error as any).reason || (error as any).message; + return API.v1.failure(reason); + } + return API.v1.failure('error-returning-inquiry'); + }
153-159: Fix: Missing Meteor import (breaks error handling).
Meteor.Erroris referenced butMeteorisn’t imported; this will crash the endpoint on error paths.+import { Meteor } from 'meteor/meteor';Also applies to: 1-4
141-147: Authorize who can return a room to the queue (assignee or manager only).Any agent with
view-l-roomcan return another agent’s chat; restrict to current assignee or privileged users.+import { hasPermissionAsync } from '../../../../authorization/server/functions/hasPermission'; @@ if (!room.open) { return API.v1.failure('room-closed'); } + const isAssignee = room.servedBy?._id === this.userId; + const canManageQueue = await hasPermissionAsync(this.userId, 'view-livechat-manager'); + if (!isAssignee && !canManageQueue) { + return API.v1.forbidden(); + } + if (!(await Omnichannel.isWithinMACLimit(room))) { return API.v1.failure('mac-limit-reached'); }
🧹 Nitpick comments (1)
apps/meteor/app/livechat/imports/server/rest/inquiries.ts (1)
134-139: Validate departmentId when provided.Early-check the department to fail fast with a clear 400, avoiding generic backend errors.
const { roomId, departmentId } = this.bodyParams; + if (departmentId) { + const dep = await LivechatDepartment.findOneById(departmentId, { projection: { _id: 1 } }); + if (!dep) { + return API.v1.failure('invalid-department'); + } + } + const room = await LivechatRooms.findOneById(roomId); if (!room || room.t !== 'l') { return API.v1.failure('invalid-room'); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
apps/meteor/app/livechat/imports/server/rest/inquiries.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/meteor/app/livechat/imports/server/rest/inquiries.ts (6)
packages/rest-typings/src/v1/omnichannel.ts (2)
POSTLivechatInquiriesReturnAsInquirySuccessResponse(3430-3432)isPOSTLivechatInquiriesReturnAsInquiry(3412-3414)packages/rest-typings/src/v1/Ajv.ts (3)
validateBadRequestErrorResponse(46-46)validateUnauthorizedErrorResponse(69-69)validateForbiddenErrorResponse(92-92)packages/models/src/index.ts (1)
LivechatRooms(175-175)packages/core-services/src/index.ts (1)
Omnichannel(181-181)apps/meteor/app/livechat/server/lib/rooms.ts (1)
returnRoomAsInquiry(211-255)apps/meteor/app/api/server/ApiClass.ts (1)
ExtractRoutesFromAPI(73-77)
dougfabris
left a comment
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.
On behalf of frontend, LGTM!
0a255f7
…w endpoint replacing it (#36973)
…w endpoint replacing it (#36973)
…w endpoint replacing it (#36973)
…w endpoint replacing it (#36973)
…w endpoint replacing it (#36973)
…w endpoint replacing it (#36973)
…w endpoint replacing it (#36973)
Proposed changes (including videos or screenshots)
This PR adds a deprecation warning for livechat:returnAsInquiry meteor method, as well as it adds an endpoint (livechat/inquiries.returnAsInquiry) to replace it.
Issue(s)
CTZ-61
Steps to test or reproduce
Further comments
Summary by CodeRabbit
New Features
Deprecations
Refactor
Tests
Bug Fixes
Chores