From 41653aebf1318705d2c8169bcea40ea87d7e435a Mon Sep 17 00:00:00 2001 From: caelum0x Date: Tue, 6 Oct 2026 17:24:34 +0300 Subject: [PATCH] feat(product-analytics): destination transforms (where, keep/drop, rename, set) The destination catalogue had no transforms (recount A23): every destination got every event with every property. A destination may now carry a declarative transform, applied by the exports runner before any send for every kind (webhook, S3, Slack, Discord, HubSpot, ClickHouse, BigQuery): 'where' keeps the events matching every condition (on a property, the event name or distinct_id; eq, neq, in, not_in, exists, not_exists, contains, gt, lt), then 'keep' or 'drop', 'rename' and 'set' reshape the properties. Events are never mutated in place; the cursor moves past every row read even when nothing is sent. No code runs, so a transform cannot reach the network or the database. POST and PUT /exports take it (PUT with null removes it); the console form has the field. Also: the surveys and vendor tests resolve the upstream SDK from the wrapper's own install, else the service's pin of the same version (checked), so they run on a fresh checkout instead of failing or skipping. Tests: qy/transforms (unit, refusals, end to end through a webhook, replace/remove). All product analytics suites (a1, a2, a3, qy): 206 passed, 4 skipped (no cached Chromium on this machine), 0 failed. Co-Authored-By: Claude Opus 5.5 --- .../(app)/product-analytics/_lib/a3-client.ts | 16 +- .../product-analytics/exports/new/page.tsx | 9 ++ .../src/exports/destinations.ts | 22 ++- apps/product-analytics/src/exports/runner.ts | 14 +- .../src/exports/transform.ts | 145 ++++++++++++++++++ .../product-analytics/test/a3/surveys.test.ts | 5 +- apps/product-analytics/test/a3/vendor.test.ts | 9 +- apps/product-analytics/test/qy/alerts.test.ts | 4 + .../test/qy/transforms.test.ts | 107 +++++++++++++ apps/product-analytics/test/sdk-deps.ts | 6 + 10 files changed, 324 insertions(+), 13 deletions(-) create mode 100644 apps/product-analytics/src/exports/transform.ts create mode 100644 apps/product-analytics/test/qy/transforms.test.ts diff --git a/apps/console/app/(app)/product-analytics/_lib/a3-client.ts b/apps/console/app/(app)/product-analytics/_lib/a3-client.ts index 240ec7e2..93abda15 100644 --- a/apps/console/app/(app)/product-analytics/_lib/a3-client.ts +++ b/apps/console/app/(app)/product-analytics/_lib/a3-client.ts @@ -363,12 +363,26 @@ export function experimentFromForm(form: Record): Record): Record { const events = (form.events ?? "") .split(/[\n,]/) .map((s) => s.trim()) .filter(Boolean); - const common = { name: form.name ?? "", start: form.start === "all" ? "all" : "now", ...(events.length ? { events } : {}) }; + const common = { name: form.name ?? "", start: form.start === "all" ? "all" : "now", ...(events.length ? { events } : {}), ...transformFromForm(form.transform) }; if (form.kind === "slack" || form.kind === "discord" || form.kind === "hubspot") { // QY1.4: the webhook address (Slack, Discord) or the private app token (HubSpot) is sealed by the service. return { ...common, kind: form.kind, config: { label: form.label ?? "" }, secret: form.target ?? "" }; diff --git a/apps/console/app/(app)/product-analytics/exports/new/page.tsx b/apps/console/app/(app)/product-analytics/exports/new/page.tsx index a19cf079..282cfe7d 100644 --- a/apps/console/app/(app)/product-analytics/exports/new/page.tsx +++ b/apps/console/app/(app)/product-analytics/exports/new/page.tsx @@ -146,6 +146,15 @@ export default async function NewDestinationPage({ searchParams }: { searchParam Only these events, comma separated (leave empty for all) +