@sssb/kit 0.0.0 → 0.3.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 (227) 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 +212 -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 +313 -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 +248 -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 +93 -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 +142 -0
  28. package/src/adapters/lazy-jobs.ts +25 -0
  29. package/src/adapters/proxy.ts +34 -0
  30. package/src/adapters/real/absent.ts +41 -0
  31. package/src/adapters/real/accept-invite-form.tsx +77 -0
  32. package/src/adapters/real/analytics.ts +28 -0
  33. package/src/adapters/real/auth.ts +216 -0
  34. package/src/adapters/real/clerk-proxy.ts +111 -0
  35. package/src/adapters/real/contract-data-api.ts +104 -0
  36. package/src/adapters/real/contract-postgres.ts +167 -0
  37. package/src/adapters/real/database-transport.ts +34 -0
  38. package/src/adapters/real/db-data-api.ts +61 -0
  39. package/src/adapters/real/db-port.ts +26 -0
  40. package/src/adapters/real/db.ts +69 -0
  41. package/src/adapters/real/email.ts +22 -0
  42. package/src/adapters/real/index.ts +139 -0
  43. package/src/adapters/real/jobs-in-process.ts +118 -0
  44. package/src/adapters/real/jobs.ts +33 -0
  45. package/src/adapters/real/llm.ts +108 -0
  46. package/src/adapters/real/migrate-handler.ts +66 -0
  47. package/src/adapters/real/optional-ports.ts +78 -0
  48. package/src/adapters/real/providers.tsx +12 -0
  49. package/src/adapters/real/rds-data-codec.ts +508 -0
  50. package/src/adapters/real/rds-data-dialect.ts +470 -0
  51. package/src/adapters/real/rds-data-emulator.ts +351 -0
  52. package/src/adapters/real/s3-storage.ts +233 -0
  53. package/src/adapters/real/sign-in-form.tsx +59 -0
  54. package/src/adapters/real/storage.ts +10 -0
  55. package/src/adapters/run-mode.ts +11 -0
  56. package/src/adapters/sentry/baseline.ts +90 -0
  57. package/src/adapters/sentry/client.ts +17 -0
  58. package/src/adapters/sentry/init.ts +17 -0
  59. package/src/authz/app-exemptions.ts +226 -0
  60. package/src/authz/authorize.ts +214 -0
  61. package/src/authz/route-policy.ts +153 -0
  62. package/src/authz/route-scan.ts +1516 -0
  63. package/src/components/agreements/acceptances-section.tsx +55 -0
  64. package/src/components/agreements/agreement-advisory-banner.tsx +33 -0
  65. package/src/components/agreements/agreement-body.tsx +34 -0
  66. package/src/components/agreements/agreement-gate.tsx +45 -0
  67. package/src/components/app-header.tsx +45 -0
  68. package/src/components/auth/accept-invite-screen.tsx +126 -0
  69. package/src/components/auth/auth-icons.tsx +68 -0
  70. package/src/components/auth/org-switcher.tsx +76 -0
  71. package/src/components/auth/people-picker.tsx +50 -0
  72. package/src/components/auth/preview-row.tsx +64 -0
  73. package/src/components/auth/sign-in-screen.tsx +24 -0
  74. package/src/components/auth/user-menu.tsx +64 -0
  75. package/src/components/demo-badge.tsx +20 -0
  76. package/src/components/demo-banner.tsx +14 -0
  77. package/src/components/gates/gate-interstitial.tsx +23 -0
  78. package/src/components/job-timeline.tsx +64 -0
  79. package/src/components/notifications/notification-bell.tsx +120 -0
  80. package/src/components/notifications/notification-prefs-section.tsx +112 -0
  81. package/src/components/org-screen.tsx +197 -0
  82. package/src/components/profile-screen.tsx +100 -0
  83. package/src/components/simulator/actor-runtime.ts +180 -0
  84. package/src/components/simulator/actor-shell.tsx +275 -0
  85. package/src/components/simulator/actors-app.tsx +119 -0
  86. package/src/components/simulator/errors-app.tsx +84 -0
  87. package/src/components/simulator/events-app.tsx +210 -0
  88. package/src/components/simulator/format-when.ts +20 -0
  89. package/src/components/simulator/hooks-app.tsx +319 -0
  90. package/src/components/simulator/inbound-app.tsx +210 -0
  91. package/src/components/simulator/jobs-app.tsx +471 -0
  92. package/src/components/simulator/mail-app.tsx +290 -0
  93. package/src/components/simulator/messages-app.tsx +64 -0
  94. package/src/components/simulator/people-app.tsx +140 -0
  95. package/src/components/simulator/people-dimensions.ts +16 -0
  96. package/src/components/simulator/simulator-host.tsx +335 -0
  97. package/src/components/simulator/simulator-panel.tsx +704 -0
  98. package/src/components/simulator/snapshots-app.tsx +398 -0
  99. package/src/components/simulator/tab-mount.ts +25 -0
  100. package/src/components/simulator/tours-app.tsx +105 -0
  101. package/src/components/webhook-endpoints-card.tsx +172 -0
  102. package/src/core/abilities.ts +464 -0
  103. package/src/core/agreements.ts +139 -0
  104. package/src/core/gates.ts +157 -0
  105. package/src/core/greeting.ts +11 -0
  106. package/src/core/inbound-email.ts +129 -0
  107. package/src/core/jobs.ts +51 -0
  108. package/src/core/keyset.ts +227 -0
  109. package/src/core/llm-models.ts +10 -0
  110. package/src/core/locale.ts +3 -0
  111. package/src/core/notifications.ts +182 -0
  112. package/src/core/presets.ts +456 -0
  113. package/src/core/roles.ts +47 -0
  114. package/src/core/same-origin-path.ts +20 -0
  115. package/src/core/schedules.ts +147 -0
  116. package/src/core/standard-schema.ts +56 -0
  117. package/src/core/state-machine.ts +43 -0
  118. package/src/core/webhook-events.ts +86 -0
  119. package/src/core/webhook-hmac.ts +248 -0
  120. package/src/core/webhook-signing.ts +27 -0
  121. package/src/cutover/rows.json +101 -0
  122. package/src/db/agreements.ts +176 -0
  123. package/src/db/app-roles.ts +197 -0
  124. package/src/db/audit.ts +356 -0
  125. package/src/db/inbound-email.ts +145 -0
  126. package/src/db/jobs.ts +300 -0
  127. package/src/db/jsonb.ts +18 -0
  128. package/src/db/keyset.ts +179 -0
  129. package/src/db/migrate.ts +73 -0
  130. package/src/db/migrations/0001_tenants.ts +25 -0
  131. package/src/db/migrations/0003_organizations.ts +27 -0
  132. package/src/db/migrations/0004_jobs.ts +64 -0
  133. package/src/db/migrations/0005_service_keys.ts +33 -0
  134. package/src/db/migrations/0008_audit_events.ts +51 -0
  135. package/src/db/migrations/0009_job_schedules.ts +52 -0
  136. package/src/db/migrations/0010_webhooks.ts +100 -0
  137. package/src/db/migrations/0011_notifications.ts +98 -0
  138. package/src/db/migrations/0012_inbound_email.ts +74 -0
  139. package/src/db/migrations/0013_agreements.ts +98 -0
  140. package/src/db/migrations/0014_audit_credential.ts +29 -0
  141. package/src/db/migrations/0015_app_user_grant.ts +67 -0
  142. package/src/db/migrations/0016_audit_detail.ts +26 -0
  143. package/src/db/migrations/index.ts +49 -0
  144. package/src/db/notifications.ts +185 -0
  145. package/src/db/org-lookup.ts +104 -0
  146. package/src/db/owner-pass.ts +252 -0
  147. package/src/db/rls-coverage.ts +259 -0
  148. package/src/db/rls-proof-runner.ts +94 -0
  149. package/src/db/rls-proofs.ts +1176 -0
  150. package/src/db/schedules.ts +187 -0
  151. package/src/db/schema.ts +235 -0
  152. package/src/db/seed.ts +176 -0
  153. package/src/db/service-keys.ts +50 -0
  154. package/src/db/tenant-lookup.ts +13 -0
  155. package/src/db/webhooks.ts +483 -0
  156. package/src/db/with-tenant.ts +26 -0
  157. package/src/demo-static/actor-drivers.ts +161 -0
  158. package/src/demo-static/assistant-replay.ts +61 -0
  159. package/src/demo-static/contracts.ts +282 -0
  160. package/src/demo-static/email-html.ts +58 -0
  161. package/src/demo-static/hash-route.ts +24 -0
  162. package/src/demo-static/rows.ts +105 -0
  163. package/src/demo-static/shell.tsx +440 -0
  164. package/src/demo-static/tour/contracts.ts +97 -0
  165. package/src/demo-static/tour/driver.ts +320 -0
  166. package/src/demo-static/tour/tour-overlay.tsx +226 -0
  167. package/src/demo-static/tour/use-tours.tsx +394 -0
  168. package/src/demo-static/world.ts +1480 -0
  169. package/src/email/send.ts +12 -0
  170. package/src/email/templates/digest-email.tsx +61 -0
  171. package/src/email/templates/invite-email.tsx +57 -0
  172. package/src/email/templates/notification-email.tsx +39 -0
  173. package/src/guide.md +132 -0
  174. package/src/i18n/messages/en.json +373 -0
  175. package/src/i18n/messages/es.json +373 -0
  176. package/src/i18n/messages.ts +34 -0
  177. package/src/i18n/namespaces.ts +32 -0
  178. package/src/i18n/request.ts +34 -0
  179. package/src/i18n/routing.ts +7 -0
  180. package/src/inbound-email/handlers.ts +67 -0
  181. package/src/inbound-email/intake.ts +180 -0
  182. package/src/jobs/digest-email.ts +112 -0
  183. package/src/jobs/run-in-process.ts +82 -0
  184. package/src/observability/scrub.ts +44 -0
  185. package/src/ports/README.md +8 -0
  186. package/src/ports/analytics.ts +8 -0
  187. package/src/ports/auth.ts +87 -0
  188. package/src/ports/db.ts +27 -0
  189. package/src/ports/email.ts +14 -0
  190. package/src/ports/errors.ts +46 -0
  191. package/src/ports/jobs.ts +69 -0
  192. package/src/ports/llm.ts +85 -0
  193. package/src/ports/storage.ts +132 -0
  194. package/src/seed/contracts.ts +129 -0
  195. package/src/server-lib/assistant.ts +45 -0
  196. package/src/server-lib/defer.ts +57 -0
  197. package/src/server-lib/demo-presets.ts +85 -0
  198. package/src/server-lib/invite.ts +92 -0
  199. package/src/server-lib/notify-deps.ts +15 -0
  200. package/src/server-lib/notify.ts +252 -0
  201. package/src/server-lib/preset-operations.ts +121 -0
  202. package/src/server-lib/scheduled-tick.ts +48 -0
  203. package/src/server-lib/simulator-api.ts +311 -0
  204. package/src/server-lib/sms.ts +43 -0
  205. package/src/server-lib/webhook-dispatch.ts +75 -0
  206. package/src/service-auth/credential.ts +20 -0
  207. package/src/service-auth/mailgun.ts +70 -0
  208. package/src/service-auth/verify.ts +80 -0
  209. package/src/service-auth/webhook.ts +69 -0
  210. package/src/testing/checks.json +103 -0
  211. package/src/testing/conformance/authz.ts +46 -0
  212. package/src/testing/conformance/db.ts +258 -0
  213. package/src/testing/conformance/demo-presets.ts +295 -0
  214. package/src/testing/conformance/i18n.ts +80 -0
  215. package/src/testing/conformance/register.ts +200 -0
  216. package/src/testing/conformance/seam-map.ts +205 -0
  217. package/src/testing/conformance/suite.ts +59 -0
  218. package/src/testing/conformance/types.ts +18 -0
  219. package/src/testing/contract.ts +200 -0
  220. package/src/testing/e2e.ts +15 -0
  221. package/src/testing/index.ts +6 -0
  222. package/src/testing/seam-specifiers.json +22 -0
  223. package/src/testing/tmp-dir-marker.d.mts +4 -0
  224. package/src/testing/tmp-dir-marker.mjs +5 -0
  225. package/src/testing/tmp-dir.ts +182 -0
  226. package/src/theme.ts +28 -0
  227. package/README.md +0 -3
