-
Notifications
You must be signed in to change notification settings - Fork 2.2k
refactor: migrate collaborator api #9605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
✅ Circular References ReportGenerated at: 2026-01-27T06:51:23.295Z Summary
Click to view all circular references in PR (85)Click to view all circular references in base branch (85)Analysis✅ No Change: This PR does not introduce or remove any circular references. This report was generated automatically by comparing against the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors collaborator API calls by migrating them from direct insomniaFetch calls to a centralized insomnia-api package. This improves code organization and maintainability by consolidating API client logic.
Changes:
- Created new
collaborators.tsmodule ininsomnia-apipackage with type definitions and API functions for all collaborator-related endpoints - Updated imports across multiple files to use the new API functions from
insomnia-apiinstead of direct fetch calls - Removed duplicate type definitions from consumer files and centralized them in the API package
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/insomnia-api/src/collaborators.ts | New module containing all collaborator API functions (getCollaborators, searchCollaborators, startAddingCollaborators, finishAddingCollaborators, unlinkCollaborator, getRealTimeCollaborators) and related types |
| packages/insomnia-api/src/index.ts | Added export for the new collaborators module |
| packages/insomnia/src/ui/context/app/insomnia-event-stream-context.tsx | Migrated getRealTimeCollaborators call and imported UserPresence type from insomnia-api |
| packages/insomnia/src/ui/components/modals/invite-modal/invite-modal.tsx | Imported Collaborator type and unlinkCollaborator function from insomnia-api |
| packages/insomnia/src/ui/components/modals/invite-modal/encryption.ts | Migrated startAddingCollaborators and finishAddingCollaborators calls to use insomnia-api |
| packages/insomnia/src/routes/organization.$organizationId.collaborators.tsx | Replaced direct fetch with getCollaborators function, removed duplicate type definitions |
| packages/insomnia/src/routes/organization.$organizationId.collaborators-search.tsx | Replaced direct fetch with searchCollaborators function, removed duplicate types |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return fetch<CollaboratorsListResult>({ | ||
| method: 'GET', | ||
| path: `/v1/desktop/organizations/${organizationId}/collaborators?per_page=${pageLimit}&page=${page}&filter=${filter}`, |
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The URL query parameters are not properly handled for optional values. When filter is undefined, it will be appended to the URL as the string "undefined" (e.g., &filter=undefined), which will be sent to the server as a literal string. The original implementation conditionally appended these parameters only when they had values. Consider using URLSearchParams or conditionally building the query string to avoid sending "undefined" values to the API.
| return fetch<CollaboratorsListResult>({ | |
| method: 'GET', | |
| path: `/v1/desktop/organizations/${organizationId}/collaborators?per_page=${pageLimit}&page=${page}&filter=${filter}`, | |
| const params = new URLSearchParams(); | |
| params.set('per_page', String(pageLimit)); | |
| if (page !== undefined) { | |
| params.set('page', String(page)); | |
| } | |
| if (filter !== undefined) { | |
| params.set('filter', filter); | |
| } | |
| return fetch<CollaboratorsListResult>({ | |
| method: 'GET', | |
| path: `/v1/desktop/organizations/${organizationId}/collaborators?${params.toString()}`, |
| }); | ||
| }; | ||
|
|
||
| type CollaboratorType = 'invite' | 'member' | 'group'; |
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type ordering inconsistency: The CollaboratorType type is defined after the Collaborator interface that uses it. While TypeScript hoisting handles this, it's better practice to define types before they are referenced for better readability and maintainability.
|
|
||
| type CollaboratorType = 'invite' | 'member' | 'group'; | ||
|
|
||
| interface CollaboratorSearchResultItem { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we unify CollaboratorSearchResultItem with Collaborator?
| | (PaginatedList & { | ||
| collaborators: Collaborator[]; | ||
| }) | ||
| | Error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this shouldn't return an error.
| }) => { | ||
| return fetch<CollaboratorsListResult>({ | ||
| method: 'GET', | ||
| path: `/v1/desktop/organizations/${organizationId}/collaborators?per_page=${pageLimit}&page=${page}&filter=${filter}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This path uses a template, so pageLimit, page and filter should have default value of be required value
| onlyResolveOnSuccess: true, | ||
| }).catch(error => { | ||
| try { | ||
| return unlinkCollaborator({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add await before unlinkCollaborator? Otherwise try/catch doesn't work
Migrate collaborator apis into
insomnia-apipackage: