From 955ce583ea5faf51690c2d218939e7ef78b31afa Mon Sep 17 00:00:00 2001 From: AKHIL Date: Tue, 14 Jul 2026 09:30:34 +0530 Subject: [PATCH 1/2] UI --- apps/web/messages/en.json | 11 +- .../__tests__/generate-code.test.ts | 30 ++++ .../components/api-client/p2p-sync-dialog.tsx | 138 ------------------ apps/web/src/lib/p2p/peer-sync.ts | 110 -------------- 4 files changed, 40 insertions(+), 249 deletions(-) create mode 100644 apps/web/src/components/api-client/__tests__/generate-code.test.ts delete mode 100644 apps/web/src/components/api-client/p2p-sync-dialog.tsx delete mode 100644 apps/web/src/lib/p2p/peer-sync.ts diff --git a/apps/web/messages/en.json b/apps/web/messages/en.json index b75d7296..bce7291c 100644 --- a/apps/web/messages/en.json +++ b/apps/web/messages/en.json @@ -1863,8 +1863,17 @@ "code": "Generate code", "save": "Save request", "importCurl": "Import cURL", + "importCollection": "Import collection (Postman / HAR)", "environments": "Environments", - "shortcuts": "Keyboard shortcuts" + "cookies": "Cookies", + "perfRun": "Performance run", + "fuzzRun": "Fuzz run", + "publicMocks": "Public mocks", + "plugins": "Plugins", + "metrics": "Metrics", + "recorder": "Capture & replay", + "shortcuts": "Keyboard shortcuts", + "extensionImported": "Imported {method} {url} from extension" } }, "RichEditor": { diff --git a/apps/web/src/components/api-client/__tests__/generate-code.test.ts b/apps/web/src/components/api-client/__tests__/generate-code.test.ts new file mode 100644 index 00000000..dfd8d484 --- /dev/null +++ b/apps/web/src/components/api-client/__tests__/generate-code.test.ts @@ -0,0 +1,30 @@ +import { generateCode } from "../generate-code" +import type { ApiRequestState } from "../types" + +function gqlRequest(graphqlVariables?: string): ApiRequestState { + return { + method: "POST", + url: "https://api.example.com/graphql", + headers: [], + params: [], + auth: { type: "none" }, + body: { type: "graphql", content: "query { me { id } }", graphqlVariables }, + } as unknown as ApiRequestState +} + +describe("generateCode graphql body", () => { + it("serialises query + variables as JSON with application/json", () => { + const curl = generateCode(gqlRequest('{"id": 1}'), "curl") + expect(curl).toContain('"query":"query { me { id } }"') + expect(curl).toContain('"variables":{"id":1}') + expect(curl).toContain("Content-Type: application/json") + }) + + it("emits query-only payload when variables missing or invalid", () => { + for (const vars of [undefined, "not json"]) { + const curl = generateCode(gqlRequest(vars), "curl") + expect(curl).toContain('{"query":"query { me { id } }"}') + expect(curl).not.toContain('"variables"') + } + }) +}) diff --git a/apps/web/src/components/api-client/p2p-sync-dialog.tsx b/apps/web/src/components/api-client/p2p-sync-dialog.tsx deleted file mode 100644 index 5f839066..00000000 --- a/apps/web/src/components/api-client/p2p-sync-dialog.tsx +++ /dev/null @@ -1,138 +0,0 @@ -"use client" - -import * as React from "react" -import { - Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, -} from "@/components/ui/dialog" -import { Button } from "@/components/ui/button" -import { Textarea } from "@/components/ui/textarea" -import { Label } from "@/components/ui/label" -import { createOffer, acceptOffer, applyAnswer, type PeerSyncHandle } from "@/lib/p2p/peer-sync" -import { useCollectionsState, useCollectionsActions } from "./context/collections-context" -import type { Collection } from "./types" -import { toast } from "sonner" - -interface P2pSyncDialogProps { - open: boolean - onOpenChange: (open: boolean) => void -} - -export function P2pSyncDialog({ open, onOpenChange }: P2pSyncDialogProps) { - const { collections } = useCollectionsState() - const { importCollection } = useCollectionsActions() - const [mode, setMode] = React.useState<"offer" | "accept">("offer") - const [offerSdp, setOfferSdp] = React.useState("") - const [answerSdp, setAnswerSdp] = React.useState("") - const [handleRef, setHandleRef] = React.useState(null) - const [status, setStatus] = React.useState("idle") - - React.useEffect(() => () => handleRef?.close(), [handleRef]) - - const startAsOfferer = async () => { - setStatus("creating offer…") - const { handle, offer } = await createOffer({ - onOpen: () => { - setStatus("connected — sending collections") - try { handle.send({ kind: "collections", payload: collections }) } - catch (e) { toast.error((e as Error).message) } - }, - onMessage: async (msg) => { - const data = msg as { kind?: string; payload?: Collection[] } - if (data?.kind === "collections" && Array.isArray(data.payload)) { - let imported = 0 - for (const c of data.payload) { - const out = await importCollection(c) - if (out) imported++ - } - toast.success(`Imported ${imported} peer collections`) - } - }, - onClose: () => setStatus("disconnected"), - }) - setHandleRef(handle) - setOfferSdp(offer) - setStatus("share the offer SDP with peer; paste their answer below") - } - - const acceptAsReceiver = async () => { - if (!offerSdp.trim()) return - setStatus("accepting offer…") - const { handle, answer } = await acceptOffer(offerSdp, { - onOpen: () => { - setStatus("connected — sending collections") - try { handle.send({ kind: "collections", payload: collections }) } - catch (e) { toast.error((e as Error).message) } - }, - onMessage: async (msg) => { - const data = msg as { kind?: string; payload?: Collection[] } - if (data?.kind === "collections" && Array.isArray(data.payload)) { - let imported = 0 - for (const c of data.payload) { - const out = await importCollection(c) - if (out) imported++ - } - toast.success(`Imported ${imported} peer collections`) - } - }, - onClose: () => setStatus("disconnected"), - }) - setHandleRef(handle) - setAnswerSdp(answer) - setStatus("share the answer SDP back to the offerer") - } - - const applyPeerAnswer = async () => { - if (!handleRef || !answerSdp.trim()) return - await applyAnswer(handleRef, answerSdp) - setStatus("waiting for channel to open…") - } - - return ( - - - - Peer sync (WebRTC) - - Direct E2E-encrypted swap of collections between two clients. Out-of-band signalling — - copy/paste the SDP blobs over any side channel. - - -
- - - {status} -
- {mode === "offer" ? ( -
- - {offerSdp && ( - <> - -