@sssb/kit 0.0.0 → 0.2.0

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 (214) hide show
  1. package/LICENSE +21 -0
  2. package/dist/core/webhook-hmac.d.ts +69 -0
  3. package/dist/release.json +1 -0
  4. package/dist/testing/e2e.d.ts +15 -0
  5. package/dist/testing/e2e.js +195 -0
  6. package/package.json +209 -5
  7. package/src/adapters/README.md +6 -0
  8. package/src/adapters/dev-server.ts +21 -0
  9. package/src/adapters/fake/agreements.ts +81 -0
  10. package/src/adapters/fake/analytics.ts +93 -0
  11. package/src/adapters/fake/atomic-write.ts +161 -0
  12. package/src/adapters/fake/audit.ts +58 -0
  13. package/src/adapters/fake/auth.ts +312 -0
  14. package/src/adapters/fake/clock.ts +54 -0
  15. package/src/adapters/fake/data-dir.ts +27 -0
  16. package/src/adapters/fake/db.ts +88 -0
  17. package/src/adapters/fake/email.ts +46 -0
  18. package/src/adapters/fake/jobs.ts +270 -0
  19. package/src/adapters/fake/llm.ts +230 -0
  20. package/src/adapters/fake/pglite-dialect.ts +124 -0
  21. package/src/adapters/fake/service-auth.ts +145 -0
  22. package/src/adapters/fake/simulator-admin.ts +203 -0
  23. package/src/adapters/fake/simulator.ts +94 -0
  24. package/src/adapters/fake/sms.ts +43 -0
  25. package/src/adapters/fake/storage.ts +288 -0
  26. package/src/adapters/fake/webhooks.ts +98 -0
  27. package/src/adapters/index.ts +115 -0
  28. package/src/adapters/real/accept-invite-form.tsx +77 -0
  29. package/src/adapters/real/analytics.ts +28 -0
  30. package/src/adapters/real/auth.ts +216 -0
  31. package/src/adapters/real/contract-data-api.ts +104 -0
  32. package/src/adapters/real/contract-postgres.ts +167 -0
  33. package/src/adapters/real/database-transport.ts +34 -0
  34. package/src/adapters/real/db-data-api.ts +61 -0
  35. package/src/adapters/real/db.ts +88 -0
  36. package/src/adapters/real/email.ts +22 -0
  37. package/src/adapters/real/index.ts +89 -0
  38. package/src/adapters/real/jobs.ts +32 -0
  39. package/src/adapters/real/llm.ts +108 -0
  40. package/src/adapters/real/migrate-handler.ts +66 -0
  41. package/src/adapters/real/providers.tsx +12 -0
  42. package/src/adapters/real/rds-data-codec.ts +508 -0
  43. package/src/adapters/real/rds-data-dialect.ts +470 -0
  44. package/src/adapters/real/rds-data-emulator.ts +351 -0
  45. package/src/adapters/real/s3-storage.ts +233 -0
  46. package/src/adapters/real/sign-in-form.tsx +59 -0
  47. package/src/adapters/real/storage.ts +10 -0
  48. package/src/adapters/sentry/baseline.ts +90 -0
  49. package/src/adapters/sentry/client.ts +17 -0
  50. package/src/adapters/sentry/init.ts +17 -0
  51. package/src/authz/app-exemptions.ts +226 -0
  52. package/src/authz/authorize.ts +214 -0
  53. package/src/authz/route-policy.ts +153 -0
  54. package/src/authz/route-scan.ts +1516 -0
  55. package/src/components/agreements/acceptances-section.tsx +55 -0
  56. package/src/components/agreements/agreement-advisory-banner.tsx +33 -0
  57. package/src/components/agreements/agreement-body.tsx +34 -0
  58. package/src/components/agreements/agreement-gate.tsx +45 -0
  59. package/src/components/app-header.tsx +45 -0
  60. package/src/components/auth/accept-invite-screen.tsx +126 -0
  61. package/src/components/auth/auth-icons.tsx +68 -0
  62. package/src/components/auth/org-switcher.tsx +76 -0
  63. package/src/components/auth/people-picker.tsx +50 -0
  64. package/src/components/auth/preview-row.tsx +64 -0
  65. package/src/components/auth/sign-in-screen.tsx +24 -0
  66. package/src/components/auth/user-menu.tsx +64 -0
  67. package/src/components/demo-badge.tsx +20 -0
  68. package/src/components/demo-banner.tsx +14 -0
  69. package/src/components/gates/gate-interstitial.tsx +23 -0
  70. package/src/components/job-timeline.tsx +64 -0
  71. package/src/components/notifications/notification-bell.tsx +120 -0
  72. package/src/components/notifications/notification-prefs-section.tsx +112 -0
  73. package/src/components/org-screen.tsx +197 -0
  74. package/src/components/profile-screen.tsx +100 -0
  75. package/src/components/simulator/actor-runtime.ts +180 -0
  76. package/src/components/simulator/actor-shell.tsx +275 -0
  77. package/src/components/simulator/actors-app.tsx +119 -0
  78. package/src/components/simulator/errors-app.tsx +84 -0
  79. package/src/components/simulator/events-app.tsx +210 -0
  80. package/src/components/simulator/format-when.ts +20 -0
  81. package/src/components/simulator/hooks-app.tsx +319 -0
  82. package/src/components/simulator/inbound-app.tsx +210 -0
  83. package/src/components/simulator/jobs-app.tsx +471 -0
  84. package/src/components/simulator/mail-app.tsx +290 -0
  85. package/src/components/simulator/messages-app.tsx +64 -0
  86. package/src/components/simulator/people-app.tsx +140 -0
  87. package/src/components/simulator/people-dimensions.ts +16 -0
  88. package/src/components/simulator/simulator-panel.tsx +716 -0
  89. package/src/components/simulator/snapshots-app.tsx +398 -0
  90. package/src/components/simulator/tab-mount.ts +25 -0
  91. package/src/components/simulator/tours-app.tsx +105 -0
  92. package/src/components/webhook-endpoints-card.tsx +172 -0
  93. package/src/core/abilities.ts +459 -0
  94. package/src/core/agreements.ts +139 -0
  95. package/src/core/gates.ts +157 -0
  96. package/src/core/greeting.ts +11 -0
  97. package/src/core/inbound-email.ts +129 -0
  98. package/src/core/jobs.ts +51 -0
  99. package/src/core/keyset.ts +227 -0
  100. package/src/core/llm-models.ts +10 -0
  101. package/src/core/locale.ts +3 -0
  102. package/src/core/notifications.ts +182 -0
  103. package/src/core/presets.ts +456 -0
  104. package/src/core/roles.ts +47 -0
  105. package/src/core/schedules.ts +147 -0
  106. package/src/core/standard-schema.ts +56 -0
  107. package/src/core/state-machine.ts +43 -0
  108. package/src/core/webhook-events.ts +86 -0
  109. package/src/core/webhook-hmac.ts +248 -0
  110. package/src/core/webhook-signing.ts +27 -0
  111. package/src/cutover/rows.json +101 -0
  112. package/src/db/agreements.ts +176 -0
  113. package/src/db/app-roles.ts +197 -0
  114. package/src/db/audit.ts +356 -0
  115. package/src/db/inbound-email.ts +145 -0
  116. package/src/db/jobs.ts +300 -0
  117. package/src/db/jsonb.ts +18 -0
  118. package/src/db/keyset.ts +179 -0
  119. package/src/db/migrate.ts +73 -0
  120. package/src/db/migrations/0001_tenants.ts +25 -0
  121. package/src/db/migrations/0003_organizations.ts +27 -0
  122. package/src/db/migrations/0004_jobs.ts +64 -0
  123. package/src/db/migrations/0005_service_keys.ts +33 -0
  124. package/src/db/migrations/0008_audit_events.ts +51 -0
  125. package/src/db/migrations/0009_job_schedules.ts +52 -0
  126. package/src/db/migrations/0010_webhooks.ts +100 -0
  127. package/src/db/migrations/0011_notifications.ts +98 -0
  128. package/src/db/migrations/0012_inbound_email.ts +74 -0
  129. package/src/db/migrations/0013_agreements.ts +98 -0
  130. package/src/db/migrations/0014_audit_credential.ts +29 -0
  131. package/src/db/migrations/0015_app_user_grant.ts +67 -0
  132. package/src/db/migrations/0016_audit_detail.ts +26 -0
  133. package/src/db/migrations/index.ts +49 -0
  134. package/src/db/notifications.ts +185 -0
  135. package/src/db/org-lookup.ts +104 -0
  136. package/src/db/owner-pass.ts +252 -0
  137. package/src/db/rls-coverage.ts +259 -0
  138. package/src/db/rls-proof-runner.ts +94 -0
  139. package/src/db/rls-proofs.ts +1176 -0
  140. package/src/db/schedules.ts +187 -0
  141. package/src/db/schema.ts +235 -0
  142. package/src/db/seed.ts +176 -0
  143. package/src/db/service-keys.ts +50 -0
  144. package/src/db/tenant-lookup.ts +13 -0
  145. package/src/db/webhooks.ts +483 -0
  146. package/src/db/with-tenant.ts +26 -0
  147. package/src/demo-static/actor-drivers.ts +161 -0
  148. package/src/demo-static/assistant-replay.ts +61 -0
  149. package/src/demo-static/contracts.ts +282 -0
  150. package/src/demo-static/email-html.ts +58 -0
  151. package/src/demo-static/hash-route.ts +24 -0
  152. package/src/demo-static/rows.ts +105 -0
  153. package/src/demo-static/shell.tsx +440 -0
  154. package/src/demo-static/tour/contracts.ts +97 -0
  155. package/src/demo-static/tour/driver.ts +320 -0
  156. package/src/demo-static/tour/tour-overlay.tsx +226 -0
  157. package/src/demo-static/tour/use-tours.tsx +394 -0
  158. package/src/demo-static/world.ts +1479 -0
  159. package/src/email/send.ts +12 -0
  160. package/src/email/templates/digest-email.tsx +61 -0
  161. package/src/email/templates/invite-email.tsx +57 -0
  162. package/src/email/templates/notification-email.tsx +39 -0
  163. package/src/guide.md +118 -0
  164. package/src/i18n/messages/en.json +373 -0
  165. package/src/i18n/messages/es.json +373 -0
  166. package/src/i18n/messages.ts +34 -0
  167. package/src/i18n/namespaces.ts +32 -0
  168. package/src/i18n/request.ts +34 -0
  169. package/src/i18n/routing.ts +7 -0
  170. package/src/inbound-email/handlers.ts +67 -0
  171. package/src/inbound-email/intake.ts +180 -0
  172. package/src/jobs/digest-email.ts +97 -0
  173. package/src/observability/scrub.ts +42 -0
  174. package/src/ports/README.md +8 -0
  175. package/src/ports/analytics.ts +8 -0
  176. package/src/ports/auth.ts +87 -0
  177. package/src/ports/db.ts +27 -0
  178. package/src/ports/email.ts +14 -0
  179. package/src/ports/errors.ts +46 -0
  180. package/src/ports/jobs.ts +48 -0
  181. package/src/ports/llm.ts +85 -0
  182. package/src/ports/storage.ts +132 -0
  183. package/src/seed/contracts.ts +129 -0
  184. package/src/server-lib/assistant.ts +45 -0
  185. package/src/server-lib/defer.ts +53 -0
  186. package/src/server-lib/demo-presets.ts +85 -0
  187. package/src/server-lib/invite.ts +92 -0
  188. package/src/server-lib/notify-deps.ts +15 -0
  189. package/src/server-lib/notify.ts +252 -0
  190. package/src/server-lib/preset-operations.ts +121 -0
  191. package/src/server-lib/scheduled-tick.ts +38 -0
  192. package/src/server-lib/sms.ts +43 -0
  193. package/src/server-lib/webhook-dispatch.ts +75 -0
  194. package/src/service-auth/mailgun.ts +70 -0
  195. package/src/service-auth/verify.ts +73 -0
  196. package/src/service-auth/webhook.ts +60 -0
  197. package/src/testing/checks.json +103 -0
  198. package/src/testing/conformance/authz.ts +46 -0
  199. package/src/testing/conformance/db.ts +258 -0
  200. package/src/testing/conformance/demo-presets.ts +295 -0
  201. package/src/testing/conformance/i18n.ts +80 -0
  202. package/src/testing/conformance/register.ts +200 -0
  203. package/src/testing/conformance/seam-map.ts +205 -0
  204. package/src/testing/conformance/suite.ts +59 -0
  205. package/src/testing/conformance/types.ts +18 -0
  206. package/src/testing/contract.ts +200 -0
  207. package/src/testing/e2e.ts +15 -0
  208. package/src/testing/index.ts +6 -0
  209. package/src/testing/seam-specifiers.json +22 -0
  210. package/src/testing/tmp-dir-marker.d.mts +4 -0
  211. package/src/testing/tmp-dir-marker.mjs +5 -0
  212. package/src/testing/tmp-dir.ts +182 -0
  213. package/src/theme.ts +28 -0
  214. package/README.md +0 -3
