import { platform } from "@yaakapp-internal/platform"; import { InlineCode } from "@yaakapp-internal/ui"; import { Link } from "../components/core/Link"; import { showConfirm } from "./confirm"; const acceptedProxies = new Set(); const pendingConfirmations = new Map>(); /** One decision for all pending sends; only acceptance is remembered. */ export function confirmWebProxy(): Promise { const proxyUrl = platform.httpProxyUrl; if (proxyUrl == null) return Promise.resolve(true); const key = `yaak.webProxyConsent.v1:${proxyUrl}`; try { if (localStorage.getItem(key) === "accepted") return Promise.resolve(true); } catch { // Storage can be unavailable in private or restricted browsing. } if (acceptedProxies.has(proxyUrl)) return Promise.resolve(true); const pending = pendingConfirmations.get(proxyUrl); if (pending != null) return pending; const confirmation = showConfirm({ id: "web-proxy-consent", title: "Requests in Yaak Web use a proxy", confirmText: "Send via Proxy", description: (

Yaak Web sends requests through a hosted proxy. Request and response data, including credentials, pass through the server shown below.

{proxyUrl}

Learn more about{" "} how the proxy works.

), }) .then((accepted) => { if (accepted) { acceptedProxies.add(proxyUrl); try { localStorage.setItem(key, "accepted"); } catch { // Keep acceptance for this tab if it cannot be persisted. } } return accepted; }) .finally(() => pendingConfirmations.delete(proxyUrl)); pendingConfirmations.set(proxyUrl, confirmation); return confirmation; }