Skip to content

Conversation

@deepak0x
Copy link

@deepak0x deepak0x commented Jan 4, 2026

Preparation & Setup

Helper Types Migration

  • Migrate PaginatedRequest to re-export from @rocket.chat/rest-typings
  • Migrate PaginatedResult to re-export from @rocket.chat/rest-typings
  • Update helpers/index.ts with TODO for future endpoint migration
  • Keep custom ResultFor, Serialized, ErrorResult for SDK compatibility

Proposed changes

Issue(s)

How to test or reproduce

Screenshots

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves a current function)
  • New feature (non-breaking change which adds functionality)
  • Documentation update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • I have added necessary documentation (if applicable)
  • Any dependent changes have been merged and published in downstream modules

Further comments

Summary by CodeRabbit

  • Refactor

    • Centralized pagination typings into shared packages and added migration notes.
  • Bug Fixes

    • Improved endpoint response handling to better detect and surface failed responses.
  • Chores

    • Added new shared typing package dependencies (v6.13.1).

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 4, 2026

Walkthrough

Replaced several local REST typing definitions with re-exports and types from @rocket.chat/rest-typings and @rocket.chat/core-typings, updated many v1 endpoint files to import those external types, expanded helpers index with extensive type re-exports and mappings, added the two dependencies, and adjusted a hook to guard response shapes.

Changes

Cohort / File(s) Summary
Helpers — removed local pagination types
app/definitions/rest/helpers/PaginatedRequest.ts, app/definitions/rest/helpers/PaginatedResult.ts
Deleted local PaginatedRequest and PaginatedResult type aliases; module no longer defines those types locally.
Helpers index — large typing refactor / re-exports
app/definitions/rest/helpers/index.ts
Rewrote to re-export many typings from @rocket.chat/rest-typings and introduced numerous derived type utilities and maps (Method, Path, PathPattern, GetParams/GetResult-style mappings, MethodToPath* maps, ResultFor/ParamsFor, Success/Failure/Unauthorized result shapes, etc.). Added migration/POC comments.
Endpoint type imports (v1)
app/definitions/rest/v1/channels.ts, app/definitions/rest/v1/chat.ts, app/definitions/rest/v1/directory.ts, app/definitions/rest/v1/emojiCustom.ts, app/definitions/rest/v1/groups.ts, app/definitions/rest/v1/im.ts, app/definitions/rest/v1/omnichannel.ts, app/definitions/rest/v1/settings.ts, app/definitions/rest/v1/teams.ts, app/definitions/rest/v1/videoConference.ts
Replaced relative/local imports of PaginatedRequest/PaginatedResult with type-only imports from @rocket.chat/rest-typings. No endpoint signatures changed.
Dependencies
package.json
Added dependencies: @rocket.chat/[email protected] and @rocket.chat/[email protected].
Hook response handling change
app/lib/hooks/useEndpointData.ts
Tightened GET response handling: result typed as any, added guard for non-object or missing success property, treat falsy success as error; updated branching to ensure proper error vs. result assignment.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇
I nibbled at types with hop and cheer,
Plucked pagination from the code-yard near,
Packaged them off to a tidy crate,
Now externals handle the paging gate. 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main changes: installing rest-typings package and migrating helper types from local definitions to external re-exports.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@deepak0x deepak0x force-pushed the refactor/rest-typings-setup_and_helpers_migration branch from 39693ae to 1c1e6dc Compare January 4, 2026 07:53
Copy link
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.

Actionable comments posted: 3

🧹 Nitpick comments (1)
scripts/verify-migration-phase.sh (1)

1-52: Consider adding test execution to match documentation.

MIGRATION_SUMMARY.md and MIGRATION_CHECKLIST.md both reference running yarn test as part of the verification process, but this script only checks TypeScript compilation and linting. Consider adding test execution or updating the documentation to reflect the actual verification steps.

🔎 Proposed addition of test execution
 echo "✅ Linting passed with 0 errors"
 
