mirror of
https://github.com/Kong/insomnia
synced 2024-11-12 17:26:32 +00:00
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import { exportWorkspacesData, exportWorkspacesHAR } from '../../common/export';
|
|
import type { ImportRawConfig } from '../../common/import';
|
|
import { importRaw, importUri } from '../../common/import';
|
|
import type { Workspace, WorkspaceScope } from '../../models/workspace';
|
|
|
|
interface PluginImportOptions {
|
|
workspaceId?: string;
|
|
scope?: WorkspaceScope;
|
|
}
|
|
|
|
interface InsomniaExport {
|
|
workspace?: Workspace;
|
|
includePrivate?: boolean;
|
|
format?: 'json' | 'yaml';
|
|
}
|
|
|
|
type HarExport = Omit<InsomniaExport, 'format'>;
|
|
|
|
const buildImportRawConfig = (options: PluginImportOptions): ImportRawConfig => ({
|
|
getWorkspaceId: () => Promise.resolve(options.workspaceId || null),
|
|
getWorkspaceScope: options.scope && (() => (
|
|
Promise.resolve<WorkspaceScope>(options.scope as WorkspaceScope))
|
|
),
|
|
});
|
|
|
|
export const init = () => ({
|
|
data: {
|
|
import: {
|
|
uri: async (uri: string, options: PluginImportOptions = {}) => {
|
|
await importUri(uri, buildImportRawConfig(options));
|
|
},
|
|
raw: async (text: string, options: PluginImportOptions = {}) => {
|
|
await importRaw(text, buildImportRawConfig(options));
|
|
},
|
|
},
|
|
export: {
|
|
insomnia: async ({
|
|
workspace,
|
|
includePrivate,
|
|
format,
|
|
}: InsomniaExport = {}) => exportWorkspacesData(
|
|
workspace ? [workspace] : [],
|
|
Boolean(includePrivate),
|
|
format || 'json',
|
|
),
|
|
|
|
har: async ({
|
|
workspace,
|
|
includePrivate,
|
|
}: HarExport = {}) => exportWorkspacesHAR(
|
|
workspace ? [workspace] : [],
|
|
Boolean(includePrivate),
|
|
),
|
|
},
|
|
},
|
|
});
|