@asteby/metacore-webhooks 2.0.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 +201 -0
- package/README.md +92 -0
- package/dist/components/create-dialog.d.ts +24 -0
- package/dist/components/create-dialog.d.ts.map +1 -0
- package/dist/components/create-dialog.js +134 -0
- package/dist/components/create-dialog.js.map +1 -0
- package/dist/components/index.d.ts +9 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +5 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/logs-dialog.d.ts +16 -0
- package/dist/components/logs-dialog.d.ts.map +1 -0
- package/dist/components/logs-dialog.js +58 -0
- package/dist/components/logs-dialog.js.map +1 -0
- package/dist/components/stats-bar.d.ts +12 -0
- package/dist/components/stats-bar.d.ts.map +1 -0
- package/dist/components/stats-bar.js +42 -0
- package/dist/components/stats-bar.js.map +1 -0
- package/dist/components/webhooks-list.d.ts +16 -0
- package/dist/components/webhooks-list.d.ts.map +1 -0
- package/dist/components/webhooks-list.js +64 -0
- package/dist/components/webhooks-list.js.map +1 -0
- package/dist/hooks.d.ts +51 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +136 -0
- package/dist/hooks.js.map +1 -0
- package/dist/i18n.d.ts +13 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +11 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +138 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/webhooks-manager.d.ts +18 -0
- package/dist/webhooks-manager.d.ts.map +1 -0
- package/dist/webhooks-manager.js +90 -0
- package/dist/webhooks-manager.js.map +1 -0
- package/package.json +81 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { WebhookStats } from '../types';
|
|
2
|
+
import type { WebhooksTranslate } from '../i18n';
|
|
3
|
+
export interface StatsBarProps {
|
|
4
|
+
stats: WebhookStats | null;
|
|
5
|
+
t?: WebhooksTranslate;
|
|
6
|
+
className?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Four-counter summary: active / paused / failed / total deliveries.
|
|
10
|
+
*/
|
|
11
|
+
export declare function StatsBar({ stats, t, className }: StatsBarProps): import("react/jsx-runtime").JSX.Element | null;
|
|
12
|
+
//# sourceMappingURL=stats-bar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stats-bar.d.ts","sourceRoot":"","sources":["../../src/components/stats-bar.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAC5C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAGhD,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,YAAY,GAAG,IAAI,CAAA;IAC1B,CAAC,CAAC,EAAE,iBAAiB,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAoB,EAAE,SAAS,EAAE,EAAE,aAAa,kDA+CjF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from '@asteby/metacore-ui/lib';
|
|
3
|
+
import { defaultTranslate } from '../i18n';
|
|
4
|
+
/**
|
|
5
|
+
* Four-counter summary: active / paused / failed / total deliveries.
|
|
6
|
+
*/
|
|
7
|
+
export function StatsBar({ stats, t = defaultTranslate, className }) {
|
|
8
|
+
if (!stats)
|
|
9
|
+
return null;
|
|
10
|
+
const items = [
|
|
11
|
+
{
|
|
12
|
+
key: 'active',
|
|
13
|
+
label: t('webhooks.stats.active', 'Activos'),
|
|
14
|
+
value: stats.active_webhooks,
|
|
15
|
+
color: 'text-emerald-500',
|
|
16
|
+
bg: 'bg-emerald-500/10',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
key: 'paused',
|
|
20
|
+
label: t('webhooks.stats.paused', 'Pausados'),
|
|
21
|
+
value: stats.paused_webhooks,
|
|
22
|
+
color: 'text-amber-500',
|
|
23
|
+
bg: 'bg-amber-500/10',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
key: 'failed',
|
|
27
|
+
label: t('webhooks.stats.failed', 'Fallidos'),
|
|
28
|
+
value: stats.failed_webhooks,
|
|
29
|
+
color: 'text-red-500',
|
|
30
|
+
bg: 'bg-red-500/10',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
key: 'deliveries',
|
|
34
|
+
label: t('webhooks.stats.deliveries', 'Entregas totales'),
|
|
35
|
+
value: (stats.total_deliveries ?? 0).toLocaleString(),
|
|
36
|
+
color: 'text-violet-500',
|
|
37
|
+
bg: 'bg-violet-500/10',
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
return (_jsx("div", { className: cn('grid grid-cols-2 md:grid-cols-4 gap-3', className), children: items.map((item) => (_jsxs("div", { className: cn('flex items-center gap-3 px-4 py-3 rounded-xl border', item.bg), children: [_jsx("div", { className: cn('text-2xl font-bold tabular-nums', item.color), children: item.value }), _jsx("div", { className: "text-xs text-muted-foreground font-medium", children: item.label })] }, item.key))) }));
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=stats-bar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stats-bar.js","sourceRoot":"","sources":["../../src/components/stats-bar.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,yBAAyB,CAAA;AAG5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAQ1C;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,gBA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,CAAC,KAAK,GAAO,KAJxE,IAAI,CAAC,GAAG,CAKT,CACP,CAAC,GACE,CACP,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Webhook } from '../types';
|
|
2
|
+
import type { WebhooksTranslate } from '../i18n';
|
|
3
|
+
export interface WebhooksListProps {
|
|
4
|
+
webhooks: Webhook[];
|
|
5
|
+
isLoading?: boolean;
|
|
6
|
+
onDelete: (id: string) => void;
|
|
7
|
+
onToggle: (id: string, nextStatus: 'active' | 'paused') => void;
|
|
8
|
+
onTest?: (id: string) => void;
|
|
9
|
+
onViewLogs: (webhook: Webhook) => void;
|
|
10
|
+
enableTest?: boolean;
|
|
11
|
+
/** Whether the row should show a device chip (device scope). */
|
|
12
|
+
showDeviceChip?: boolean;
|
|
13
|
+
t?: WebhooksTranslate;
|
|
14
|
+
}
|
|
15
|
+
export declare function WebhooksList({ webhooks, isLoading, onDelete, onToggle, onTest, onViewLogs, enableTest, showDeviceChip, t, }: WebhooksListProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
//# sourceMappingURL=webhooks-list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks-list.d.ts","sourceRoot":"","sources":["../../src/components/webhooks-list.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAGhD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;IAC9B,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,GAAG,QAAQ,KAAK,IAAI,CAAA;IAC/D,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;IAC7B,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IACtC,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,gEAAgE;IAChE,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,CAAC,CAAC,EAAE,iBAAiB,CAAA;CACtB;AAED,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,UAAU,EACV,UAAiB,EACjB,cAAsB,EACtB,CAAoB,GACrB,EAAE,iBAAiB,2CAiSnB"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { AlertTriangle, CheckCircle2, ChevronDown, FileText, Pause, Play, Send, Trash2, Webhook as WebhookIcon, XCircle, } from 'lucide-react';
|
|
4
|
+
import { Badge, Button } from '@asteby/metacore-ui/primitives';
|
|
5
|
+
import { cn } from '@asteby/metacore-ui/lib';
|
|
6
|
+
import { defaultTranslate } from '../i18n';
|
|
7
|
+
export function WebhooksList({ webhooks, isLoading, onDelete, onToggle, onTest, onViewLogs, enableTest = true, showDeviceChip = false, t = defaultTranslate, }) {
|
|
8
|
+
const [expanded, setExpanded] = useState(null);
|
|
9
|
+
if (isLoading) {
|
|
10
|
+
return (_jsx("div", { className: "space-y-3", children: [1, 2, 3].map((i) => (_jsx("div", { className: "h-20 rounded-xl bg-muted/20 animate-pulse" }, i))) }));
|
|
11
|
+
}
|
|
12
|
+
if (webhooks.length === 0) {
|
|
13
|
+
return (_jsxs("div", { className: "flex flex-col items-center justify-center py-16 text-center", children: [_jsx("div", { className: "relative mb-6", children: _jsx("div", { className: "h-20 w-20 rounded-2xl bg-gradient-to-br from-violet-500/10 to-violet-500/5 flex items-center justify-center ring-1 ring-violet-500/10", children: _jsx(WebhookIcon, { className: "h-10 w-10 text-violet-500/40" }) }) }), _jsx("h3", { className: "text-lg font-bold mb-1", children: t('webhooks.empty.title', 'Sin webhooks') }), _jsx("p", { className: "text-sm text-muted-foreground max-w-[280px]", children: t('webhooks.empty.subtitle', 'Registra tu primer webhook para recibir eventos en tiempo real en tu servidor.') })] }));
|
|
14
|
+
}
|
|
15
|
+
return (_jsx("div", { className: "space-y-2", children: webhooks.map((wh) => {
|
|
16
|
+
const isExpanded = expanded === wh.id;
|
|
17
|
+
const isActive = wh.status === 'active';
|
|
18
|
+
const isFailed = wh.status === 'failed';
|
|
19
|
+
const isPaused = wh.status === 'paused';
|
|
20
|
+
const totalAttempts = wh.success_count + wh.failure_count;
|
|
21
|
+
const successRate = totalAttempts > 0
|
|
22
|
+
? Math.round((wh.success_count / totalAttempts) * 100)
|
|
23
|
+
: 100;
|
|
24
|
+
return (_jsxs("div", { className: cn('rounded-xl border transition-all duration-200', isActive
|
|
25
|
+
? 'bg-card/60 border-border/60 hover:border-violet-500/20'
|
|
26
|
+
: isFailed
|
|
27
|
+
? 'bg-destructive/5 border-destructive/20'
|
|
28
|
+
: 'bg-muted/10 border-border/30 opacity-70'), children: [_jsxs("div", { className: "flex items-center gap-4 px-4 py-3.5 cursor-pointer", onClick: () => setExpanded(isExpanded ? null : wh.id), children: [_jsx("div", { className: cn('h-9 w-9 rounded-lg flex items-center justify-center shrink-0', isActive
|
|
29
|
+
? 'bg-violet-500/10'
|
|
30
|
+
: isFailed
|
|
31
|
+
? 'bg-destructive/10'
|
|
32
|
+
: 'bg-muted/30'), children: _jsx(WebhookIcon, { className: cn('h-4 w-4', isActive
|
|
33
|
+
? 'text-violet-500'
|
|
34
|
+
: isFailed
|
|
35
|
+
? 'text-destructive'
|
|
36
|
+
: 'text-muted-foreground') }) }), _jsxs("div", { className: "flex-1 min-w-0", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "text-sm font-semibold truncate", children: wh.name }), _jsx(Badge, { variant: isActive ? 'default' : isFailed ? 'destructive' : 'secondary', className: "text-[10px] px-1.5 py-0", children: isActive
|
|
37
|
+
? t('webhooks.status.active', 'Activo')
|
|
38
|
+
: isFailed
|
|
39
|
+
? t('webhooks.status.failed', 'Fallido')
|
|
40
|
+
: t('webhooks.status.paused', 'Pausado') }), successRate < 90 && totalAttempts > 0 && (_jsx(Badge, { variant: "outline", className: "text-[10px] px-1.5 py-0 text-amber-600 border-amber-300", children: t('webhooks.list.success_rate', '{{rate}}% éxito', {
|
|
41
|
+
rate: successRate,
|
|
42
|
+
}) }))] }), _jsxs("div", { className: "flex items-center gap-3 text-xs text-muted-foreground mt-0.5", children: [_jsx("span", { className: "font-mono truncate max-w-[200px]", children: wh.url }), showDeviceChip && wh.device && (_jsxs(_Fragment, { children: [_jsx("span", { children: "\u2022" }), _jsx("span", { children: wh.device.name })] })), _jsx("span", { children: "\u2022" }), _jsxs("span", { className: "flex items-center gap-1", children: [_jsx(CheckCircle2, { className: "h-3 w-3 text-emerald-500" }), wh.success_count] }), wh.failure_count > 0 && (_jsxs("span", { className: "flex items-center gap-1 text-destructive", children: [_jsx(XCircle, { className: "h-3 w-3" }), wh.failure_count] }))] })] }), _jsx(ChevronDown, { className: cn('h-4 w-4 text-muted-foreground transition-transform', isExpanded && 'rotate-180') })] }), isExpanded && (_jsxs("div", { className: "px-4 pb-4 pt-0 border-t border-border/40 animate-in slide-in-from-top-2 fade-in duration-200", children: [_jsxs("div", { className: "grid grid-cols-2 md:grid-cols-4 gap-4 py-3", children: [_jsxs("div", { children: [_jsx("span", { className: "text-[10px] font-semibold text-muted-foreground uppercase tracking-wider", children: t('webhooks.fields.events', 'Eventos') }), _jsx("div", { className: "flex flex-wrap gap-1 mt-1", children: wh.events.split(',').map((e) => (_jsx(Badge, { variant: "outline", className: "text-[9px] px-1.5 py-0", children: e.trim() }, e))) })] }), _jsxs("div", { children: [_jsx("span", { className: "text-[10px] font-semibold text-muted-foreground uppercase tracking-wider", children: t('webhooks.fields.max_retries', 'Reintentos') }), _jsx("p", { className: "text-sm font-medium mt-1", children: t('webhooks.list.retries', '{{n}} intentos', {
|
|
43
|
+
n: wh.max_retries,
|
|
44
|
+
}) })] }), _jsxs("div", { children: [_jsx("span", { className: "text-[10px] font-semibold text-muted-foreground uppercase tracking-wider", children: t('webhooks.list.last_delivery', 'Última entrega') }), _jsx("p", { className: "text-sm mt-1", children: wh.last_delivered_at
|
|
45
|
+
? new Date(wh.last_delivered_at).toLocaleString()
|
|
46
|
+
: t('webhooks.list.never', 'Nunca') })] }), _jsxs("div", { children: [_jsx("span", { className: "text-[10px] font-semibold text-muted-foreground uppercase tracking-wider", children: t('webhooks.list.signing_secret', 'Signing secret') }), _jsx("p", { className: "text-sm font-mono mt-1", children: wh.secret_masked || '\u2022\u2022\u2022' })] })] }), wh.last_error && (_jsx("div", { className: "mb-3 p-2.5 rounded-lg bg-destructive/5 border border-destructive/20", children: _jsxs("div", { className: "flex items-center gap-2 text-xs", children: [_jsx(AlertTriangle, { className: "h-3.5 w-3.5 text-destructive shrink-0" }), _jsx("span", { className: "text-destructive font-medium", children: t('webhooks.list.last_error', 'Último error:') }), _jsx("span", { className: "text-muted-foreground truncate", children: wh.last_error })] }) })), _jsxs("div", { className: "flex items-center gap-2 pt-2 border-t border-border/20 flex-wrap", children: [enableTest && onTest && (_jsxs(Button, { size: "sm", variant: "outline", className: "gap-1.5 text-xs", onClick: (e) => {
|
|
47
|
+
e.stopPropagation();
|
|
48
|
+
onTest(wh.id);
|
|
49
|
+
}, children: [_jsx(Send, { className: "h-3.5 w-3.5" }), t('webhooks.actions.test', 'Test')] })), _jsxs(Button, { size: "sm", variant: "outline", className: "gap-1.5 text-xs", onClick: (e) => {
|
|
50
|
+
e.stopPropagation();
|
|
51
|
+
onViewLogs(wh);
|
|
52
|
+
}, children: [_jsx(FileText, { className: "h-3.5 w-3.5" }), t('webhooks.actions.logs', 'Logs')] }), isActive && (_jsxs(Button, { size: "sm", variant: "outline", className: "gap-1.5 text-xs text-amber-600 hover:bg-amber-500/10", onClick: (e) => {
|
|
53
|
+
e.stopPropagation();
|
|
54
|
+
onToggle(wh.id, 'paused');
|
|
55
|
+
}, children: [_jsx(Pause, { className: "h-3.5 w-3.5" }), t('webhooks.actions.pause', 'Pausar')] })), (isPaused || isFailed) && (_jsxs(Button, { size: "sm", variant: "outline", className: "gap-1.5 text-xs text-emerald-600 hover:bg-emerald-500/10", onClick: (e) => {
|
|
56
|
+
e.stopPropagation();
|
|
57
|
+
onToggle(wh.id, 'active');
|
|
58
|
+
}, children: [_jsx(Play, { className: "h-3.5 w-3.5" }), t('webhooks.actions.activate', 'Activar')] })), _jsxs(Button, { size: "sm", variant: "outline", className: "gap-1.5 text-xs text-destructive hover:bg-destructive/10 hover:text-destructive hover:border-destructive/30 ml-auto", onClick: (e) => {
|
|
59
|
+
e.stopPropagation();
|
|
60
|
+
onDelete(wh.id);
|
|
61
|
+
}, children: [_jsx(Trash2, { className: "h-3.5 w-3.5" }), t('webhooks.actions.delete', 'Eliminar')] })] })] }))] }, wh.id));
|
|
62
|
+
}) }));
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=webhooks-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks-list.js","sourceRoot":"","sources":["../../src/components/webhooks-list.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChC,OAAO,EACL,aAAa,EACb,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,OAAO,IAAI,WAAW,EACtB,OAAO,GACR,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAA;AAC9D,OAAO,EAAE,EAAE,EAAE,MAAM,yBAAyB,CAAA;AAG5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAe1C,MAAM,UAAU,YAAY,CAAC,EAC3B,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OAAO,EAAC,SAAS,EACjB,SAAS,EAAC,0DAA0D,EACpE,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;4CACb,CAAC,CAAC,eAAe,EAAE,CAAA;4CACnB,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAA;wCAC3B,CAAC,aAED,KAAC,IAAI,IAAC,SAAS,EAAC,aAAa,GAAG,EAC/B,CAAC,CAAC,2BAA2B,EAAE,SAAS,CAAC,IACnC,CACV,EAED,MAAC,MAAM,IACL,IAAI,EAAC,IAAI,EACT,OAAO,EAAC,SAAS,EACjB,SAAS,EAAC,qHAAqH,EAC/H,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;4CACb,CAAC,CAAC,eAAe,EAAE,CAAA;4CACnB,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,CAAA;wCACjB,CAAC,aAED,KAAC,MAAM,IAAC,SAAS,EAAC,aAAa,GAAG,EACjC,CAAC,CAAC,yBAAyB,EAAE,UAAU,CAAC,IAClC,IACL,IACF,CACP,KAzOI,EAAE,CAAC,EAAE,CA0ON,CACP,CAAA;QACH,CAAC,CAAC,GACE,CACP,CAAA;AACH,CAAC"}
|
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type UseMutationResult, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { CreateWebhookPayload, CreateWebhookResponse, Webhook, WebhookLog, WebhookStats, WebhooksApiClient, WebhooksConfig } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Compute the default base path for the current scope.
|
|
5
|
+
*/
|
|
6
|
+
export declare function resolveBasePath(config: Pick<WebhooksConfig, 'scope' | 'apiBasePath'>): string;
|
|
7
|
+
/** Shared query-key builder. */
|
|
8
|
+
export declare const webhookKeys: {
|
|
9
|
+
all: (scope: string, deviceId?: string) => readonly ["metacore-webhooks", string, string | null];
|
|
10
|
+
list: (scope: string, deviceId?: string) => readonly ["metacore-webhooks", string, string | null, "list"];
|
|
11
|
+
stats: (scope: string, deviceId?: string) => readonly ["metacore-webhooks", string, string | null, "stats"];
|
|
12
|
+
logs: (scope: string, webhookId: string, page: number, deviceId?: string) => readonly ["metacore-webhooks", string, string | null, "logs", string, number];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Core data-hook. Returns the list, stats, and the mutations needed by the
|
|
16
|
+
* UI (create / delete / toggle / test / replay).
|
|
17
|
+
*/
|
|
18
|
+
export declare function useWebhooks(config: WebhooksConfig): {
|
|
19
|
+
webhooks: Webhook[];
|
|
20
|
+
stats: WebhookStats | null;
|
|
21
|
+
isLoading: boolean;
|
|
22
|
+
isError: boolean;
|
|
23
|
+
refetch: () => Promise<unknown>;
|
|
24
|
+
list: UseQueryResult<Webhook[]>;
|
|
25
|
+
statsQuery: UseQueryResult<WebhookStats | null>;
|
|
26
|
+
create: UseMutationResult<CreateWebhookResponse, unknown, CreateWebhookPayload>;
|
|
27
|
+
update: UseMutationResult<unknown, unknown, {
|
|
28
|
+
id: string;
|
|
29
|
+
patch: Partial<Webhook>;
|
|
30
|
+
}>;
|
|
31
|
+
remove: UseMutationResult<unknown, unknown, string>;
|
|
32
|
+
test: UseMutationResult<unknown, unknown, string>;
|
|
33
|
+
replay: UseMutationResult<unknown, unknown, {
|
|
34
|
+
webhookId: string;
|
|
35
|
+
logId: string;
|
|
36
|
+
}>;
|
|
37
|
+
basePath: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Paginated logs for a single webhook. Separate from {@link useWebhooks} so
|
|
41
|
+
* the logs dialog can use its own pagination state without re-triggering the
|
|
42
|
+
* list query.
|
|
43
|
+
*/
|
|
44
|
+
export declare function useWebhookLogs(apiClient: WebhooksApiClient, basePath: string, webhookId: string | null, page: number, options?: {
|
|
45
|
+
perPage?: number;
|
|
46
|
+
enabled?: boolean;
|
|
47
|
+
}): UseQueryResult<{
|
|
48
|
+
logs: WebhookLog[];
|
|
49
|
+
totalPages: number;
|
|
50
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O,CAAC,CAAA;KAAE,CAAC,CAAA;IACpF,MAAM,EAAE,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;IACnD,IAAI,EAAE,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;IACjD,MAAM,EAAE,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACjF,QAAQ,EAAE,MAAM,CAAA;CACjB,CAqGA;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,iBAAiB,EAC5B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO;UAQ7B,UAAU,EAAE;gBAAc,MAAM;UAazD"}
|
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useMutation, useQuery, useQueryClient, } from '@tanstack/react-query';
|
|
3
|
+
/**
|
|
4
|
+
* Compute the default base path for the current scope.
|
|
5
|
+
*/
|
|
6
|
+
export function resolveBasePath(config) {
|
|
7
|
+
if (config.apiBasePath)
|
|
8
|
+
return config.apiBasePath.replace(/\/$/, '');
|
|
9
|
+
return config.scope === 'organization' ? '/org-webhooks' : '/webhooks';
|
|
10
|
+
}
|
|
11
|
+
/** Shared query-key builder. */
|
|
12
|
+
export const webhookKeys = {
|
|
13
|
+
all: (scope, deviceId) => ['metacore-webhooks', scope, deviceId ?? null],
|
|
14
|
+
list: (scope, deviceId) => [...webhookKeys.all(scope, deviceId), 'list'],
|
|
15
|
+
stats: (scope, deviceId) => [...webhookKeys.all(scope, deviceId), 'stats'],
|
|
16
|
+
logs: (scope, webhookId, page, deviceId) => [...webhookKeys.all(scope, deviceId), 'logs', webhookId, page],
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Core data-hook. Returns the list, stats, and the mutations needed by the
|
|
20
|
+
* UI (create / delete / toggle / test / replay).
|
|
21
|
+
*/
|
|
22
|
+
export function useWebhooks(config) {
|
|
23
|
+
const { apiClient, scope, deviceId, disablePolling } = config;
|
|
24
|
+
const basePath = resolveBasePath(config);
|
|
25
|
+
const queryClient = useQueryClient();
|
|
26
|
+
const listQueryKey = webhookKeys.list(scope, deviceId);
|
|
27
|
+
const statsQueryKey = webhookKeys.stats(scope, deviceId);
|
|
28
|
+
const list = useQuery({
|
|
29
|
+
queryKey: listQueryKey,
|
|
30
|
+
queryFn: async () => {
|
|
31
|
+
const url = scope === 'device' && deviceId
|
|
32
|
+
? `${basePath}?device_id=${encodeURIComponent(deviceId)}`
|
|
33
|
+
: basePath;
|
|
34
|
+
const res = await apiClient.get(url);
|
|
35
|
+
return res.data?.data ?? [];
|
|
36
|
+
},
|
|
37
|
+
refetchInterval: disablePolling ? false : 30_000,
|
|
38
|
+
});
|
|
39
|
+
const statsQuery = useQuery({
|
|
40
|
+
queryKey: statsQueryKey,
|
|
41
|
+
queryFn: async () => {
|
|
42
|
+
try {
|
|
43
|
+
const res = await apiClient.get(`${basePath}/stats`);
|
|
44
|
+
return res.data?.data ?? null;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
refetchInterval: disablePolling ? false : 30_000,
|
|
51
|
+
});
|
|
52
|
+
const invalidate = async () => {
|
|
53
|
+
await Promise.all([
|
|
54
|
+
queryClient.invalidateQueries({ queryKey: listQueryKey }),
|
|
55
|
+
queryClient.invalidateQueries({ queryKey: statsQueryKey }),
|
|
56
|
+
]);
|
|
57
|
+
};
|
|
58
|
+
const create = useMutation({
|
|
59
|
+
mutationFn: async (payload) => {
|
|
60
|
+
const body = { ...payload };
|
|
61
|
+
if (scope === 'device' && deviceId && !body.device_id) {
|
|
62
|
+
body.device_id = deviceId;
|
|
63
|
+
}
|
|
64
|
+
const res = await apiClient.post(basePath, body);
|
|
65
|
+
return res.data;
|
|
66
|
+
},
|
|
67
|
+
onSuccess: invalidate,
|
|
68
|
+
});
|
|
69
|
+
const update = useMutation({
|
|
70
|
+
mutationFn: async ({ id, patch }) => {
|
|
71
|
+
const res = await apiClient.put(`${basePath}/${id}`, patch);
|
|
72
|
+
return res.data;
|
|
73
|
+
},
|
|
74
|
+
onSuccess: invalidate,
|
|
75
|
+
});
|
|
76
|
+
const remove = useMutation({
|
|
77
|
+
mutationFn: async (id) => {
|
|
78
|
+
const res = await apiClient.delete(`${basePath}/${id}`);
|
|
79
|
+
return res.data;
|
|
80
|
+
},
|
|
81
|
+
onSuccess: invalidate,
|
|
82
|
+
});
|
|
83
|
+
const test = useMutation({
|
|
84
|
+
mutationFn: async (id) => {
|
|
85
|
+
const res = await apiClient.post(`${basePath}/${id}/test`);
|
|
86
|
+
return res.data;
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
const replay = useMutation({
|
|
90
|
+
mutationFn: async ({ webhookId, logId }) => {
|
|
91
|
+
const res = await apiClient.post(`${basePath}/${webhookId}/logs/${logId}/replay`);
|
|
92
|
+
return res.data;
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
webhooks: list.data ?? [],
|
|
97
|
+
stats: statsQuery.data ?? null,
|
|
98
|
+
isLoading: list.isLoading,
|
|
99
|
+
isError: list.isError,
|
|
100
|
+
refetch: async () => {
|
|
101
|
+
await Promise.all([list.refetch(), statsQuery.refetch()]);
|
|
102
|
+
},
|
|
103
|
+
list,
|
|
104
|
+
statsQuery,
|
|
105
|
+
create,
|
|
106
|
+
update,
|
|
107
|
+
remove,
|
|
108
|
+
test,
|
|
109
|
+
replay,
|
|
110
|
+
basePath,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Paginated logs for a single webhook. Separate from {@link useWebhooks} so
|
|
115
|
+
* the logs dialog can use its own pagination state without re-triggering the
|
|
116
|
+
* list query.
|
|
117
|
+
*/
|
|
118
|
+
export function useWebhookLogs(apiClient, basePath, webhookId, page, options = {}) {
|
|
119
|
+
const { perPage = 15, enabled = true } = options;
|
|
120
|
+
const queryKey = useMemo(() => ['metacore-webhook-logs', basePath, webhookId, page, perPage], [basePath, webhookId, page, perPage]);
|
|
121
|
+
return useQuery({
|
|
122
|
+
queryKey,
|
|
123
|
+
enabled: !!webhookId && enabled,
|
|
124
|
+
queryFn: async () => {
|
|
125
|
+
if (!webhookId)
|
|
126
|
+
return { logs: [], totalPages: 1 };
|
|
127
|
+
const url = `${basePath}/${webhookId}/logs?page=${page}&per_page=${perPage}`;
|
|
128
|
+
const res = await apiClient.get(url);
|
|
129
|
+
return {
|
|
130
|
+
logs: res.data?.data ?? [],
|
|
131
|
+
totalPages: res.data?.meta?.pages ?? 1,
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EACL,WAAW,EACX,QAAQ,EACR,cAAc,GAGf,MAAM,uBAAuB,CAAA;AAW9B;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,MAAqD;IACnF,IAAI,MAAM,CAAC,WAAW;QAAE,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;IACpE,OAAO,MAAM,CAAC,KAAK,KAAK,cAAc,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,WAAW,CAAA;AACxE,CAAC;AAED,gCAAgC;AAChC,MAAM,CAAC,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,EAAE,CAAA;YAC5E,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,GAAG,CAA6B,GAAG,CAAC,CAAA;YAChE,OAAO;gBACL,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE;gBAC1B,UAAU,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;aACvC,CAAA;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/i18n.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal translation type. Consumers can pass a function that wraps
|
|
3
|
+
* `react-i18next`'s `t` (or any other i18n library). When omitted, components
|
|
4
|
+
* simply render the supplied defaults (with `{{var}}` interpolation).
|
|
5
|
+
*/
|
|
6
|
+
export type WebhooksTranslate = (key: string, defaultValue: string, vars?: Record<string, unknown>) => string;
|
|
7
|
+
export declare function interpolate(s: string, vars?: Record<string, unknown>): string;
|
|
8
|
+
/**
|
|
9
|
+
* Default translate — simply echoes the fallback string with optional
|
|
10
|
+
* variable interpolation. Plug in your own `t` via the `WebhooksManager` prop.
|
|
11
|
+
*/
|
|
12
|
+
export declare const defaultTranslate: WebhooksTranslate;
|
|
13
|
+
//# sourceMappingURL=i18n.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC9B,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,MAAM,EACpB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC3B,MAAM,CAAA;AAEX,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAK7E;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,iBACE,CAAA"}
|
package/dist/i18n.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function interpolate(s, vars) {
|
|
2
|
+
if (!vars)
|
|
3
|
+
return s;
|
|
4
|
+
return s.replace(/\{\{\s*(\w+)\s*\}\}/g, (_, k) => vars[k] !== undefined ? String(vars[k]) : '');
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Default translate — simply echoes the fallback string with optional
|
|
8
|
+
* variable interpolation. Plug in your own `t` via the `WebhooksManager` prop.
|
|
9
|
+
*/
|
|
10
|
+
export const defaultTranslate = (_key, defaultValue, vars) => interpolate(defaultValue, vars);
|
|
11
|
+
//# sourceMappingURL=i18n.js.map
|
package/dist/i18n.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.js","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,WAAW,CAAC,CAAS,EAAE,IAA8B;IACnE,IAAI,CAAC,IAAI;QAAE,OAAO,CAAC,CAAA;IACnB,OAAO,CAAC,CAAC,OAAO,CAAC,sBAAsB,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAChD,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAC7C,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAsB,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,CAC9E,WAAW,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { WebhooksManager } from './webhooks-manager';
|
|
2
|
+
export type { WebhooksManagerProps } from './webhooks-manager';
|
|
3
|
+
export { StatsBar, CreateDialog, DEFAULT_EVENT_PRESETS, LogsDialog, WebhooksList, } from './components';
|
|
4
|
+
export type { StatsBarProps, CreateDialogProps, LogsDialogProps, WebhooksListProps, } from './components';
|
|
5
|
+
export { useWebhooks, useWebhookLogs, resolveBasePath, webhookKeys } from './hooks';
|
|
6
|
+
export type { Webhook, WebhookLog, WebhookStats, WebhookStatus, WebhookDeviceRef, WebhookEventOption, WebhooksApiClient, WebhooksConfig, CreateWebhookPayload, CreateWebhookResponse, } from './types';
|
|
7
|
+
export type { WebhooksTranslate } from './i18n';
|
|
8
|
+
export { defaultTranslate, interpolate } from './i18n';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,YAAY,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAE9D,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,qBAAqB,EACrB,UAAU,EACV,YAAY,GACb,MAAM,cAAc,CAAA;AACrB,YAAY,EACV,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,iBAAiB,GAClB,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAEnF,YAAY,EACV,OAAO,EACP,UAAU,EACV,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,SAAS,CAAA;AAEhB,YAAY,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { WebhooksManager } from './webhooks-manager';
|
|
2
|
+
export { StatsBar, CreateDialog, DEFAULT_EVENT_PRESETS, LogsDialog, WebhooksList, } from './components';
|
|
3
|
+
export { useWebhooks, useWebhookLogs, resolveBasePath, webhookKeys } from './hooks';
|
|
4
|
+
export { defaultTranslate, interpolate } from './i18n';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAGpD,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,qBAAqB,EACrB,UAAU,EACV,YAAY,GACb,MAAM,cAAc,CAAA;AAQrB,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAgBnF,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common webhook types shared across scopes (device / organization).
|
|
3
|
+
*
|
|
4
|
+
* The types are intentionally permissive — backend payloads may carry
|
|
5
|
+
* additional fields that callers are free to keep on the objects without
|
|
6
|
+
* losing typing.
|
|
7
|
+
*/
|
|
8
|
+
/** Status lifecycle reported by the API. */
|
|
9
|
+
export type WebhookStatus = 'active' | 'paused' | 'failed' | (string & {});
|
|
10
|
+
/** Device reference optionally attached to device-scoped webhooks. */
|
|
11
|
+
export interface WebhookDeviceRef {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
type: string;
|
|
15
|
+
}
|
|
16
|
+
/** A webhook registration row. */
|
|
17
|
+
export interface Webhook {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
url: string;
|
|
21
|
+
/** Masked signing secret (first / last chars). Null for just-created rows. */
|
|
22
|
+
secret_masked?: string;
|
|
23
|
+
/** Only present on device-scoped webhooks. */
|
|
24
|
+
device_id?: string;
|
|
25
|
+
device?: WebhookDeviceRef;
|
|
26
|
+
status: WebhookStatus;
|
|
27
|
+
/** Comma-separated list of event types. */
|
|
28
|
+
events: string;
|
|
29
|
+
max_retries: number;
|
|
30
|
+
timeout_secs: number;
|
|
31
|
+
success_count: number;
|
|
32
|
+
failure_count: number;
|
|
33
|
+
consecutive_failures: number;
|
|
34
|
+
last_delivered_at: string | null;
|
|
35
|
+
last_failed_at: string | null;
|
|
36
|
+
last_http_status: number;
|
|
37
|
+
last_error: string;
|
|
38
|
+
auto_disable_threshold: number;
|
|
39
|
+
created_at: string;
|
|
40
|
+
}
|
|
41
|
+
/** A single delivery attempt recorded in the backend logs. */
|
|
42
|
+
export interface WebhookLog {
|
|
43
|
+
id: string;
|
|
44
|
+
event_type: string;
|
|
45
|
+
event_id: string;
|
|
46
|
+
request_url: string;
|
|
47
|
+
request_body: string;
|
|
48
|
+
response_status: number;
|
|
49
|
+
response_body: string;
|
|
50
|
+
response_time_msec: number;
|
|
51
|
+
status: string;
|
|
52
|
+
attempt_num: number;
|
|
53
|
+
error: string;
|
|
54
|
+
created_at: string;
|
|
55
|
+
}
|
|
56
|
+
/** Stats bar payload. */
|
|
57
|
+
export interface WebhookStats {
|
|
58
|
+
total_webhooks: number;
|
|
59
|
+
active_webhooks: number;
|
|
60
|
+
paused_webhooks: number;
|
|
61
|
+
failed_webhooks: number;
|
|
62
|
+
total_deliveries: number;
|
|
63
|
+
total_failures: number;
|
|
64
|
+
}
|
|
65
|
+
/** Item used to render the event picker in the create dialog. */
|
|
66
|
+
export interface WebhookEventOption {
|
|
67
|
+
value: string;
|
|
68
|
+
/** Optional i18n key; if omitted `label` is used. */
|
|
69
|
+
labelKey?: string;
|
|
70
|
+
/** Fallback label when i18n is not available or the key is missing. */
|
|
71
|
+
label: string;
|
|
72
|
+
/** Short emoji / glyph displayed next to the option. */
|
|
73
|
+
icon?: string;
|
|
74
|
+
}
|
|
75
|
+
/** Payload accepted by the create mutation. */
|
|
76
|
+
export interface CreateWebhookPayload {
|
|
77
|
+
name: string;
|
|
78
|
+
url: string;
|
|
79
|
+
events: string;
|
|
80
|
+
max_retries: number;
|
|
81
|
+
timeout_secs: number;
|
|
82
|
+
auto_disable_threshold: number;
|
|
83
|
+
/** Only set when `scope === 'device'`. */
|
|
84
|
+
device_id?: string;
|
|
85
|
+
}
|
|
86
|
+
/** Shape of the `{ data: { secret } }` envelope returned on create. */
|
|
87
|
+
export interface CreateWebhookResponse {
|
|
88
|
+
success: boolean;
|
|
89
|
+
data: {
|
|
90
|
+
secret: string;
|
|
91
|
+
[key: string]: unknown;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Minimal axios-compatible client surface used by the hooks. Consumers pass
|
|
96
|
+
* their own axios instance (from `@asteby/metacore-auth` or anywhere else).
|
|
97
|
+
*/
|
|
98
|
+
export interface WebhooksApiClient {
|
|
99
|
+
get: <T = unknown>(url: string, config?: unknown) => Promise<{
|
|
100
|
+
data: T;
|
|
101
|
+
}>;
|
|
102
|
+
post: <T = unknown>(url: string, body?: unknown, config?: unknown) => Promise<{
|
|
103
|
+
data: T;
|
|
104
|
+
}>;
|
|
105
|
+
put: <T = unknown>(url: string, body?: unknown, config?: unknown) => Promise<{
|
|
106
|
+
data: T;
|
|
107
|
+
}>;
|
|
108
|
+
delete: <T = unknown>(url: string, config?: unknown) => Promise<{
|
|
109
|
+
data: T;
|
|
110
|
+
}>;
|
|
111
|
+
}
|
|
112
|
+
/** Configuration shared by the hook + the top-level manager component. */
|
|
113
|
+
export interface WebhooksConfig {
|
|
114
|
+
apiClient: WebhooksApiClient;
|
|
115
|
+
/** `"device"` scopes requests with `device_id`; `"organization"` is org-wide. */
|
|
116
|
+
scope: 'device' | 'organization';
|
|
117
|
+
/** Required when `scope === 'device'`. */
|
|
118
|
+
deviceId?: string;
|
|
119
|
+
/**
|
|
120
|
+
* Base path on the backend (no trailing slash). Defaults to `"/webhooks"`
|
|
121
|
+
* for device scope and `"/org-webhooks"` for organization scope.
|
|
122
|
+
*/
|
|
123
|
+
apiBasePath?: string;
|
|
124
|
+
/** Devices available in the create dialog (device scope only). */
|
|
125
|
+
devices?: WebhookDeviceRef[];
|
|
126
|
+
/** Event presets for the create dialog. */
|
|
127
|
+
eventPresets?: WebhookEventOption[];
|
|
128
|
+
/** Show the "Test" button on each row. Default: true. */
|
|
129
|
+
enableTest?: boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Show the "Replay" button on logs (device scope feature). When true the
|
|
132
|
+
* log row renders a replay action that POSTs to `{base}/{id}/logs/{logId}/replay`.
|
|
133
|
+
*/
|
|
134
|
+
enableReplay?: boolean;
|
|
135
|
+
/** Disable automatic query polling. Default: false. */
|
|
136
|
+
disablePolling?: boolean;
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,4CAA4C;AAC5C,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAE1E,sEAAsE;AACtE,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb;AAED,kCAAkC;AAClC,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,8EAA8E;IAC9E,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,8CAA8C;IAC9C,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,gBAAgB,CAAA;IACzB,MAAM,EAAE,aAAa,CAAA;IACrB,2CAA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C,CAAA;CAC7E;AAED,0EAA0E;AAC1E,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,iBAAiB,CAAA;IAC5B,iFAAiF;IACjF,KAAK,EAAE,QAAQ,GAAG,cAAc,CAAA;IAChC,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,kEAAkE;IAClE,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAA;IAC5B,2CAA2C;IAC3C,YAAY,CAAC,EAAE,kBAAkB,EAAE,CAAA;IACnC,yDAAyD;IACzD,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,uDAAuD;IACvD,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common webhook types shared across scopes (device / organization).
|
|
3
|
+
*
|
|
4
|
+
* The types are intentionally permissive — backend payloads may carry
|
|
5
|
+
* additional fields that callers are free to keep on the objects without
|
|
6
|
+
* losing typing.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { WebhooksConfig } from './types';
|
|
2
|
+
import { type WebhooksTranslate } from './i18n';
|
|
3
|
+
export interface WebhooksManagerProps extends WebhooksConfig {
|
|
4
|
+
/** Optional translation function (`react-i18next`-compatible signature). */
|
|
5
|
+
t?: WebhooksTranslate;
|
|
6
|
+
/** Optional extra class for the root element. */
|
|
7
|
+
className?: string;
|
|
8
|
+
/** Hide the header block. */
|
|
9
|
+
hideHeader?: boolean;
|
|
10
|
+
/** Hide the payload/headers reference block at the bottom. */
|
|
11
|
+
hidePayloadReference?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Top-level component orchestrating the webhooks UX. Wire it with any
|
|
15
|
+
* axios-compatible client plus the scope (`device` | `organization`).
|
|
16
|
+
*/
|
|
17
|
+
export declare function WebhooksManager(props: WebhooksManagerProps): import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
//# sourceMappingURL=webhooks-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks-manager.d.ts","sourceRoot":"","sources":["../src/webhooks-manager.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAW,cAAc,EAAE,MAAM,SAAS,CAAA;AACtD,OAAO,EAAoB,KAAK,iBAAiB,EAAE,MAAM,QAAQ,CAAA;AAEjE,MAAM,WAAW,oBAAqB,SAAQ,cAAc;IAC1D,4EAA4E;IAC5E,CAAC,CAAC,EAAE,iBAAiB,CAAA;IACrB,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,6BAA6B;IAC7B,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,8DAA8D;IAC9D,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,2CAsJ1D"}
|