+# Run tests
+echo "🧪 Running tests..."
+if ! yarn test; then
+    echo "❌ Tests failed!"
+    exit 1
+fi
+echo "✅ Tests passed"
+
 echo ""
 echo "✅ Phase $PHASE verification complete!"
 echo "   - TypeScript: ✅"
 echo "   - Linting: ✅ (0 errors)"
+echo "   - Tests: ✅"
📜 Review details

Configuration used: Organization 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 3315fb4 and 39693ae.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (10)
  • .gitignore
  • MIGRATION_CHECKLIST.md
  • MIGRATION_PLAN.md
  • MIGRATION_SUMMARY.md
  • app/definitions/rest/COMPATIBILITY_LAYER.md
  • app/definitions/rest/helpers/PaginatedRequest.ts
  • app/definitions/rest/helpers/PaginatedResult.ts
  • app/definitions/rest/helpers/index.ts
  • package.json
  • scripts/verify-migration-phase.sh
🔇 Additional comments (8)
app/definitions/rest/COMPATIBILITY_LAYER.md (1)

1-52: Documentation looks good, but note the .gitignore conflict.

The compatibility layer documentation is well-structured and provides clear guidance with helpful examples. However, this file is listed in .gitignore (line 92), which conflicts with it being committed. Please refer to the review comment on .gitignore for resolution.

MIGRATION_PLAN.md (1)

1-315: Comprehensive migration plan, but conflicts with .gitignore.

The migration plan is well-structured with clear phases, time estimates, and quality gates. However, this file matches the *MIGRATION*.md pattern in .gitignore (line 88), which would prevent it from being tracked. Please refer to the review comment on .gitignore for resolution.

app/definitions/rest/helpers/PaginatedResult.ts (1)

1-2: No action needed—verification confirms the external type exists and all usages are type-safe.

The @rocket.chat/rest-typings package (v6.13.1) is properly declared in package.json, and the re-export is working correctly across all seven files that import PaginatedResult (directory.ts, settings.ts, teams.ts, videoConference.ts, omnichannel.ts, emojiCustom.ts, chat.ts). No type errors or import failures are present, confirming structure compatibility and type-safety.

package.json (1)

50-53: The specified versions (6.13.1) exist, are published, and have no known security vulnerabilities. They are compatible by design, released together as matched versions in Rocket.Chat 6.13.1. The exact version pinning indicates intentional selection for stable compatibility with a specific Rocket.Chat server release, which is appropriate for a mobile client targeting that version. No action needed.

app/definitions/rest/helpers/index.ts (1)

2-4: LGTM! Clear migration plan documented.

The TODO comments effectively communicate the migration strategy and rationale for maintaining the current implementation during the transition phase.

MIGRATION_SUMMARY.md (1)

1-58: Well-structured migration documentation.

The summary provides a clear overview of the migration process with helpful quick references, phase descriptions, quality gates, and important notes. The structure will guide developers effectively through the phased migration.

MIGRATION_CHECKLIST.md (1)

1-288: Excellent comprehensive migration checklist.

This checklist is well-structured and provides clear, actionable steps for each migration phase. The inclusion of verification commands (yarn lint, tsc --noEmit) after each category and standardized commit messages will help maintain quality and consistency throughout the migration process.

app/definitions/rest/helpers/PaginatedRequest.ts (1)

1-2: No action needed. The re-export to @rocket.chat/rest-typings is confirmed compatible.

The migration refactored the local PaginatedRequest definition to use the external package type, which correctly supports generic parameters T (request body) and an optional S (sort field) as evidenced by usage patterns throughout the codebase (PaginatedRequest<{ query: string }, 'name'>, PaginatedRequest<{ text: string }>). The external type includes the expected fields: count, offset, sort, and query. The codebase actively uses this re-export without type errors across multiple endpoint definitions.

@deepak0x deepak0x force-pushed the refactor/rest-typings-setup_and_helpers_migration branch 4 times, most recently from 861a4fa to d9b821b Compare January 4, 2026 08:04
Copy link
Member

@diegolmello diegolmello left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!
Left a few comments.

@@ -1,4 +1,7 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
// TODO: Once we migrate all endpoints to use @rocket.chat/rest-typings,
Copy link
Member

