import React from "react";
import { getMemory } from "../memory";
import { RequestCluster } from "../request-cluster";
import { MergedStolenDataEntry, Sources } from "../stolen-data-entry";
import { hyphenate, useEmitter } from "../util";
const MAX_STRING_VALUE_LENGTH = 100;
function StolenDataValueTable({
entry,
prefixKey = "",
}: {
entry: MergedStolenDataEntry;
prefixKey: string;
}) {
return (
{entry.getDecodingsApplied().includes("base64") ? (
"base64"
) : (
""
)}
{Object.keys(entry.getParsedValues(prefixKey)[0]).map((key) => {
const subkey = `${prefixKey}.${key}`;
return (
{
entry.toggleMark(subkey);
e.stopPropagation();
}}
style={{
border: entry.hasMark(subkey)
? "2px solid red"
: "2px solid transparent",
}}
>
{hyphenate(key)}
|
|
);
})}
);
}
function StolenDataValue({
entry,
prefixKey = "",
}: {
entry: MergedStolenDataEntry;
prefixKey?: string;
}) {
const [version] = useEmitter(entry);
const value = entry.getParsedValues(prefixKey)[0];
let body = null;
if (!value) {
body = <>>;
} else if (typeof value === "string") {
const content = entry.getParsedValues(prefixKey)[0] as string;
body = (
{content.slice(0, MAX_STRING_VALUE_LENGTH)}{" "}
{content.length > MAX_STRING_VALUE_LENGTH ? "(...)" : ""}
);
} else {
body = ;
}
return (
{
entry.toggleMark(prefixKey);
e.stopPropagation();
}}
data-marks={entry.getMarkedValues().join(", ")}
>
{body}
);
}
const icons: Record = {
cookie: "🍪",
pathname: "🛣",
queryparams: "🅿",
header: "H",
};
function StolenDataRow({
entry,
cluster,
}: {
entry: MergedStolenDataEntry;
cluster: RequestCluster;
}) {
const [version] = useEmitter(entry);
return (
entry.toggleMark("")}
>
{entry.getNames().map(hyphenate).join(", ")}
|
{entry.getSources().map((source) => icons[source])} |
|
);
}
export default function StolenDataCluster({
origin,
shorthost,
minValueLength,
cookiesOnly,
cookiesOrOriginOnly,
}: {
origin: string;
shorthost: string;
refreshToken: number;
minValueLength: number;
cookiesOnly: boolean;
cookiesOrOriginOnly: boolean;
}) {
const cluster = getMemory().getClustersForOrigin(origin)[shorthost];
return (
{cluster.getFullHosts().map((host) => (
{host},
))}
{cluster
.getStolenData({ minValueLength, cookiesOnly, cookiesOrOriginOnly })
.map((entry) => (
))}
);
}