@krak-stack/notifications-admin 0.2.0 → 0.2.1
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/CHANGELOG.md +19 -0
- package/README.md +183 -3
- package/dist/atoms.d.ts +1 -0
- package/dist/atoms.js +33 -14
- package/dist/chunk-4r5x0qzz.js +522 -0
- package/dist/{chunk-wkxc1y7w.js → chunk-d32m2dmf.js} +160 -136
- package/dist/chunk-ghs5tkqn.js +37 -0
- package/dist/client-options.d.ts +9 -0
- package/dist/deliveries.d.ts +69 -1
- package/dist/deliveries.js +10 -2
- package/dist/delivery.atom.d.ts +95 -9
- package/dist/hooks.d.ts +21 -0
- package/dist/hooks.js +6 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +21 -3
- package/dist/operations.atom.d.ts +6 -4
- package/dist/operations.d.ts +39 -1
- package/dist/operations.js +8 -2
- package/dist/presentation.d.ts +13 -3
- package/package.json +7 -3
- package/dist/chunk-28xppc9m.js +0 -404
|
@@ -9,8 +9,9 @@ import {
|
|
|
9
9
|
import {
|
|
10
10
|
Tabs,
|
|
11
11
|
TabsList,
|
|
12
|
-
TabsTrigger
|
|
13
|
-
|
|
12
|
+
TabsTrigger,
|
|
13
|
+
NotificationAttemptHistory2
|
|
14
|
+
} from "./chunk-4r5x0qzz.js";
|
|
14
15
|
import {
|
|
15
16
|
NotificationTable2,
|
|
16
17
|
NotificationReference2
|
|
@@ -21,6 +22,7 @@ import { useState } from "react";
|
|
|
21
22
|
import { Effect, Schema } from "effect";
|
|
22
23
|
import * as S from "@krak-stack/notifications/admin/operations.schema";
|
|
23
24
|
import { useAppForm } from "@krak-stack/registry/form";
|
|
25
|
+
import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
|
|
24
26
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
25
27
|
var views = S.OperationsView.literals;
|
|
26
28
|
var metricKeys = [
|
|
@@ -46,10 +48,15 @@ var Records = ({
|
|
|
46
48
|
items,
|
|
47
49
|
columns,
|
|
48
50
|
m,
|
|
49
|
-
table
|
|
51
|
+
table,
|
|
52
|
+
tableId,
|
|
53
|
+
tableOptions
|
|
50
54
|
}) => /* @__PURE__ */ jsx(NotificationTable2, {
|
|
51
|
-
|
|
52
|
-
|
|
55
|
+
notificationTable: tableId,
|
|
56
|
+
initialState: tableOptions?.initialState,
|
|
57
|
+
className: tableOptions?.className,
|
|
58
|
+
rowData: table?.status?.error ? [] : items ?? [],
|
|
59
|
+
columnDefs: (tableOptions?.columns?.(columns) ?? columns).map((column) => column.colId === "inspect" || column.colId === "remove" ? {
|
|
53
60
|
...column,
|
|
54
61
|
sortable: false,
|
|
55
62
|
filterable: false,
|
|
@@ -64,6 +71,15 @@ var Records = ({
|
|
|
64
71
|
},
|
|
65
72
|
...table
|
|
66
73
|
});
|
|
74
|
+
var recordControls = (p) => ({
|
|
75
|
+
state: p.tableState,
|
|
76
|
+
onStateChange: p.onTableStateChange,
|
|
77
|
+
status: { loading: p.pending, error: p.error },
|
|
78
|
+
features: {
|
|
79
|
+
pagination: p.total === undefined ? { mode: "client" } : { mode: "server", rowCount: p.error ? 0 : p.total },
|
|
80
|
+
refresh: p.onRefresh
|
|
81
|
+
}
|
|
82
|
+
});
|
|
67
83
|
var OverviewWindowForm2 = ({
|
|
68
84
|
filters,
|
|
69
85
|
m,
|
|
@@ -130,7 +146,11 @@ var SuppressionDialog = ({
|
|
|
130
146
|
onSubmit: async ({ value }) => {
|
|
131
147
|
setFailure(undefined);
|
|
132
148
|
try {
|
|
133
|
-
if (record)
|
|
149
|
+
if (record && !onRemove || !record && !onAdd) {
|
|
150
|
+
setFailure(m.failed);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (record && onRemove)
|
|
134
154
|
await onRemove({
|
|
135
155
|
id: record.id,
|
|
136
156
|
payload: {
|
|
@@ -139,7 +159,7 @@ var SuppressionDialog = ({
|
|
|
139
159
|
reason: value.reason
|
|
140
160
|
}
|
|
141
161
|
});
|
|
142
|
-
else
|
|
162
|
+
else if (onAdd)
|
|
143
163
|
await onAdd({ requestId, email: value.email, reason: value.reason });
|
|
144
164
|
onClose();
|
|
145
165
|
} catch {
|
|
@@ -216,56 +236,10 @@ var SuppressionDialog = ({
|
|
|
216
236
|
})
|
|
217
237
|
});
|
|
218
238
|
};
|
|
219
|
-
var
|
|
220
|
-
const
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
onStateChange: p.onTableStateChange,
|
|
224
|
-
status: { loading: p.pending, error: p.error },
|
|
225
|
-
features: {
|
|
226
|
-
pagination: p.total === undefined ? { mode: "client" } : { mode: "server", rowCount: p.total },
|
|
227
|
-
refresh: p.onRefresh
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
const [manage, setManage] = useState();
|
|
231
|
-
const date = (value) => value ? value.toLocaleString() : m.never;
|
|
232
|
-
const activityColumns = [
|
|
233
|
-
{ field: "email", headerName: m.email },
|
|
234
|
-
{ field: "subject", headerName: m.subject },
|
|
235
|
-
{
|
|
236
|
-
field: "status",
|
|
237
|
-
headerName: m.status,
|
|
238
|
-
filterOptions: Object.entries(m.statuses).map(([value, label]) => ({
|
|
239
|
-
value,
|
|
240
|
-
label
|
|
241
|
-
})),
|
|
242
|
-
cellRenderer: ({ data }) => m.statuses[data.status]
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
field: "campaignName",
|
|
246
|
-
headerName: m.campaign,
|
|
247
|
-
cellRenderer: ({ data }) => data.campaignId && p.onCampaign ? /* @__PURE__ */ jsx(Button, {
|
|
248
|
-
variant: "link",
|
|
249
|
-
onClick: () => p.onCampaign?.(data.campaignId),
|
|
250
|
-
children: data.campaignName
|
|
251
|
-
}) : data.campaignName ?? "—"
|
|
252
|
-
},
|
|
253
|
-
{ field: "attempts", headerName: m.attempts, type: "number" },
|
|
254
|
-
{ field: "provider", headerName: m.provider },
|
|
255
|
-
{ field: "errorMessage", headerName: m.reason },
|
|
256
|
-
{ field: "createdAt", headerName: m.created, type: "date" },
|
|
257
|
-
{ field: "scheduledFor", headerName: m.scheduled, type: "date" },
|
|
258
|
-
{ field: "sentAt", headerName: m.accepted, type: "date" },
|
|
259
|
-
{
|
|
260
|
-
colId: "inspect",
|
|
261
|
-
headerName: m.inspect,
|
|
262
|
-
cellRenderer: ({ data }) => /* @__PURE__ */ jsx(Button, {
|
|
263
|
-
variant: "outline",
|
|
264
|
-
onClick: () => p.onInspect(data.id),
|
|
265
|
-
children: m.inspect
|
|
266
|
-
})
|
|
267
|
-
}
|
|
268
|
-
];
|
|
239
|
+
var NotificationFeedbackTable2 = (p) => {
|
|
240
|
+
const m = p.messages;
|
|
241
|
+
const locale = useKrakstackLocale();
|
|
242
|
+
const date = (value) => value ? value.toLocaleString(locale) : m.never;
|
|
269
243
|
const feedbackColumns = [
|
|
270
244
|
{ field: "recipientAddress", headerName: m.email },
|
|
271
245
|
{
|
|
@@ -324,6 +298,23 @@ var SendOperationsAdmin2 = (p) => {
|
|
|
324
298
|
}) : "—"
|
|
325
299
|
}
|
|
326
300
|
];
|
|
301
|
+
return /* @__PURE__ */ jsx(Records, {
|
|
302
|
+
items: p.items,
|
|
303
|
+
columns: feedbackColumns,
|
|
304
|
+
m,
|
|
305
|
+
table: recordControls(p),
|
|
306
|
+
tableId: "feedback",
|
|
307
|
+
tableOptions: p.tableOptions
|
|
308
|
+
});
|
|
309
|
+
};
|
|
310
|
+
var NotificationSuppressions2 = (p) => {
|
|
311
|
+
const m = p.messages;
|
|
312
|
+
const locale = useKrakstackLocale();
|
|
313
|
+
const date = (value) => value ? value.toLocaleString(locale) : m.never;
|
|
314
|
+
const [manage, setManage] = useState();
|
|
315
|
+
const canManage = manage === null ? !!p.onAddSuppression : !!p.onRemoveSuppression;
|
|
316
|
+
if ((p.error || !canManage) && manage !== undefined)
|
|
317
|
+
setManage(undefined);
|
|
327
318
|
const suppressionColumns = [
|
|
328
319
|
{ field: "email", headerName: m.email },
|
|
329
320
|
{
|
|
@@ -361,6 +352,34 @@ var SendOperationsAdmin2 = (p) => {
|
|
|
361
352
|
})
|
|
362
353
|
}
|
|
363
354
|
];
|
|
355
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
356
|
+
children: [
|
|
357
|
+
!p.error && p.onAddSuppression && /* @__PURE__ */ jsx(Button, {
|
|
358
|
+
onClick: () => setManage(null),
|
|
359
|
+
children: m.addSuppression
|
|
360
|
+
}),
|
|
361
|
+
/* @__PURE__ */ jsx(Records, {
|
|
362
|
+
items: p.items,
|
|
363
|
+
columns: p.onRemoveSuppression ? suppressionColumns : suppressionColumns.filter((column) => column.colId !== "remove"),
|
|
364
|
+
m,
|
|
365
|
+
table: recordControls(p),
|
|
366
|
+
tableId: "suppressions",
|
|
367
|
+
tableOptions: p.tableOptions
|
|
368
|
+
}),
|
|
369
|
+
!p.error && canManage && manage !== undefined && /* @__PURE__ */ jsx(SuppressionDialog, {
|
|
370
|
+
record: manage,
|
|
371
|
+
m,
|
|
372
|
+
onAdd: p.onAddSuppression,
|
|
373
|
+
onRemove: p.onRemoveSuppression,
|
|
374
|
+
onClose: () => setManage(undefined)
|
|
375
|
+
})
|
|
376
|
+
]
|
|
377
|
+
});
|
|
378
|
+
};
|
|
379
|
+
var NotificationSuppressionAudit2 = (p) => {
|
|
380
|
+
const m = p.messages;
|
|
381
|
+
const locale = useKrakstackLocale();
|
|
382
|
+
const date = (value) => value ? value.toLocaleString(locale) : m.never;
|
|
364
383
|
const auditColumns = [
|
|
365
384
|
{ field: "email", headerName: m.email },
|
|
366
385
|
{
|
|
@@ -384,6 +403,61 @@ var SendOperationsAdmin2 = (p) => {
|
|
|
384
403
|
{ field: "requestId", headerName: m.requestId },
|
|
385
404
|
{ field: "suppressionId", headerName: m.id }
|
|
386
405
|
];
|
|
406
|
+
return /* @__PURE__ */ jsx(Records, {
|
|
407
|
+
items: p.items?.map((row) => ({ ...row, id: row.requestId })),
|
|
408
|
+
columns: auditColumns,
|
|
409
|
+
m,
|
|
410
|
+
table: recordControls(p),
|
|
411
|
+
tableId: "suppression-audit",
|
|
412
|
+
tableOptions: p.tableOptions
|
|
413
|
+
});
|
|
414
|
+
};
|
|
415
|
+
var SendOperationsAdmin2 = (p) => {
|
|
416
|
+
const { messages: m, view } = p;
|
|
417
|
+
const locale = useKrakstackLocale();
|
|
418
|
+
const date = (value) => value ? value.toLocaleString(locale) : m.never;
|
|
419
|
+
const tableControls = recordControls(p);
|
|
420
|
+
const visibleViews = p.views ?? views;
|
|
421
|
+
const activityColumns = [
|
|
422
|
+
{ field: "email", headerName: m.email },
|
|
423
|
+
{ field: "subject", headerName: m.subject },
|
|
424
|
+
{
|
|
425
|
+
field: "status",
|
|
426
|
+
headerName: m.status,
|
|
427
|
+
filterOptions: Object.entries(m.statuses).map(([value, label]) => ({
|
|
428
|
+
value,
|
|
429
|
+
label
|
|
430
|
+
})),
|
|
431
|
+
cellRenderer: ({ data }) => m.statuses[data.status]
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
field: "campaignName",
|
|
435
|
+
headerName: m.campaign,
|
|
436
|
+
cellRenderer: ({ data }) => data.campaignId && p.onCampaign ? /* @__PURE__ */ jsx(Button, {
|
|
437
|
+
variant: "link",
|
|
438
|
+
onClick: () => {
|
|
439
|
+
if (data.campaignId)
|
|
440
|
+
p.onCampaign?.(data.campaignId);
|
|
441
|
+
},
|
|
442
|
+
children: data.campaignName
|
|
443
|
+
}) : data.campaignName ?? "—"
|
|
444
|
+
},
|
|
445
|
+
{ field: "attempts", headerName: m.attempts, type: "number" },
|
|
446
|
+
{ field: "provider", headerName: m.provider },
|
|
447
|
+
{ field: "errorMessage", headerName: m.reason },
|
|
448
|
+
{ field: "createdAt", headerName: m.created, type: "date" },
|
|
449
|
+
{ field: "scheduledFor", headerName: m.scheduled, type: "date" },
|
|
450
|
+
{ field: "sentAt", headerName: m.accepted, type: "date" },
|
|
451
|
+
{
|
|
452
|
+
colId: "inspect",
|
|
453
|
+
headerName: m.inspect,
|
|
454
|
+
cellRenderer: ({ data }) => /* @__PURE__ */ jsx(Button, {
|
|
455
|
+
variant: "outline",
|
|
456
|
+
onClick: () => p.onInspect(data.id),
|
|
457
|
+
children: m.inspect
|
|
458
|
+
})
|
|
459
|
+
}
|
|
460
|
+
];
|
|
387
461
|
const recipientColumns = [
|
|
388
462
|
{ field: "email", headerName: m.email },
|
|
389
463
|
{
|
|
@@ -407,11 +481,13 @@ var SendOperationsAdmin2 = (p) => {
|
|
|
407
481
|
}
|
|
408
482
|
];
|
|
409
483
|
const delivery = p.inspection?.delivery;
|
|
484
|
+
if (!visibleViews.includes(view))
|
|
485
|
+
return null;
|
|
410
486
|
return /* @__PURE__ */ jsxs("section", {
|
|
411
487
|
className: "space-y-4",
|
|
412
488
|
"aria-busy": p.pending,
|
|
413
489
|
children: [
|
|
414
|
-
/* @__PURE__ */ jsxs("header", {
|
|
490
|
+
p.header !== false && /* @__PURE__ */ jsxs("header", {
|
|
415
491
|
className: "flex items-start justify-between gap-4",
|
|
416
492
|
children: [
|
|
417
493
|
/* @__PURE__ */ jsxs("div", {
|
|
@@ -432,13 +508,17 @@ var SendOperationsAdmin2 = (p) => {
|
|
|
432
508
|
})
|
|
433
509
|
]
|
|
434
510
|
}),
|
|
435
|
-
/* @__PURE__ */ jsx(Tabs, {
|
|
511
|
+
p.navigation !== false && /* @__PURE__ */ jsx(Tabs, {
|
|
436
512
|
value: view,
|
|
437
|
-
onValueChange: (value) =>
|
|
513
|
+
onValueChange: (value) => {
|
|
514
|
+
const next = Schema.decodeUnknownSync(S.OperationsView)(value);
|
|
515
|
+
if (visibleViews.includes(next))
|
|
516
|
+
p.onView(next);
|
|
517
|
+
},
|
|
438
518
|
children: /* @__PURE__ */ jsx(TabsList, {
|
|
439
519
|
className: "h-auto flex-wrap",
|
|
440
520
|
"aria-label": m.title,
|
|
441
|
-
children:
|
|
521
|
+
children: visibleViews.map((v) => /* @__PURE__ */ jsx(TabsTrigger, {
|
|
442
522
|
value: v,
|
|
443
523
|
children: m.views[v]
|
|
444
524
|
}, v))
|
|
@@ -475,7 +555,7 @@ var SendOperationsAdmin2 = (p) => {
|
|
|
475
555
|
role: "status",
|
|
476
556
|
children: m.loading
|
|
477
557
|
}),
|
|
478
|
-
view === "overview" && p.overview && /* @__PURE__ */ jsx("dl", {
|
|
558
|
+
view === "overview" && p.overview && !p.error && /* @__PURE__ */ jsx("dl", {
|
|
479
559
|
className: "grid gap-3 sm:grid-cols-3",
|
|
480
560
|
children: metricKeys.map((key) => /* @__PURE__ */ jsxs("div", {
|
|
481
561
|
role: "group",
|
|
@@ -496,38 +576,26 @@ var SendOperationsAdmin2 = (p) => {
|
|
|
496
576
|
items: p.activity?.items,
|
|
497
577
|
columns: activityColumns,
|
|
498
578
|
m,
|
|
499
|
-
table: tableControls
|
|
579
|
+
table: tableControls,
|
|
580
|
+
tableId: "operations-activity"
|
|
500
581
|
}),
|
|
501
|
-
view === "feedback" && /* @__PURE__ */ jsx(
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
m,
|
|
505
|
-
table: tableControls
|
|
582
|
+
view === "feedback" && /* @__PURE__ */ jsx(NotificationFeedbackTable2, {
|
|
583
|
+
...p,
|
|
584
|
+
items: p.feedback?.items
|
|
506
585
|
}),
|
|
507
|
-
view === "suppressions" && /* @__PURE__ */
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
onClick: () => setManage(null),
|
|
511
|
-
children: m.addSuppression
|
|
512
|
-
}),
|
|
513
|
-
/* @__PURE__ */ jsx(Records, {
|
|
514
|
-
items: p.suppressions?.items,
|
|
515
|
-
columns: suppressionColumns,
|
|
516
|
-
table: tableControls,
|
|
517
|
-
m
|
|
518
|
-
})
|
|
519
|
-
]
|
|
586
|
+
view === "suppressions" && /* @__PURE__ */ jsx(NotificationSuppressions2, {
|
|
587
|
+
...p,
|
|
588
|
+
items: p.suppressions?.items
|
|
520
589
|
}),
|
|
521
|
-
view === "audit" && /* @__PURE__ */ jsx(
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
table: tableControls,
|
|
525
|
-
m
|
|
590
|
+
view === "audit" && /* @__PURE__ */ jsx(NotificationSuppressionAudit2, {
|
|
591
|
+
...p,
|
|
592
|
+
items: p.audit?.items
|
|
526
593
|
}),
|
|
527
594
|
view === "recipients" && (p.filters.campaignId ? /* @__PURE__ */ jsx(Records, {
|
|
528
595
|
items: p.recipients?.items,
|
|
529
596
|
columns: recipientColumns,
|
|
530
597
|
table: tableControls,
|
|
598
|
+
tableId: "campaign-recipients",
|
|
531
599
|
m
|
|
532
600
|
}) : /* @__PURE__ */ jsx("p", {
|
|
533
601
|
children: m.recipientsHint
|
|
@@ -554,7 +622,7 @@ var SendOperationsAdmin2 = (p) => {
|
|
|
554
622
|
role: "status",
|
|
555
623
|
children: m.loading
|
|
556
624
|
}),
|
|
557
|
-
delivery && /* @__PURE__ */ jsxs(Fragment, {
|
|
625
|
+
delivery && !p.error && /* @__PURE__ */ jsxs(Fragment, {
|
|
558
626
|
children: [
|
|
559
627
|
p.onContact && /* @__PURE__ */ jsx(Button, {
|
|
560
628
|
variant: "outline",
|
|
@@ -626,47 +694,10 @@ var SendOperationsAdmin2 = (p) => {
|
|
|
626
694
|
/* @__PURE__ */ jsx("h3", {
|
|
627
695
|
children: m.attempts
|
|
628
696
|
}),
|
|
629
|
-
/* @__PURE__ */ jsx(
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
{ field: "generation", headerName: m.generation },
|
|
634
|
-
{ field: "attempt", headerName: m.attempts },
|
|
635
|
-
{
|
|
636
|
-
colId: "outcome",
|
|
637
|
-
headerName: m.outcome,
|
|
638
|
-
cellRenderer: ({ data }) => data.outcome ? m.outcomes[data.outcome._tag] : m.pending
|
|
639
|
-
},
|
|
640
|
-
{
|
|
641
|
-
colId: "reason",
|
|
642
|
-
headerName: m.reason,
|
|
643
|
-
cellRenderer: ({ data }) => {
|
|
644
|
-
const outcome = data.outcome;
|
|
645
|
-
if (!outcome)
|
|
646
|
-
return "—";
|
|
647
|
-
switch (outcome._tag) {
|
|
648
|
-
case "Sent":
|
|
649
|
-
return outcome.providerMessageId ?? "—";
|
|
650
|
-
case "Skipped":
|
|
651
|
-
return outcome.reason;
|
|
652
|
-
case "RetryableFailure":
|
|
653
|
-
case "PermanentFailure":
|
|
654
|
-
case "Unavailable":
|
|
655
|
-
return outcome.message;
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
},
|
|
659
|
-
{
|
|
660
|
-
colId: "started",
|
|
661
|
-
headerName: m.started,
|
|
662
|
-
cellRenderer: ({ data }) => date(data.startedAt)
|
|
663
|
-
},
|
|
664
|
-
{
|
|
665
|
-
colId: "completed",
|
|
666
|
-
headerName: m.completed,
|
|
667
|
-
cellRenderer: ({ data }) => date(data.completedAt)
|
|
668
|
-
}
|
|
669
|
-
]
|
|
697
|
+
/* @__PURE__ */ jsx(NotificationAttemptHistory2, {
|
|
698
|
+
messages: m,
|
|
699
|
+
attempts: p.inspection?.attempts ?? [],
|
|
700
|
+
tableId: "operations-attempts"
|
|
670
701
|
}),
|
|
671
702
|
/* @__PURE__ */ jsx(Button, {
|
|
672
703
|
onClick: () => {
|
|
@@ -689,16 +720,9 @@ var SendOperationsAdmin2 = (p) => {
|
|
|
689
720
|
})
|
|
690
721
|
]
|
|
691
722
|
})
|
|
692
|
-
}),
|
|
693
|
-
manage !== undefined && /* @__PURE__ */ jsx(SuppressionDialog, {
|
|
694
|
-
record: manage,
|
|
695
|
-
m,
|
|
696
|
-
onAdd: p.onAddSuppression,
|
|
697
|
-
onRemove: p.onRemoveSuppression,
|
|
698
|
-
onClose: () => setManage(undefined)
|
|
699
723
|
})
|
|
700
724
|
]
|
|
701
725
|
});
|
|
702
726
|
};
|
|
703
727
|
|
|
704
|
-
export { SendOperationsAdmin2 };
|
|
728
|
+
export { NotificationFeedbackTable2, NotificationSuppressions2, NotificationSuppressionAudit2, SendOperationsAdmin2 };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// src/hooks.ts
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { useAtomRefresh, useAtomValue } from "@effect/atom-react";
|
|
4
|
+
import { Option } from "effect";
|
|
5
|
+
import { AsyncResult } from "effect/reactivity";
|
|
6
|
+
var useNotificationQuery2 = (resource, options) => {
|
|
7
|
+
const result = useAtomValue(resource.atom);
|
|
8
|
+
const failed = AsyncResult.isFailure(result);
|
|
9
|
+
const data = failed ? undefined : Option.getOrUndefined(AsyncResult.value(result));
|
|
10
|
+
const total = data === undefined ? undefined : options.total?.(data);
|
|
11
|
+
const [previous, setPrevious] = useState({
|
|
12
|
+
key: options.retentionKey,
|
|
13
|
+
total: total ?? 0
|
|
14
|
+
});
|
|
15
|
+
const retainedTotal = failed ? 0 : total ?? (previous.key === options.retentionKey ? previous.total : 0);
|
|
16
|
+
if (previous.key !== options.retentionKey || previous.total !== retainedTotal) {
|
|
17
|
+
setPrevious({ key: options.retentionKey, total: retainedTotal });
|
|
18
|
+
}
|
|
19
|
+
const refresh = useAtomRefresh(resource.refresh);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const interval = options.refreshIntervalMillis;
|
|
22
|
+
if (interval === undefined || interval <= 0)
|
|
23
|
+
return;
|
|
24
|
+
const timer = setInterval(refresh, interval);
|
|
25
|
+
return () => clearInterval(timer);
|
|
26
|
+
}, [refresh, options.refreshIntervalMillis]);
|
|
27
|
+
return {
|
|
28
|
+
result,
|
|
29
|
+
data,
|
|
30
|
+
total: retainedTotal,
|
|
31
|
+
failed,
|
|
32
|
+
refresh,
|
|
33
|
+
pending: AsyncResult.isInitial(result) || AsyncResult.isWaiting(result)
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { useNotificationQuery2 };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Layer } from "effect";
|
|
2
|
+
import type { HttpClient } from "effect/http";
|
|
3
|
+
export interface NotificationAdminClientOptions {
|
|
4
|
+
readonly baseUrl: string;
|
|
5
|
+
/** Non-secret cache identity. Recreate factories when the session/grants change. */
|
|
6
|
+
readonly authorizationKey: string;
|
|
7
|
+
/** Host-provided cookie/CSRF transport; provide its dependencies beforehand. */
|
|
8
|
+
readonly httpClient?: Layer.Layer<HttpClient.HttpClient>;
|
|
9
|
+
}
|
package/dist/deliveries.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type * as S from "@krak-stack/notifications/admin/delivery.schema";
|
|
2
|
-
import {
|
|
2
|
+
import type { DataTablePublicState } from "@krak-stack/registry/data-table";
|
|
3
3
|
import type { SendOperationsMessages } from "./operations.js";
|
|
4
|
+
import { type NotificationTableOptions, type NotificationTableId } from "./presentation.js";
|
|
4
5
|
export interface NotificationDeliveryMessages {
|
|
5
6
|
readonly common: SendOperationsMessages;
|
|
6
7
|
readonly title: string;
|
|
@@ -17,6 +18,62 @@ export interface NotificationDeliveryMessages {
|
|
|
17
18
|
readonly feedbackNotice: string;
|
|
18
19
|
readonly feedbackCovered: string;
|
|
19
20
|
readonly feedbackUnavailable: string;
|
|
21
|
+
readonly sections?: {
|
|
22
|
+
readonly summary: string;
|
|
23
|
+
readonly sending: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
interface ReadState {
|
|
27
|
+
readonly pending?: boolean;
|
|
28
|
+
/** A failed protected read hides retained data, not just an error banner. */
|
|
29
|
+
readonly error?: string;
|
|
30
|
+
}
|
|
31
|
+
export type NotificationAttemptHistoryMessages = Pick<SendOperationsMessages, "generation" | "attempts" | "outcome" | "outcomes" | "pending" | "reason" | "started" | "completed" | "empty" | "loading">;
|
|
32
|
+
export type NotificationDeliveryActivityMessages = Pick<NotificationDeliveryMessages, "source" | "sources" | "recipientUserId" | "organizationId" | "workspaceId" | "eventKey" | "template" | "purposes"> & {
|
|
33
|
+
readonly common: Pick<SendOperationsMessages, "email" | "purpose" | "status" | "statuses" | "attempts" | "provider" | "created" | "accepted" | "inspect" | "empty" | "loading">;
|
|
34
|
+
};
|
|
35
|
+
export type NotificationDeliveryOverviewMessages = Pick<NotificationDeliveryMessages, "feedbackCovered" | "feedbackUnavailable" | "feedbackNotice"> & {
|
|
36
|
+
readonly common: {
|
|
37
|
+
readonly loading: string;
|
|
38
|
+
readonly metrics: Pick<SendOperationsMessages["metrics"], Exclude<NotificationDeliveryMetric, "feedbackCovered" | "feedbackUnavailable">>;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export type NotificationDeliveryDetailsMessages = Pick<NotificationDeliveryMessages, "source" | "sources" | "recipientUserId" | "organizationId" | "workspaceId" | "eventKey" | "template" | "purposes" | "sections" | "references"> & {
|
|
42
|
+
readonly common: NotificationAttemptHistoryMessages & Pick<SendOperationsMessages, "email" | "purpose" | "status" | "statuses" | "created" | "scheduled" | "accepted" | "id" | "provider" | "providerMessageId" | "updated" | "contactId" | "campaign"> & {
|
|
43
|
+
readonly views: Pick<SendOperationsMessages["views"], "overview">;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export interface NotificationDeliveryActivityProps extends ReadState {
|
|
47
|
+
readonly messages: NotificationDeliveryActivityMessages;
|
|
48
|
+
readonly activity?: typeof S.AdminDeliveryPage.Type;
|
|
49
|
+
readonly table: DataTablePublicState;
|
|
50
|
+
readonly total: number;
|
|
51
|
+
readonly onTable: (table: DataTablePublicState) => void;
|
|
52
|
+
readonly onInspect: (id: string) => void;
|
|
53
|
+
readonly onRefresh?: () => void;
|
|
54
|
+
readonly tableOptions?: NotificationTableOptions<typeof S.AdminDelivery.Type>;
|
|
55
|
+
}
|
|
56
|
+
export type NotificationDeliveryMetric = keyof typeof S.DeliveryOverview.Type;
|
|
57
|
+
export interface NotificationDeliveryOverviewProps extends ReadState {
|
|
58
|
+
readonly messages: NotificationDeliveryOverviewMessages;
|
|
59
|
+
readonly overview?: typeof S.DeliveryOverview.Type;
|
|
60
|
+
readonly variant?: "cards" | "rows";
|
|
61
|
+
readonly groups?: ReadonlyArray<{
|
|
62
|
+
readonly label?: string;
|
|
63
|
+
readonly metrics: ReadonlyArray<NotificationDeliveryMetric>;
|
|
64
|
+
}>;
|
|
65
|
+
}
|
|
66
|
+
export interface NotificationAttemptHistoryProps extends ReadState {
|
|
67
|
+
readonly messages: NotificationAttemptHistoryMessages;
|
|
68
|
+
readonly attempts: (typeof S.AdminDeliveryInspection.Type)["attempts"];
|
|
69
|
+
readonly tableOptions?: NotificationTableOptions<(typeof S.AdminDeliveryInspection.Type)["attempts"][number]>;
|
|
70
|
+
readonly tableId?: Extract<NotificationTableId, "delivery-attempts" | "operations-attempts">;
|
|
71
|
+
}
|
|
72
|
+
export interface NotificationDeliveryDetailsProps extends ReadState {
|
|
73
|
+
readonly messages: NotificationDeliveryDetailsMessages;
|
|
74
|
+
readonly inspection?: typeof S.AdminDeliveryInspection.Type;
|
|
75
|
+
readonly onContact?: (id: string) => void;
|
|
76
|
+
readonly onCampaign?: (id: string) => void;
|
|
20
77
|
}
|
|
21
78
|
export interface NotificationDeliveriesProps {
|
|
22
79
|
readonly messages: NotificationDeliveryMessages;
|
|
@@ -38,5 +95,16 @@ export interface NotificationDeliveriesProps {
|
|
|
38
95
|
readonly onRefresh: () => void;
|
|
39
96
|
readonly onContact?: (id: string) => void;
|
|
40
97
|
readonly onCampaign?: (id: string) => void;
|
|
98
|
+
readonly header?: boolean;
|
|
99
|
+
readonly navigation?: boolean;
|
|
100
|
+
readonly sourcePicker?: boolean;
|
|
101
|
+
readonly tableOptions?: NotificationDeliveryActivityProps["tableOptions"];
|
|
41
102
|
}
|
|
103
|
+
export declare const NotificationDeliveryOverview: (p: NotificationDeliveryOverviewProps) => import("react").JSX.Element | null;
|
|
104
|
+
export declare const NotificationDeliveryActivity: (p: NotificationDeliveryActivityProps) => import("react").JSX.Element;
|
|
105
|
+
export declare const NotificationAttemptHistory: (p: NotificationAttemptHistoryProps) => import("react").JSX.Element;
|
|
106
|
+
/** Read-only content for a host dialog, drawer or route; no fetching or shell. */
|
|
107
|
+
export declare const NotificationDeliveryDetails: (p: NotificationDeliveryDetailsProps) => import("react").JSX.Element;
|
|
108
|
+
/** Backwards-compatible default composition; hosts can mount the sections alone. */
|
|
42
109
|
export declare const NotificationDeliveries: (p: NotificationDeliveriesProps) => import("react").JSX.Element;
|
|
110
|
+
export {};
|
package/dist/deliveries.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
|
+
NotificationDeliveryOverview2,
|
|
3
|
+
NotificationDeliveryActivity2,
|
|
4
|
+
NotificationAttemptHistory2,
|
|
5
|
+
NotificationDeliveryDetails2,
|
|
2
6
|
NotificationDeliveries2
|
|
3
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-4r5x0qzz.js";
|
|
4
8
|
import"./chunk-tck9drx2.js";
|
|
5
9
|
import"./chunk-aqmv7g24.js";
|
|
6
10
|
export {
|
|
7
|
-
|
|
11
|
+
NotificationAttemptHistory2 as NotificationAttemptHistory,
|
|
12
|
+
NotificationDeliveries2 as NotificationDeliveries,
|
|
13
|
+
NotificationDeliveryActivity2 as NotificationDeliveryActivity,
|
|
14
|
+
NotificationDeliveryDetails2 as NotificationDeliveryDetails,
|
|
15
|
+
NotificationDeliveryOverview2 as NotificationDeliveryOverview
|
|
8
16
|
};
|