Choose a reason for hiding this comment

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

Can you do it on this PR or start the work on this PR, so it serves as a POC?

Copy link
Author

Choose a reason for hiding this comment

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

sure...will try my best...

Preparation & Setup
- Install @rocket.chat/[email protected]
- Install @rocket.chat/[email protected] (required dependency)
- Explore and document package structure

Helper Types Migration
- Migrate PaginatedRequest to re-export from @rocket.chat/rest-typings
- Migrate PaginatedResult to re-export from @rocket.chat/rest-typings
- Update helpers/index.ts with TODO for future endpoint migration
- Keep custom ResultFor, Serialized, ErrorResult for SDK compatibility
- Remove PaginatedRequest.ts and PaginatedResult.ts wrapper files
- Use KeyOfEach and ReplacePlaceholders from @rocket.chat packages
- Implement rest-typings patterns: PathFor, PathWithParamsFor, PathWithoutParamsFor
- Add utilities: JoinPathPattern, UrlParams, MethodOf, ParamsFor
- Use MethodToPathPatternToParamsMap and MethodToPathPatternToResultMap patterns
- Fix TypeScript errors in useEndpointData with proper type guards
- Update import order in endpoint definition files
@deepak0x deepak0x force-pushed the refactor/rest-typings-setup_and_helpers_migration branch from 0aa5c81 to b5e17a7 Compare January 11, 2026 17:42
Copy link
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.

Actionable comments posted: 0

🧹 Nitpick comments (2)
app/definitions/rest/helpers/index.ts (2)

1-1: Verify the necessity of the eslint-disable directive.

The no-unused-vars disable is common in type-only files, but it can mask legitimate issues. Consider reviewing whether all type parameters are actually necessary.


2-4: Track the migration TODO for future completion.

The POC comment indicates this is a temporary bridge implementation until full migration to @rocket.chat/rest-typings. This technical debt should be tracked to ensure the migration is completed.

Would you like me to create a tracking issue for the full migration to @rocket.chat/rest-typings endpoints (replacing the current Endpoints structure with /v1/ prefixed paths)?

📜 Review details

Configuration used: Organization 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 0aa5c81 and b5e17a7.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (15)
  • app/definitions/rest/helpers/PaginatedRequest.ts
  • app/definitions/rest/helpers/PaginatedResult.ts
  • app/definitions/rest/helpers/index.ts
  • app/definitions/rest/v1/channels.ts
  • app/definitions/rest/v1/chat.ts
  • app/definitions/rest/v1/directory.ts
  • app/definitions/rest/v1/emojiCustom.ts
  • app/definitions/rest/v1/groups.ts
  • app/definitions/rest/v1/im.ts
  • app/definitions/rest/v1/omnichannel.ts
  • app/definitions/rest/v1/settings.ts
  • app/definitions/rest/v1/teams.ts
  • app/definitions/rest/v1/videoConference.ts
  • app/lib/hooks/useEndpointData.ts
  • package.json
💤 Files with no reviewable changes (2)
  • app/definitions/rest/helpers/PaginatedRequest.ts
  • app/definitions/rest/helpers/PaginatedResult.ts
✅ Files skipped from review due to trivial changes (1)
  • app/definitions/rest/v1/videoConference.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
🧰 Additional context used
🧬 Code graph analysis (2)
app/definitions/rest/helpers/index.ts (1)
app/definitions/rest/v1/index.ts (1)
  • Endpoints (25-47)
app/lib/hooks/useEndpointData.ts (1)
app/definitions/rest/helpers/index.ts (4)
  • ErrorResult (182-182)
  • Serialized (48-56)
  • ResultFor (177-180)
  • MatchPathPattern (59-61)
🔇 Additional comments (13)
app/lib/hooks/useEndpointData.ts (1)

45-51: The error-handling logic is correct and intentional.

The SDK resolves promises in both success and error cases—it only rejects for network/connection errors. The logic correctly identifies errors when responses have success: false and treats all other resolved values as results. This matches the actual SDK behavior shown in the tests and is part of the @rocket.chat/rest-typings migration.

