@sssb/kit 0.8.0 → 0.9.1

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 (36) hide show
  1. package/dist/release.json +1 -1
  2. package/package.json +3 -1
  3. package/src/adapters/edge-headers.ts +171 -0
  4. package/src/adapters/fake/simulator-admin.ts +7 -3
  5. package/src/adapters/fake/storage.ts +60 -8
  6. package/src/adapters/origin-form.ts +24 -0
  7. package/src/adapters/real/auth.ts +3 -2
  8. package/src/adapters/real/clerk-authorized-parties.ts +3 -14
  9. package/src/adapters/real/index.ts +8 -0
  10. package/src/adapters/real/optional-ports.ts +3 -2
  11. package/src/adapters/real/s3-storage.ts +66 -5
  12. package/src/adapters/real/storage-settings.ts +7 -4
  13. package/src/adapters/real/storage.ts +9 -7
  14. package/src/authz/route-policy.ts +7 -4
  15. package/src/components/simulator/actors-app.tsx +1 -1
  16. package/src/components/simulator/errors-app.tsx +4 -1
  17. package/src/components/simulator/inbound-app.tsx +1 -1
  18. package/src/components/simulator/jobs-app.tsx +3 -3
  19. package/src/components/simulator/mail-app.tsx +1 -1
  20. package/src/components/simulator/mail-link.ts +27 -0
  21. package/src/components/simulator/simulator-host.tsx +556 -82
  22. package/src/components/simulator/simulator-panel.tsx +1 -1
  23. package/src/db/inbound-email.ts +7 -5
  24. package/src/db/migrations/0018_organizations_write.ts +87 -0
  25. package/src/db/migrations/index.ts +2 -0
  26. package/src/db/org-lookup.ts +4 -4
  27. package/src/db/rls-coverage.ts +140 -24
  28. package/src/db/rls-proofs.ts +147 -0
  29. package/src/demo-static/world.ts +2 -2
  30. package/src/guide.md +6 -0
  31. package/src/ports/storage.ts +50 -9
  32. package/src/server-lib/invite.ts +5 -1
  33. package/src/server-lib/simulator-api.ts +320 -3
  34. package/src/service-auth/secret-env.ts +19 -0
  35. package/src/service-auth/standard-webhooks.ts +358 -0
  36. package/src/service-auth/webhook.ts +39 -12
