Skip to content

fix: narrow IModerationReport ts type from Date | string to Date#39641

Open
Avanish-Gupta-CSE wants to merge 1 commit into
RocketChat:developfrom
Avanish-Gupta-CSE:fix/issue-39551-moderation-audit-ts-type
Open

fix: narrow IModerationReport ts type from Date | string to Date#39641
Avanish-Gupta-CSE wants to merge 1 commit into
RocketChat:developfrom
Avanish-Gupta-CSE:fix/issue-39551-moderation-audit-ts-type

Conversation

@Avanish-Gupta-CSE
Copy link
Copy Markdown

@Avanish-Gupta-CSE Avanish-Gupta-CSE commented Mar 15, 2026

Proposed changes (including videos or screenshots)

Narrows the ts type on IModerationReport from Date | string to Date, fixing the AJV oneOf validation failure described in #39551.

Changes:

  1. packages/core-typings/src/IModerationReport.ts - Changed ts: Date | string to ts: Date
  2. apps/meteor/app/api/server/v1/moderation.ts - Removed 5 TODO workaround comment blocks (30 lines) that documented the oneOf issue
  3. docs/api-endpoint-migration.md - Updated "Known Pitfall" section to document the fix
  4. .changeset/fix-moderation-audit-ts-type.md - Added changeset for @rocket.chat/core-typings and @rocket.chat/meteor

Root cause

IModerationReport.ts defined ts: Date | string. When typia generates JSON Schema from this union, it creates a oneOf with:

  • { type: "string", format: "date-time" } (for Date)
  • { type: "string" } (for string)

An ISO date string like "2026-03-11T16:07:21.755Z" matches both branches, causing AJV oneOf to fail with passingSchemas: 0,1.

Why Date is correct

  • Reports are always created with ts: new Date() (both createWithMessageDescriptionAndUserId and createWithDescriptionAndUser in ModerationReports.ts)
  • MongoDB stores ts as a native Date object
  • JSON serialization produces ISO strings that match date-time format validation

Resolves #39551

Issue(s)

Closes #39551

Steps to test or reproduce

  1. Apply the type change
  2. Verify that moderation API endpoints (moderation.reportsByUsers, moderation.userReports, etc.) no longer fail AJV validation when returning reports with ISO date string ts fields

Further comments

The inline AJV schemas in moderation.ts (which manually define ts: { type: 'string' }) remain functionally correct and are kept as-is. The TODO workaround comments are removed since the root cause is now fixed at the type level.

Made with Cursor

Summary by CodeRabbit

  • Bug Fixes

    • Fixed validation issues in moderation reports with improved date type handling to enhance API reliability and data consistency.
  • Documentation

    • Updated API migration documentation to reflect moderation report date type improvements.

Resolves RocketChat#39551. The Date | string union generated a oneOf in JSON Schema
where an ISO date string matched both branches, causing AJV validation to
fail with passingSchemas: 0,1. Since MongoDB stores ts as Date and JSON
serialization produces ISO strings matching date-time format, narrowing
to Date eliminates the oneOf and fixes validation.

Made-with: Cursor
@Avanish-Gupta-CSE Avanish-Gupta-CSE requested review from a team as code owners March 15, 2026 05:09
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented Mar 15, 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 15, 2026

🦋 Changeset detected

Latest commit: 4162b0d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 41 packages
Name Type
@rocket.chat/core-typings Patch
@rocket.chat/meteor Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/ddp-client Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/gazzodown Patch
@rocket.chat/http-router Patch
@rocket.chat/livechat Patch
@rocket.chat/model-typings Patch
@rocket.chat/rest-typings Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-client Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/ui-voip Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/abac Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/license Patch
@rocket.chat/media-calls Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/network-broker Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/mock-providers Patch
@rocket.chat/models Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch
@rocket.chat/server-fetch Patch

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 15, 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: 50d8b3e2-38af-4228-aeac-61e8b9c05028

📥 Commits

Reviewing files that changed from the base of the PR and between a834e17 and 4162b0d.