@@ -0,0 +1,12 @@
1
+ import { render } from '@react-email/render'
2
+ import type { ReactElement } from 'react'
3
+ import type { EmailPort } from '../ports/email'
4
+
5
+ /** Renders a react-email template to html+text and hands it to whichever email adapter is wired. */
6
+ export async function sendTemplate(
7
+ port: EmailPort,
8
+ options: { to: string; subject: string; template: ReactElement },
9
+ ): Promise<void> {
10
+ const [html, text] = await Promise.all([render(options.template), render(options.template, { plainText: true })])
11
+ await port.send({ to: options.to, subject: options.subject, html, text })
12
+ }
@@ -0,0 +1,61 @@
1
+ import { Body, Container, Head, Heading, Html, Preview, Section, Text } from '@react-email/components'
2
+
3
+ interface DigestEmailLabels {
4
+ preview: string
5
+ heading: string
6
+ intro: string
7
+ /** Already-localized "You have N items." (count interpolated by the caller — the app names them). */
8
+ countLine: string
9
+ recentHeading: string
10
+ /** Shown instead of the recent list when the team has nothing to digest. */
11
+ emptyLine: string
12
+ footer: string
13
+ }
14
+
15
+ export interface DigestEmailProps {
16
+ /** All copy arrives pre-localized from the caller's next-intl lookup (`email` namespace) —
17
+ * templates render outside a request context, so they never call next-intl themselves. */
18
+ labels: DigestEmailLabels
19
+ /** Recent item snippets — user DATA, not UI copy, so they pass through verbatim. */
20
+ recentTitles: string[]
21
+ }
22
+
23
+ /**
24
+ * The scheduled org digest, previewed in Ladle, rendered by packages/kit/src/email/send.ts. Structurally
25
+ * a sibling of invite-email.tsx: a `labels` bag of pre-localized strings plus structured data (the
26
+ * recent-item snippets). The Simulator Mail tab renders it end-to-end when a schedule fires.
27
+ */
28
+ export function DigestEmail({ labels, recentTitles }: DigestEmailProps) {
29
+ return (
30
+ <Html lang="en">
31
+ <Head />
32
+ <Preview>{labels.preview}</Preview>
33
+ <Body style={{ backgroundColor: '#f4f4f5', fontFamily: 'sans-serif' }}>
34
+ <Container style={{ backgroundColor: '#ffffff', borderRadius: 8, margin: '40px auto', padding: 24 }}>
35
+ <Heading as="h2">{labels.heading}</Heading>
36
+ <Section>
37
+ <Text>{labels.intro}</Text>
38
+ <Text style={{ fontWeight: 600 }}>{labels.countLine}</Text>
39
+ {recentTitles.length > 0 ? (
40
+ <Section>
41
+ <Text style={{ fontWeight: 600, marginBottom: 4 }}>{labels.recentHeading}</Text>
42
+ {recentTitles.map((title, index) => (
43
+ <Text
44
+ // Snippets can repeat, so index-suffix the key (order is stable).
45
+ key={`${index}-${title}`}
46
+ style={{ margin: '2px 0', color: '#333333' }}
47
+ >
48
+ {`• ${title}`}
49
+ </Text>
50
+ ))}
51
+ </Section>
52
+ ) : (
53
+ <Text style={{ color: '#666666' }}>{labels.emptyLine}</Text>
54
+ )}
55
+ <Text style={{ fontSize: 12, color: '#666666', marginTop: 16 }}>{labels.footer}</Text>
56
+ </Section>
57
+ </Container>
58
+ </Body>
59
+ </Html>
60
+ )
61
+ }
@@ -0,0 +1,57 @@
1
+ import { Body, Button, Container, Head, Heading, Html, Preview, Section, Text } from '@react-email/components'
2
+
3
+ interface InviteEmailLabels {
4
+ preview: string
5
+ heading: string
6
+ body: string
7
+ button: string
8
+ linkFallback: string
9
+ }
10
+
11
+ export interface InviteEmailProps {
12
+ /** All copy arrives pre-localized from the caller's next-intl lookup (`email` namespace) —
13
+ * templates render outside a request context, so they never call next-intl themselves. */
14
+ labels: InviteEmailLabels
15
+ /** Built by the caller (src/app/api/org/invite/route.ts) from the invite id and request origin. */
16
+ acceptUrl: string
17
+ }
18
+
19
+ /**
20
+ * Templates are react-email components (ADR-0011); previewed in Ladle, rendered by
21
+ * packages/kit/src/email/send.ts. `acceptUrl` is the real accept-invitation entrypoint (src/app/[locale]/accept-invite) —
22
+ * the Simulator Mail tab renders this end-to-end (clicks inside the reading pane bridge out to
23
+ * the app's navigation policy; the extracted link rows carry a copy button).
24
+ */
25
+ export function InviteEmail({ labels, acceptUrl }: InviteEmailProps) {
26
+ return (
27
+ <Html lang="en">
28
+ <Head />
29
+ <Preview>{labels.preview}</Preview>
30
+ <Body style={{ backgroundColor: '#f4f4f5', fontFamily: 'sans-serif' }}>
31
+ <Container style={{ backgroundColor: '#ffffff', borderRadius: 8, margin: '40px auto', padding: 24 }}>
32
+ <Heading as="h2">{labels.heading}</Heading>
33
+ <Section>
34
+ <Text>{labels.body}</Text>
35
+ <Section style={{ textAlign: 'center', margin: '24px 0' }}>
36
+ <Button
37
+ href={acceptUrl}
38
+ style={{
39
+ backgroundColor: '#4c6ef5',
40
+ color: '#ffffff',
41
+ borderRadius: 6,
42
+ padding: '12px 24px',
43
+ }}
44
+ >
45
+ {labels.button}
46
+ </Button>
47
+ </Section>
48
+ <Text style={{ fontSize: 12, color: '#666666' }}>
49
+ {`${labels.linkFallback} `}
50
+ {acceptUrl}
51
+ </Text>
52
+ </Section>
53
+ </Container>
54
+ </Body>
55
+ </Html>
56
+ )
57
+ }
@@ -0,0 +1,39 @@
1
+ import { Body, Container, Head, Heading, Html, Preview, Section, Text } from '@react-email/components'
2
+
3
+ interface NotificationEmailLabels {
4
+ preview: string
5
+ heading: string
6
+ body: string
7
+ footer: string
8
+ }
9
+
10
+ export interface NotificationEmailProps {
11
+ /** All copy arrives pre-localized from the caller's next-intl lookup (`notifications` namespace) —
12
+ * templates render outside a request context, so they never call next-intl themselves. ONE generic
13
+ * template serves every NotificationKind; the kind decides only which labels the caller passes. */
14
+ labels: NotificationEmailLabels
15
+ }
16
+
17
+ /**
18
+ * The generic notification email — the `email` fan-out channel. Deliberately ONE template
19
+ * with kind-based copy rather than a template per kind: the channel is the reusable thing, and a new
20
+ * NotificationKind ships copy in the i18n `notifications` namespace, not a new react-email file.
21
+ * Previewed in Ladle, rendered by packages/kit/src/email/send.ts, caught by the Simulator Mail tab.
22
+ */
23
+ export function NotificationEmail({ labels }: NotificationEmailProps) {
24
+ return (
25
+ <Html lang="en">
26
+ <Head />
27
+ <Preview>{labels.preview}</Preview>
28
+ <Body style={{ backgroundColor: '#f4f4f5', fontFamily: 'sans-serif' }}>
29
+ <Container style={{ backgroundColor: '#ffffff', borderRadius: 8, margin: '40px auto', padding: 24 }}>
30
+ <Heading as="h2">{labels.heading}</Heading>
31
+ <Section>
32
+ <Text>{labels.body}</Text>
33
+ <Text style={{ fontSize: 12, color: '#666666' }}>{labels.footer}</Text>
34
+ </Section>
35
+ </Container>
36
+ </Body>
37
+ </Html>
38
+ )
39
+ }
package/src/guide.md ADDED
@@ -0,0 +1,132 @@
1
+ # SSSB app guide
2
+
3
+ The rules for an app built on SSSB (`@sssb/kit`). Paths are relative to the app's own directory, the package that
4
+ depends on `@sssb/kit`. `pnpm exec sssb guide` copies this file into your repository under a hash stamp: edit nothing in
5
+ the copy, rerun the command after an upgrade, and review the diff. Most rules are enforced by the `@sssb/eslint-plugin`
6
+ preset, SSSB's conformance suite or `sssb doctor`; keep the rest by hand.
7
+
8
+ ## The seam
9
+
10
+ - The app extends the framework only through the `@sssb/app-config/*` seam, the modules in `src/app-config/`.
11
+ Register new subjects, jobs, event kinds, tables and migrations there. Never edit or patch a framework base union or
12
+ registry.
13
+ - Import `@sssb/kit` only by a published subpath, a key of its `exports` map. Everything else in the package is
14
+ internal.
15
+
16
+ ## Vendors, environment and parameters
17
+
18
+ - Vendor SDKs (`@clerk/*`, `@aws-sdk/*`, `@anthropic-ai/*`, `@sentry/*`, `posthog-*`, `mailgun.js`, `pg`) are
19
+ imported only in an app's real adapters, `adapters/real/` (and in what runs outside the request path: `next.config.*`
20
+ for the Sentry build plugin, the contract tests in `tests/contract/`, the deployment in `infra/`). Everything else
21
+ codes against a port: `@sssb/kit/ports/*`, or a port the app owns. SSSB's own real adapters
22
+ (`@sssb/kit/adapters/real/*`) load their SDK too, so every module of the app outside `adapters/real/` (which may
23
+ build on one) and the vendor carve-outs above, tests, stories and scripts included, reaches one only with `import()`
24
+ when `!isSimulated`, never by an import declaration (re-exports included; a type-only `import type` or
25
+ `export type`, which loads nothing, is allowed).
26
+ - A vendor SSSB has no port for gets a port the app owns, under `src`: the port module (`ports/<name>.ts`), a registry
27
+ (`adapters/index.ts`) that takes the run mode from SSSB's `isSimulated` (`@sssb/kit/adapters/index`) and loads the
28
+ real adapter only with `import()`, a fake, and the real adapter in `adapters/real/`, the one directory that imports
29
+ the SDK. Nothing imports `adapters/real/` statically, and a fake never imports it at all. Add the SDK to the ban in
30
+ the app's own `package.json`: `"sssb": { "vendors": ["stripe", "stripe/*"] }`.
31
+ - Read `process.env` only in `adapters/real/` (and never the run mode there), in Next's instrumentation hooks, in
32
+ tests and in the app-root tool configs (Playwright, Vite). Every other module imports the resolved value: deployment
33
+ parameters from `config/params.ts`, the run mode from `isSimulated`.
34
+ - Deployment and service parameters exist only in `config/params.ts`. Secret values never enter the repository.
35
+ - Declare which of SSSB's optional ports the app uses in `config/params.ts`'s `ports` (`llm`, `email`, `inboundEmail`,
36
+ `jobs`). A port the app does not use is `none`, never configured with placeholder values.
37
+ - A job handler never reads the seed (`@sssb/app-config/seed`), which a deployment does not have: it finds people with
38
+ `ctx.auth.listMembers(orgSlug)`, and a person's locale with `ctx.resolveLocale`, where the runner provides one.
39
+ - `pnpm dev` stays hermetic: no docker, no credentials, no network. Never add `next/font/google`, telemetry, or
40
+ anything that phones home.
41
+ - Anything that needs real credentials, accounts or money is a row in the workspace's cutover checklist, never a
42
+ blocker: the app boots, and is tested, without it.
43
+ - `src/proxy.ts` default-exports the app's proxy wrapped in `withAuthProxy` from `@sssb/kit/adapters/proxy`, and its
44
+ `config.matcher` sends it every page and every `/api` route: in real mode SSSB's auth adapter needs its provider's
45
+ middleware to have seen the request, and `withAuthProxy` runs that middleware around your proxy (loading none of it
46
+ in simulated mode). Never import the provider's middleware yourself. A page path has no dot in it (the generated
47
+ matcher leaves those out, as static files), and Next buffers at most `proxyClientMaxBodySize` (10MB by default) of a
48
+ body the proxy sees, so an upload limit above it raises
49
+ `experimental.proxyClientMaxBodySize` in `next.config.ts` too.
50
+
51
+ ## Data
52
+
53
+ - Tenant-scoped queries run only inside `db.withTenant()`. `getDb()` is banned in every module under `src`
54
+ (`sssb/no-raw-db-handle`); tests are exempt, except a route's or a screen's. A module that truly needs the raw
55
+ client is a named entry, with its reason, in the app's `lint-exceptions.mjs`: a path relative to the app, one
56
+ existing file per entry, never a glob or a directory.
57
+ - A list that can grow pages through `@sssb/kit/db/keyset`, never a hand-rolled `LIMIT`/`OFFSET`. Parse the cursor
58
+ with `parseDbKeysetCursor` and answer 400 when it is `invalid`; clamp the page size on the server; fix the
59
+ `orderBy` column per route, never from the client.
60
+ - App migrations live in `src/app-config/db/migrations/`, numbered 1001 and up (0001–0999 are the framework's), and
61
+ are listed in `src/app-config/db/migrations/index.ts`. A new tenant table copies the RLS pattern of
62
+ `src/app-config/db/migrations/1001_items.ts`, the generated app's first migration (once you have removed it, read it
63
+ in SSSB's repository at your release), and its isolation proofs go in `src/app-config/db/rls-proofs.ts`.
64
+ - A role is cluster-wide, so a migration that creates one of the app's own creates it only where it does not exist
65
+ yet: a `DO` block that runs `CREATE ROLE reviewer NOLOGIN` only when
66
+ `NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'reviewer')`. Keep it an ordinary role, before and after every
67
+ migration: NOLOGIN, never CREATEDB, CREATEROLE, SUPERUSER, BYPASSRLS or REPLICATION, granted no privilege on a server
68
+ parameter (`GRANT ... ON PARAMETER`), the owner of no database or tablespace, and a member of no role (at any depth)
69
+ but `app_user` and the app's other named roles (`GRANT reviewer TO app_user` is fine;
70
+ `GRANT pg_read_all_data TO reviewer` is not). Leave the framework's `app_user` ordinary too, since every later owner
71
+ gets ADMIN on it as well: never change its attributes, give it no parameter privilege, database or tablespace, and grant it only
72
+ the app's named roles, never a `pg_*` one. Name your role in `appRoles`, exported beside `appMigrations` from
73
+ `src/app-config/db/migrations/index.ts`: `export const appRoles = ['reviewer'] as const`. The contract tests' owner
74
+ pass grants a later database owner ADMIN on exactly those roles and `app_user`, as Aurora's master user holds on a
75
+ role it created, and refuses a role that is not ordinary; the conformance suite's `app-roles` check fails a role the
76
+ migrations create and `appRoles` does not name, a name they do not create, and a named role or `app_user` they leave
77
+ more than ordinary. Never name `app_user` or a `pg_*` or `rds_*` role.
78
+ - After any migration or database change, run the contract tests on real Postgres (`pnpm test:contract` from the
79
+ workspace root). After renumbering or renaming a migration, wipe
80
+ the local `.data` first.
81
+
82
+ ## Authorization
83
+
84
+ - Every exported mutating route handler (POST, PUT, PATCH, DELETE) in a `route.ts` anywhere under `src/app`, not only
85
+ under `src/app/api`, calls `authorize(...)` from `@sssb/kit/authz/authorize` on its own path, as
86
+ `src/app/api/items/route.ts` does (the generated app's; once you have removed it, read it in SSSB's repository at your
87
+ release). The conformance suite's `authz-mutations` check reads each handler: a string, a
88
+ comment, a dead branch or a helper in another module does not count. Neither does a call whose denial cannot stop
89
+ the handler: in an `async` helper or a callback whose promise the handler neither awaits nor returns, in a callback
90
+ handed to a function the route file defines, or in a `try` whose `catch` does not rethrow. `await` the helper that
91
+ authorizes, and let `withPortErrors` answer the 403.
92
+ - An exemption is an entry in the app's `authz-exemptions.mjs` (`{ files, prefixes }`, keys relative to
93
+ `src/app/api`), with a reason and a `mustMatch` gate. A mutating route outside `src/app/api` can match no
94
+ exemption.
95
+
96
+ ## UI
97
+
98
+ - No hard-coded UI strings: all copy goes through next-intl, accessible names, placeholders, titles and alt text
99
+ included (`sssb/no-jsx-literals`, `sssb/no-literal-a11y-copy`). The app's namespaces live in `messages/en.json` and
100
+ `messages/es.json`; the framework ships its own catalog, and the two are deep-merged wherever messages load. The
101
+ merged catalogs stay key- and placeholder-identical.
102
+ - Screens are router-agnostic: they live in `src/components`, and the files under `src/app` are thin wrappers with no
103
+ logic, so the `file://` static demo still builds.
104
+
105
+ ## Tests
106
+
107
+ - Keep `src/sssb.conformance.test.ts` (SSSB's conformance suite) and `tests/contract/rls-contract.test.ts` (the
108
+ contract runner on real Postgres). Leave a check out only by a named opt-out with its reason,
109
+ `optOut: { '<check id>': '<why>' }`. `sssb doctor` fails when the Vitest config does not run them.
110
+ - A test that needs a scratch directory calls `makeTestTmpDir()` or `makeTestTmpDirAsync()` from
111
+ `@sssb/tools/testing/tmp-dir`, never `mkdtemp` directly. A script that runs Vitest as a gate goes through
112
+ `sssb check-tmpdir-leak`.
113
+ - E2E specs live in `tests/e2e/` and reach the framework only through `@sssb/kit/testing/e2e` (`sssb check-e2e`).
114
+ Playwright's `workers` stays 1: every worker shares one `.data` behind one dev server.
115
+ - Dead code fails `knip`. Never silence a finding with a broad ignore; add the narrowest entry, with its reason.
116
+
117
+ ## The dev loop
118
+
119
+ - Scheduled work runs in dev only when something ticks it: the app's `pnpm tick` calls the running dev server's cron
120
+ route once, and `DEV_TICK_SECONDS=<n> pnpm dev` ticks it every n seconds. The ticker is off by default and stays off
121
+ under e2e. The cron route (`src/app/api/webhooks/cron/route.ts`) stays behind `withWebhookSecret`: never add a
122
+ bypass for the ticker.
123
+ - The Simulator panel on `pnpm dev` is SSSB's: `src/app/api/simulator/[...path]/route.ts` serves it and the locale
124
+ layout renders it, both in simulated mode only. Each handler in that route file opens with the simulated-mode 404 and
125
+ imports SSSB's handler after it; that first line is what exempts the route from `authorize(...)`.
126
+ - In a linked git worktree the app's ports are derived per checkout, so parallel sessions never adopt each other's dev
127
+ server; `pnpm exec sssb port`, run from the app, prints its port. An app declares its port slot in its package.json,
128
+ `"sssb": { "port": { "name": "ledger", "default": 3800 } }`, and reads its override from `LEDGER_PORT`; its scripts and
129
+ Playwright config name no slot (`sssb tick`, `sssb dev-tick`, `originForApp(__dirname)`), so they read it. Every app of
130
+ a workspace needs a slot of its own, which `sssb doctor` checks: `pnpm exec sssb add-app <slug>` gives a new app one.
131
+ - Before finishing a change, run `pnpm verify` from the workspace root. Format with `pnpm lint:fix`, never by hand.
132
+ Commit messages are conventional commits; the commit-msg hook runs commitlint.