dsh-magpie-connect 0.7.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dsh.plugin.json +1 -1
- package/lib/client.js +57 -22
- package/lib/index.js +83 -25
- package/lib/index.js.map +2 -2
- package/lib/types/client/trace-wires.d.ts +65 -0
- package/lib/types/trace.d.ts +2 -0
- package/package.json +1 -1
package/dsh.plugin.json
CHANGED
package/lib/client.js
CHANGED
|
@@ -781,7 +781,7 @@ function shouldRetryPending(snapshot2, attempts, limit = PENDING_RETRY_LIMIT) {
|
|
|
781
781
|
|
|
782
782
|
// src/client/page.tsx
|
|
783
783
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
784
|
-
var PLUGIN_VERSION = "0.7.
|
|
784
|
+
var PLUGIN_VERSION = "0.7.2";
|
|
785
785
|
var REPO_URL = "https://github.com/bitxeno/dsh-magpie-connect";
|
|
786
786
|
var css2 = {
|
|
787
787
|
section: { display: "flex", flexDirection: "column", gap: 16, maxWidth: 780, paddingBottom: 32 },
|
|
@@ -1401,6 +1401,34 @@ function prefersCoarsePointer(target) {
|
|
|
1401
1401
|
return matchMedia("(pointer: coarse)").matches;
|
|
1402
1402
|
}
|
|
1403
1403
|
|
|
1404
|
+
// src/client/trace-wires.ts
|
|
1405
|
+
var WIRE_GUTTER = 34;
|
|
1406
|
+
var WIRE_X0 = 10;
|
|
1407
|
+
var WIRE_X1 = 26;
|
|
1408
|
+
var WIRE_Y0 = 16;
|
|
1409
|
+
var NO_WIRES = { width: 0, height: 0, paths: [] };
|
|
1410
|
+
function buildWireState(group, cards, activeIndex, outcomes) {
|
|
1411
|
+
const midX = (WIRE_X0 + WIRE_X1) / 2;
|
|
1412
|
+
const paths = cards.map((card, index) => {
|
|
1413
|
+
const y3 = card.top - group.top + card.height / 2;
|
|
1414
|
+
return {
|
|
1415
|
+
// The S curve: leave the header horizontally, bend through the gutter,
|
|
1416
|
+
// and meet the card horizontally at its mid-height.
|
|
1417
|
+
d: `M${WIRE_X0} ${WIRE_Y0} C${midX} ${WIRE_Y0} ${midX} ${y3} ${WIRE_X1} ${y3}`,
|
|
1418
|
+
active: index === activeIndex,
|
|
1419
|
+
live: outcomes[index] === "processing"
|
|
1420
|
+
};
|
|
1421
|
+
});
|
|
1422
|
+
return { width: WIRE_GUTTER, height: group.height, paths };
|
|
1423
|
+
}
|
|
1424
|
+
function sameWires(a, b) {
|
|
1425
|
+
if (a.width !== b.width || a.height !== b.height || a.paths.length !== b.paths.length) return false;
|
|
1426
|
+
return a.paths.every((path, index) => {
|
|
1427
|
+
const other = b.paths[index];
|
|
1428
|
+
return other !== void 0 && other.d === path.d && other.active === path.active && other.live === path.live;
|
|
1429
|
+
});
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1404
1432
|
// src/client/trace-button.tsx
|
|
1405
1433
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1406
1434
|
var DESKTOP_REFRESH_MS = 5e3;
|
|
@@ -1792,42 +1820,49 @@ function RoutingGroupCard(props) {
|
|
|
1792
1820
|
const showHeader = section.hideHeader !== true;
|
|
1793
1821
|
const activeIndex = section.candidates.findIndex((candidate) => candidate.outcome === "answered" || candidate.outcome === "processing");
|
|
1794
1822
|
const groupRef = (0, import_react4.useRef)(null);
|
|
1795
|
-
const [wires, setWires] = (0, import_react4.useState)(
|
|
1823
|
+
const [wires, setWires] = (0, import_react4.useState)(NO_WIRES);
|
|
1796
1824
|
(0, import_react4.useLayoutEffect)(() => {
|
|
1797
1825
|
const container = groupRef.current;
|
|
1798
1826
|
if (container === null || !showHeader) {
|
|
1799
|
-
setWires(
|
|
1827
|
+
setWires(NO_WIRES);
|
|
1800
1828
|
return;
|
|
1801
1829
|
}
|
|
1802
1830
|
const measure = () => {
|
|
1803
|
-
const rect = container.getBoundingClientRect();
|
|
1804
1831
|
const rows = Array.from(container.querySelectorAll("[data-magpie-candidate]"));
|
|
1805
|
-
const
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
return {
|
|
1813
|
-
d: `M${x0} ${y0} C${mx} ${y0} ${mx} ${y3} ${x3} ${y3}`,
|
|
1814
|
-
active: index === activeIndex,
|
|
1815
|
-
live: section.candidates[index]?.outcome === "processing"
|
|
1816
|
-
};
|
|
1817
|
-
});
|
|
1818
|
-
setWires({ width: rect.width, height: rect.height, paths });
|
|
1832
|
+
const next = buildWireState(
|
|
1833
|
+
container.getBoundingClientRect(),
|
|
1834
|
+
rows.map((row) => row.getBoundingClientRect()),
|
|
1835
|
+
activeIndex,
|
|
1836
|
+
section.candidates.map((candidate) => candidate.outcome)
|
|
1837
|
+
);
|
|
1838
|
+
setWires((current) => sameWires(current, next) ? current : next);
|
|
1819
1839
|
};
|
|
1820
1840
|
measure();
|
|
1821
1841
|
window.addEventListener("resize", measure);
|
|
1822
|
-
|
|
1842
|
+
const observer = new ResizeObserver(measure);
|
|
1843
|
+
observer.observe(container);
|
|
1844
|
+
return () => {
|
|
1845
|
+
observer.disconnect();
|
|
1846
|
+
window.removeEventListener("resize", measure);
|
|
1847
|
+
};
|
|
1823
1848
|
}, [showHeader, activeIndex, section.candidates]);
|
|
1824
1849
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { ref: groupRef, style: traceGroupStyle, children: [
|
|
1825
|
-
showHeader && wires.
|
|
1850
|
+
showHeader && wires.height > 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1826
1851
|
"svg",
|
|
1827
1852
|
{
|
|
1828
1853
|
"aria-hidden": "true",
|
|
1829
|
-
viewBox: `0 0 ${
|
|
1830
|
-
style: {
|
|
1854
|
+
viewBox: `0 0 ${WIRE_GUTTER} ${wires.height}`,
|
|
1855
|
+
style: {
|
|
1856
|
+
position: "absolute",
|
|
1857
|
+
top: 0,
|
|
1858
|
+
left: 0,
|
|
1859
|
+
// An explicit box equal to the viewBox: no aspect-ratio fitting,
|
|
1860
|
+
// so no scale — a stroke stays 1.5px and a wire stays put.
|
|
1861
|
+
width: `${WIRE_GUTTER}px`,
|
|
1862
|
+
height: `${wires.height}px`,
|
|
1863
|
+
overflow: "visible",
|
|
1864
|
+
pointerEvents: "none"
|
|
1865
|
+
},
|
|
1831
1866
|
children: wires.paths.map((wire, index) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1832
1867
|
"path",
|
|
1833
1868
|
{
|
package/lib/index.js
CHANGED
|
@@ -1717,14 +1717,65 @@ function statusForStatusCode(code) {
|
|
|
1717
1717
|
if (code >= 500) return "network";
|
|
1718
1718
|
return "unknown";
|
|
1719
1719
|
}
|
|
1720
|
+
var WEB_PROBE_TIMEOUT_MS = 1500;
|
|
1721
|
+
var WEB_COOKIE_FALLBACK_PORTS = ["3430", "443", "80"];
|
|
1722
|
+
function guessedWebCookie(base) {
|
|
1723
|
+
try {
|
|
1724
|
+
const url = new URL(base);
|
|
1725
|
+
return `magpie_web_${url.port || (url.protocol === "https:" ? "443" : "80")}`;
|
|
1726
|
+
} catch {
|
|
1727
|
+
return "magpie_web_3430";
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
var webCookieNames = /* @__PURE__ */ new Map();
|
|
1731
|
+
var webBasesResolved = /* @__PURE__ */ new Map();
|
|
1732
|
+
async function discoverWebCookieName(base, webKey, signal) {
|
|
1733
|
+
try {
|
|
1734
|
+
const response = await fetch(`${base.replace(/\/+$/, "")}/?k=${encodeURIComponent(webKey)}`, {
|
|
1735
|
+
redirect: "manual",
|
|
1736
|
+
cache: "no-store",
|
|
1737
|
+
signal
|
|
1738
|
+
});
|
|
1739
|
+
const match = /magpie_web_[A-Za-z0-9._-]+/.exec(response.headers.get("set-cookie") ?? "");
|
|
1740
|
+
return match?.[0];
|
|
1741
|
+
} catch {
|
|
1742
|
+
return void 0;
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
async function fetchWebResponse(base, webKey, path, accept, signal) {
|
|
1746
|
+
const tried = [];
|
|
1747
|
+
const attempt = (name2) => {
|
|
1748
|
+
tried.push(name2);
|
|
1749
|
+
return fetch(`${base}${path}`, {
|
|
1750
|
+
headers: { cookie: `${name2}=${webKey}`, accept },
|
|
1751
|
+
cache: "no-store",
|
|
1752
|
+
signal
|
|
1753
|
+
});
|
|
1754
|
+
};
|
|
1755
|
+
const cached = webCookieNames.get(base);
|
|
1756
|
+
let response = await attempt(cached ?? guessedWebCookie(base));
|
|
1757
|
+
if (response.status === 401) {
|
|
1758
|
+
const discovered = await discoverWebCookieName(base, webKey, signal);
|
|
1759
|
+
if (discovered !== void 0 && !tried.includes(discovered)) {
|
|
1760
|
+
response = await attempt(discovered);
|
|
1761
|
+
}
|
|
1762
|
+
if (response.status === 401) {
|
|
1763
|
+
for (const port of WEB_COOKIE_FALLBACK_PORTS) {
|
|
1764
|
+
const name2 = `magpie_web_${port}`;
|
|
1765
|
+
if (tried.includes(name2)) continue;
|
|
1766
|
+
response = await attempt(name2);
|
|
1767
|
+
if (response.status !== 401) break;
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
if (response.ok) {
|
|
1772
|
+
const winner = tried[tried.length - 1];
|
|
1773
|
+
if (winner !== void 0) webCookieNames.set(base, winner);
|
|
1774
|
+
}
|
|
1775
|
+
return response;
|
|
1776
|
+
}
|
|
1720
1777
|
async function fetchWebJson(base, webKey, path, signal) {
|
|
1721
|
-
const
|
|
1722
|
-
const port = url.port || (url.protocol === "https:" ? "443" : "80");
|
|
1723
|
-
const response = await fetch(`${base}${path}`, {
|
|
1724
|
-
headers: { cookie: `magpie_web_${port}=${webKey}`, accept: "application/json" },
|
|
1725
|
-
cache: "no-store",
|
|
1726
|
-
signal
|
|
1727
|
-
});
|
|
1778
|
+
const response = await fetchWebResponse(base, webKey, path, "application/json", signal);
|
|
1728
1779
|
if (!response.ok) {
|
|
1729
1780
|
const error = new Error(`Magpie Web HTTP ${response.status} ${path}`);
|
|
1730
1781
|
error.statusCode = response.status;
|
|
@@ -1733,29 +1784,40 @@ async function fetchWebJson(base, webKey, path, signal) {
|
|
|
1733
1784
|
return await response.json();
|
|
1734
1785
|
}
|
|
1735
1786
|
function webBases(base) {
|
|
1736
|
-
const candidates = [];
|
|
1787
|
+
const candidates = [base];
|
|
1737
1788
|
try {
|
|
1738
1789
|
const url = new URL(base);
|
|
1739
|
-
if (url.port
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1790
|
+
if (url.port !== "3430") {
|
|
1791
|
+
url.port = "3430";
|
|
1792
|
+
candidates.push(`${url.origin}${url.pathname.replace(/\/+$/, "")}`);
|
|
1793
|
+
}
|
|
1743
1794
|
} catch {
|
|
1744
1795
|
return [base];
|
|
1745
1796
|
}
|
|
1746
1797
|
return [...new Set(candidates)];
|
|
1747
1798
|
}
|
|
1799
|
+
function orderedWebBases(base) {
|
|
1800
|
+
const bases = webBases(base);
|
|
1801
|
+
const known = webBasesResolved.get(base);
|
|
1802
|
+
return known !== void 0 && bases.includes(known) ? [known, ...bases.filter((b) => b !== known)] : bases;
|
|
1803
|
+
}
|
|
1804
|
+
function webTrySignal(signal, index) {
|
|
1805
|
+
if (index === 0) return signal;
|
|
1806
|
+
const budget = AbortSignal.timeout(WEB_PROBE_TIMEOUT_MS);
|
|
1807
|
+
return typeof AbortSignal.any === "function" ? AbortSignal.any([signal, budget]) : budget;
|
|
1808
|
+
}
|
|
1748
1809
|
async function fetchFullWebTrace(base, webKey, signal) {
|
|
1749
1810
|
let lastError;
|
|
1750
|
-
for (const candidate of
|
|
1811
|
+
for (const [index, candidate] of orderedWebBases(base).entries()) {
|
|
1751
1812
|
try {
|
|
1752
|
-
const trace = await fetchWebJson(candidate, webKey, `${WEB_TRACE_PATH}?after=0`, signal);
|
|
1813
|
+
const trace = await fetchWebJson(candidate, webKey, `${WEB_TRACE_PATH}?after=0`, webTrySignal(signal, index));
|
|
1753
1814
|
if (!Array.isArray(trace.routes)) {
|
|
1754
1815
|
throw new Error("Magpie Web returned an unexpected trace shape");
|
|
1755
1816
|
}
|
|
1817
|
+
webBasesResolved.set(base, candidate);
|
|
1756
1818
|
return { trace, base: candidate };
|
|
1757
1819
|
} catch (error) {
|
|
1758
|
-
if (
|
|
1820
|
+
if (signal.aborted) throw error;
|
|
1759
1821
|
lastError = error;
|
|
1760
1822
|
}
|
|
1761
1823
|
}
|
|
@@ -1765,13 +1827,7 @@ function routingUrlFor(base) {
|
|
|
1765
1827
|
return `${base.replace(/\/+$/, "")}/?view=routing`;
|
|
1766
1828
|
}
|
|
1767
1829
|
async function fetchWebBinary(base, webKey, path, signal) {
|
|
1768
|
-
const
|
|
1769
|
-
const port = url.port || (url.protocol === "https:" ? "443" : "80");
|
|
1770
|
-
const response = await fetch(`${base}${path}`, {
|
|
1771
|
-
headers: { cookie: `magpie_web_${port}=${webKey}`, accept: "image/svg+xml,image/png,*/*" },
|
|
1772
|
-
cache: "no-store",
|
|
1773
|
-
signal
|
|
1774
|
-
});
|
|
1830
|
+
const response = await fetchWebResponse(base, webKey, path, "image/svg+xml,image/png,*/*", signal);
|
|
1775
1831
|
if (!response.ok) {
|
|
1776
1832
|
const error = new Error(`Magpie Web HTTP ${response.status} ${path}`);
|
|
1777
1833
|
error.statusCode = response.status;
|
|
@@ -1803,11 +1859,13 @@ async function fetchWebIcon(base, webKey, name2, signal) {
|
|
|
1803
1859
|
const ext = PNG_ICONS.has(safe) ? "png" : "svg";
|
|
1804
1860
|
const path = `/icons/${safe}.${ext}`;
|
|
1805
1861
|
let lastError;
|
|
1806
|
-
for (const candidate of
|
|
1862
|
+
for (const [index, candidate] of orderedWebBases(base).entries()) {
|
|
1807
1863
|
try {
|
|
1808
|
-
|
|
1864
|
+
const icon = await fetchWebBinary(candidate, webKey, path, webTrySignal(signal, index));
|
|
1865
|
+
webBasesResolved.set(base, candidate);
|
|
1866
|
+
return icon;
|
|
1809
1867
|
} catch (error) {
|
|
1810
|
-
if (
|
|
1868
|
+
if (signal.aborted) throw error;
|
|
1811
1869
|
lastError = error;
|
|
1812
1870
|
}
|
|
1813
1871
|
}
|