📒 Files selected for processing (4)
  • .changeset/fix-moderation-audit-ts-type.md
  • apps/meteor/app/api/server/v1/moderation.ts
  • docs/api-endpoint-migration.md
  • packages/core-typings/src/IModerationReport.ts
💤 Files with no reviewable changes (1)
  • apps/meteor/app/api/server/v1/moderation.ts
📜 Recent review details
⏰ 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). (1)
  • GitHub Check: cubic · AI code reviewer
🧰 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:

  • packages/core-typings/src/IModerationReport.ts
🧠 Learnings (12)
📓 Common learnings
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39230
File: apps/meteor/app/api/server/v1/chat.ts:214-222
Timestamp: 2026-03-03T11:11:48.541Z
Learning: In apps/meteor/server/lib/moderation/reportMessage.ts, the reportMessage function validates that description is not empty or whitespace-only with `if (!description.trim())`. When migrating the chat.reportMessage endpoint to OpenAPI, adding minLength validation to the schema preserves this existing behavior.
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39414
File: apps/meteor/app/api/server/v1/rooms.ts:1241-1297
Timestamp: 2026-03-10T08:13:52.153Z
Learning: In the RocketChat/Rocket.Chat OpenAPI migration PRs for endpoints under apps/meteor/app/api/server/v1/rooms.ts, the pattern `ajv.compile<void>({...})` is intentionally used for the 200 response schema even when the endpoint returns `{ success: true }`. This is an established convention across all migrated endpoints (rooms.leave, rooms.favorite, rooms.delete, rooms.muteUser, rooms.unmuteUser). Do not flag this as a type mismatch during reviews of these migration PRs.
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38219
File: packages/core-typings/src/cloud/Announcement.ts:5-6
Timestamp: 2026-01-17T01:51:47.764Z
Learning: In packages/core-typings/src/cloud/Announcement.ts, the AnnouncementSchema.createdBy field intentionally overrides IBannerSchema.createdBy (object with _id and optional username) with a string enum ['cloud', 'system'] to match existing runtime behavior. This is documented as technical debt with a FIXME comment at apps/meteor/app/cloud/server/functions/syncWorkspace/handleCommsSync.ts:53 and should not be flagged as an error until the runtime behavior is corrected.
Learnt from: smirk-dev
Repo: RocketChat/Rocket.Chat PR: 39625
File: apps/meteor/app/api/server/v1/push.ts:85-97
Timestamp: 2026-03-14T14:58:50.283Z
Learning: In RocketChat/Rocket.Chat, the `push.token` POST/DELETE endpoints in `apps/meteor/app/api/server/v1/push.ts` were already migrated to the chained router API pattern on `develop` prior to PR `#39625`. `cleanTokenResult` (which strips `authToken` and returns `PushTokenResult`) and `isPushTokenPOSTProps`/`isPushTokenDELETEProps` validators already exist on `develop`. PR `#39625` only migrates `push.get` and `push.info` to the chained pattern. Do not flag `cleanTokenResult` or `PushTokenResult` as newly introduced behavior-breaking changes when reviewing this PR.
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39397
File: packages/gazzodown/src/elements/Timestamp/DateTimeFormats.spec.tsx:20-23
Timestamp: 2026-03-06T18:09:17.867Z
Learning: In the RocketChat/Rocket.Chat gazzodown package (`packages/gazzodown`), tests are intended to run under the UTC timezone, but as of PR `#39397` this is NOT yet explicitly enforced in `jest.config.ts` or the `package.json` test scripts (which just run `jest` without `TZ=UTC`). To make timezone-sensitive snapshot tests reliable across all environments, `TZ=UTC` should be added to the test scripts in `package.json` or to `jest.config.ts` via `testEnvironmentOptions.timezone`. Without explicit UTC enforcement, snapshot tests involving date-fns formatted output or `toLocaleString()` will fail for contributors in non-UTC timezones.
📚 Learning: 2026-01-17T01:51:47.764Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38219
File: packages/core-typings/src/cloud/Announcement.ts:5-6
Timestamp: 2026-01-17T01:51:47.764Z
Learning: In packages/core-typings/src/cloud/Announcement.ts, the AnnouncementSchema.createdBy field intentionally overrides IBannerSchema.createdBy (object with _id and optional username) with a string enum ['cloud', 'system'] to match existing runtime behavior. This is documented as technical debt with a FIXME comment at apps/meteor/app/cloud/server/functions/syncWorkspace/handleCommsSync.ts:53 and should not be flagged as an error until the runtime behavior is corrected.

