Skip to content

Commit

Permalink
Merge branch 'develop' into feat-send-progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ihexxa authored May 16, 2024
2 parents 4e632b6 + 9b0654f commit 0d25008
Show file tree
Hide file tree
Showing 21 changed files with 177 additions and 86 deletions.
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,37 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [core@9.2.0] - 2024-05-15

## What's Changed

- :rocket: 9.1.1 by @insomnia-infra in <https://github.com/Kong/insomnia/pull/7386>

- Types/ipc-channels by @jackkav in <https://github.com/Kong/insomnia/pull/7379>
- fix(analytics): add missing session id by @gatzjames in <https://github.com/Kong/insomnia/pull/7389>
- point changelog url at releases by @jackkav in <https://github.com/Kong/insomnia/pull/7387>
- fix: add missing 9.1.1 changelog [no-ticket] by @filfreire in <https://github.com/Kong/insomnia/pull/7392>
- fixes codemirror measure issue by @jackkav in <https://github.com/Kong/insomnia/pull/7391>
- fix: extract correct position through err message by @CurryYangxx in <https://github.com/Kong/insomnia/pull/7398>
- fix(ui): Misalignments in the UI by @gatzjames in <https://github.com/Kong/insomnia/pull/7400>
- fix: environment edit modal save by @oahmed-OS in <https://github.com/Kong/insomnia/pull/7371>
- perf: improve performance when spec lint [INS-3724] by @CurryYangxx in <https://github.com/Kong/insomnia/pull/7374>
- improve VCS api by @jackkav in <https://github.com/Kong/insomnia/pull/7404>
- Feat: add-faker by @jackkav in <https://github.com/Kong/insomnia/pull/7390>
- fix(Preferences): Error when there is no active project in the preferences data tab by @gatzjames in <https://github.com/Kong/insomnia/pull/7406>
- feat(command-palette): Add global search for unsynced files by @gatzjames in <https://github.com/Kong/insomnia/pull/7405>
- only prompt with private envs by @jackkav in <https://github.com/Kong/insomnia/pull/7407>
- fix(Project): Show errors when something goes wrong while updating projects by @gatzjames in <https://github.com/Kong/insomnia/pull/7412>
- fix(Spec): Expand lint errors and hide the preview pane appropriately by @gatzjames in <https://github.com/Kong/insomnia/pull/7413>
- fix(CloudSync Pull): Fix issue where workspaces could change parentId on pull by @gatzjames in <https://github.com/Kong/insomnia/pull/7414>
- fix(UI): add titles to some elements in Test view by @filfreire in <https://github.com/Kong/insomnia/pull/7416>

## New Contributors

- @oahmed-OS made their first contribution in <https://github.com/Kong/insomnia/pull/7371>

**Full Changelog**: <https://github.com/Kong/insomnia/compare/core@9.1.1...core@9.2.0>

## [core@9.1.1] - 2024-05-07

