Skip to content
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

Chore/flatten-plugins-cont #6186

Merged
merged 20 commits into from
Jul 25, 2023
Merged
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = {
project: [
'./tsconfig.eslint.json',
'./packages/*/tsconfig.json',
'./plugins/*/tsconfig.json',
],
tsconfigRootDir: __dirname,
ecmaFeatures: {
Expand Down
3 changes: 1 addition & 2 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"version": "3.19.0-beta.4",
"packages": [
"packages/*",
"plugins/*"
"packages/*"
]
}
4 changes: 0 additions & 4 deletions packages/insomnia-inso/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@
"consola": "^2.15.0",
"cosmiconfig": "^6.0.0",
"enquirer": "^2.3.6",
"insomnia-plugin-core-themes": "^3.19.0-beta.4",
"insomnia-plugin-default-headers": "^3.19.0-beta.4",
"insomnia-plugin-request": "^3.19.0-beta.4",
"insomnia-plugin-response": "^3.19.0-beta.4",
"insomnia-send-request": "^3.19.0-beta.4",
"insomnia-testing": "^3.19.0-beta.4",
"nedb": "^1.8.0",
Expand Down
8 changes: 1 addition & 7 deletions packages/insomnia/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,5 @@
"development": "rTOCSvGV23cHGJyb3HI9EUQDNA6ar7ay",
"production": "4l7QUfACrIcqvC913hiIwAA2BDYP2OJ1"
},
"sentryDsn": "https://aaec2e800e644070a8daba5b7ad02c16@o1147619.ingest.sentry.io/6311804",
"plugins": [
"insomnia-plugin-request",
"insomnia-plugin-response",
"insomnia-plugin-core-themes",
"insomnia-plugin-default-headers"
]
"sentryDsn": "https://aaec2e800e644070a8daba5b7ad02c16@o1147619.ingest.sentry.io/6311804"
}
4 changes: 0 additions & 4 deletions packages/insomnia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@
"html-entities": "^2.4.0",
"httpsnippet": "^2.0.0",
"iconv-lite": "^0.6.3",
"insomnia-plugin-core-themes": "^3.19.0-beta.4",
"insomnia-plugin-default-headers": "^3.19.0-beta.4",
"insomnia-plugin-request": "^3.19.0-beta.4",
"insomnia-plugin-response": "^3.19.0-beta.4",
"insomnia-testing": "^3.19.0-beta.4",
"isomorphic-git": "^1.10.4",
"js-yaml": "^3.14.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/insomnia/src/main.development.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import contextMenu from 'electron-context-menu';
import installExtension, { REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS } from 'electron-devtools-installer';
import path from 'path';

import appConfig from '../config/config.json';
import { userDataFolder } from '../config/config.json';
import { changelogUrl, getAppVersion, isDevelopment, isMac } from './common/constants';
import { database } from './common/database';
import log, { initializeLogging } from './common/log';
Expand Down Expand Up @@ -39,7 +39,7 @@ if (envDataPath) {
} else {
// Explicitly set userData folder from config because it's sketchy to rely on electron-builder to use productName, which could be changed by accident.
const defaultPath = app.getPath('userData');
const newPath = path.join(defaultPath, '../', isDevelopment() ? 'insomnia-app' : appConfig.userDataFolder);
const newPath = path.join(defaultPath, '../', isDevelopment() ? 'insomnia-app' : userDataFolder);
app.setPath('userData', newPath);
}

Expand Down
69 changes: 45 additions & 24 deletions packages/insomnia/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import electron from 'electron';
import fs from 'fs';
import path from 'path';

import appConfig from '../../config/config.json';
import { ParsedApiSpec } from '../common/api-specs';
import { resolveHomePath } from '../common/misc';
import type { PluginConfig, PluginConfigMap } from '../common/settings';
Expand All @@ -14,6 +13,7 @@ import type { Workspace } from '../models/workspace';
import type { PluginTemplateTag } from '../templating/extensions/index';
import { showError } from '../ui/components/modals/index';
import type { PluginTheme } from './misc';
import themes from './themes';

export interface Module {
templateTags?: PluginTemplateTag[];
Expand Down Expand Up @@ -209,26 +209,6 @@ export async function getPlugins(force = false): Promise<Plugin[]> {
// "name": "module"
};

for (const p of appConfig.plugins) {
if (ignorePlugins.includes(p)) {
continue;
}

try {
const pluginJson = global.require(`${p}/package.json`);

if (ignorePlugins.includes(pluginJson.name)) {
continue;
}

const pluginModule = global.require(p);

pluginMap[pluginJson.name] = _initPlugin(pluginJson, pluginModule, allConfigs);
} catch (err) {
console.error(`[plugin] Failed to load plugin: ${p}`, err);
}
}

await _traversePluginPath(pluginMap, allPaths, allConfigs);
plugins = Object.keys(pluginMap).map(name => pluginMap[name]);
}
Expand Down Expand Up @@ -330,7 +310,37 @@ export async function getTemplateTags(): Promise<TemplateTag[]> {
}

