@sssb/kit 0.0.0-stage → 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.
- 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 +209 -3
- 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 +312 -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 +270 -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 +94 -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 +115 -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/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.ts +88 -0
- package/src/adapters/real/email.ts +22 -0
- package/src/adapters/real/index.ts +89 -0
- package/src/adapters/real/jobs.ts +32 -0
- package/src/adapters/real/llm.ts +108 -0
- package/src/adapters/real/migrate-handler.ts +66 -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/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-panel.tsx +716 -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 +459 -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/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 +1479 -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 +118 -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 +97 -0
- package/src/observability/scrub.ts +42 -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 +48 -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 +53 -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 +38 -0
- package/src/server-lib/sms.ts +43 -0
- package/src/server-lib/webhook-dispatch.ts +75 -0
- package/src/service-auth/mailgun.ts +70 -0
- package/src/service-auth/verify.ts +73 -0
- package/src/service-auth/webhook.ts +60 -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,84 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { Button, Card, Code, Container, Group, Stack, Text, Title } from '@mantine/core'
|
|
4
|
+
import { useTranslations } from 'next-intl'
|
|
5
|
+
import { useState } from 'react'
|
|
6
|
+
import { scrubEvent } from '../../observability/scrub'
|
|
7
|
+
|
|
8
|
+
export interface ScrubResult {
|
|
9
|
+
raw: unknown
|
|
10
|
+
scrubbed: unknown
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Simulator Errors tab: proof that Sentry scrubbing (ADR-0010) works without a DSN — client and server. */
|
|
14
|
+
export function ErrorsApp({ runServerScenario }: { runServerScenario?: () => Promise<ScrubResult> }) {
|
|
15
|
+
const t = useTranslations('errors')
|
|
16
|
+
const [result, setResult] = useState<ScrubResult | null>(null)
|
|
17
|
+
|
|
18
|
+
function throwClientError() {
|
|
19
|
+
try {
|
|
20
|
+
throw new Error('Test error (client) from /dev/errors')
|
|
21
|
+
} catch (err) {
|
|
22
|
+
const base = {
|
|
23
|
+
message: (err as Error).message,
|
|
24
|
+
request: {
|
|
25
|
+
query_string: 'q=SECRET_QUERY',
|
|
26
|
+
headers: { authorization: 'Bearer SECRET_TOKEN' },
|
|
27
|
+
},
|
|
28
|
+
user: { id: 'user_123', email: 'user@example.com', ip_address: '203.0.113.7' },
|
|
29
|
+
}
|
|
30
|
+
setResult({ raw: structuredClone(base), scrubbed: scrubEvent(structuredClone(base)) })
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
// No landmark: this screen renders only inside the Simulator <aside>, never as a page.
|
|
36
|
+
<Container size="md" py="xl">
|
|
37
|
+
<Stack gap="lg">
|
|
38
|
+
<Title order={1}>{t('title')}</Title>
|
|
39
|
+
<Text c="gray.7">{t('intro')}</Text>
|
|
40
|
+
<Group gap="sm">
|
|
41
|
+
<Button data-testid="throw-client-error" onClick={throwClientError}>
|
|
42
|
+
{t('throwClient')}
|
|
43
|
+
</Button>
|
|
44
|
+
{runServerScenario ? (
|
|
45
|
+
<Button
|
|
46
|
+
variant="default"
|
|
47
|
+
data-testid="throw-server-error"
|
|
48
|
+
onClick={() => {
|
|
49
|
+
runServerScenario().then(setResult)
|
|
50
|
+
}}
|
|
51
|
+
>
|
|
52
|
+
{t('throwServer')}
|
|
53
|
+
</Button>
|
|
54
|
+
) : null}
|
|
55
|
+
</Group>
|
|
56
|
+
{result ? (
|
|
57
|
+
<Stack gap="md">
|
|
58
|
+
<Card withBorder padding="lg" radius="md">
|
|
59
|
+
<Title order={2} size="h3" mb="sm">
|
|
60
|
+
{t('rawHeading')}
|
|
61
|
+
</Title>
|
|
62
|
+
<Code block data-testid="error-raw">
|
|
63
|
+
{JSON.stringify(result.raw, null, 2)}
|
|
64
|
+
</Code>
|
|
65
|
+
</Card>
|
|
66
|
+
<Card withBorder padding="lg" radius="md">
|
|
67
|
+
<Title order={2} size="h3" mb="sm">
|
|
68
|
+
{t('scrubbedHeading')}
|
|
69
|
+
</Title>
|
|
70
|
+
<Code block data-testid="error-scrubbed">
|
|
71
|
+
{JSON.stringify(result.scrubbed, null, 2)}
|
|
72
|
+
</Code>
|
|
73
|
+
</Card>
|
|
74
|
+
<Text size="sm" c="gray.7">
|
|
75
|
+
{t('note')}
|
|
76
|
+
</Text>
|
|
77
|
+
</Stack>
|
|
78
|
+
) : (
|
|
79
|
+
<Text c="gray.7">{t('empty')}</Text>
|
|
80
|
+
)}
|
|
81
|
+
</Stack>
|
|
82
|
+
</Container>
|
|
83
|
+
)
|
|
84
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { Box, Divider, Group, Stack, Text, UnstyledButton } from '@mantine/core'
|
|
4
|
+
import { useLocale, useTranslations } from 'next-intl'
|
|
5
|
+
import { useState } from 'react'
|
|
6
|
+
import { formatTimeShort, formatWhen } from './format-when'
|
|
7
|
+
|
|
8
|
+
export interface AnalyticsEvent {
|
|
9
|
+
id: string
|
|
10
|
+
at: string
|
|
11
|
+
event: string
|
|
12
|
+
properties?: Record<string, unknown> | undefined
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* One compliance-grade audit event — the durable "who did what when" product record, distinct
|
|
17
|
+
* from the analytics events above it. In the real app these arrive from GET /api/simulator/audit (the
|
|
18
|
+
* cross-tenant god view of the audit_events table); the static twin appends them in memory from its own
|
|
19
|
+
* mutations. tenantSlug/orgSlug are present in the god view (cross-tenant) and in the twin.
|
|
20
|
+
*/
|
|
21
|
+
export interface AuditEntry {
|
|
22
|
+
id: string
|
|
23
|
+
at: string
|
|
24
|
+
action: string
|
|
25
|
+
subjectType: string
|
|
26
|
+
subjectId: string | null
|
|
27
|
+
actorUserId: string
|
|
28
|
+
tenantSlug?: string
|
|
29
|
+
orgSlug?: string | null
|
|
30
|
+
/**
|
|
31
|
+
* Why, as codes and counts (audit_events.detail, migration 0016), or null. Shown only inside the
|
|
32
|
+
* expanded row's JSON, as a React text child: escaped, never parsed as HTML.
|
|
33
|
+
*/
|
|
34
|
+
detail?: Readonly<Record<string, unknown>> | null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** A dark-skin expandable row shared by both sections (analytics events + audit). */
|
|
38
|
+
function LogRow({
|
|
39
|
+
id,
|
|
40
|
+
title,
|
|
41
|
+
hint,
|
|
42
|
+
at,
|
|
43
|
+
open,
|
|
44
|
+
onToggle,
|
|
45
|
+
detail,
|
|
46
|
+
glyph,
|
|
47
|
+
testidPrefix,
|
|
48
|
+
}: {
|
|
49
|
+
id: string
|
|
50
|
+
title: string
|
|
51
|
+
hint: string | null
|
|
52
|
+
at: string
|
|
53
|
+
open: boolean
|
|
54
|
+
onToggle: () => void
|
|
55
|
+
detail: unknown
|
|
56
|
+
glyph: string
|
|
57
|
+
testidPrefix: string
|
|
58
|
+
}) {
|
|
59
|
+
const locale = useLocale()
|
|
60
|
+
return (
|
|
61
|
+
<Box data-testid={`${testidPrefix}-${id}`} style={{ borderBottom: '1px solid rgba(255,255,255,0.12)' }}>
|
|
62
|
+
<UnstyledButton
|
|
63
|
+
data-testid={`${testidPrefix}-toggle-${id}`}
|
|
64
|
+
aria-expanded={open}
|
|
65
|
+
onClick={onToggle}
|
|
66
|
+
style={{ display: 'block', width: '100%', padding: '8px 4px' }}
|
|
67
|
+
>
|
|
68
|
+
<Group gap={8} wrap="nowrap" align="center">
|
|
69
|
+
<Text
|
|
70
|
+
size="xs"
|
|
71
|
+
c="gray.5"
|
|
72
|
+
aria-hidden
|
|
73
|
+
style={{
|
|
74
|
+
flexShrink: 0,
|
|
75
|
+
display: 'inline-block',
|
|
76
|
+
transform: open ? 'rotate(90deg)' : 'none',
|
|
77
|
+
transition: 'transform 120ms',
|
|
78
|
+
}}
|
|
79
|
+
>
|
|
80
|
+
{glyph}
|
|
81
|
+
</Text>
|
|
82
|
+
<Text size="sm" fw={600} c="gray.0" truncate style={{ minWidth: 0 }}>
|
|
83
|
+
{title}
|
|
84
|
+
</Text>
|
|
85
|
+
{hint ? (
|
|
86
|
+
<Text size="xs" c="gray.5" truncate style={{ minWidth: 0, flex: 1 }}>
|
|
87
|
+
{hint}
|
|
88
|
+
</Text>
|
|
89
|
+
) : (
|
|
90
|
+
<span style={{ flex: 1 }} />
|
|
91
|
+
)}
|
|
92
|
+
<Text size="xs" c="gray.5" style={{ flexShrink: 0, whiteSpace: 'nowrap' }}>
|
|
93
|
+
{formatTimeShort(at, locale)}
|
|
94
|
+
</Text>
|
|
95
|
+
</Group>
|
|
96
|
+
</UnstyledButton>
|
|
97
|
+
{open ? (
|
|
98
|
+
<Stack gap={6} pb="xs" px={4}>
|
|
99
|
+
<Text size="xs" c="gray.5">
|
|
100
|
+
{formatWhen(at, locale)}
|
|
101
|
+
</Text>
|
|
102
|
+
<Box
|
|
103
|
+
component="pre"
|
|
104
|
+
style={{
|
|
105
|
+
fontFamily: 'monospace',
|
|
106
|
+
fontSize: 11,
|
|
107
|
+
whiteSpace: 'pre-wrap',
|
|
108
|
+
wordBreak: 'break-word',
|
|
109
|
+
background: 'rgba(255,255,255,0.06)',
|
|
110
|
+
borderRadius: 6,
|
|
111
|
+
padding: 8,
|
|
112
|
+
color: '#f8f9fa',
|
|
113
|
+
margin: 0,
|
|
114
|
+
}}
|
|
115
|
+
>
|
|
116
|
+
{JSON.stringify(detail, null, 2)}
|
|
117
|
+
</Box>
|
|
118
|
+
</Stack>
|
|
119
|
+
) : null}
|
|
120
|
+
</Box>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Simulator Events tab (ADR-0010): TWO stacked read-only sections — the fake analytics adapter's
|
|
125
|
+
* event log (dev telemetry, observation only), and below a labeled divider the durable audit trail,
|
|
126
|
+
* the compliance-grade product record. Keeping audit here rather than in an eighth tab
|
|
127
|
+
* respects the events-are-observations doctrine while making clear these are different KINDS of record.
|
|
128
|
+
* Compact dark-skin rows that expand to the full timestamp + details (this screen renders only inside
|
|
129
|
+
* the Simulator <aside>, so it shares the panel's dark palette rather than a light box). */
|
|
130
|
+
export function EventsApp({ events, audit = [] }: { events: AnalyticsEvent[]; audit?: AuditEntry[] }) {
|
|
131
|
+
const t = useTranslations('events')
|
|
132
|
+
const [openEventId, setOpenEventId] = useState<string | null>(null)
|
|
133
|
+
const [openAuditId, setOpenAuditId] = useState<string | null>(null)
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
// No landmark: this screen renders only inside the Simulator <aside>, never as a page.
|
|
137
|
+
<Stack gap="md">
|
|
138
|
+
<Stack gap={4}>
|
|
139
|
+
<Text size="xs" fw={700} c="gray.4" tt="uppercase" data-testid="events-heading">
|
|
140
|
+
{t('analyticsHeading')}
|
|
141
|
+
</Text>
|
|
142
|
+
{events.length === 0 ? (
|
|
143
|
+
<Text size="sm" c="gray.5" data-testid="events-empty">
|
|
144
|
+
{t('empty')}
|
|
145
|
+
</Text>
|
|
146
|
+
) : (
|
|
147
|
+
<Stack gap={0} data-testid="events-list">
|
|
148
|
+
{events.map((event) => {
|
|
149
|
+
// The one-line hint prefers a page path, then a tenant slug — either identifies
|
|
150
|
+
// the event at a glance. Only strings qualify (properties is loose).
|
|
151
|
+
const path = event.properties?.['path']
|
|
152
|
+
const tenant = event.properties?.['tenant']
|
|
153
|
+
const hint = typeof path === 'string' ? path : typeof tenant === 'string' ? tenant : null
|
|
154
|
+
return (
|
|
155
|
+
<LogRow
|
|
156
|
+
key={event.id}
|
|
157
|
+
id={event.id}
|
|
158
|
+
testidPrefix="event"
|
|
159
|
+
title={event.event}
|
|
160
|
+
hint={hint}
|
|
161
|
+
at={event.at}
|
|
162
|
+
open={event.id === openEventId}
|
|
163
|
+
onToggle={() => setOpenEventId(event.id === openEventId ? null : event.id)}
|
|
164
|
+
detail={event.properties ?? {}}
|
|
165
|
+
glyph={t('toggleGlyph')}
|
|
166
|
+
/>
|
|
167
|
+
)
|
|
168
|
+
})}
|
|
169
|
+
</Stack>
|
|
170
|
+
)}
|
|
171
|
+
</Stack>
|
|
172
|
+
|
|
173
|
+
<Divider label={t('auditHeading')} labelPosition="left" color="dark.4" data-testid="audit-divider" />
|
|
174
|
+
|
|
175
|
+
{audit.length === 0 ? (
|
|
176
|
+
<Text size="sm" c="gray.5" data-testid="audit-empty">
|
|
177
|
+
{t('auditEmpty')}
|
|
178
|
+
</Text>
|
|
179
|
+
) : (
|
|
180
|
+
<Stack gap={0} data-testid="audit-list">
|
|
181
|
+
{audit.map((entry) => {
|
|
182
|
+
// Cross-tenant god view: the org (then tenant) slug identifies the record at a glance.
|
|
183
|
+
const hint = entry.orgSlug ?? entry.tenantSlug ?? null
|
|
184
|
+
return (
|
|
185
|
+
<LogRow
|
|
186
|
+
key={entry.id}
|
|
187
|
+
id={entry.id}
|
|
188
|
+
testidPrefix="audit"
|
|
189
|
+
title={entry.action}
|
|
190
|
+
hint={hint}
|
|
191
|
+
at={entry.at}
|
|
192
|
+
open={entry.id === openAuditId}
|
|
193
|
+
onToggle={() => setOpenAuditId(entry.id === openAuditId ? null : entry.id)}
|
|
194
|
+
detail={{
|
|
195
|
+
subjectType: entry.subjectType,
|
|
196
|
+
subjectId: entry.subjectId,
|
|
197
|
+
actorUserId: entry.actorUserId,
|
|
198
|
+
tenant: entry.tenantSlug ?? null,
|
|
199
|
+
org: entry.orgSlug ?? null,
|
|
200
|
+
detail: entry.detail ?? null,
|
|
201
|
+
}}
|
|
202
|
+
glyph={t('toggleGlyph')}
|
|
203
|
+
/>
|
|
204
|
+
)
|
|
205
|
+
})}
|
|
206
|
+
</Stack>
|
|
207
|
+
)}
|
|
208
|
+
</Stack>
|
|
209
|
+
)
|
|
210
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Human timestamp for Simulator surfaces (mail rows, snapshot rows, event log). Falls back to the
|
|
3
|
+
* raw value when it isn't a parseable instant (the static twin stamps some rows with plain
|
|
4
|
+
* labels). Pure helper — locale arrives from the caller's next-intl context.
|
|
5
|
+
*/
|
|
6
|
+
export function formatWhen(value: string, locale: string): string {
|
|
7
|
+
const parsed = Date.parse(value)
|
|
8
|
+
if (Number.isNaN(parsed)) return value
|
|
9
|
+
return new Intl.DateTimeFormat(locale, { dateStyle: 'medium', timeStyle: 'short' }).format(parsed)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Time-only variant for compact rows (the Events log's right-aligned column): drops the date so a
|
|
14
|
+
* narrow row shows just the clock time. Same invalid-instant fallback as formatWhen.
|
|
15
|
+
*/
|
|
16
|
+
export function formatTimeShort(value: string, locale: string): string {
|
|
17
|
+
const parsed = Date.parse(value)
|
|
18
|
+
if (Number.isNaN(parsed)) return value
|
|
19
|
+
return new Intl.DateTimeFormat(locale, { timeStyle: 'short' }).format(parsed)
|
|
20
|
+
}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { Box, Group, Stack, Text, UnstyledButton } from '@mantine/core'
|
|
4
|
+
import { useLocale, useTranslations } from 'next-intl'
|
|
5
|
+
import { useState } from 'react'
|
|
6
|
+
import { chipStyle } from './people-app'
|
|
7
|
+
import { formatWhen } from './format-when'
|
|
8
|
+
|
|
9
|
+
/** One endpoint as the Hooks tab renders it (local shape, decoupled from packages/kit/src/db's WorldEndpoint). */
|
|
10
|
+
export interface HookEndpointRow {
|
|
11
|
+
id: string
|
|
12
|
+
url: string
|
|
13
|
+
eventKinds: string[]
|
|
14
|
+
enabled: boolean
|
|
15
|
+
tenantSlug: string
|
|
16
|
+
orgSlug: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** One delivery + the caught signed body/header (local shape, decoupled from packages/kit/src/db's WorldDelivery). */
|
|
20
|
+
export interface HookDeliveryRow {
|
|
21
|
+
id: string
|
|
22
|
+
endpointUrl: string
|
|
23
|
+
eventKind: string
|
|
24
|
+
status: string
|
|
25
|
+
attemptCount: number
|
|
26
|
+
nextAttemptAt: string
|
|
27
|
+
lastError: string | null
|
|
28
|
+
createdAt: string
|
|
29
|
+
deliveredAt: string | null
|
|
30
|
+
tenantSlug: string
|
|
31
|
+
orgSlug: string
|
|
32
|
+
signature: string | null
|
|
33
|
+
body: string | null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const runButtonStyle = {
|
|
37
|
+
fontSize: 12,
|
|
38
|
+
fontWeight: 600,
|
|
39
|
+
color: '#f8f9fa',
|
|
40
|
+
border: '1px solid #373a40',
|
|
41
|
+
borderRadius: 6,
|
|
42
|
+
padding: '4px 10px',
|
|
43
|
+
} as const
|
|
44
|
+
|
|
45
|
+
const sectionStyle = {
|
|
46
|
+
border: '1px solid rgba(255,255,255,0.18)',
|
|
47
|
+
borderRadius: 8,
|
|
48
|
+
padding: 10,
|
|
49
|
+
} as const
|
|
50
|
+
|
|
51
|
+
/** Colour cue per delivery status — presentational only; the chip label stays the raw enum. */
|
|
52
|
+
function statusColor(status: string): string {
|
|
53
|
+
switch (status) {
|
|
54
|
+
case 'delivered':
|
|
55
|
+
return 'teal.4'
|
|
56
|
+
case 'failed':
|
|
57
|
+
return 'yellow.4'
|
|
58
|
+
case 'dead':
|
|
59
|
+
return 'red.4'
|
|
60
|
+
default:
|
|
61
|
+
return 'gray.4'
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function Endpoints({
|
|
66
|
+
endpoints,
|
|
67
|
+
failingEndpointIds,
|
|
68
|
+
onToggleFail,
|
|
69
|
+
}: {
|
|
70
|
+
endpoints: HookEndpointRow[]
|
|
71
|
+
failingEndpointIds: string[]
|
|
72
|
+
onToggleFail: (endpointId: string, failing: boolean) => void | Promise<void>
|
|
73
|
+
}) {
|
|
74
|
+
const t = useTranslations('webhooks')
|
|
75
|
+
const failing = new Set(failingEndpointIds)
|
|
76
|
+
const [busy, setBusy] = useState(false)
|
|
77
|
+
|
|
78
|
+
const run = (action: () => void | Promise<void>) => {
|
|
79
|
+
setBusy(true)
|
|
80
|
+
void Promise.resolve(action()).finally(() => setBusy(false))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<Box style={sectionStyle} data-testid="simulator-hook-endpoints">
|
|
85
|
+
<Text size="xs" fw={700} c="gray.0" mb={6}>
|
|
86
|
+
{t('simulatorEndpointsTitle')}
|
|
87
|
+
</Text>
|
|
88
|
+
{endpoints.length === 0 ? (
|
|
89
|
+
<Text size="xs" c="gray.5" data-testid="simulator-hook-endpoints-empty">
|
|
90
|
+
{t('simulatorEndpointsEmpty')}
|
|
91
|
+
</Text>
|
|
92
|
+
) : (
|
|
93
|
+
<Stack gap={6}>
|
|
94
|
+
{endpoints.map((endpoint) => {
|
|
95
|
+
const isFailing = failing.has(endpoint.id)
|
|
96
|
+
return (
|
|
97
|
+
<Box
|
|
98
|
+
key={endpoint.id}
|
|
99
|
+
data-testid={`simulator-hook-endpoint-${endpoint.id}`}
|
|
100
|
+
style={{
|
|
101
|
+
border: '1px solid rgba(255,255,255,0.12)',
|
|
102
|
+
borderRadius: 6,
|
|
103
|
+
padding: '6px 8px',
|
|
104
|
+
}}
|
|
105
|
+
>
|
|
106
|
+
<Group justify="space-between" wrap="nowrap" gap="xs" align="start">
|
|
107
|
+
<Stack gap={2} style={{ minWidth: 0 }}>
|
|
108
|
+
<Text size="sm" fw={600} c="gray.0" truncate>
|
|
109
|
+
{endpoint.url}
|
|
110
|
+
</Text>
|
|
111
|
+
<Text size="xs" c="gray.4" truncate>
|
|
112
|
+
{endpoint.eventKinds.join(', ')}
|
|
113
|
+
</Text>
|
|
114
|
+
<Group gap={4} wrap="wrap">
|
|
115
|
+
<Text size="xs" c="gray.3" style={chipStyle}>
|
|
116
|
+
{endpoint.tenantSlug}
|
|
117
|
+
</Text>
|
|
118
|
+
<Text size="xs" c="gray.3" style={chipStyle}>
|
|
119
|
+
{endpoint.orgSlug}
|
|
120
|
+
</Text>
|
|
121
|
+
<Text
|
|
122
|
+
size="xs"
|
|
123
|
+
fw={700}
|
|
124
|
+
c={endpoint.enabled ? 'teal.4' : 'gray.5'}
|
|
125
|
+
style={chipStyle}
|
|
126
|
+
>
|
|
127
|
+
{endpoint.enabled ? t('enabled') : t('disabled')}
|
|
128
|
+
</Text>
|
|
129
|
+
</Group>
|
|
130
|
+
</Stack>
|
|
131
|
+
<UnstyledButton
|
|
132
|
+
data-testid={`simulator-hook-fail-${endpoint.id}`}
|
|
133
|
+
disabled={busy}
|
|
134
|
+
onClick={() => run(() => onToggleFail(endpoint.id, !isFailing))}
|
|
135
|
+
style={{
|
|
136
|
+
...runButtonStyle,
|
|
137
|
+
flexShrink: 0,
|
|
138
|
+
opacity: busy ? 0.6 : 1,
|
|
139
|
+
color: isFailing ? '#ffd43b' : '#f8f9fa',
|
|
140
|
+
}}
|
|
141
|
+
>
|
|
142
|
+
{isFailing ? t('simulatorRecover') : t('simulatorFail')}
|
|
143
|
+
</UnstyledButton>
|
|
144
|
+
</Group>
|
|
145
|
+
</Box>
|
|
146
|
+
)
|
|
147
|
+
})}
|
|
148
|
+
</Stack>
|
|
149
|
+
)}
|
|
150
|
+
</Box>
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function Deliveries({ deliveries }: { deliveries: HookDeliveryRow[] }) {
|
|
155
|
+
const t = useTranslations('webhooks')
|
|
156
|
+
const locale = useLocale()
|
|
157
|
+
const [openId, setOpenId] = useState<string | null>(null)
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<Box style={sectionStyle} data-testid="simulator-hook-deliveries">
|
|
161
|
+
<Text size="xs" fw={700} c="gray.0" mb={6}>
|
|
162
|
+
{t('simulatorDeliveriesTitle')}
|
|
163
|
+
</Text>
|
|
164
|
+
{deliveries.length === 0 ? (
|
|
165
|
+
<Text size="xs" c="gray.5" data-testid="simulator-hook-deliveries-empty">
|
|
166
|
+
{t('simulatorDeliveriesEmpty')}
|
|
167
|
+
</Text>
|
|
168
|
+
) : (
|
|
169
|
+
<Stack gap={6}>
|
|
170
|
+
{deliveries.map((delivery) => {
|
|
171
|
+
const open = delivery.id === openId
|
|
172
|
+
return (
|
|
173
|
+
<Box
|
|
174
|
+
key={delivery.id}
|
|
175
|
+
data-testid={`simulator-hook-delivery-${delivery.id}`}
|
|
176
|
+
style={{ border: '1px solid rgba(255,255,255,0.12)', borderRadius: 6 }}
|
|
177
|
+
>
|
|
178
|
+
<UnstyledButton
|
|
179
|
+
data-testid={`simulator-hook-delivery-toggle-${delivery.id}`}
|
|
180
|
+
aria-expanded={open}
|
|
181
|
+
onClick={() => setOpenId(open ? null : delivery.id)}
|
|
182
|
+
style={{ display: 'block', width: '100%', padding: '6px 8px' }}
|
|
183
|
+
>
|
|
184
|
+
<Group justify="space-between" wrap="nowrap" gap="xs" align="start">
|
|
185
|
+
<Stack gap={2} style={{ minWidth: 0 }}>
|
|
186
|
+
<Text size="sm" fw={600} c="gray.0" truncate>
|
|
187
|
+
{delivery.eventKind}
|
|
188
|
+
</Text>
|
|
189
|
+
<Text size="xs" c="gray.4" truncate>
|
|
190
|
+
{delivery.endpointUrl}
|
|
191
|
+
</Text>
|
|
192
|
+
</Stack>
|
|
193
|
+
<Stack gap={2} align="end" style={{ flexShrink: 0 }}>
|
|
194
|
+
<Text
|
|
195
|
+
size="xs"
|
|
196
|
+
fw={700}
|
|
197
|
+
c={statusColor(delivery.status)}
|
|
198
|
+
style={chipStyle}
|
|
199
|
+
data-testid={`simulator-hook-delivery-status-${delivery.id}`}
|
|
200
|
+
>
|
|
201
|
+
{delivery.status}
|
|
202
|
+
</Text>
|
|
203
|
+
<Text
|
|
204
|
+
size="xs"
|
|
205
|
+
c="gray.5"
|
|
206
|
+
style={{ whiteSpace: 'nowrap' }}
|
|
207
|
+
data-testid={`simulator-hook-delivery-attempts-${delivery.id}`}
|
|
208
|
+
>
|
|
209
|
+
{t('simulatorAttempts', { count: delivery.attemptCount })}
|
|
210
|
+
</Text>
|
|
211
|
+
</Stack>
|
|
212
|
+
</Group>
|
|
213
|
+
</UnstyledButton>
|
|
214
|
+
{open ? (
|
|
215
|
+
<Box px={8} pb="xs" style={{ color: '#f8f9fa' }}>
|
|
216
|
+
<Text size="xs" c="gray.5">
|
|
217
|
+
{t('simulatorNextRetry', {
|
|
218
|
+
when: formatWhen(delivery.nextAttemptAt, locale),
|
|
219
|
+
})}
|
|
220
|
+
</Text>
|
|
221
|
+
{delivery.lastError ? (
|
|
222
|
+
<Text
|
|
223
|
+
size="xs"
|
|
224
|
+
c="red.4"
|
|
225
|
+
data-testid={`simulator-hook-delivery-error-${delivery.id}`}
|
|
226
|
+
>
|
|
227
|
+
{delivery.lastError}
|
|
228
|
+
</Text>
|
|
229
|
+
) : null}
|
|
230
|
+
{delivery.signature ? (
|
|
231
|
+
<>
|
|
232
|
+
<Text size="xs" fw={700} c="gray.3" mt={4}>
|
|
233
|
+
{t('simulatorSignature')}
|
|
234
|
+
</Text>
|
|
235
|
+
<Text
|
|
236
|
+
size="xs"
|
|
237
|
+
c="gray.4"
|
|
238
|
+
data-testid={`simulator-hook-delivery-signature-${delivery.id}`}
|
|
239
|
+
style={{ wordBreak: 'break-all', fontFamily: 'monospace' }}
|
|
240
|
+
>
|
|
241
|
+
{delivery.signature}
|
|
242
|
+
</Text>
|
|
243
|
+
</>
|
|
244
|
+
) : null}
|
|
245
|
+
{delivery.body ? (
|
|
246
|
+
<>
|
|
247
|
+
<Text size="xs" fw={700} c="gray.3" mt={4}>
|
|
248
|
+
{t('simulatorBody')}
|
|
249
|
+
</Text>
|
|
250
|
+
<Text
|
|
251
|
+
size="xs"
|
|
252
|
+
c="gray.4"
|
|
253
|
+
component="pre"
|
|
254
|
+
data-testid={`simulator-hook-delivery-body-${delivery.id}`}
|
|
255
|
+
style={{
|
|
256
|
+
whiteSpace: 'pre-wrap',
|
|
257
|
+
wordBreak: 'break-all',
|
|
258
|
+
fontFamily: 'monospace',
|
|
259
|
+
margin: 0,
|
|
260
|
+
}}
|
|
261
|
+
>
|
|
262
|
+
{delivery.body}
|
|
263
|
+
</Text>
|
|
264
|
+
</>
|
|
265
|
+
) : null}
|
|
266
|
+
</Box>
|
|
267
|
+
) : null}
|
|
268
|
+
</Box>
|
|
269
|
+
)
|
|
270
|
+
})}
|
|
271
|
+
</Stack>
|
|
272
|
+
)}
|
|
273
|
+
</Box>
|
|
274
|
+
)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Router-agnostic Simulator Hooks tab (ADR-0006 twin lives in @sssb/kit/demo-static): the simulated world's
|
|
279
|
+
* outbound-webhook surface. Shows every endpoint (with a per-endpoint failure toggle that
|
|
280
|
+
* drives the fake dispatch) and every delivery (status, attempts, next retry, and the caught signed
|
|
281
|
+
* body + signature header, inspectable), plus a "deliver due now" button. Dark-skinned to match
|
|
282
|
+
* the other world tabs; presentational only — the host owns fetching and the mutations.
|
|
283
|
+
*/
|
|
284
|
+
export function HooksApp({
|
|
285
|
+
endpoints,
|
|
286
|
+
deliveries,
|
|
287
|
+
failingEndpointIds,
|
|
288
|
+
onToggleFail,
|
|
289
|
+
onRunDue,
|
|
290
|
+
}: {
|
|
291
|
+
endpoints: HookEndpointRow[]
|
|
292
|
+
deliveries: HookDeliveryRow[]
|
|
293
|
+
failingEndpointIds: string[]
|
|
294
|
+
onToggleFail: (endpointId: string, failing: boolean) => void | Promise<void>
|
|
295
|
+
onRunDue: () => void | Promise<void>
|
|
296
|
+
}) {
|
|
297
|
+
const t = useTranslations('webhooks')
|
|
298
|
+
const [busy, setBusy] = useState(false)
|
|
299
|
+
|
|
300
|
+
return (
|
|
301
|
+
<Stack gap="sm" data-testid="simulator-hooks">
|
|
302
|
+
<Group justify="flex-end">
|
|
303
|
+
<UnstyledButton
|
|
304
|
+
data-testid="simulator-hooks-run-due"
|
|
305
|
+
disabled={busy}
|
|
306
|
+
onClick={() => {
|
|
307
|
+
setBusy(true)
|
|
308
|
+
void Promise.resolve(onRunDue()).finally(() => setBusy(false))
|
|
309
|
+
}}
|
|
310
|
+
style={{ ...runButtonStyle, opacity: busy ? 0.6 : 1 }}
|
|
311
|
+
>
|
|
312
|
+
{t('simulatorRunDue')}
|
|
313
|
+
</UnstyledButton>
|
|
314
|
+
</Group>
|
|
315
|
+
<Endpoints endpoints={endpoints} failingEndpointIds={failingEndpointIds} onToggleFail={onToggleFail} />
|
|
316
|
+
<Deliveries deliveries={deliveries} />
|
|
317
|
+
</Stack>
|
|
318
|
+
)
|
|
319
|
+
}
|