## What's Changed
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/insomnia-inso/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "insomnia-inso",
"version": "9.2.0-beta.0",
"version": "9.2.0",
"homepage": "https://insomnia.rest",
"description": "A CLI for Insomnia - The Collaborative API Design Tool",
"author": "Kong <office@konghq.com>",
Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "insomnia-sdk",
"version": "9.2.0-beta.0",
"version": "9.2.0",
"description": "",
"main": "src/objects/index.ts",
"types": "src/objects/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia-send-request/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": true,
"name": "insomnia-send-request",
"license": "Apache-2.0",
"version": "9.2.0-beta.0",
"version": "9.2.0",
"author": "Kong <office@konghq.com>",
"main": "dist/index.js",
"types": "dist/send-request/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia-smoke-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"bugs": {
"url": "https://github.com/kong/insomnia/issues"
},
"version": "9.2.0-beta.0",
"version": "9.2.0",
"scripts": {
"test:dev": "xvfb-maybe cross-env BUNDLE=dev playwright test",
"test:build": "xvfb-maybe cross-env BUNDLE=build playwright test",
Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": true,
"name": "insomnia-testing",
"license": "Apache-2.0",
"version": "9.2.0-beta.0",
"version": "9.2.0",
"author": "Kong <office@konghq.com>",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "insomnia",
"version": "9.2.0-beta.0",
"version": "9.2.0",
"productName": "Insomnia",
"private": true,
"description": "The Collaborative API Design Tool",
Expand Down
61 changes: 34 additions & 27 deletions packages/insomnia/src/common/export.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import YAML from 'yaml';

import { isApiSpec } from '../models/api-spec';
import { isCookieJar } from '../models/cookie-jar';
import { isEnvironment } from '../models/environment';
import { Environment, isEnvironment } from '../models/environment';
import { isGrpcRequest } from '../models/grpc-request';
import * as requestOperations from '../models/helpers/request-operations';
import type { BaseModel } from '../models/index';
import { type BaseModel, environment } from '../models/index';
import * as models from '../models/index';
import { isProtoDirectory } from '../models/proto-directory';
import { isProtoFile } from '../models/proto-file';
Expand Down Expand Up @@ -375,7 +375,18 @@ export const exportProjectToFile = (activeProjectName: string, workspacesForActi

showSelectExportTypeModal({
onDone: async selectedFormat => {
const exportPrivateEnvironments = await showExportPrivateEnvironmentsModal();
const baseEnvironments = await database.find<Environment>(environment.type, {
parentId: { $in: workspacesForActiveProject.map(w => w._id) },
});

const subEnvironments = await database.find<Environment>(environment.type, {
parentId: { $in: baseEnvironments.map(w => w._id) },
});
const shouldPrompt = subEnvironments.some(e => e.isPrivate);
let shouldExportPrivateEnvironments = false;
if (shouldPrompt) {
shouldExportPrivateEnvironments = await showExportPrivateEnvironmentsModal();
}
const fileName = await showSaveExportedFileDialog({
exportedFileNamePrefix: activeProjectName,
selectedFormat,
Expand All @@ -390,15 +401,15 @@ export const exportProjectToFile = (activeProjectName: string, workspacesForActi
try {
switch (selectedFormat) {
case VALUE_HAR:
stringifiedExport = await exportWorkspacesHAR(workspacesForActiveProject, exportPrivateEnvironments);
stringifiedExport = await exportWorkspacesHAR(workspacesForActiveProject, shouldExportPrivateEnvironments);
break;

case VALUE_YAML:
stringifiedExport = await exportWorkspacesData(workspacesForActiveProject, exportPrivateEnvironments, 'yaml');
stringifiedExport = await exportWorkspacesData(workspacesForActiveProject, shouldExportPrivateEnvironments, 'yaml');
break;

case VALUE_JSON:
stringifiedExport = await exportWorkspacesData(workspacesForActiveProject, exportPrivateEnvironments, 'json');
stringifiedExport = await exportWorkspacesData(workspacesForActiveProject, shouldExportPrivateEnvironments, 'json');
break;

default:
Expand Down Expand Up @@ -480,32 +491,28 @@ export const exportMockServerToFile = async (workspace: Workspace) => {
});

};
export const exportRequestsToFile = (requestIds: string[]) => {
export const exportRequestsToFile = (workspaceId: string, requestIds: string[]) => {
showSelectExportTypeModal({
onDone: async selectedFormat => {
const requests: BaseModel[] = [];
const workspaceLookup: any = {};
for (const requestId of requestIds) {
const request = await requestOperations.getById(requestId);

if (request == null) {
continue;
}

requests.push(request);
const ancestors = await database.withAncestors(request, [
models.workspace.type,
models.requestGroup.type,
]);
const workspace = ancestors.find(isWorkspace);

if (workspace == null || workspaceLookup.hasOwnProperty(workspace._id)) {
continue;
if (request) {
requests.push(request);
}
}
const [baseEnvironment] = await database.find<Environment>(environment.type, {
parentId: workspaceId,
});

workspaceLookup[workspace._id] = true;
const subEnvironments = await database.find<Environment>(environment.type, {
parentId: baseEnvironment?._id,
});
const shouldPrompt = subEnvironments.some(e => e.isPrivate);
let shouldExportPrivateEnvironments = false;
if (shouldPrompt) {
shouldExportPrivateEnvironments = await showExportPrivateEnvironmentsModal();
}
const exportPrivateEnvironments = await showExportPrivateEnvironmentsModal();
const fileName = await showSaveExportedFileDialog({
exportedFileNamePrefix: 'Insomnia',
selectedFormat,
Expand All @@ -520,15 +527,15 @@ export const exportRequestsToFile = (requestIds: string[]) => {
try {
switch (selectedFormat) {
case VALUE_HAR:
stringifiedExport = await exportRequestsHAR(requests, exportPrivateEnvironments);
stringifiedExport = await exportRequestsHAR(requests, shouldExportPrivateEnvironments);
break;

case VALUE_YAML:
stringifiedExport = await exportRequestsData(requests, exportPrivateEnvironments, 'yaml');
stringifiedExport = await exportRequestsData(requests, shouldExportPrivateEnvironments, 'yaml');
break;

case VALUE_JSON:
stringifiedExport = await exportRequestsData(requests, exportPrivateEnvironments, 'json');
stringifiedExport = await exportRequestsData(requests, shouldExportPrivateEnvironments, 'json');
break;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('pullBackendProject()', () => {
const request = requests[0];
expect(request).toStrictEqual(existingReq);

expect(vcs.pull).toHaveBeenCalledWith({ candidates: [], teamId: project?.parentId, teamProjectId: project?._id });
expect(vcs.pull).toHaveBeenCalledWith({ candidates: [], teamId: project?.parentId, teamProjectId: project?._id, projectId: project?._id });
});
});

Expand Down
31 changes: 16 additions & 15 deletions packages/insomnia/src/sync/vcs/pull-backend-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export const pullBackendProject = async ({ vcs, backendProject, remoteProject }:

const defaultBranchMissing = !remoteBranches.includes(DEFAULT_BRANCH_NAME);

let workspaceId;

// @TODO Revisit the UX for this. What should happen if there are other branches?
// The default branch does not exist, so we create it and the workspace locally
if (defaultBranchMissing) {
const workspace = await models.initModel<Workspace>(
Expand All @@ -41,23 +40,25 @@ export const pullBackendProject = async ({ vcs, backendProject, remoteProject }:

await database.upsert(workspace);

workspaceId = workspace._id;
} else {
await vcs.pull({ candidates: [], teamId: remoteProject.parentId, teamProjectId: remoteProject._id }); // There won't be any existing docs since it's a new pull
return { project: remoteProject, workspaceId: workspace._id };
}

const flushId = await database.bufferChanges();
await vcs.pull({ candidates: [], teamId: remoteProject.parentId, teamProjectId: remoteProject._id, projectId: remoteProject._id }); // There won't be any existing docs since it's a new pull

// @ts-expect-error -- TSCONVERSION
for (const doc of (await vcs.allDocuments()) || []) {
if (isWorkspace(doc)) {
doc.parentId = remoteProject._id;
workspaceId = doc._id;
}
await database.upsert(doc);
const flushId = await database.bufferChanges();
let workspaceId;
// @ts-expect-error -- TSCONVERSION
for (const doc of (await vcs.allDocuments()) || []) {
// When we pull a BackendProject we need to update the parent ID of the workspace so that it appears inside.
// There can't be more than one workspace.
if (isWorkspace(doc)) {
doc.parentId = remoteProject._id;
workspaceId = doc._id;
}

await database.flushChanges(flushId);
await database.upsert(doc);
}

await database.flushChanges(flushId);
return { project: remoteProject, workspaceId };

};
13 changes: 11 additions & 2 deletions packages/insomnia/src/sync/vcs/vcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import path from 'path';

import * as crypt from '../../account/crypt';
import * as session from '../../account/session';
import type { Operation } from '../../common/database';
import { generateId } from '../../common/misc';
import { BaseModel } from '../../models';
import { insomniaFetch } from '../../ui/insomniaFetch';
Expand Down Expand Up @@ -577,7 +578,7 @@ export class VCS {
console.log(`[sync] Created commit ${snapshot.id} (${name})`);
}

async pull({ candidates, teamId, teamProjectId }: { candidates: StatusCandidate[]; teamId: string; teamProjectId: string }) {
async pull({ candidates, teamId, teamProjectId, projectId }: { candidates: StatusCandidate[]; teamId: string; teamProjectId: string; projectId: string }) {
await this._getOrCreateRemoteBackendProject({ teamId, teamProjectId });
const localBranch = await this._getCurrentBranch();
const tmpBranchForRemote = await this.customFetch(localBranch.name + '.hidden', localBranch.name);
Expand All @@ -589,10 +590,18 @@ export class VCS {
tmpBranchForRemote.name,
message,
true,
);
) as unknown as Operation;
// Remove tmp branch
await this._removeBranch(tmpBranchForRemote);
console.log(`[sync] Pulled branch ${localBranch.name}`);

// vcs.pull sometimes results in a delta with parentId: null, causing workspaces to be orphaned, this is a hack to restore those parentIds until we have a chance to redesign vcs
delta.upsert?.forEach(doc => {
if (!doc.parentId && doc.type === 'Workspace') {
doc.parentId = projectId;
}
});

return delta;
}

Expand Down
10 changes: 10 additions & 0 deletions packages/insomnia/src/ui/components/dropdowns/project-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ export const ProjectDropdown: FC<Props> = ({ project, organizationId, storage })
});
}
}, [deleteProjectFetcher.data, deleteProjectFetcher.state]);

useEffect(() => {
if (updateProjectFetcher.data && updateProjectFetcher.data.error && updateProjectFetcher.state === 'idle') {
showAlert({
title: 'Could not update project',
message: updateProjectFetcher.data.error,
});
}
}, [updateProjectFetcher.data, updateProjectFetcher.state]);

const defaultStorageSelection = storage === 'local_only' ? 'local' : 'remote';
return (
<Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export const ExportRequestsModal = ({ workspace, onClose }: { workspace: Workspa
</Button>
<Button
onPress={() => {
state?.treeRoot && exportRequestsToFile(getSelectedRequestIds(state.treeRoot));
state?.treeRoot && exportRequestsToFile(workspace._id, getSelectedRequestIds(state.treeRoot));
close();
}}
isDisabled={isExportDisabled}
Expand Down
Loading

0 comments on commit 0d25008

Please sign in to comment.