@@ -50,9 +50,12 @@ export const EXEMPT_PREFIXES: Readonly<Record<string, Exemption>> = {
50
50
  'webhooks/': {
51
51
  reason:
52
52
  'authenticated by a machine caller, not a user session — a shared webhook secret ' +
53
- '(withWebhookSecret) or the Mailgun inbound signature (withMailgunSignature) — so no ' +
54
- 'per-actor ability applies',
55
- mustMatch: { kind: 'wrapped-by', callees: ['withWebhookSecret', 'withMailgunSignature'] },
53
+ '(withWebhookSecret), the Mailgun inbound signature (withMailgunSignature) or a Standard Webhooks ' +
54
+ 'signature (withStandardWebhookSignature) — so no per-actor ability applies',
55
+ mustMatch: {
56
+ kind: 'wrapped-by',
57
+ callees: ['withWebhookSecret', 'withMailgunSignature', 'withStandardWebhookSignature'],
58
+ },
56
59
  },
57
60
  'simulator/': {
58
61
  reason: 'simulated-world surface, simulated-mode-gated (404 in real) — never a product mutation path',
@@ -96,7 +99,7 @@ export const EXEMPT_FILES: Readonly<Record<string, Exemption>> = {
96
99
  },
97
100
  'storage-upload/route.ts': {
98
101
  reason:
99
- 'simulated-mode-only (404 in real) multipart upload endpoint — the local twin of an S3 presigned POST, ' +
102
+ 'simulated-mode-only (404 in real) upload endpoint — the local twin of an S3 presigned POST (multipart) and of a presigned PUT, ' +
100
103
  'authenticated by the server-signed HMAC upload-target fields (like the webhook secret), NOT a user ' +
101
104
  'session; the upload TARGET was already authorized by the app route that minted it',
102
105
  mustMatch: SIMULATED_404,
@@ -11,7 +11,7 @@ import { chipStyle } from './people-app'
11
11
  * router- and transport-blind — and catalog-blind: WHICH counterparties exist is app vocabulary, so
12
12
  * their copy belongs in the app's catalog and arrives here as finished strings, exactly like
13
13
  * SimulatorExtraTab.label). The
14
- * real glue hands over a same-origin iframe src pointing at the actor's own page; the static twin
14
+ * app on the server host hands over a same-origin iframe src pointing at the actor's own page; the static twin
15
15
  * hands over an already-mounted ActorShell node running inline. A discriminated union keeps the two
16
16
  * shapes mutually exclusive rather than an always-both-optional prop bag.
17
17
  */
@@ -46,7 +46,10 @@ export function ErrorsApp({ runServerScenario }: { runServerScenario?: () => Pro
46
46
  variant="default"
47
47
  data-testid="throw-server-error"
48
48
  onClick={() => {
49
- runServerScenario().then(setResult)
49
+ // A server that could not answer leaves the last result showing.
50
+ runServerScenario()
51
+ .then(setResult)
52
+ .catch(() => undefined)
50
53
  }}
51
54
  >
52
55
  {t('throwServer')}
@@ -54,7 +54,7 @@ function statusColor(status: string): string {
54
54
 
55
55
  /**
56
56
  * The Mail tab's "compose inbound" affordance + inbound list: the world emails the app. Data
57
- * and callbacks only — the glue (simulator-glue.tsx) owns fetching and the POST, and the static-demo
57
+ * and callbacks only — the host (`./simulator-host`) owns fetching and the POST, and the static-demo
58
58
  * twin drives the same props over its in-memory intake. Native <select>s (not Mantine comboboxes) keep
59
59
  * the compose form trivially Playwright-selectable. The handler is a free-text field so an unknown slug
60
60
  * can be sent on purpose to demonstrate the 'unmatched' path.
@@ -32,7 +32,7 @@ export interface ScheduleRowLike {
32
32
  orgSlug: string
33
33
  }
34
34
 
35
- /** The simulated world-clock control surface, wired by the host (real glue / static twin). */
35
+ /** The simulated world-clock control surface, wired by the host (the server host / the static twin). */
36
36
  export interface WorldClockLike {
37
37
  /** Current offset ahead of real time, in ms (0 = real time). */
38
38
  offsetMs: number
@@ -47,8 +47,8 @@ export interface WorldClockLike {
47
47
  }
48
48
 
49
49
  /**
50
- * The dev ticker, wired by the real glue only, and only when the dev server answers for it (a simulated `next dev`;
51
- * never a production build, the demo, e2e or the static twin, which has no server). `running`..`lastError` are the
50
+ * The dev ticker, wired by the server host only, and only when the app's own ticker route answers for it (a simulated
51
+ * `next dev`; never a production build, the demo, e2e or the static twin, which has no server). `running`..`lastError` are the
52
52
  * ticker's own status (@sssb/tools/ticker); `elsewhere` is a ticker this panel did not start, live on the same world.
53
53
  */
54
54
  export interface DevTickerLike {
@@ -85,7 +85,7 @@ function ClearMailControl({ onClear }: { onClear: () => void }) {
85
85
  /**
86
86
  * Router-agnostic Mail tab (ADR-0006 twin lives in @sssb/kit/demo-static): a per-person inbox over the
87
87
  * fake email adapter's catch store, plus an "all mail" scope, styled like a small mail client.
88
- * Data and callbacks only — the glue (src/app/[locale]/simulator-glue.tsx) owns fetching, scope
88
+ * Data and callbacks only — the host (`./simulator-host`) owns fetching, scope
89
89
  * persistence, and deciding what a link is allowed to do.
90
90
  */
91
91
  export function MailApp({
@@ -0,0 +1,27 @@
1
+ import { sameOriginPath } from '../../core/same-origin-path'
2
+
3
+ /** What the Simulator does with a link in a caught email: follow `path`, or say why not. */
4
+ export type MailLinkTarget = { path: string } | { refused: 'origin'; origin: string } | { refused: 'unusable' }
5
+
6
+ /**
7
+ * Same origin only (design invariant), and never silently. A path is followed; so is an absolute URL on this origin,
8
+ * since a real email (the invite accept link) carries one. Both go through `sameOriginPath`, which refuses what a
9
+ * browser would read as another origin (`/\host`, a tab inside), so a prefix check is not the gate. A
10
+ * protocol-relative `//host` link is resolved against this page and judged by its host like any absolute URL; one
11
+ * with no origin at all (`mailto:`) is unusable here.
12
+ */
13
+ export function mailLinkTarget(href: string, pageHref: string): MailLinkTarget {
14
+ const path = sameOriginPath(href)
15
+ if (path) return { path }
16
+ let url: URL
17
+ try {
18
+ url = href.startsWith('//') ? new URL(href, pageHref) : new URL(href)
19
+ } catch {
20
+ return { refused: 'unusable' }
21
+ }
22
+ const origin = new URL(pageHref).origin
23
+ const local = url.origin === origin ? sameOriginPath(url.pathname + url.search + url.hash) : null
24
+ if (local) return { path: local }
25
+ if (url.origin === origin || url.origin === 'null') return { refused: 'unusable' }
26
+ return { refused: 'origin', origin: url.origin }
27
+ }