@kerf-js/veneer 0.0.0-stage → 0.1.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 +16 -0
- package/README.md +1338 -2
- package/package.json +56 -3
- package/plugin.d.mts +187 -0
- package/plugin.mjs +399 -0
- package/src/Accordion.tsx +98 -0
- package/src/Alert.tsx +55 -0
- package/src/Badge.tsx +39 -0
- package/src/Button.tsx +175 -0
- package/src/Calendar-month.tsx +140 -0
- package/src/Calendar.tsx +335 -0
- package/src/Canvas.tsx +221 -0
- package/src/Card.tsx +85 -0
- package/src/Chart.tsx +278 -0
- package/src/Charts.tsx +158 -0
- package/src/Chip.tsx +61 -0
- package/src/Choice-checkbox.tsx +53 -0
- package/src/Choice-parts.tsx +7 -0
- package/src/Choice-radio.tsx +78 -0
- package/src/Choice-segmented.tsx +76 -0
- package/src/Choice-switch.tsx +51 -0
- package/src/Choice.tsx +4 -0
- package/src/CloseX.tsx +14 -0
- package/src/CodeBlock.tsx +81 -0
- package/src/CodeInput.tsx +256 -0
- package/src/Combobox.tsx +281 -0
- package/src/CommandPalette-controller.ts +314 -0
- package/src/CommandPalette-rows.tsx +137 -0
- package/src/CommandPalette.tsx +196 -0
- package/src/DataGrid-actions.ts +119 -0
- package/src/DataGrid-body.tsx +58 -0
- package/src/DataGrid-controller.ts +145 -0
- package/src/DataGrid-header.tsx +108 -0
- package/src/DataGrid-model.ts +248 -0
- package/src/DataGrid-pivot.tsx +108 -0
- package/src/DataGrid-rows.tsx +296 -0
- package/src/DataGrid-toolbar.tsx +127 -0
- package/src/DataGrid-tree.ts +149 -0
- package/src/DataGrid-viewport.tsx +37 -0
- package/src/DataGrid.tsx +145 -0
- package/src/DateField-presets.tsx +27 -0
- package/src/DateField-range.tsx +370 -0
- package/src/DateField.tsx +295 -0
- package/src/Dither.tsx +313 -0
- package/src/Drawer.tsx +123 -0
- package/src/DurationField.tsx +227 -0
- package/src/Feed.tsx +78 -0
- package/src/Field/view.tsx +147 -0
- package/src/Field.tsx +238 -0
- package/src/HamburgerMenu.tsx +119 -0
- package/src/Icon.tsx +15 -0
- package/src/Kbd.tsx +6 -0
- package/src/KeyValueEditor/actions.ts +75 -0
- package/src/KeyValueEditor/rows.tsx +104 -0
- package/src/KeyValueEditor.tsx +112 -0
- package/src/Layout.tsx +221 -0
- package/src/Markdown.tsx +127 -0
- package/src/MentionsInput/actions.ts +161 -0
- package/src/MentionsInput/end.tsx +82 -0
- package/src/MentionsInput.tsx +103 -0
- package/src/Menu.tsx +221 -0
- package/src/Modal.tsx +109 -0
- package/src/MonthPicker/month.tsx +117 -0
- package/src/MonthPicker/period.tsx +197 -0
- package/src/MonthPicker/shared.tsx +272 -0
- package/src/MonthPicker/week.tsx +103 -0
- package/src/MonthPicker.tsx +11 -0
- package/src/MultiSelect.tsx +139 -0
- package/src/Nav.tsx +36 -0
- package/src/NumberField.tsx +156 -0
- package/src/Pagination.tsx +335 -0
- package/src/PaymentCard.tsx +111 -0
- package/src/Picker.tsx +228 -0
- package/src/PlaceField.tsx +285 -0
- package/src/Popover.tsx +88 -0
- package/src/Presence.tsx +37 -0
- package/src/Progress.tsx +71 -0
- package/src/RecurrenceField.tsx +372 -0
- package/src/RichSelect/codes.tsx +94 -0
- package/src/RichSelect/list.tsx +380 -0
- package/src/RichSelect/phone-view.tsx +114 -0
- package/src/RichSelect/phone.tsx +305 -0
- package/src/RichSelect/search-keys.ts +28 -0
- package/src/RichSelect/timezone.tsx +53 -0
- package/src/RichSelect.tsx +13 -0
- package/src/RichTextEditor/controller.tsx +305 -0
- package/src/RichTextEditor/editor.tsx +61 -0
- package/src/RichTextEditor/tools.tsx +132 -0
- package/src/RichTextEditor/view.tsx +210 -0
- package/src/RichTextEditor.tsx +9 -0
- package/src/ScrollGrid/measure.ts +39 -0
- package/src/ScrollGrid/parts.tsx +112 -0
- package/src/ScrollGrid.tsx +375 -0
- package/src/ScrollRail.tsx +114 -0
- package/src/ScrollView.tsx +57 -0
- package/src/Segments/controller.tsx +148 -0
- package/src/Segments/events.ts +99 -0
- package/src/Segments/view.tsx +77 -0
- package/src/Segments.tsx +2 -0
- package/src/Select.tsx +343 -0
- package/src/Shape.tsx +41 -0
- package/src/Shell/branches.tsx +108 -0
- package/src/Shell/button.tsx +33 -0
- package/src/Shell/shared.tsx +220 -0
- package/src/Shell/shell.tsx +25 -0
- package/src/Shell/state.ts +138 -0
- package/src/Shell/view.tsx +280 -0
- package/src/Shell.tsx +17 -0
- package/src/SideNav/sections.tsx +50 -0
- package/src/SideNav/state.ts +140 -0
- package/src/SideNav.tsx +130 -0
- package/src/SideNavTitle.tsx +25 -0
- package/src/SignaturePad/state.ts +172 -0
- package/src/SignaturePad/view.tsx +69 -0
- package/src/SignaturePad.tsx +76 -0
- package/src/Skeleton.tsx +46 -0
- package/src/Slider.tsx +81 -0
- package/src/Spinner.tsx +21 -0
- package/src/Stage-director.ts +361 -0
- package/src/Stage-look.ts +75 -0
- package/src/Stage-poster.tsx +62 -0
- package/src/Stage-types.ts +206 -0
- package/src/Stage.tsx +147 -0
- package/src/TabBar.tsx +114 -0
- package/src/Table-actions.tsx +51 -0
- package/src/Table-base.ts +70 -0
- package/src/Table-body.tsx +84 -0
- package/src/Table-columns.tsx +58 -0
- package/src/Table-details.tsx +66 -0
- package/src/Table-editor.tsx +66 -0
- package/src/Table-head.tsx +52 -0
- package/src/Table-model.ts +82 -0
- package/src/Table-notice.ts +39 -0
- package/src/Table-paging.ts +50 -0
- package/src/Table-rows.tsx +308 -0
- package/src/Table-selection.ts +63 -0
- package/src/Table-sortbar.tsx +41 -0
- package/src/Table-source.ts +66 -0
- package/src/Table-toolbar.tsx +71 -0
- package/src/Table-types.ts +115 -0
- package/src/Table-view.tsx +87 -0
- package/src/Table.tsx +31 -0
- package/src/Tabs.tsx +129 -0
- package/src/Tag.tsx +40 -0
- package/src/Ticker.tsx +42 -0
- package/src/TimeField-date-model.ts +77 -0
- package/src/TimeField-date-view.tsx +152 -0
- package/src/TimeField-model.ts +80 -0
- package/src/TimeField-options.tsx +224 -0
- package/src/TimeField-slots.tsx +32 -0
- package/src/TimeField-types.ts +33 -0
- package/src/TimeField-view.tsx +124 -0
- package/src/TimeField.tsx +126 -0
- package/src/Toast.tsx +143 -0
- package/src/Toggle.tsx +75 -0
- package/src/Tooltip.tsx +69 -0
- package/src/Type.tsx +136 -0
- package/src/VirtualList-controls.ts +105 -0
- package/src/VirtualList-data.ts +43 -0
- package/src/VirtualList-measure.ts +169 -0
- package/src/VirtualList-metrics.ts +41 -0
- package/src/VirtualList-mount.ts +145 -0
- package/src/VirtualList-rows.tsx +91 -0
- package/src/VirtualList-types.ts +76 -0
- package/src/VirtualList-view.tsx +123 -0
- package/src/VirtualList.tsx +81 -0
- package/src/admin/ApiKeys-actions.ts +124 -0
- package/src/admin/ApiKeys-form.tsx +64 -0
- package/src/admin/ApiKeys-view.tsx +101 -0
- package/src/admin/ApiKeys.tsx +224 -0
- package/src/admin/Audit.tsx +246 -0
- package/src/admin/Billing.tsx +307 -0
- package/src/admin/Cart.tsx +177 -0
- package/src/admin/Checkout-address.tsx +125 -0
- package/src/admin/Checkout-cart.tsx +78 -0
- package/src/admin/Checkout-coupon.ts +34 -0
- package/src/admin/Checkout-done.tsx +31 -0
- package/src/admin/Checkout-model.ts +33 -0
- package/src/admin/Checkout-navigation.ts +76 -0
- package/src/admin/Checkout-payment-view.tsx +49 -0
- package/src/admin/Checkout-payment.ts +80 -0
- package/src/admin/Checkout-review.tsx +60 -0
- package/src/admin/Checkout-shipping.tsx +47 -0
- package/src/admin/Checkout-state.ts +122 -0
- package/src/admin/Checkout-steps.ts +10 -0
- package/src/admin/Checkout-summary.tsx +97 -0
- package/src/admin/Checkout-types.ts +60 -0
- package/src/admin/Checkout-view.tsx +51 -0
- package/src/admin/Checkout.tsx +72 -0
- package/src/admin/CsvImport-actions.ts +131 -0
- package/src/admin/CsvImport.tsx +379 -0
- package/src/admin/Danger.tsx +240 -0
- package/src/admin/Integrations/Card.tsx +82 -0
- package/src/admin/Integrations/Webhooks.tsx +341 -0
- package/src/admin/Integrations.tsx +169 -0
- package/src/admin/InviteDialog.tsx +153 -0
- package/src/admin/Members/columns.tsx +181 -0
- package/src/admin/Members.tsx +316 -0
- package/src/admin/Order.tsx +115 -0
- package/src/admin/PlainTable.tsx +34 -0
- package/src/admin/Plans.tsx +375 -0
- package/src/admin/SaveBar/actions.ts +86 -0
- package/src/admin/SaveBar.tsx +153 -0
- package/src/admin/Secret.tsx +74 -0
- package/src/admin/Settings.tsx +145 -0
- package/src/admin/StepBar.tsx +66 -0
- package/src/admin/TagsInput/actions.ts +60 -0
- package/src/admin/TagsInput.tsx +95 -0
- package/src/admin/atoms.tsx +73 -0
- package/src/admin/index.ts +67 -0
- package/src/agent/Actions/reasons.tsx +38 -0
- package/src/agent/Actions.tsx +166 -0
- package/src/agent/AgentPlan.tsx +86 -0
- package/src/agent/ArtifactPanel.tsx +299 -0
- package/src/agent/Assistant.tsx +168 -0
- package/src/agent/Checkpoint.tsx +19 -0
- package/src/agent/Cite.tsx +70 -0
- package/src/agent/ContextMeter.tsx +70 -0
- package/src/agent/Conversation.tsx +70 -0
- package/src/agent/Message.tsx +92 -0
- package/src/agent/ModelPicker.tsx +167 -0
- package/src/agent/Prompt-model.ts +118 -0
- package/src/agent/Prompt-view.tsx +246 -0
- package/src/agent/Prompt.tsx +128 -0
- package/src/agent/Prose.tsx +118 -0
- package/src/agent/Question.tsx +137 -0
- package/src/agent/Reasoning.tsx +31 -0
- package/src/agent/Shimmer.tsx +11 -0
- package/src/agent/Sources.tsx +23 -0
- package/src/agent/SpeechInput.tsx +243 -0
- package/src/agent/Suggestions.tsx +36 -0
- package/src/agent/ToolCall.tsx +219 -0
- package/src/agent/TraceViewer.tsx +96 -0
- package/src/agent/bits.tsx +88 -0
- package/src/agent/index.ts +38 -0
- package/src/bind.ts +57 -0
- package/src/collab/AutoTrack.tsx +91 -0
- package/src/collab/Comments.tsx +204 -0
- package/src/collab/Composer/state.ts +125 -0
- package/src/collab/Composer/view.tsx +155 -0
- package/src/collab/Composer.tsx +141 -0
- package/src/collab/ConversationList.tsx +120 -0
- package/src/collab/Cursors.tsx +71 -0
- package/src/collab/DataIntegrity.tsx +103 -0
- package/src/collab/Kanban-card.ts +74 -0
- package/src/collab/Kanban.tsx +368 -0
- package/src/collab/Lock.tsx +36 -0
- package/src/collab/PresenceStack.tsx +176 -0
- package/src/collab/ShareDialog.tsx +273 -0
- package/src/collab/Status.tsx +101 -0
- package/src/collab/SyncedForm.tsx +42 -0
- package/src/collab/Thread/Message.tsx +265 -0
- package/src/collab/Thread/rows.tsx +56 -0
- package/src/collab/Thread.tsx +323 -0
- package/src/collab/VersionHistory.tsx +173 -0
- package/src/collab/ViewportRail.tsx +73 -0
- package/src/collab/index.ts +37 -0
- package/src/collab/peer.tsx +42 -0
- package/src/fields.ts +5 -0
- package/src/flow/AuthScreen.tsx +81 -0
- package/src/flow/AuthSteps.tsx +296 -0
- package/src/flow/Checklist.tsx +211 -0
- package/src/flow/ConnBanner.tsx +304 -0
- package/src/flow/Flow.tsx +97 -0
- package/src/flow/MfaSetup.tsx +244 -0
- package/src/flow/Otp.tsx +243 -0
- package/src/flow/ReauthDialog.tsx +79 -0
- package/src/flow/ShortcutsOverlay.tsx +121 -0
- package/src/flow/SignGate.tsx +184 -0
- package/src/flow/SignIn.tsx +136 -0
- package/src/flow/SignUp.tsx +149 -0
- package/src/flow/Sso.tsx +96 -0
- package/src/flow/SystemPage/accounts.tsx +74 -0
- package/src/flow/SystemPage/art.tsx +113 -0
- package/src/flow/SystemPage.tsx +395 -0
- package/src/flow/Tour.tsx +207 -0
- package/src/flow/index.ts +29 -0
- package/src/flow/kit.tsx +334 -0
- package/src/index.ts +237 -0
- package/src/layout.css +4 -0
- package/src/links.css +4 -0
- package/src/live/ActivityFeed.tsx +88 -0
- package/src/live/Bell.tsx +108 -0
- package/src/live/Connection.tsx +113 -0
- package/src/live/Inbox.tsx +113 -0
- package/src/live/InboxFeed.tsx +67 -0
- package/src/live/InboxGestures.ts +41 -0
- package/src/live/InboxHandlers.ts +102 -0
- package/src/live/InboxHeader.tsx +81 -0
- package/src/live/InboxModel.ts +81 -0
- package/src/live/InboxRow.tsx +125 -0
- package/src/live/MeetingRoom.tsx +22 -0
- package/src/live/MeetingRoomControlBar.tsx +197 -0
- package/src/live/MeetingRoomHandlers.ts +53 -0
- package/src/live/MeetingRoomLayout.tsx +27 -0
- package/src/live/MeetingRoomModel.ts +49 -0
- package/src/live/MeetingRoomMount.ts +49 -0
- package/src/live/MeetingRoomParts.tsx +178 -0
- package/src/live/MeetingRoomPerson.tsx +21 -0
- package/src/live/MeetingRoomState.ts +88 -0
- package/src/live/MeetingRoomTile.tsx +84 -0
- package/src/live/MeetingRoomTypes.ts +68 -0
- package/src/live/MeetingRoomView.tsx +36 -0
- package/src/live/NotificationPreferences.tsx +99 -0
- package/src/live/NotificationPreferencesActions.ts +55 -0
- package/src/live/NotificationPreferencesCell.tsx +26 -0
- package/src/live/NotificationPreferencesCells.tsx +59 -0
- package/src/live/NotificationPreferencesGrid.tsx +129 -0
- package/src/live/NotificationPreferencesModel.tsx +91 -0
- package/src/live/NotificationPreferencesSave.ts +85 -0
- package/src/live/NotificationPreferencesWatch.ts +31 -0
- package/src/live/Prejoin.tsx +238 -0
- package/src/live/PrejoinMeter.tsx +26 -0
- package/src/live/PrejoinPreview.tsx +53 -0
- package/src/live/PushSoftAsk.tsx +63 -0
- package/src/live/TransportPicker.tsx +341 -0
- package/src/live/TransportPickerDetails.tsx +130 -0
- package/src/live/index.ts +31 -0
- package/src/live/notify.tsx +22 -0
- package/src/live/shared.tsx +110 -0
- package/src/parts.tsx +199 -0
- package/src/plugin/catalog.mjs +129 -0
- package/src/plugin/dtcg.mjs +79 -0
- package/src/plugin/icons.mjs +7 -0
- package/src/plugin/seed.mjs +40 -0
- package/src/plugin/theme-context.mjs +44 -0
- package/src/plugin/theme-css.mjs +143 -0
- package/src/plugin/theme-motion.mjs +43 -0
- package/src/plugin/theme-parts.d.mts +41 -0
- package/src/plugin/theme-parts.mjs +224 -0
- package/src/plugin/theme-text.mjs +93 -0
- package/src/plugin/theme-values.mjs +15 -0
- package/src/plugin/theme.d.mts +82 -0
- package/src/plugin/theme.mjs +316 -0
- package/src/schedule/Agenda.tsx +124 -0
- package/src/schedule/AgendaActions.ts +31 -0
- package/src/schedule/AgendaDay.tsx +124 -0
- package/src/schedule/AgendaGestures.ts +27 -0
- package/src/schedule/AgendaKeys.ts +52 -0
- package/src/schedule/AgendaModel.ts +82 -0
- package/src/schedule/AgendaNavigation.ts +38 -0
- package/src/schedule/AgendaPage.tsx +39 -0
- package/src/schedule/AgendaStrip.tsx +55 -0
- package/src/schedule/AvailabilityEditor-actions.ts +146 -0
- package/src/schedule/AvailabilityEditor-day.tsx +119 -0
- package/src/schedule/AvailabilityEditor-view.tsx +205 -0
- package/src/schedule/AvailabilityEditor.tsx +113 -0
- package/src/schedule/BookingCalendar.tsx +121 -0
- package/src/schedule/BookingCalendarActions.ts +85 -0
- package/src/schedule/BookingCalendarModel.ts +86 -0
- package/src/schedule/BookingCalendarParts.tsx +87 -0
- package/src/schedule/Calendar/AgendaView.tsx +45 -0
- package/src/schedule/Calendar/CalendarDialogs.tsx +105 -0
- package/src/schedule/Calendar/CalendarMain.tsx +47 -0
- package/src/schedule/Calendar/CalendarToolbar.tsx +106 -0
- package/src/schedule/Calendar/Column.tsx +129 -0
- package/src/schedule/Calendar/EventBlock.tsx +71 -0
- package/src/schedule/Calendar/MiniMonth.tsx +169 -0
- package/src/schedule/Calendar/MonthGrid.tsx +296 -0
- package/src/schedule/Calendar/TimeGrid.tsx +252 -0
- package/src/schedule/Calendar/Timeline.tsx +287 -0
- package/src/schedule/Calendar/ZoneChip.tsx +73 -0
- package/src/schedule/Calendar/calendar-shell.ts +160 -0
- package/src/schedule/Calendar/calendar-state.ts +30 -0
- package/src/schedule/Calendar/now-spans.tsx +33 -0
- package/src/schedule/Calendar/shared.ts +3 -0
- package/src/schedule/Calendar/state-actions.ts +189 -0
- package/src/schedule/Calendar/state-base.ts +143 -0
- package/src/schedule/Calendar/state-keys.ts +128 -0
- package/src/schedule/Calendar/time-fit.ts +84 -0
- package/src/schedule/Calendar.tsx +182 -0
- package/src/schedule/EventEditor.tsx +267 -0
- package/src/schedule/EventPopover.tsx +190 -0
- package/src/schedule/MeetingPlanner-model.ts +222 -0
- package/src/schedule/MeetingPlanner-view.tsx +310 -0
- package/src/schedule/MeetingPlanner.tsx +122 -0
- package/src/schedule/MoveSheet.tsx +168 -0
- package/src/schedule/YearView-model.ts +164 -0
- package/src/schedule/YearView-parts.tsx +147 -0
- package/src/schedule/YearView.tsx +100 -0
- package/src/schedule/bits.tsx +65 -0
- package/src/schedule/index.ts +25 -0
- package/src/skeleton-css.ts +4 -0
- package/src/styles.ts +13 -0
- package/src/type.css +15 -0
- package/src/ui.ts +41 -0
- package/src/use-ui.ts +10 -0
- package/tailwind.css +38 -0
- package/tokens/color.mjs +87 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { State } from '@kerf-js/core'
|
|
2
|
+
import { Checkbox } from '../Choice'
|
|
3
|
+
import { Input } from '../Field'
|
|
4
|
+
import { Select } from '../Select'
|
|
5
|
+
|
|
6
|
+
type KeyForm = {
|
|
7
|
+
name: State<string>
|
|
8
|
+
nameError: State<string>
|
|
9
|
+
chosen: State<string[]>
|
|
10
|
+
scopeError: State<string>
|
|
11
|
+
readonly scopes: { value: string; label: string }[]
|
|
12
|
+
expires: State<string>
|
|
13
|
+
readonly expiries: { value: string; label: string }[]
|
|
14
|
+
toggle: (value: string, on: boolean) => void
|
|
15
|
+
make: () => Promise<void>
|
|
16
|
+
setForm: (node: HTMLElement) => void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function keyForm(input: KeyForm) {
|
|
20
|
+
const { name, nameError, chosen, scopeError, expires, toggle, make, setForm } = input
|
|
21
|
+
return (
|
|
22
|
+
<form
|
|
23
|
+
ref={(n) => setForm(n)}
|
|
24
|
+
data-scope="stack"
|
|
25
|
+
style="padding-block-start:var(--veneer-space-related)"
|
|
26
|
+
novalidate
|
|
27
|
+
onSubmit={(e: Event) => {
|
|
28
|
+
e.preventDefault()
|
|
29
|
+
void make()
|
|
30
|
+
}}
|
|
31
|
+
>
|
|
32
|
+
<Input
|
|
33
|
+
label="Key name"
|
|
34
|
+
placeholder="e.g. CI deploys"
|
|
35
|
+
autofocus
|
|
36
|
+
value={name.value}
|
|
37
|
+
error={nameError.value}
|
|
38
|
+
onInput={(e) => {
|
|
39
|
+
name.value = e.currentTarget.value
|
|
40
|
+
nameError.value = ''
|
|
41
|
+
}}
|
|
42
|
+
/>
|
|
43
|
+
<fieldset data-scope="choice">
|
|
44
|
+
<legend>Scopes</legend>
|
|
45
|
+
{input.scopes.map((s) => (
|
|
46
|
+
<Checkbox
|
|
47
|
+
key={s.value}
|
|
48
|
+
checked={chosen.value.includes(s.value)}
|
|
49
|
+
error={s === input.scopes[0] && scopeError.value ? scopeError.value : undefined}
|
|
50
|
+
onChange={(e: Event) => toggle(s.value, (e.currentTarget as HTMLInputElement).checked)}
|
|
51
|
+
>
|
|
52
|
+
{s.label}
|
|
53
|
+
</Checkbox>
|
|
54
|
+
))}
|
|
55
|
+
</fieldset>
|
|
56
|
+
<Select
|
|
57
|
+
label="Expires"
|
|
58
|
+
options={input.expiries}
|
|
59
|
+
value={expires.value}
|
|
60
|
+
onChange={(e: Event) => (expires.value = (e.currentTarget as HTMLInputElement).value)}
|
|
61
|
+
/>
|
|
62
|
+
</form>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { KeyIcon } from '@kerf-js/veneer-icons'
|
|
2
|
+
import type { State } from '@kerf-js/core'
|
|
3
|
+
import { Modal } from '../Modal'
|
|
4
|
+
import { Table, type Column } from '../Table'
|
|
5
|
+
import { ConfirmDialog, TypeToConfirm } from './Danger'
|
|
6
|
+
import { SecretReveal } from './Secret'
|
|
7
|
+
import { keyForm } from './ApiKeys-form'
|
|
8
|
+
import type { ApiKey } from './ApiKeys'
|
|
9
|
+
import type { KeyActionsContext, createKeyActions, revokeKeyActions } from './ApiKeys-actions'
|
|
10
|
+
|
|
11
|
+
type View = KeyActionsContext &
|
|
12
|
+
Pick<ReturnType<typeof createKeyActions>, 'make' | 'toggle'> &
|
|
13
|
+
Pick<ReturnType<typeof revokeKeyActions>, 'gone'> & {
|
|
14
|
+
armed: State<boolean>
|
|
15
|
+
dialog: State<boolean>
|
|
16
|
+
seen: State<boolean>
|
|
17
|
+
title: { readonly value: string }
|
|
18
|
+
tools: { readonly value: unknown }
|
|
19
|
+
footer: { readonly value: unknown }
|
|
20
|
+
columns: Column<ApiKey>[]
|
|
21
|
+
scopes: () => { value: string; label: string }[]
|
|
22
|
+
expiries: () => { value: string; label: string }[]
|
|
23
|
+
setForm: (node: HTMLElement) => void
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function keyView(view: View) {
|
|
27
|
+
const { title, list, columns, tools, armed, dialog, secret, footer } = view
|
|
28
|
+
const { name, seen, nameError, chosen, scopeError, expires } = view
|
|
29
|
+
const { toggle, make, setForm, typedOpen, revoking, gone, plainOpen } = view
|
|
30
|
+
return (
|
|
31
|
+
<div data-scope="stack">
|
|
32
|
+
<Table
|
|
33
|
+
caption={`${title.value === 'live' ? 'Live' : 'Test'} API keys`}
|
|
34
|
+
captionHidden
|
|
35
|
+
rows={list}
|
|
36
|
+
columns={columns}
|
|
37
|
+
picker={false}
|
|
38
|
+
heading={3}
|
|
39
|
+
actions={tools.value}
|
|
40
|
+
empty={{ title: 'No keys yet', text: 'Create one to call the API.' }}
|
|
41
|
+
/>
|
|
42
|
+
{armed.value && (
|
|
43
|
+
<Modal
|
|
44
|
+
open={dialog}
|
|
45
|
+
alert={!!secret.value}
|
|
46
|
+
title={secret.value ? 'Copy your new key' : `Create a ${title.value} key`}
|
|
47
|
+
description={
|
|
48
|
+
secret.value
|
|
49
|
+
? 'You won’t see it again. Store it in your secrets manager now.'
|
|
50
|
+
: 'Give it a name you’ll recognise in the audit log.'
|
|
51
|
+
}
|
|
52
|
+
footer={<>{footer.value}</>}
|
|
53
|
+
>
|
|
54
|
+
{secret.value ? (
|
|
55
|
+
<SecretReveal
|
|
56
|
+
label={name.value}
|
|
57
|
+
secret={secret.value}
|
|
58
|
+
done={seen}
|
|
59
|
+
ack="I’ve saved this key somewhere safe"
|
|
60
|
+
/>
|
|
61
|
+
) : (
|
|
62
|
+
keyForm({
|
|
63
|
+
name,
|
|
64
|
+
nameError,
|
|
65
|
+
chosen,
|
|
66
|
+
scopeError,
|
|
67
|
+
get scopes() {
|
|
68
|
+
return view.scopes()
|
|
69
|
+
},
|
|
70
|
+
expires,
|
|
71
|
+
get expiries() {
|
|
72
|
+
return view.expiries()
|
|
73
|
+
},
|
|
74
|
+
toggle,
|
|
75
|
+
make,
|
|
76
|
+
setForm,
|
|
77
|
+
})
|
|
78
|
+
)}
|
|
79
|
+
</Modal>
|
|
80
|
+
)}
|
|
81
|
+
<TypeToConfirm
|
|
82
|
+
open={typedOpen}
|
|
83
|
+
glyph={KeyIcon}
|
|
84
|
+
title={`Revoke “${revoking.value?.name}”?`}
|
|
85
|
+
description="This key was used in the last 24 hours. Anything using it stops working right away."
|
|
86
|
+
confirmText={revoking.value?.name ?? ''}
|
|
87
|
+
action="Revoke key"
|
|
88
|
+
onConfirm={gone}
|
|
89
|
+
/>
|
|
90
|
+
<ConfirmDialog
|
|
91
|
+
open={plainOpen}
|
|
92
|
+
glyph={KeyIcon}
|
|
93
|
+
tone="critical"
|
|
94
|
+
title={`Revoke “${revoking.value?.name}”?`}
|
|
95
|
+
description="Anything still using it stops working right away."
|
|
96
|
+
action="Revoke key"
|
|
97
|
+
onConfirm={gone}
|
|
98
|
+
/>
|
|
99
|
+
</div>
|
|
100
|
+
)
|
|
101
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { agoText } from '@kerf-js/veneer-core'
|
|
2
|
+
import { derived, state, type State } from '@kerf-js/core'
|
|
3
|
+
import { Badge } from '../Badge'
|
|
4
|
+
import { Button } from '../Button'
|
|
5
|
+
import type { Column } from '../Table'
|
|
6
|
+
import { useReveal } from './Secret'
|
|
7
|
+
import { guarded, latch, read } from './atoms'
|
|
8
|
+
import { createKeyActions, revokeKeyActions } from './ApiKeys-actions'
|
|
9
|
+
import { keyView } from './ApiKeys-view'
|
|
10
|
+
import '../styles'
|
|
11
|
+
import '@kerf-js/veneer-core/styles/flows/tokens.css'
|
|
12
|
+
import '@kerf-js/veneer-core/styles/flows/base.css'
|
|
13
|
+
import '@kerf-js/veneer-core/styles/rich/helpers.css'
|
|
14
|
+
import '@kerf-js/veneer-core/styles/layout/tokens.css'
|
|
15
|
+
import '@kerf-js/veneer-core/styles/layout/row.css'
|
|
16
|
+
import '@kerf-js/veneer-core/styles/layout/stack.css'
|
|
17
|
+
import '@kerf-js/veneer-core/styles/flows/api-key.css'
|
|
18
|
+
import '@kerf-js/veneer-core/styles/flows/choice.css'
|
|
19
|
+
|
|
20
|
+
/** An API key as listed: never the secret, only its prefix. */
|
|
21
|
+
export type ApiKey = {
|
|
22
|
+
id: string
|
|
23
|
+
name: string
|
|
24
|
+
prefix: string
|
|
25
|
+
scopes: string[]
|
|
26
|
+
created: string
|
|
27
|
+
lastUsed?: string
|
|
28
|
+
}
|
|
29
|
+
/** What the create form hands to `onCreate`. */
|
|
30
|
+
export type KeyDraft = { name: string; scopes: string[]; expires: string }
|
|
31
|
+
|
|
32
|
+
/** Props for ApiKeys. */
|
|
33
|
+
export interface ApiKeysProps {
|
|
34
|
+
keys: readonly ApiKey[] | State<readonly ApiKey[]>
|
|
35
|
+
kind?: 'test' | 'live' | undefined
|
|
36
|
+
/** Now, for "last used" and the 24-hour revoke rule. */
|
|
37
|
+
now: string
|
|
38
|
+
scopes?: { value: string; label: string }[]
|
|
39
|
+
expiries?: { value: string; label: string }[]
|
|
40
|
+
/** Fresh credentials first (09 §2.1, a 5-minute grant); false stops. */
|
|
41
|
+
onReauth?: (reason: string) => Promise<boolean>
|
|
42
|
+
/** Returns the full secret, which leaves this component only through the Copy button. */
|
|
43
|
+
onCreate: (draft: KeyDraft) => Promise<string>
|
|
44
|
+
onRevoke: (key: ApiKey) => Promise<void> | void
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const SCOPES = [
|
|
48
|
+
{ value: 'read', label: 'Read projects and deploys' },
|
|
49
|
+
{ value: 'deploy', label: 'Trigger deploys' },
|
|
50
|
+
{ value: 'admin', label: 'Manage members (admins only)' },
|
|
51
|
+
]
|
|
52
|
+
const EXPIRIES = [
|
|
53
|
+
{ value: '30', label: 'In 30 days' },
|
|
54
|
+
{ value: '90', label: 'In 90 days' },
|
|
55
|
+
{ value: 'never', label: 'Never' },
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* API keys (09 §4.2): a DataTable of prefixes. Create asks for re-auth, then name, scopes and expiry, then shows the key
|
|
60
|
+
* once: it can't be dismissed before "I've saved it". Revoke is type-to-confirm when the key was used in the last 24 h.
|
|
61
|
+
* Live keys sit behind SignGate, which the app wraps around this component.
|
|
62
|
+
*/
|
|
63
|
+
export function ApiKeys({
|
|
64
|
+
keys,
|
|
65
|
+
kind = 'test',
|
|
66
|
+
now,
|
|
67
|
+
scopes = SCOPES,
|
|
68
|
+
expiries = EXPIRIES,
|
|
69
|
+
onReauth,
|
|
70
|
+
onCreate,
|
|
71
|
+
onRevoke,
|
|
72
|
+
}: ApiKeysProps) {
|
|
73
|
+
const creating = state(false)
|
|
74
|
+
const { secret, seen } = useReveal(creating)
|
|
75
|
+
const dialog = guarded(creating, () => !secret.value || seen.value)
|
|
76
|
+
const armed = latch(creating)
|
|
77
|
+
const name = state('')
|
|
78
|
+
const chosen = state<string[]>(['read'])
|
|
79
|
+
const expires = state('90')
|
|
80
|
+
const nameError = state('')
|
|
81
|
+
const scopeError = state('')
|
|
82
|
+
const busy = state(false)
|
|
83
|
+
const revoking = state<ApiKey | undefined>(undefined)
|
|
84
|
+
const typedOpen = state(false)
|
|
85
|
+
const plainOpen = state(false)
|
|
86
|
+
let opener: HTMLElement | undefined
|
|
87
|
+
let form: HTMLElement | undefined
|
|
88
|
+
const list = derived(() => read(keys))
|
|
89
|
+
const title = derived(() => (kind === 'live' ? 'live' : 'test'))
|
|
90
|
+
|
|
91
|
+
const context = {
|
|
92
|
+
creating,
|
|
93
|
+
name,
|
|
94
|
+
chosen,
|
|
95
|
+
expires,
|
|
96
|
+
nameError,
|
|
97
|
+
scopeError,
|
|
98
|
+
busy,
|
|
99
|
+
secret,
|
|
100
|
+
list,
|
|
101
|
+
revoking,
|
|
102
|
+
typedOpen,
|
|
103
|
+
plainOpen,
|
|
104
|
+
now: () => now,
|
|
105
|
+
hasReauth: () => !!onReauth,
|
|
106
|
+
onReauth: (reason: string) => onReauth!(reason),
|
|
107
|
+
onCreate: (draft: () => KeyDraft) => onCreate(draft()),
|
|
108
|
+
onRevoke: (key: ApiKey) => onRevoke(key),
|
|
109
|
+
getForm: () => form,
|
|
110
|
+
getOpener: () => opener,
|
|
111
|
+
setOpener: (n: HTMLElement) => (opener = n),
|
|
112
|
+
}
|
|
113
|
+
const { start, make, toggle } = createKeyActions(context)
|
|
114
|
+
const { revoke, gone } = revokeKeyActions(context)
|
|
115
|
+
const columns = apiKeyColumns(
|
|
116
|
+
() => now,
|
|
117
|
+
(k, e) => {
|
|
118
|
+
opener ??= e.currentTarget as HTMLElement
|
|
119
|
+
revoke(k)
|
|
120
|
+
},
|
|
121
|
+
)
|
|
122
|
+
const tools = derived(() => <Button onClick={start}>{`Create ${title.value} key`}</Button>) // one build: Table reads the prop twice
|
|
123
|
+
const footer = keyFooter({ secret, seen, dialog, busy, make })
|
|
124
|
+
return keyView({
|
|
125
|
+
...context,
|
|
126
|
+
make,
|
|
127
|
+
toggle,
|
|
128
|
+
gone,
|
|
129
|
+
armed,
|
|
130
|
+
dialog,
|
|
131
|
+
seen,
|
|
132
|
+
title,
|
|
133
|
+
tools,
|
|
134
|
+
footer,
|
|
135
|
+
columns,
|
|
136
|
+
scopes: () => scopes,
|
|
137
|
+
expiries: () => expiries,
|
|
138
|
+
setForm: (n) => (form = n),
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function apiKeyColumns(
|
|
143
|
+
now: () => string,
|
|
144
|
+
revokeClick: (key: ApiKey, e: MouseEvent) => void,
|
|
145
|
+
): Column<ApiKey>[] {
|
|
146
|
+
return [
|
|
147
|
+
{
|
|
148
|
+
id: 'name',
|
|
149
|
+
header: 'Name',
|
|
150
|
+
rowHeader: true,
|
|
151
|
+
card: 'title',
|
|
152
|
+
cell: (k) => (
|
|
153
|
+
<span data-scope="row">
|
|
154
|
+
<b>{k.name}</b>
|
|
155
|
+
{k.scopes.map((s) => (
|
|
156
|
+
<Badge key={s}>{s}</Badge>
|
|
157
|
+
))}
|
|
158
|
+
</span>
|
|
159
|
+
),
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
id: 'prefix',
|
|
163
|
+
header: 'Key',
|
|
164
|
+
cell: (k) => (
|
|
165
|
+
<span data-scope="api-key">
|
|
166
|
+
<code data-part="prefix">{k.prefix}…</code>
|
|
167
|
+
</span>
|
|
168
|
+
),
|
|
169
|
+
},
|
|
170
|
+
{ id: 'created', header: 'Created' },
|
|
171
|
+
{
|
|
172
|
+
id: 'lastUsed',
|
|
173
|
+
header: 'Last used',
|
|
174
|
+
value: (k) => (k.lastUsed ? agoText(k.lastUsed, now()) : 'Never'),
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
id: 'revoke',
|
|
178
|
+
header: 'Actions',
|
|
179
|
+
value: () => '',
|
|
180
|
+
cell: (k) => (
|
|
181
|
+
<Button
|
|
182
|
+
emphasis="soft"
|
|
183
|
+
tone="critical"
|
|
184
|
+
size="sm"
|
|
185
|
+
aria-label={`Revoke ${k.name}`}
|
|
186
|
+
onClick={(e: MouseEvent) => revokeClick(k, e)}
|
|
187
|
+
>
|
|
188
|
+
Revoke
|
|
189
|
+
</Button>
|
|
190
|
+
),
|
|
191
|
+
},
|
|
192
|
+
]
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function keyFooter({
|
|
196
|
+
secret,
|
|
197
|
+
seen,
|
|
198
|
+
dialog,
|
|
199
|
+
busy,
|
|
200
|
+
make,
|
|
201
|
+
}: {
|
|
202
|
+
secret: State<string>
|
|
203
|
+
seen: State<boolean>
|
|
204
|
+
dialog: State<boolean>
|
|
205
|
+
busy: State<boolean>
|
|
206
|
+
make: () => Promise<void>
|
|
207
|
+
}) {
|
|
208
|
+
return derived(() =>
|
|
209
|
+
secret.value ? (
|
|
210
|
+
<Button disabled={!seen.value} onClick={() => (dialog.value = false)}>
|
|
211
|
+
Done
|
|
212
|
+
</Button>
|
|
213
|
+
) : (
|
|
214
|
+
<>
|
|
215
|
+
<Button emphasis="frame" data-close="">
|
|
216
|
+
Cancel
|
|
217
|
+
</Button>
|
|
218
|
+
<Button loading={busy.value} onClick={make}>
|
|
219
|
+
Create key
|
|
220
|
+
</Button>
|
|
221
|
+
</>
|
|
222
|
+
),
|
|
223
|
+
)
|
|
224
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { agoText, announce, plural } from '@kerf-js/veneer-core'
|
|
2
|
+
import { derived, onCleanup, state, type State } from '@kerf-js/core'
|
|
3
|
+
import { Button } from '../Button'
|
|
4
|
+
import { LiveStatus, type LiveState } from '../parts'
|
|
5
|
+
import { Tooltip } from '../Tooltip'
|
|
6
|
+
import { Segmented } from '../Choice'
|
|
7
|
+
import { Select } from '../Select'
|
|
8
|
+
import { Table, type Column } from '../Table'
|
|
9
|
+
import { read } from './atoms'
|
|
10
|
+
import '../styles'
|
|
11
|
+
import '@kerf-js/veneer-core/styles/flows/tokens.css'
|
|
12
|
+
import '@kerf-js/veneer-core/styles/flows/base.css'
|
|
13
|
+
import '@kerf-js/veneer-core/styles/rich/helpers.css'
|
|
14
|
+
import '@kerf-js/veneer-core/styles/layout/tokens.css'
|
|
15
|
+
import '@kerf-js/veneer-core/styles/layout/row.css'
|
|
16
|
+
import '@kerf-js/veneer-core/styles/layout/stack.css'
|
|
17
|
+
|
|
18
|
+
/** One line of the audit log. */
|
|
19
|
+
export type AuditEvent = {
|
|
20
|
+
id: string
|
|
21
|
+
at: string
|
|
22
|
+
actor: string
|
|
23
|
+
category: string
|
|
24
|
+
verb: string
|
|
25
|
+
target: string
|
|
26
|
+
href?: string
|
|
27
|
+
ip: string
|
|
28
|
+
diff?: { field: string; from: string; to: string }[]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Props for AuditLog. */
|
|
32
|
+
export interface AuditLogProps {
|
|
33
|
+
events: readonly AuditEvent[] | State<readonly AuditEvent[]>
|
|
34
|
+
now: string
|
|
35
|
+
categories?: { value: string; label: string }[]
|
|
36
|
+
/** The realtime pill, when the rows come from a live query. */
|
|
37
|
+
live?: LiveState | undefined
|
|
38
|
+
/** Resolve with `{ retryAfter }` (seconds) when rate limited (§5.5). */
|
|
39
|
+
onExport?: () => Promise<{ retryAfter?: number } | void>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const RANGES = [
|
|
43
|
+
{ value: 'all', label: 'Any time', hours: Infinity },
|
|
44
|
+
{ value: '24h', label: 'Last 24 hours', hours: 24 },
|
|
45
|
+
{ value: '7d', label: 'Last 7 days', hours: 168 },
|
|
46
|
+
{ value: '30d', label: 'Last 30 days', hours: 720 },
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The audit log (09 §4.5): a read-only DataTable. Time is relative, exact on hover and focus; each event opens its diff.
|
|
51
|
+
* Filters: actor, action, date range. New rows arrive by key, so a live query never rebuilds the table.
|
|
52
|
+
*/
|
|
53
|
+
const stamp = (at: string) => at.replace('T', ' ').replace(/:\d\dZ$/, ' UTC')
|
|
54
|
+
|
|
55
|
+
/** The audit log: who did what and when, filtered by category and actor, with an export. */
|
|
56
|
+
export function AuditLog({
|
|
57
|
+
events,
|
|
58
|
+
now,
|
|
59
|
+
categories = [{ value: 'all', label: 'All' }],
|
|
60
|
+
live,
|
|
61
|
+
onExport,
|
|
62
|
+
}: AuditLogProps) {
|
|
63
|
+
const category = state('all')
|
|
64
|
+
const actor = state('all')
|
|
65
|
+
const range = state('all')
|
|
66
|
+
const wait = state(0)
|
|
67
|
+
const { actors, shown } = auditFilters(
|
|
68
|
+
() => events,
|
|
69
|
+
() => now,
|
|
70
|
+
{ category, actor, range },
|
|
71
|
+
)
|
|
72
|
+
let root: HTMLElement | undefined
|
|
73
|
+
const say = auditAnnouncer(() => root)
|
|
74
|
+
const exportIt = auditExport(() => onExport?.(), wait, say)
|
|
75
|
+
const refilter = () => queueMicrotask(() => say(`${plural(shown.value.length, 'event')} shown`))
|
|
76
|
+
const columns = auditColumns(() => now)
|
|
77
|
+
const diff = (event: AuditEvent) => auditDiff(event)
|
|
78
|
+
const hasLive = derived(() => live !== undefined)
|
|
79
|
+
return (
|
|
80
|
+
<div ref={(n) => (root = n)} data-scope="stack">
|
|
81
|
+
<div data-scope="row" data-justify="between">
|
|
82
|
+
<Segmented
|
|
83
|
+
label="Filter events"
|
|
84
|
+
size="sm"
|
|
85
|
+
value={category.value}
|
|
86
|
+
options={categories}
|
|
87
|
+
onChange={(v) => setAuditFilter(category, v, refilter)}
|
|
88
|
+
/>
|
|
89
|
+
{hasLive.value && <LiveStatus state={live!} label="Audit log" />}
|
|
90
|
+
</div>
|
|
91
|
+
<div data-scope="row">
|
|
92
|
+
<div data-grow="">
|
|
93
|
+
<Select
|
|
94
|
+
label="Actor"
|
|
95
|
+
size="sm"
|
|
96
|
+
options={actors.value}
|
|
97
|
+
value={actor.value}
|
|
98
|
+
onChange={(e: Event) => auditInput(e, actor, refilter)}
|
|
99
|
+
/>
|
|
100
|
+
</div>
|
|
101
|
+
<div data-grow="">
|
|
102
|
+
<Select
|
|
103
|
+
label="Date range"
|
|
104
|
+
size="sm"
|
|
105
|
+
options={RANGES}
|
|
106
|
+
value={range.value}
|
|
107
|
+
onChange={(e: Event) => auditInput(e, range, refilter)}
|
|
108
|
+
/>
|
|
109
|
+
</div>
|
|
110
|
+
{onExport && (
|
|
111
|
+
<Button
|
|
112
|
+
emphasis="frame"
|
|
113
|
+
aria-disabled={wait.value > 0 ? 'true' : undefined}
|
|
114
|
+
onClick={exportIt}
|
|
115
|
+
>
|
|
116
|
+
{wait.value > 0 ? `Try again in ${wait.value}s` : 'Export CSV'}
|
|
117
|
+
</Button>
|
|
118
|
+
)}
|
|
119
|
+
</div>
|
|
120
|
+
<Table
|
|
121
|
+
caption="Recent events"
|
|
122
|
+
captionHidden
|
|
123
|
+
rows={shown}
|
|
124
|
+
columns={columns}
|
|
125
|
+
picker={false}
|
|
126
|
+
heading={3}
|
|
127
|
+
details="sheet"
|
|
128
|
+
expand={diff}
|
|
129
|
+
empty={{ title: 'Nothing matches', text: 'Try a wider filter.' }}
|
|
130
|
+
/>
|
|
131
|
+
</div>
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function auditColumns(now: () => string): Column<AuditEvent>[] {
|
|
136
|
+
return [
|
|
137
|
+
{
|
|
138
|
+
id: 'at',
|
|
139
|
+
header: 'When',
|
|
140
|
+
sort: (r) => r.at,
|
|
141
|
+
cell: (e) => {
|
|
142
|
+
const at = stamp(e.at)
|
|
143
|
+
return (
|
|
144
|
+
<Tooltip content={at}>
|
|
145
|
+
<time datetime={e.at} tabindex="0">
|
|
146
|
+
{agoText(e.at, now())}
|
|
147
|
+
</time>
|
|
148
|
+
</Tooltip>
|
|
149
|
+
)
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
{ id: 'actor', header: 'Who', rowHeader: true, card: 'title' },
|
|
153
|
+
{
|
|
154
|
+
id: 'what',
|
|
155
|
+
header: 'What',
|
|
156
|
+
value: (e) => `${e.verb} ${e.target}`,
|
|
157
|
+
cell: (e) => (
|
|
158
|
+
<>
|
|
159
|
+
{e.verb} {e.href ? <a href={e.href}>{e.target}</a> : e.target}
|
|
160
|
+
</>
|
|
161
|
+
),
|
|
162
|
+
},
|
|
163
|
+
{ id: 'ip', header: 'IP', priority: 2, cell: (e) => <code>{e.ip}</code> },
|
|
164
|
+
]
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function auditDiff(e: AuditEvent) {
|
|
168
|
+
return e.diff?.length ? (
|
|
169
|
+
<dl data-scope="desc">
|
|
170
|
+
{e.diff.map((d) => (
|
|
171
|
+
<div key={d.field}>
|
|
172
|
+
<dt>{d.field}</dt>
|
|
173
|
+
<dd>
|
|
174
|
+
{d.from} → {d.to}
|
|
175
|
+
</dd>
|
|
176
|
+
</div>
|
|
177
|
+
))}
|
|
178
|
+
</dl>
|
|
179
|
+
) : (
|
|
180
|
+
<span class="muted">No field changes were recorded.</span>
|
|
181
|
+
)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function auditFilters(
|
|
185
|
+
events: () => AuditLogProps['events'],
|
|
186
|
+
now: () => string,
|
|
187
|
+
{
|
|
188
|
+
category,
|
|
189
|
+
actor,
|
|
190
|
+
range,
|
|
191
|
+
}: { category: State<string>; actor: State<string>; range: State<string> },
|
|
192
|
+
) {
|
|
193
|
+
const list = derived(() => read(events()))
|
|
194
|
+
const actors = derived(() => [
|
|
195
|
+
{ value: 'all', label: 'Everyone' },
|
|
196
|
+
...[...new Set(list.value.map((e) => e.actor))].map((a) => ({ value: a, label: a })),
|
|
197
|
+
])
|
|
198
|
+
const shown = derived(() => {
|
|
199
|
+
const hours = RANGES.find((r) => r.value === range.value)!.hours
|
|
200
|
+
return list.value.filter(
|
|
201
|
+
(e) =>
|
|
202
|
+
(category.value === 'all' || e.category === category.value) &&
|
|
203
|
+
(actor.value === 'all' || e.actor === actor.value) &&
|
|
204
|
+
Date.parse(now()) - Date.parse(e.at) <= hours * 36e5,
|
|
205
|
+
)
|
|
206
|
+
})
|
|
207
|
+
return { actors, shown }
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function auditExport(
|
|
211
|
+
onExport: () => ReturnType<NonNullable<AuditLogProps['onExport']>> | undefined,
|
|
212
|
+
wait: State<number>,
|
|
213
|
+
say: (t: string) => void,
|
|
214
|
+
) {
|
|
215
|
+
let tick: ReturnType<typeof setInterval> | undefined
|
|
216
|
+
onCleanup(() => clearInterval(tick))
|
|
217
|
+
const exportIt = async () => {
|
|
218
|
+
const r = await onExport()
|
|
219
|
+
if (!r?.retryAfter) return
|
|
220
|
+
wait.value = r.retryAfter
|
|
221
|
+
say(`Export limit reached. Try again in ${r.retryAfter} seconds.`)
|
|
222
|
+
tick = setInterval(() => {
|
|
223
|
+
wait.value -= 1
|
|
224
|
+
if (wait.value > 0) return
|
|
225
|
+
clearInterval(tick)
|
|
226
|
+
say('You can export again.')
|
|
227
|
+
}, 1000)
|
|
228
|
+
}
|
|
229
|
+
return exportIt
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function auditAnnouncer(root: () => HTMLElement | undefined) {
|
|
233
|
+
return (text: string) => {
|
|
234
|
+
const element = root()
|
|
235
|
+
if (element) announce(element.ownerDocument, text)
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function setAuditFilter(filter: State<string>, value: string, refilter: () => void) {
|
|
240
|
+
filter.value = value
|
|
241
|
+
refilter()
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function auditInput(e: Event, filter: State<string>, refilter: () => void) {
|
|
245
|
+
setAuditFilter(filter, (e.currentTarget as HTMLInputElement).value, refilter)
|
|
246
|
+
}
|