Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ jobs:
- name: Lint
run: npm run lint

- name: Check renderer Node import baseline
run: npm run check:renderer-node-imports

- name: Type checks
run: npm run type-check

Expand Down
56 changes: 0 additions & 56 deletions packages/insomnia/config/renderer-node-import-baseline.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/insomnia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
"verify-bundle-plugins": "esr --cache ./scripts/verify-bundle-plugins.ts",
"install-x64-native-dependencies": "esr --cache ./scripts/install-x64-native-dependencies.ts",
"build": "react-router build && esr --cache ./scripts/build.ts --noErrorTruncation",
"analyze:renderer-node-imports": "cross-env NODE_OPTIONS=--max-old-space-size=8192 INSOMNIA_NODE_IMPORT_REPORT=1 react-router build",
"check:renderer-node-imports": "npm run analyze:renderer-node-imports && esr --cache ./scripts/check-renderer-node-imports.ts",
"update:renderer-node-import-baseline": "npm run analyze:renderer-node-imports && esr --cache ./scripts/check-renderer-node-imports.ts --write-baseline",
"build:react-router": "react-router build",
"generate:schema": "esr ./src/schema.ts",
"build:electron-entrypoints": "cross-env NODE_ENV=development esr esbuild.entrypoints.ts",
Expand Down
115 changes: 0 additions & 115 deletions packages/insomnia/scripts/check-renderer-node-imports.ts

This file was deleted.

12 changes: 7 additions & 5 deletions packages/insomnia/src/account/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { models, services } from '~/insomnia-data';

import { AI_PLUGIN_NAME, LLM_BACKENDS } from '../common/constants';
import { database } from '../common/database';
import * as crypt from './crypt';
import type { AESMessage } from './crypt';

export interface SessionData {
accountId: string;
Expand All @@ -15,7 +15,7 @@ export interface SessionData {
lastName: string;
symmetricKey: JsonWebKey;
publicKey: JsonWebKey;
encPrivateKey: crypt.AESMessage;
encPrivateKey: AESMessage;
}

/** Creates a session from a sessionId and derived symmetric key. */
Expand All @@ -28,7 +28,8 @@ export async function absorbKey(sessionId: string, key: string) {
]);
const { public_key: publicKey, enc_private_key: encPrivateKey, enc_symmetric_key: encSymmetricKey } = keys;
const { email, id: accountId, first_name: firstName, last_name: lastName } = profile;
const symmetricKeyStr = crypt.decryptAES(key, JSON.parse(encSymmetricKey));
const { decryptAES } = await import('./crypt');
const symmetricKeyStr = decryptAES(key, JSON.parse(encSymmetricKey));

// Store the information for later
await setSessionData(
Expand Down Expand Up @@ -58,7 +59,8 @@ export async function getPrivateKey() {
throw new Error("Can't get private key: session is missing keys.");
}

const privateKeyStr = crypt.decryptAES(symmetricKey, encPrivateKey);
const { decryptAES } = await import('./crypt');
const privateKeyStr = decryptAES(symmetricKey, encPrivateKey);
return JSON.parse(privateKeyStr) as JsonWebKey;
}

