Skip to content

fix(apps): handle multiple results returned from /apps/marketplace#39555

Open
gauravsingh001-cyber wants to merge 3 commits into
RocketChat:developfrom
gauravsingh001-cyber:fix/apps-marketplace-multiple-results
Open

fix(apps): handle multiple results returned from /apps/marketplace#39555
gauravsingh001-cyber wants to merge 3 commits into
RocketChat:developfrom
gauravsingh001-cyber:fix/apps-marketplace-multiple-results

Conversation

@gauravsingh001-cyber
Copy link
Copy Markdown
Contributor

@gauravsingh001-cyber gauravsingh001-cyber commented Mar 12, 2026

Description

The /apps/marketplace endpoint is expected to return an array of marketplace apps. However, in some environments multiple results may be returned (for example from different cluster nodes).

The current implementation assumes the response is always a single array of apps and returns an error when the structure is different.

This change ensures that if multiple results are returned, the client safely uses the first result and continues processing the apps list normally.

Changes

  • Added handling for cases where the API returns multiple marketplace results
  • Ensured the client extracts the first valid result before processing the apps list

Notes

This resolves the TODO comment in orchestrator.ts regarding handling multiple results returned from the marketplace API.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of nested marketplace responses so app listings are correctly interpreted and displayed. Marketplace apps now load more reliably and consistently, reducing display errors and missing items when backend responses include nested arrays.

@gauravsingh001-cyber gauravsingh001-cyber requested a review from a team as a code owner March 12, 2026 06:41
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 12, 2026

⚠️ No Changeset found

Latest commit: b0a9309

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

@dionisio-bot
Copy link
Copy Markdown
Contributor

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 12, 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: 65857efc-9850-4596-b057-b92918333b7f

📥 Commits

Reviewing files that changed from the base of the PR and between 7e48bf7 and b0a9309.

📒 Files selected for processing (1)
  • apps/meteor/client/apps/orchestrator.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/client/apps/orchestrator.ts

Walkthrough

Adds handling in getAppsFromMarketplace to detect and unwrap nested array responses (2D arrays) from the marketplace API, converting them to a flat array before performing validation.

Changes

Cohort / File(s) Summary
Marketplace Data Handling
apps/meteor/client/apps/orchestrator.ts
Add conditional logic in getAppsFromMarketplace to detect when the API result is an array whose items lack a latest property and to replace result with a nested array element (flattening a 2D array) before validation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

type: bug

