Skip to content

refactor: migrate rooms.nameExists to new route pattern#39309

Closed
Rohitgiri02 wants to merge 4 commits intoRocketChat:developfrom
Rohitgiri02:migrate/rooms-nameexists
Closed

refactor: migrate rooms.nameExists to new route pattern#39309
Rohitgiri02 wants to merge 4 commits intoRocketChat:developfrom
Rohitgiri02:migrate/rooms-nameexists

Conversation

@Rohitgiri02
Copy link
Copy Markdown
Contributor

@Rohitgiri02 Rohitgiri02 commented Mar 3, 2026


Proposed Changes

  • Migrated /v1/rooms.nameExists from the legacy API.v1.addRoute() pattern to
    the new chained .get() pattern on roomEndpoints with full AJV request/response
    validation.
  • Removed the manual /v1/rooms.nameExists definition (GETRoomsNameExists,
    GETRoomsNameExistsSchema, isGETRoomsNameExists) from
    @rocket.chat/rest-typings.
  • Updated the existing end-to-end test for rooms.nameExists to align with the
    new route validation behavior.

Why

The Migration

The codebase is migrating away from manually defining REST endpoint types in
@rocket.chat/rest-typings toward automatically extracting them from the API
implementation using ExtractRoutesFromAPI + module augmentation:

// apps/meteor/app/api/server/v1/rooms.ts
type RoomEndpoints = ExtractRoutesFromAPI<typeof roomEndpoints>;

declare module '@rocket.chat/rest-typings' {
  interface Endpoints extends RoomEndpoints {}
}

Benefits:

  • Types are co-located with their implementation — no duplication.
  • Adds proper AJV request query schema + 200/400/401 response validation.
  • Stricter return types.
  • OpenAPI spec is automatically generated from the implementation.

The Test Fix

After migrating to the new chained .get() pattern, the HTTP router layer
validates query params before the auth middleware runs. The old
API.v1.addRoute() + validateParams checked auth first, then params.

This means the unauthenticated test case:

it('should return 401 unauthorized when user is not logged in')

previously sent a request with no roomName param, which was fine because auth
was checked first. With the new pattern, the missing roomName param is caught
first by AJV validation, returning 400 Bad Request before auth is even checked.

Fix: Pass a valid roomName query param in the unauthenticated test. The
router then passes validation and reaches the auth check, which correctly returns
401 Unauthorized.


Test Results

Screenshot 2026-03-03 174333

Summary by CodeRabbit

  • New Features

    • Added an authenticated GET endpoint to check whether a room name exists; returns { exists: boolean }.
  • Bug Fixes

    • Improved query validation and consistent 200/400/401 responses for the name-check endpoint.
  • Refactor

    • Integrated the name-check route into the consolidated room endpoints (authenticated).
  • Tests

    • Updated end-to-end test to include the roomName query parameter for the name-check endpoint.

@Rohitgiri02 Rohitgiri02 requested review from a team as code owners March 3, 2026 19:30
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot bot commented Mar 3, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 3, 2026

⚠️ No Changeset found

Latest commit: bfebb00

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e14bdf68-a740-4449-82ec-66f864d08ca9

📥 Commits

Reviewing files that changed from the base of the PR and between a145b65 and bfebb00.

📒 Files selected for processing (1)
  • apps/meteor/app/api/server/v1/rooms.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/app/api/server/v1/rooms.ts

Walkthrough

Added a GET rooms.nameExists route into the consolidated roomEndpoints (with auth and AJV query/response validation), removed the legacy standalone route and matching REST-typings, and updated an end-to-end test to include the roomName query for the unauthorized rooms.nameExists request.

Changes

Cohort / File(s) Summary
Endpoint Implementation
apps/meteor/app/api/server/v1/rooms.ts
Removed standalone API.v1.addRoute('rooms.nameExists', ...); inlined GET rooms.nameExists into roomEndpoints with authRequired: true, AJV query schema (roomName: string, no extra props), explicit 200/400/401 responses, handler using Rooms.findOneByName(...){ projection: { _id: 1 } } and returning { success: true, exists: boolean }; updated exported RoomEndpoints type to include the new route.
Public typings
packages/rest-typings/src/v1/rooms.ts
Deleted GETRoomsNameExists type, GETRoomsNameExistsSchema, exported validator isGETRoomsNameExists, and removed the /v1/rooms.nameExists GET entry from RoomsEndpoints.
End-to-End Tests
apps/meteor/tests/end-to-end/api/rooms.ts
Modified unauthorized test for rooms.nameExists to include ?roomName=test query parameter in the request.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

