betterstart-cli 0.0.28 → 0.0.30
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/assets/adapters/next/integrations/mailchimp/actions/mailchimp.ts +0 -1
- package/dist/assets/adapters/next/plugins/blog/schemas/menus.json +1 -1
- package/dist/assets/adapters/next/plugins/blog/schemas/posts.json +1 -1
- package/dist/assets/adapters/next/templates/init/admin-globals.css +1 -1
- package/dist/assets/adapters/next/templates/init/components/layouts/admin-nav-link.tsx +12 -2
- package/dist/assets/adapters/next/templates/init/components/layouts/admin-settings-sidebar.tsx +75 -0
- package/dist/assets/adapters/next/templates/init/components/layouts/admin-sidebar-nav-link.tsx +12 -2
- package/dist/assets/adapters/next/templates/init/components/layouts/admin-sidebar.tsx +2 -8
- package/dist/assets/adapters/next/templates/init/components/shared/data-table/data-grid.tsx +14 -5
- package/dist/assets/adapters/next/templates/init/components/shared/data-table/data-table.tsx +111 -112
- package/dist/assets/adapters/next/templates/init/components/shared/dev-mode/dev-mode-types.ts +4 -0
- package/dist/assets/adapters/next/templates/init/components/shared/dev-mode-integrate.tsx +1 -1
- package/dist/assets/adapters/next/templates/init/components/shared/entity-versions/entity-versions-drawer.tsx +1 -1
- package/dist/assets/adapters/next/templates/init/components/shared/media/media-url-importer.tsx +45 -47
- package/dist/assets/adapters/next/templates/init/components/shared/page-header.tsx +1 -1
- package/dist/assets/adapters/next/templates/init/data/webhook-events.ts +5 -0
- package/dist/assets/adapters/next/templates/init/hooks/use-table-utils.ts +27 -7
- package/dist/assets/adapters/next/templates/init/hooks/use-webhooks.ts +211 -0
- package/dist/assets/adapters/next/templates/init/lib/actions/audit/types.ts +2 -0
- package/dist/assets/adapters/next/templates/init/lib/actions/forms/index.ts +0 -1
- package/dist/assets/adapters/next/templates/init/lib/actions/forms/types.ts +0 -4
- package/dist/assets/adapters/next/templates/init/lib/actions/forms/upsert-form-settings.ts +0 -2
- package/dist/assets/adapters/next/templates/init/lib/actions/webhooks/create-webhook.ts +55 -0
- package/dist/assets/adapters/next/templates/init/lib/actions/webhooks/delete-webhook.ts +26 -0
- package/dist/assets/adapters/next/templates/init/lib/actions/webhooks/dispatch.ts +135 -0
- package/dist/assets/adapters/next/templates/init/lib/actions/webhooks/get-webhook-deliveries.ts +124 -0
- package/dist/assets/adapters/next/templates/init/lib/actions/webhooks/get-webhook-secret.ts +28 -0
- package/dist/assets/adapters/next/templates/init/lib/actions/webhooks/get-webhook-subscriptions.ts +32 -0
- package/dist/assets/adapters/next/templates/init/lib/actions/webhooks/get-webhooks.ts +154 -0
- package/dist/assets/adapters/next/templates/init/lib/actions/webhooks/index.ts +30 -0
- package/dist/assets/adapters/next/templates/init/lib/actions/webhooks/internal-get-active-endpoints.ts +20 -0
- package/dist/assets/adapters/next/templates/init/lib/actions/webhooks/regenerate-webhook-secret.ts +35 -0
- package/dist/assets/adapters/next/templates/init/lib/actions/webhooks/register.ts +70 -0
- package/dist/assets/adapters/next/templates/init/lib/actions/webhooks/send-test-webhook.ts +81 -0
- package/dist/assets/adapters/next/templates/init/lib/actions/webhooks/types.ts +104 -0
- package/dist/assets/adapters/next/templates/init/lib/actions/webhooks/update-webhook.ts +72 -0
- package/dist/assets/adapters/next/templates/init/lib/db/core/schema.ts +71 -2
- package/dist/assets/adapters/next/templates/init/lib/lifecycle-hooks/register.ts +2 -0
- package/dist/assets/adapters/next/templates/init/lib/lifecycle-hooks/runner.ts +3 -1
- package/dist/assets/adapters/next/templates/init/lib/lifecycle-hooks/types.ts +6 -1
- package/dist/assets/adapters/next/templates/init/pages/auth-gate-rsc.tsx +1 -1
- package/dist/assets/adapters/next/templates/init/pages/media/media-page-content.tsx +1 -1
- package/dist/assets/adapters/next/templates/init/pages/media/media-page-skeleton.tsx +1 -1
- package/dist/assets/adapters/next/templates/init/pages/settings/audit-log/audit-log-columns.tsx +150 -0
- package/dist/assets/adapters/next/templates/init/pages/settings/audit-log/audit-log-page-content.tsx +137 -0
- package/dist/assets/adapters/next/templates/init/pages/{audit-log → settings/audit-log}/audit-log-page-skeleton.tsx +1 -1
- package/dist/assets/adapters/next/templates/init/pages/settings/audit-log/audit-log-table.tsx +295 -0
- package/dist/assets/adapters/next/templates/init/pages/settings/forms/edit-form-notifications-dialog.tsx +128 -0
- package/dist/assets/adapters/next/templates/init/pages/settings/forms/forms-settings-page-content.tsx +111 -0
- package/dist/assets/adapters/next/templates/init/pages/settings/forms/forms-settings-page-skeleton.tsx +7 -0
- package/dist/assets/adapters/next/templates/init/pages/settings/forms/forms-settings-page.tsx +14 -0
- package/dist/assets/adapters/next/templates/init/pages/settings/settings-layout.tsx +10 -0
- package/dist/assets/adapters/next/templates/init/pages/settings/webhooks/delete-webhook-dialog.tsx +82 -0
- package/dist/assets/adapters/next/templates/init/pages/settings/webhooks/webhook-actions.tsx +53 -0
- package/dist/assets/adapters/next/templates/init/pages/settings/webhooks/webhook-enabled-switch.tsx +18 -0
- package/dist/assets/adapters/next/templates/init/pages/settings/webhooks/webhook-endpoint-dialog.tsx +370 -0
- package/dist/assets/adapters/next/templates/init/pages/settings/webhooks/webhooks-columns.tsx +258 -0
- package/dist/assets/adapters/next/templates/init/pages/settings/webhooks/webhooks-logs-columns.tsx +200 -0
- package/dist/assets/adapters/next/templates/init/pages/settings/webhooks/webhooks-logs-page-content.tsx +117 -0
- package/dist/assets/adapters/next/templates/init/pages/settings/webhooks/webhooks-logs-page.tsx +14 -0
- package/dist/assets/adapters/next/templates/init/pages/settings/webhooks/webhooks-logs-table.tsx +253 -0
- package/dist/assets/adapters/next/templates/init/pages/settings/webhooks/webhooks-page-content.tsx +161 -0
- package/dist/assets/adapters/next/templates/init/pages/settings/webhooks/webhooks-page-skeleton.tsx +7 -0
- package/dist/assets/adapters/next/templates/init/pages/settings/webhooks/webhooks-page.tsx +14 -0
- package/dist/assets/adapters/next/templates/init/pages/settings/webhooks/webhooks-table.tsx +264 -0
- package/dist/assets/adapters/next/templates/init/pages/users/users-page-skeleton.tsx +1 -1
- package/dist/assets/adapters/next/templates/init/pages/users/users-table.tsx +103 -109
- package/dist/assets/adapters/next/templates/init/types/webhooks.ts +7 -0
- package/dist/assets/adapters/next/templates/init/utils/webhook/signature.ts +13 -0
- package/dist/assets/shared-assets/react-admin/ui/card.tsx +1 -1
- package/dist/assets/shared-assets/react-admin/ui/drawer.tsx +2 -2
- package/dist/assets/shared-assets/react-admin/ui/input-group.tsx +3 -3
- package/dist/assets/shared-assets/react-admin/ui/sidebar.tsx +1 -1
- package/dist/cli.js +947 -620
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
- package/dist/assets/adapters/next/templates/init/lib/actions/forms/test-form-webhook.ts +0 -40
- package/dist/assets/adapters/next/templates/init/pages/audit-log/audit-log-page-content.tsx +0 -550
- package/dist/assets/adapters/next/templates/init/utils/webhook/webhook.ts +0 -28
- /package/dist/assets/adapters/next/templates/init/pages/{audit-log → settings/audit-log}/audit-log-detail-drawer.tsx +0 -0
- /package/dist/assets/adapters/next/templates/init/pages/{audit-log → settings/audit-log}/audit-log-detail-row.tsx +0 -0
- /package/dist/assets/adapters/next/templates/init/pages/{audit-log → settings/audit-log}/audit-log-page.tsx +0 -0
package/dist/assets/adapters/next/templates/init/pages/settings/webhooks/webhook-endpoint-dialog.tsx
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import type { WebhookEndpointListItem } from '@admin/actions/webhooks'
|
|
4
|
+
import {
|
|
5
|
+
createWebhook,
|
|
6
|
+
getWebhookSecret,
|
|
7
|
+
regenerateWebhookSecret,
|
|
8
|
+
sendTestWebhook,
|
|
9
|
+
updateWebhook
|
|
10
|
+
} from '@admin/actions/webhooks'
|
|
11
|
+
import { Button } from '@admin/components/ui/button'
|
|
12
|
+
import { Checkbox } from '@admin/components/ui/checkbox'
|
|
13
|
+
import {
|
|
14
|
+
Dialog,
|
|
15
|
+
DialogBody,
|
|
16
|
+
DialogContent,
|
|
17
|
+
DialogDescription,
|
|
18
|
+
DialogFooter,
|
|
19
|
+
DialogHeader,
|
|
20
|
+
DialogTitle
|
|
21
|
+
} from '@admin/components/ui/dialog'
|
|
22
|
+
import {
|
|
23
|
+
Form,
|
|
24
|
+
FormControl,
|
|
25
|
+
FormField,
|
|
26
|
+
FormItem,
|
|
27
|
+
FormLabel,
|
|
28
|
+
FormMessage
|
|
29
|
+
} from '@admin/components/ui/form'
|
|
30
|
+
import { Input } from '@admin/components/ui/input'
|
|
31
|
+
import { Switch } from '@admin/components/ui/switch'
|
|
32
|
+
import { webhookEventSources } from '@admin/data/webhook-events'
|
|
33
|
+
import { useWebhookSubscriptions } from '@admin/hooks/use-webhooks'
|
|
34
|
+
import { standardSchemaResolver } from '@hookform/resolvers/standard-schema'
|
|
35
|
+
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
36
|
+
import { LoaderCircle } from 'lucide-react'
|
|
37
|
+
import * as React from 'react'
|
|
38
|
+
import { useForm } from 'react-hook-form'
|
|
39
|
+
import { toast } from 'sonner'
|
|
40
|
+
import { z } from 'zod/v3'
|
|
41
|
+
|
|
42
|
+
const endpointSchema = z.object({
|
|
43
|
+
name: z.string().trim().min(1, 'Name is required').max(200, 'Name is too long'),
|
|
44
|
+
url: z.string().trim().url('Enter a valid URL'),
|
|
45
|
+
enabled: z.boolean(),
|
|
46
|
+
events: z.array(z.string())
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
type EndpointFormValues = z.infer<typeof endpointSchema>
|
|
50
|
+
|
|
51
|
+
interface WebhookEndpointDialogProps {
|
|
52
|
+
webhook: WebhookEndpointListItem | null
|
|
53
|
+
open: boolean
|
|
54
|
+
onOpenChange: (open: boolean) => void
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function WebhookEndpointDialog({ webhook, open, onOpenChange }: WebhookEndpointDialogProps) {
|
|
58
|
+
const queryClient = useQueryClient()
|
|
59
|
+
const isEdit = webhook !== null
|
|
60
|
+
const { data: subscriptions } = useWebhookSubscriptions()
|
|
61
|
+
const subscribedEvents = React.useMemo(
|
|
62
|
+
() =>
|
|
63
|
+
webhook
|
|
64
|
+
? (subscriptions ?? [])
|
|
65
|
+
.filter((entry) => entry.webhookId === webhook.id)
|
|
66
|
+
.map((entry) => entry.event)
|
|
67
|
+
: [],
|
|
68
|
+
[subscriptions, webhook]
|
|
69
|
+
)
|
|
70
|
+
const [selectedEvents, setSelectedEvents] = React.useState<string[] | null>(null)
|
|
71
|
+
const events = selectedEvents ?? subscribedEvents
|
|
72
|
+
const [secret, setSecret] = React.useState<string | null>(null)
|
|
73
|
+
|
|
74
|
+
const formSources = webhookEventSources.filter((source) => source.kind === 'form')
|
|
75
|
+
const contentSources = webhookEventSources.filter((source) => source.kind !== 'form')
|
|
76
|
+
|
|
77
|
+
const form = useForm<EndpointFormValues>({
|
|
78
|
+
resolver: standardSchemaResolver(endpointSchema),
|
|
79
|
+
defaultValues: {
|
|
80
|
+
name: webhook?.name ?? '',
|
|
81
|
+
url: webhook?.url ?? '',
|
|
82
|
+
enabled: webhook?.enabled ?? true,
|
|
83
|
+
events: subscribedEvents
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
const saveMutation = useMutation({
|
|
88
|
+
mutationFn: async (values: EndpointFormValues) => {
|
|
89
|
+
const endpointValues = {
|
|
90
|
+
name: values.name,
|
|
91
|
+
url: values.url,
|
|
92
|
+
enabled: values.enabled
|
|
93
|
+
}
|
|
94
|
+
const result = webhook
|
|
95
|
+
? await updateWebhook(webhook.id, { ...endpointValues, events })
|
|
96
|
+
: await createWebhook({ ...endpointValues, events })
|
|
97
|
+
if (!result.success) {
|
|
98
|
+
throw new Error(result.error || 'Failed to save endpoint')
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return result
|
|
102
|
+
},
|
|
103
|
+
onSuccess: async () => {
|
|
104
|
+
toast.success(isEdit ? 'Endpoint saved' : 'Endpoint created')
|
|
105
|
+
await queryClient.invalidateQueries({ queryKey: ['webhooks'] })
|
|
106
|
+
await queryClient.invalidateQueries({
|
|
107
|
+
queryKey: ['webhook-subscriptions']
|
|
108
|
+
})
|
|
109
|
+
onOpenChange(false)
|
|
110
|
+
},
|
|
111
|
+
onError: (error: Error) => {
|
|
112
|
+
toast.error(error.message || 'An unexpected error occurred')
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
const revealSecretMutation = useMutation({
|
|
117
|
+
mutationFn: async () => {
|
|
118
|
+
if (!webhook) throw new Error('Save the endpoint first')
|
|
119
|
+
const result = await getWebhookSecret(webhook.id)
|
|
120
|
+
if (!result.success || !result.secret) {
|
|
121
|
+
throw new Error(result.error || 'Failed to fetch signing secret')
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return result.secret
|
|
125
|
+
},
|
|
126
|
+
onSuccess: (value) => setSecret(value),
|
|
127
|
+
onError: (error: Error) => {
|
|
128
|
+
toast.error(error.message || 'Failed to fetch signing secret')
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
const regenerateSecretMutation = useMutation({
|
|
133
|
+
mutationFn: async () => {
|
|
134
|
+
if (!webhook) throw new Error('Save the endpoint first')
|
|
135
|
+
const result = await regenerateWebhookSecret(webhook.id)
|
|
136
|
+
if (!result.success || !result.secret) {
|
|
137
|
+
throw new Error(result.error || 'Failed to regenerate signing secret')
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return result.secret
|
|
141
|
+
},
|
|
142
|
+
onSuccess: (value) => {
|
|
143
|
+
setSecret(value)
|
|
144
|
+
toast.success('Signing secret regenerated')
|
|
145
|
+
},
|
|
146
|
+
onError: (error: Error) => {
|
|
147
|
+
toast.error(error.message || 'Failed to regenerate signing secret')
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
const testMutation = useMutation({
|
|
152
|
+
mutationFn: async () => {
|
|
153
|
+
if (!webhook) throw new Error('Save the endpoint first')
|
|
154
|
+
const result = await sendTestWebhook(webhook.id)
|
|
155
|
+
if (!result.success) {
|
|
156
|
+
throw new Error(result.error || 'Test webhook failed')
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return result
|
|
160
|
+
},
|
|
161
|
+
onSuccess: async (result) => {
|
|
162
|
+
toast.success(
|
|
163
|
+
result.statusCode ? `Test delivered (status ${result.statusCode})` : 'Test delivered'
|
|
164
|
+
)
|
|
165
|
+
await queryClient.invalidateQueries({ queryKey: ['webhook-deliveries'] })
|
|
166
|
+
},
|
|
167
|
+
onError: (error: Error) => {
|
|
168
|
+
toast.error(error.message || 'Test webhook failed')
|
|
169
|
+
}
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
const isPending = saveMutation.isPending
|
|
173
|
+
|
|
174
|
+
function toggleEvent(event: string, checked: boolean) {
|
|
175
|
+
const nextEvents = checked ? [...events, event] : events.filter((entry) => entry !== event)
|
|
176
|
+
setSelectedEvents(nextEvents)
|
|
177
|
+
form.setValue('events', nextEvents)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return (
|
|
181
|
+
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
182
|
+
<DialogContent className="sm:max-w-135">
|
|
183
|
+
<Form {...form}>
|
|
184
|
+
<form onSubmit={form.handleSubmit((values) => saveMutation.mutate(values))}>
|
|
185
|
+
<DialogHeader>
|
|
186
|
+
<DialogTitle>
|
|
187
|
+
{isEdit ? `Edit endpoint — ${webhook.name}` : 'Add endpoint'}
|
|
188
|
+
</DialogTitle>
|
|
189
|
+
<DialogDescription>
|
|
190
|
+
Events are delivered as signed JSON POST requests
|
|
191
|
+
</DialogDescription>
|
|
192
|
+
</DialogHeader>
|
|
193
|
+
|
|
194
|
+
<DialogBody>
|
|
195
|
+
<div className="space-y-4">
|
|
196
|
+
<FormField
|
|
197
|
+
control={form.control}
|
|
198
|
+
name="name"
|
|
199
|
+
render={({ field }) => (
|
|
200
|
+
<FormItem>
|
|
201
|
+
<FormLabel>Name</FormLabel>
|
|
202
|
+
<FormControl>
|
|
203
|
+
<Input placeholder="Zapier" disabled={isPending} {...field} />
|
|
204
|
+
</FormControl>
|
|
205
|
+
<FormMessage />
|
|
206
|
+
</FormItem>
|
|
207
|
+
)}
|
|
208
|
+
/>
|
|
209
|
+
<FormField
|
|
210
|
+
control={form.control}
|
|
211
|
+
name="url"
|
|
212
|
+
render={({ field }) => (
|
|
213
|
+
<FormItem>
|
|
214
|
+
<FormLabel>URL</FormLabel>
|
|
215
|
+
<FormControl>
|
|
216
|
+
<Input
|
|
217
|
+
type="url"
|
|
218
|
+
placeholder="https://example.com/webhooks"
|
|
219
|
+
disabled={isPending}
|
|
220
|
+
{...field}
|
|
221
|
+
/>
|
|
222
|
+
</FormControl>
|
|
223
|
+
<FormMessage />
|
|
224
|
+
</FormItem>
|
|
225
|
+
)}
|
|
226
|
+
/>
|
|
227
|
+
<FormField
|
|
228
|
+
control={form.control}
|
|
229
|
+
name="enabled"
|
|
230
|
+
render={({ field }) => (
|
|
231
|
+
<FormItem className="flex items-center justify-between rounded-md border border-border px-3 py-2">
|
|
232
|
+
<FormLabel>Enabled</FormLabel>
|
|
233
|
+
<FormControl>
|
|
234
|
+
<Switch
|
|
235
|
+
checked={field.value}
|
|
236
|
+
onCheckedChange={field.onChange}
|
|
237
|
+
disabled={isPending}
|
|
238
|
+
/>
|
|
239
|
+
</FormControl>
|
|
240
|
+
</FormItem>
|
|
241
|
+
)}
|
|
242
|
+
/>
|
|
243
|
+
{isEdit && (
|
|
244
|
+
<div className="space-y-2 rounded-md border border-border p-3">
|
|
245
|
+
<p className="text-sm font-medium leading-none">Signing secret</p>
|
|
246
|
+
<div className="flex items-center gap-2">
|
|
247
|
+
<span className="min-w-0 flex-1 truncate font-mono text-xs">
|
|
248
|
+
{secret ?? 'whsec_••••••••••••••••'}
|
|
249
|
+
</span>
|
|
250
|
+
<Button
|
|
251
|
+
type="button"
|
|
252
|
+
variant="outline"
|
|
253
|
+
size="sm"
|
|
254
|
+
disabled={revealSecretMutation.isPending || secret !== null}
|
|
255
|
+
onClick={() => revealSecretMutation.mutate()}
|
|
256
|
+
>
|
|
257
|
+
Reveal
|
|
258
|
+
</Button>
|
|
259
|
+
<Button
|
|
260
|
+
type="button"
|
|
261
|
+
variant="outline"
|
|
262
|
+
size="sm"
|
|
263
|
+
disabled={regenerateSecretMutation.isPending}
|
|
264
|
+
onClick={() => regenerateSecretMutation.mutate()}
|
|
265
|
+
>
|
|
266
|
+
{regenerateSecretMutation.isPending && (
|
|
267
|
+
<LoaderCircle className="animate-spin" />
|
|
268
|
+
)}
|
|
269
|
+
Regenerate
|
|
270
|
+
</Button>
|
|
271
|
+
</div>
|
|
272
|
+
<p className="text-xs text-muted-foreground">
|
|
273
|
+
Requests carry x-webhook-id, x-webhook-timestamp, and an HMAC-SHA256
|
|
274
|
+
x-webhook-signature of the body.
|
|
275
|
+
</p>
|
|
276
|
+
</div>
|
|
277
|
+
)}
|
|
278
|
+
{(formSources.length > 0 || contentSources.length > 0) && (
|
|
279
|
+
<FormField
|
|
280
|
+
control={form.control}
|
|
281
|
+
name="events"
|
|
282
|
+
render={() => (
|
|
283
|
+
<React.Fragment>
|
|
284
|
+
{formSources.length > 0 && (
|
|
285
|
+
<fieldset className="space-y-2 rounded-md border border-border p-3">
|
|
286
|
+
<legend className="px-1 text-xs font-medium uppercase tracking-wide text-muted-foreground">
|
|
287
|
+
Events · Forms
|
|
288
|
+
</legend>
|
|
289
|
+
{formSources.flatMap((source) =>
|
|
290
|
+
source.events.map((event) => (
|
|
291
|
+
<FormItem key={event} className="flex items-center gap-2 space-y-0">
|
|
292
|
+
<FormControl>
|
|
293
|
+
<Checkbox
|
|
294
|
+
checked={events.includes(event)}
|
|
295
|
+
onCheckedChange={(checked) =>
|
|
296
|
+
toggleEvent(event, checked === true)
|
|
297
|
+
}
|
|
298
|
+
disabled={isPending}
|
|
299
|
+
/>
|
|
300
|
+
</FormControl>
|
|
301
|
+
<FormLabel className="font-mono text-xs font-normal">
|
|
302
|
+
{event}
|
|
303
|
+
</FormLabel>
|
|
304
|
+
</FormItem>
|
|
305
|
+
))
|
|
306
|
+
)}
|
|
307
|
+
</fieldset>
|
|
308
|
+
)}
|
|
309
|
+
{contentSources.length > 0 && (
|
|
310
|
+
<fieldset className="space-y-2 rounded-md border border-border p-3">
|
|
311
|
+
<legend className="px-1 text-xs font-medium uppercase tracking-wide text-muted-foreground">
|
|
312
|
+
Events · Entities
|
|
313
|
+
</legend>
|
|
314
|
+
{contentSources.flatMap((source) =>
|
|
315
|
+
source.events.map((event) => (
|
|
316
|
+
<FormItem key={event} className="flex items-center gap-2 space-y-0">
|
|
317
|
+
<FormControl>
|
|
318
|
+
<Checkbox
|
|
319
|
+
checked={events.includes(event)}
|
|
320
|
+
onCheckedChange={(checked) =>
|
|
321
|
+
toggleEvent(event, checked === true)
|
|
322
|
+
}
|
|
323
|
+
disabled={isPending}
|
|
324
|
+
/>
|
|
325
|
+
</FormControl>
|
|
326
|
+
<FormLabel className="font-mono text-xs font-normal">
|
|
327
|
+
{event}
|
|
328
|
+
</FormLabel>
|
|
329
|
+
</FormItem>
|
|
330
|
+
))
|
|
331
|
+
)}
|
|
332
|
+
</fieldset>
|
|
333
|
+
)}
|
|
334
|
+
</React.Fragment>
|
|
335
|
+
)}
|
|
336
|
+
/>
|
|
337
|
+
)}
|
|
338
|
+
{formSources.length === 0 && contentSources.length === 0 && (
|
|
339
|
+
<p className="text-sm text-muted-foreground">
|
|
340
|
+
No schemas yet — generate an entity or form schema to subscribe this endpoint to
|
|
341
|
+
its events.
|
|
342
|
+
</p>
|
|
343
|
+
)}
|
|
344
|
+
</div>
|
|
345
|
+
</DialogBody>
|
|
346
|
+
|
|
347
|
+
<DialogFooter showCloseButton={true}>
|
|
348
|
+
{isEdit && (
|
|
349
|
+
<Button
|
|
350
|
+
type="button"
|
|
351
|
+
variant="outline"
|
|
352
|
+
size="lg"
|
|
353
|
+
disabled={testMutation.isPending}
|
|
354
|
+
onClick={() => testMutation.mutate()}
|
|
355
|
+
>
|
|
356
|
+
{testMutation.isPending && <LoaderCircle className="animate-spin" />}
|
|
357
|
+
Send test
|
|
358
|
+
</Button>
|
|
359
|
+
)}
|
|
360
|
+
<Button type="submit" disabled={isPending} size="lg">
|
|
361
|
+
{isPending && <LoaderCircle className="animate-spin" />}
|
|
362
|
+
{isEdit ? 'Save endpoint' : 'Create endpoint'}
|
|
363
|
+
</Button>
|
|
364
|
+
</DialogFooter>
|
|
365
|
+
</form>
|
|
366
|
+
</Form>
|
|
367
|
+
</DialogContent>
|
|
368
|
+
</Dialog>
|
|
369
|
+
)
|
|
370
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import type { WebhookEndpointListItem } from '@admin/actions/webhooks'
|
|
4
|
+
import { SortIndicator } from '@admin/components/shared/sort-indicator'
|
|
5
|
+
import { Badge } from '@admin/components/ui/badge'
|
|
6
|
+
import { Button } from '@admin/components/ui/button'
|
|
7
|
+
import type { ColumnDef } from '@tanstack/react-table'
|
|
8
|
+
import { formatDistanceToNow } from 'date-fns'
|
|
9
|
+
import { WebhookActions } from './webhook-actions'
|
|
10
|
+
import { WebhookEnabledSwitch } from './webhook-enabled-switch'
|
|
11
|
+
|
|
12
|
+
interface WebhooksColumnsOptions {
|
|
13
|
+
onEdit: (webhook: WebhookEndpointListItem) => void
|
|
14
|
+
onDelete: (webhook: WebhookEndpointListItem) => void
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function createWebhooksColumns({
|
|
18
|
+
onEdit,
|
|
19
|
+
onDelete
|
|
20
|
+
}: WebhooksColumnsOptions): ColumnDef<WebhookEndpointListItem>[] {
|
|
21
|
+
return [
|
|
22
|
+
{
|
|
23
|
+
accessorKey: 'name',
|
|
24
|
+
size: 240,
|
|
25
|
+
header: ({ column }) => {
|
|
26
|
+
const sortDirection = column.getIsSorted()
|
|
27
|
+
const sortLabel =
|
|
28
|
+
sortDirection === 'asc'
|
|
29
|
+
? 'sorted ascending'
|
|
30
|
+
: sortDirection === 'desc'
|
|
31
|
+
? 'sorted descending'
|
|
32
|
+
: 'not sorted'
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<Button
|
|
36
|
+
variant="ghost"
|
|
37
|
+
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
|
38
|
+
className="w-full min-w-0 justify-start overflow-hidden px-0! border-none rounded-none bg-transparent! scale-100! group"
|
|
39
|
+
aria-label={`Sort by Name, ${sortLabel}`}
|
|
40
|
+
aria-sort={
|
|
41
|
+
sortDirection === 'asc'
|
|
42
|
+
? 'ascending'
|
|
43
|
+
: sortDirection === 'desc'
|
|
44
|
+
? 'descending'
|
|
45
|
+
: 'none'
|
|
46
|
+
}
|
|
47
|
+
>
|
|
48
|
+
<span className="truncate">Name</span>
|
|
49
|
+
<SortIndicator direction={sortDirection} />
|
|
50
|
+
</Button>
|
|
51
|
+
)
|
|
52
|
+
},
|
|
53
|
+
cell: ({ row }) => <span className="truncate font-medium">{row.original.name}</span>,
|
|
54
|
+
enableHiding: false
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
accessorKey: 'url',
|
|
58
|
+
size: 320,
|
|
59
|
+
header: ({ column }) => {
|
|
60
|
+
const sortDirection = column.getIsSorted()
|
|
61
|
+
const sortLabel =
|
|
62
|
+
sortDirection === 'asc'
|
|
63
|
+
? 'sorted ascending'
|
|
64
|
+
: sortDirection === 'desc'
|
|
65
|
+
? 'sorted descending'
|
|
66
|
+
: 'not sorted'
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<Button
|
|
70
|
+
variant="ghost"
|
|
71
|
+
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
|
72
|
+
className="w-full min-w-0 justify-start overflow-hidden px-0! border-none rounded-none bg-transparent! scale-100! group"
|
|
73
|
+
aria-label={`Sort by URL, ${sortLabel}`}
|
|
74
|
+
aria-sort={
|
|
75
|
+
sortDirection === 'asc'
|
|
76
|
+
? 'ascending'
|
|
77
|
+
: sortDirection === 'desc'
|
|
78
|
+
? 'descending'
|
|
79
|
+
: 'none'
|
|
80
|
+
}
|
|
81
|
+
>
|
|
82
|
+
<span className="truncate">URL</span>
|
|
83
|
+
<SortIndicator direction={sortDirection} />
|
|
84
|
+
</Button>
|
|
85
|
+
)
|
|
86
|
+
},
|
|
87
|
+
cell: ({ row }) => (
|
|
88
|
+
<span className="truncate font-mono text-xs text-muted-foreground">{row.original.url}</span>
|
|
89
|
+
)
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
accessorKey: 'enabled',
|
|
93
|
+
size: 110,
|
|
94
|
+
header: ({ column }) => {
|
|
95
|
+
const sortDirection = column.getIsSorted()
|
|
96
|
+
const sortLabel =
|
|
97
|
+
sortDirection === 'asc'
|
|
98
|
+
? 'sorted ascending'
|
|
99
|
+
: sortDirection === 'desc'
|
|
100
|
+
? 'sorted descending'
|
|
101
|
+
: 'not sorted'
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<Button
|
|
105
|
+
variant="ghost"
|
|
106
|
+
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
|
107
|
+
className="w-full min-w-0 justify-start overflow-hidden px-0! border-none rounded-none bg-transparent! scale-100! group"
|
|
108
|
+
aria-label={`Sort by Enabled, ${sortLabel}`}
|
|
109
|
+
aria-sort={
|
|
110
|
+
sortDirection === 'asc'
|
|
111
|
+
? 'ascending'
|
|
112
|
+
: sortDirection === 'desc'
|
|
113
|
+
? 'descending'
|
|
114
|
+
: 'none'
|
|
115
|
+
}
|
|
116
|
+
>
|
|
117
|
+
<span className="truncate">Enabled</span>
|
|
118
|
+
<SortIndicator direction={sortDirection} />
|
|
119
|
+
</Button>
|
|
120
|
+
)
|
|
121
|
+
},
|
|
122
|
+
cell: ({ row }) => <WebhookEnabledSwitch webhook={row.original} />
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
accessorKey: 'eventCount',
|
|
126
|
+
size: 100,
|
|
127
|
+
header: ({ column }) => {
|
|
128
|
+
const sortDirection = column.getIsSorted()
|
|
129
|
+
const sortLabel =
|
|
130
|
+
sortDirection === 'asc'
|
|
131
|
+
? 'sorted ascending'
|
|
132
|
+
: sortDirection === 'desc'
|
|
133
|
+
? 'sorted descending'
|
|
134
|
+
: 'not sorted'
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<Button
|
|
138
|
+
variant="ghost"
|
|
139
|
+
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
|
140
|
+
className="w-full min-w-0 justify-start overflow-hidden px-0! border-none rounded-none bg-transparent! scale-100! group"
|
|
141
|
+
aria-label={`Sort by Events, ${sortLabel}`}
|
|
142
|
+
aria-sort={
|
|
143
|
+
sortDirection === 'asc'
|
|
144
|
+
? 'ascending'
|
|
145
|
+
: sortDirection === 'desc'
|
|
146
|
+
? 'descending'
|
|
147
|
+
: 'none'
|
|
148
|
+
}
|
|
149
|
+
>
|
|
150
|
+
<span className="truncate">Events</span>
|
|
151
|
+
<SortIndicator direction={sortDirection} />
|
|
152
|
+
</Button>
|
|
153
|
+
)
|
|
154
|
+
},
|
|
155
|
+
cell: ({ row }) => <span className="tabular-nums">{row.original.eventCount}</span>
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
accessorKey: 'lastDeliveryAt',
|
|
159
|
+
size: 220,
|
|
160
|
+
header: ({ column }) => {
|
|
161
|
+
const sortDirection = column.getIsSorted()
|
|
162
|
+
const sortLabel =
|
|
163
|
+
sortDirection === 'asc'
|
|
164
|
+
? 'sorted ascending'
|
|
165
|
+
: sortDirection === 'desc'
|
|
166
|
+
? 'sorted descending'
|
|
167
|
+
: 'not sorted'
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<Button
|
|
171
|
+
variant="ghost"
|
|
172
|
+
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
|
173
|
+
className="w-full min-w-0 justify-start overflow-hidden px-0! border-none rounded-none bg-transparent! scale-100! group"
|
|
174
|
+
aria-label={`Sort by Last delivery, ${sortLabel}`}
|
|
175
|
+
aria-sort={
|
|
176
|
+
sortDirection === 'asc'
|
|
177
|
+
? 'ascending'
|
|
178
|
+
: sortDirection === 'desc'
|
|
179
|
+
? 'descending'
|
|
180
|
+
: 'none'
|
|
181
|
+
}
|
|
182
|
+
>
|
|
183
|
+
<span className="truncate">Last delivery</span>
|
|
184
|
+
<SortIndicator direction={sortDirection} />
|
|
185
|
+
</Button>
|
|
186
|
+
)
|
|
187
|
+
},
|
|
188
|
+
cell: ({ row }) =>
|
|
189
|
+
row.original.lastDeliveryAt ? (
|
|
190
|
+
<span className="flex min-w-0 items-center gap-2">
|
|
191
|
+
<Badge variant={row.original.lastDeliverySuccess ? 'outline' : 'destructive'}>
|
|
192
|
+
{row.original.lastDeliverySuccess ? 'Delivered' : 'Failed'}
|
|
193
|
+
</Badge>
|
|
194
|
+
<span className="truncate text-xs text-muted-foreground">
|
|
195
|
+
{formatDistanceToNow(new Date(row.original.lastDeliveryAt), {
|
|
196
|
+
addSuffix: true
|
|
197
|
+
})}
|
|
198
|
+
</span>
|
|
199
|
+
</span>
|
|
200
|
+
) : (
|
|
201
|
+
<span className="text-muted-foreground">—</span>
|
|
202
|
+
)
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
accessorKey: 'createdAt',
|
|
206
|
+
size: 120,
|
|
207
|
+
header: ({ column }) => {
|
|
208
|
+
const sortDirection = column.getIsSorted()
|
|
209
|
+
const sortLabel =
|
|
210
|
+
sortDirection === 'asc'
|
|
211
|
+
? 'sorted ascending'
|
|
212
|
+
: sortDirection === 'desc'
|
|
213
|
+
? 'sorted descending'
|
|
214
|
+
: 'not sorted'
|
|
215
|
+
|
|
216
|
+
return (
|
|
217
|
+
<Button
|
|
218
|
+
variant="ghost"
|
|
219
|
+
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
|
220
|
+
className="w-full min-w-0 justify-start overflow-hidden px-0! border-none rounded-none bg-transparent! scale-100! group"
|
|
221
|
+
aria-label={`Sort by Created, ${sortLabel}`}
|
|
222
|
+
aria-sort={
|
|
223
|
+
sortDirection === 'asc'
|
|
224
|
+
? 'ascending'
|
|
225
|
+
: sortDirection === 'desc'
|
|
226
|
+
? 'descending'
|
|
227
|
+
: 'none'
|
|
228
|
+
}
|
|
229
|
+
>
|
|
230
|
+
<span className="truncate">Created</span>
|
|
231
|
+
<SortIndicator direction={sortDirection} />
|
|
232
|
+
</Button>
|
|
233
|
+
)
|
|
234
|
+
},
|
|
235
|
+
cell: ({ row }) => (
|
|
236
|
+
<div className="text-sm">
|
|
237
|
+
{new Date(row.original.createdAt).toLocaleDateString('en-US', {
|
|
238
|
+
month: 'short',
|
|
239
|
+
day: 'numeric',
|
|
240
|
+
year: 'numeric'
|
|
241
|
+
})}
|
|
242
|
+
</div>
|
|
243
|
+
)
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
id: 'actions',
|
|
247
|
+
size: 64,
|
|
248
|
+
enableResizing: false,
|
|
249
|
+
meta: { width: '64px' },
|
|
250
|
+
header: () => <span className="sr-only">Actions</span>,
|
|
251
|
+
cell: ({ row }) => (
|
|
252
|
+
<div className="flex justify-end">
|
|
253
|
+
<WebhookActions webhook={row.original} onEdit={onEdit} onDelete={onDelete} />
|
|
254
|
+
</div>
|
|
255
|
+
)
|
|
256
|
+
}
|
|
257
|
+
]
|
|
258
|
+
}
|