refactor: move organization to service layer#9973
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors organization and project migration/sync logic out of UI utilities and into common/service layers, aligning organization-related behavior with the data service architecture.
Changes:
- Replaces
~/ui/organization-utilsimports with~/common/organization. - Moves project migration, cloud project sync, and workspace commit/push helpers into
insomnia-dataservices. - Removes old UI/sync migration utility modules and updates route callers to use service methods.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
packages/insomnia/src/ui/organization-utils.ts |
Removes the old UI organization utility module. |
packages/insomnia/src/sync/vcs/migrate-projects-into-organization.ts |
Removes the old migration helper module. |
packages/insomnia/src/sync/vcs/initialize-backend-project.ts |
Delegates snapshot creation to workspace services and renames push org parameter. |
packages/insomnia/src/common/organization.ts |
Adds common organization sync exports and project sync wrapper. |
packages/insomnia/src/insomnia-data/node-src/services/project.ts |
Adds project migration, backend project sync, local project push, and lookup service methods. |
packages/insomnia/src/insomnia-data/node-src/services/workspace.ts |
Adds workspace lookup, commit, commit-and-push, and git metadata helpers. |
packages/insomnia/src/insomnia-data/node-src/services/vcs.ts |
Adds shared VCS-related service types. |
packages/insomnia/src/insomnia-data/node-src/services/organization.ts |
Adds organization scratchpad check and project sync service wrapper. |
packages/insomnia/src/routes/trial.start.tsx |
Inlines current plan sync after trial start. |
packages/insomnia/src/routes/organization.sync.tsx |
Updates organization sync import. |
packages/insomnia/src/routes/organization.sync-organizations-and-projects.tsx |
Uses service-layer migration and project lookup. |
packages/insomnia/src/routes/organization.$organizationId.sync-projects.tsx |
Updates project sync import. |
packages/insomnia/src/routes/organization.$organizationId.storage-rules.tsx |
Updates storage rule import. |
packages/insomnia/src/routes/organization.$organizationId.project.$projectId.workspace.$workspaceId.spec.tsx |
Updates storage rules constant import. |
packages/insomnia/src/routes/organization.$organizationId.project.$projectId.tsx |
Updates storage rules constant import. |
packages/insomnia/src/routes/organization.$organizationId.project.$projectId._index.tsx |
Updates storage rules constant import. |
packages/insomnia/src/routes/organization.$organizationId.project._index.tsx |
Updates storage rules constant import. |
packages/insomnia/src/routes/organization.$organizationId._index.tsx |
Updates project sync import. |
packages/insomnia/src/routes/organization._index.tsx |
Uses service-layer migration. |
packages/insomnia/src/routes/onboarding.migrate.tsx |
Uses service-layer migration detection. |
packages/insomnia/src/ui/components/dropdowns/git-project-sync-dropdown.tsx |
Updates storage rules constant import. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| export async function migrateProjectsUnderOrganization(orgId: string, preferredProjectType: string | null) { | ||
| if (await hasProjectsToMigrate()) { | ||
| await migrateProjectsIntoOrganization(orgId); | ||
|
|
||
| if (preferredProjectType === 'remote') { | ||
| const localProjects = await getLocalProjectsOfOrg(orgId); | ||
|
|
||
| // If any of those fail projects will still be under the organization as local projects | ||
| for (const project of localProjects) { | ||
| try { | ||
| await pushLocalProject({ | ||
| project, | ||
| organizationId: orgId, | ||
| vcs: window.main.sync, |
| await commitAll({ workspace, vcs, message }); | ||
| // Mark for pushing to the active project | ||
| await updateMetaByParentId(workspace._id, { pushSnapshotOnInitialize: true }); | ||
| const hasProject = await vcs.hasBackendProject(); | ||
| if (projectId === workspace.parentId && hasProject && projectRemoteId) { | ||
| await updateMetaByParentId(workspace._id, { pushSnapshotOnInitialize: false }); // after below? | ||
| await vcs.push({ teamId: orgId, teamProjectId: projectRemoteId }); |
✅ Circular References ReportGenerated at: 2026-05-28T06:27:22.165Z Summary
Click to view all circular references in PR (18)Click to view all circular references in base branch (18)Analysis✅ No Change: This PR does not introduce or remove any circular references. This report was generated automatically by comparing against the |
62507fa to
d943b0b
Compare
d943b0b to
0062ec4
Compare
0062ec4 to
dba4640
Compare
| vcs: SyncVCSLike; | ||
| message: string; | ||
| }) { | ||
| if (!vcs.hasBackendProject()) { |
There was a problem hiding this comment.
| if (!vcs.hasBackendProject()) { | |
| if (!(await vcs.hasBackendProject())) { |
| message: string; | ||
| project: Project; | ||
| }) { | ||
| if (!vcs.hasBackendProject()) { |
There was a problem hiding this comment.
| if (!vcs.hasBackendProject()) { | |
| if (!(await vcs.hasBackendProject())) { |
| export interface SyncVCSLike { | ||
| hasBackendProject: () => boolean | Promise<boolean>; | ||
| push: (options: { teamId: string; teamProjectId: string }) => Promise<void>; | ||
| stage: (stageEntries: StageEntry[]) => Promise<Stage>; | ||
| status: (candidates: StatusCandidate[]) => Promise<Status>; | ||
| switchAndCreateBackendProjectIfNotExist: (rootDocumentId: string, name: string) => Promise<void>; | ||
| takeSnapshot: (name: string) => Promise<void>; |
There was a problem hiding this comment.
Duplicate with packages/insomnia/src/sync/vcs/initialize-backend-project.ts#L6-L13
|
|
||
| export async function syncProjectsOfOrg(organizationId: string) { | ||
| const user = await userSessionService.get(); | ||
| const teamProjects = await getAllTeamProjects(organizationId); |
There was a problem hiding this comment.
getAllTeamProjects is only used here. Maybe it's unnecessary to extract as a service at this moment. As well as syncProjectsWithBackend.
| const user = await userSessionService.get(); | ||
| const teamProjects = await getAllTeamProjects(organizationId); | ||
| // ensure we don't sync projects in the wrong place | ||
| if (Array.isArray(teamProjects) && user.id && !isScratchpad(organizationId)) { |
There was a problem hiding this comment.
We can check scratch and user id before calling getAllTeamProjects. It introduce unnecessary api calls.
| }); | ||
| } | ||
|
|
||
| export async function pushLocalProject({ |
There was a problem hiding this comment.
This is only used in this file, shouldn't be exported.
INS-2682