export async function getRequestHooks(): Promise<RequestHook[]> {
let functions: RequestHook[] = [];
let functions: RequestHook[] = [{
plugin: {
name: 'default-headers',
description: 'Set default headers for all requests',
version: '0.0.0',
directory: '',
config: {
disabled: false,
},
module: {},
},
hook: context => {
const headers = context.request.getEnvironmentVariable('DEFAULT_HEADERS');
if (!headers) {
return;
}
for (const name of Object.keys(headers)) {
const value = headers[name];
if (context.request.hasHeader(name)) {
console.log(`[header] Skip setting default header ${name}. Already set to ${value}`);
continue;
}
if (value === 'null') {
context.request.removeHeader(name);
console.log(`[header] Remove default header ${name}`);
} else {
context.request.setHeader(name, value);
console.log(`[header] Set default header ${name}: ${value}`);
}
}
} }];

for (const plugin of await getActivePlugins()) {
const moreFunctions = plugin.module.requestHooks || [];
Expand Down Expand Up @@ -364,8 +374,19 @@ export async function getResponseHooks(): Promise<ResponseHook[]> {
}

export async function getThemes(): Promise<Theme[]> {
let extensions: Theme[] = [];

let extensions = themes.map(theme => ({
plugin: {
name: theme.name,
description: 'Built-in themes',
version: '0.0.0',
directory: '',
config: {
disabled: false,
},
module: {},
},
theme,
})) as Theme[];
for (const plugin of await getActivePlugins()) {
const themes = plugin.module.themes || [];
extensions = [
Expand Down
21 changes: 21 additions & 0 deletions packages/insomnia/src/plugins/themes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

import r from './themes/colorblind-dark';
import a from './themes/default';
import k from './themes/gruvbox';
import q from './themes/high-contrast-light';
import l from './themes/hyper';
import b from './themes/legacy';
import e from './themes/material';
import i from './themes/one-dark';
import h from './themes/one-light';
import j from './themes/purple';
import m from './themes/railscasts';
import g from './themes/simple-dark';
import f from './themes/simple-light';
import o from './themes/solarized';
import p from './themes/solarized-dark';
import n from './themes/solarized-light';
import d from './themes/studio-dark';
import c from './themes/studio-light';

export default [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r];
55 changes: 55 additions & 0 deletions packages/insomnia/src/plugins/themes/colorblind-dark.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
export default {
name: 'colorblind-dark',
displayName: 'Dark Colorblind',
theme: {
background: {
default: '#21262D', // primary background color
success: '#0080FF', // POST request, 200 OK, parameter names
notice: '#E8F086', // SEND button, GET request
warning: '#A691AE', // PUT request
danger: '#CC5500', // DELETE request
surprise: '#FFC20A', // accent (Dashboard link, branch button, add plugin button)
info: '#58A6FF', // OPTIONS AND HEAD request
},
foreground: {
default: '#fff', // primary font color
success: '#000', // secondary font color for success background
notice: '#000', // secondary font color for notice background
warning: '#fff', // secondary font color for warning background
danger: '#fff', // secondary font color for danger background
surprise: '#000', // secondary font color for surprise background
info: '#000', // secondary font color for info background
},
highlight: {
default: '#D3D3D3', // sidebar highlight color
},
styles: {
appHeader: {
foreground: {
surprise: '#000', // branch button font color
},
},
paneHeader: {
foreground: {
surprise: '#000', // accent font color
info: '#000', // response font color
},
},
editor: {
foreground: {
default: '#000', // primary editor font color
surprise: '#000', // accent font color
info: '#000', // response font color
},
},
dialog: {
background: {
default: '#2E4052', // modal primary background color
},
foreground: {
default: '#fff', // primary font color for modals
},
},
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const sidebarBackground = {
info: '#46c1e6',
};

module.exports = {
export default {
name: 'default',
displayName: 'Default',
theme: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'gruvbox-dark',
displayName: 'Gruvbox Dark',
theme: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'high-contrast-light',
displayName: 'High Contrast',
theme: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'hyper',
displayName: 'Hyper',
theme: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const sidebarBackground = {
info: '#46c1e6',
};

module.exports = {
export default {
name: 'legacy',
displayName: 'Legacy',
theme: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'material',
displayName: 'Material',
theme: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'one-dark',
displayName: 'One Dark',
theme: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const sidebarBackground = {
info: '#0184bc',
};

module.exports = {
export default {
name: 'one-light',
displayName: 'One Light',
theme: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'purple',
displayName: 'Purple',
theme: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'railscasts',
displayName: 'Railscasts',
theme: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'dark',
displayName: 'Simple Dark',
theme: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'light',
displayName: 'Simple Light',
theme: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'solarized-dark',
displayName: 'Solarized Dark',
theme: {
Expand Down Expand Up @@ -28,7 +28,7 @@ module.exports = {
highlight: {
default: 'rgb(88, 110, 117)',
},
}
},
},
},
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'solarized-light',
displayName: 'Solarized Light',
theme: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'solarized',
displayName: 'Solarized',
theme: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
name: 'studio-colorful',
displayName: 'Designer Dark',
theme: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const background = {
surprise: '#6030BF',
};

module.exports = {
export default {
name: 'studio-light',
displayName: 'Designer Light',
theme: {
Expand Down
6 changes: 5 additions & 1 deletion packages/insomnia/src/templating/extensions/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ExtraRenderInfo } from '../../common/render';
import type { Request } from '../../models/request';
import type { Response } from '../../models/response';
import {
Expand All @@ -8,7 +9,7 @@ import { HelperContext } from '../base-extension';
import type { NunjucksActionTag, NunjucksParsedTagArg } from '../utils';
export type PluginArgumentValue = string | number | boolean;

type DisplayName = string | ((args: NunjucksParsedTagArg[]) => string);
export type DisplayName = string | ((args: NunjucksParsedTagArg[]) => string);

interface PluginArgumentBase {
displayName: DisplayName;
Expand Down Expand Up @@ -68,6 +69,9 @@ export type PluginArgument =
export type PluginTemplateTagContext = HelperContext & {
app: AppContext;
store: PluginStore;
network: {
sendRequest(request: Request, extraInfo?: ExtraRenderInfo): Promise<Response>;
};
util: {
models: {
request: {
Expand Down