🚥 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 accurately describes the main change: adding handling for multiple results from the /apps/marketplace endpoint, which aligns with both the code changes and PR objectives.
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.


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.

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 1 file

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/meteor/client/apps/orchestrator.ts`:
- Around line 72-74: The current branch handling a non-App[] clustered response
always picks result[0], which can be an invalid entry; instead scan the outer
array for the first inner array payload and assign that to result. Locate the
variable result in apps/meteor/client/apps/orchestrator.ts (the branch that
checks Array.isArray(result) && Array.isArray(result[0])), replace the blind
result = result[0] with logic to find the first element where
Array.isArray(element) is true and set result to that array (fallback to [] or
original result shape if none found) so the mapper that follows receives a valid
App[] payload.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 19d9fa0b-ac0d-4856-9edb-bb9395b9b2b8

📥 Commits

Reviewing files that changed from the base of the PR and between 7485960 and 15a1b40.

📒 Files selected for processing (1)
  • apps/meteor/client/apps/orchestrator.ts
📜 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:

  • apps/meteor/client/apps/orchestrator.ts
🧠 Learnings (3)
📚 Learning: 2026-02-10T16:32:42.586Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:42.586Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON and Date fields arrive as Date objects; do not manually construct new Date() in stream handlers (for example, in sdk.stream()). Only REST API responses return plain JSON where dates are strings, so implement explicit conversion there if needed. Apply this guidance to all TypeScript files under apps/meteor/client to ensure consistent date handling in DDP streams and REST responses.

Applied to files:

  • apps/meteor/client/apps/orchestrator.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/client/apps/orchestrator.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/client/apps/orchestrator.ts

Comment thread apps/meteor/client/apps/orchestrator.ts Outdated
@coderabbitai coderabbitai Bot removed the type: bug label Mar 12, 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.

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/meteor/client/apps/orchestrator.ts">

<violation number="1" location="apps/meteor/client/apps/orchestrator.ts:72">
P2: Unsafe use of `in` inside `every` can throw on non-object array items, causing a runtime crash before error fallback handling.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread apps/meteor/client/apps/orchestrator.ts Outdated
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.

♻️ Duplicate comments (1)
apps/meteor/client/apps/orchestrator.ts (1)

72-75: ⚠️ Potential issue | 🔴 Critical

Model the clustered response as a union before reassigning result.

result is declared as App[], so result.find((item) => Array.isArray(item)) is being typed against App elements, not the nested payload this branch is trying to unwrap. The reassignment result = valid bypasses type safety and leaves the normalization path under-modeled. Widen the response type first, then use a proper type guard to narrow it back to App[].

Suggested fix
-		let result: App[] = [];
+		let result: App[] | App[][] = [];
@@
-		if (Array.isArray(result) && !result.every((item) => 'latest' in item)) {
-			const valid = result.find((item) => Array.isArray(item));
-			if (valid) {
-				result = valid;
-			}
-		}
+		if (Array.isArray(result) && result.some(Array.isArray)) {
+			const valid = result.find((item): item is App[] => Array.isArray(item));
+			if (!valid) {
+				return { apps: [], error: 'Invalid response from API' };
+			}
+			result = valid;
+		}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/client/apps/orchestrator.ts` around lines 72 - 75, The code is
unwrapping a clustered response by assigning a found nested array to result
(variable result) without updating its type; first widen result's type to
include the nested-array shape (e.g., App | App[] | App[][] or unknown) where
result is declared, then use a proper type guard when checking the branch (use
Array.isArray checks that narrow types, e.g., confirm valid is an array of App
via a predicate) and then assign result = valid as App[] only after the guard;
update the normalization/consumer code to accept the narrowed App[] type rather
than bypassing the compiler with an untyped reassignment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@apps/meteor/client/apps/orchestrator.ts`:
- Around line 72-75: The code is unwrapping a clustered response by assigning a
found nested array to result (variable result) without updating its type; first
widen result's type to include the nested-array shape (e.g., App | App[] |
App[][] or unknown) where result is declared, then use a proper type guard when
checking the branch (use Array.isArray checks that narrow types, e.g., confirm
valid is an array of App via a predicate) and then assign result = valid as
App[] only after the guard; update the normalization/consumer code to accept the
narrowed App[] type rather than bypassing the compiler with an untyped
reassignment.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b6f24792-ae65-46d3-bd6f-d8b04f39bd3a

📥 Commits

Reviewing files that changed from the base of the PR and between 15a1b40 and 7e48bf7.

📒 Files selected for processing (1)
  • apps/meteor/client/apps/orchestrator.ts
📜 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:

  • apps/meteor/client/apps/orchestrator.ts
🧠 Learnings (6)
📚 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:

  • apps/meteor/client/apps/orchestrator.ts
📚 Learning: 2025-10-06T20:32:23.658Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 37152
File: packages/apps-engine/tests/test-data/utilities.ts:557-573
Timestamp: 2025-10-06T20:32:23.658Z
Learning: In packages/apps-engine/tests/test-data/utilities.ts, the field name `isSubscripbedViaBundle` in the `IMarketplaceSubscriptionInfo` type should not be flagged as a typo, as it may match the upstream API's field name.

Applied to files:

  • apps/meteor/client/apps/orchestrator.ts
📚 Learning: 2026-03-09T21:20:12.687Z
Learnt from: pierre-lehnen-rc
Repo: RocketChat/Rocket.Chat PR: 39386
File: apps/meteor/server/services/push/tokenManagement/findDocumentToUpdate.ts:12-15
Timestamp: 2026-03-09T21:20:12.687Z
Learning: In `apps/meteor/server/services/push/tokenManagement/findDocumentToUpdate.ts`, the early return `if (data.voipToken) return null` (Lines 13-15) is intentionally correct. VoIP token updates always include an `_id`, so they are handled by the `_id` lookup block above (Lines 5-9) and never reach this guard. The guard is only a safety net for edge cases where `_id` is absent or no document was found, preventing an incorrect `token + appName` fallback match for VoIP-only payloads.

Applied to files:

  • apps/meteor/client/apps/orchestrator.ts
📚 Learning: 2026-02-10T16:32:42.586Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:42.586Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON and Date fields arrive as Date objects; do not manually construct new Date() in stream handlers (for example, in sdk.stream()). Only REST API responses return plain JSON where dates are strings, so implement explicit conversion there if needed. Apply this guidance to all TypeScript files under apps/meteor/client to ensure consistent date handling in DDP streams and REST responses.

Applied to files:

  • apps/meteor/client/apps/orchestrator.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/client/apps/orchestrator.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/client/apps/orchestrator.ts

@gauravsingh001-cyber
Copy link
Copy Markdown
Contributor Author

Hi @dougfabris, could you please take a look at this PR when you have time? I’d really appreciate your review. Thanks!

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.

1 participant