@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.
- package/LICENSE +21 -0
- package/dist/core/webhook-hmac.d.ts +69 -0
- package/dist/release.json +1 -0
- package/dist/testing/e2e.d.ts +15 -0
- package/dist/testing/e2e.js +195 -0
- package/package.json +212 -5
- package/src/adapters/README.md +6 -0
- package/src/adapters/dev-server.ts +21 -0
- package/src/adapters/fake/agreements.ts +81 -0
- package/src/adapters/fake/analytics.ts +93 -0
- package/src/adapters/fake/atomic-write.ts +161 -0
- package/src/adapters/fake/audit.ts +58 -0
- package/src/adapters/fake/auth.ts +313 -0
- package/src/adapters/fake/clock.ts +54 -0
- package/src/adapters/fake/data-dir.ts +27 -0
- package/src/adapters/fake/db.ts +88 -0
- package/src/adapters/fake/email.ts +46 -0
- package/src/adapters/fake/jobs.ts +248 -0
- package/src/adapters/fake/llm.ts +230 -0
- package/src/adapters/fake/pglite-dialect.ts +124 -0
- package/src/adapters/fake/service-auth.ts +145 -0
- package/src/adapters/fake/simulator-admin.ts +203 -0
- package/src/adapters/fake/simulator.ts +93 -0
- package/src/adapters/fake/sms.ts +43 -0
- package/src/adapters/fake/storage.ts +288 -0
- package/src/adapters/fake/webhooks.ts +98 -0
- package/src/adapters/index.ts +142 -0
- package/src/adapters/lazy-jobs.ts +25 -0
- package/src/adapters/proxy.ts +34 -0
- package/src/adapters/real/absent.ts +41 -0
- package/src/adapters/real/accept-invite-form.tsx +77 -0
- package/src/adapters/real/analytics.ts +28 -0
- package/src/adapters/real/auth.ts +216 -0
- package/src/adapters/real/clerk-proxy.ts +111 -0
- package/src/adapters/real/contract-data-api.ts +104 -0
- package/src/adapters/real/contract-postgres.ts +167 -0
- package/src/adapters/real/database-transport.ts +34 -0
- package/src/adapters/real/db-data-api.ts +61 -0
- package/src/adapters/real/db-port.ts +26 -0
- package/src/adapters/real/db.ts +69 -0
- package/src/adapters/real/email.ts +22 -0
- package/src/adapters/real/index.ts +139 -0
- package/src/adapters/real/jobs-in-process.ts +118 -0
- package/src/adapters/real/jobs.ts +33 -0
- package/src/adapters/real/llm.ts +108 -0
- package/src/adapters/real/migrate-handler.ts +66 -0
- package/src/adapters/real/optional-ports.ts +78 -0
- package/src/adapters/real/providers.tsx +12 -0
- package/src/adapters/real/rds-data-codec.ts +508 -0
- package/src/adapters/real/rds-data-dialect.ts +470 -0
- package/src/adapters/real/rds-data-emulator.ts +351 -0
- package/src/adapters/real/s3-storage.ts +233 -0
- package/src/adapters/real/sign-in-form.tsx +59 -0
- package/src/adapters/real/storage.ts +10 -0
- package/src/adapters/run-mode.ts +11 -0
- package/src/adapters/sentry/baseline.ts +90 -0
- package/src/adapters/sentry/client.ts +17 -0
- package/src/adapters/sentry/init.ts +17 -0
- package/src/authz/app-exemptions.ts +226 -0
- package/src/authz/authorize.ts +214 -0
- package/src/authz/route-policy.ts +153 -0
- package/src/authz/route-scan.ts +1516 -0
- package/src/components/agreements/acceptances-section.tsx +55 -0
- package/src/components/agreements/agreement-advisory-banner.tsx +33 -0
- package/src/components/agreements/agreement-body.tsx +34 -0
- package/src/components/agreements/agreement-gate.tsx +45 -0
- package/src/components/app-header.tsx +45 -0
- package/src/components/auth/accept-invite-screen.tsx +126 -0
- package/src/components/auth/auth-icons.tsx +68 -0
- package/src/components/auth/org-switcher.tsx +76 -0
- package/src/components/auth/people-picker.tsx +50 -0
- package/src/components/auth/preview-row.tsx +64 -0
- package/src/components/auth/sign-in-screen.tsx +24 -0
- package/src/components/auth/user-menu.tsx +64 -0
- package/src/components/demo-badge.tsx +20 -0
- package/src/components/demo-banner.tsx +14 -0
- package/src/components/gates/gate-interstitial.tsx +23 -0
- package/src/components/job-timeline.tsx +64 -0
- package/src/components/notifications/notification-bell.tsx +120 -0
- package/src/components/notifications/notification-prefs-section.tsx +112 -0
- package/src/components/org-screen.tsx +197 -0
- package/src/components/profile-screen.tsx +100 -0
- package/src/components/simulator/actor-runtime.ts +180 -0
- package/src/components/simulator/actor-shell.tsx +275 -0
- package/src/components/simulator/actors-app.tsx +119 -0
- package/src/components/simulator/errors-app.tsx +84 -0
- package/src/components/simulator/events-app.tsx +210 -0
- package/src/components/simulator/format-when.ts +20 -0
- package/src/components/simulator/hooks-app.tsx +319 -0
- package/src/components/simulator/inbound-app.tsx +210 -0
- package/src/components/simulator/jobs-app.tsx +471 -0
- package/src/components/simulator/mail-app.tsx +290 -0
- package/src/components/simulator/messages-app.tsx +64 -0
- package/src/components/simulator/people-app.tsx +140 -0
- package/src/components/simulator/people-dimensions.ts +16 -0
- package/src/components/simulator/simulator-host.tsx +335 -0
- package/src/components/simulator/simulator-panel.tsx +704 -0
- package/src/components/simulator/snapshots-app.tsx +398 -0
- package/src/components/simulator/tab-mount.ts +25 -0
- package/src/components/simulator/tours-app.tsx +105 -0
- package/src/components/webhook-endpoints-card.tsx +172 -0
- package/src/core/abilities.ts +464 -0
- package/src/core/agreements.ts +139 -0
- package/src/core/gates.ts +157 -0
- package/src/core/greeting.ts +11 -0
- package/src/core/inbound-email.ts +129 -0
- package/src/core/jobs.ts +51 -0
- package/src/core/keyset.ts +227 -0
- package/src/core/llm-models.ts +10 -0
- package/src/core/locale.ts +3 -0
- package/src/core/notifications.ts +182 -0
- package/src/core/presets.ts +456 -0
- package/src/core/roles.ts +47 -0
- package/src/core/same-origin-path.ts +20 -0
- package/src/core/schedules.ts +147 -0
- package/src/core/standard-schema.ts +56 -0
- package/src/core/state-machine.ts +43 -0
- package/src/core/webhook-events.ts +86 -0
- package/src/core/webhook-hmac.ts +248 -0
- package/src/core/webhook-signing.ts +27 -0
- package/src/cutover/rows.json +101 -0
- package/src/db/agreements.ts +176 -0
- package/src/db/app-roles.ts +197 -0
- package/src/db/audit.ts +356 -0
- package/src/db/inbound-email.ts +145 -0
- package/src/db/jobs.ts +300 -0
- package/src/db/jsonb.ts +18 -0
- package/src/db/keyset.ts +179 -0
- package/src/db/migrate.ts +73 -0
- package/src/db/migrations/0001_tenants.ts +25 -0
- package/src/db/migrations/0003_organizations.ts +27 -0
- package/src/db/migrations/0004_jobs.ts +64 -0
- package/src/db/migrations/0005_service_keys.ts +33 -0
- package/src/db/migrations/0008_audit_events.ts +51 -0
- package/src/db/migrations/0009_job_schedules.ts +52 -0
- package/src/db/migrations/0010_webhooks.ts +100 -0
- package/src/db/migrations/0011_notifications.ts +98 -0
- package/src/db/migrations/0012_inbound_email.ts +74 -0
- package/src/db/migrations/0013_agreements.ts +98 -0
- package/src/db/migrations/0014_audit_credential.ts +29 -0
- package/src/db/migrations/0015_app_user_grant.ts +67 -0
- package/src/db/migrations/0016_audit_detail.ts +26 -0
- package/src/db/migrations/index.ts +49 -0
- package/src/db/notifications.ts +185 -0
- package/src/db/org-lookup.ts +104 -0
- package/src/db/owner-pass.ts +252 -0
- package/src/db/rls-coverage.ts +259 -0
- package/src/db/rls-proof-runner.ts +94 -0
- package/src/db/rls-proofs.ts +1176 -0
- package/src/db/schedules.ts +187 -0
- package/src/db/schema.ts +235 -0
- package/src/db/seed.ts +176 -0
- package/src/db/service-keys.ts +50 -0
- package/src/db/tenant-lookup.ts +13 -0
- package/src/db/webhooks.ts +483 -0
- package/src/db/with-tenant.ts +26 -0
- package/src/demo-static/actor-drivers.ts +161 -0
- package/src/demo-static/assistant-replay.ts +61 -0
- package/src/demo-static/contracts.ts +282 -0
- package/src/demo-static/email-html.ts +58 -0
- package/src/demo-static/hash-route.ts +24 -0
- package/src/demo-static/rows.ts +105 -0
- package/src/demo-static/shell.tsx +440 -0
- package/src/demo-static/tour/contracts.ts +97 -0
- package/src/demo-static/tour/driver.ts +320 -0
- package/src/demo-static/tour/tour-overlay.tsx +226 -0
- package/src/demo-static/tour/use-tours.tsx +394 -0
- package/src/demo-static/world.ts +1480 -0
- package/src/email/send.ts +12 -0
- package/src/email/templates/digest-email.tsx +61 -0
- package/src/email/templates/invite-email.tsx +57 -0
- package/src/email/templates/notification-email.tsx +39 -0
- package/src/guide.md +132 -0
- package/src/i18n/messages/en.json +373 -0
- package/src/i18n/messages/es.json +373 -0
- package/src/i18n/messages.ts +34 -0
- package/src/i18n/namespaces.ts +32 -0
- package/src/i18n/request.ts +34 -0
- package/src/i18n/routing.ts +7 -0
- package/src/inbound-email/handlers.ts +67 -0
- package/src/inbound-email/intake.ts +180 -0
- package/src/jobs/digest-email.ts +112 -0
- package/src/jobs/run-in-process.ts +82 -0
- package/src/observability/scrub.ts +44 -0
- package/src/ports/README.md +8 -0
- package/src/ports/analytics.ts +8 -0
- package/src/ports/auth.ts +87 -0
- package/src/ports/db.ts +27 -0
- package/src/ports/email.ts +14 -0
- package/src/ports/errors.ts +46 -0
- package/src/ports/jobs.ts +69 -0
- package/src/ports/llm.ts +85 -0
- package/src/ports/storage.ts +132 -0
- package/src/seed/contracts.ts +129 -0
- package/src/server-lib/assistant.ts +45 -0
- package/src/server-lib/defer.ts +57 -0
- package/src/server-lib/demo-presets.ts +85 -0
- package/src/server-lib/invite.ts +92 -0
- package/src/server-lib/notify-deps.ts +15 -0
- package/src/server-lib/notify.ts +252 -0
- package/src/server-lib/preset-operations.ts +121 -0
- package/src/server-lib/scheduled-tick.ts +48 -0
- package/src/server-lib/simulator-api.ts +311 -0
- package/src/server-lib/sms.ts +43 -0
- package/src/server-lib/webhook-dispatch.ts +75 -0
- package/src/service-auth/credential.ts +20 -0
- package/src/service-auth/mailgun.ts +70 -0
- package/src/service-auth/verify.ts +80 -0
- package/src/service-auth/webhook.ts +69 -0
- package/src/testing/checks.json +103 -0
- package/src/testing/conformance/authz.ts +46 -0
- package/src/testing/conformance/db.ts +258 -0
- package/src/testing/conformance/demo-presets.ts +295 -0
- package/src/testing/conformance/i18n.ts +80 -0
- package/src/testing/conformance/register.ts +200 -0
- package/src/testing/conformance/seam-map.ts +205 -0
- package/src/testing/conformance/suite.ts +59 -0
- package/src/testing/conformance/types.ts +18 -0
- package/src/testing/contract.ts +200 -0
- package/src/testing/e2e.ts +15 -0
- package/src/testing/index.ts +6 -0
- package/src/testing/seam-specifiers.json +22 -0
- package/src/testing/tmp-dir-marker.d.mts +4 -0
- package/src/testing/tmp-dir-marker.mjs +5 -0
- package/src/testing/tmp-dir.ts +182 -0
- package/src/theme.ts +28 -0
- package/README.md +0 -3
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { Box, Button, Group, SegmentedControl, Stack, Text, UnstyledButton } from '@mantine/core'
|
|
4
|
+
import { useLocale, useTranslations } from 'next-intl'
|
|
5
|
+
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
6
|
+
import { formatWhen } from './format-when'
|
|
7
|
+
|
|
8
|
+
export interface MailItem {
|
|
9
|
+
id: string
|
|
10
|
+
to: string
|
|
11
|
+
subject: string
|
|
12
|
+
at: string
|
|
13
|
+
html: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const linkRowStyle = {
|
|
17
|
+
textAlign: 'left' as const,
|
|
18
|
+
flex: 1,
|
|
19
|
+
minWidth: 0,
|
|
20
|
+
borderRadius: 6,
|
|
21
|
+
padding: '6px 10px',
|
|
22
|
+
border: '1px solid rgba(255,255,255,0.2)',
|
|
23
|
+
background: 'rgba(255,255,255,0.06)',
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The reading-pane iframe is sandboxed with ONLY allow-scripts (opaque origin, no top-navigation),
|
|
28
|
+
* so the email can't navigate anything itself. This bridge script, appended to the srcDoc,
|
|
29
|
+
* intercepts anchor clicks inside the message and postMessages the href to the parent — which
|
|
30
|
+
* routes it through the caller's onOpenLink, the SAME policy gate the extracted link rows use.
|
|
31
|
+
* That makes the email's own buttons/links actually work without widening what they're allowed
|
|
32
|
+
* to do. Caught mail is app-composed (the fake adapter stores our own sends), so running its
|
|
33
|
+
* scripts in an opaque origin is an acceptable dev-tool tradeoff.
|
|
34
|
+
*/
|
|
35
|
+
const BRIDGE_SCRIPT =
|
|
36
|
+
'<script>document.addEventListener("click",function(e){' +
|
|
37
|
+
'var t=e.target;var a=t&&t.closest?t.closest("a[href]"):null;if(!a)return;' +
|
|
38
|
+
'e.preventDefault();parent.postMessage({type:"app-mail-link",href:a.getAttribute("href")},"*")' +
|
|
39
|
+
'})</script>'
|
|
40
|
+
|
|
41
|
+
/** Pulls `a[href]` out of the message html with DOMParser so the caller can offer link rows with
|
|
42
|
+
* copy buttons (handy for opening an invite in a second browser profile). Browser API only;
|
|
43
|
+
* guarded so this never runs during SSR of this 'use client' component. */
|
|
44
|
+
function extractLinks(html: string): string[] {
|
|
45
|
+
if (typeof DOMParser === 'undefined') return []
|
|
46
|
+
const doc = new DOMParser().parseFromString(html, 'text/html')
|
|
47
|
+
return Array.from(doc.querySelectorAll('a[href]'))
|
|
48
|
+
.map((anchor) => anchor.getAttribute('href'))
|
|
49
|
+
.filter((href): href is string => !!href)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Two-step clear-mailbox control (mirrors the Snapshots reset — this app avoids blocking dialogs).
|
|
54
|
+
* Owns its armed/confirming state so the CALLER can reset it with `key`: an armed confirm must not
|
|
55
|
+
* outlive the view it was armed against (scope switch, list changing underneath), and a remount is
|
|
56
|
+
* the effect-free way to guarantee that.
|
|
57
|
+
*/
|
|
58
|
+
function ClearMailControl({ onClear }: { onClear: () => void }) {
|
|
59
|
+
const t = useTranslations('simulator')
|
|
60
|
+
const [confirming, setConfirming] = useState(false)
|
|
61
|
+
if (!confirming) {
|
|
62
|
+
return (
|
|
63
|
+
<Button size="compact-xs" variant="default" data-testid="mail-clear" onClick={() => setConfirming(true)}>
|
|
64
|
+
{t('mailClearButton')}
|
|
65
|
+
</Button>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
return (
|
|
69
|
+
<Group gap="xs">
|
|
70
|
+
<Button color="red.8" size="compact-xs" data-testid="mail-clear-confirm" onClick={onClear}>
|
|
71
|
+
{t('mailClearConfirm')}
|
|
72
|
+
</Button>
|
|
73
|
+
<Button
|
|
74
|
+
variant="default"
|
|
75
|
+
size="compact-xs"
|
|
76
|
+
data-testid="mail-clear-cancel"
|
|
77
|
+
onClick={() => setConfirming(false)}
|
|
78
|
+
>
|
|
79
|
+
{t('mailClearCancel')}
|
|
80
|
+
</Button>
|
|
81
|
+
</Group>
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Router-agnostic Mail tab (ADR-0006 twin lives in @sssb/kit/demo-static): a per-person inbox over the
|
|
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
|
|
89
|
+
* persistence, and deciding what a link is allowed to do.
|
|
90
|
+
*/
|
|
91
|
+
export function MailApp({
|
|
92
|
+
emails,
|
|
93
|
+
scope,
|
|
94
|
+
onScopeChange,
|
|
95
|
+
personEmail,
|
|
96
|
+
mailSeenAt,
|
|
97
|
+
allCount,
|
|
98
|
+
onOpenLink,
|
|
99
|
+
onSeen,
|
|
100
|
+
onClear,
|
|
101
|
+
onCopyLink,
|
|
102
|
+
}: {
|
|
103
|
+
emails: MailItem[]
|
|
104
|
+
scope: 'person' | 'all'
|
|
105
|
+
onScopeChange: (scope: 'person' | 'all') => void
|
|
106
|
+
personEmail: string | null
|
|
107
|
+
mailSeenAt?: string | null
|
|
108
|
+
allCount?: number
|
|
109
|
+
onOpenLink: (href: string) => void
|
|
110
|
+
onSeen: () => void
|
|
111
|
+
onClear?: () => void
|
|
112
|
+
onCopyLink?: (href: string) => void
|
|
113
|
+
}) {
|
|
114
|
+
const t = useTranslations('simulator')
|
|
115
|
+
const locale = useLocale()
|
|
116
|
+
const [openId, setOpenId] = useState<string | null>(null)
|
|
117
|
+
const open = emails.find((email) => email.id === openId) ?? null
|
|
118
|
+
const links = useMemo(() => (open ? extractLinks(open.html) : []), [open])
|
|
119
|
+
const frameRef = useRef<HTMLIFrameElement | null>(null)
|
|
120
|
+
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
// Opening the Mail tab renders this component in 'person' scope by default, and switching
|
|
123
|
+
// scope to 'person' fires this again — both count as "read your mail" (design invariant).
|
|
124
|
+
// A poll tick that merely refreshes `emails` doesn't re-run this (scope hasn't changed).
|
|
125
|
+
if (scope === 'person') onSeen()
|
|
126
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
127
|
+
}, [scope])
|
|
128
|
+
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
function onMessage(event: MessageEvent) {
|
|
131
|
+
// Only the reading pane's own window may speak; anything else on the page is ignored.
|
|
132
|
+
if (!frameRef.current || event.source !== frameRef.current.contentWindow) return
|
|
133
|
+
const data = event.data as { type?: unknown; href?: unknown }
|
|
134
|
+
if (data?.type === 'app-mail-link' && typeof data.href === 'string') onOpenLink(data.href)
|
|
135
|
+
}
|
|
136
|
+
window.addEventListener('message', onMessage)
|
|
137
|
+
return () => window.removeEventListener('message', onMessage)
|
|
138
|
+
}, [onOpenLink])
|
|
139
|
+
|
|
140
|
+
const showEmptyPersonHint = scope === 'person' && emails.length === 0 && (allCount ?? 0) > 0
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<Stack gap="sm" data-testid="simulator-mail">
|
|
144
|
+
<Group justify="space-between" wrap="wrap" gap="xs">
|
|
145
|
+
<SegmentedControl
|
|
146
|
+
data-testid="mail-scope"
|
|
147
|
+
size="xs"
|
|
148
|
+
value={scope}
|
|
149
|
+
disabled={!personEmail}
|
|
150
|
+
data={[
|
|
151
|
+
{ value: 'person', label: <span data-testid="mail-scope-person">{t('mailScopePerson')}</span> },
|
|
152
|
+
{ value: 'all', label: <span data-testid="mail-scope-all">{t('mailScopeAll')}</span> },
|
|
153
|
+
]}
|
|
154
|
+
onChange={(value) => onScopeChange(value === 'all' ? 'all' : 'person')}
|
|
155
|
+
/>
|
|
156
|
+
{onClear && emails.length > 0 ? (
|
|
157
|
+
// Keyed by scope + list size: any change remounts the control, disarming a
|
|
158
|
+
// pending confirm that was armed against a view that no longer exists.
|
|
159
|
+
<ClearMailControl key={`${scope}:${emails.length}`} onClear={onClear} />
|
|
160
|
+
) : null}
|
|
161
|
+
</Group>
|
|
162
|
+
{emails.length === 0 ? (
|
|
163
|
+
showEmptyPersonHint ? (
|
|
164
|
+
<Stack gap="xs" data-testid="mail-empty-person">
|
|
165
|
+
<Text size="xs" c="gray.5">
|
|
166
|
+
{t('mailEmptyPerson', { email: personEmail ?? '' })}
|
|
167
|
+
</Text>
|
|
168
|
+
<Button
|
|
169
|
+
size="xs"
|
|
170
|
+
variant="default"
|
|
171
|
+
data-testid="mail-show-all"
|
|
172
|
+
onClick={() => onScopeChange('all')}
|
|
173
|
+
>
|
|
174
|
+
{t('mailShowAll', { count: allCount ?? 0 })}
|
|
175
|
+
</Button>
|
|
176
|
+
</Stack>
|
|
177
|
+
) : (
|
|
178
|
+
<Text size="xs" c="gray.5" data-testid="mail-empty">
|
|
179
|
+
{t('mailEmpty')}
|
|
180
|
+
</Text>
|
|
181
|
+
)
|
|
182
|
+
) : (
|
|
183
|
+
<Stack gap={0} data-testid="mail-list">
|
|
184
|
+
{emails.map((email) => {
|
|
185
|
+
const unread = scope === 'person' && (!mailSeenAt || email.at > mailSeenAt)
|
|
186
|
+
const selected = email.id === openId
|
|
187
|
+
return (
|
|
188
|
+
<Box key={email.id} style={{ borderBottom: '1px solid rgba(255,255,255,0.12)' }}>
|
|
189
|
+
<UnstyledButton
|
|
190
|
+
data-testid={`mail-item-${email.id}`}
|
|
191
|
+
aria-expanded={selected}
|
|
192
|
+
onClick={() => setOpenId(selected ? null : email.id)}
|
|
193
|
+
style={{
|
|
194
|
+
display: 'block',
|
|
195
|
+
width: '100%',
|
|
196
|
+
borderRadius: 8,
|
|
197
|
+
padding: '8px 10px',
|
|
198
|
+
background: selected ? 'rgba(255,255,255,0.14)' : 'transparent',
|
|
199
|
+
}}
|
|
200
|
+
>
|
|
201
|
+
<Group gap={8} wrap="nowrap" align="start">
|
|
202
|
+
<Box
|
|
203
|
+
mt={6}
|
|
204
|
+
style={{
|
|
205
|
+
width: 8,
|
|
206
|
+
height: 8,
|
|
207
|
+
borderRadius: 999,
|
|
208
|
+
flexShrink: 0,
|
|
209
|
+
background: unread ? '#4dabf7' : 'transparent',
|
|
210
|
+
}}
|
|
211
|
+
/>
|
|
212
|
+
<Stack gap={0} style={{ minWidth: 0, flex: 1 }}>
|
|
213
|
+
<Group justify="space-between" wrap="nowrap" gap="xs">
|
|
214
|
+
<Text size="sm" fw={unread ? 700 : 500} c="gray.0" truncate>
|
|
215
|
+
{email.subject}
|
|
216
|
+
</Text>
|
|
217
|
+
<Text size="xs" c="gray.6" style={{ whiteSpace: 'nowrap' }}>
|
|
218
|
+
{formatWhen(email.at, locale)}
|
|
219
|
+
</Text>
|
|
220
|
+
</Group>
|
|
221
|
+
<Text size="xs" c="gray.5" truncate>
|
|
222
|
+
{t('mailToLine', { to: email.to })}
|
|
223
|
+
</Text>
|
|
224
|
+
</Stack>
|
|
225
|
+
</Group>
|
|
226
|
+
</UnstyledButton>
|
|
227
|
+
{selected ? (
|
|
228
|
+
// Reading pane renders inline under its own row — no duplicated
|
|
229
|
+
// subject/to/time header (the row already shows it); just the
|
|
230
|
+
// sandboxed body + policy-gated extracted links.
|
|
231
|
+
<Box pb="xs">
|
|
232
|
+
<iframe
|
|
233
|
+
ref={frameRef}
|
|
234
|
+
title={email.subject}
|
|
235
|
+
srcDoc={email.html + BRIDGE_SCRIPT}
|
|
236
|
+
sandbox="allow-scripts"
|
|
237
|
+
style={{
|
|
238
|
+
width: '100%',
|
|
239
|
+
height: 260,
|
|
240
|
+
border: 0,
|
|
241
|
+
borderRadius: 6,
|
|
242
|
+
background: '#fff',
|
|
243
|
+
display: 'block',
|
|
244
|
+
}}
|
|
245
|
+
data-testid="mail-body"
|
|
246
|
+
/>
|
|
247
|
+
{links.length > 0 ? (
|
|
248
|
+
<Stack gap={4} pt="xs">
|
|
249
|
+
<Text size="xs" fw={700} c="gray.4">
|
|
250
|
+
{t('mailLinksHeading')}
|
|
251
|
+
</Text>
|
|
252
|
+
{links.map((href, index) => (
|
|
253
|
+
<Group key={`${href}-${index}`} gap={6} wrap="nowrap">
|
|
254
|
+
<UnstyledButton
|
|
255
|
+
data-testid="mail-link"
|
|
256
|
+
onClick={() => onOpenLink(href)}
|
|
257
|
+
style={linkRowStyle}
|
|
258
|
+
>
|
|
259
|
+
<Text
|
|
260
|
+
size="xs"
|
|
261
|
+
c="gray.0"
|
|
262
|
+
style={{ wordBreak: 'break-all' }}
|
|
263
|
+
>
|
|
264
|
+
{href}
|
|
265
|
+
</Text>
|
|
266
|
+
</UnstyledButton>
|
|
267
|
+
{onCopyLink ? (
|
|
268
|
+
<Button
|
|
269
|
+
size="compact-xs"
|
|
270
|
+
variant="default"
|
|
271
|
+
data-testid="mail-link-copy"
|
|
272
|
+
onClick={() => onCopyLink(href)}
|
|
273
|
+
>
|
|
274
|
+
{t('mailCopyButton')}
|
|
275
|
+
</Button>
|
|
276
|
+
) : null}
|
|
277
|
+
</Group>
|
|
278
|
+
))}
|
|
279
|
+
</Stack>
|
|
280
|
+
) : null}
|
|
281
|
+
</Box>
|
|
282
|
+
) : null}
|
|
283
|
+
</Box>
|
|
284
|
+
)
|
|
285
|
+
})}
|
|
286
|
+
</Stack>
|
|
287
|
+
)}
|
|
288
|
+
</Stack>
|
|
289
|
+
)
|
|
290
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { Badge, Box, Group, Stack, Text } from '@mantine/core'
|
|
4
|
+
import { useLocale, useTranslations } from 'next-intl'
|
|
5
|
+
import { formatWhen } from './format-when'
|
|
6
|
+
|
|
7
|
+
/** One caught SMS as the tab sees it — local row type, decoupled from the fake adapter's CaughtSms
|
|
8
|
+
* (the hooks-app HookDeliveryRow precedent), so the twin can produce it with no server types. */
|
|
9
|
+
export interface SmsMessageRow {
|
|
10
|
+
id: string
|
|
11
|
+
to: string
|
|
12
|
+
body: string
|
|
13
|
+
kind: string
|
|
14
|
+
at: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Router-agnostic Simulator Messages tab — the fake SMS channel's catch-store surfaced as a
|
|
19
|
+
* world view, the second consumer that keeps the notification channel abstraction honest. Display-only
|
|
20
|
+
* (no clear control — Snapshots reset wipes `.data/sms/`): data + nothing else. The ADR-0006 twin in
|
|
21
|
+
* @sssb/kit/demo-static renders the same component over in-memory rows.
|
|
22
|
+
*/
|
|
23
|
+
export function MessagesApp({ messages }: { messages: SmsMessageRow[] }) {
|
|
24
|
+
const t = useTranslations('messages')
|
|
25
|
+
const locale = useLocale()
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<Stack gap="sm" data-testid="simulator-messages">
|
|
29
|
+
{messages.length === 0 ? (
|
|
30
|
+
<Text size="xs" c="gray.5" data-testid="messages-empty">
|
|
31
|
+
{t('empty')}
|
|
32
|
+
</Text>
|
|
33
|
+
) : (
|
|
34
|
+
<Stack gap={0} data-testid="messages-list">
|
|
35
|
+
{messages.map((message) => (
|
|
36
|
+
<Box
|
|
37
|
+
key={message.id}
|
|
38
|
+
data-testid={`message-item-${message.id}`}
|
|
39
|
+
py="xs"
|
|
40
|
+
style={{ borderBottom: '1px solid rgba(255,255,255,0.12)' }}
|
|
41
|
+
>
|
|
42
|
+
<Group justify="space-between" wrap="nowrap" gap="xs">
|
|
43
|
+
<Group gap="xs" wrap="nowrap" style={{ minWidth: 0 }}>
|
|
44
|
+
<Badge size="xs" variant="light" color="grape">
|
|
45
|
+
{message.kind}
|
|
46
|
+
</Badge>
|
|
47
|
+
<Text size="sm" fw={600} c="gray.0" truncate>
|
|
48
|
+
{t('toLine', { to: message.to })}
|
|
49
|
+
</Text>
|
|
50
|
+
</Group>
|
|
51
|
+
<Text size="xs" c="gray.6" style={{ whiteSpace: 'nowrap' }}>
|
|
52
|
+
{formatWhen(message.at, locale)}
|
|
53
|
+
</Text>
|
|
54
|
+
</Group>
|
|
55
|
+
<Text size="xs" c="gray.4" mt={2} data-testid="message-body">
|
|
56
|
+
{message.body}
|
|
57
|
+
</Text>
|
|
58
|
+
</Box>
|
|
59
|
+
))}
|
|
60
|
+
</Stack>
|
|
61
|
+
)}
|
|
62
|
+
</Stack>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { Group, Stack, Text, UnstyledButton } from '@mantine/core'
|
|
4
|
+
import { useTranslations } from 'next-intl'
|
|
5
|
+
import { useState } from 'react'
|
|
6
|
+
import { peopleDimensions } from './people-dimensions'
|
|
7
|
+
|
|
8
|
+
export interface Person {
|
|
9
|
+
key: string
|
|
10
|
+
/** null for an invited-but-unregistered person — there's no account yet to hold a name. */
|
|
11
|
+
name: string | null
|
|
12
|
+
email: string
|
|
13
|
+
/** The person's role — rendered only when `orgs` is absent (an app that doesn't populate it). */
|
|
14
|
+
role: string
|
|
15
|
+
/** Every org (product copy: "team") the person belongs to, with their role IN that org. When
|
|
16
|
+
* present it replaces the single `role` chip — a multi-org person's role differs per org, so one
|
|
17
|
+
* role alone misstates every membership but the first. The org NAME shows only when the rows span
|
|
18
|
+
* more than one org (./people-dimensions); in a one-team world each chip is just the role. */
|
|
19
|
+
orgs?: { orgSlug: string; role: string }[]
|
|
20
|
+
tenantSlug: string
|
|
21
|
+
status: 'active' | 'invited'
|
|
22
|
+
hasAccount: boolean
|
|
23
|
+
unreadMail: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The panel-wide pill look for tiny metadata chips (org·role/tenant here, the header's invited
|
|
27
|
+
* badge) — exported so the two stay in lockstep. */
|
|
28
|
+
export const chipStyle = {
|
|
29
|
+
border: '1px solid rgba(255,255,255,0.25)',
|
|
30
|
+
borderRadius: 999,
|
|
31
|
+
padding: '1px 8px',
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Router-agnostic People tab (ADR-0006 twin lives in @sssb/kit/demo-static): one row per known person —
|
|
35
|
+
* seeded/dynamic people AND invited-but-unregistered people alike — current viewpoint
|
|
36
|
+
* highlighted, click to switch. Invited rows have no name yet, so they show their email as the
|
|
37
|
+
* label plus an "invited" badge; they're still selectable (as a viewpoint, not a sign-in). */
|
|
38
|
+
export function PeopleApp({
|
|
39
|
+
people,
|
|
40
|
+
viewpoint,
|
|
41
|
+
onSelect,
|
|
42
|
+
}: {
|
|
43
|
+
people: Person[]
|
|
44
|
+
viewpoint: string | null
|
|
45
|
+
onSelect: (key: string) => void
|
|
46
|
+
}) {
|
|
47
|
+
const t = useTranslations('simulator')
|
|
48
|
+
// Rows carry a persistent border + faint fill so they read as buttons at rest; hover lifts the
|
|
49
|
+
// non-active fill (local state — no global CSS), the active row stays brightest.
|
|
50
|
+
const [hoveredKey, setHoveredKey] = useState<string | null>(null)
|
|
51
|
+
const { showTenant, showOrg } = peopleDimensions(people)
|
|
52
|
+
return (
|
|
53
|
+
<Stack gap={6} data-testid="simulator-people">
|
|
54
|
+
{people.map((person) => {
|
|
55
|
+
const idPart = person.key.replace(/^(person|invited):/, '')
|
|
56
|
+
const active = person.key === viewpoint
|
|
57
|
+
const hovered = person.key === hoveredKey
|
|
58
|
+
const background = active
|
|
59
|
+
? 'rgba(255,255,255,0.14)'
|
|
60
|
+
: hovered
|
|
61
|
+
? 'rgba(255,255,255,0.10)'
|
|
62
|
+
: 'rgba(255,255,255,0.04)'
|
|
63
|
+
return (
|
|
64
|
+
<UnstyledButton
|
|
65
|
+
key={person.key}
|
|
66
|
+
onClick={() => onSelect(person.key)}
|
|
67
|
+
onMouseEnter={() => setHoveredKey(person.key)}
|
|
68
|
+
onMouseLeave={() => setHoveredKey((current) => (current === person.key ? null : current))}
|
|
69
|
+
data-testid={`people-${idPart}`}
|
|
70
|
+
aria-current={active ? 'true' : undefined}
|
|
71
|
+
style={{
|
|
72
|
+
borderRadius: 8,
|
|
73
|
+
padding: '8px 10px',
|
|
74
|
+
background,
|
|
75
|
+
border: active ? '1px solid rgba(255,255,255,0.45)' : '1px solid rgba(255,255,255,0.18)',
|
|
76
|
+
}}
|
|
77
|
+
>
|
|
78
|
+
<Group justify="space-between" wrap="nowrap" gap="xs">
|
|
79
|
+
<Stack gap={0}>
|
|
80
|
+
<Text size="sm" fw={600} c="gray.0">
|
|
81
|
+
{person.name ?? person.email}
|
|
82
|
+
</Text>
|
|
83
|
+
{person.name ? (
|
|
84
|
+
<Text size="xs" c="gray.5">
|
|
85
|
+
{person.email}
|
|
86
|
+
</Text>
|
|
87
|
+
) : null}
|
|
88
|
+
</Stack>
|
|
89
|
+
{/* Wraps: a multi-org person carries one chip per membership, which at the
|
|
90
|
+
panel's 300px minimum would otherwise squeeze the name column. */}
|
|
91
|
+
<Group gap={4} wrap="wrap" justify="flex-end">
|
|
92
|
+
{person.orgs && person.orgs.length > 0 && showOrg ? (
|
|
93
|
+
person.orgs.map((org) => (
|
|
94
|
+
<Text
|
|
95
|
+
key={org.orgSlug}
|
|
96
|
+
size="xs"
|
|
97
|
+
c="gray.3"
|
|
98
|
+
style={chipStyle}
|
|
99
|
+
data-testid={`org-chip-${idPart}-${org.orgSlug}`}
|
|
100
|
+
>
|
|
101
|
+
{t('peopleOrgRole', { org: org.orgSlug, role: org.role })}
|
|
102
|
+
</Text>
|
|
103
|
+
))
|
|
104
|
+
) : (
|
|
105
|
+
<Text size="xs" c="gray.3" style={chipStyle}>
|
|
106
|
+
{person.orgs?.[0]?.role ?? person.role}
|
|
107
|
+
</Text>
|
|
108
|
+
)}
|
|
109
|
+
{showTenant ? (
|
|
110
|
+
<Text size="xs" c="gray.3" style={chipStyle} data-testid={`tenant-chip-${idPart}`}>
|
|
111
|
+
{person.tenantSlug}
|
|
112
|
+
</Text>
|
|
113
|
+
) : null}
|
|
114
|
+
{person.status === 'invited' ? (
|
|
115
|
+
<Text size="xs" c="gray.3" style={chipStyle} data-testid="people-invited-badge">
|
|
116
|
+
{t('peopleInvitedBadge')}
|
|
117
|
+
</Text>
|
|
118
|
+
) : null}
|
|
119
|
+
{person.unreadMail > 0 ? (
|
|
120
|
+
<Text
|
|
121
|
+
size="xs"
|
|
122
|
+
fw={700}
|
|
123
|
+
style={{
|
|
124
|
+
background: '#c92a2a',
|
|
125
|
+
color: '#fff',
|
|
126
|
+
borderRadius: 999,
|
|
127
|
+
padding: '1px 7px',
|
|
128
|
+
}}
|
|
129
|
+
>
|
|
130
|
+
{person.unreadMail}
|
|
131
|
+
</Text>
|
|
132
|
+
) : null}
|
|
133
|
+
</Group>
|
|
134
|
+
</Group>
|
|
135
|
+
</UnstyledButton>
|
|
136
|
+
)
|
|
137
|
+
})}
|
|
138
|
+
</Stack>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which identity dimensions the People tab shows. Every SSSB app HAS a tenant and an org for every
|
|
3
|
+
* person (the auth port requires both), but many apps only ever run one tenant, or one team, and then
|
|
4
|
+
* a chip naming it on every row tells the viewer nothing. So a dimension is shown only when it
|
|
5
|
+
* DISTINGUISHES the rows on screen — computed from the rows themselves, never from app configuration,
|
|
6
|
+
* so the chip appears on its own the day a second tenant or team does. Role is always shown: it is the
|
|
7
|
+
* one per-person fact every app has.
|
|
8
|
+
*/
|
|
9
|
+
export function peopleDimensions(people: { tenantSlug: string; orgs?: { orgSlug: string }[] }[]): {
|
|
10
|
+
showTenant: boolean
|
|
11
|
+
showOrg: boolean
|
|
12
|
+
} {
|
|
13
|
+
const tenants = new Set(people.map((person) => person.tenantSlug))
|
|
14
|
+
const orgs = new Set(people.flatMap((person) => (person.orgs ?? []).map((org) => org.orgSlug)))
|
|
15
|
+
return { showTenant: tenants.size > 1, showOrg: orgs.size > 1 }
|
|
16
|
+
}
|