caelum0x b4612a4f57 feat(analytics): alerts, weekly dashboard emails and Slack, Discord and HubSpot destinations (QY1.4, A25, A23)
Alerts and subscriptions (A25)
- PA src/alerts: threshold alerts (above/below a number) and anomaly alerts
  (the last complete interval N standard deviations from at least 7 before
  it) on any saved insight, watching one headline value per insight kind
  (metric.ts). Checked by the service scheduler every minute, each alert at
  its own hour or day, leased so two passes never double-send; an alert
  emails once when it starts firing and again only after it clears.
- Weekly dashboard emails at a weekday and hour (UTC): an HTML table of each
  tile's latest value and the interval before (no images), then the next
  weekly slot.
- Mail through the Rally Send transactional contract (Wave E 5.2:
  product, project, to, from_local, subject, html, text, idempotency_key,
  unsubscribe_url, tags; 202/422/429 read) when RALLY_TX_URL/KEY are set.
  The service has no other mail path, so without them each email is
  logged as not_configured (never dropped silently) and the console says so.
- Every email has an unsubscribe link (HMAC-signed, GET page or one-click
  POST); unsubscribed addresses are skipped and logged; per-recipient mail
  log (sent, failed, unsubscribed, not_configured).
- Migrations 0026 alerts, 0027 subscriptions, 0028 mail log and
  unsubscribes, 0029 row level security for all four.
- Console: product-analytics/alerts (one screen: alerts and weekly emails,
  pause, check or send now, delete, latest emails).

Destination catalogue (A23)
- Slack ({text, blocks}), Discord ({content}, no mentions) and HubSpot
  (contacts upserted by email through CRM v3 batch upsert with the
  customer's private app token) next to the webhook and S3 kinds
  (migration 0025). Each request carries Standard Webhooks headers under a
  per-destination signing secret shown once; the target secret (webhook
  address or token) is sealed with it and never read back. Delivery,
  backoff retries, the run log and the on/off switch are the exports
  runner's. Shapes follow PostHog CDP templates slack and hubspot (MIT,
  1348173f5911, nothing from ee/); NOTICE updated. Outside dev/test only
  hooks.slack.com and discord.com webhook addresses are accepted.
- MAX_DESTINATIONS 3 -> 6 (target) so the catalogue fits; the A3 cap test
  follows the constant. Console exports screens list the new kinds.

Also: the A2 lane-scope test now skips QY commits (the QY lane owns RY/
and wires the console on purpose). Deploy fragment and README name
PA_EXPORTS_KEY, PA_PUBLIC_URL, PA_CONSOLE_URL, RALLY_TX_URL, RALLY_TX_KEY.

Tests: product-analytics test/qy 26 (alerts 10 incl. one-tick mail with a
fake clock, anomaly, weekly table, unsubscribe, isolation, not configured,
Rally contract, copy lint of every email, console form mappings;
destinations 3 incl. signatures, isolation, retry with backoff and the
switch; migrations 2) + a3 exports 6 + a1 52/52 + a2 67/67 + a3 49/49;
console 142/142; PA and console tsc clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 13:35:28 +03:00

44 lines
2.3 KiB
Plaintext

Railyard product analytics service
Copyright 2026 Railyard
This service implements the public capture, flags and remote-config wire
protocol of the PostHog SDKs so their unmodified MIT/Apache-2.0 clients can
send to it. Parts are ported from open-source projects:
- PostHog (https://github.com/PostHog/posthog), MIT License (Expat), outside
the `ee/` directory, commit cbb1e9253027:
- nodejs/src/common/persons/person-utils.ts: the illegal distinct-id lists
(src/persons/ids.ts);
- nodejs/src/common/persons/person-property-utils.ts: the event-to-person
and campaign property sets (src/persons/properties.ts);
- nodejs/src/ingestion/common/persons/person-merge-service.ts: identify,
alias and merge semantics, re-implemented on Postgres
(src/persons/service.ts);
- person overrides (merges without rewriting events) and group-type
numbering semantics (src/persons/overrides.ts, src/groups/groups.ts).
Copyright (c) 2020-2026 PostHog Inc. Permission is hereby granted, free of
charge, to any person obtaining a copy of this software and associated
documentation files, to deal in the Software without restriction, subject
to including the copyright notice and permission notice in all copies.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
Web analytics view (QY1.2, src/web/query.ts): the breakdown semantics of
PostHog/posthog products/web_analytics/backend/hogql_queries/stats_table.py
and the web vitals tiles (MIT; commit 7b13402a6350; nothing from `ee/`) are
re-implemented in Postgres SQL: page views of `$pageview`, entry referrer and
UTM per session, "$direct" without a referrer, p75 page speed with the
published thresholds. Same MIT notice as above.
Destination catalogue (QY1.4, src/exports/catalogue.ts): the Slack message
and HubSpot upsert shapes follow PostHog/posthog
nodejs/src/cdp/templates/_destinations/{slack,hubspot} (MIT; commit
1348173f5911; nothing from `ee/`), re-implemented in TypeScript. Same MIT
notice as above.
Runtime dependencies (unmodified, from npm): hono and @hono/node-server
(MIT), pg (MIT), fflate (MIT), jose (MIT).
Test-only dependencies (unmodified, from npm): posthog-js (Apache-2.0 AND
MIT), posthog-node (MIT), posthog-react-native (MIT), @babel/runtime (MIT),
jsdom (MIT), playwright-core (Apache-2.0), typescript (Apache-2.0).