Skip to content
Merged
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
10 changes: 10 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
[tools]
node = "20"
pnpm = "9"

[tasks.validate]
description = "Run all checks: install, lint, typecheck, test, build"
run = """
pnpm i
pnpm lint
pnpm typecheck
pnpm test
pnpm build
"""
2 changes: 1 addition & 1 deletion caido.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default defineConfig({
id,
name: "Data Grep",
description: "Extract data from your requests and responses",
version: "1.2.3",
version: "1.2.4",
author: {
name: "Caido Labs Inc.",
email: "dev@caido.io",
Expand Down
22 changes: 22 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { defaultConfig } from "@caido/eslint-config";
import globals from "globals";

export default [
...defaultConfig({
compat: false,
}),
{
files: ["packages/frontend/**/*.{ts,vue}"],
languageOptions: {
globals: {
...globals.browser,
},
},
},
{
ignores: [
"packages/backend/vitest.config.ts",
"packages/frontend/vitest.config.ts",
],
},
];
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@
"name": "frontend-vue",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"test": "pnpm -r --parallel test",
"typecheck": "pnpm -r typecheck",
"lint": "eslint packages/",
"lint:fix": "eslint packages/ --fix",
"build": "caido-dev build",
"watch": "caido-dev watch"
},
"devDependencies": {
"@caido-community/dev": "^0.1.3",
"@caido-community/dev": "0.1.6",
"@caido/eslint-config": "0.9.0",
"@caido/tailwindcss": "0.0.1",
"@vitejs/plugin-vue": "5.2.1",
"eslint": "9.39.4",
"globals": "17.5.0",
"postcss-prefixwrap": "1.51.0",
"tailwindcss": "3.4.13",
"tailwindcss-primeui": "0.3.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"devDependencies": {
"@caido/sdk-backend": "0.55.3",
"shared": "workspace:*",
"vitest": "^2.1.0"
"vitest": "2.1.9"
},
"dependencies": {
"zod": "3.25.76"
Expand Down
27 changes: 14 additions & 13 deletions packages/backend/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { GrepOptions, CustomRegex, MatchResult } from "shared";
import type { CustomRegex, GrepOptions, MatchResult } from "shared";

import { grepService } from "../services/grep";
import { getStorageService } from "../services/storage";
import type { CaidoBackendSDK } from "../types";
import {
CustomRegexSchema,
GrepOptionsSchema,
RegexIdSchema,
GrepPatternSchema,
RegexIdSchema,
} from "../validation/schemas";
import { handleValidationError } from "../validation/utils";

Expand All @@ -16,7 +17,7 @@ import { handleValidationError } from "../validation/utils";
export const grepRequests = async (
sdk: CaidoBackendSDK,
pattern: string,
options: GrepOptions
options: GrepOptions,
): Promise<{
data?: {
matchesCount?: number;
Expand All @@ -37,7 +38,7 @@ export const grepRequests = async (
/**
* Stop an active grep operation
*/
export const stopGrep = async (): Promise<{
export const stopGrep = (): Promise<{
data?: { success: boolean; message: string };
error?: string;
}> => {
Expand All @@ -47,17 +48,17 @@ export const stopGrep = async (): Promise<{
/**
* Returns all matches from the last completed grep operation
*/
export const downloadResults = async (): Promise<{
export const downloadResults = (): {
data?: MatchResult[];
error?: string;
}> => {
} => {
return grepService.downloadResults();
};

export const upsertCustomRegex = async (
sdk: CaidoBackendSDK,
id: string,
regex: CustomRegex
regex: CustomRegex,
): Promise<{
data?: { success: boolean };
error?: string;
Expand All @@ -75,7 +76,7 @@ export const upsertCustomRegex = async (
};

export const listCustomRegexes = async (
sdk: CaidoBackendSDK
sdk: CaidoBackendSDK,
): Promise<{
data?: { id: string; regex: CustomRegex }[];
error?: string;
Expand All @@ -91,7 +92,7 @@ export const listCustomRegexes = async (

export const deleteCustomRegex = async (
sdk: CaidoBackendSDK,
id: string
id: string,
): Promise<{
data?: { success: boolean };
error?: string;
Expand All @@ -115,11 +116,11 @@ export const deleteCustomRegex = async (
*/
export const getRequestData = async (
sdk: CaidoBackendSDK,
requestId: string
requestId: string,
): Promise<{
data?: {
requestRaw: string;
responseRaw: string | null;
responseRaw?: string;
};
error?: string;
}> => {
Expand All @@ -129,8 +130,8 @@ export const getRequestData = async (
return { error: "Request not found" };
}

const requestRaw = reqRes.request.getRaw()?.toText() || "";
const responseRaw = reqRes.response?.getRaw()?.toText() || null;
const requestRaw = reqRes.request.getRaw()?.toText() ?? "";
const responseRaw = reqRes.response?.getRaw()?.toText();

return {
data: {
Expand Down
7 changes: 4 additions & 3 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { DefineAPI, SDK } from "caido:plugin";

import {
deleteCustomRegex,
downloadResults,
getRequestData,
grepRequests,
listCustomRegexes,
stopGrep,
upsertCustomRegex,
listCustomRegexes,
deleteCustomRegex,
getRequestData,
} from "./api";
import { initStorageService } from "./services/storage";
import type { BackendEvents } from "./types";
Expand Down
24 changes: 12 additions & 12 deletions packages/backend/src/services/grep.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, it, expect, vi } from "vitest";
import { grepService } from "./grep";
import type { GrepOptions } from "shared";
import { describe, expect, it, type Mock, vi } from "vitest";

import { grepService } from "./grep";

function createMockRequest(id: string, raw: string) {
return {
Expand All @@ -26,9 +27,10 @@ function createMockSDK(
const mockItems = items.map((item) => ({
cursor: item.id,
request: createMockRequest(item.id, item.rawRequest),
response: item.rawResponse
? createMockResponse(item.rawResponse)
: undefined,
response:
item.rawResponse !== undefined
? createMockResponse(item.rawResponse)
: undefined,
}));

let queryCallCount = 0;
Expand Down Expand Up @@ -84,16 +86,16 @@ function createMockSDK(
const defaultOptions: GrepOptions = {
includeRequests: true,
includeResponses: false,
maxResults: null,
maxResults: undefined,
matchGroups: [0],
onlyInScope: false,
skipLargeResponses: false,
customHTTPQL: null,
customHTTPQL: undefined,
cleanupOutput: false,
transformScript: null,
transformScript: undefined,
};

function getMatchValues(send: ReturnType<typeof vi.fn>): string[] {
function getMatchValues(send: Mock): string[] {
return send.mock.calls
.filter(
(call: unknown[]) =>
Expand Down Expand Up @@ -311,9 +313,7 @@ describe("grepService.grepRequests", () => {

it("returns error when no project is selected", async () => {
const { sdk } = createMockSDK([]);
(sdk.projects.getCurrent as ReturnType<typeof vi.fn>).mockResolvedValue(
null,
);
vi.mocked(sdk.projects.getCurrent).mockResolvedValue(null as never);

const result = await grepService.grepRequests(sdk, "test", defaultOptions);

Expand Down
Loading
Loading