Applied to files:

  • docs/api-endpoint-migration.md
  • .changeset/fix-moderation-audit-ts-type.md
📚 Learning: 2026-03-12T10:26:26.697Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39340
File: apps/meteor/app/api/server/v1/im.ts:1349-1398
Timestamp: 2026-03-12T10:26:26.697Z
Learning: In `apps/meteor/app/api/server/v1/im.ts` (PR `#39340`), the `DmEndpoints` type intentionally includes temporary stub entries for `/v1/im.kick`, `/v1/dm.kick`, `/v1/im.leave`, and `/v1/dm.leave` (using `DmKickProps` and `DmLeaveProps`) even though no route handlers exist for them yet. These stubs were added to preserve type compatibility after removing the original `DmLeaveProps` and related files. They are planned for cleanup in a follow-up PR. Do not flag these as missing implementations when reviewing this file until the follow-up is merged.

Applied to files:

  • docs/api-endpoint-migration.md
📚 Learning: 2026-03-10T08:13:52.153Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39414
File: apps/meteor/app/api/server/v1/rooms.ts:1241-1297
Timestamp: 2026-03-10T08:13:52.153Z
Learning: In the RocketChat/Rocket.Chat OpenAPI migration PRs for endpoints under apps/meteor/app/api/server/v1/rooms.ts, the pattern `ajv.compile<void>({...})` is intentionally used for the 200 response schema even when the endpoint returns `{ success: true }`. This is an established convention across all migrated endpoints (rooms.leave, rooms.favorite, rooms.delete, rooms.muteUser, rooms.unmuteUser). Do not flag this as a type mismatch during reviews of these migration PRs.

Applied to files:

  • docs/api-endpoint-migration.md
  • .changeset/fix-moderation-audit-ts-type.md
📚 Learning: 2026-03-06T18:09:17.867Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39397
File: packages/gazzodown/src/elements/Timestamp/DateTimeFormats.spec.tsx:20-23
Timestamp: 2026-03-06T18:09:17.867Z
Learning: In the RocketChat/Rocket.Chat gazzodown package (`packages/gazzodown`), tests are intended to run under the UTC timezone, but as of PR `#39397` this is NOT yet explicitly enforced in `jest.config.ts` or the `package.json` test scripts (which just run `jest` without `TZ=UTC`). To make timezone-sensitive snapshot tests reliable across all environments, `TZ=UTC` should be added to the test scripts in `package.json` or to `jest.config.ts` via `testEnvironmentOptions.timezone`. Without explicit UTC enforcement, snapshot tests involving date-fns formatted output or `toLocaleString()` will fail for contributors in non-UTC timezones.

Applied to files:

  • docs/api-endpoint-migration.md
  • .changeset/fix-moderation-audit-ts-type.md
📚 Learning: 2026-03-03T11:11:48.541Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 39230
File: apps/meteor/app/api/server/v1/chat.ts:214-222
Timestamp: 2026-03-03T11:11:48.541Z
Learning: In apps/meteor/server/lib/moderation/reportMessage.ts, the reportMessage function validates that description is not empty or whitespace-only with `if (!description.trim())`. When migrating the chat.reportMessage endpoint to OpenAPI, adding minLength validation to the schema preserves this existing behavior.

Applied to files:

  • packages/core-typings/src/IModerationReport.ts
  • .changeset/fix-moderation-audit-ts-type.md
📚 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: AppUserBridge.getUserRoomIds in apps/meteor/app/apps/server/bridges/users.ts always returns an array of strings (mapping subscription documents to room IDs), never undefined, even when user has no room subscriptions.