The guards are appropriate: e && typeof e === 'object' && 'success' in e && !e.success ensures non-objects and objects without a success property pass through to setResult, which is the correct behavior since the type system guarantees all SDK responses are objects with a success property.

Likely an incorrect or invalid review comment.

app/definitions/rest/v1/im.ts (1)

1-1: LGTM! Import migration correctly applied.

The migration from local PaginatedRequest to @rocket.chat/rest-typings follows the same pattern as other files in this PR. Type-only import is appropriate.

app/definitions/rest/v1/channels.ts (1)

1-1: LGTM! Consistent with the rest-typings migration.

The migration from local PaginatedRequest to @rocket.chat/rest-typings is correctly implemented.

app/definitions/rest/v1/teams.ts (1)

1-1: LGTM! Migration correctly applied.

The migration from local PaginatedResult to @rocket.chat/rest-typings is consistent with the broader refactoring effort.

app/definitions/rest/v1/settings.ts (1)

1-1: LGTM! Import migration correctly applied.

The migration from local PaginatedResult to @rocket.chat/rest-typings is correctly implemented. The type is used in an intersection type at line 70, which should work seamlessly with the external definition.

app/definitions/rest/v1/chat.ts (1)

1-1: LGTM! Migration to @rocket.chat/rest-typings is correctly implemented.

The type-only import from @rocket.chat/rest-typings for PaginatedResult is properly used and compatible. The old local definition has been removed, and the generic PaginatedResult<T> type matches the usage patterns in chat.ts and other REST endpoint definitions. Package version 6.13.1 is stable and was released as part of the official Rocket.Chat 6.13.1 release.

app/definitions/rest/v1/emojiCustom.ts (1)

1-1: LGTM! Clean migration to external types.

The import consolidation from local helpers to @rocket.chat/rest-typings aligns with the PR objectives and maintains existing type signatures.

app/definitions/rest/v1/directory.ts (1)

1-1: LGTM! Consistent with migration pattern.

The import source change maintains the existing type contract while aligning with the centralized type definitions from @rocket.chat/rest-typings.

app/definitions/rest/v1/omnichannel.ts (1)

1-1: LGTM! Extensive migration completed successfully.

The import migration to @rocket.chat/rest-typings is applied consistently across all OmnichannelEndpoints, maintaining type safety while reducing local type duplication.

app/definitions/rest/helpers/index.ts (3)

29-29: Type intersection ensures string compatibility.

The TPathPattern & string intersection correctly constrains the type for ReplacePlaceholders, ensuring that only string-compatible path patterns are processed.


175-180: LGTM! Error handling wrapper aligns with SDK needs.

The ResultFor type correctly wraps operation results with SuccessResult, FailureResult, and UnauthorizedResult patterns, providing comprehensive error handling for SDK consumers.


64-158: This is a POC adaptation—verify against actual rest-typings 6.13.1 when migrating endpoints.

The type utilities are correctly documented as adaptations rather than direct implementations from @rocket.chat/rest-typings. The file comment explicitly notes this is a temporary POC pattern awaiting full endpoint migration. The only direct import from rest-typings is ReplacePlaceholders, which is properly re-exported; the remaining utilities (UrlParams, MethodOf, PathFor, etc.) are locally implemented to match the current Endpoints structure.

Before merging, confirm:

  • The local type implementations are compatible with rest-typings 6.13.1's type signatures when endpoints are eventually migrated to use /v1/ prefix paths
  • No breaking changes in future rest-typings versions (6.13.1+) will affect the mapped type patterns used here

The TypeScript strict mode configuration and tsc in the lint script will catch type errors during compilation, but real compatibility should be verified once these types are actively used.

app/definitions/rest/v1/groups.ts (1)

1-1: Clean refactor with confirmed package compatibility.

The migration to @rocket.chat/rest-typings improves type consistency across the codebase. The package version 6.13.1 is correctly specified in package.json, and PaginatedRequest is properly exported and already in use across multiple endpoint definitions.

@deepak0x deepak0x requested a review from diegolmello January 12, 2026 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants