@kelpie/ui 0.22.0 → 0.23.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/dist/api/resource.d.ts +12 -0
- package/dist/api/resource.d.ts.map +1 -1
- package/dist/api/resource.js +11 -0
- package/dist/api/resource.js.map +1 -1
- package/dist/api/resources/decisions.d.ts +31 -0
- package/dist/api/resources/decisions.d.ts.map +1 -1
- package/dist/api/resources/decisions.js +51 -1
- package/dist/api/resources/decisions.js.map +1 -1
- package/dist/api/resources/oauth.d.ts +2 -0
- package/dist/api/resources/oauth.d.ts.map +1 -1
- package/dist/api/resources/oauth.js +13 -1
- package/dist/api/resources/oauth.js.map +1 -1
- package/dist/api/resources/personIntake.d.ts +15 -3
- package/dist/api/resources/personIntake.d.ts.map +1 -1
- package/dist/api/resources/personIntake.js +38 -9
- package/dist/api/resources/personIntake.js.map +1 -1
- package/dist/api/resources/session.d.ts.map +1 -1
- package/dist/api/resources/session.js +4 -0
- package/dist/api/resources/session.js.map +1 -1
- package/dist/app/KelpieApp.d.ts.map +1 -1
- package/dist/app/KelpieApp.js +2 -1
- package/dist/app/KelpieApp.js.map +1 -1
- package/dist/components/AddRecordPanel.d.ts +35 -0
- package/dist/components/AddRecordPanel.d.ts.map +1 -0
- package/dist/components/AddRecordPanel.js +35 -0
- package/dist/components/AddRecordPanel.js.map +1 -0
- package/dist/components/AiDrawer.d.ts.map +1 -1
- package/dist/components/AiDrawer.js +29 -6
- package/dist/components/AiDrawer.js.map +1 -1
- package/dist/components/ApiKeysPanel.d.ts.map +1 -1
- package/dist/components/ApiKeysPanel.js +101 -44
- package/dist/components/ApiKeysPanel.js.map +1 -1
- package/dist/components/CustomFieldsPanel.d.ts.map +1 -1
- package/dist/components/CustomFieldsPanel.js +5 -2
- package/dist/components/CustomFieldsPanel.js.map +1 -1
- package/dist/components/DecisionProvenance.d.ts +27 -0
- package/dist/components/DecisionProvenance.d.ts.map +1 -0
- package/dist/components/DecisionProvenance.js +53 -0
- package/dist/components/DecisionProvenance.js.map +1 -0
- package/dist/components/DecisionsPanel.d.ts +3 -0
- package/dist/components/DecisionsPanel.d.ts.map +1 -1
- package/dist/components/DecisionsPanel.js +9 -5
- package/dist/components/DecisionsPanel.js.map +1 -1
- package/dist/components/MarkdownView.d.ts.map +1 -1
- package/dist/components/MarkdownView.js +18 -2
- package/dist/components/MarkdownView.js.map +1 -1
- package/dist/components/NotesPanel.d.ts.map +1 -1
- package/dist/components/NotesPanel.js +7 -3
- package/dist/components/NotesPanel.js.map +1 -1
- package/dist/components/OriginLabel.d.ts +5 -0
- package/dist/components/OriginLabel.d.ts.map +1 -0
- package/dist/components/OriginLabel.js +22 -0
- package/dist/components/OriginLabel.js.map +1 -0
- package/dist/components/Shell.d.ts.map +1 -1
- package/dist/components/Shell.js +17 -5
- package/dist/components/Shell.js.map +1 -1
- package/dist/components/aiDrawerState.d.ts +12 -0
- package/dist/components/aiDrawerState.d.ts.map +1 -1
- package/dist/components/aiDrawerState.js.map +1 -1
- package/dist/components/personIntakeTask.d.ts +15 -0
- package/dist/components/personIntakeTask.d.ts.map +1 -1
- package/dist/components/personIntakeTask.js +42 -0
- package/dist/components/personIntakeTask.js.map +1 -1
- package/dist/lib/personIntakeRunStorage.d.ts +15 -0
- package/dist/lib/personIntakeRunStorage.d.ts.map +1 -0
- package/dist/lib/personIntakeRunStorage.js +88 -0
- package/dist/lib/personIntakeRunStorage.js.map +1 -0
- package/dist/modules/PersonIntakeWizard.d.ts +1 -1
- package/dist/modules/PersonIntakeWizard.d.ts.map +1 -1
- package/dist/modules/PersonIntakeWizard.js +243 -29
- package/dist/modules/PersonIntakeWizard.js.map +1 -1
- package/dist/modules/ai.d.ts +1 -1
- package/dist/modules/ai.js +1 -1
- package/dist/pages/CompaniesPage.d.ts.map +1 -1
- package/dist/pages/CompaniesPage.js +13 -6
- package/dist/pages/CompaniesPage.js.map +1 -1
- package/dist/pages/DealsPage.d.ts.map +1 -1
- package/dist/pages/DealsPage.js +16 -8
- package/dist/pages/DealsPage.js.map +1 -1
- package/dist/pages/DecisionsPage.d.ts.map +1 -1
- package/dist/pages/DecisionsPage.js +7 -3
- package/dist/pages/DecisionsPage.js.map +1 -1
- package/dist/pages/EnquiriesPage.d.ts.map +1 -1
- package/dist/pages/EnquiriesPage.js +14 -6
- package/dist/pages/EnquiriesPage.js.map +1 -1
- package/dist/pages/FundraisingPage.d.ts.map +1 -1
- package/dist/pages/FundraisingPage.js +16 -11
- package/dist/pages/FundraisingPage.js.map +1 -1
- package/dist/pages/OpportunitiesPage.d.ts.map +1 -1
- package/dist/pages/OpportunitiesPage.js +14 -6
- package/dist/pages/OpportunitiesPage.js.map +1 -1
- package/dist/pages/PartnershipsPage.d.ts.map +1 -1
- package/dist/pages/PartnershipsPage.js +16 -11
- package/dist/pages/PartnershipsPage.js.map +1 -1
- package/dist/pages/PeoplePage.d.ts.map +1 -1
- package/dist/pages/PeoplePage.js +13 -8
- package/dist/pages/PeoplePage.js.map +1 -1
- package/dist/pages/PersonDetail.js +2 -2
- package/dist/pages/PersonDetail.js.map +1 -1
- package/dist/pages/SearchPage.d.ts.map +1 -1
- package/dist/pages/SearchPage.js +2 -1
- package/dist/pages/SearchPage.js.map +1 -1
- package/dist/pages/account/ConnectedAppsPage.d.ts +0 -5
- package/dist/pages/account/ConnectedAppsPage.d.ts.map +1 -1
- package/dist/pages/account/ConnectedAppsPage.js +38 -6
- package/dist/pages/account/ConnectedAppsPage.js.map +1 -1
- package/dist/pages/admin/AgentsPanel.d.ts +10 -0
- package/dist/pages/admin/AgentsPanel.d.ts.map +1 -0
- package/dist/pages/admin/AgentsPanel.js +81 -0
- package/dist/pages/admin/AgentsPanel.js.map +1 -0
- package/dist/pages/admin/AiAdminPage.d.ts.map +1 -1
- package/dist/pages/admin/AiAdminPage.js +9 -6
- package/dist/pages/admin/AiAdminPage.js.map +1 -1
- package/dist/pages/admin/AiPage.js +1 -1
- package/dist/pages/admin/TeamPage.d.ts.map +1 -1
- package/dist/pages/admin/TeamPage.js +16 -3
- package/dist/pages/admin/TeamPage.js.map +1 -1
- package/dist/pages/ai/AiAccessPage.d.ts +11 -0
- package/dist/pages/ai/AiAccessPage.d.ts.map +1 -0
- package/dist/pages/ai/AiAccessPage.js +16 -0
- package/dist/pages/ai/AiAccessPage.js.map +1 -0
- package/dist/pages/ai/McpPanel.d.ts +7 -0
- package/dist/pages/ai/McpPanel.d.ts.map +1 -0
- package/dist/pages/ai/McpPanel.js +86 -0
- package/dist/pages/ai/McpPanel.js.map +1 -0
- package/dist/pages/auth/nextPath.d.ts +6 -0
- package/dist/pages/auth/nextPath.d.ts.map +1 -1
- package/dist/pages/auth/nextPath.js +16 -1
- package/dist/pages/auth/nextPath.js.map +1 -1
- package/dist/pages/dashboard/sections.d.ts.map +1 -1
- package/dist/pages/dashboard/sections.js +4 -2
- package/dist/pages/dashboard/sections.js.map +1 -1
- package/dist/pages/forms/EmbedPanel.js +1 -1
- package/dist/pages/forms/EmbedPanel.js.map +1 -1
- package/dist/pages/forms/FormEmails.d.ts.map +1 -1
- package/dist/pages/forms/FormEmails.js +6 -1
- package/dist/pages/forms/FormEmails.js.map +1 -1
- package/dist/pages/forms/FormSettings.d.ts.map +1 -1
- package/dist/pages/forms/FormSettings.js +6 -2
- package/dist/pages/forms/FormSettings.js.map +1 -1
- package/dist/pages/forms/SubmissionDetail.js +15 -3
- package/dist/pages/forms/SubmissionDetail.js.map +1 -1
- package/dist/pages/forms/SubmissionsTable.js +5 -2
- package/dist/pages/forms/SubmissionsTable.js.map +1 -1
- package/dist/pages/oauth/ConsentPage.d.ts.map +1 -1
- package/dist/pages/oauth/ConsentPage.js +132 -15
- package/dist/pages/oauth/ConsentPage.js.map +1 -1
- package/dist/registry/contributions.d.ts +1 -1
- package/package.json +3 -3
- package/src/api/resource.ts +16 -0
- package/src/api/resources/decisions.ts +81 -1
- package/src/api/resources/oauth.ts +15 -1
- package/src/api/resources/personIntake.ts +54 -13
- package/src/api/resources/session.ts +4 -0
- package/src/app/KelpieApp.tsx +4 -2
- package/src/components/AddRecordPanel.tsx +143 -0
- package/src/components/AiDrawer.tsx +34 -7
- package/src/components/ApiKeysPanel.tsx +193 -75
- package/src/components/CustomFieldsPanel.tsx +15 -5
- package/src/components/DecisionProvenance.tsx +95 -0
- package/src/components/DecisionsPanel.tsx +30 -2
- package/src/components/MarkdownView.tsx +45 -11
- package/src/components/NotesPanel.tsx +15 -6
- package/src/components/OriginLabel.tsx +26 -0
- package/src/components/Shell.tsx +30 -6
- package/src/components/aiDrawerState.ts +12 -0
- package/src/components/personIntakeTask.tsx +48 -0
- package/src/lib/personIntakeRunStorage.ts +97 -0
- package/src/modules/PersonIntakeWizard.tsx +391 -30
- package/src/modules/ai.tsx +1 -1
- package/src/pages/CompaniesPage.tsx +22 -5
- package/src/pages/DealsPage.tsx +25 -8
- package/src/pages/DecisionsPage.tsx +28 -1
- package/src/pages/EnquiriesPage.tsx +23 -5
- package/src/pages/FundraisingPage.tsx +25 -11
- package/src/pages/OpportunitiesPage.tsx +23 -5
- package/src/pages/PartnershipsPage.tsx +25 -11
- package/src/pages/PeoplePage.tsx +22 -7
- package/src/pages/PersonDetail.tsx +4 -2
- package/src/pages/SearchPage.tsx +3 -0
- package/src/pages/account/ConnectedAppsPage.tsx +97 -14
- package/src/pages/admin/{McpPanel.tsx → AgentsPanel.tsx} +11 -168
- package/src/pages/admin/AiAdminPage.tsx +16 -11
- package/src/pages/admin/AiPage.tsx +1 -1
- package/src/pages/admin/TeamPage.tsx +33 -0
- package/src/pages/ai/AiAccessPage.tsx +23 -0
- package/src/pages/ai/McpPanel.tsx +261 -0
- package/src/pages/auth/nextPath.ts +18 -1
- package/src/pages/dashboard/sections.tsx +4 -0
- package/src/pages/forms/EmbedPanel.tsx +3 -2
- package/src/pages/forms/FormEmails.tsx +11 -2
- package/src/pages/forms/FormSettings.tsx +5 -0
- package/src/pages/forms/SubmissionDetail.tsx +23 -4
- package/src/pages/forms/SubmissionsTable.tsx +9 -1
- package/src/pages/oauth/ConsentPage.tsx +271 -33
- package/src/registry/contributions.ts +1 -1
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import { useCompanies } from '../api/resources/companies.ts'
|
|
4
|
+
import { EntitySearch } from './EntitySearch.tsx'
|
|
5
|
+
import type { SearchOption } from './EntitySearch.tsx'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Asks for a record's name before the record exists.
|
|
9
|
+
*
|
|
10
|
+
* A list page's Add button opens this instead of creating a record with a
|
|
11
|
+
* placeholder name. The created event then carries the real name, which is what
|
|
12
|
+
* a webhook, an agent task or a notification reads. Nothing is saved when the
|
|
13
|
+
* reader cancels.
|
|
14
|
+
*
|
|
15
|
+
* `company` adds a required company picker, for the records that belong to one
|
|
16
|
+
* (deals, raises, partnerships).
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export interface AddRecordValues {
|
|
20
|
+
readonly name: string
|
|
21
|
+
/** Set only when the panel was given `company`. */
|
|
22
|
+
readonly companyId?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface AddRecordCompanyPicker {
|
|
26
|
+
readonly options: readonly SearchOption[]
|
|
27
|
+
/** Set to search on the server as the reader types. */
|
|
28
|
+
readonly onQueryChange?: (query: string) => void
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface AddRecordPanelProps {
|
|
32
|
+
/** The heading and the submit label, e.g. "Add person". */
|
|
33
|
+
readonly title: string
|
|
34
|
+
readonly namePlaceholder?: string
|
|
35
|
+
readonly company?: AddRecordCompanyPicker
|
|
36
|
+
readonly isPending: boolean
|
|
37
|
+
readonly onCancel: () => void
|
|
38
|
+
readonly onCreate: (values: AddRecordValues) => void
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function AddRecordPanel({
|
|
42
|
+
title,
|
|
43
|
+
namePlaceholder,
|
|
44
|
+
company,
|
|
45
|
+
isPending,
|
|
46
|
+
onCancel,
|
|
47
|
+
onCreate,
|
|
48
|
+
}: AddRecordPanelProps): React.JSX.Element {
|
|
49
|
+
const [name, setName] = useState('')
|
|
50
|
+
const [companyId, setCompanyId] = useState('')
|
|
51
|
+
const trimmed = name.trim()
|
|
52
|
+
const ready = trimmed.length > 0 && (company === undefined || companyId.length > 0)
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<form
|
|
56
|
+
aria-label={title}
|
|
57
|
+
className="mb-3 max-w-md rounded-md border border-border bg-surface-raised p-4"
|
|
58
|
+
onSubmit={(event) => {
|
|
59
|
+
event.preventDefault()
|
|
60
|
+
|
|
61
|
+
if (!ready || isPending) {
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
onCreate(company === undefined ? { name: trimmed } : { name: trimmed, companyId })
|
|
66
|
+
}}
|
|
67
|
+
onKeyDown={(event) => {
|
|
68
|
+
if (event.key === 'Escape' && !isPending) {
|
|
69
|
+
onCancel()
|
|
70
|
+
}
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
73
|
+
<p className="text-[13px] font-semibold text-ink">{title}</p>
|
|
74
|
+
|
|
75
|
+
<div className="mt-3 space-y-3">
|
|
76
|
+
<label className="block text-[12px] font-medium text-ink-muted">
|
|
77
|
+
Name
|
|
78
|
+
<input
|
|
79
|
+
// The reader pressed Add to type a name, so the caret starts here.
|
|
80
|
+
autoFocus
|
|
81
|
+
value={name}
|
|
82
|
+
onChange={(event) => {
|
|
83
|
+
setName(event.target.value)
|
|
84
|
+
}}
|
|
85
|
+
placeholder={namePlaceholder}
|
|
86
|
+
className="mt-1 block w-full rounded-md border border-border bg-surface px-2.5 py-1.5 text-[13px] text-ink"
|
|
87
|
+
/>
|
|
88
|
+
</label>
|
|
89
|
+
|
|
90
|
+
{company !== undefined && (
|
|
91
|
+
<div className="text-[12px] font-medium text-ink-muted">
|
|
92
|
+
Company
|
|
93
|
+
<div className="mt-1">
|
|
94
|
+
<EntitySearch
|
|
95
|
+
options={company.options}
|
|
96
|
+
value={companyId}
|
|
97
|
+
onChange={setCompanyId}
|
|
98
|
+
onQueryChange={company.onQueryChange}
|
|
99
|
+
placeholder="Search companies…"
|
|
100
|
+
emptyMessage="No company matches"
|
|
101
|
+
size="sm"
|
|
102
|
+
/>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
)}
|
|
106
|
+
</div>
|
|
107
|
+
|
|
108
|
+
<div className="mt-4 flex justify-end gap-2">
|
|
109
|
+
<button
|
|
110
|
+
type="button"
|
|
111
|
+
onClick={onCancel}
|
|
112
|
+
disabled={isPending}
|
|
113
|
+
className="rounded-md px-2.5 py-1 text-[12px] font-medium text-ink-muted hover:text-ink disabled:opacity-50"
|
|
114
|
+
>
|
|
115
|
+
Cancel
|
|
116
|
+
</button>
|
|
117
|
+
<button
|
|
118
|
+
type="submit"
|
|
119
|
+
disabled={isPending || !ready}
|
|
120
|
+
className="rounded-md bg-accent px-3 py-1.5 text-[12px] font-semibold text-accent-fg hover:bg-accent-hover disabled:opacity-50"
|
|
121
|
+
>
|
|
122
|
+
{isPending ? 'Adding…' : title}
|
|
123
|
+
</button>
|
|
124
|
+
</div>
|
|
125
|
+
</form>
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** `AddRecordPanel` with the company picker searching the workspace's companies. */
|
|
130
|
+
export function AddCompanyRecordPanel(props: Omit<AddRecordPanelProps, 'company'>): React.JSX.Element {
|
|
131
|
+
const [search, setSearch] = useState('')
|
|
132
|
+
const companies = useCompanies({ term: search.trim().length > 0 ? search.trim() : undefined })
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<AddRecordPanel
|
|
136
|
+
{...props}
|
|
137
|
+
company={{
|
|
138
|
+
options: companies.records.map((company) => ({ id: company.id, label: company.name })),
|
|
139
|
+
onQueryChange: setSearch,
|
|
140
|
+
}}
|
|
141
|
+
/>
|
|
142
|
+
)
|
|
143
|
+
}
|
|
@@ -63,10 +63,22 @@ export function AiDrawerProvider({ children }: { readonly children: ReactNode })
|
|
|
63
63
|
const activeRef = useRef<AiDrawerTask | undefined>(undefined)
|
|
64
64
|
const { session } = useSession()
|
|
65
65
|
const workspaceId = session?.workspaceId ?? null
|
|
66
|
-
|
|
66
|
+
// The session's workspace, current before any child's effect runs, so a
|
|
67
|
+
// task opened from an effect during a switch is recorded against the new one.
|
|
68
|
+
const currentWorkspaceRef = useRef<string | null>(workspaceId)
|
|
69
|
+
// The workspace the active task belongs to.
|
|
70
|
+
const taskWorkspaceRef = useRef<string | null>(null)
|
|
71
|
+
|
|
72
|
+
useLayoutEffect(() => {
|
|
73
|
+
currentWorkspaceRef.current = workspaceId
|
|
74
|
+
}, [workspaceId])
|
|
67
75
|
|
|
68
76
|
const finish = useCallback((): void => {
|
|
77
|
+
const ended = activeRef.current
|
|
78
|
+
const endedWorkspace = taskWorkspaceRef.current
|
|
69
79
|
activeRef.current = undefined
|
|
80
|
+
taskWorkspaceRef.current = null
|
|
81
|
+
ended?.onEnd?.(endedWorkspace)
|
|
70
82
|
setActiveTask(undefined)
|
|
71
83
|
setIsOpen(false)
|
|
72
84
|
setIsPending(false)
|
|
@@ -82,11 +94,22 @@ export function AiDrawerProvider({ children }: { readonly children: ReactNode })
|
|
|
82
94
|
}
|
|
83
95
|
|
|
84
96
|
activeRef.current = task
|
|
97
|
+
taskWorkspaceRef.current = currentWorkspaceRef.current
|
|
85
98
|
setActiveTask(task)
|
|
86
99
|
setBusyNotice(false)
|
|
87
100
|
return true
|
|
88
101
|
}, [])
|
|
89
102
|
|
|
103
|
+
const restore = useCallback((task: AiDrawerTask): boolean => {
|
|
104
|
+
if (activeRef.current !== undefined) return false
|
|
105
|
+
|
|
106
|
+
activeRef.current = task
|
|
107
|
+
taskWorkspaceRef.current = currentWorkspaceRef.current
|
|
108
|
+
setActiveTask(task)
|
|
109
|
+
setIsOpen(false)
|
|
110
|
+
return true
|
|
111
|
+
}, [])
|
|
112
|
+
|
|
90
113
|
const reopen = useCallback((): void => {
|
|
91
114
|
if (activeRef.current !== undefined) setIsOpen(true)
|
|
92
115
|
}, [])
|
|
@@ -97,18 +120,22 @@ export function AiDrawerProvider({ children }: { readonly children: ReactNode })
|
|
|
97
120
|
}, [])
|
|
98
121
|
|
|
99
122
|
// A task belongs to one workspace. The switcher asks first when a request is
|
|
100
|
-
// pending; this is the backstop for any other way the session moves.
|
|
123
|
+
// pending; this is the backstop for any other way the session moves. It ends
|
|
124
|
+
// only a task of another workspace, so a task restored for the new one in
|
|
125
|
+
// the same commit stays.
|
|
101
126
|
useEffect(() => {
|
|
102
|
-
|
|
127
|
+
const taskWorkspace = taskWorkspaceRef.current
|
|
128
|
+
|
|
129
|
+
const otherWorkspace = taskWorkspace !== null && workspaceId !== null && taskWorkspace !== workspaceId
|
|
130
|
+
|
|
131
|
+
if (activeRef.current !== undefined && otherWorkspace) {
|
|
103
132
|
finish()
|
|
104
133
|
}
|
|
105
|
-
|
|
106
|
-
if (workspaceId !== null) workspaceRef.current = workspaceId
|
|
107
134
|
}, [workspaceId, finish])
|
|
108
135
|
|
|
109
136
|
const state = useMemo<AiDrawerState>(
|
|
110
|
-
() => ({ activeTask, isOpen, isPending, open, reopen, close, finish }),
|
|
111
|
-
[activeTask, isOpen, isPending, open, reopen, close, finish],
|
|
137
|
+
() => ({ activeTask, isOpen, isPending, open, restore, reopen, close, finish }),
|
|
138
|
+
[activeTask, isOpen, isPending, open, restore, reopen, close, finish],
|
|
112
139
|
)
|
|
113
140
|
|
|
114
141
|
return (
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import type { ApiKey, ApiKeyGranularScope, ApiKeyKind, ApiKeyScope, CreatedApiKey } from '@kelpie/schemas'
|
|
2
2
|
import {
|
|
3
|
+
API_KEY_DEFAULT_SCOPES,
|
|
4
|
+
API_KEY_OPT_IN_SCOPES,
|
|
3
5
|
API_KEY_PRESET_SCOPES,
|
|
4
6
|
API_KEY_SCOPE_GROUPS,
|
|
5
7
|
API_KEY_SCOPE_LABELS,
|
|
8
|
+
apiKeyScopeRisk,
|
|
6
9
|
expandApiKeyScopes,
|
|
7
|
-
isApiKeyGranularScope,
|
|
8
10
|
isApiKeyPresetScope,
|
|
11
|
+
isSensitiveApiKeyScope,
|
|
12
|
+
sensitiveApiKeyScopesHeld,
|
|
9
13
|
} from '@kelpie/schemas'
|
|
10
|
-
import { useMemo, useState } from 'react'
|
|
14
|
+
import { useId, useMemo, useState } from 'react'
|
|
11
15
|
import type { FormEvent } from 'react'
|
|
12
16
|
|
|
13
17
|
import { useTimezone } from '../api/resources/account.ts'
|
|
14
18
|
import { useApiKeys, useCreateApiKey, useRevokeApiKey } from '../api/resources/apiKeys.ts'
|
|
15
19
|
import { formatDate } from '../lib/dates.ts'
|
|
16
20
|
import { mcpClientConfig, mcpEndpoint } from '../lib/mcpConfig.ts'
|
|
21
|
+
import { Chip } from './Chip.tsx'
|
|
17
22
|
import { CopyButton } from './CopyButton.tsx'
|
|
18
23
|
import { ErrorPanel, LoadingPanel } from './QueryState.tsx'
|
|
19
24
|
|
|
@@ -29,7 +34,25 @@ export interface ApiKeysPanelProps {
|
|
|
29
34
|
readonly emptyMessage: string
|
|
30
35
|
}
|
|
31
36
|
|
|
32
|
-
const
|
|
37
|
+
const OPT_IN_SCOPES: readonly ApiKeyScope[] = API_KEY_OPT_IN_SCOPES
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The presets with a tick box in the Presets list. `write:all` is not offered
|
|
41
|
+
* as a preset, and a preset that is an extra permission has its tick box in
|
|
42
|
+
* that section, where it is beside what it risks.
|
|
43
|
+
*/
|
|
44
|
+
const PRESET_OPTIONS = API_KEY_PRESET_SCOPES.filter((scope) => scope !== 'write:all' && !OPT_IN_SCOPES.includes(scope))
|
|
45
|
+
|
|
46
|
+
const GRID_SCOPES: ReadonlySet<ApiKeyScope> = new Set(API_KEY_SCOPE_GROUPS.flatMap((group) => group.scopes))
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The extra permissions that the custom grid has no tick box for, by name or
|
|
50
|
+
* by the scopes they expand to. With custom scopes these are the only extras
|
|
51
|
+
* shown: a second tick box for a scope in the grid could disagree with it.
|
|
52
|
+
*/
|
|
53
|
+
const EXTRAS_OUTSIDE_GRID = API_KEY_OPT_IN_SCOPES.filter((scope) =>
|
|
54
|
+
[...expandApiKeyScopes([scope])].some((granular) => !GRID_SCOPES.has(granular)),
|
|
55
|
+
)
|
|
33
56
|
|
|
34
57
|
export function ApiKeysPanel({
|
|
35
58
|
kind,
|
|
@@ -117,46 +140,89 @@ function CreateKeyModal({
|
|
|
117
140
|
}): React.JSX.Element {
|
|
118
141
|
const createApiKey = useCreateApiKey()
|
|
119
142
|
const [name, setName] = useState('')
|
|
120
|
-
|
|
121
|
-
|
|
143
|
+
// The form opens on the scopes the server gives a key that names none, so
|
|
144
|
+
// what a person sees ticked is what a person who only clicks Create gets.
|
|
145
|
+
const [accessMode, setAccessMode] = useState<AccessMode>('presets')
|
|
146
|
+
const [selectedPresets, setSelectedPresets] = useState<readonly ApiKeyScope[]>(API_KEY_DEFAULT_SCOPES)
|
|
122
147
|
const [selectedCustom, setSelectedCustom] = useState<readonly ApiKeyScope[]>([])
|
|
148
|
+
// Apart from the presets and the custom grid: no preset in the list above
|
|
149
|
+
// them includes one, so a person adds it to either.
|
|
150
|
+
const [selectedExtras, setSelectedExtras] = useState<readonly ApiKeyScope[]>([])
|
|
123
151
|
const [showCustom, setShowCustom] = useState(false)
|
|
152
|
+
const hintId = useId()
|
|
153
|
+
const offeredExtras = accessMode === 'custom' ? EXTRAS_OUTSIDE_GRID : API_KEY_OPT_IN_SCOPES
|
|
124
154
|
|
|
125
155
|
const presetExpandedScopes = useMemo(
|
|
126
|
-
() => expandApiKeyScopes(selectedPresets),
|
|
127
|
-
[selectedPresets],
|
|
156
|
+
() => expandApiKeyScopes([...selectedPresets, ...selectedExtras]),
|
|
157
|
+
[selectedPresets, selectedExtras],
|
|
128
158
|
)
|
|
129
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Moves to the custom grid. Every extra that the grid can show goes into
|
|
162
|
+
* it, so nothing stays ticked in a place the person can no longer see.
|
|
163
|
+
*/
|
|
164
|
+
function enterCustomMode(scopes: readonly ApiKeyScope[]): void {
|
|
165
|
+
const outsideGrid: readonly ApiKeyScope[] = EXTRAS_OUTSIDE_GRID
|
|
166
|
+
|
|
167
|
+
setAccessMode('custom')
|
|
168
|
+
setSelectedPresets([])
|
|
169
|
+
setSelectedCustom(scopes.filter((scope) => GRID_SCOPES.has(scope)))
|
|
170
|
+
setSelectedExtras((current) => current.filter((scope) => outsideGrid.includes(scope)))
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// The grid stays open while it holds a tick. What the form sends must be on
|
|
174
|
+
// the page: a hidden grid with ticks in it would send scopes nobody can see.
|
|
130
175
|
const showScopeGrid =
|
|
131
|
-
(accessMode === 'custom' && showCustom) ||
|
|
176
|
+
(accessMode === 'custom' && (showCustom || selectedCustom.length > 0)) ||
|
|
132
177
|
(accessMode === 'presets' && selectedPresets.length > 0)
|
|
133
178
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
179
|
+
const chosenScopes: readonly ApiKeyScope[] =
|
|
180
|
+
accessMode === 'full'
|
|
181
|
+
? []
|
|
182
|
+
: [...(accessMode === 'presets' ? selectedPresets : selectedCustom), ...selectedExtras]
|
|
183
|
+
// A request with no scopes gets the server's default ones. The form never
|
|
184
|
+
// sends that: it would create a key that differs from what is ticked.
|
|
185
|
+
const nothingChosen = accessMode !== 'full' && chosenScopes.length === 0
|
|
138
186
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return selectedCustom.length === 0 ? undefined : selectedCustom
|
|
187
|
+
function toggleExtra(scope: ApiKeyScope): void {
|
|
188
|
+
setSelectedExtras((current) =>
|
|
189
|
+
current.includes(scope) ? current.filter((entry) => entry !== scope) : [...current, scope],
|
|
190
|
+
)
|
|
144
191
|
}
|
|
145
192
|
|
|
146
193
|
function submit(event: FormEvent): void {
|
|
147
194
|
event.preventDefault()
|
|
148
|
-
|
|
195
|
+
|
|
196
|
+
if (nothingChosen) {
|
|
197
|
+
return
|
|
198
|
+
}
|
|
149
199
|
|
|
150
200
|
createApiKey
|
|
151
201
|
.runAsync({
|
|
152
202
|
name: name.trim(),
|
|
153
203
|
kind,
|
|
154
|
-
...(
|
|
204
|
+
...(accessMode === 'full' ? { fullAccess: true } : { scopes: chosenScopes }),
|
|
155
205
|
})
|
|
156
206
|
.then(onCreated)
|
|
157
207
|
.catch(() => undefined)
|
|
158
208
|
}
|
|
159
209
|
|
|
210
|
+
function toggleFullAccess(): void {
|
|
211
|
+
setSelectedCustom([])
|
|
212
|
+
setSelectedExtras([])
|
|
213
|
+
setShowCustom(false)
|
|
214
|
+
|
|
215
|
+
if (accessMode === 'full') {
|
|
216
|
+
setAccessMode('presets')
|
|
217
|
+
setSelectedPresets(API_KEY_DEFAULT_SCOPES)
|
|
218
|
+
|
|
219
|
+
return
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
setAccessMode('full')
|
|
223
|
+
setSelectedPresets([])
|
|
224
|
+
}
|
|
225
|
+
|
|
160
226
|
function togglePreset(scope: ApiKeyScope): void {
|
|
161
227
|
setAccessMode('presets')
|
|
162
228
|
setSelectedCustom([])
|
|
@@ -208,52 +274,40 @@ function CreateKeyModal({
|
|
|
208
274
|
<fieldset className="mt-4">
|
|
209
275
|
<legend className="mb-2 text-[12px] font-medium text-ink">Access</legend>
|
|
210
276
|
<div className="space-y-2">
|
|
211
|
-
|
|
212
|
-
<
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
{PRESET_OPTIONS.map((scope) => (
|
|
231
|
-
<label key={scope} className="flex items-center gap-2 text-[13px] text-ink">
|
|
232
|
-
<input
|
|
233
|
-
type="checkbox"
|
|
234
|
-
checked={accessMode === 'presets' && selectedPresets.includes(scope)}
|
|
235
|
-
onChange={() => {
|
|
236
|
-
togglePreset(scope)
|
|
237
|
-
}}
|
|
238
|
-
/>
|
|
239
|
-
{API_KEY_SCOPE_LABELS[scope]}
|
|
240
|
-
</label>
|
|
241
|
-
))}
|
|
277
|
+
{accessMode !== 'full' && (
|
|
278
|
+
<div className="rounded-md border border-border p-3">
|
|
279
|
+
<p className="mb-2 text-[11px] font-medium tracking-wide text-ink-muted uppercase">
|
|
280
|
+
Presets
|
|
281
|
+
</p>
|
|
282
|
+
<div className="space-y-1.5">
|
|
283
|
+
{PRESET_OPTIONS.map((scope) => (
|
|
284
|
+
<label key={scope} className="flex items-center gap-2 text-[13px] text-ink">
|
|
285
|
+
<input
|
|
286
|
+
type="checkbox"
|
|
287
|
+
checked={accessMode === 'presets' && selectedPresets.includes(scope)}
|
|
288
|
+
onChange={() => {
|
|
289
|
+
togglePreset(scope)
|
|
290
|
+
}}
|
|
291
|
+
/>
|
|
292
|
+
{API_KEY_SCOPE_LABELS[scope]}
|
|
293
|
+
</label>
|
|
294
|
+
))}
|
|
295
|
+
</div>
|
|
242
296
|
</div>
|
|
243
|
-
|
|
244
|
-
{accessMode
|
|
297
|
+
)}
|
|
298
|
+
{((accessMode === 'custom' && selectedCustom.length === 0) ||
|
|
299
|
+
(accessMode === 'presets' && selectedPresets.length === 0)) && (
|
|
245
300
|
<button
|
|
246
301
|
type="button"
|
|
247
302
|
onClick={() => {
|
|
248
303
|
setShowCustom((open) => !open)
|
|
249
|
-
if (!showCustom) {
|
|
250
|
-
|
|
251
|
-
setSelectedPresets([])
|
|
304
|
+
if (!showCustom && accessMode !== 'custom') {
|
|
305
|
+
enterCustomMode([...presetExpandedScopes])
|
|
252
306
|
}
|
|
253
307
|
}}
|
|
254
308
|
className="text-[12px] font-medium text-accent hover:underline"
|
|
255
309
|
>
|
|
256
|
-
{showCustom ? 'Hide custom scopes' : 'Custom scopes…'}
|
|
310
|
+
{showCustom && accessMode === 'custom' ? 'Hide custom scopes' : 'Custom scopes…'}
|
|
257
311
|
</button>
|
|
258
312
|
)}
|
|
259
313
|
{showScopeGrid && (
|
|
@@ -294,9 +348,7 @@ function CreateKeyModal({
|
|
|
294
348
|
<button
|
|
295
349
|
type="button"
|
|
296
350
|
onClick={() => {
|
|
297
|
-
|
|
298
|
-
setSelectedPresets([])
|
|
299
|
-
setSelectedCustom([...presetExpandedScopes])
|
|
351
|
+
enterCustomMode([...presetExpandedScopes])
|
|
300
352
|
setShowCustom(true)
|
|
301
353
|
}}
|
|
302
354
|
className="text-[12px] font-medium text-accent hover:underline"
|
|
@@ -306,9 +358,48 @@ function CreateKeyModal({
|
|
|
306
358
|
)}
|
|
307
359
|
</div>
|
|
308
360
|
)}
|
|
361
|
+
{accessMode !== 'full' && (
|
|
362
|
+
<div role="group" aria-label="Extra permissions" className="rounded-md border border-border p-3">
|
|
363
|
+
<p aria-hidden className="mb-2 text-[11px] font-medium tracking-wide text-ink-muted uppercase">
|
|
364
|
+
Extra permissions
|
|
365
|
+
</p>
|
|
366
|
+
<div className="space-y-2">
|
|
367
|
+
{offeredExtras.map((scope) => (
|
|
368
|
+
<label key={scope} className="flex items-start gap-2 text-[13px] text-ink">
|
|
369
|
+
<input
|
|
370
|
+
type="checkbox"
|
|
371
|
+
className="mt-0.5"
|
|
372
|
+
checked={selectedExtras.includes(scope)}
|
|
373
|
+
onChange={() => {
|
|
374
|
+
toggleExtra(scope)
|
|
375
|
+
}}
|
|
376
|
+
/>
|
|
377
|
+
<span>
|
|
378
|
+
{API_KEY_SCOPE_LABELS[scope]}
|
|
379
|
+
<span className="block text-[11px] text-ink-muted">{apiKeyScopeRisk(scope)}</span>
|
|
380
|
+
</span>
|
|
381
|
+
</label>
|
|
382
|
+
))}
|
|
383
|
+
</div>
|
|
384
|
+
</div>
|
|
385
|
+
)}
|
|
386
|
+
<div className="rounded-md border border-warning/40 bg-warning-soft p-3">
|
|
387
|
+
<label className="flex items-center gap-2 text-[13px] font-medium text-ink">
|
|
388
|
+
<input type="checkbox" checked={accessMode === 'full'} onChange={toggleFullAccess} />
|
|
389
|
+
Full access
|
|
390
|
+
</label>
|
|
391
|
+
<p className="mt-1 text-[11px] text-warning">
|
|
392
|
+
{kind === 'workspace'
|
|
393
|
+
? 'A full-access workspace key can do everything an admin can in this workspace: delete records, change the handbook, and manage members, keys and webhooks.'
|
|
394
|
+
: 'A full-access personal key can do everything you can do in this workspace, now and after your role changes. That includes deleting records.'}{' '}
|
|
395
|
+
Choose it only for a program that you control completely.
|
|
396
|
+
</p>
|
|
397
|
+
</div>
|
|
309
398
|
</div>
|
|
310
|
-
<p className="mt-2 text-[11px] text-ink-faint">
|
|
311
|
-
|
|
399
|
+
<p id={hintId} className="mt-2 text-[11px] text-ink-faint">
|
|
400
|
+
{nothingChosen
|
|
401
|
+
? 'Choose at least one permission, or full access.'
|
|
402
|
+
: 'Write includes read for the same resource, and does not include delete. Presets cover many scopes at once. No preset includes an extra permission.'}
|
|
312
403
|
</p>
|
|
313
404
|
</fieldset>
|
|
314
405
|
|
|
@@ -328,7 +419,10 @@ function CreateKeyModal({
|
|
|
328
419
|
</button>
|
|
329
420
|
<button
|
|
330
421
|
type="submit"
|
|
331
|
-
disabled={createApiKey.isPending}
|
|
422
|
+
disabled={createApiKey.isPending || nothingChosen}
|
|
423
|
+
// The hint says why the button is off. A screen reader reads it
|
|
424
|
+
// with the button, which is otherwise only greyed out.
|
|
425
|
+
aria-describedby={nothingChosen ? hintId : undefined}
|
|
332
426
|
className="rounded-md bg-accent px-3.5 py-2 text-[12px] font-semibold text-accent-fg hover:bg-accent-hover disabled:opacity-50"
|
|
333
427
|
>
|
|
334
428
|
{createApiKey.isPending ? 'Creating…' : 'Create'}
|
|
@@ -385,24 +479,46 @@ function SecretOnce({
|
|
|
385
479
|
)
|
|
386
480
|
}
|
|
387
481
|
|
|
482
|
+
/**
|
|
483
|
+
* The scopes of a key that give no sensitive power, in a few words: each
|
|
484
|
+
* preset by name, and the per-resource ones as a count.
|
|
485
|
+
*/
|
|
388
486
|
function formatScopeSummary(scopes: readonly ApiKeyScope[]): string {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
487
|
+
const plain = scopes.filter((scope) => !isSensitiveApiKeyScope(scope) || scope === 'write:all')
|
|
488
|
+
const presets = plain.filter(isApiKeyPresetScope)
|
|
489
|
+
const granular = plain.filter((scope) => !isApiKeyPresetScope(scope))
|
|
490
|
+
const custom =
|
|
491
|
+
presets.length === 0 ? `Custom (${String(granular.length)} scopes)` : `Custom (${String(granular.length)})`
|
|
392
492
|
|
|
393
|
-
|
|
394
|
-
|
|
493
|
+
return [...presets.map((scope) => API_KEY_SCOPE_LABELS[scope]), ...(granular.length === 0 ? [] : [custom])].join(', ')
|
|
494
|
+
}
|
|
395
495
|
|
|
396
|
-
|
|
397
|
-
|
|
496
|
+
/**
|
|
497
|
+
* What a key can reach, for the list. A sensitive power is always named and
|
|
498
|
+
* never counted into "Custom": a count would hide that a key can delete
|
|
499
|
+
* records or change the handbook. `write:all` stays in the words, and what it
|
|
500
|
+
* holds that is sensitive is named beside it.
|
|
501
|
+
*/
|
|
502
|
+
function ScopeSummary({ scopes }: { readonly scopes: readonly ApiKeyScope[] }): React.JSX.Element {
|
|
503
|
+
if (scopes.length === 0) {
|
|
504
|
+
return <Chip tone="warning">Full access</Chip>
|
|
398
505
|
}
|
|
399
506
|
|
|
400
|
-
|
|
401
|
-
return `Custom (${String(scopes.length)} scopes)`
|
|
402
|
-
}
|
|
507
|
+
const sensitive = sensitiveApiKeyScopesHeld(scopes)
|
|
403
508
|
|
|
404
|
-
return
|
|
405
|
-
|
|
509
|
+
return (
|
|
510
|
+
<>
|
|
511
|
+
{formatScopeSummary(scopes)}
|
|
512
|
+
{sensitive.length > 0 && (
|
|
513
|
+
<ul aria-label="Extra permissions" className="mt-1 flex flex-wrap gap-1">
|
|
514
|
+
{sensitive.map((scope) => (
|
|
515
|
+
<li key={scope}>
|
|
516
|
+
<Chip tone="warning">{API_KEY_SCOPE_LABELS[scope]}</Chip>
|
|
517
|
+
</li>
|
|
518
|
+
))}
|
|
519
|
+
</ul>
|
|
520
|
+
)}
|
|
521
|
+
</>
|
|
406
522
|
)
|
|
407
523
|
}
|
|
408
524
|
|
|
@@ -463,7 +579,9 @@ function ApiKeyRow({
|
|
|
463
579
|
return (
|
|
464
580
|
<tr className="border-b border-border last:border-0">
|
|
465
581
|
<td className="px-4 py-3 font-medium">{apiKey.name}</td>
|
|
466
|
-
<td className="px-4 py-3 text-ink-muted">
|
|
582
|
+
<td className="px-4 py-3 text-ink-muted">
|
|
583
|
+
<ScopeSummary scopes={apiKey.scopes} />
|
|
584
|
+
</td>
|
|
467
585
|
<td className="px-4 py-3 font-mono text-[12px] text-ink-muted">{apiKey.displayPrefix}</td>
|
|
468
586
|
<td className="px-4 py-3 text-ink-muted">{formatDate(apiKey.createdAt, timezone)}</td>
|
|
469
587
|
<td className="px-4 py-3 text-ink-muted">
|
|
@@ -10,6 +10,7 @@ import { useMemo, useState } from 'react'
|
|
|
10
10
|
import { Link } from 'react-router'
|
|
11
11
|
|
|
12
12
|
import { useCustomFields } from '../api/resources/customFields.ts'
|
|
13
|
+
import { useSession } from '../api/resources/session.ts'
|
|
13
14
|
import { InlineEdit } from './InlineEdit.tsx'
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -42,6 +43,8 @@ export function CustomFieldsPanel({
|
|
|
42
43
|
onPatch,
|
|
43
44
|
}: CustomFieldsPanelProps): React.JSX.Element {
|
|
44
45
|
const definitions = useCustomFields({ objectType, sort: 'sort_order', limit: 200 })
|
|
46
|
+
const { session } = useSession()
|
|
47
|
+
const isAdmin = session?.role === 'owner' || session?.role === 'admin'
|
|
45
48
|
|
|
46
49
|
if (definitions.isLoading) {
|
|
47
50
|
return <p className="text-[13px] text-ink-muted">Loading fields…</p>
|
|
@@ -50,11 +53,18 @@ export function CustomFieldsPanel({
|
|
|
50
53
|
if (definitions.records.length === 0) {
|
|
51
54
|
return (
|
|
52
55
|
<p className="text-[13px] text-ink-muted">
|
|
53
|
-
No custom fields yet.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
No custom fields yet.
|
|
57
|
+
{/* Admin is closed to a member, so only an admin gets the link. */}
|
|
58
|
+
{isAdmin && (
|
|
59
|
+
<>
|
|
60
|
+
{' '}
|
|
61
|
+
Add them at{' '}
|
|
62
|
+
<Link to="/admin/fields" className="text-accent hover:text-accent-hover">
|
|
63
|
+
Admin → Fields
|
|
64
|
+
</Link>
|
|
65
|
+
.
|
|
66
|
+
</>
|
|
67
|
+
)}
|
|
58
68
|
</p>
|
|
59
69
|
)
|
|
60
70
|
}
|