Applied to files:

  • packages/core-typings/src/IModerationReport.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: AppUserBridge.getUserRoomIds in apps/meteor/app/apps/server/bridges/users.ts always returns an array of strings by mapping subscription documents to room IDs, never undefined, even when user has no room subscriptions.

Applied to files:

  • packages/core-typings/src/IModerationReport.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:

  • packages/core-typings/src/IModerationReport.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:

  • packages/core-typings/src/IModerationReport.ts
📚 Learning: 2026-02-25T20:10:16.987Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38913
File: packages/ddp-client/src/legacy/types/SDKLegacy.ts:34-34
Timestamp: 2026-02-25T20:10:16.987Z
Learning: In the RocketChat/Rocket.Chat monorepo, packages/ddp-client and apps/meteor do not use TypeScript project references. Module augmentations in apps/meteor (e.g., declare module 'rocket.chat/rest-typings') are not visible when compiling packages/ddp-client in isolation, which is why legacy SDK methods that depend on OperationResult types for OpenAPI-migrated endpoints must remain commented out.

Applied to files:

  • .changeset/fix-moderation-audit-ts-type.md
📚 Learning: 2025-12-10T21:00:54.909Z
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.

Applied to files:

  • .changeset/fix-moderation-audit-ts-type.md
🔇 Additional comments (4)
packages/core-typings/src/IModerationReport.ts (2)

11-11: LGTM!

The type narrowing from Date | string to Date correctly reflects the runtime behavior: reports are created with new Date() (as confirmed by the write-sites in ModerationReports.ts), MongoDB stores native Date objects, and JSON serialization produces ISO date strings that validate against the date-time format schema. This resolves the AJV oneOf validation failure.


43-43: Downstream type reference correctly inherits the narrowed type.

IModerationAudit.ts uses IModerationReport['ts'], so it automatically picks up the narrowed Date type without requiring separate changes.

.changeset/fix-moderation-audit-ts-type.md (1)

1-6: LGTM!

The changeset correctly marks both @rocket.chat/core-typings and @rocket.chat/meteor as patch releases. The description accurately captures the type narrowing and the AJV validation issue it resolves.

docs/api-endpoint-migration.md (1)

420-422: LGTM!

The documentation update clearly explains the root cause (typia generating ambiguous oneOf schemas for Date | string unions) and provides actionable guidance: narrow the type to Date in core-typings. The reference to issue #39551 adds traceability.


Walkthrough

The changes narrow the IModerationReport.ts property type from Date | string to Date to resolve an AJV oneOf validation failure when MongoDB aggregations return ISO date strings. Related TODO comments are removed from the API endpoints, and documentation is updated to reflect the fix.

Changes

Cohort / File(s) Summary
Type Definition Refinement
packages/core-typings/src/IModerationReport.ts
Narrowed ts property from Date | string to Date in IModerationReport interface, ensuring type consistency with MongoDB aggregation behavior.
Comment Cleanup
apps/meteor/app/api/server/v1/moderation.ts
Removed TODO comments documenting the AJV oneOf validation workaround for union types, as the underlying type issue is now resolved.
Documentation & Changeset
.changeset/fix-moderation-audit-ts-type.md, docs/api-endpoint-migration.md
Updated changeset indicating dependency bumps; replaced historical workaround narrative in documentation with concise type-narrowing fix reference.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: narrowing the IModerationReport ts type from Date | string to Date.
Linked Issues check ✅ Passed All coding requirements from issue #39551 are met: the ts property in IModerationReport is narrowed to Date, TODO comments documenting the workaround are removed, and documentation is updated.
Out of Scope Changes check ✅ Passed All changes are directly scoped to resolving issue #39551: the core type fix, documentation updates, TODO comment removal, and changeset addition.
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.

📝 Coding Plan
  • Generate coding plan for human review comments

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

CodeRabbit can use oxc to improve the quality of JavaScript and TypeScript code reviews.

Add a configuration file to your project to customize how CodeRabbit runs oxc.

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 4 files

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.

IModerationAudit defines ts as Date | string which generates a oneOf in JSON Schema.

1 participant