@shware/workflow-ui 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/index.mjs +56 -56
  2. package/dist/index.mjs.map +1 -1
  3. package/dist/postgres.mjs +4 -4
  4. package/dist/postgres.mjs.map +1 -1
  5. package/package.json +2 -2
  6. package/src/app/integrations/toast/toast-provider.tsx +2 -2
  7. package/src/app/routes/__root.tsx +9 -9
  8. package/src/app/routes/emails.tsx +2 -2
  9. package/src/app/routes/home.tsx +4 -4
  10. package/src/app/routes/metrics.tsx +19 -19
  11. package/src/app/routes/segment-overview.tsx +21 -21
  12. package/src/app/routes/segments.tsx +2 -2
  13. package/src/app/routes/settings.tsx +6 -6
  14. package/src/app/routes/workflows.tsx +5 -5
  15. package/src/components/avatar.tsx +1 -1
  16. package/src/components/breadcrumb.tsx +3 -3
  17. package/src/components/button/index.tsx +4 -4
  18. package/src/components/chat-markup.tsx +6 -6
  19. package/src/components/date-range.tsx +6 -6
  20. package/src/components/dropdown/index.tsx +8 -8
  21. package/src/components/email-defaults.tsx +3 -3
  22. package/src/components/email-list.tsx +6 -6
  23. package/src/components/flag.tsx +7 -4
  24. package/src/components/input/index.tsx +2 -2
  25. package/src/components/input/search-input.tsx +1 -1
  26. package/src/components/menu/index.tsx +2 -2
  27. package/src/components/metric-card.tsx +7 -7
  28. package/src/components/modal/index.tsx +2 -2
  29. package/src/components/nav-drawer.tsx +3 -3
  30. package/src/components/node-inspector.tsx +5 -5
  31. package/src/components/profile-drawer.tsx +8 -8
  32. package/src/components/segment-list.tsx +9 -9
  33. package/src/components/select/index.tsx +3 -3
  34. package/src/components/tabs/index.tsx +2 -2
  35. package/src/components/templates-page.tsx +23 -23
  36. package/src/components/textarea/index.tsx +2 -2
  37. package/src/components/thumbnail-window.tsx +1 -1
  38. package/src/components/workflow-list.tsx +8 -8
  39. package/src/postgres.ts +4 -2
package/dist/postgres.mjs CHANGED
@@ -41,13 +41,13 @@ function postgresStats(options) {
41
41
  anchor = Date.now();
42
42
  return;
43
43
  }
44
- const [row] = await sql`
44
+ const row = (await sql`
45
45
  select greatest(
46
46
  (select max(sent_at) from ${t("message")}),
47
47
  (select max(node_at) from ${t("instance")}),
48
48
  (select max(finished_at) from ${t("instance")}),
49
49
  (select max(taken_at) from ${t("segment_snapshot")})
50
- ) as latest`;
50
+ ) as latest`).at(0);
51
51
  const latest = row?.latest === null || row?.latest === void 0 ? Date.now() : new Date(row.latest).getTime();
52
52
  anchor = Math.min(latest, Date.now());
53
53
  }
@@ -278,8 +278,8 @@ function postgresStats(options) {
278
278
  },
