From 12f9dfa352c77b5d02f98e1bfd4beeb808e8615f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Fri, 29 May 2026 12:56:36 +0200 Subject: [PATCH] Expose HTTP cookie source through the console API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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é --- .../_components/DetectedTrackerRow.tsx | 13 ++--- .../TrackerPatternPropertiesSection.tsx | 27 ++--------- .../_components/TrackerPatternRow.tsx | 25 ++-------- packages/helpers/src/index.ts | 1 + packages/helpers/src/tracker.ts | 48 +++++++++++++++++++ .../console/v1/graphql/cookie_banner.graphql | 4 ++ 6 files changed, 63 insertions(+), 55 deletions(-) create mode 100644 packages/helpers/src/tracker.ts diff --git a/apps/console/src/pages/organizations/cookie-banners/configuration/trackers/_components/DetectedTrackerRow.tsx b/apps/console/src/pages/organizations/cookie-banners/configuration/trackers/_components/DetectedTrackerRow.tsx index f07355ef0..f444f498f 100644 --- a/apps/console/src/pages/organizations/cookie-banners/configuration/trackers/_components/DetectedTrackerRow.tsx +++ b/apps/console/src/pages/organizations/cookie-banners/configuration/trackers/_components/DetectedTrackerRow.tsx @@ -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 {tracker.source ? ( - - {sourceBadge(tracker.source, __).label} + + {getTrackerSourceBadge(tracker.source, __).label} ) : -} diff --git a/apps/console/src/pages/organizations/cookie-banners/configuration/trackers/_components/TrackerPatternPropertiesSection.tsx b/apps/console/src/pages/organizations/cookie-banners/configuration/trackers/_components/TrackerPatternPropertiesSection.tsx index 42f830708..805ff56d1 100644 --- a/apps/console/src/pages/organizations/cookie-banners/configuration/trackers/_components/TrackerPatternPropertiesSection.tsx +++ b/apps/console/src/pages/organizations/cookie-banners/configuration/trackers/_components/TrackerPatternPropertiesSection.tsx @@ -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 ( @@ -89,8 +70,8 @@ export function TrackerPatternPropertiesSection({ {pattern.source && ( - - {sourceBadge(pattern.source, __).label} + + {getTrackerSourceBadge(pattern.source, __).label} )} diff --git a/apps/console/src/pages/organizations/cookie-banners/configuration/trackers/_components/TrackerPatternRow.tsx b/apps/console/src/pages/organizations/cookie-banners/configuration/trackers/_components/TrackerPatternRow.tsx index 50055cd68..379d2fc92 100644 --- a/apps/console/src/pages/organizations/cookie-banners/configuration/trackers/_components/TrackerPatternRow.tsx +++ b/apps/console/src/pages/organizations/cookie-banners/configuration/trackers/_components/TrackerPatternRow.tsx @@ -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 ( diff --git a/packages/helpers/src/index.ts b/packages/helpers/src/index.ts index 015a5aff9..14dff2cc7 100644 --- a/packages/helpers/src/index.ts +++ b/packages/helpers/src/index.ts @@ -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"; diff --git a/packages/helpers/src/tracker.ts b/packages/helpers/src/tracker.ts new file mode 100644 index 000000000..a3d4e8b3d --- /dev/null +++ b/packages/helpers/src/tracker.ts @@ -0,0 +1,48 @@ +// Copyright (c) 2025-2026 Probo Inc . +// +// 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" }; + } +} diff --git a/pkg/server/api/console/v1/graphql/cookie_banner.graphql b/pkg/server/api/console/v1/graphql/cookie_banner.graphql index 4ac8bebd5..2aeb7cf2c 100644 --- a/pkg/server/api/console/v1/graphql/cookie_banner.graphql +++ b/pkg/server/api/console/v1/graphql/cookie_banner.graphql @@ -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"