Skip to content

refactor(api): migrate WebLink and File from Flow to TypeScript - #4989

Open
bonchevskyi wants to merge 1 commit into
box:masterfrom
bonchevskyi:refactor/flow-to-ts-api-weblink-file
Open

bonchevskyi wants to merge 1 commit into
box:masterfrom
bonchevskyi:refactor/flow-to-ts-api-weblink-file

Conversation

@bonchevskyi

@bonchevskyi bonchevskyi commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Convert WebLink and File APIs to TypeScript

This PR converts src/api/WebLink and src/api/File from JavaScript with Flow to TypeScript.

Changes

  • Converted WebLink.js to WebLink.ts and File.js to File.ts
  • Converted __tests__/WebLink.test.js and __tests__/File.test.js to .test.ts
  • Created .js.flow files (original Flow source) for backward compatibility
  • Updated src/utils/__tests__/flatten.test.ts for type fallout (as APIOptions on FileAPI / WebLinkAPI construction)

Contract

  • Declared Flow contract preserved (method signatures, requiredness, defaults, exports), with one narrowing:
  • Contract change: File.getThumbnailUrl Promise<?string> → Promise<string | null> — every return path resolves to a string or null, never undefined

Summary by CodeRabbit

  • New Features
    • Added support for retrieving files and web links, including requested-field and cache handling.
    • Added file download and thumbnail links, representation status checks, and file description updates.
    • Added file extension retrieval.
  • Tests
    • Updated and expanded test coverage for file and web link behavior.

@bonchevskyi
bonchevskyi requested a review from a team as a code owner November 30, 2026 14:01
@mergify

mergify Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

This pull request adds File and WebLink API classes. The file API supports download and thumbnail URLs, representation polling, description updates, and cached file retrieval. The web-link API supports cached retrieval. Related tests now use TypeScript imports and types.

Changes

File and WebLink API clients

Layer / File(s) Summary
File URLs and representations
src/api/File.ts, src/api/__tests__/File.test.ts
Adds authenticated download and thumbnail URL generation, representation completion checks, and polling. Thumbnail tests type results as string | null.
File descriptions and retrieval
src/api/File.ts, src/api/__tests__/File.test.ts
Adds description updates and cached file retrieval, including extension retrieval. Updates test imports and uses noop callbacks in the destroyed-file case.
Web-link retrieval and type updates
src/api/WebLink.ts, src/api/__tests__/WebLink.test.ts, src/utils/__tests__/flatten.test.ts
Adds web-link URL construction and cached retrieval. Updates test setup to use APIOptions types.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Possibly related PRs

Suggested reviewers: vitali-usik, tjiang-box, jpan-box

Merge Risk: Minimal · up to 48c97

This change migrates the File and WebLink API clients to TypeScript and keeps Flow type definitions for existing consumers. No concrete regression was found, and the merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: migrating the WebLink and File APIs from Flow to TypeScript. The changeset renames the implementations and tests to .ts, adds .js.flow files, and adds as APIOptions ca…
Description check Passed The description follows the repository's content: it names the converted files, lists the test renames and .js.flow backward-compatibility files, notes the flatten.test.ts type fallout, and records th…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: migrating the WebLink and File APIs from Flow to TypeScript. The changeset renames the implementations and tests to .ts, adds .js.flow files, and adds as APIOptions casts in flatten.test.ts. The title is concise and matches the primary change.

Full details: Description check

Explanation

The description follows the repository's content: it names the converted files, lists the test renames and .js.flow backward-compatibility files, notes the flatten.test.ts type fallout, and records the one contract change to File.getThumbnailUrl. The template is a reviewer-workflow note about the ready-to-merge label and has no required fields to fill. The description covers the template's intent, so it passes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit checks the file URL,
Then waits for views to finish too.
A token joins the download stream,
Cached fields return as seen.
Web links hop back with typed fields.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 60984e73-c645-4a8d-8068-e9edbd4d3396
Commits

Reviewing files that changed from the base of the PR and between fcd5d5b and 48c9756.

Files selected for processing: 7

  • src/api/File.js.flow
  • src/api/File.ts
  • src/api/WebLink.js.flow
  • src/api/WebLink.ts
  • src/api/__tests__/File.test.ts
  • src/api/__tests__/WebLink.test.ts
  • src/utils/__tests__/flatten.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

This branch has not been deployed

No deployments
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.

1 participant