Expose HTTP cookie source through the console API
The coredata CookieSource enum and the ingestion path both support an HTTP source, but the GraphQL CookieSource enum never declared it. The generated marshaler is a plain map lookup with no fallback, so an HTTP value missed the map and serialized to an empty string. The console UI treats that empty string as falsy and rendered no source badge at all, making HTTP-sourced trackers look sourceless. Add the HTTP member to the GraphQL enum so the value round-trips, and fold the duplicated tracker-type and tracker-source badge helpers from three components into a shared @probo/helpers module, adding an explicit HTTP label while consolidating. Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import { getTrackerSourceBadge } from "@probo/helpers";
|
||||
import { useTranslate } from "@probo/i18n";
|
||||
import { Badge, Td, Tr } from "@probo/ui";
|
||||
import { graphql, useFragment } from "react-relay";
|
||||
@@ -29,14 +30,6 @@ const detectedTrackerFragment = graphql`
|
||||
}
|
||||
`;
|
||||
|
||||
function sourceBadge(source: string, __: (s: string) => string) {
|
||||
switch (source) {
|
||||
case "SCRIPT": return { label: __("Script"), variant: "info" as const };
|
||||
case "PRE_EXISTING": return { label: __("Pre-existing"), variant: "outline" as const };
|
||||
default: return { label: source, variant: "neutral" as const };
|
||||
}
|
||||
}
|
||||
|
||||
interface DetectedTrackerRowProps {
|
||||
detectedTrackerKey: DetectedTrackerRow_detectedTracker$key;
|
||||
}
|
||||
@@ -63,8 +56,8 @@ export function DetectedTrackerRow({ detectedTrackerKey }: DetectedTrackerRowPro
|
||||
<Td>
|
||||
{tracker.source
|
||||
? (
|
||||
<Badge variant={sourceBadge(tracker.source, __).variant}>
|
||||
{sourceBadge(tracker.source, __).label}
|
||||
<Badge variant={getTrackerSourceBadge(tracker.source, __).variant}>
|
||||
{getTrackerSourceBadge(tracker.source, __).label}
|
||||
</Badge>
|
||||
)
|
||||
: <span className="text-txt-tertiary">-</span>}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import { humanizeSeconds } from "@probo/helpers";
|
||||
import { getTrackerSourceBadge, getTrackerTypeBadge, humanizeSeconds } from "@probo/helpers";
|
||||
import { useTranslate } from "@probo/i18n";
|
||||
import { Badge, Card, PropertyRow } from "@probo/ui";
|
||||
import { graphql, useFragment } from "react-relay";
|
||||
@@ -42,25 +42,6 @@ const trackerPatternPropertiesSectionFragment = graphql`
|
||||
}
|
||||
`;
|
||||
|
||||
function trackerTypeBadge(type: string, __: (s: string) => string) {
|
||||
switch (type) {
|
||||
case "COOKIE": return { label: __("Cookie"), variant: "warning" as const };
|
||||
case "LOCAL_STORAGE": return { label: __("localStorage"), variant: "info" as const };
|
||||
case "SESSION_STORAGE": return { label: __("sessionStorage"), variant: "highlight" as const };
|
||||
case "INDEXED_DB": return { label: __("IndexedDB"), variant: "success" as const };
|
||||
case "CACHE_STORAGE": return { label: __("Cache Storage"), variant: "outline" as const };
|
||||
default: return { label: type, variant: "neutral" as const };
|
||||
}
|
||||
}
|
||||
|
||||
function sourceBadge(source: string, __: (s: string) => string) {
|
||||
switch (source) {
|
||||
case "SCRIPT": return { label: __("Script"), variant: "info" as const };
|
||||
case "PRE_EXISTING": return { label: __("Pre-existing"), variant: "outline" as const };
|
||||
default: return { label: source, variant: "neutral" as const };
|
||||
}
|
||||
}
|
||||
|
||||
interface TrackerPatternPropertiesSectionProps {
|
||||
trackerPatternKey: TrackerPatternPropertiesSection_trackerPattern$key;
|
||||
}
|
||||
@@ -74,7 +55,7 @@ export function TrackerPatternPropertiesSection({
|
||||
trackerPatternKey,
|
||||
);
|
||||
|
||||
const typeBadge = trackerTypeBadge(pattern.trackerType, __);
|
||||
const typeBadge = getTrackerTypeBadge(pattern.trackerType, __);
|
||||
|
||||
return (
|
||||
<Card padded>
|
||||
@@ -89,8 +70,8 @@ export function TrackerPatternPropertiesSection({
|
||||
</PropertyRow>
|
||||
{pattern.source && (
|
||||
<PropertyRow label={__("Source")}>
|
||||
<Badge variant={sourceBadge(pattern.source, __).variant}>
|
||||
{sourceBadge(pattern.source, __).label}
|
||||
<Badge variant={getTrackerSourceBadge(pattern.source, __).variant}>
|
||||
{getTrackerSourceBadge(pattern.source, __).label}
|
||||
</Badge>
|
||||
</PropertyRow>
|
||||
)}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import { EyeIcon, EyeSlashIcon } from "@phosphor-icons/react";
|
||||
import { formatError, type GraphQLError } from "@probo/helpers";
|
||||
import { formatError, getTrackerSourceBadge, getTrackerTypeBadge, type GraphQLError } from "@probo/helpers";
|
||||
import { useTranslate } from "@probo/i18n";
|
||||
import {
|
||||
Badge,
|
||||
@@ -134,25 +134,6 @@ const updatePatternMutation = graphql`
|
||||
}
|
||||
`;
|
||||
|
||||
function trackerTypeBadge(type: string, __: (s: string) => string) {
|
||||
switch (type) {
|
||||
case "COOKIE": return { label: __("Cookie"), variant: "warning" as const };
|
||||
case "LOCAL_STORAGE": return { label: __("localStorage"), variant: "info" as const };
|
||||
case "SESSION_STORAGE": return { label: __("sessionStorage"), variant: "highlight" as const };
|
||||
case "INDEXED_DB": return { label: __("IndexedDB"), variant: "success" as const };
|
||||
case "CACHE_STORAGE": return { label: __("Cache Storage"), variant: "outline" as const };
|
||||
default: return { label: type, variant: "neutral" as const };
|
||||
}
|
||||
}
|
||||
|
||||
function sourceBadge(source: string, __: (s: string) => string) {
|
||||
switch (source) {
|
||||
case "SCRIPT": return { label: __("Script"), variant: "info" as const };
|
||||
case "PRE_EXISTING": return { label: __("Pre-existing"), variant: "outline" as const };
|
||||
default: return { label: source, variant: "neutral" as const };
|
||||
}
|
||||
}
|
||||
|
||||
interface TrackerPatternRowProps {
|
||||
patternKey: TrackerPatternRowFragment$key;
|
||||
connectionId: string;
|
||||
@@ -304,8 +285,8 @@ export function TrackerPatternRow({ patternKey, connectionId }: TrackerPatternRo
|
||||
);
|
||||
}
|
||||
|
||||
const typeBadge = trackerTypeBadge(pattern.trackerType, __);
|
||||
const srcBadge = pattern.source ? sourceBadge(pattern.source, __) : null;
|
||||
const typeBadge = getTrackerTypeBadge(pattern.trackerType, __);
|
||||
const srcBadge = pattern.source ? getTrackerSourceBadge(pattern.source, __) : null;
|
||||
|
||||
return (
|
||||
<Tr to={pattern.id} className={pattern.excluded ? "bg-txt-quaternary opacity-80 line-through" : undefined}>
|
||||
|
||||
@@ -109,6 +109,7 @@ export {
|
||||
toMaxAgeSeconds,
|
||||
fromMaxAgeSeconds,
|
||||
} from "./duration";
|
||||
export { getTrackerTypeBadge, getTrackerSourceBadge } from "./tracker";
|
||||
export { getTrustCenterUrl } from "./trustCenter";
|
||||
export { detectSocialName } from "./socialUrl";
|
||||
export { formatError, type GraphQLError } from "./error";
|
||||
|
||||
48
packages/helpers/src/tracker.ts
Normal file
48
packages/helpers/src/tracker.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright (c) 2025-2026 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
type Translator = (s: string) => string;
|
||||
|
||||
type BadgeVariant
|
||||
= | "warning"
|
||||
| "info"
|
||||
| "highlight"
|
||||
| "success"
|
||||
| "outline"
|
||||
| "neutral";
|
||||
|
||||
type Badge = {
|
||||
label: string;
|
||||
variant: BadgeVariant;
|
||||
};
|
||||
|
||||
export function getTrackerTypeBadge(type: string, __: Translator): Badge {
|
||||
switch (type) {
|
||||
case "COOKIE": return { label: __("Cookie"), variant: "warning" };
|
||||
case "LOCAL_STORAGE": return { label: __("localStorage"), variant: "info" };
|
||||
case "SESSION_STORAGE": return { label: __("sessionStorage"), variant: "highlight" };
|
||||
case "INDEXED_DB": return { label: __("IndexedDB"), variant: "success" };
|
||||
case "CACHE_STORAGE": return { label: __("Cache Storage"), variant: "outline" };
|
||||
default: return { label: type, variant: "neutral" };
|
||||
}
|
||||
}
|
||||
|
||||
export function getTrackerSourceBadge(source: string, __: Translator): Badge {
|
||||
switch (source) {
|
||||
case "SCRIPT": return { label: __("Script"), variant: "info" };
|
||||
case "PRE_EXISTING": return { label: __("Pre-existing"), variant: "outline" };
|
||||
case "HTTP": return { label: __("HTTP"), variant: "neutral" };
|
||||
default: return { label: source, variant: "neutral" };
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,10 @@ enum CookieSource
|
||||
@goEnum(
|
||||
value: "go.probo.inc/probo/pkg/coredata.CookieSourcePreExisting"
|
||||
)
|
||||
HTTP
|
||||
@goEnum(
|
||||
value: "go.probo.inc/probo/pkg/coredata.CookieSourceHTTP"
|
||||
)
|
||||
EXTENSION
|
||||
@goEnum(
|
||||
value: "go.probo.inc/probo/pkg/coredata.CookieSourceExtension"
|
||||
|
||||
Reference in New Issue
Block a user