mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-17 14:29:46 +02:00
Merge main into proxy branch (formatting and docs)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "@yaak/importer-insomnia",
|
||||
"displayName": "Insomnia Importer",
|
||||
"description": "Import data from Insomnia",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"description": "Import data from Insomnia",
|
||||
"scripts": {
|
||||
"build": "yaakcli build",
|
||||
"dev": "yaakcli dev",
|
||||
"test": "vitest --run tests"
|
||||
"test": "vp test --run tests"
|
||||
},
|
||||
"dependencies": {
|
||||
"yaml": "^2.4.2"
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
export function isJSObject(obj: unknown) {
|
||||
return Object.prototype.toString.call(obj) === '[object Object]';
|
||||
return Object.prototype.toString.call(obj) === "[object Object]";
|
||||
}
|
||||
|
||||
export function isJSString(obj: unknown) {
|
||||
return Object.prototype.toString.call(obj) === '[object String]';
|
||||
return Object.prototype.toString.call(obj) === "[object String]";
|
||||
}
|
||||
|
||||
export function convertId(id: string): string {
|
||||
if (id.startsWith('GENERATE_ID::')) {
|
||||
if (id.startsWith("GENERATE_ID::")) {
|
||||
return id;
|
||||
}
|
||||
return `GENERATE_ID::${id}`;
|
||||
@@ -17,7 +17,7 @@ export function deleteUndefinedAttrs<T>(obj: T): T {
|
||||
if (Array.isArray(obj) && obj != null) {
|
||||
return obj.map(deleteUndefinedAttrs) as T;
|
||||
}
|
||||
if (typeof obj === 'object' && obj != null) {
|
||||
if (typeof obj === "object" && obj != null) {
|
||||
return Object.fromEntries(
|
||||
Object.entries(obj)
|
||||
.filter(([, v]) => v !== undefined)
|
||||
@@ -29,14 +29,14 @@ export function deleteUndefinedAttrs<T>(obj: T): T {
|
||||
|
||||
/** Recursively render all nested object properties */
|
||||
export function convertTemplateSyntax<T>(obj: T): T {
|
||||
if (typeof obj === 'string') {
|
||||
// biome-ignore lint/suspicious/noTemplateCurlyInString: Yaak template syntax
|
||||
return obj.replaceAll(/{{\s*(_\.)?([^}]+)\s*}}/g, '${[$2]}') as T;
|
||||
if (typeof obj === "string") {
|
||||
// oxlint-disable-next-line no-template-curly-in-string -- Yaak template syntax
|
||||
return obj.replaceAll(/{{\s*(_\.)?([^}]+)\s*}}/g, "${[$2]}") as T;
|
||||
}
|
||||
if (Array.isArray(obj) && obj != null) {
|
||||
return obj.map(convertTemplateSyntax) as T;
|
||||
}
|
||||
if (typeof obj === 'object' && obj != null) {
|
||||
if (typeof obj === "object" && obj != null) {
|
||||
return Object.fromEntries(
|
||||
Object.entries(obj).map(([k, v]) => [k, convertTemplateSyntax(v)]),
|
||||
) as T;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import type { Context, PluginDefinition } from '@yaakapp/api';
|
||||
import YAML from 'yaml';
|
||||
import { deleteUndefinedAttrs, isJSObject } from './common';
|
||||
import { convertInsomniaV4 } from './v4';
|
||||
import { convertInsomniaV5 } from './v5';
|
||||
import type { Context, PluginDefinition } from "@yaakapp/api";
|
||||
import YAML from "yaml";
|
||||
import { deleteUndefinedAttrs, isJSObject } from "./common";
|
||||
import { convertInsomniaV4 } from "./v4";
|
||||
import { convertInsomniaV5 } from "./v5";
|
||||
|
||||
export const plugin: PluginDefinition = {
|
||||
importer: {
|
||||
name: 'Insomnia',
|
||||
description: 'Import Insomnia workspaces',
|
||||
name: "Insomnia",
|
||||
description: "Import Insomnia workspaces",
|
||||
async onImport(_ctx: Context, args: { text: string }) {
|
||||
return convertInsomnia(args.text);
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// biome-ignore-all lint/suspicious/noExplicitAny: too flexible for strict types
|
||||
import type { PartialImportResources } from '@yaakapp/api';
|
||||
import { convertId, convertTemplateSyntax, isJSObject } from './common';
|
||||
/* oxlint-disable no-explicit-any */
|
||||
import type { PartialImportResources } from "@yaakapp/api";
|
||||
import { convertId, convertTemplateSyntax, isJSObject } from "./common";
|
||||
|
||||
export function convertInsomniaV4(parsed: any) {
|
||||
if (!Array.isArray(parsed.resources)) return null;
|
||||
@@ -16,19 +16,19 @@ export function convertInsomniaV4(parsed: any) {
|
||||
|
||||
// Import workspaces
|
||||
const workspacesToImport = parsed.resources.filter(
|
||||
(r: any) => isJSObject(r) && r._type === 'workspace',
|
||||
(r: any) => isJSObject(r) && r._type === "workspace",
|
||||
);
|
||||
for (const w of workspacesToImport) {
|
||||
resources.workspaces.push({
|
||||
id: convertId(w._id),
|
||||
createdAt: w.created ? new Date(w.created).toISOString().replace('Z', '') : undefined,
|
||||
updatedAt: w.updated ? new Date(w.updated).toISOString().replace('Z', '') : undefined,
|
||||
model: 'workspace',
|
||||
createdAt: w.created ? new Date(w.created).toISOString().replace("Z", "") : undefined,
|
||||
updatedAt: w.updated ? new Date(w.updated).toISOString().replace("Z", "") : undefined,
|
||||
model: "workspace",
|
||||
name: w.name,
|
||||
description: w.description || undefined,
|
||||
});
|
||||
const environmentsToImport = parsed.resources.filter(
|
||||
(r: any) => isJSObject(r) && r._type === 'environment',
|
||||
(r: any) => isJSObject(r) && r._type === "environment",
|
||||
);
|
||||
resources.environments.push(
|
||||
...environmentsToImport.map((r: any) => importEnvironment(r, w._id)),
|
||||
@@ -39,12 +39,12 @@ export function convertInsomniaV4(parsed: any) {
|
||||
for (const child of children) {
|
||||
if (!isJSObject(child)) continue;
|
||||
|
||||
if (child._type === 'request_group') {
|
||||
if (child._type === "request_group") {
|
||||
resources.folders.push(importFolder(child, w._id));
|
||||
nextFolder(child._id);
|
||||
} else if (child._type === 'request') {
|
||||
} else if (child._type === "request") {
|
||||
resources.httpRequests.push(importHttpRequest(child, w._id));
|
||||
} else if (child._type === 'grpc_request') {
|
||||
} else if (child._type === "grpc_request") {
|
||||
resources.grpcRequests.push(importGrpcRequest(child, w._id));
|
||||
}
|
||||
}
|
||||
@@ -63,48 +63,48 @@ export function convertInsomniaV4(parsed: any) {
|
||||
return { resources: convertTemplateSyntax(resources) };
|
||||
}
|
||||
|
||||
function importHttpRequest(r: any, workspaceId: string): PartialImportResources['httpRequests'][0] {
|
||||
function importHttpRequest(r: any, workspaceId: string): PartialImportResources["httpRequests"][0] {
|
||||
let bodyType: string | null = null;
|
||||
let body = {};
|
||||
if (r.body.mimeType === 'application/octet-stream') {
|
||||
bodyType = 'binary';
|
||||
body = { filePath: r.body.fileName ?? '' };
|
||||
} else if (r.body?.mimeType === 'application/x-www-form-urlencoded') {
|
||||
bodyType = 'application/x-www-form-urlencoded';
|
||||
if (r.body.mimeType === "application/octet-stream") {
|
||||
bodyType = "binary";
|
||||
body = { filePath: r.body.fileName ?? "" };
|
||||
} else if (r.body?.mimeType === "application/x-www-form-urlencoded") {
|
||||
bodyType = "application/x-www-form-urlencoded";
|
||||
body = {
|
||||
form: (r.body.params ?? []).map((p: any) => ({
|
||||
enabled: !p.disabled,
|
||||
name: p.name ?? '',
|
||||
value: p.value ?? '',
|
||||
name: p.name ?? "",
|
||||
value: p.value ?? "",
|
||||
})),
|
||||
};
|
||||
} else if (r.body?.mimeType === 'multipart/form-data') {
|
||||
bodyType = 'multipart/form-data';
|
||||
} else if (r.body?.mimeType === "multipart/form-data") {
|
||||
bodyType = "multipart/form-data";
|
||||
body = {
|
||||
form: (r.body.params ?? []).map((p: any) => ({
|
||||
enabled: !p.disabled,
|
||||
name: p.name ?? '',
|
||||
value: p.value ?? '',
|
||||
name: p.name ?? "",
|
||||
value: p.value ?? "",
|
||||
file: p.fileName ?? null,
|
||||
})),
|
||||
};
|
||||
} else if (r.body?.mimeType === 'application/graphql') {
|
||||
bodyType = 'graphql';
|
||||
body = { text: r.body.text ?? '' };
|
||||
} else if (r.body?.mimeType === 'application/json') {
|
||||
bodyType = 'application/json';
|
||||
body = { text: r.body.text ?? '' };
|
||||
} else if (r.body?.mimeType === "application/graphql") {
|
||||
bodyType = "graphql";
|
||||
body = { text: r.body.text ?? "" };
|
||||
} else if (r.body?.mimeType === "application/json") {
|
||||
bodyType = "application/json";
|
||||
body = { text: r.body.text ?? "" };
|
||||
}
|
||||
|
||||
let authenticationType: string | null = null;
|
||||
let authentication = {};
|
||||
if (r.authentication.type === 'bearer') {
|
||||
authenticationType = 'bearer';
|
||||
if (r.authentication.type === "bearer") {
|
||||
authenticationType = "bearer";
|
||||
authentication = {
|
||||
token: r.authentication.token,
|
||||
};
|
||||
} else if (r.authentication.type === 'basic') {
|
||||
authenticationType = 'basic';
|
||||
} else if (r.authentication.type === "basic") {
|
||||
authenticationType = "basic";
|
||||
authentication = {
|
||||
username: r.authentication.username,
|
||||
password: r.authentication.password,
|
||||
@@ -113,19 +113,19 @@ function importHttpRequest(r: any, workspaceId: string): PartialImportResources[
|
||||
|
||||
return {
|
||||
id: convertId(r.meta?.id ?? r._id),
|
||||
createdAt: r.created ? new Date(r.created).toISOString().replace('Z', '') : undefined,
|
||||
updatedAt: r.modified ? new Date(r.modified).toISOString().replace('Z', '') : undefined,
|
||||
createdAt: r.created ? new Date(r.created).toISOString().replace("Z", "") : undefined,
|
||||
updatedAt: r.modified ? new Date(r.modified).toISOString().replace("Z", "") : undefined,
|
||||
workspaceId: convertId(workspaceId),
|
||||
folderId: r.parentId === workspaceId ? null : convertId(r.parentId),
|
||||
model: 'http_request',
|
||||
model: "http_request",
|
||||
sortPriority: r.metaSortKey,
|
||||
name: r.name,
|
||||
description: r.description || undefined,
|
||||
url: r.url,
|
||||
urlParameters: (r.parameters ?? []).map((p: any) => ({
|
||||
enabled: !p.disabled,
|
||||
name: p.name ?? '',
|
||||
value: p.value ?? '',
|
||||
name: p.name ?? "",
|
||||
value: p.value ?? "",
|
||||
})),
|
||||
body,
|
||||
bodyType,
|
||||
@@ -135,51 +135,51 @@ function importHttpRequest(r: any, workspaceId: string): PartialImportResources[
|
||||
headers: (r.headers ?? [])
|
||||
.map((h: any) => ({
|
||||
enabled: !h.disabled,
|
||||
name: h.name ?? '',
|
||||
value: h.value ?? '',
|
||||
name: h.name ?? "",
|
||||
value: h.value ?? "",
|
||||
}))
|
||||
.filter(({ name, value }: any) => name !== '' || value !== ''),
|
||||
.filter(({ name, value }: any) => name !== "" || value !== ""),
|
||||
};
|
||||
}
|
||||
|
||||
function importGrpcRequest(r: any, workspaceId: string): PartialImportResources['grpcRequests'][0] {
|
||||
const parts = r.protoMethodName.split('/').filter((p: any) => p !== '');
|
||||
function importGrpcRequest(r: any, workspaceId: string): PartialImportResources["grpcRequests"][0] {
|
||||
const parts = r.protoMethodName.split("/").filter((p: any) => p !== "");
|
||||
const service = parts[0] ?? null;
|
||||
const method = parts[1] ?? null;
|
||||
|
||||
return {
|
||||
id: convertId(r.meta?.id ?? r._id),
|
||||
createdAt: r.created ? new Date(r.created).toISOString().replace('Z', '') : undefined,
|
||||
updatedAt: r.modified ? new Date(r.modified).toISOString().replace('Z', '') : undefined,
|
||||
createdAt: r.created ? new Date(r.created).toISOString().replace("Z", "") : undefined,
|
||||
updatedAt: r.modified ? new Date(r.modified).toISOString().replace("Z", "") : undefined,
|
||||
workspaceId: convertId(workspaceId),
|
||||
folderId: r.parentId === workspaceId ? null : convertId(r.parentId),
|
||||
model: 'grpc_request',
|
||||
model: "grpc_request",
|
||||
sortPriority: r.metaSortKey,
|
||||
name: r.name,
|
||||
description: r.description || undefined,
|
||||
url: r.url,
|
||||
service,
|
||||
method,
|
||||
message: r.body?.text ?? '',
|
||||
message: r.body?.text ?? "",
|
||||
metadata: (r.metadata ?? [])
|
||||
.map((h: any) => ({
|
||||
enabled: !h.disabled,
|
||||
name: h.name ?? '',
|
||||
value: h.value ?? '',
|
||||
name: h.name ?? "",
|
||||
value: h.value ?? "",
|
||||
}))
|
||||
.filter(({ name, value }: any) => name !== '' || value !== ''),
|
||||
.filter(({ name, value }: any) => name !== "" || value !== ""),
|
||||
};
|
||||
}
|
||||
|
||||
function importFolder(f: any, workspaceId: string): PartialImportResources['folders'][0] {
|
||||
function importFolder(f: any, workspaceId: string): PartialImportResources["folders"][0] {
|
||||
return {
|
||||
id: convertId(f._id),
|
||||
createdAt: f.created ? new Date(f.created).toISOString().replace('Z', '') : undefined,
|
||||
updatedAt: f.modified ? new Date(f.modified).toISOString().replace('Z', '') : undefined,
|
||||
createdAt: f.created ? new Date(f.created).toISOString().replace("Z", "") : undefined,
|
||||
updatedAt: f.modified ? new Date(f.modified).toISOString().replace("Z", "") : undefined,
|
||||
folderId: f.parentId === workspaceId ? null : convertId(f.parentId),
|
||||
workspaceId: convertId(workspaceId),
|
||||
description: f.description || undefined,
|
||||
model: 'folder',
|
||||
model: "folder",
|
||||
name: f.name,
|
||||
};
|
||||
}
|
||||
@@ -188,22 +188,22 @@ function importEnvironment(
|
||||
e: any,
|
||||
workspaceId: string,
|
||||
isParentOg?: boolean,
|
||||
): PartialImportResources['environments'][0] {
|
||||
): PartialImportResources["environments"][0] {
|
||||
const isParent = isParentOg ?? e.parentId === workspaceId;
|
||||
return {
|
||||
id: convertId(e._id),
|
||||
createdAt: e.created ? new Date(e.created).toISOString().replace('Z', '') : undefined,
|
||||
updatedAt: e.modified ? new Date(e.modified).toISOString().replace('Z', '') : undefined,
|
||||
createdAt: e.created ? new Date(e.created).toISOString().replace("Z", "") : undefined,
|
||||
updatedAt: e.modified ? new Date(e.modified).toISOString().replace("Z", "") : undefined,
|
||||
workspaceId: convertId(workspaceId),
|
||||
sortPriority: e.metaSortKey,
|
||||
parentModel: isParent ? 'workspace' : 'environment',
|
||||
parentModel: isParent ? "workspace" : "environment",
|
||||
parentId: null,
|
||||
model: 'environment',
|
||||
model: "environment",
|
||||
name: e.name,
|
||||
variables: Object.entries(e.data).map(([name, value]) => ({
|
||||
enabled: true,
|
||||
name,
|
||||
value: `${value}`,
|
||||
value: String(value),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// biome-ignore-all lint/suspicious/noExplicitAny: too flexible for strict types
|
||||
import type { PartialImportResources } from '@yaakapp/api';
|
||||
import { convertId, convertTemplateSyntax, isJSObject } from './common';
|
||||
/* oxlint-disable no-explicit-any */
|
||||
import type { PartialImportResources } from "@yaakapp/api";
|
||||
import { convertId, convertTemplateSyntax, isJSObject } from "./common";
|
||||
|
||||
export function convertInsomniaV5(parsed: any) {
|
||||
// Assert parsed is object
|
||||
if (parsed == null || typeof parsed !== 'object') {
|
||||
if (parsed == null || typeof parsed !== "object") {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!('collection' in parsed) || !Array.isArray(parsed.collection)) {
|
||||
if (!("collection" in parsed) || !Array.isArray(parsed.collection)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -22,12 +22,12 @@ export function convertInsomniaV5(parsed: any) {
|
||||
};
|
||||
|
||||
// Import workspaces
|
||||
const meta = ('meta' in parsed ? parsed.meta : {}) as Record<string, any>;
|
||||
const meta = ("meta" in parsed ? parsed.meta : {}) as Record<string, any>;
|
||||
resources.workspaces.push({
|
||||
id: convertId(meta.id ?? 'collection'),
|
||||
createdAt: meta.created ? new Date(meta.created).toISOString().replace('Z', '') : undefined,
|
||||
updatedAt: meta.modified ? new Date(meta.modified).toISOString().replace('Z', '') : undefined,
|
||||
model: 'workspace',
|
||||
id: convertId(meta.id ?? "collection"),
|
||||
createdAt: meta.created ? new Date(meta.created).toISOString().replace("Z", "") : undefined,
|
||||
updatedAt: meta.modified ? new Date(meta.modified).toISOString().replace("Z", "") : undefined,
|
||||
model: "workspace",
|
||||
name: parsed.name,
|
||||
description: meta.description || undefined,
|
||||
...importHeaders(parsed),
|
||||
@@ -76,7 +76,7 @@ function importHttpRequest(
|
||||
r: any,
|
||||
workspaceId: string,
|
||||
parentId: string,
|
||||
): PartialImportResources['httpRequests'][0] {
|
||||
): PartialImportResources["httpRequests"][0] {
|
||||
const id = r.meta?.id ?? r._id;
|
||||
const created = r.meta?.created ?? r.created;
|
||||
const updated = r.meta?.modified ?? r.updated;
|
||||
@@ -84,51 +84,51 @@ function importHttpRequest(
|
||||
|
||||
let bodyType: string | null = null;
|
||||
let body = {};
|
||||
if (r.body?.mimeType === 'application/octet-stream') {
|
||||
bodyType = 'binary';
|
||||
body = { filePath: r.body.fileName ?? '' };
|
||||
} else if (r.body?.mimeType === 'application/x-www-form-urlencoded') {
|
||||
bodyType = 'application/x-www-form-urlencoded';
|
||||
if (r.body?.mimeType === "application/octet-stream") {
|
||||
bodyType = "binary";
|
||||
body = { filePath: r.body.fileName ?? "" };
|
||||
} else if (r.body?.mimeType === "application/x-www-form-urlencoded") {
|
||||
bodyType = "application/x-www-form-urlencoded";
|
||||
body = {
|
||||
form: (r.body.params ?? []).map((p: any) => ({
|
||||
enabled: !p.disabled,
|
||||
name: p.name ?? '',
|
||||
value: p.value ?? '',
|
||||
name: p.name ?? "",
|
||||
value: p.value ?? "",
|
||||
})),
|
||||
};
|
||||
} else if (r.body?.mimeType === 'multipart/form-data') {
|
||||
bodyType = 'multipart/form-data';
|
||||
} else if (r.body?.mimeType === "multipart/form-data") {
|
||||
bodyType = "multipart/form-data";
|
||||
body = {
|
||||
form: (r.body.params ?? []).map((p: any) => ({
|
||||
enabled: !p.disabled,
|
||||
name: p.name ?? '',
|
||||
value: p.value ?? '',
|
||||
name: p.name ?? "",
|
||||
value: p.value ?? "",
|
||||
file: p.fileName ?? null,
|
||||
})),
|
||||
};
|
||||
} else if (r.body?.mimeType === 'application/graphql') {
|
||||
bodyType = 'graphql';
|
||||
body = { text: r.body.text ?? '' };
|
||||
} else if (r.body?.mimeType === 'application/json') {
|
||||
bodyType = 'application/json';
|
||||
body = { text: r.body.text ?? '' };
|
||||
} else if (r.body?.mimeType === "application/graphql") {
|
||||
bodyType = "graphql";
|
||||
body = { text: r.body.text ?? "" };
|
||||
} else if (r.body?.mimeType === "application/json") {
|
||||
bodyType = "application/json";
|
||||
body = { text: r.body.text ?? "" };
|
||||
}
|
||||
|
||||
return {
|
||||
id: convertId(id),
|
||||
workspaceId: convertId(workspaceId),
|
||||
createdAt: created ? new Date(created).toISOString().replace('Z', '') : undefined,
|
||||
updatedAt: updated ? new Date(updated).toISOString().replace('Z', '') : undefined,
|
||||
createdAt: created ? new Date(created).toISOString().replace("Z", "") : undefined,
|
||||
updatedAt: updated ? new Date(updated).toISOString().replace("Z", "") : undefined,
|
||||
folderId: parentId === workspaceId ? null : convertId(parentId),
|
||||
sortPriority: sortKey,
|
||||
model: 'http_request',
|
||||
model: "http_request",
|
||||
name: r.name,
|
||||
description: r.meta?.description || undefined,
|
||||
url: r.url,
|
||||
urlParameters: (r.parameters ?? []).map((p: any) => ({
|
||||
enabled: !p.disabled,
|
||||
name: p.name ?? '',
|
||||
value: p.value ?? '',
|
||||
name: p.name ?? "",
|
||||
value: p.value ?? "",
|
||||
})),
|
||||
body,
|
||||
bodyType,
|
||||
@@ -142,22 +142,22 @@ function importGrpcRequest(
|
||||
r: any,
|
||||
workspaceId: string,
|
||||
parentId: string,
|
||||
): PartialImportResources['grpcRequests'][0] {
|
||||
): PartialImportResources["grpcRequests"][0] {
|
||||
const id = r.meta?.id ?? r._id;
|
||||
const created = r.meta?.created ?? r.created;
|
||||
const updated = r.meta?.modified ?? r.updated;
|
||||
const sortKey = r.meta?.sortKey ?? r.sortKey;
|
||||
|
||||
const parts = r.protoMethodName.split('/').filter((p: any) => p !== '');
|
||||
const parts = r.protoMethodName.split("/").filter((p: any) => p !== "");
|
||||
const service = parts[0] ?? null;
|
||||
const method = parts[1] ?? null;
|
||||
|
||||
return {
|
||||
model: 'grpc_request',
|
||||
model: "grpc_request",
|
||||
id: convertId(id),
|
||||
workspaceId: convertId(workspaceId),
|
||||
createdAt: created ? new Date(created).toISOString().replace('Z', '') : undefined,
|
||||
updatedAt: updated ? new Date(updated).toISOString().replace('Z', '') : undefined,
|
||||
createdAt: created ? new Date(created).toISOString().replace("Z", "") : undefined,
|
||||
updatedAt: updated ? new Date(updated).toISOString().replace("Z", "") : undefined,
|
||||
folderId: parentId === workspaceId ? null : convertId(parentId),
|
||||
sortPriority: sortKey,
|
||||
name: r.name,
|
||||
@@ -165,14 +165,14 @@ function importGrpcRequest(
|
||||
url: r.url,
|
||||
service,
|
||||
method,
|
||||
message: r.body?.text ?? '',
|
||||
message: r.body?.text ?? "",
|
||||
metadata: (r.metadata ?? [])
|
||||
.map((h: any) => ({
|
||||
enabled: !h.disabled,
|
||||
name: h.name ?? '',
|
||||
value: h.value ?? '',
|
||||
name: h.name ?? "",
|
||||
value: h.value ?? "",
|
||||
}))
|
||||
.filter(({ name, value }: any) => name !== '' || value !== ''),
|
||||
.filter(({ name, value }: any) => name !== "" || value !== ""),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -180,24 +180,24 @@ function importWebsocketRequest(
|
||||
r: any,
|
||||
workspaceId: string,
|
||||
parentId: string,
|
||||
): PartialImportResources['websocketRequests'][0] {
|
||||
): PartialImportResources["websocketRequests"][0] {
|
||||
const id = r.meta?.id ?? r._id;
|
||||
const created = r.meta?.created ?? r.created;
|
||||
const updated = r.meta?.modified ?? r.updated;
|
||||
const sortKey = r.meta?.sortKey ?? r.sortKey;
|
||||
|
||||
return {
|
||||
model: 'websocket_request',
|
||||
model: "websocket_request",
|
||||
id: convertId(id),
|
||||
workspaceId: convertId(workspaceId),
|
||||
createdAt: created ? new Date(created).toISOString().replace('Z', '') : undefined,
|
||||
updatedAt: updated ? new Date(updated).toISOString().replace('Z', '') : undefined,
|
||||
createdAt: created ? new Date(created).toISOString().replace("Z", "") : undefined,
|
||||
updatedAt: updated ? new Date(updated).toISOString().replace("Z", "") : undefined,
|
||||
folderId: parentId === workspaceId ? null : convertId(parentId),
|
||||
sortPriority: sortKey,
|
||||
name: r.name,
|
||||
description: r.description || undefined,
|
||||
url: r.url,
|
||||
message: r.body?.text ?? '',
|
||||
message: r.body?.text ?? "",
|
||||
...importHeaders(r),
|
||||
...importAuthentication(r),
|
||||
};
|
||||
@@ -207,23 +207,23 @@ function importHeaders(obj: any) {
|
||||
const headers = (obj.headers ?? [])
|
||||
.map((h: any) => ({
|
||||
enabled: !h.disabled,
|
||||
name: h.name ?? '',
|
||||
value: h.value ?? '',
|
||||
name: h.name ?? "",
|
||||
value: h.value ?? "",
|
||||
}))
|
||||
.filter(({ name, value }: any) => name !== '' || value !== '');
|
||||
.filter(({ name, value }: any) => name !== "" || value !== "");
|
||||
return { headers } as const;
|
||||
}
|
||||
|
||||
function importAuthentication(obj: any) {
|
||||
let authenticationType: string | null = null;
|
||||
let authentication = {};
|
||||
if (obj.authentication?.type === 'bearer') {
|
||||
authenticationType = 'bearer';
|
||||
if (obj.authentication?.type === "bearer") {
|
||||
authenticationType = "bearer";
|
||||
authentication = {
|
||||
token: obj.authentication.token,
|
||||
};
|
||||
} else if (obj.authentication?.type === 'basic') {
|
||||
authenticationType = 'basic';
|
||||
} else if (obj.authentication?.type === "basic") {
|
||||
authenticationType = "basic";
|
||||
authentication = {
|
||||
username: obj.authentication.username,
|
||||
password: obj.authentication.password,
|
||||
@@ -238,40 +238,40 @@ function importFolder(
|
||||
workspaceId: string,
|
||||
parentId: string,
|
||||
): {
|
||||
folder: PartialImportResources['folders'][0];
|
||||
environment: PartialImportResources['environments'][0] | null;
|
||||
folder: PartialImportResources["folders"][0];
|
||||
environment: PartialImportResources["environments"][0] | null;
|
||||
} {
|
||||
const id = f.meta?.id ?? f._id;
|
||||
const created = f.meta?.created ?? f.created;
|
||||
const updated = f.meta?.modified ?? f.updated;
|
||||
const sortKey = f.meta?.sortKey ?? f.sortKey;
|
||||
|
||||
let environment: PartialImportResources['environments'][0] | null = null;
|
||||
let environment: PartialImportResources["environments"][0] | null = null;
|
||||
if (Object.keys(f.environment ?? {}).length > 0) {
|
||||
environment = {
|
||||
id: convertId(`${id}folder`),
|
||||
createdAt: created ? new Date(created).toISOString().replace('Z', '') : undefined,
|
||||
updatedAt: updated ? new Date(updated).toISOString().replace('Z', '') : undefined,
|
||||
createdAt: created ? new Date(created).toISOString().replace("Z", "") : undefined,
|
||||
updatedAt: updated ? new Date(updated).toISOString().replace("Z", "") : undefined,
|
||||
workspaceId: convertId(workspaceId),
|
||||
public: true,
|
||||
parentModel: 'folder',
|
||||
parentModel: "folder",
|
||||
parentId: convertId(id),
|
||||
model: 'environment',
|
||||
name: 'Folder Environment',
|
||||
model: "environment",
|
||||
name: "Folder Environment",
|
||||
variables: Object.entries(f.environment ?? {}).map(([name, value]) => ({
|
||||
enabled: true,
|
||||
name,
|
||||
value: `${value}`,
|
||||
value: String(value),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
folder: {
|
||||
model: 'folder',
|
||||
model: "folder",
|
||||
id: convertId(id),
|
||||
createdAt: created ? new Date(created).toISOString().replace('Z', '') : undefined,
|
||||
updatedAt: updated ? new Date(updated).toISOString().replace('Z', '') : undefined,
|
||||
createdAt: created ? new Date(created).toISOString().replace("Z", "") : undefined,
|
||||
updatedAt: updated ? new Date(updated).toISOString().replace("Z", "") : undefined,
|
||||
folderId: parentId === workspaceId ? null : convertId(parentId),
|
||||
sortPriority: sortKey,
|
||||
workspaceId: convertId(workspaceId),
|
||||
@@ -288,7 +288,7 @@ function importEnvironment(
|
||||
e: any,
|
||||
workspaceId: string,
|
||||
isParent?: boolean,
|
||||
): PartialImportResources['environments'][0] {
|
||||
): PartialImportResources["environments"][0] {
|
||||
const id = e.meta?.id ?? e._id;
|
||||
const created = e.meta?.created ?? e.created;
|
||||
const updated = e.meta?.modified ?? e.updated;
|
||||
@@ -296,19 +296,19 @@ function importEnvironment(
|
||||
|
||||
return {
|
||||
id: convertId(id),
|
||||
createdAt: created ? new Date(created).toISOString().replace('Z', '') : undefined,
|
||||
updatedAt: updated ? new Date(updated).toISOString().replace('Z', '') : undefined,
|
||||
createdAt: created ? new Date(created).toISOString().replace("Z", "") : undefined,
|
||||
updatedAt: updated ? new Date(updated).toISOString().replace("Z", "") : undefined,
|
||||
workspaceId: convertId(workspaceId),
|
||||
public: !e.isPrivate,
|
||||
sortPriority: sortKey,
|
||||
parentModel: isParent ? 'workspace' : 'environment',
|
||||
parentModel: isParent ? "workspace" : "environment",
|
||||
parentId: null,
|
||||
model: 'environment',
|
||||
model: "environment",
|
||||
name: e.name,
|
||||
variables: Object.entries(e.data ?? {}).map(([name, value]) => ({
|
||||
enabled: true,
|
||||
name,
|
||||
value: `${value}`,
|
||||
value: String(value),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import YAML from 'yaml';
|
||||
import { convertInsomnia } from '../src';
|
||||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import { describe, expect, test } from "vite-plus/test";
|
||||
import YAML from "yaml";
|
||||
import { convertInsomnia } from "../src";
|
||||
|
||||
describe('importer-yaak', () => {
|
||||
const p = path.join(__dirname, 'fixtures');
|
||||
describe("importer-yaak", () => {
|
||||
const p = path.join(__dirname, "fixtures");
|
||||
const fixtures = fs.readdirSync(p);
|
||||
|
||||
for (const fixture of fixtures) {
|
||||
if (fixture.includes('.output')) {
|
||||
if (fixture.includes(".output")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
test(`Imports ${fixture}`, () => {
|
||||
const contents = fs.readFileSync(path.join(p, fixture), 'utf-8');
|
||||
const contents = fs.readFileSync(path.join(p, fixture), "utf-8");
|
||||
const expected = fs.readFileSync(
|
||||
path.join(p, fixture.replace(/.input\..*/, '.output.json')),
|
||||
'utf-8',
|
||||
path.join(p, fixture.replace(/.input\..*/, ".output.json")),
|
||||
"utf-8",
|
||||
);
|
||||
const result = convertInsomnia(contents);
|
||||
// console.log(JSON.stringify(result, null, 2))
|
||||
|
||||
Reference in New Issue
Block a user