mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-06-28 04:46:20 +02:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bb9aa6b55d | |||
| 3de9a1edd4 | |||
| 1b28dfd9d1 | |||
| 9f51c61447 | |||
| b17ccbeebe | |||
| 463cc6f5a3 | |||
| 1307ea4e67 | |||
| 710b8e34ac | |||
| f251772a4a |
@@ -290,10 +290,10 @@ function BaseInput({
|
||||
<HStack
|
||||
className={classNames(
|
||||
inputWrapperClassName,
|
||||
"w-full min-w-0 px-2",
|
||||
"flex-1 min-w-0 px-2",
|
||||
fullHeight && "h-full",
|
||||
leftSlot ? "pl-0.5 -ml-2" : null,
|
||||
rightSlot ? "pr-0.5 -mr-2" : null,
|
||||
leftSlot ? "pl-0" : null,
|
||||
rightSlot ? "pr-0" : null,
|
||||
)}
|
||||
>
|
||||
<Editor
|
||||
|
||||
@@ -69,6 +69,7 @@ function HttpTextViewer({ response, text, language, pretty, className }: HttpTex
|
||||
text={text}
|
||||
language={language}
|
||||
stateKey={`response.body.${response.id}`}
|
||||
filterStateKey={`response.body.${response.requestId}`}
|
||||
pretty={pretty}
|
||||
className={className}
|
||||
onFilter={filterCallback}
|
||||
|
||||
@@ -16,6 +16,7 @@ interface Props {
|
||||
text: string;
|
||||
language: EditorProps["language"];
|
||||
stateKey: string | null;
|
||||
filterStateKey?: string | null;
|
||||
pretty?: boolean;
|
||||
className?: string;
|
||||
onFilter?: (filter: string) => {
|
||||
@@ -27,16 +28,25 @@ interface Props {
|
||||
|
||||
const useFilterText = createGlobalState<Record<string, string | null>>({});
|
||||
|
||||
export function TextViewer({ language, text, stateKey, pretty, className, onFilter }: Props) {
|
||||
export function TextViewer({
|
||||
language,
|
||||
text,
|
||||
stateKey,
|
||||
filterStateKey,
|
||||
pretty,
|
||||
className,
|
||||
onFilter,
|
||||
}: Props) {
|
||||
const filterKey = filterStateKey ?? stateKey;
|
||||
const [filterTextMap, setFilterTextMap] = useFilterText();
|
||||
const filterText = stateKey ? (filterTextMap[stateKey] ?? null) : null;
|
||||
const filterText = filterKey ? (filterTextMap[filterKey] ?? null) : null;
|
||||
const debouncedFilterText = useDebouncedValue(filterText);
|
||||
const setFilterText = useCallback(
|
||||
(v: string | null) => {
|
||||
if (!stateKey) return;
|
||||
setFilterTextMap((m) => ({ ...m, [stateKey]: v }));
|
||||
if (!filterKey) return;
|
||||
setFilterTextMap((m) => ({ ...m, [filterKey]: v }));
|
||||
},
|
||||
[setFilterTextMap, stateKey],
|
||||
[filterKey, setFilterTextMap],
|
||||
);
|
||||
|
||||
const isSearching = filterText != null;
|
||||
@@ -64,7 +74,7 @@ export function TextViewer({ language, text, stateKey, pretty, className, onFilt
|
||||
nodes.push(
|
||||
<div key="input" className="w-full !opacity-100">
|
||||
<Input
|
||||
key={stateKey ?? "filter"}
|
||||
key={filterKey ?? "filter"}
|
||||
validate={!filteredResponse.error}
|
||||
hideLabel
|
||||
autoFocus
|
||||
@@ -76,7 +86,7 @@ export function TextViewer({ language, text, stateKey, pretty, className, onFilt
|
||||
defaultValue={filterText}
|
||||
onKeyDown={(e) => e.key === "Escape" && toggleSearch()}
|
||||
onChange={setFilterText}
|
||||
stateKey={stateKey ? `filter.${stateKey}` : null}
|
||||
stateKey={filterKey ? `filter.${filterKey}` : null}
|
||||
/>
|
||||
</div>,
|
||||
);
|
||||
@@ -97,12 +107,12 @@ export function TextViewer({ language, text, stateKey, pretty, className, onFilt
|
||||
return nodes;
|
||||
}, [
|
||||
canFilter,
|
||||
filterKey,
|
||||
filterText,
|
||||
filteredResponse.error,
|
||||
filteredResponse.isPending,
|
||||
isSearching,
|
||||
language,
|
||||
stateKey,
|
||||
setFilterText,
|
||||
toggleSearch,
|
||||
]);
|
||||
|
||||
@@ -35,10 +35,15 @@ export async function deleteModelWithConfirm(
|
||||
<>
|
||||
the following?
|
||||
<Prose className="mt-2">
|
||||
<ul>
|
||||
<ul className="space-y-1">
|
||||
{models.map((m) => (
|
||||
<li key={m.id}>
|
||||
<InlineCode>{resolvedModelName(m)}</InlineCode>
|
||||
<InlineCode
|
||||
className="inline-block truncate align-bottom max-w-full"
|
||||
title={resolvedModelName(m)}
|
||||
>
|
||||
{resolvedModelName(m)}
|
||||
</InlineCode>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
@@ -98,7 +98,7 @@
|
||||
"babel-plugin-react-compiler": "^1.0.0",
|
||||
"decompress": "^4.2.1",
|
||||
"internal-ip": "^8.0.0",
|
||||
"postcss": "^8.5.6",
|
||||
"postcss": "^8.5.14",
|
||||
"postcss-nesting": "^13.0.2",
|
||||
"rollup": "^4.60.3",
|
||||
"tailwindcss": "^3.4.17",
|
||||
@@ -107,6 +107,6 @@
|
||||
"vite-plugin-svgr": "^4.5.0",
|
||||
"vite-plugin-top-level-await": "^1.5.0",
|
||||
"vite-plugin-wasm": "^3.5.0",
|
||||
"vite-plus": "^0.1.20"
|
||||
"vite-plus": "^0.1.24"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,6 @@
|
||||
"babel-plugin-react-compiler": "^1.0.0",
|
||||
"typescript": "^5.8.3",
|
||||
"vite": "npm:@voidzero-dev/vite-plus-core@^0.1.20",
|
||||
"vite-plus": "^0.1.20"
|
||||
"vite-plus": "^0.1.24"
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+618
-242
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -121,7 +121,7 @@
|
||||
"npm-run-all": "^4.1.5",
|
||||
"typescript": "^5.8.3",
|
||||
"vite": "npm:@voidzero-dev/vite-plus-core@^0.1.20",
|
||||
"vite-plus": "^0.1.20",
|
||||
"vite-plus": "^0.1.24",
|
||||
"vitest": "npm:@voidzero-dev/vite-plus-test@^0.1.20"
|
||||
},
|
||||
"overrides": {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"build:main": "esbuild src/index.ts --bundle --platform=node --outfile=../../crates-tauri/yaak-app-client/vendored/plugin-runtime/index.cjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"ws": "^8.18.0"
|
||||
"ws": "^8.20.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/ws": "^8.5.13"
|
||||
|
||||
@@ -181,6 +181,78 @@ export function convertCurl(rawData: string) {
|
||||
};
|
||||
}
|
||||
|
||||
interface ExtractedAuthentication {
|
||||
authenticationType: string | null;
|
||||
authentication: Record<string, string>;
|
||||
filteredHeaders: HttpUrlParameter[]; // headers without authorization
|
||||
}
|
||||
|
||||
function extractAuthenticationFromHeaders(headers: HttpUrlParameter[]): ExtractedAuthentication {
|
||||
const authorizationHeaderIndex = headers.findIndex(
|
||||
(h) => h.name.toLowerCase() === "authorization",
|
||||
);
|
||||
|
||||
const authorizationHeader = headers[authorizationHeaderIndex];
|
||||
if (authorizationHeader == null) {
|
||||
return {
|
||||
authenticationType: null,
|
||||
authentication: {},
|
||||
filteredHeaders: headers,
|
||||
};
|
||||
}
|
||||
|
||||
const value = authorizationHeader.value.trim();
|
||||
const spaceIndex = value.indexOf(" ");
|
||||
|
||||
if (spaceIndex <= 0) {
|
||||
return {
|
||||
authenticationType: null,
|
||||
authentication: {},
|
||||
filteredHeaders: headers,
|
||||
};
|
||||
}
|
||||
|
||||
const scheme = value.slice(0, spaceIndex).toLowerCase();
|
||||
const credentials = value.slice(spaceIndex + 1).trim();
|
||||
|
||||
// Bearer authentication (RFC 6750)
|
||||
if (scheme === "bearer") {
|
||||
const filteredHeaders = headers.filter((_, i) => i !== authorizationHeaderIndex);
|
||||
return {
|
||||
authenticationType: "bearer",
|
||||
authentication: { token: credentials, prefix: "Bearer" },
|
||||
filteredHeaders,
|
||||
};
|
||||
}
|
||||
|
||||
// Basic authentication (RFC 7617)
|
||||
if (scheme === "basic") {
|
||||
try {
|
||||
const decoded = Buffer.from(credentials, "base64").toString();
|
||||
const colonIndex = decoded.indexOf(":");
|
||||
if (colonIndex > 0) {
|
||||
const filteredHeaders = headers.filter((_, i) => i !== authorizationHeaderIndex);
|
||||
return {
|
||||
authenticationType: "basic",
|
||||
authentication: {
|
||||
username: decoded.slice(0, colonIndex),
|
||||
password: decoded.slice(colonIndex + 1),
|
||||
},
|
||||
filteredHeaders,
|
||||
};
|
||||
}
|
||||
} catch {
|
||||
// Invalid base64, keep header as-is
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
authenticationType: null,
|
||||
authentication: {},
|
||||
filteredHeaders: headers,
|
||||
};
|
||||
}
|
||||
|
||||
function importCommand(parseEntries: string[], workspaceId: string) {
|
||||
// ~~~~~~~~~~~~~~~~~~~~~ //
|
||||
// Collect all the flags //
|
||||
@@ -323,8 +395,23 @@ function importCommand(parseEntries: string[], workspaceId: string) {
|
||||
});
|
||||
}
|
||||
|
||||
// Extract authentication from Authorization headers (Bearer/Basic)
|
||||
const {
|
||||
authenticationType: extractedAuthenticationType,
|
||||
authentication: extractedAuthentication,
|
||||
filteredHeaders,
|
||||
} = extractAuthenticationFromHeaders(headers);
|
||||
|
||||
// Use extracted authentication from header if found, otherwise fall back to -u/--user parsing
|
||||
const finalAuthenticationType = extractedAuthenticationType || authenticationType;
|
||||
const finalAuthentication = extractedAuthenticationType
|
||||
? extractedAuthentication
|
||||
: authentication;
|
||||
|
||||
// Body (Text or Blob)
|
||||
const contentTypeHeader = headers.find((header) => header.name.toLowerCase() === "content-type");
|
||||
const contentTypeHeader = filteredHeaders.find(
|
||||
(header) => header.name.toLowerCase() === "content-type",
|
||||
);
|
||||
const mimeType = contentTypeHeader ? contentTypeHeader.value.split(";")[0]?.trim() : null;
|
||||
|
||||
// Extract boundary from Content-Type header for multipart parsing
|
||||
@@ -398,7 +485,7 @@ function importCommand(parseEntries: string[], workspaceId: string) {
|
||||
value: decodeURIComponent(parameter.value || ""),
|
||||
})),
|
||||
};
|
||||
headers.push({
|
||||
filteredHeaders.push({
|
||||
name: "Content-Type",
|
||||
value: "application/x-www-form-urlencoded",
|
||||
enabled: true,
|
||||
@@ -419,7 +506,7 @@ function importCommand(parseEntries: string[], workspaceId: string) {
|
||||
form: formDataParams,
|
||||
};
|
||||
if (mimeType == null) {
|
||||
headers.push({
|
||||
filteredHeaders.push({
|
||||
name: "Content-Type",
|
||||
value: "multipart/form-data",
|
||||
enabled: true,
|
||||
@@ -442,9 +529,9 @@ function importCommand(parseEntries: string[], workspaceId: string) {
|
||||
urlParameters,
|
||||
url,
|
||||
method,
|
||||
headers,
|
||||
authentication,
|
||||
authenticationType,
|
||||
headers: filteredHeaders,
|
||||
authentication: finalAuthentication,
|
||||
authenticationType: finalAuthenticationType,
|
||||
body,
|
||||
bodyType,
|
||||
folderId: null,
|
||||
|
||||
@@ -332,6 +332,142 @@ describe("importer-curl", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("Imports Bearer token from Authorization header", () => {
|
||||
expect(convertCurl('curl -H "Authorization: Bearer token123" https://yaak.app')).toEqual({
|
||||
resources: {
|
||||
workspaces: [baseWorkspace()],
|
||||
httpRequests: [
|
||||
baseRequest({
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "bearer",
|
||||
authentication: {
|
||||
token: "token123",
|
||||
prefix: "Bearer",
|
||||
},
|
||||
headers: [],
|
||||
}),
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test("Trims whitespace before Bearer token from Authorization header", () => {
|
||||
expect(convertCurl('curl -H "Authorization: Bearer token123" https://yaak.app')).toEqual({
|
||||
resources: {
|
||||
workspaces: [baseWorkspace()],
|
||||
httpRequests: [
|
||||
baseRequest({
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "bearer",
|
||||
authentication: {
|
||||
token: "token123",
|
||||
prefix: "Bearer",
|
||||
},
|
||||
headers: [],
|
||||
}),
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test("Imports Basic auth from Authorization header (base64 decoded)", () => {
|
||||
expect(
|
||||
convertCurl('curl -H "Authorization: Basic dXNlcjpwYXNzd29yZA==" https://yaak.app'),
|
||||
).toEqual({
|
||||
resources: {
|
||||
workspaces: [baseWorkspace()],
|
||||
httpRequests: [
|
||||
baseRequest({
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "basic",
|
||||
authentication: {
|
||||
username: "user",
|
||||
password: "password",
|
||||
},
|
||||
headers: [],
|
||||
}),
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test("Authorization header takes precedence over -u flag", () => {
|
||||
expect(
|
||||
convertCurl('curl -u admin:secret -H "Authorization: Bearer token123" https://yaak.app'),
|
||||
).toEqual({
|
||||
resources: {
|
||||
workspaces: [baseWorkspace()],
|
||||
httpRequests: [
|
||||
baseRequest({
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "bearer",
|
||||
authentication: {
|
||||
token: "token123",
|
||||
prefix: "Bearer",
|
||||
},
|
||||
headers: [],
|
||||
}),
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test("Authorization header extraction is case-insensitive", () => {
|
||||
expect(convertCurl('curl -H "authorization: bearer lowercaseToken" https://yaak.app')).toEqual({
|
||||
resources: {
|
||||
workspaces: [baseWorkspace()],
|
||||
httpRequests: [
|
||||
baseRequest({
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "bearer",
|
||||
authentication: {
|
||||
token: "lowercaseToken",
|
||||
prefix: "Bearer",
|
||||
},
|
||||
headers: [],
|
||||
}),
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test("Preserves other headers when extracting Authorization", () => {
|
||||
expect(
|
||||
convertCurl('curl -H "Authorization: Bearer token123" -H "X-Custom: value" https://yaak.app'),
|
||||
).toEqual({
|
||||
resources: {
|
||||
workspaces: [baseWorkspace()],
|
||||
httpRequests: [
|
||||
baseRequest({
|
||||
url: "https://yaak.app",
|
||||
authenticationType: "bearer",
|
||||
authentication: {
|
||||
token: "token123",
|
||||
prefix: "Bearer",
|
||||
},
|
||||
headers: [{ name: "X-Custom", value: "value", enabled: true }],
|
||||
}),
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test("Invalid base64 in Basic auth keeps header in headers", () => {
|
||||
expect(
|
||||
convertCurl('curl -H "Authorization: Basic not-valid-base64!!!" https://yaak.app'),
|
||||
).toEqual({
|
||||
resources: {
|
||||
workspaces: [baseWorkspace()],
|
||||
httpRequests: [
|
||||
baseRequest({
|
||||
url: "https://yaak.app",
|
||||
headers: [{ name: "Authorization", value: "Basic not-valid-base64!!!", enabled: true }],
|
||||
}),
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test("Imports cookie as header", () => {
|
||||
expect(convertCurl('curl --cookie "foo=bar" https://yaak.app')).toEqual({
|
||||
resources: {
|
||||
|
||||
Reference in New Issue
Block a user