279
279
  async profiles(segment, { limit, offset }) {
280
280
  await refreshAnchor();
281
- const [count] = await sql`
282
- select count(*)::int as total from ${t("segment_member")} where segment = ${segment}`;
281
+ const count = (await sql`
282
+ select count(*)::int as total from ${t("segment_member")} where segment = ${segment}`).at(0);
283
283
  const rows = await sql`
284
284
  select m.user_id as id, p.props,
285
285
  ${onJourneyClock(sql`first_event.ts`)} as created_at
@@ -1 +1 @@
1
- {"version":3,"file":"postgres.mjs","names":[],"sources":["../src/postgres.ts"],"sourcesContent":["import { type JourneyConfig, resolveRuntime } from '@shware/workflow';\nimport { DEFAULT_SCHEMA } from '@shware/workflow/store';\nimport postgres from 'postgres';\nimport {\n type Granularity,\n type MetricChannel,\n type StatsRange,\n type StatsSource,\n defineStats,\n} from './config';\n\n/**\n * `@shware/workflow-ui/postgres` — the Studio's numbers read straight from the reporting a\n * journeyWorker on Postgres keeps (the engine's schema, `database.schema` in the config). The\n * Studio runs a stats source on its dev server, never in the browser, so it connects with a real\n * connection string:\n *\n * // workflow.stats.ts\n * export default postgresStats({ config, connectionString: process.env.STATS_DATABASE_URL });\n *\n * Time: a fast-forwarded environment (`runtime.<environment>.timeScale`) plays a journey day out\n * in minutes, so every timestamp is read on the journey's clock — `now - (anchor - t) ×\n * timeScale`, the anchor being the latest activity — and the Studio's date ranges are mapped back\n * the same way. A local run of an hour then reads as weeks of history; production (scale 1) is\n * unchanged.\n *\n * Days: the Studio's dates are the viewer's calendar days, so buckets are cut in the same time\n * zone (this machine's by default). Cut in UTC instead, \"today\" east of Greenwich is an empty\n * bucket on every chart.\n */\n\nexport interface PostgresStatsOptions {\n /** The project's `workflow.config.ts`: its database schema, and the runtime's time scale. */\n config: JourneyConfig;\n connectionString: string;\n /** Which `runtime` entry the data was written under; `development` by default. */\n environment?: string;\n /** The zone the Studio's days are cut in; this machine's by default. */\n timeZone?: string;\n}\n\n/** A calendar day `count` days from a `YYYY-MM-DD` one: plain date math, no zone in it. */\nconst addDays = (day: string, count: number) =>\n new Date(Date.parse(`${day}T00:00:00Z`) + count * 86_400_000).toISOString().slice(0, 10);\n\n/**\n * One pool per database across reloads: the dev server re-evaluates the stats module on every\n * config change, and a pool per evaluation kept its connections open until Postgres ran out.\n */\nconst pools = ((\n globalThis as { __workflowStatsPools?: Map<string, postgres.Sql> }\n).__workflowStatsPools ??= new Map());\n\nfunction pool(connectionString: string): postgres.Sql {\n let sql = pools.get(connectionString);\n if (sql === undefined) {\n sql = postgres(connectionString, { max: 4, idle_timeout: 20, fetch_types: false });\n pools.set(connectionString, sql);\n }\n return sql;\n}\n\nexport function postgresStats(options: PostgresStatsOptions): StatsSource {\n const sql = pool(options.connectionString);\n const schema = options.config.database?.schema ?? DEFAULT_SCHEMA;\n /** A table of the engine's schema. */\n const t = (name: string) => sql(`${schema}.${name}`);\n const scale = resolveRuntime(\n options.config.runtime,\n options.environment ?? 'development'\n ).timeScale;\n const timeZone = options.timeZone ?? Intl.DateTimeFormat().resolvedOptions().timeZone;\n\n /**\n * The moment the journey clock reads \"now\": the latest activity in the data, so a\n * fast-forwarded run keeps reading as the history up to today however long ago it ran —\n * anchored on the real now instead, a run from last night had drifted hundreds of journey days\n * out of every range by morning. Refreshed at the start of every call; with scale 1 it is now.\n */\n let anchor = Date.now();\n\n async function refreshAnchor(): Promise<void> {\n if (scale === 1) {\n anchor = Date.now();\n return;\n }\n const [row] = await sql<{ latest: Date | null }[]>`\n select greatest(\n (select max(sent_at) from ${t('message')}),\n (select max(node_at) from ${t('instance')}),\n (select max(finished_at) from ${t('instance')}),\n (select max(taken_at) from ${t('segment_snapshot')})\n ) as latest`;\n const latest =\n row?.latest === null || row?.latest === undefined\n ? Date.now()\n : new Date(row.latest).getTime();\n anchor = Math.min(latest, Date.now());\n }\n\n /** An instant on the journey's clock: `now - (anchor - t) × timeScale`. */\n const onJourneyClock = (instant: postgres.PendingQuery<postgres.Row[]>) =>\n sql`(${new Date().toISOString()}::timestamptz - (${new Date(anchor).toISOString()}::timestamptz - ${instant}) * ${scale}::float)`;\n const virtual = (column: string) => onJourneyClock(sql`${sql(column)}`);\n\n /** A column on the journey's clock, as a wall-clock time in the viewer's zone. */\n const local = (column: string) => sql`(${virtual(column)} at time zone ${timeZone})`;\n\n /** `YYYY-MM-DD` of an instant in the viewer's zone. */\n const localDate = (ms: number) =>\n new Intl.DateTimeFormat('en-CA', {\n timeZone,\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n }).format(ms);\n\n /** The instant a local calendar day starts. */\n function startOfLocalDay(day: string): number {\n const utcMidnight = Date.parse(`${day}T00:00:00Z`);\n // The zone's offset at that moment: how far its wall clock reads from UTC\n const parts = Object.fromEntries(\n new Intl.DateTimeFormat('en-US', {\n timeZone,\n hourCycle: 'h23',\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n })\n .formatToParts(utcMidnight)\n .map((part) => [part.type, part.value])\n );\n const n = (type: string) => Number(parts[type] ?? 0);\n const wall = Date.UTC(n('year'), n('month') - 1, n('day'), n('hour'), n('minute'), n('second'));\n return utcMidnight - (wall - utcMidnight);\n }\n\n /** The real instants a virtual `YYYY-MM-DD` range (both ends inclusive, local days) covers. */\n function realRange({ from, to }: StatsRange): { from: string; to: string } {\n const now = Date.now();\n const back = (ms: number) => new Date(anchor - (now - ms) / scale).toISOString();\n // The end is the start of the next local day, not 24 hours on: a DST day is 23 or 25\n return { from: back(startOfLocalDay(from)), to: back(startOfLocalDay(addDays(to, 1))) };\n }\n\n /**\n * When a copy reached its recipient: the transport's acceptance for email and Android, the\n * device's own report for iOS and the web — a push APNs or a push service accepted can still\n * never arrive (the app was deleted, the device stayed off). An app version without the\n * reporting extension shows its iOS pushes undelivered.\n */\n const reached = sql`(case when m.channel in ('push_ios', 'push_web') then m.device_delivered_at else m.delivered_at end)`;\n\n /**\n * A converted instance: `converted_at` is set whatever the status (with `exitOnMatch: false` a\n * conversion ends `completed`); rows written before the column existed only had status `goal`.\n */\n const converted = sql`(converted_at is not null or status = 'goal')`;\n\n const channelFilter = (channel: MetricChannel | undefined) =>\n channel === undefined ? sql`true` : sql`m.channel = ${channel}`;\n\n /** The last 14 journey days, oldest first, as local `YYYY-MM-DD`. */\n function lastDays(count = 14): string[] {\n const today = localDate(Date.now());\n return Array.from({ length: count }, (_, i) => addDays(today, i - (count - 1)));\n }\n\n return defineStats({\n async reports() {\n await refreshAnchor();\n const totals = await sql<\n { id: string; entered: number; active: number; completed: number; converted: number }[]\n >`\n select workflow as id,\n count(*)::int as entered,\n count(*) filter (where status = 'running')::int as active,\n count(*) filter (where status in ('completed', 'exited', 'exit_when', 'goal'))::int as completed,\n count(*) filter (where ${converted})::int as converted\n from ${t('instance')} group by workflow`;\n const engagement = await sql<\n { id: string; delivered: number; opened: number; clicked: number }[]\n >`\n select workflow as id,\n count(${reached})::int as delivered,\n count(opened_at) filter (where ${reached} is not null)::int as opened,\n count(clicked_at) filter (where ${reached} is not null)::int as clicked\n from ${t('message')} m group by workflow`;\n const days = lastDays();\n const series = await sql<\n { id: string; day: string; delivered: number; opened: number; clicked: number }[]\n >`\n select workflow as id, to_char(${local('delivered_at')}, 'YYYY-MM-DD') as day,\n count(${reached})::int as delivered,\n count(opened_at) filter (where ${reached} is not null)::int as opened,\n count(clicked_at) filter (where ${reached} is not null)::int as clicked\n from ${t('message')} m where delivered_at is not null\n group by 1, 2`;\n const conversions = await sql<{ id: string; day: string; converted: number }[]>`\n select workflow as id,\n to_char(${onJourneyClock(sql`coalesce(converted_at, finished_at)`)} at time zone ${timeZone}, 'YYYY-MM-DD') as day,\n count(*)::int as converted\n from ${t('instance')} where ${converted} group by 1, 2`;\n const daily = (id: string, rows: { id: string; day: string }[], key: string) =>\n days.map(\n (day) =>\n (\n rows.find((r) => r.id === id && r.day === day) as Record<string, number> | undefined\n )?.[key] ?? 0\n );\n return totals.map((total) => {\n const e = engagement.find((row) => row.id === total.id);\n return {\n id: total.id,\n entered: total.entered,\n active: total.active,\n completed: total.completed,\n converted: total.converted,\n delivered: e?.delivered ?? 0,\n opened: e?.opened ?? 0,\n clicked: e?.clicked ?? 0,\n series: {\n delivered: daily(total.id, series, 'delivered'),\n opened: daily(total.id, series, 'opened'),\n clicked: daily(total.id, series, 'clicked'),\n converted: daily(total.id, conversions, 'converted'),\n },\n };\n });\n },\n\n async nodeStats(workflow) {\n await refreshAnchor();\n const rows = await sql<{ node_id: string; users: number }[]>`\n select node_id, count(*)::int as users from ${t('instance')}\n where workflow = ${workflow} and status = 'running' and node_id is not null\n group by node_id`;\n return Object.fromEntries(rows.map((row) => [row.node_id, row.users]));\n },\n\n async metrics(workflow, query) {\n await refreshAnchor();\n const { from, to } = realRange(query);\n const unit: Granularity = query.granularity;\n const bucket = (column: string) =>\n sql`to_char(date_trunc(${unit}, ${local(column)}), 'YYYY-MM-DD')`;\n const messages = await sql<\n {\n day: string;\n sent: number;\n delivered: number;\n opened: number;\n opened_human: number;\n clicked: number;\n clicked_human: number;\n }[]\n >`\n with m as (\n select * from ${t('message')} m\n where m.workflow = ${workflow} and ${channelFilter(query.channel)}\n ),\n events as (\n select ${bucket('sent_at')} as day, 'sent' as kind, false as human from m\n where sent_at between ${from} and ${to}\n union all select ${bucket('delivered_at')}, 'delivered', false from m\n where ${reached} is not null and delivered_at between ${from} and ${to}\n -- Opens and clicks count against the bucket the message was delivered in (its cohort),\n -- not the day they happened: the rates drawn are opened / delivered, and an open\n -- counted on another day than its delivery reads as 160% on a quiet day\n union all select ${bucket('delivered_at')}, 'opened', human_opened_at is not null from m\n where opened_at is not null and ${reached} is not null and delivered_at between ${from} and ${to}\n union all select ${bucket('delivered_at')}, 'clicked', human_clicked_at is not null from m\n where clicked_at is not null and ${reached} is not null and delivered_at between ${from} and ${to}\n )\n select day,\n count(*) filter (where kind = 'sent')::int as sent,\n count(*) filter (where kind = 'delivered')::int as delivered,\n count(*) filter (where kind = 'opened')::int as opened,\n count(*) filter (where kind = 'opened' and human)::int as opened_human,\n count(*) filter (where kind = 'clicked')::int as clicked,\n count(*) filter (where kind = 'clicked' and human)::int as clicked_human\n from events group by day`;\n // Users by the bucket they entered in, and how many of each cohort reached the goal: the\n // conversion rate is a share of one group of people, so it stays within 100%\n const cohorts = await sql<{ day: string; entered: number; converted: number }[]>`\n select ${bucket('entered_at')} as day, count(*)::int as entered,\n count(*) filter (where ${converted})::int as converted\n from ${t('instance')}\n where workflow = ${workflow} and entered_at between ${from} and ${to}\n group by 1`;\n const buckets = await sql<{ day: string }[]>`\n select to_char(d, 'YYYY-MM-DD') as day\n from generate_series(date_trunc(${unit}, ${query.from}::date), ${query.to}::date, ${`1 ${unit}`}::interval) d`;\n return buckets.map(({ day }) => {\n const m = messages.find((row) => row.day === day);\n const opened = m?.opened ?? 0;\n const clicked = m?.clicked ?? 0;\n const cohort = cohorts.find((row) => row.day === day);\n return {\n date: day,\n sent: m?.sent ?? 0,\n delivered: m?.delivered ?? 0,\n opened,\n openedHuman: m?.opened_human ?? 0,\n openedMachine: opened - (m?.opened_human ?? 0),\n clicked,\n clickedHuman: m?.clicked_human ?? 0,\n clickedMachine: clicked - (m?.clicked_human ?? 0),\n entered: cohort?.entered ?? 0,\n converted: cohort?.converted ?? 0,\n };\n });\n },\n\n async links(workflow, query) {\n await refreshAnchor();\n const { from, to } = realRange(query);\n return sql<{ url: string; clicks: number }[]>`\n select c.url, count(*)::int as clicks\n from ${t('message_click')} c\n join ${t('message')} m on m.id = c.message_id\n where m.workflow = ${workflow} and ${channelFilter(query.channel)}\n and c.clicked_at between ${from} and ${to}\n -- People's clicks only: a scanner follows every link, the footer's included\n and not c.machine\n group by c.url order by clicks desc limit 50`;\n },\n\n async messages(workflow, query) {\n await refreshAnchor();\n const { from, to } = realRange(query);\n return sql<\n {\n nodeId: string;\n template: string;\n channel: MetricChannel;\n sent: number;\n delivered: number;\n opened: number;\n clicked: number;\n unsubscribed: number;\n }[]\n >`\n select node_id as \"nodeId\", template, channel,\n count(*)::int as sent,\n count(${reached})::int as delivered,\n count(opened_at) filter (where ${reached} is not null)::int as opened,\n count(clicked_at) filter (where ${reached} is not null)::int as clicked,\n count(unsubscribed_at)::int as unsubscribed\n from ${t('message')} m\n where m.workflow = ${workflow} and ${channelFilter(query.channel)}\n and m.sent_at between ${from} and ${to}\n group by node_id, template, channel order by node_id, channel`;\n },\n\n async segments() {\n await refreshAnchor();\n const sizes = await sql<{ id: string; size: number }[]>`\n select s.id, count(m.user_id)::int as size\n from ${t('segment')} s\n left join ${t('segment_member')} m on m.segment = s.id\n group by s.id`;\n const days = lastDays();\n // The last snapshot of each journey day\n const snapshots = await sql<{ id: string; day: string; size: number }[]>`\n select distinct on (segment, day) segment as id, day, size from (\n select segment, size, taken_at, to_char(${local('taken_at')}, 'YYYY-MM-DD') as day\n from ${t('segment_snapshot')}\n ) s order by segment, day, taken_at desc`;\n return sizes.map(({ id, size }) => {\n let last = 0;\n const series = days.map((day) => {\n last = snapshots.find((s) => s.id === id && s.day === day)?.size ?? last;\n return last;\n });\n return { id, size, series };\n });\n },\n\n async profiles(segment, { limit, offset }) {\n await refreshAnchor();\n const [count] = await sql<{ total: number }[]>`\n select count(*)::int as total from ${t('segment_member')} where segment = ${segment}`;\n // \"Created\" is the user's first event: the engine knows nothing older about them\n const rows = await sql<\n { id: string; props: Record<string, unknown> | null; created_at: Date | null }[]\n >`\n select m.user_id as id, p.props,\n ${onJourneyClock(sql`first_event.ts`)} as created_at\n from ${t('segment_member')} m\n left join ${t('profile')} p on p.user_id = m.user_id\n left join lateral (\n select min(ts) as ts from ${t('event')} e where e.user_id = m.user_id\n ) first_event on true\n where m.segment = ${segment}\n order by m.ts desc, m.user_id\n limit ${limit} offset ${offset}`;\n return {\n total: count?.total ?? 0,\n profiles: rows.map(({ id, props, created_at }) => {\n const { email, ...properties } = props ?? {};\n const profile: { id: string; email?: string; createdAt?: string } & {\n properties: Record<string, unknown>;\n } = { id, properties };\n if (typeof email === 'string') profile.email = email;\n if (created_at !== null) profile.createdAt = new Date(created_at).toISOString();\n return profile;\n }),\n };\n },\n });\n}\n"],"mappings":";;;;;;AA0CA,MAAM,WAAW,KAAa,UAC5B,IAAI,KAAK,KAAK,MAAM,GAAG,IAAI,WAAW,IAAI,QAAQ,KAAU,CAAC,CAAC,YAAY,CAAC,CAAC,MAAM,GAAG,EAAE;;;;;AAMzF,MAAM,QAAS,WAEb,yCAAyB,IAAI,IAAI;AAEnC,SAAS,KAAK,kBAAwC;CACpD,IAAI,MAAM,MAAM,IAAI,gBAAgB;CACpC,IAAI,QAAQ,KAAA,GAAW;EACrB,MAAM,SAAS,kBAAkB;GAAE,KAAK;GAAG,cAAc;GAAI,aAAa;EAAM,CAAC;EACjF,MAAM,IAAI,kBAAkB,GAAG;CACjC;CACA,OAAO;AACT;AAEA,SAAgB,cAAc,SAA4C;CACxE,MAAM,MAAM,KAAK,QAAQ,gBAAgB;CACzC,MAAM,SAAS,QAAQ,OAAO,UAAU,UAAU;;CAElD,MAAM,KAAK,SAAiB,IAAI,GAAG,OAAO,GAAG,MAAM;CACnD,MAAM,QAAQ,eACZ,QAAQ,OAAO,SACf,QAAQ,eAAe,aACzB,CAAC,CAAC;CACF,MAAM,WAAW,QAAQ,YAAY,KAAK,eAAe,CAAC,CAAC,gBAAgB,CAAC,CAAC;;;;;;;CAQ7E,IAAI,SAAS,KAAK,IAAI;CAEtB,eAAe,gBAA+B;EA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":["../src/postgres.ts"],"sourcesContent":["import { type JourneyConfig, resolveRuntime } from '@shware/workflow';\nimport { DEFAULT_SCHEMA } from '@shware/workflow/store';\nimport postgres from 'postgres';\nimport {\n type Granularity,\n type MetricChannel,\n type StatsRange,\n type StatsSource,\n defineStats,\n} from './config';\n\n/**\n * `@shware/workflow-ui/postgres` — the Studio's numbers read straight from the reporting a\n * journeyWorker on Postgres keeps (the engine's schema, `database.schema` in the config). The\n * Studio runs a stats source on its dev server, never in the browser, so it connects with a real\n * connection string:\n *\n * // workflow.stats.ts\n * export default postgresStats({ config, connectionString: process.env.STATS_DATABASE_URL });\n *\n * Time: a fast-forwarded environment (`runtime.<environment>.timeScale`) plays a journey day out\n * in minutes, so every timestamp is read on the journey's clock — `now - (anchor - t) ×\n * timeScale`, the anchor being the latest activity — and the Studio's date ranges are mapped back\n * the same way. A local run of an hour then reads as weeks of history; production (scale 1) is\n * unchanged.\n *\n * Days: the Studio's dates are the viewer's calendar days, so buckets are cut in the same time\n * zone (this machine's by default). Cut in UTC instead, \"today\" east of Greenwich is an empty\n * bucket on every chart.\n */\n\nexport interface PostgresStatsOptions {\n /** The project's `workflow.config.ts`: its database schema, and the runtime's time scale. */\n config: JourneyConfig;\n connectionString: string;\n /** Which `runtime` entry the data was written under; `development` by default. */\n environment?: string;\n /** The zone the Studio's days are cut in; this machine's by default. */\n timeZone?: string;\n}\n\n/** A calendar day `count` days from a `YYYY-MM-DD` one: plain date math, no zone in it. */\nconst addDays = (day: string, count: number) =>\n new Date(Date.parse(`${day}T00:00:00Z`) + count * 86_400_000).toISOString().slice(0, 10);\n\n/**\n * One pool per database across reloads: the dev server re-evaluates the stats module on every\n * config change, and a pool per evaluation kept its connections open until Postgres ran out.\n */\nconst pools = ((\n globalThis as { __workflowStatsPools?: Map<string, postgres.Sql> }\n).__workflowStatsPools ??= new Map());\n\nfunction pool(connectionString: string): postgres.Sql {\n let sql = pools.get(connectionString);\n if (sql === undefined) {\n sql = postgres(connectionString, { max: 4, idle_timeout: 20, fetch_types: false });\n pools.set(connectionString, sql);\n }\n return sql;\n}\n\nexport function postgresStats(options: PostgresStatsOptions): StatsSource {\n const sql = pool(options.connectionString);\n const schema = options.config.database?.schema ?? DEFAULT_SCHEMA;\n /** A table of the engine's schema. */\n const t = (name: string) => sql(`${schema}.${name}`);\n const scale = resolveRuntime(\n options.config.runtime,\n options.environment ?? 'development'\n ).timeScale;\n const timeZone = options.timeZone ?? Intl.DateTimeFormat().resolvedOptions().timeZone;\n\n /**\n * The moment the journey clock reads \"now\": the latest activity in the data, so a\n * fast-forwarded run keeps reading as the history up to today however long ago it ran —\n * anchored on the real now instead, a run from last night had drifted hundreds of journey days\n * out of every range by morning. Refreshed at the start of every call; with scale 1 it is now.\n */\n let anchor = Date.now();\n\n async function refreshAnchor(): Promise<void> {\n if (scale === 1) {\n anchor = Date.now();\n return;\n }\n const rows = await sql<{ latest: Date | null }[]>`\n select greatest(\n (select max(sent_at) from ${t('message')}),\n (select max(node_at) from ${t('instance')}),\n (select max(finished_at) from ${t('instance')}),\n (select max(taken_at) from ${t('segment_snapshot')})\n ) as latest`;\n const row = rows.at(0);\n const latest =\n row?.latest === null || row?.latest === undefined\n ? Date.now()\n : new Date(row.latest).getTime();\n anchor = Math.min(latest, Date.now());\n }\n\n /** An instant on the journey's clock: `now - (anchor - t) × timeScale`. */\n const onJourneyClock = (instant: postgres.PendingQuery<postgres.Row[]>) =>\n sql`(${new Date().toISOString()}::timestamptz - (${new Date(anchor).toISOString()}::timestamptz - ${instant}) * ${scale}::float)`;\n const virtual = (column: string) => onJourneyClock(sql`${sql(column)}`);\n\n /** A column on the journey's clock, as a wall-clock time in the viewer's zone. */\n const local = (column: string) => sql`(${virtual(column)} at time zone ${timeZone})`;\n\n /** `YYYY-MM-DD` of an instant in the viewer's zone. */\n const localDate = (ms: number) =>\n new Intl.DateTimeFormat('en-CA', {\n timeZone,\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n }).format(ms);\n\n /** The instant a local calendar day starts. */\n function startOfLocalDay(day: string): number {\n const utcMidnight = Date.parse(`${day}T00:00:00Z`);\n // The zone's offset at that moment: how far its wall clock reads from UTC\n const parts = Object.fromEntries(\n new Intl.DateTimeFormat('en-US', {\n timeZone,\n hourCycle: 'h23',\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n })\n .formatToParts(utcMidnight)\n .map((part) => [part.type, part.value])\n );\n const n = (type: string) => Number(parts[type] ?? 0);\n const wall = Date.UTC(n('year'), n('month') - 1, n('day'), n('hour'), n('minute'), n('second'));\n return utcMidnight - (wall - utcMidnight);\n }\n\n /** The real instants a virtual `YYYY-MM-DD` range (both ends inclusive, local days) covers. */\n function realRange({ from, to }: StatsRange): { from: string; to: string } {\n const now = Date.now();\n const back = (ms: number) => new Date(anchor - (now - ms) / scale).toISOString();\n // The end is the start of the next local day, not 24 hours on: a DST day is 23 or 25\n return { from: back(startOfLocalDay(from)), to: back(startOfLocalDay(addDays(to, 1))) };\n }\n\n /**\n * When a copy reached its recipient: the transport's acceptance for email and Android, the\n * device's own report for iOS and the web — a push APNs or a push service accepted can still\n * never arrive (the app was deleted, the device stayed off). An app version without the\n * reporting extension shows its iOS pushes undelivered.\n */\n const reached = sql`(case when m.channel in ('push_ios', 'push_web') then m.device_delivered_at else m.delivered_at end)`;\n\n /**\n * A converted instance: `converted_at` is set whatever the status (with `exitOnMatch: false` a\n * conversion ends `completed`); rows written before the column existed only had status `goal`.\n */\n const converted = sql`(converted_at is not null or status = 'goal')`;\n\n const channelFilter = (channel: MetricChannel | undefined) =>\n channel === undefined ? sql`true` : sql`m.channel = ${channel}`;\n\n /** The last 14 journey days, oldest first, as local `YYYY-MM-DD`. */\n function lastDays(count = 14): string[] {\n const today = localDate(Date.now());\n return Array.from({ length: count }, (_, i) => addDays(today, i - (count - 1)));\n }\n\n return defineStats({\n async reports() {\n await refreshAnchor();\n const totals = await sql<\n { id: string; entered: number; active: number; completed: number; converted: number }[]\n >`\n select workflow as id,\n count(*)::int as entered,\n count(*) filter (where status = 'running')::int as active,\n count(*) filter (where status in ('completed', 'exited', 'exit_when', 'goal'))::int as completed,\n count(*) filter (where ${converted})::int as converted\n from ${t('instance')} group by workflow`;\n const engagement = await sql<\n { id: string; delivered: number; opened: number; clicked: number }[]\n >`\n select workflow as id,\n count(${reached})::int as delivered,\n count(opened_at) filter (where ${reached} is not null)::int as opened,\n count(clicked_at) filter (where ${reached} is not null)::int as clicked\n from ${t('message')} m group by workflow`;\n const days = lastDays();\n const series = await sql<\n { id: string; day: string; delivered: number; opened: number; clicked: number }[]\n >`\n select workflow as id, to_char(${local('delivered_at')}, 'YYYY-MM-DD') as day,\n count(${reached})::int as delivered,\n count(opened_at) filter (where ${reached} is not null)::int as opened,\n count(clicked_at) filter (where ${reached} is not null)::int as clicked\n from ${t('message')} m where delivered_at is not null\n group by 1, 2`;\n const conversions = await sql<{ id: string; day: string; converted: number }[]>`\n select workflow as id,\n to_char(${onJourneyClock(sql`coalesce(converted_at, finished_at)`)} at time zone ${timeZone}, 'YYYY-MM-DD') as day,\n count(*)::int as converted\n from ${t('instance')} where ${converted} group by 1, 2`;\n const daily = (id: string, rows: { id: string; day: string }[], key: string) =>\n days.map(\n (day) =>\n (\n rows.find((r) => r.id === id && r.day === day) as Record<string, number> | undefined\n )?.[key] ?? 0\n );\n return totals.map((total) => {\n const e = engagement.find((row) => row.id === total.id);\n return {\n id: total.id,\n entered: total.entered,\n active: total.active,\n completed: total.completed,\n converted: total.converted,\n delivered: e?.delivered ?? 0,\n opened: e?.opened ?? 0,\n clicked: e?.clicked ?? 0,\n series: {\n delivered: daily(total.id, series, 'delivered'),\n opened: daily(total.id, series, 'opened'),\n clicked: daily(total.id, series, 'clicked'),\n converted: daily(total.id, conversions, 'converted'),\n },\n };\n });\n },\n\n async nodeStats(workflow) {\n await refreshAnchor();\n const rows = await sql<{ node_id: string; users: number }[]>`\n select node_id, count(*)::int as users from ${t('instance')}\n where workflow = ${workflow} and status = 'running' and node_id is not null\n group by node_id`;\n return Object.fromEntries(rows.map((row) => [row.node_id, row.users]));\n },\n\n async metrics(workflow, query) {\n await refreshAnchor();\n const { from, to } = realRange(query);\n const unit: Granularity = query.granularity;\n const bucket = (column: string) =>\n sql`to_char(date_trunc(${unit}, ${local(column)}), 'YYYY-MM-DD')`;\n const messages = await sql<\n {\n day: string;\n sent: number;\n delivered: number;\n opened: number;\n opened_human: number;\n clicked: number;\n clicked_human: number;\n }[]\n >`\n with m as (\n select * from ${t('message')} m\n where m.workflow = ${workflow} and ${channelFilter(query.channel)}\n ),\n events as (\n select ${bucket('sent_at')} as day, 'sent' as kind, false as human from m\n where sent_at between ${from} and ${to}\n union all select ${bucket('delivered_at')}, 'delivered', false from m\n where ${reached} is not null and delivered_at between ${from} and ${to}\n -- Opens and clicks count against the bucket the message was delivered in (its cohort),\n -- not the day they happened: the rates drawn are opened / delivered, and an open\n -- counted on another day than its delivery reads as 160% on a quiet day\n union all select ${bucket('delivered_at')}, 'opened', human_opened_at is not null from m\n where opened_at is not null and ${reached} is not null and delivered_at between ${from} and ${to}\n union all select ${bucket('delivered_at')}, 'clicked', human_clicked_at is not null from m\n where clicked_at is not null and ${reached} is not null and delivered_at between ${from} and ${to}\n )\n select day,\n count(*) filter (where kind = 'sent')::int as sent,\n count(*) filter (where kind = 'delivered')::int as delivered,\n count(*) filter (where kind = 'opened')::int as opened,\n count(*) filter (where kind = 'opened' and human)::int as opened_human,\n count(*) filter (where kind = 'clicked')::int as clicked,\n count(*) filter (where kind = 'clicked' and human)::int as clicked_human\n from events group by day`;\n // Users by the bucket they entered in, and how many of each cohort reached the goal: the\n // conversion rate is a share of one group of people, so it stays within 100%\n const cohorts = await sql<{ day: string; entered: number; converted: number }[]>`\n select ${bucket('entered_at')} as day, count(*)::int as entered,\n count(*) filter (where ${converted})::int as converted\n from ${t('instance')}\n where workflow = ${workflow} and entered_at between ${from} and ${to}\n group by 1`;\n const buckets = await sql<{ day: string }[]>`\n select to_char(d, 'YYYY-MM-DD') as day\n from generate_series(date_trunc(${unit}, ${query.from}::date), ${query.to}::date, ${`1 ${unit}`}::interval) d`;\n return buckets.map(({ day }) => {\n const m = messages.find((row) => row.day === day);\n const opened = m?.opened ?? 0;\n const clicked = m?.clicked ?? 0;\n const cohort = cohorts.find((row) => row.day === day);\n return {\n date: day,\n sent: m?.sent ?? 0,\n delivered: m?.delivered ?? 0,\n opened,\n openedHuman: m?.opened_human ?? 0,\n openedMachine: opened - (m?.opened_human ?? 0),\n clicked,\n clickedHuman: m?.clicked_human ?? 0,\n clickedMachine: clicked - (m?.clicked_human ?? 0),\n entered: cohort?.entered ?? 0,\n converted: cohort?.converted ?? 0,\n };\n });\n },\n\n async links(workflow, query) {\n await refreshAnchor();\n const { from, to } = realRange(query);\n return sql<{ url: string; clicks: number }[]>`\n select c.url, count(*)::int as clicks\n from ${t('message_click')} c\n join ${t('message')} m on m.id = c.message_id\n where m.workflow = ${workflow} and ${channelFilter(query.channel)}\n and c.clicked_at between ${from} and ${to}\n -- People's clicks only: a scanner follows every link, the footer's included\n and not c.machine\n group by c.url order by clicks desc limit 50`;\n },\n\n async messages(workflow, query) {\n await refreshAnchor();\n const { from, to } = realRange(query);\n return sql<\n {\n nodeId: string;\n template: string;\n channel: MetricChannel;\n sent: number;\n delivered: number;\n opened: number;\n clicked: number;\n unsubscribed: number;\n }[]\n >`\n select node_id as \"nodeId\", template, channel,\n count(*)::int as sent,\n count(${reached})::int as delivered,\n count(opened_at) filter (where ${reached} is not null)::int as opened,\n count(clicked_at) filter (where ${reached} is not null)::int as clicked,\n count(unsubscribed_at)::int as unsubscribed\n from ${t('message')} m\n where m.workflow = ${workflow} and ${channelFilter(query.channel)}\n and m.sent_at between ${from} and ${to}\n group by node_id, template, channel order by node_id, channel`;\n },\n\n async segments() {\n await refreshAnchor();\n const sizes = await sql<{ id: string; size: number }[]>`\n select s.id, count(m.user_id)::int as size\n from ${t('segment')} s\n left join ${t('segment_member')} m on m.segment = s.id\n group by s.id`;\n const days = lastDays();\n // The last snapshot of each journey day\n const snapshots = await sql<{ id: string; day: string; size: number }[]>`\n select distinct on (segment, day) segment as id, day, size from (\n select segment, size, taken_at, to_char(${local('taken_at')}, 'YYYY-MM-DD') as day\n from ${t('segment_snapshot')}\n ) s order by segment, day, taken_at desc`;\n return sizes.map(({ id, size }) => {\n let last = 0;\n const series = days.map((day) => {\n last = snapshots.find((s) => s.id === id && s.day === day)?.size ?? last;\n return last;\n });\n return { id, size, series };\n });\n },\n\n async profiles(segment, { limit, offset }) {\n await refreshAnchor();\n const counts = await sql<{ total: number }[]>`\n select count(*)::int as total from ${t('segment_member')} where segment = ${segment}`;\n const count = counts.at(0);\n // \"Created\" is the user's first event: the engine knows nothing older about them\n const rows = await sql<\n { id: string; props: Record<string, unknown> | null; created_at: Date | null }[]\n >`\n select m.user_id as id, p.props,\n ${onJourneyClock(sql`first_event.ts`)} as created_at\n from ${t('segment_member')} m\n left join ${t('profile')} p on p.user_id = m.user_id\n left join lateral (\n select min(ts) as ts from ${t('event')} e where e.user_id = m.user_id\n ) first_event on true\n where m.segment = ${segment}\n order by m.ts desc, m.user_id\n limit ${limit} offset ${offset}`;\n return {\n total: count?.total ?? 0,\n profiles: rows.map(({ id, props, created_at }) => {\n const { email, ...properties } = props ?? {};\n const profile: { id: string; email?: string; createdAt?: string } & {\n properties: Record<string, unknown>;\n } = { id, properties };\n if (typeof email === 'string') profile.email = email;\n if (created_at !== null) profile.createdAt = new Date(created_at).toISOString();\n return profile;\n }),\n };\n },\n });\n}\n"],"mappings":";;;;;;AA0CA,MAAM,WAAW,KAAa,UAC5B,IAAI,KAAK,KAAK,MAAM,GAAG,IAAI,WAAW,IAAI,QAAQ,KAAU,CAAC,CAAC,YAAY,CAAC,CAAC,MAAM,GAAG,EAAE;;;;;AAMzF,MAAM,QAAS,WAEb,yCAAyB,IAAI,IAAI;AAEnC,SAAS,KAAK,kBAAwC;CACpD,IAAI,MAAM,MAAM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EAAE,mBAAmB,UAAA,CACzD,GAAG,CAAC;GAEzB,MAAM,OAAO,MAAM,GAElB;;YAEK,eAAe,GAAG,gBAAgB,EAAE;eACjC,EAAE,gBAAgB,EAAE;oBACf,EAAE,SAAS,EAAE;;sCAEK,EAAE,OAAO,EAAE;;4BAErB,QAAQ;;gBAEpB,MAAM,UAAU;GAC1B,OAAO;IACL,OAAO,OAAO,SAAS;IACvB,UAAU,KAAK,KAAK,EAAE,IAAI,OAAO,iBAAiB;KAChD,MAAM,EAAE,OAAO,GAAG,eAAe,SAAS,CAAC;KAC3C,MAAM,UAEF;MAAE;MAAI;KAAW;KACrB,IAAI,OAAO,UAAU,UAAU,QAAQ,QAAQ;KAC/C,IAAI,eAAe,MAAM,QAAQ,YAAY,IAAI,KAAK,UAAU,CAAC,CAAC,YAAY;KAC9E,OAAO;IACT,CAAC;GACH;EACF;CACF,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/workflow-ui",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ShwareHQ/shware-sdk.git"
@@ -40,7 +40,7 @@
40
40
  "@floating-ui/react": "^0.27.20",
