Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
ποΈ Enforce the DAL pattern (RAL-1333) (#2659)
Luke Vella82290a7817fd
diff --git a/CLAUDE.md b/CLAUDE.mdindex 60c468785..4583d5f62 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -193,6 +193,8 @@ Always use gitmoji prefixes in commit messages. Follow the gitmoji convention (h- `assets/` β static files used by the feature- NOT allowed: `index.ts` barrels, `helpers.ts`, `queries.ts`, `hooks.ts`, `lib/`, `libs/`+**DAL enforcement** β `@rallly/database` may only be imported from `features/**/data.ts` and `features/**/mutations.ts` (lint-enforced via `noRestrictedImports`; existing violations sit on a shrinking migration allowlist in `apps/web/biome.json`). Parameterized reads take their tenant scope as `spaceId: AuthorizedSpaceId` (from `@/features/space/types`); only the session gate (`createSpaceDTO`) and the API key middleware may cast to it. API routes under `app/api/**` (except tRPC and better-auth) must not import session scoped DAL modules β they authenticate their own way and pass proven scope to parameterized reads. `api/private` handlers own serialization and must parse response bodies through their zod schemas.+**Cross-feature imports** β allowed, public surface only (the vocabulary files above); never reach into another feature's internals. No cycles between features (CI-enforced). For UI, prefer composing multiple features at the page level in `app/` over feature-to-feature component imports.**`trpc/` is frozen legacy transport** β queries only; routers call `features/*/data.ts`. No new mutations β writes are server actions calling `features/*/mutations.ts`.diff --git a/apps/web/biome.json b/apps/web/biome.jsonindex a26b5fb1c..a71b19bc8 100644--- a/apps/web/biome.json+++ b/apps/web/biome.json@@ -12,7 +12,8 @@"options": {"paths": {"dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json).",- "@/lib/dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json)."+ "@/lib/dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json).",+ "@rallly/database": "Database access is confined to the DAL: only features/**/data.ts and features/**/mutations.ts may import @rallly/database. Existing violations are on the migration allowlist (see overrides in apps/web/biome.json)."},"patterns": [{@@ -21,7 +22,7 @@},{"group": ["@/utils", "@/utils/**"],- "message": "src/utils is dissolved (RAL-1286). Generic helpers live in @/lib/utils, infrastructure in @/lib, domain code in the owning feature."+ "message": "src/utils is dissolved. Generic helpers live in @/lib/utils, infrastructure in @/lib, domain code in the owning feature."}]}@@ -40,12 +41,13 @@"options": {"paths": {"dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json).",- "@/lib/dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json)."+ "@/lib/dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json).",+ "@rallly/database": "Database access is confined to the DAL: only features/**/data.ts and features/**/mutations.ts may import @rallly/database. Existing violations are on the migration allowlist (see overrides in apps/web/biome.json)."},"patterns": [{"group": ["@/features/**"],- "message": "components/ is domain-agnostic UI and must not depend on features/. Move domain components into features/<domain>/components/ (RAL-1291). Existing violations are on the migration allowlist (see overrides in apps/web/biome.json)."+ "message": "components/ is domain-agnostic UI and must not depend on features/. Move domain components into features/<domain>/components/. Existing violations are on the migration allowlist (see overrides in apps/web/biome.json)."},{"group": ["@/app", "@/app/**"],@@ -53,7 +55,7 @@},{"group": ["@/utils", "@/utils/**"],- "message": "src/utils is dissolved (RAL-1286). Generic helpers live in @/lib/utils, infrastructure in @/lib, domain code in the owning feature."+ "message": "src/utils is dissolved. Generic helpers live in @/lib/utils, infrastructure in @/lib, domain code in the owning feature."}]}@@ -72,7 +74,8 @@"options": {"paths": {"dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json).",- "@/lib/dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json)."+ "@/lib/dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json).",+ "@rallly/database": "Database access is confined to the DAL: only features/**/data.ts and features/**/mutations.ts may import @rallly/database. Existing violations are on the migration allowlist (see overrides in apps/web/biome.json)."},"patterns": [{@@ -85,7 +88,7 @@},{"group": ["@/utils", "@/utils/**"],- "message": "src/utils is dissolved (RAL-1286). Generic helpers live in @/lib/utils, infrastructure in @/lib, domain code in the owning feature."+ "message": "src/utils is dissolved. Generic helpers live in @/lib/utils, infrastructure in @/lib, domain code in the owning feature."}]}@@ -96,6 +99,169 @@},{"includes": ["src/app/**"],+ "linter": {+ "rules": {+ "style": {+ "noRestrictedImports": {+ "level": "error",+ "options": {+ "paths": {+ "dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json).",+ "@/lib/dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json).",+ "@rallly/database": "Database access is confined to the DAL: only features/**/data.ts and features/**/mutations.ts may import @rallly/database. Existing violations are on the migration allowlist (see overrides in apps/web/biome.json)."+ },+ "patterns": [+ {+ "group": ["@/utils", "@/utils/**"],+ "message": "src/utils is dissolved. Generic helpers live in @/lib/utils, infrastructure in @/lib, domain code in the owning feature."+ }+ ]+ }+ }+ }+ }+ }+ },+ {+ "includes": [+ "src/app/api/**",+ "!src/app/api/trpc/**",+ "!src/app/api/better-auth/**"+ ],+ "linter": {+ "rules": {+ "style": {+ "noRestrictedImports": {+ "level": "error",+ "options": {+ "paths": {+ "dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json).",+ "@/lib/dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json).",+ "@rallly/database": "Database access is confined to the DAL: only features/**/data.ts and features/**/mutations.ts may import @rallly/database. Existing violations are on the migration allowlist (see overrides in apps/web/biome.json)."+ },+ "patterns": [+ {+ "group": [+ "@/features/user/data",+ "@/features/api-keys/data"+ ],+ "message": "Session scoped DAL modules derive the actor from cookies and must not be used in API routes. Webhooks, cron and API key routes authenticate their own way and pass proven scope to parameterized reads."+ },+ {+ "group": ["@/utils", "@/utils/**"],+ "message": "src/utils is dissolved. Generic helpers live in @/lib/utils, infrastructure in @/lib, domain code in the owning feature."+ }+ ]+ }+ }+ }+ }+ }+ },+ {+ "includes": [+ "src/app/api/event/**",+ "src/app/api/legacy/**",+ "src/app/api/status/**",+ "src/app/api/updates/**",+ "src/app/api/private/**"+ ],+ "linter": {+ "rules": {+ "style": {+ "noRestrictedImports": {+ "level": "error",+ "options": {+ "paths": {+ "dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json).",+ "@/lib/dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json)."+ },+ "patterns": [+ {+ "group": [+ "@/features/user/data",+ "@/features/api-keys/data"+ ],+ "message": "Session scoped DAL modules derive the actor from cookies and must not be used in API routes. Webhooks, cron and API key routes authenticate their own way and pass proven scope to parameterized reads."+ },+ {+ "group": ["@/utils", "@/utils/**"],+ "message": "src/utils is dissolved. Generic helpers live in @/lib/utils, infrastructure in @/lib, domain code in the owning feature."+ }+ ]+ }+ }+ }+ }+ }+ },+ {+ "includes": [+ "src/app/*/(optional-space)/new/page.tsx",+ "src/app/*/(optional-space)/poll/*/layout.tsx",+ "src/app/*/(space)/settings/preferences/components/date-time-preferences.tsx",+ "src/app/*/accept-invite/*/page.tsx",+ "src/app/*/invite/*/page.tsx",+ "src/app/*/control-panel/settings/actions.ts",+ "src/app/*/control-panel/users/page.tsx",+ "src/app/*/e/*/components/rsvp-area.tsx"+ ],+ "linter": {+ "rules": {+ "style": {+ "noRestrictedImports": {+ "level": "error",+ "options": {+ "paths": {+ "dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json).",+ "@/lib/dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json)."+ },+ "patterns": [+ {+ "group": ["@/utils", "@/utils/**"],+ "message": "src/utils is dissolved. Generic helpers live in @/lib/utils, infrastructure in @/lib, domain code in the owning feature."+ }+ ]+ }+ }+ }+ }+ }+ },+ {+ "includes": [+ "src/trpc/trpc.ts",+ "src/trpc/client/types.ts",+ "src/trpc/routers/auth.ts",+ "src/trpc/routers/dashboard.ts",+ "src/trpc/routers/event-types.ts",+ "src/trpc/routers/events.ts",+ "src/trpc/routers/spaces.ts",+ "src/trpc/routers/system.ts",+ "src/trpc/routers/user.ts",+ "src/trpc/routers/polls/comments.ts",+ "src/trpc/routers/polls/participants.ts",+ "src/features/billing/components/subscription-status-label.tsx",+ "src/features/licensing/actions.ts",+ "src/features/poll/components/desktop-poll/participant-row.tsx",+ "src/features/poll/components/mobile-poll/poll-option.tsx",+ "src/features/poll/components/mobile-poll/poll-options.tsx",+ "src/features/poll/components/new-participant-modal.tsx",+ "src/features/poll/components/participants-provider.tsx",+ "src/features/poll/components/poll-context.tsx",+ "src/features/poll/components/poll-status-icon.tsx",+ "src/features/poll/components/types.ts",+ "src/features/poll/components/vote-icon.tsx",+ "src/features/poll/components/vote-selector.tsx",+ "src/features/scheduled-event/components/scheduled-event-list.tsx",+ "src/features/scheduled-event/utils.ts",+ "src/features/setup/utils.ts",+ "src/features/space/actions.ts",+ "src/features/space/utils.ts",+ "src/features/user/ability.ts",+ "src/features/user/actions.ts",+ "src/features/user/schema.ts"+ ],"linter": {"rules": {"style": {@@ -107,9 +273,77 @@"@/lib/dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json)."},"patterns": [+ {+ "group": ["@/app", "@/app/**"],+ "message": "Only files inside app/ may import from app/. Routes are thin adapters; shared code belongs in features/, components/, or lib/. Existing violations are on the migration allowlist (see overrides in apps/web/biome.json)."+ },+ {+ "group": ["@/utils", "@/utils/**"],+ "message": "src/utils is dissolved. Generic helpers live in @/lib/utils, infrastructure in @/lib, domain code in the owning feature."+ }+ ]+ }+ }+ }+ }+ }+ },+ {+ "includes": ["src/components/time-format-picker.tsx"],+ "linter": {+ "rules": {+ "style": {+ "noRestrictedImports": {+ "level": "error",+ "options": {+ "paths": {+ "dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json).",+ "@/lib/dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json)."+ },+ "patterns": [+ {+ "group": ["@/features/**"],+ "message": "components/ is domain-agnostic UI and must not depend on features/. Move domain components into features/<domain>/components/. Existing violations are on the migration allowlist (see overrides in apps/web/biome.json)."+ },+ {+ "group": ["@/app", "@/app/**"],+ "message": "Only files inside app/ may import from app/. Routes are thin adapters; shared code belongs in features/, components/, or lib/."+ },+ {+ "group": ["@/utils", "@/utils/**"],+ "message": "src/utils is dissolved. Generic helpers live in @/lib/utils, infrastructure in @/lib, domain code in the owning feature."+ }+ ]+ }+ }+ }+ }+ }+ },+ {+ "includes": [+ "src/features/**/data.ts",+ "src/features/**/mutations.ts",+ "!src/features/**/components/**"+ ],+ "linter": {+ "rules": {+ "style": {+ "noRestrictedImports": {+ "level": "error",+ "options": {+ "paths": {+ "dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json).",+ "@/lib/dayjs": "Use the formatters in `@/lib/datetime` for display. dayjs is only allowed in files on the migration allowlist (see overrides in biome.json)."+ },+ "patterns": [+ {+ "group": ["@/app", "@/app/**"],+ "message": "Only files inside app/ may import from app/. Routes are thin adapters; shared code belongs in features/, components/, or lib/. Existing violations are on the migration allowlist (see overrides in apps/web/biome.json)."+ },{"group": ["@/utils", "@/utils/**"],- "message": "src/utils is dissolved (RAL-1286). Generic helpers live in @/lib/utils, infrastructure in @/lib, domain code in the owning feature."+ "message": "src/utils is dissolved. Generic helpers live in @/lib/utils, infrastructure in @/lib, domain code in the owning feature."}]}diff --git a/apps/web/src/app/[locale]/(auth)/components/already-logged-in.tsx b/apps/web/src/app/[locale]/(auth)/components/already-logged-in.tsxindex f3b6ad878..51cc070e5 100644--- a/apps/web/src/app/[locale]/(auth)/components/already-logged-in.tsx+++ b/apps/web/src/app/[locale]/(auth)/components/already-logged-in.tsx@@ -15,7 +15,7 @@ import { SignOutButton } from "./sign-out-button";/*** Shown on /login instead of redirecting when a session already exists.* The redirect used to be automatic, which made /login one leg of the- * / β /login redirect loop (RAL-1313) β a loop needs two automated legs,+ * / β /login redirect loop β a loop needs two automated legs,* so the user must click to continue. The sign out button is the escape* hatch when the session only looks alive (stale cookie cache).*diff --git a/apps/web/src/app/[locale]/(auth)/login/page.tsx b/apps/web/src/app/[locale]/(auth)/login/page.tsxindex fa120a4a9..2072e6f40 100644--- a/apps/web/src/app/[locale]/(auth)/login/page.tsx+++ b/apps/web/src/app/[locale]/(auth)/login/page.tsx@@ -43,7 +43,7 @@ export default async function LoginPage(props: {const searchParams = await props.searchParams;// No automatic redirect to / β an automated redirect here is one leg of- // the / β /login redirect loop (RAL-1313). The user must click through.+ // the / β /login redirect loop. The user must click through.// On "error" the session is unknown, so we fall through to the login// form rather than guess.const sessionState = await getSessionState();diff --git a/apps/web/src/app/[locale]/error.tsx b/apps/web/src/app/[locale]/error.tsxindex 74fb61b24..fcb099333 100644--- a/apps/web/src/app/[locale]/error.tsx+++ b/apps/web/src/app/[locale]/error.tsx@@ -31,7 +31,7 @@ export default function LocaleErrorBoundary({if (isInvalidSession) {// Never sign out automatically β a failed sign out turns this into an- // infinite loop with the login page (RAL-1313).+ // infinite loop with the login page.return (<ErrorPagelabel={<Trans i18nKey="invalidSessionLabel" defaults="Session" />}diff --git a/apps/web/src/app/api/private/[...route]/route.test.ts b/apps/web/src/app/api/private/[...route]/route.test.tsindex 9832edd78..ed041ddc3 100644--- a/apps/web/src/app/api/private/[...route]/route.test.ts+++ b/apps/web/src/app/api/private/[...route]/route.test.ts@@ -58,9 +58,27 @@ vi.mock("@/lib/kv", () => ({import { prisma } from "@rallly/database";import { after } from "next/server";import { hashApiKey, verifyApiKey } from "@/features/api-keys/utils";+import {+ createPollSuccessResponseSchema,+ deletePollSuccessResponseSchema,+ getPollParticipantsSuccessResponseSchema,+ getPollResultsSuccessResponseSchema,+ getPollSuccessResponseSchema,+} from "../schemas";import { RATE_LIMIT_PER_MINUTE } from "../utils/rate-limit";import { app } from "./route";+const expectMatchesContract = (+ schema: {+ safeParse: (data: unknown) => { success: boolean; error?: unknown };+ },+ body: unknown,+) => {+ const result = schema.safeParse(body);+ expect(result.error).toBeUndefined();+ expect(result.success).toBe(true);+};+// Pre-generated test API key fixture. The stored hash deliberately uses the// deprecated scrypt format so every test in this file exercises the legacy// verification path that existing production keys depend on.@@ -415,6 +433,7 @@ describe("Private API - /polls", () => {expect(res.status).toBe(200);const json = await res.json();+ expectMatchesContract(createPollSuccessResponseSchema, json);expect(json.data.id).toBe("test-poll-id");expect(json.data.adminUrl).toBe("https://example.com/poll/test-poll-id");expect(json.data.inviteUrl).toBe(@@ -528,6 +547,7 @@ describe("Private API - /polls", () => {expect(res.status).toBe(200);const json = await res.json();+ expectMatchesContract(createPollSuccessResponseSchema, json);expect(json.data.id).toBe("test-poll-id");expect(mockCreatePoll).toHaveBeenCalledWith(@@ -711,6 +731,7 @@ describe("Private API - /polls", () => {expect(res.status).toBe(200);const json = await res.json();+ expectMatchesContract(deletePollSuccessResponseSchema, json);expect(json.data.id).toBe("test-poll-id");expect(json.data.deleted).toBe(true);@@ -813,6 +834,7 @@ describe("Private API - /polls", () => {expect(res.status).toBe(200);const json = await res.json();+ expectMatchesContract(getPollSuccessResponseSchema, json);expect(json.data.id).toBe("test-poll-id");expect(json.data.title).toBe("Team sync");expect(json.data.description).toBe("Weekly team meeting");@@ -962,6 +984,7 @@ describe("Private API - /polls", () => {expect(res.status).toBe(200);const json = await res.json();+ expectMatchesContract(getPollResultsSuccessResponseSchema, json);expect(json.data.pollId).toBe("test-poll-id");expect(json.data.participantCount).toBe(5);@@ -1223,6 +1246,7 @@ describe("Private API - /polls", () => {expect(res.status).toBe(200);const json = await res.json();+ expectMatchesContract(getPollParticipantsSuccessResponseSchema, json);expect(json.data.pollId).toBe("test-poll-id");expect(json.data.participants).toHaveLength(2);diff --git a/apps/web/src/app/api/private/[...route]/route.ts b/apps/web/src/app/api/private/[...route]/route.tsindex 1cbffbdf3..459f34429 100644--- a/apps/web/src/app/api/private/[...route]/route.ts+++ b/apps/web/src/app/api/private/[...route]/route.ts@@ -12,6 +12,7 @@ import {} from "hono-openapi";import { getPollParticipants, getPollResults } from "@/features/poll/data";import { createPoll, deletePoll } from "@/features/poll/mutations";+import type { AuthorizedSpaceId } from "@/features/space/types";import { isMaintenanceModeEnabled } from "@/lib/maintenance";import {createPollInputSchema,@@ -36,7 +37,7 @@ import { wideEvent } from "../utils/wide-event";type Env = {Variables: {apiAuth: {- spaceId: string;+ spaceId: AuthorizedSpaceId;spaceOwnerId: string;spaceTier: SpaceTier;apiKeyId: string;@@ -46,6 +47,43 @@ type Env = {const app = new Hono<Env>().basePath("/api/private");+function toPollResponseBody(poll: {+ id: string;+ title: string;+ description: string | null;+ location: string | null;+ timeZone: string | null;+ status: string;+ createdAt: Date;+ user: { name: string; image: string | null } | null;+ options: { id: string; startTime: Date; duration: number }[];+}) {+ return {+ data: {+ id: poll.id,+ title: poll.title,+ description: poll.description,+ location: poll.location,+ timezone: poll.timeZone,+ status: poll.status,+ createdAt: poll.createdAt.toISOString(),+ user: poll.user+ ? {+ name: poll.user.name,+ image: poll.user.image,+ }+ : null,+ options: poll.options.map((option) => ({+ id: option.id,+ startTime: option.startTime.toISOString(),+ duration: option.duration,+ })),+ adminUrl: absoluteUrl(`/poll/${poll.id}`),+ inviteUrl: shortUrl(`/invite/${poll.id}`),+ },+ };+}+app.use("*", wideEvent);app.use("*", async (c, next) => {@@ -226,30 +264,9 @@ app.post(spaceId,});- return c.json({- data: {- id: poll.id,- title: poll.title,- description: poll.description,- location: poll.location,- timeZone: poll.timeZone,- status: poll.status,- createdAt: poll.createdAt.toISOString(),- user: poll.user- ? {- name: poll.user.name,- image: poll.user.image,- }- : null,- options: poll.options.map((option) => ({- id: option.id,- startTime: option.startTime.toISOString(),- duration: option.duration,- })),- adminUrl: absoluteUrl(`/poll/${poll.id}`),- inviteUrl: shortUrl(`/invite/${poll.id}`),- },- });+ return c.json(+ createPollSuccessResponseSchema.parse(toPollResponseBody(poll)),+ );}// Process slots (time-based options)@@ -317,30 +334,9 @@ app.post(spaceId,});- return c.json({- data: {- id: poll.id,- title: poll.title,- description: poll.description,- location: poll.location,- timezone: poll.timeZone,- status: poll.status,- createdAt: poll.createdAt.toISOString(),- user: poll.user- ? {- name: poll.user.name,- image: poll.user.image,- }- : null,- options: poll.options.map((option) => ({- id: option.id,- startTime: option.startTime.toISOString(),- duration: option.duration,- })),- adminUrl: absoluteUrl(`/poll/${poll.id}`),- inviteUrl: shortUrl(`/invite/${poll.id}`),- },- });+ return c.json(+ createPollSuccessResponseSchema.parse(toPollResponseBody(poll)),+ );},);@@ -422,30 +418,7 @@ app.get();}- return c.json({- data: {- id: poll.id,- title: poll.title,- description: poll.description,- location: poll.location,- timezone: poll.timeZone,- status: poll.status,- createdAt: poll.createdAt.toISOString(),- user: poll.user- ? {- name: poll.user.name,- image: poll.user.image,- }- : null,- options: poll.options.map((option) => ({- id: option.id,- startTime: option.startTime.toISOString(),- duration: option.duration,- })),- adminUrl: absoluteUrl(`/poll/${poll.id}`),- inviteUrl: shortUrl(`/invite/${poll.id}`),- },- });+ return c.json(getPollSuccessResponseSchema.parse(toPollResponseBody(poll)));},);@@ -496,9 +469,17 @@ app.get();}- return c.json({- data,- });+ return c.json(+ getPollResultsSuccessResponseSchema.parse({+ data: {+ ...data,+ options: data.options.map((option) => ({+ ...option,+ startTime: option.startTime.toISOString(),+ })),+ },+ }),+ );},);@@ -549,9 +530,17 @@ app.get();}- return c.json({- data,- });+ return c.json(+ getPollParticipantsSuccessResponseSchema.parse({+ data: {+ pollId: data.pollId,+ participants: data.participants.map((participant) => ({+ ...participant,+ createdAt: participant.createdAt.toISOString(),+ })),+ },+ }),+ );},);@@ -602,12 +591,14 @@ app.delete();}- return c.json({- data: {- id: result.id,- deleted: true as const,- },- });+ return c.json(+ deletePollSuccessResponseSchema.parse({+ data: {+ id: result.id,+ deleted: true,+ },+ }),+ );},);diff --git a/apps/web/src/app/api/private/utils/api-key.ts b/apps/web/src/app/api/private/utils/api-key.tsindex 16773f571..02d9b1afe 100644--- a/apps/web/src/app/api/private/utils/api-key.ts+++ b/apps/web/src/app/api/private/utils/api-key.ts@@ -11,6 +11,7 @@ import {isLegacyApiKeyHash,verifyApiKey,} from "@/features/api-keys/utils";+import type { AuthorizedSpaceId } from "@/features/space/types";import { isSelfHosted } from "@/lib/constants";import { apiError } from "./poll";@@ -82,7 +83,7 @@ const verifyKey = bearerAuth({const effectiveTier = isSelfHosted ? ("pro" as const) : spaceTier;c.set("apiAuth", {- spaceId,+ spaceId: spaceId as AuthorizedSpaceId,spaceOwnerId,spaceTier: effectiveTier,apiKeyId,diff --git a/apps/web/src/features/poll/data.ts b/apps/web/src/features/poll/data.tsindex 2ef93fb65..3fc174e4f 100644--- a/apps/web/src/features/poll/data.ts+++ b/apps/web/src/features/poll/data.ts@@ -2,13 +2,14 @@ import "server-only";import type { PollStatus, Prisma } from "@rallly/database";import { prisma } from "@rallly/database";+import type { AuthorizedSpaceId } from "@/features/space/types";export async function getPollResults({pollId,spaceId,}: {pollId: string;- spaceId: string;+ spaceId: AuthorizedSpaceId;}) {// Run poll query and vote aggregation in parallelconst [poll, voteCounts] = await Promise.all([@@ -114,7 +115,7 @@ export async function getPollParticipants({spaceId,}: {pollId: string;- spaceId: string;+ spaceId: AuthorizedSpaceId;}) {const poll = await prisma.poll.findFirst({where: {diff --git a/apps/web/src/features/poll/mutations.ts b/apps/web/src/features/poll/mutations.tsindex c0596b286..51aadbdf5 100644--- a/apps/web/src/features/poll/mutations.ts+++ b/apps/web/src/features/poll/mutations.ts@@ -2,6 +2,7 @@ import "server-only";import { prisma } from "@rallly/database";import { nanoid } from "@rallly/utils/nanoid";+import type { AuthorizedSpaceId } from "@/features/space/types";export type PollOption = {startTime: Date;@@ -19,7 +20,7 @@ export type CreatePollParams = {hideScores?: boolean;disableComments?: boolean;options: PollOption[];- spaceId: string;+ spaceId: AuthorizedSpaceId;};export const createPoll = async ({@@ -85,7 +86,10 @@ export const createPoll = async ({return poll;};-export const deletePoll = async (pollId: string, spaceId: string) => {+export const deletePoll = async (+ pollId: string,+ spaceId: AuthorizedSpaceId,+) => {const poll = await prisma.poll.findFirst({where: {id: pollId,diff --git a/apps/web/src/features/space/data.ts b/apps/web/src/features/space/data.tsindex a837bf21f..98a316c09 100644--- a/apps/web/src/features/space/data.ts+++ b/apps/web/src/features/space/data.ts@@ -8,7 +8,7 @@ import { prisma } from "@rallly/database";import { cache } from "react";import type { MemberDTO } from "@/features/space/member/types";-import type { SpaceDTO } from "@/features/space/types";+import type { AuthorizedSpaceId, SpaceDTO } from "@/features/space/types";import { fromDBRole } from "@/features/space/utils";import { isSelfHosted } from "@/lib/constants";@@ -57,7 +57,7 @@ export function createSpaceDTO(space: {showBranding: boolean;}): SpaceDTO {return {- id: space.id,+ id: space.id as AuthorizedSpaceId,name: space.name,ownerId: space.ownerId,tier: isSelfHosted ? "pro" : space.tier,diff --git a/apps/web/src/features/space/types.ts b/apps/web/src/features/space/types.tsindex f5a21427b..1cd88a085 100644--- a/apps/web/src/features/space/types.ts+++ b/apps/web/src/features/space/types.ts@@ -1,7 +1,13 @@import type { MemberRole } from "@/features/space/schema";+// Tenant scope proven by auth. Minted only by the session gate and the API+// key middleware; parameterized DAL reads require it.+export type AuthorizedSpaceId = string & {+ readonly __brand: "AuthorizedSpaceId";+};+export type SpaceDTO = {- id: string;+ id: AuthorizedSpaceId;name: string;ownerId: string;tier: "hobby" | "pro";diff --git a/apps/web/src/lib/auth.ts b/apps/web/src/lib/auth.tsindex d4ba24669..ec88923af 100644--- a/apps/web/src/lib/auth.ts+++ b/apps/web/src/lib/auth.ts@@ -535,7 +535,7 @@ export type SessionData = {* failure) is not the same as "there is no session". Redirect guards must* not treat an error as either logged-in or logged-out β reacting to an* unknown state is what turns a transient failure into a redirect loop- * between / and /login (RAL-1313).+ * between / and /login.*/export type SessionState =| { status: "authenticated"; session: SessionData }diff --git a/apps/web/src/trpc/client/provider.tsx b/apps/web/src/trpc/client/provider.tsxindex 21d3c94bf..575c8e0ba 100644--- a/apps/web/src/trpc/client/provider.tsx+++ b/apps/web/src/trpc/client/provider.tsx@@ -30,7 +30,7 @@ export function TRPCProvider(props: { children: React.ReactNode }) {switch (error.data?.code) {case "UNAUTHORIZED":// Never sign out automatically β a failed sign out turns this- // into an infinite loop with the login page (RAL-1313).+ // into an infinite loop with the login page.if (error.data.appError === "INVALID_SESSION") {toast.error(t("actionErrorInvalidSession", {diff --git a/apps/web/src/trpc/server/create-ssr-helper.ts b/apps/web/src/trpc/server/create-ssr-helper.tsindex 4c90416a9..f1f56bd1a 100644--- a/apps/web/src/trpc/server/create-ssr-helper.ts+++ b/apps/web/src/trpc/server/create-ssr-helper.ts@@ -40,7 +40,7 @@ export const createPrivateSSRHelper = cache(async () => {// An unreadable session (store unreachable, transient failure) is not// "logged out". Redirecting to /login on it is one leg of the / β /login- // redirect loop (RAL-1313) β fail the render instead so the user gets+ // redirect loop β fail the render instead so the user gets// the error boundary's retry page.if (state.status === "error") {throw new Error("Failed to read session");diff --git a/apps/web/tests/accessibility.spec.ts b/apps/web/tests/accessibility.spec.tsindex fa119b70a..3ef411882 100644--- a/apps/web/tests/accessibility.spec.ts+++ b/apps/web/tests/accessibility.spec.ts@@ -4,7 +4,7 @@ import { expect, test } from "@playwright/test";import { NewPollPage } from "./new-poll-page";/**- * Standing accessibility regression check (RAL-1233).+ * Standing accessibility regression check.** Runs axe-core against the pages covered by the ACR evidence scans. Scope is* WCAG 2.1 A/AA. If this fails, either fix the violation or β only for issues