@@ -0,0 +1,55 @@
1
+ import { Card, Group, Stack, Text, Title } from '@mantine/core'
2
+ import { useTranslations } from 'next-intl'
3
+
4
+ /** One accepted-agreement row for the profile list (structurally matches packages/kit/src/db/agreements
5
+ * AcceptanceRecord; declared here so this shared component doesn't import a server module). */
6
+ export interface AcceptanceItem {
7
+ agreementId: string
8
+ title: string
9
+ kind: string
10
+ version: number
11
+ acceptedAt: string
12
+ }
13
+
14
+ /**
15
+ * Profile "Agreements you've accepted" section — a read-only record of which agreements and
16
+ * versions the user accepted, and when. Router-agnostic and presentational; the real app feeds it from
17
+ * the DB (server-rendered), the static twin from its in-memory acceptances. Empty state included so the
18
+ * section is honest when nothing has been accepted yet.
19
+ */
20
+ export function AcceptancesSection({ acceptances }: { acceptances: AcceptanceItem[] }) {
21
+ const t = useTranslations('agreements')
22
+ return (
23
+ <Card withBorder padding="lg" radius="md" data-testid="acceptances-section">
24
+ <Title order={2} size="h3" mb="md">
25
+ {t('acceptancesTitle')}
26
+ </Title>
27
+ {acceptances.length === 0 ? (
28
+ <Text c="gray.7" size="sm" data-testid="acceptances-empty">
29
+ {t('acceptancesEmpty')}
30
+ </Text>
31
+ ) : (
32
+ <Stack gap="sm">
33
+ {acceptances.map((acceptance) => (
34
+ <Group
35
+ key={`${acceptance.agreementId}-${acceptance.version}-${acceptance.acceptedAt}`}
36
+ justify="space-between"
37
+ wrap="nowrap"
38
+ data-testid="acceptance-row"
39
+ >
40
+ <Text size="sm" fw={500}>
41
+ {acceptance.title}
42
+ </Text>
43
+ <Text size="xs" c="gray.7" style={{ whiteSpace: 'nowrap' }}>
44
+ {t('acceptanceMeta', {
45
+ version: acceptance.version,
46
+ date: acceptance.acceptedAt.slice(0, 10),
47
+ })}
48
+ </Text>
49
+ </Group>
50
+ ))}
51
+ </Stack>
52
+ )}
53
+ </Card>
54
+ )
55
+ }
@@ -0,0 +1,33 @@
1
+ 'use client'
2
+
3
+ import { Alert } from '@mantine/core'
4
+ import { useTranslations } from 'next-intl'
5
+ import { useState } from 'react'
6
+ import type { PendingAgreement } from '../../core/agreements'
7
+
8
+ /**
9
+ * Advisory agreement banner: the non-blocking half of the gate seam. Where a blocking
10
+ * agreement renders the full interstitial instead of the app, an ADVISORY one passes through and shows
11
+ * this dismissible banner above the app (the demo-banner precedent) — the actor may proceed. Dismiss is
12
+ * local (session) state; it reappears on a full reload, which is the right posture for an advisory
13
+ * notice. Lists the pending advisory agreement titles (world content, passed as a param).
14
+ */
15
+ export function AgreementAdvisoryBanner({ agreements }: { agreements: PendingAgreement[] }) {
16
+ const t = useTranslations('agreements')
17
+ const [dismissed, setDismissed] = useState(false)
18
+ if (dismissed || agreements.length === 0) return null
19
+ const titles = agreements.map((agreement) => agreement.title).join(', ')
20
+ return (
21
+ <Alert
22
+ variant="light"
23
+ color="yellow"
24
+ radius={0}
25
+ withCloseButton
26
+ closeButtonLabel={t('advisoryDismiss')}
27
+ onClose={() => setDismissed(true)}
28
+ data-testid="agreement-advisory-banner"
29
+ >
30
+ {t('advisoryBanner', { titles })}
31
+ </Alert>
32
+ )
33
+ }
@@ -0,0 +1,34 @@
1
+ import { Box, Stack, Text } from '@mantine/core'
2
+
3
+ /**
4
+ * "Rendered simply" markdown for an agreement body — deliberately NO markdown dependency
5
+ * (rich text is a recorded non-gap; the single-file demo budget guards new deps). Splits on blank
6
+ * lines into blocks; a leading `#…` line renders as a bold heading, everything else as a paragraph with
7
+ * whitespace preserved. The text is world CONTENT (like a note body), not UI copy, so it is not i18n'd.
8
+ */
9
+ export function AgreementBody({ bodyMd }: { bodyMd: string }) {
10
+ const blocks = bodyMd.split(/\n{2,}/).filter((block) => block.trim().length > 0)
11
+ return (
12
+ <Box
13
+ data-testid="agreement-body"
14
+ style={{ maxHeight: 320, overflowY: 'auto' }}
15
+ p="sm"
16
+ bd="1px solid var(--mantine-color-gray-3)"
17
+ >
18
+ <Stack gap="sm">
19
+ {blocks.map((block, index) => {
20
+ const heading = /^#{1,6}\s+(.*)$/.exec(block.trim())
21
+ return heading ? (
22
+ <Text key={`${index}-h`} fw={700} size="md">
23
+ {heading[1]}
24
+ </Text>
25
+ ) : (
26
+ <Text key={`${index}-p`} size="sm" style={{ whiteSpace: 'pre-wrap' }}>
27
+ {block}
28
+ </Text>
29
+ )
30
+ })}
31
+ </Stack>
32
+ </Box>
33
+ )
34
+ }
@@ -0,0 +1,45 @@
1
+ 'use client'
2
+
3
+ import { Button, Stack, Text } from '@mantine/core'
4
+ import { useTranslations } from 'next-intl'
5
+ import { useState } from 'react'
6
+ import type { PendingAgreement } from '../../core/agreements'
7
+ import { GateInterstitial } from '../gates/gate-interstitial'
8
+ import { AgreementBody } from './agreement-body'
9
+
10
+ /**
11
+ * The agreements worked example filling the generic gate interstitial: the pending
12
+ * agreement's title + body, and the one action that resolves it — Accept. Router-agnostic and
13
+ * presentational; `onAccept` is supplied by the host (the protected-layout glue POSTs + reloads; the
14
+ * static twin records in memory). One agreement at a time — the layout re-evaluates after each accept,
15
+ * so a second pending block agreement simply appears next.
16
+ */
17
+ export function AgreementGate({ agreement, onAccept }: { agreement: PendingAgreement; onAccept: () => Promise<void> }) {
18
+ const t = useTranslations('agreements')
19
+ const [busy, setBusy] = useState(false)
20
+
21
+ return (
22
+ <GateInterstitial title={t('gateTitle')}>
23
+ <Stack gap="md" data-testid="agreement-gate">
24
+ <Text fw={600} size="lg">
25
+ {agreement.title}
26
+ </Text>
27
+ <Text c="gray.7" size="sm">
28
+ {t('gateLead')}
29
+ </Text>
30
+ <AgreementBody bodyMd={agreement.bodyMd} />
31
+ <Button
32
+ data-testid="agreement-accept"
33
+ loading={busy}
34
+ onClick={() => {
35
+ setBusy(true)
36
+ void onAccept().finally(() => setBusy(false))
37
+ }}
38
+ style={{ alignSelf: 'start' }}
39
+ >
40
+ {t('acceptButton')}
41
+ </Button>
42
+ </Stack>
43
+ </GateInterstitial>
44
+ )
45
+ }
@@ -0,0 +1,45 @@
1
+ 'use client'
2
+
3
+ import { Group, Text } from '@mantine/core'
4
+ import type { ReactNode } from 'react'
5
+
6
+ /** Shell header for signed-in pages: app name left, notification bell + tenant switcher + user menu right. */
7
+ export function AppHeader({
8
+ tenantName,
9
+ controls,
10
+ nav,
11
+ bell,
12
+ appName,
13
+ }: {
14
+ tenantName: string
15
+ controls: ReactNode
16
+ nav?: ReactNode
17
+ bell?: ReactNode
18
+ /**
19
+ * The product's display name — REQUIRED, and supplied by the app from its own catalog (the
20
+ * `welcome.appName` convention both apps here follow).
21
+ *
22
+ * REQUIRED rather than optional, deliberately. One shared framework catalog cannot name two
23
+ * products, so any fallback key here would hold whichever app was written first and render it
24
+ * for every other app — silently, because a default that resolves is indistinguishable from a
25
+ * default that is right. Requiring the prop moves that from a sentence in a docstring to
26
+ * something the compiler checks (ADR-0012, docs/adopting.md).
27
+ */
28
+ appName: ReactNode
29
+ }) {
30
+ return (
31
+ <Group component="header" justify="space-between" px="md" py="xs" bg="gray.0">
32
+ <Group gap="xs">
33
+ <Text fw={700}>{appName}</Text>
34
+ <Text size="sm" c="gray.7" data-testid="active-tenant">
35
+ {tenantName}
36
+ </Text>
37
+ {nav}
38
+ </Group>
39
+ <Group gap="sm">
40
+ {bell}
41
+ {controls}
42
+ </Group>
43
+ </Group>
44
+ )
45
+ }
@@ -0,0 +1,126 @@
1
+ 'use client'
2
+
3
+ import { Button, Card, Container, Stack, Text, TextInput, Title } from '@mantine/core'
4
+ import { useForm } from '@mantine/form'
5
+ import { useTranslations } from 'next-intl'
6
+ import type { ReactNode } from 'react'
7
+ import { useState } from 'react'
8
+
9
+ /**
10
+ * Shared shell for every accept-invite state — the fake name-form flow below AND the real
11
+ * Clerk-ticket flow (whose form slots in from packages/kit/src/adapters/real/accept-invite-form.tsx). One
12
+ * auth UI in every mode (ADR-0003), same as SignInScreen wrapping RealSignInForm.
13
+ */
14
+ export function AcceptInviteShell({
15
+ title,
16
+ lead,
17
+ body,
18
+ testId,
19
+ }: {
20
+ title: string
21
+ lead?: ReactNode
22
+ body: ReactNode
23
+ testId?: string
24
+ }) {
25
+ return (
26
+ <Container component="main" size="xs" py="xl" data-testid={testId}>
27
+ <Stack gap="md">
28
+ <Title order={1}>{title}</Title>
29
+ {lead}
30
+ <Card withBorder padding="lg" radius="md">
31
+ {body}
32
+ </Card>
33
+ </Stack>
34
+ </Container>
35
+ )
36
+ }
37
+
38
+ interface AcceptInviteValidState {
39
+ kind: 'valid'
40
+ inviteId: string
41
+ orgName: string
42
+ role: string
43
+ email: string
44
+ }
45
+
46
+ interface AcceptInviteInvalidState {
47
+ kind: 'invalid'
48
+ }
49
+
50
+ export type AcceptInviteState = AcceptInviteValidState | AcceptInviteInvalidState
51
+
52
+ /**
53
+ * Router-agnostic accept-invitation screen (ADR-0006 twin lives in @sssb/kit/demo-static): the real
54
+ * product surface the invite email's accept link lands on. `valid` shows who's being invited into
55
+ * which tenant, as what role, and collects the one field a brand-new person can supply — their
56
+ * name; `invalid` covers an unknown or already-consumed invite id, with a way back to sign-in.
57
+ */
58
+ export function AcceptInviteScreen({
59
+ state,
60
+ error,
61
+ onAccept,
62
+ onSignIn,
63
+ }: {
64
+ state: AcceptInviteState
65
+ error?: string | null
66
+ onAccept: (values: { name: string }) => Promise<void>
67
+ onSignIn: () => void
68
+ }) {
69
+ const t = useTranslations('acceptInvite')
70
+ const [busy, setBusy] = useState(false)
71
+ const form = useForm({
72
+ initialValues: { name: '' },
73
+ validate: { name: (value) => (value.trim() ? null : t('nameRequired')) },
74
+ })
75
+
76
+ if (state.kind === 'invalid') {
77
+ return (
78
+ <AcceptInviteShell
79
+ title={t('invalidTitle')}
80
+ testId="accept-invalid"
81
+ body={
82
+ <Stack gap="sm">
83
+ <Text c="gray.7">{t('invalidBody')}</Text>
84
+ <Button variant="subtle" onClick={onSignIn} data-testid="accept-signin-link">
85
+ {t('backToSignIn')}
86
+ </Button>
87
+ </Stack>
88
+ }
89
+ />
90
+ )
91
+ }
92
+
93
+ return (
94
+ <AcceptInviteShell
95
+ title={t('title', { org: state.orgName })}
96
+ lead={<Text c="gray.7">{t('subtitle', { role: state.role, email: state.email })}</Text>}
97
+ body={
98
+ <form
99
+ onSubmit={form.onSubmit((values) => {
100
+ setBusy(true)
101
+ onAccept({ name: values.name }).finally(() => setBusy(false))
102
+ })}
103
+ >
104
+ <Stack>
105
+ <TextInput
106
+ label={t('nameLabel')}
107
+ data-testid="accept-name"
108
+ required
109
+ {...form.getInputProps('name')}
110
+ />
111
+ <Button type="submit" loading={busy} data-testid="accept-submit">
112
+ {t('acceptButton')}
113
+ </Button>
114
+ {/* Clickwrap notice: joining ALSO records acceptance of the tenant's
115
+ current agreements, so the assent being manifested must be disclosed here —
116
+ an acceptance record without notice is not real clickwrap. */}
117
+ <Text size="xs" c="gray.7" data-testid="accept-agreements-notice">
118
+ {t('agreementsNotice')}
119
+ </Text>
120
+ {error ? <Text c="red.8">{error}</Text> : null}
121
+ </Stack>
122
+ </form>
123
+ }
124
+ />
125
+ )
126
+ }
@@ -0,0 +1,68 @@
1
+ import type { ReactNode } from 'react'
2
+
3
+ /**
4
+ * Tiny inline stroke icons (Lucide-style paths, MIT) for the auth surfaces. Inline rather than a
5
+ * dependency so the single-file demo stays inside its size budget and dev stays hermetic; they
6
+ * inherit `currentColor` and are aria-hidden (the surrounding control carries the label).
7
+ */
8
+ function Glyph({ children, size = 16 }: { children: ReactNode; size?: number }) {
9
+ return (
10
+ <svg
11
+ width={size}
12
+ height={size}
13
+ viewBox="0 0 24 24"
14
+ fill="none"
15
+ stroke="currentColor"
16
+ strokeWidth={2}
17
+ strokeLinecap="round"
18
+ strokeLinejoin="round"
19
+ aria-hidden="true"
20
+ >
21
+ {children}
22
+ </svg>
23
+ )
24
+ }
25
+
26
+ export function ChevronDownIcon() {
27
+ return (
28
+ <Glyph>
29
+ <path d="m6 9 6 6 6-6" />
30
+ </Glyph>
31
+ )
32
+ }
33
+
34
+ export function CheckIcon() {
35
+ return (
36
+ <Glyph>
37
+ <path d="M20 6 9 17l-5-5" />
38
+ </Glyph>
39
+ )
40
+ }
41
+
42
+ export function UserIcon() {
43
+ return (
44
+ <Glyph>
45
+ <path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2" />
46
+ <circle cx="12" cy="7" r="4" />
47
+ </Glyph>
48
+ )
49
+ }
50
+
51
+ export function SignOutIcon() {
52
+ return (
53
+ <Glyph>
54
+ <path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4" />
55
+ <path d="m16 17 5-5-5-5" />
56
+ <path d="M21 12H9" />
57
+ </Glyph>
58
+ )
59
+ }
60
+
61
+ export function BellIcon() {
62
+ return (
63
+ <Glyph size={20}>
64
+ <path d="M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9" />
65
+ <path d="M10.3 21a1.94 1.94 0 0 0 3.4 0" />
66
+ </Glyph>
67
+ )
68
+ }
@@ -0,0 +1,76 @@
1
+ 'use client'
2
+
3
+ import { Group, Menu, UnstyledButton, VisuallyHidden } from '@mantine/core'
4
+ import { useTranslations } from 'next-intl'
5
+ import { CheckIcon, ChevronDownIcon } from './auth-icons'
6
+ import { PreviewRow } from './preview-row'
7
+
8
+ export interface SwitcherOrg {
9
+ slug: string
10
+ name: string
11
+ /** The user's role in this org — shown as the popover sub-line (optional; omitted in the twin). */
12
+ role?: string
13
+ }
14
+
15
+ /**
16
+ * Lean take on Clerk's OrganizationSwitcher (ADR-0003): the trigger is the active org as a preview
17
+ * row + chevron; the popover lists every membership as a preview row (role sub-line, active check).
18
+ * Hidden when the user belongs to a single org — there's nothing to switch.
19
+ */
20
+ export function OrgSwitcher({
21
+ orgs,
22
+ activeSlug,
23
+ onSwitch,
24
+ }: {
25
+ orgs: SwitcherOrg[]
26
+ activeSlug: string
27
+ onSwitch: (slug: string) => void
28
+ }) {
29
+ const t = useTranslations('org')
30
+ if (orgs.length <= 1) return null
31
+ const active = orgs.find((o) => o.slug === activeSlug) ?? orgs[0]
32
+ if (!active) return null
33
+
34
+ return (
35
+ <Menu position="bottom-end" width={264} withinPortal>
36
+ <Menu.Target>
37
+ {/* Named by its content, never an aria-label (WCAG 2.5.3 Label in Name): the name is the
38
+ team name the button shows, then a visually hidden ", switch team". The avatar's
39
+ initials are aria-hidden (PreviewRow): they are a symbol, like a "B" on a Bold
40
+ button, not the label. An aria-label would have to repeat them, since axe 4.14
41
+ compares one with every word on screen. */}
42
+ <UnstyledButton
43
+ data-testid="org-switcher"
44
+ style={{
45
+ maxWidth: 220,
46
+ padding: '4px 8px',
47
+ borderRadius: 'var(--mantine-radius-default)',
48
+ border: '1px solid var(--mantine-color-gray-3)',
49
+ }}
50
+ >
51
+ <Group gap="xs" wrap="nowrap" style={{ minWidth: 0 }}>
52
+ <PreviewRow name={active.name} title={active.name} size="sm" />
53
+ <ChevronDownIcon />
54
+ </Group>
55
+ <VisuallyHidden>{t('switchTriggerSuffix')}</VisuallyHidden>
56
+ </UnstyledButton>
57
+ </Menu.Target>
58
+ <Menu.Dropdown>
59
+ {/* Mantine's default Menu.Label color is `dimmed` (gray-6, ~2.7:1) — bump to gray.7 for AA. */}
60
+ <Menu.Label c="gray.7">{t('switchLabel')}</Menu.Label>
61
+ {orgs.map((org) => (
62
+ <Menu.Item
63
+ key={org.slug}
64
+ data-testid={`org-switcher-item-${org.slug}`}
65
+ onClick={() => {
66
+ if (org.slug !== activeSlug) onSwitch(org.slug)
67
+ }}
68
+ rightSection={org.slug === active.slug ? <CheckIcon /> : undefined}
69
+ >
70
+ <PreviewRow name={org.name} title={org.name} subtitle={org.role} size="sm" />
71
+ </Menu.Item>
72
+ ))}
73
+ </Menu.Dropdown>
74
+ </Menu>
75
+ )
76
+ }
@@ -0,0 +1,50 @@
1
+ 'use client'
2
+
3
+ import { Button, Stack, Text } from '@mantine/core'
4
+ import { useTranslations } from 'next-intl'
5
+ import { useState } from 'react'
6
+
7
+ export interface PickerPerson {
8
+ id: string
9
+ name: string
10
+ role: string
11
+ tenantName: string
12
+ }
13
+
14
+ /**
15
+ * Simulated-mode sign-in: the same card layout the real credential form uses, listing seeded
16
+ * people. One auth UI in every mode (ADR-0003).
17
+ */
18
+ export function PeoplePicker({ people, onPick }: { people: PickerPerson[]; onPick: (id: string) => void }) {
19
+ const t = useTranslations('auth')
20
+ const [busy, setBusy] = useState<string | null>(null)
21
+
22
+ return (
23
+ <Stack gap="sm">
24
+ <Text size="sm" c="gray.7">
25
+ {t('personHint')}
26
+ </Text>
27
+ {people.map((person) => (
28
+ <Button
29
+ key={person.id}
30
+ variant="light"
31
+ justify="space-between"
32
+ fullWidth
33
+ loading={busy === person.id}
34
+ data-testid={`person-${person.id}`}
35
+ rightSection={
36
+ <Text size="xs" c="gray.7">
37
+ {t('personMeta', { role: person.role, tenant: person.tenantName })}
38
+ </Text>
39
+ }
40
+ onClick={() => {
41
+ setBusy(person.id)
42
+ onPick(person.id)
43
+ }}
44
+ >
45
+ {person.name}
46
+ </Button>
47
+ ))}
48
+ </Stack>
49
+ )
50
+ }
@@ -0,0 +1,64 @@
1
+ 'use client'
2
+
3
+ import { Avatar, Group, Stack, Text } from '@mantine/core'
4
+ import type { ReactNode } from 'react'
5
+
6
+ // Avatars are a dark filled neutral (white initials on near-black): the hash-colored
7
+ // `color="initials"` variants — and even Mantine's default gray placeholder — land at ~3.7–4.4:1 for
8
+ // many hue+initials combinations and can't clear WCAG AA reliably (autoContrast's threshold doesn't
9
+ // align with 4.5:1 either). White-on-dark is ~15:1 for any initials. See docs/build-notes.md.
10
+
11
+ /**
12
+ * The one identity row behind both the OrgSwitcher and the UserMenu — an initials avatar plus a
13
+ * stacked title / subtitle, truncation-safe. Clerk composes its OrganizationPreview and UserPreview
14
+ * from a single such element; we do the same in Mantine (ADR-0003, one owned auth UI).
15
+ */
16
+ export function PreviewRow({
17
+ name,
18
+ title,
19
+ subtitle,
20
+ badge,
21
+ rounded = false,
22
+ size = 'md',
23
+ }: {
24
+ /** Seeds the initials avatar (org name or person name). */
25
+ name: string
26
+ title: string
27
+ subtitle?: ReactNode
28
+ badge?: ReactNode
29
+ /** Round avatar for people, squared for orgs (mirrors Clerk's org-vs-user distinction). */
30
+ rounded?: boolean
31
+ size?: 'sm' | 'md'
32
+ }) {
33
+ const dim = size === 'sm' ? 30 : 38
34
+ return (
35
+ <Group gap="sm" wrap="nowrap" style={{ minWidth: 0 }}>
36
+ <Avatar
37
+ name={name}
38
+ radius={rounded ? 'xl' : 'sm'}
39
+ size={dim}
40
+ // Decorative: the title beside it already says the name, so assistive tech skips the
41
+ // initials rather than read "DO Dana Okoye".
42
+ aria-hidden
43
+ styles={{
44
+ placeholder: { color: '#fff', background: 'var(--mantine-color-dark-6)' },
45
+ }}
46
+ />
47
+ <Stack gap={2} style={{ minWidth: 0 }}>
48
+ <Group gap={6} wrap="nowrap" style={{ minWidth: 0 }}>
49
+ {/* Explicit dark color: inside Mantine's Menu.Label (user menu header) an
50
+ uncolored Text would inherit the label's dimmed gray-6 (~3.3:1, fails AA). */}
51
+ <Text size="sm" fw={600} truncate c="gray.9">
52
+ {title}
53
+ </Text>
54
+ {badge}
55
+ </Group>
56
+ {subtitle != null ? (
57
+ <Text size="xs" c="gray.7" truncate component="div">
58
+ {subtitle}
59
+ </Text>
60
+ ) : null}
61
+ </Stack>
62
+ </Group>
63
+ )
64
+ }
@@ -0,0 +1,24 @@
1
+ 'use client'
2
+
3
+ import { Card, Container, Stack, Text, Title } from '@mantine/core'
4
+ import { useTranslations } from 'next-intl'
5
+ import type { ReactNode } from 'react'
6
+
7
+ /**
8
+ * The single sign-in surface (ADR-0003). In simulated mode `body` is the PeoplePicker; in real mode
9
+ * it is the Clerk-headless credential form injected by the route glue. Same card either way.
10
+ */
11
+ export function SignInScreen({ body }: { body: ReactNode }) {
12
+ const t = useTranslations('auth')
13
+ return (
14
+ <Container component="main" size="xs" py="xl">
15
+ <Stack gap="md">
16
+ <Title order={1}>{t('signInTitle')}</Title>
17
+ <Text c="gray.7">{t('signInSubtitle')}</Text>
18
+ <Card withBorder padding="lg" radius="md">
19
+ {body}
20
+ </Card>
21
+ </Stack>
22
+ </Container>
23
+ )
24
+ }