41
41
  "@fontsource-variable/inter": "^5.3.0",
42
42
  "@react-email/render": "^2.1.1",
43
- "@shware/workflow": "2.0.0",
43
+ "@shware/workflow": "2.0.1",
44
44
  "@tailwindcss/vite": "^4.3.3",
45
45
  "@tanstack/react-query": "^5.104.3",
46
46
  "@tanstack/react-router": "^1.170.45",
@@ -30,13 +30,13 @@ export function ToastProvider() {
30
30
  classNames: {
31
31
  toast: clsx(
32
32
  'flex w-90 items-center gap-x-2 font-sans',
33
- 'bg-card ring-border rounded-2xl py-4 pr-4 pl-3 ring-1',
33
+ 'rounded-2xl bg-card py-4 pr-4 pl-3 ring-1 ring-border',
34
34
  'shadow-[0_4px_12px_var(--color-card-shadow)]'
35
35
  ),
36
36
  title: 'text-sm font-medium text-primary',
37
37
  description: 'mt-1 text-xs font-normal text-muted',
38
38
  closeButton: clsx(
39
- 'text-muted hover:text-primary order-last ml-auto size-5 p-0.5',
39
+ 'order-last ml-auto size-5 p-0.5 text-muted hover:text-primary',
40
40
  'transition-colors duration-200'
41
41
  ),
42
42
  },
@@ -93,7 +93,7 @@ function Header({
93
93
  * than higher so a drawer's scrim (also z-20, and later in the tree) dims it.
94
94
  */
95
95
  return (
96
- <header className="border-border bg-card sticky top-0 z-20 grid h-14 grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] items-center gap-3 border-b px-4">
96
+ <header className="sticky top-0 z-20 grid h-14 grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] items-center gap-3 border-b border-border bg-card px-4">
97
97
  <div className="flex min-w-0 items-center gap-3">
98
98
  {/*
99
99
  Two buttons in one slot rather than one button with two behaviours:
@@ -108,7 +108,7 @@ function Header({
108
108
  onClick={onOpenNav}
109
109
  aria-label={t('nav.menu')}
110
110
  title={t('nav.menu')}
111
- className="text-muted hover:bg-hover hover:text-primary flex size-8 shrink-0 items-center justify-center rounded-lg transition-colors md:hidden"
111
+ className="flex size-8 shrink-0 items-center justify-center rounded-lg text-muted transition-colors hover:bg-hover hover:text-primary md:hidden"
112
112
  style={superellipse}
113
113
  >
114
114
  <Menu className="size-4" strokeWidth={2} />
@@ -118,7 +118,7 @@ function Header({
118
118
  onClick={onToggle}
119
119
  aria-label={t(collapsed ? 'nav.expand' : 'nav.collapse')}
120
120
  title={t(collapsed ? 'nav.expand' : 'nav.collapse')}
121
- className="text-muted hover:bg-hover hover:text-primary hidden size-8 shrink-0 items-center justify-center rounded-lg transition-colors md:flex"
121
+ className="hidden size-8 shrink-0 items-center justify-center rounded-lg text-muted transition-colors hover:bg-hover hover:text-primary md:flex"
122
122
  style={superellipse}
123
123
  >
124
124
  {collapsed ? (
@@ -197,26 +197,26 @@ function Shell() {
197
197
  */
198
198
  const itemClass = clsx(
199
199
  'flex h-9 items-center gap-2.5 rounded-lg px-3 text-sm font-medium',
200
- 'text-secondary hover:bg-hover overflow-hidden whitespace-nowrap transition-colors'
200
+ 'overflow-hidden whitespace-nowrap text-secondary transition-colors hover:bg-hover'
201
201
  );
202
202
 
203
203
  return (
204
- <div className="text-primary flex h-full font-sans">
204
+ <div className="flex h-full font-sans text-primary">
205
205
  {/* Gone below `md`, not merely narrowed: 64px of icons is a fifth of a
206
206
  phone's width, and the drawer below carries the same items. */}
207
207
  <aside
208
208
  className={clsx(
209
- 'border-border bg-card hidden shrink-0 flex-col overflow-hidden border-r md:flex',
209
+ 'hidden shrink-0 flex-col overflow-hidden border-r border-border bg-card md:flex',
210
210
  'transition-[width] duration-200 ease-out',
211
211
  collapsed ? 'w-16' : 'w-60'
212
212
  )}
213
213
  >
214
214
  <div className="flex h-14 shrink-0 items-center gap-2.5 px-4">
215
215
  <div
216
- className="bg-primary flex size-7 shrink-0 items-center justify-center rounded-lg"
216
+ className="flex size-7 shrink-0 items-center justify-center rounded-lg bg-primary"
217
217
  style={superellipse}
218
218
  >
219
- <Workflow className="text-card size-4" strokeWidth={2} />
219
+ <Workflow className="size-4 text-card" strokeWidth={2} />
220
220
  </div>
221
221
  {!collapsed && (
222
222
  <strong className="text-sm font-semibold whitespace-nowrap">Workflow Studio</strong>
@@ -249,7 +249,7 @@ function Shell() {
249
249
  Views must therefore not scroll internally — the canvas is the one
250
250
  exception, and it says so at its own root.
251
251
  */}
252
- <div className="bg-page min-w-0 flex-1 overflow-y-auto">
252
+ <div className="min-w-0 flex-1 overflow-y-auto bg-page">
253
253
  <Header collapsed={collapsed} onToggle={toggle} onOpenNav={() => setNavOpen(true)} />
254
254
  {/*
255
255
  A short page still has to fill the viewport: empty states centre in
@@ -52,7 +52,7 @@ function EmailsIndex() {
52
52
 
53
53
  if (items.length === 0) {
54
54
  return (
55
- <div className="text-muted flex flex-1 items-center justify-center text-sm">
55
+ <div className="flex flex-1 items-center justify-center text-sm text-muted">
56
56
  {t('emails.empty')}
57
57
  </div>
58
58
  );
@@ -77,7 +77,7 @@ function EmailsIndex() {
77
77
  </div>
78
78
  <div className="px-6 pb-6">
79
79
  {filtered.length === 0 ? (
80
- <div className="text-muted flex items-center justify-center py-24 text-sm">
80
+ <div className="flex items-center justify-center py-24 text-sm text-muted">
81
81
  {t('emails.noMatches', { query: query.trim() })}
82
82
  </div>
83
83
  ) : (
@@ -12,10 +12,10 @@ import { collectSegments } from './segments';
12
12
 
13
13
  function Stat({ label, value, hint }: { label: string; value: string; hint?: string }) {
14
14
  return (
15
- <div className="border-border bg-card rounded-2xl border px-5 py-4" style={superellipse}>
16
- <div className="text-muted text-xs">{label}</div>
15
+ <div className="rounded-2xl border border-border bg-card px-5 py-4" style={superellipse}>
16
+ <div className="text-xs text-muted">{label}</div>
17
17
  <div className="mt-1 text-2xl font-semibold tabular-nums">{value}</div>
18
- {hint !== undefined && <div className="text-muted mt-1 text-xs">{hint}</div>}
18
+ {hint !== undefined && <div className="mt-1 text-xs text-muted">{hint}</div>}
19
19
  </div>
20
20
  );
21
21
  }
@@ -52,7 +52,7 @@ function Home() {
52
52
  <div className="flex-1 p-6">
53
53
  <PageChrome breadcrumb={<Breadcrumb items={[{ label: t('nav.home') }]} />} />
54
54
  <h1 className="text-lg font-semibold">{t('home.title')}</h1>
55
- <p className="text-muted mt-1 text-sm">{t('home.subtitle')}</p>
55
+ <p className="mt-1 text-sm text-muted">{t('home.subtitle')}</p>
56
56
 
57
57
  <div className="mt-5 grid grid-cols-2 gap-3 lg:grid-cols-3">
58
58
  <Stat label={t('home.workflows')} value={String(irs.length)} />
@@ -71,8 +71,8 @@ const asChannel = (value: string): MetricChannel | undefined =>
71
71
  */
72
72
  function Panel({ title, children }: { title: string; children: ReactNode }) {
73
73
  return (
74
- <section className="border-border bg-card mt-6 rounded-2xl border" style={superellipse}>
75
- <div className="border-border border-b px-5 py-3">
74
+ <section className="mt-6 rounded-2xl border border-border bg-card" style={superellipse}>
75
+ <div className="border-b border-border px-5 py-3">
76
76
  <h2 className="text-sm font-semibold">{title}</h2>
77
77
  </div>
78
78
  {children}
@@ -87,8 +87,8 @@ function Panel({ title, children }: { title: string; children: ReactNode }) {
87
87
  */
88
88
  function FunnelCell({ rate, count }: { rate: string; count: number }) {
89
89
  return (
90
- <td className="border-border border-b px-4 py-3 align-top tabular-nums">
91
- <div className="text-muted text-xs">{rate}</div>
90
+ <td className="border-b border-border px-4 py-3 align-top tabular-nums">
91
+ <div className="text-xs text-muted">{rate}</div>
92
92
  <div className="text-sm">{number(count)}</div>
93
93
  </td>
94
94
  );
@@ -270,11 +270,11 @@ function MetricsTab() {
270
270
  return (
271
271
  <div className="flex flex-1 items-center justify-center p-8">
272
272
  <div
273
- className="border-border bg-card max-w-md rounded-2xl border border-dashed p-8 text-center"
273
+ className="max-w-md rounded-2xl border border-dashed border-border bg-card p-8 text-center"
274
274
  style={superellipse}
275
275
  >
276
276
  <p className="text-sm font-medium">{t('metrics.noSource')}</p>
277
- <p className="text-muted mt-2 text-sm">{t('metrics.noSourceHint')}</p>
277
+ <p className="mt-2 text-sm text-muted">{t('metrics.noSourceHint')}</p>
278
278
  </div>
279
279
  </div>
280
280
  );
@@ -386,7 +386,7 @@ function MetricsTab() {
386
386
  </div>
387
387
 
388
388
  {buckets.length === 0 ? (
389
- <p className="text-muted mt-6 text-sm">{t('metrics.noData')}</p>
389
+ <p className="mt-6 text-sm text-muted">{t('metrics.noData')}</p>
390
390
  ) : (
391
391
  <div className="mt-4 grid gap-4 sm:grid-cols-2 xl:grid-cols-4">{CARD_KEYS.map(cardOf)}</div>
392
392
  )}
@@ -396,7 +396,7 @@ function MetricsTab() {
396
396
  <table className="w-full border-separate border-spacing-0 text-sm">
397
397
  <thead>
398
398
  <tr className="text-left text-xs font-semibold">
399
- <th className="border-border border-b px-4 py-2.5">
399
+ <th className="border-b border-border px-4 py-2.5">
400
400
  <button
401
401
  type="button"
402
402
  className="inline-flex items-center gap-1"
@@ -411,7 +411,7 @@ function MetricsTab() {
411
411
  </button>
412
412
  </th>
413
413
  {MESSAGE_COLUMNS.map((column) => (
414
- <th key={column} className="border-border w-32 border-b px-4 py-2.5">
414
+ <th key={column} className="w-32 border-b border-border px-4 py-2.5">
415
415
  {t(`metrics.messages.${column}`)}
416
416
  </th>
417
417
  ))}
@@ -420,14 +420,14 @@ function MetricsTab() {
420
420
  <tbody>
421
421
  {rows.length === 0 ? (
422
422
  <tr>
423
- <td className="text-muted px-4 py-4 text-sm" colSpan={MESSAGE_COLUMNS.length + 1}>
423
+ <td className="px-4 py-4 text-sm text-muted" colSpan={MESSAGE_COLUMNS.length + 1}>
424
424
  {t('metrics.messages.empty')}
425
425
  </td>
426
426
  </tr>
427
427
  ) : (
428
428
  <>
429
429
  <tr>
430
- <td className="border-border border-b px-4 py-3 align-top font-semibold">
430
+ <td className="border-b border-border px-4 py-3 align-top font-semibold">
431
431
  {t('metrics.messages.allMessages')}
432
432
  </td>
433
433
  <FunnelCell rate={SENT_SHARE} count={totals.sent} />
@@ -456,13 +456,13 @@ function MetricsTab() {
456
456
  key={`${row.nodeId}:${row.template}:${row.channel}`}
457
457
  className="last:[&>td]:border-b-0"
458
458
  >
459
- <td className="border-border border-b px-4 py-3 align-top">
459
+ <td className="border-b border-border px-4 py-3 align-top">
460
460
  <span className="flex items-center gap-2">
461
461
  <RowGlyph
462
462
  size={14}
463
463
  strokeWidth={2}
464
464
  aria-hidden
465
- className="text-muted shrink-0"
465
+ className="shrink-0 text-muted"
466
466
  />
467
467
  <Link
468
468
  to="/templates/$key"
@@ -470,7 +470,7 @@ function MetricsTab() {
470
470
  search={{
471
471
  channel: row.channel.startsWith('push') ? 'push' : row.channel,
472
472
  }}
473
- className="text-accent truncate hover:underline"
473
+ className="truncate text-accent hover:underline"
474
474
  >
475
475
  {label}
476
476
  </Link>
@@ -499,10 +499,10 @@ function MetricsTab() {
499
499
  <table className="w-full table-fixed border-separate border-spacing-0 text-sm">
500
500
  <thead>
501
501
  <tr className="text-left text-xs font-semibold">
502
- <th className="border-border border-b px-5 py-2.5">
502
+ <th className="border-b border-border px-5 py-2.5">
503
503
  {t('metrics.links.topClicked')}
504
504
  </th>
505
- <th className="border-border w-40 border-b px-5 py-2.5 text-right">
505
+ <th className="w-40 border-b border-border px-5 py-2.5 text-right">
506
506
  {t('metrics.links.totalClicks')}
507
507
  </th>
508
508
  </tr>
@@ -510,17 +510,17 @@ function MetricsTab() {
510
510
  <tbody>
511
511
  {topLinks.length === 0 ? (
512
512
  <tr>
513
- <td className="text-muted px-5 py-4 text-sm" colSpan={2}>
513
+ <td className="px-5 py-4 text-sm text-muted" colSpan={2}>
514
514
  {t('metrics.links.empty')}
515
515
  </td>
516
516
  </tr>
517
517
  ) : (
518
518
  topLinks.map((link) => (
519
519
  <tr key={link.url} className="last:[&>td]:border-b-0">
520
- <td className="border-border truncate border-b px-5 py-2.5" title={link.url}>
520
+ <td className="truncate border-b border-border px-5 py-2.5" title={link.url}>
521
521
  {link.url}
522
522
  </td>
523
- <td className="border-border border-b px-5 py-2.5 text-right tabular-nums">
523
+ <td className="border-b border-border px-5 py-2.5 text-right tabular-nums">
524
524
  {number(link.clicks)}
525
525
  </td>
526
526
  </tr>
@@ -18,8 +18,8 @@ const day = (iso: string | undefined) => (iso === undefined ? '—' : iso.slice(
18
18
 
19
19
  function Stat({ label, value }: { label: string; value: string }) {
20
20
  return (
21
- <div className="border-border bg-card rounded-2xl border px-4 py-3" style={superellipse}>
22
- <div className="text-muted text-xs">{label}</div>
21
+ <div className="rounded-2xl border border-border bg-card px-4 py-3" style={superellipse}>
22
+ <div className="text-xs text-muted">{label}</div>
23
23
  <div className="mt-1 text-xl font-semibold tabular-nums">{value}</div>
24
24
  </div>
25
25
  );
@@ -70,11 +70,11 @@ function SegmentOverview() {
70
70
  return (
71
71
  <div className="flex flex-1 items-center justify-center p-8">
72
72
  <div
73
- className="border-border bg-card max-w-md rounded-2xl border border-dashed p-8 text-center"
73
+ className="max-w-md rounded-2xl border border-dashed border-border bg-card p-8 text-center"
74
74
  style={superellipse}
75
75
  >
76
76
  <p className="text-sm font-medium">{t('segments.noSource')}</p>
77
- <p className="text-muted mt-2 text-sm">{t('segments.noSourceHint')}</p>
77
+ <p className="mt-2 text-sm text-muted">{t('segments.noSourceHint')}</p>
78
78
  </div>
79
79
  </div>
80
80
  );
@@ -94,25 +94,25 @@ function SegmentOverview() {
94
94
  <Stat label={t('segments.profiles')} value={total > 0 ? number(total) : '—'} />
95
95
  </div>
96
96
 
97
- <section className="border-border bg-card mt-6 rounded-2xl border p-5" style={superellipse}>
97
+ <section className="mt-6 rounded-2xl border border-border bg-card p-5" style={superellipse}>
98
98
  <h2 className="text-sm font-semibold">{t('segments.overTime')}</h2>
99
99
  {series.length > 1 ? (
100
100
  <div className="mt-4">
101
101
  <SeriesChart values={series} ariaLabel={t('segments.overTime')} />
102
102
  </div>
103
103
  ) : (
104
- <p className="text-muted mt-6 text-sm">{t('segments.noData')}</p>
104
+ <p className="mt-6 text-sm text-muted">{t('segments.noData')}</p>
105
105
  )}
106
106
  </section>
107
107
 
108
108
  {/* No `overflow-hidden`: it would clip the corners for free, but any
109
109
  overflow value turns a card into a scrollport, which is the habit
110
110
  this layout is getting rid of. The last row re-cuts its own. */}
111
- <section className="border-border bg-card mt-6 rounded-2xl border" style={superellipse}>
112
- <div className="border-border flex items-center justify-between border-b px-5 py-3">
111
+ <section className="mt-6 rounded-2xl border border-border bg-card" style={superellipse}>
112
+ <div className="flex items-center justify-between border-b border-border px-5 py-3">
113
113
  <h2 className="text-sm font-semibold">{t('segments.members')}</h2>
114
114
  {total > PAGE_SIZE && (
115
- <div className="text-muted flex items-center gap-2 text-xs">
115
+ <div className="flex items-center gap-2 text-xs text-muted">
116
116
  <span className="tabular-nums">
117
117
  {number(page * PAGE_SIZE + 1)}–{number(Math.min((page + 1) * PAGE_SIZE, total))} /{' '}
118
118
  {number(total)}
@@ -121,7 +121,7 @@ function SegmentOverview() {
121
121
  type="button"
122
122
  disabled={page === 0}
123
123
  onClick={() => setPage((current) => current - 1)}
124
- className="hover:bg-hover rounded px-2 py-1 transition-colors disabled:opacity-40"
124
+ className="rounded px-2 py-1 transition-colors hover:bg-hover disabled:opacity-40"
125
125
  >
126
126
  {t('common.previous')}
127
127
  </button>
@@ -129,7 +129,7 @@ function SegmentOverview() {
129
129
  type="button"
130
130
  disabled={page >= lastPage}
131
131
  onClick={() => setPage((current) => current + 1)}
132
- className="hover:bg-hover rounded px-2 py-1 transition-colors disabled:opacity-40"
132
+ className="rounded px-2 py-1 transition-colors hover:bg-hover disabled:opacity-40"
133
133
  >
134
134
  {t('common.next')}
135
135
  </button>
@@ -138,18 +138,18 @@ function SegmentOverview() {
138
138
  </div>
139
139
 
140
140
  {isPending ? (
141
- <p className="text-muted p-5 text-sm">{t('common.loading')}</p>
141
+ <p className="p-5 text-sm text-muted">{t('common.loading')}</p>
142
142
  ) : profilePage === undefined || profilePage.profiles.length === 0 ? (
143
- <p className="text-muted p-5 text-sm">{t('segments.noProfiles')}</p>
143
+ <p className="p-5 text-sm text-muted">{t('segments.noProfiles')}</p>
144
144
  ) : (
145
145
  <table className="w-full table-fixed border-separate border-spacing-0 text-sm">
146
146
  <thead>
147
- <tr className="text-muted text-left text-xs font-medium">
148
- <th className="border-border border-b px-5 py-2">{t('profiles.email')}</th>
149
- <th className="border-border w-56 border-b px-5 py-2">
147
+ <tr className="text-left text-xs font-medium text-muted">
148
+ <th className="border-b border-border px-5 py-2">{t('profiles.email')}</th>
149
+ <th className="w-56 border-b border-border px-5 py-2">
150
150
  {t('profiles.utmSource')}
151
151
  </th>
152
- <th className="border-border w-36 border-b px-5 py-2 whitespace-nowrap">
152
+ <th className="w-36 border-b border-border px-5 py-2 whitespace-nowrap">
153
153
  {t('profiles.createdAt')}
154
154
  </th>
155
155
  </tr>
@@ -163,10 +163,10 @@ function SegmentOverview() {
163
163
  top of it reads as a doubled line. The hover fill sits on
164
164
  the cells so the last row's corners can follow the card's
165
165
  — a row box paints below any cell radius. */
166
- className="hover:[&>td]:bg-hover cursor-pointer [&>td]:transition-colors last:[&>td]:border-b-0 last:[&>td:first-child]:rounded-bl-2xl last:[&>td:last-child]:rounded-br-2xl"
166
+ className="cursor-pointer [&>td]:transition-colors last:[&>td]:border-b-0 hover:[&>td]:bg-hover last:[&>td:first-child]:rounded-bl-2xl last:[&>td:last-child]:rounded-br-2xl"
167
167
  style={superellipse}
168
168
  >
169
- <td className="border-border border-b px-5 py-2.5" style={superellipse}>
169
+ <td className="border-b border-border px-5 py-2.5" style={superellipse}>
170
170
  {/* The avatar is fixed-width, so the address does the
171
171
  truncating — `truncate` on the cell itself would be
172
172
  undone by the flex row inside it. */}
@@ -179,14 +179,14 @@ function SegmentOverview() {
179
179
  <span className="truncate">{profile.email ?? '—'}</span>
180
180
  </div>
181
181
  </td>
182
- <td className="border-border text-muted truncate border-b px-5 py-2.5 font-mono text-sm">
182
+ <td className="truncate border-b border-border px-5 py-2.5 font-mono text-sm text-muted">
183
183
  {/* Out of a dictionary of unknowns, so anything but a string reads as absent. */}
184
184
  {typeof profile.properties?.utm_source === 'string'
185
185
  ? profile.properties.utm_source
186
186
  : '—'}
187
187
  </td>
188
188
  <td
189
- className="border-border text-muted border-b px-5 py-2.5 whitespace-nowrap tabular-nums"
189
+ className="border-b border-border px-5 py-2.5 whitespace-nowrap text-muted tabular-nums"
190
190
  style={superellipse}
191
191
  >
192
192
  {day(profile.createdAt)}
@@ -134,7 +134,7 @@ function Segments() {
134
134
 
135
135
  if (refs.length === 0) {
136
136
  return (
137
- <div className="text-muted flex flex-1 items-center justify-center text-sm">
137
+ <div className="flex flex-1 items-center justify-center text-sm text-muted">
138
138
  {t('segments.empty')}
139
139
  </div>
140
140
  );
@@ -159,7 +159,7 @@ function Segments() {
159
159
  </div>
160
160
  <div className="px-6 pb-6">
161
161
  {filtered.length === 0 ? (
162
- <div className="text-muted flex items-center justify-center py-24 text-sm">
162
+ <div className="flex items-center justify-center py-24 text-sm text-muted">
163
163
  {t('segments.noMatches', { query: query.trim() })}
164
164
  </div>
165
165
  ) : (
@@ -29,11 +29,11 @@ function Settings() {
29
29
  <PageChrome breadcrumb={<Breadcrumb items={[{ label: t('nav.settings') }]} />} />
30
30
 
31
31
  <section
32
- className="border-border bg-card mt-5 max-w-xl rounded-2xl border p-5"
32
+ className="mt-5 max-w-xl rounded-2xl border border-border bg-card p-5"
33
33
  style={superellipse}
34
34
  >
35
35
  <h2 className="text-sm font-medium">{t('settings.language')}</h2>
36
- <p className="text-muted mt-1 text-xs">{t('settings.languageHint')}</p>
36
+ <p className="mt-1 text-xs text-muted">{t('settings.languageHint')}</p>
37
37
  <div className="mt-3 flex gap-2">
38
38
  {supportedLngs.map((lng: SupportedLng) => (
39
39
  <Button
@@ -49,11 +49,11 @@ function Settings() {
49
49
  </section>
50
50
 
51
51
  <section
52
- className="border-border bg-card mt-4 max-w-xl rounded-2xl border p-5"
52
+ className="mt-4 max-w-xl rounded-2xl border border-border bg-card p-5"
53
53
  style={superellipse}
54
54
  >
55
55
  <h2 className="text-sm font-medium">{t('settings.theme')}</h2>
56
- <p className="text-muted mt-1 text-xs">{t('settings.themeHint')}</p>
56
+ <p className="mt-1 text-xs text-muted">{t('settings.themeHint')}</p>
57
57
  <div className="mt-3 flex gap-2">
58
58
  {themes.map((option: Theme) => (
59
59
  <Button
@@ -74,11 +74,11 @@ function Settings() {
74
74
  />
75
75
 
76
76
  <section
77
- className="border-border bg-card mt-4 max-w-xl rounded-2xl border p-5"
77
+ className="mt-4 max-w-xl rounded-2xl border border-border bg-card p-5"
78
78
  style={superellipse}
79
79
  >
80
80
  <h2 className="text-sm font-medium">{t('settings.statsSource')}</h2>
81
- <p className="text-secondary mt-2 font-mono text-xs">
81
+ <p className="mt-2 font-mono text-xs text-secondary">
82
82
  {sources.length > 0 ? sources.join(', ') : t('common.notConfigured')}
83
83
  </p>
84
84
  </section>