Expand Down Expand Up @@ -105,7 +107,7 @@ export async function setSessionData(
email: string,
symmetricKey: JsonWebKey,
publicKey: JsonWebKey,
encPrivateKey: crypt.AESMessage,
encPrivateKey: AESMessage,
) {
const sessionData: SessionData = {
id,
Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia/src/common/__tests__/har.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Cookie, Request, Response } from '~/insomnia-data';
import { models, services } from '~/insomnia-data';

import { database as db } from '../../common/database';
import { exportHar, exportHarResponse, exportHarWithRequest } from '../har';
import { exportHar, exportHarResponse, exportHarWithRequest } from '../../main/har';
import { getRenderedRequestAndContext } from '../render';

describe('export', () => {
Expand Down
61 changes: 61 additions & 0 deletions packages/insomnia/src/common/cookies.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import type * as Har from 'har-format';
import { Cookie as ToughCookie, CookieJar, type CookieJSON } from 'tough-cookie';

import type { Cookie } from '~/insomnia-data';

import { getSetCookieHeaders } from './misc';

/**
* Get a list of cookie objects from a request.jar()
*/
Expand Down Expand Up @@ -47,6 +50,64 @@ export const jarFromCookies = (cookies: Cookie[] | ToughCookie[]) => {
return jar;
};

export function mapCookie(cookie: ToughCookie): Har.Cookie {
const harCookie: Har.Cookie = {
name: cookie.key,
value: cookie.value,
};

if (cookie.path) {
harCookie.path = cookie.path;
}

if (cookie.domain) {
harCookie.domain = cookie.domain;
}

if (cookie.expires) {
let expires: Date | null = null;

if (cookie.expires instanceof Date) {
expires = cookie.expires;
} else if (typeof cookie.expires === 'string') {
expires = new Date(cookie.expires);
} else if (typeof cookie.expires === 'number') {
expires = new Date();
expires.setTime(cookie.expires);
}

if (expires && !Number.isNaN(expires.getTime())) {
harCookie.expires = expires.toISOString();
}
}

if (cookie.httpOnly) {
harCookie.httpOnly = true;
}

if (cookie.secure) {
harCookie.secure = true;
}

return harCookie;
}

export function getResponseCookiesFromHeaders(headers: Har.Cookie[]) {
return getSetCookieHeaders(headers).reduce((accumulator, harCookie) => {
let cookie: null | undefined | ToughCookie = null;

try {
cookie = ToughCookie.parse(harCookie.value || '', { loose: true });
} catch {}

if (cookie === null || cookie === undefined) {
return accumulator;
}

return [...accumulator, mapCookie(cookie)];
}, [] as Har.Cookie[]);
}

export const cookieToString = (cookie: Parameters<typeof ToughCookie.fromJSON>[0] | ToughCookie) => {
// Cookie can either be a plain JS object or Cookie instance
if (!(cookie instanceof ToughCookie)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/insomnia/src/entry.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { HydratedRouter } from 'react-router/dom';

import { insomniaFetch } from '~/common/insomnia-fetch';
import { initDatabase, initServices, services } from '~/insomnia-data';
import { plugins } from '~/plugins/renderer-bridge';
import { database as clientDatabase } from '~/ui/database.client';
import { clearOAuthWindowSessionId } from '~/ui/spawn-oauth-window';

import { migrateFromLocalStorage, type SessionData, setSessionData, setVaultSessionData } from './account/session';
import { getInsomniaSession, getInsomniaVaultKey, getInsomniaVaultSalt, getSkipOnboarding } from './common/constants';
import { init as initPlugins } from './plugins';
import { applyColorScheme } from './plugins/misc';
import { registerSyncMergeConflictListener } from './sync/vcs/insomnia-sync';
import { HtmlElementWrapper } from './ui/components/html-element-wrapper';
Expand All @@ -40,7 +40,7 @@ delete window._dataServices;

configureFetch(options => insomniaFetch({ ...options, onDeepLink: (uri: string) => window.main.openDeepLink(uri) }));

await initPlugins();
await plugins.reloadPlugins();

await migrateFromLocalStorage();
registerSyncMergeConflictListener();
Expand Down
8 changes: 8 additions & 0 deletions packages/insomnia/src/entry.preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ const main: Window['main'] = {
writeFile: options => invokeWithNormalizedError('writeFile', options),
deleteRulesetFile: options => invokeWithNormalizedError('deleteRulesetFile', options),
writeResponseBodyToFile: options => invokeWithNormalizedError('writeResponseBodyToFile', options),
exportHarRequest: (requestId, environmentOrWorkspaceId, addContentLength) =>
invokeWithNormalizedError('exportHarRequest', requestId, environmentOrWorkspaceId, addContentLength),
exportHarCurrentRequest: (requestId, responseId) =>
invokeWithNormalizedError('exportHarCurrentRequest', requestId, responseId),
exportWorkspacesHAR: (workspaceIds, includePrivateDocs) =>
invokeWithNormalizedError('exportWorkspacesHAR', workspaceIds, includePrivateDocs),
exportRequestsHAR: (requestIds, includePrivateDocs) =>
invokeWithNormalizedError('exportRequestsHAR', requestIds, includePrivateDocs),
getAuthHeader: (renderedRequest: RenderedRequest, url: string): Promise<RequestHeader | undefined> =>
invokeWithNormalizedError('getAuthHeader', renderedRequest, url),
getOAuth2Token: (
Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia/src/insomnia-data/src/models/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type ThemeSettings = Pick<Settings, 'autoDetectColorScheme' | 'lightTheme
export const isSettings = (model: Pick<BaseModel, 'type'>): model is Settings => model.type === type;

// force vertical layout for playwright tests to avoid horizontal scrolling issues
const forceVerticalLayout = process.env.PLAYWRIGHT_TEST ? true : false;
const forceVerticalLayout = (typeof window !== 'undefined' ? window.env?.PLAYWRIGHT_TEST : process.env.PLAYWRIGHT_TEST) ? true : false;

export function init(): BaseSettings {
return {
Expand Down
Loading
Loading