type: chore

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor: migrate rooms.nameExists to new route pattern' directly and accurately describes the main objective of the changeset—migrating the rooms.nameExists endpoint from legacy API.v1.addRoute() to the new chained .get() pattern with AJV validation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

Migrating from UI to YAML configuration.

Use the @coderabbitai configuration command in a PR comment to get a dump of all your UI settings in YAML format. You can then edit this YAML file and upload it to the root of your repository to configure CodeRabbit programmatically.

@Rohitgiri02 Rohitgiri02 changed the title refractor: migrate rooms.nameExists to new route pattern and fix dependent packages refactor: migrate rooms.nameExists to new route pattern and fix dependent packages Mar 3, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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 3 files

@Rohitgiri02 Rohitgiri02 changed the title refactor: migrate rooms.nameExists to new route pattern and fix dependent packages refactor: migrate rooms.nameExists to new route pattern Mar 3, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/meteor/app/api/server/v1/rooms.ts (1)

1253-1256: ⚠️ Potential issue | 🟡 Minor

Duplicate type extraction.

ExtractRoutesFromAPI<typeof roomEndpoints> appears twice (lines 1253 and 1254). This is redundant and likely a copy-paste oversight.

Proposed fix
-type RoomEndpoints = ExtractRoutesFromAPI<typeof roomEndpoints> &
-	ExtractRoutesFromAPI<typeof roomEndpoints> &
+type RoomEndpoints = ExtractRoutesFromAPI<typeof roomEndpoints> &
 	ExtractRoutesFromAPI<typeof roomDeleteEndpoint> &
 	ExtractRoutesFromAPI<typeof roomsSaveNotificationEndpoint>;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/app/api/server/v1/rooms.ts` around lines 1253 - 1256,
RoomEndpoints currently includes ExtractRoutesFromAPI<typeof roomEndpoints>
twice; remove the duplicate occurrence so RoomEndpoints is composed only once
from roomEndpoints plus the other endpoints (roomDeleteEndpoint,
roomsSaveNotificationEndpoint) using ExtractRoutesFromAPI to avoid redundancy
and keep the same union of types.
🧹 Nitpick comments (1)
apps/meteor/app/api/server/v1/rooms.ts (1)

1013-1045: Clean migration to the new route pattern.

The endpoint correctly implements AJV query/response validation with efficient projection. One optional improvement: consider adding minLength: 1 to the roomName schema (similar to line 297) to reject empty strings at validation time rather than returning exists: false for semantically invalid input.

,

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/app/api/server/v1/rooms.ts` around lines 1013 - 1045, The
rooms.nameExists route's query schema allows empty roomName strings; update the
AJV query schema for the 'rooms.nameExists' GET route (the ajv.compile<{
roomName: string }> block) to include "minLength: 1" on the roomName property so
empty strings are rejected at validation time (mirroring the earlier route
pattern) and the handler (action) will only be invoked for non-empty names.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@apps/meteor/app/api/server/v1/rooms.ts`:
- Around line 1253-1256: RoomEndpoints currently includes
ExtractRoutesFromAPI<typeof roomEndpoints> twice; remove the duplicate
occurrence so RoomEndpoints is composed only once from roomEndpoints plus the
other endpoints (roomDeleteEndpoint, roomsSaveNotificationEndpoint) using
ExtractRoutesFromAPI to avoid redundancy and keep the same union of types.

---

Nitpick comments:
In `@apps/meteor/app/api/server/v1/rooms.ts`:
- Around line 1013-1045: The rooms.nameExists route's query schema allows empty
roomName strings; update the AJV query schema for the 'rooms.nameExists' GET
route (the ajv.compile<{ roomName: string }> block) to include "minLength: 1" on
the roomName property so empty strings are rejected at validation time
(mirroring the earlier route pattern) and the handler (action) will only be
invoked for non-empty names.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c0f4f59 and a145b65.

📒 Files selected for processing (2)
  • apps/meteor/app/api/server/v1/rooms.ts
  • packages/rest-typings/src/v1/rooms.ts
💤 Files with no reviewable changes (1)
  • packages/rest-typings/src/v1/rooms.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/app/api/server/v1/rooms.ts
🧠 Learnings (10)
📓 Common learnings
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 35995
File: apps/meteor/app/api/server/v1/rooms.ts:1107-1112
Timestamp: 2026-02-23T17:53:18.785Z
Learning: In Rocket.Chat PR reviews, maintain strict scope boundaries—when a PR is focused on a specific endpoint (e.g., rooms.favorite), avoid reviewing or suggesting changes to other endpoints that were incidentally refactored (e.g., rooms.invite) unless explicitly requested by maintainers.
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:09.561Z
Learning: In RocketChat/Rocket.Chat OpenAPI migration PRs for apps/meteor/app/api/server/v1 endpoints, maintainers prefer to avoid any logic changes; style-only cleanups (like removing inline comments) may be deferred to follow-ups to keep scope tight.
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37205
File: ee/packages/federation-matrix/src/FederationMatrix.ts:296-301
Timestamp: 2025-10-28T16:53:42.761Z
Learning: In the Rocket.Chat federation-matrix integration (ee/packages/federation-matrix/), the createRoom method from rocket.chat/federation-sdk will support a 4-argument signature (userId, roomName, visibility, displayName) in newer versions. Code using this 4-argument call is forward-compatible with planned library updates and should not be flagged as an error.
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37205
File: ee/packages/federation-matrix/src/FederationMatrix.ts:296-301
Timestamp: 2025-10-28T16:53:42.761Z
Learning: In the Rocket.Chat federation-matrix integration (ee/packages/federation-matrix/), the createRoom method from rocket.chat/federation-sdk will support a 4-argument signature (userId, roomName, visibility, displayName) in newer versions. Code using this 4-argument call is forward-compatible with planned library updates and should not be flagged as an error.
Learnt from: MartinSchoeler
Repo: RocketChat/Rocket.Chat PR: 37557
File: apps/meteor/client/views/admin/ABAC/AdminABACRooms.tsx:115-116
Timestamp: 2025-11-27T17:56:26.050Z
Learning: In Rocket.Chat, the GET /v1/abac/rooms endpoint (implemented in ee/packages/abac/src/index.ts) only returns rooms where abacAttributes exists and is not an empty array (query: { abacAttributes: { $exists: true, $ne: [] } }). Therefore, in components consuming this endpoint (like AdminABACRooms.tsx), room.abacAttributes is guaranteed to be defined for all returned rooms, and optional chaining before calling array methods like .join() is sufficient without additional null coalescing.
Learnt from: KevLehman
Repo: RocketChat/Rocket.Chat PR: 37091
File: ee/packages/abac/jest.config.ts:4-7
Timestamp: 2025-12-10T21:00:54.909Z
Learning: Rocket.Chat monorepo: Jest testMatch pattern '<rootDir>/src/**/*.spec.(ts|js|mjs)' is valid in this repo and used across multiple packages (e.g., packages/tools, ee/packages/omnichannel-services). Do not flag it as invalid in future reviews.
📚 Learning: 2025-11-27T17:56:26.050Z
Learnt from: MartinSchoeler
Repo: RocketChat/Rocket.Chat PR: 37557
File: apps/meteor/client/views/admin/ABAC/AdminABACRooms.tsx:115-116
Timestamp: 2025-11-27T17:56:26.050Z
Learning: In Rocket.Chat, the GET /v1/abac/rooms endpoint (implemented in ee/packages/abac/src/index.ts) only returns rooms where abacAttributes exists and is not an empty array (query: { abacAttributes: { $exists: true, $ne: [] } }). Therefore, in components consuming this endpoint (like AdminABACRooms.tsx), room.abacAttributes is guaranteed to be defined for all returned rooms, and optional chaining before calling array methods like .join() is sufficient without additional null coalescing.

Applied to files:

  • apps/meteor/app/api/server/v1/rooms.ts
📚 Learning: 2025-10-28T16:53:42.761Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37205
File: ee/packages/federation-matrix/src/FederationMatrix.ts:296-301
Timestamp: 2025-10-28T16:53:42.761Z
Learning: In the Rocket.Chat federation-matrix integration (ee/packages/federation-matrix/), the createRoom method from rocket.chat/federation-sdk will support a 4-argument signature (userId, roomName, visibility, displayName) in newer versions. Code using this 4-argument call is forward-compatible with planned library updates and should not be flagged as an error.

Applied to files:

  • apps/meteor/app/api/server/v1/rooms.ts
📚 Learning: 2026-02-24T19:09:01.522Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:01.522Z
Learning: In Rocket.Chat OpenAPI migration PRs for endpoints under apps/meteor/app/api/server/v1, avoid introducing logic changes. Only perform scope-tight changes that preserve behavior; style-only cleanups (e.g., removing inline comments) may be deferred to follow-ups to keep the migration PR focused.

Applied to files:

  • apps/meteor/app/api/server/v1/rooms.ts
📚 Learning: 2025-09-25T09:59:26.461Z
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 37057
File: packages/apps-engine/src/definition/accessors/IUserRead.ts:23-27
Timestamp: 2025-09-25T09:59:26.461Z
Learning: UserBridge.doGetUserRoomIds in packages/apps-engine/src/server/bridges/UserBridge.ts has a bug where it implicitly returns undefined when the app lacks read permission (missing return statement in the else case of the permission check).

Applied to files:

  • apps/meteor/app/api/server/v1/rooms.ts
📚 Learning: 2025-09-16T13:33:49.237Z
Learnt from: cardoso
Repo: RocketChat/Rocket.Chat PR: 36890
File: apps/meteor/tests/e2e/e2e-encryption/e2ee-otr.spec.ts:21-26
Timestamp: 2025-09-16T13:33:49.237Z
Learning: The im.delete API endpoint accepts either a `roomId` parameter (requiring the actual DM room _id) or a `username` parameter (for the DM partner's username). Constructing slug-like identifiers like `user2${Users.userE2EE.data.username}` doesn't work for this endpoint.

Applied to files:

  • apps/meteor/app/api/server/v1/rooms.ts
📚 Learning: 2025-09-16T13:33:49.237Z
Learnt from: cardoso
Repo: RocketChat/Rocket.Chat PR: 36890
File: apps/meteor/tests/e2e/e2e-encryption/e2ee-otr.spec.ts:21-26
Timestamp: 2025-09-16T13:33:49.237Z
Learning: In Rocket.Chat test files, the im.delete API endpoint accepts either a `roomId` parameter (requiring the actual DM room _id) or a `username` parameter (for the DM partner's username). It does not accept slug-like constructions such as concatenating usernames together.

Applied to files:

  • apps/meteor/app/api/server/v1/rooms.ts
📚 Learning: 2026-02-23T17:53:06.802Z
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 35995
File: apps/meteor/app/api/server/v1/rooms.ts:1107-1112
Timestamp: 2026-02-23T17:53:06.802Z
Learning: During PR reviews that touch endpoint files under apps/meteor/app/api/server/v1, enforce strict scope: if a PR targets a specific endpoint (e.g., rooms.favorite), do not propose changes to unrelated endpoints (e.g., rooms.invite) unless maintainers explicitly request them. Focus feedback on the touched endpoint's behavior, API surface, and related tests; avoid broad cross-endpoint changes in the same PR unless requested.

Applied to files:

  • apps/meteor/app/api/server/v1/rooms.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/app/api/server/v1/rooms.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/app/api/server/v1/rooms.ts

@Rohitgiri02
Copy link
Copy Markdown
Contributor Author

@ggazzo
Copy link
Copy Markdown
Member

ggazzo commented Mar 23, 2026

Hey, thanks for the contribution! 🙏

I'm closing this PR because the endpoint(s) covered here have already been migrated as part of a larger batch migration I'm working on (see #39820). I decided to go with a mass migration approach because reviewing individual PRs for each endpoint was taking too much of my time.

That said, you're more than welcome to help by reviewing and testing the changes in #39820 to make sure everything is working correctly. Your input would be really valuable!

Thanks again for your effort! 🚀

@ggazzo ggazzo closed this Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants