@shivaedev/admin 0.12.3 → 0.14.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/CHANGELOG.md +35 -0
- package/README.md +40 -6
- package/dist/client/JobButton.d.ts +3 -0
- package/dist/client/JobButton.d.ts.map +1 -0
- package/dist/client/JobButton.js +5 -0
- package/dist/client/JobButton.js.map +1 -0
- package/dist/client/JobDetail.d.ts +12 -0
- package/dist/client/JobDetail.d.ts.map +1 -0
- package/dist/client/JobDetail.js +27 -0
- package/dist/client/JobDetail.js.map +1 -0
- package/dist/client/JobList.d.ts +8 -0
- package/dist/client/JobList.d.ts.map +1 -0
- package/dist/client/JobList.js +25 -0
- package/dist/client/JobList.js.map +1 -0
- package/dist/client/JobPagination.d.ts +8 -0
- package/dist/client/JobPagination.d.ts.map +1 -0
- package/dist/client/JobPagination.js +12 -0
- package/dist/client/JobPagination.js.map +1 -0
- package/dist/client/JobTable.d.ts +6 -0
- package/dist/client/JobTable.d.ts.map +1 -0
- package/dist/client/JobTable.js +13 -0
- package/dist/client/JobTable.js.map +1 -0
- package/dist/client/JobsMetrics.d.ts +9 -0
- package/dist/client/JobsMetrics.d.ts.map +1 -0
- package/dist/client/JobsMetrics.js +15 -0
- package/dist/client/JobsMetrics.js.map +1 -0
- package/dist/client/JobsQueryPanel.d.ts +7 -0
- package/dist/client/JobsQueryPanel.d.ts.map +1 -0
- package/dist/client/JobsQueryPanel.js +11 -0
- package/dist/client/JobsQueryPanel.js.map +1 -0
- package/dist/client/JobsQueueView.d.ts +12 -0
- package/dist/client/JobsQueueView.d.ts.map +1 -0
- package/dist/client/JobsQueueView.js +18 -0
- package/dist/client/JobsQueueView.js.map +1 -0
- package/dist/client/JobsView.d.ts +12 -0
- package/dist/client/JobsView.d.ts.map +1 -0
- package/dist/client/JobsView.js +17 -0
- package/dist/client/JobsView.js.map +1 -0
- package/dist/client/SessionConfirmation.d.ts +11 -0
- package/dist/client/SessionConfirmation.d.ts.map +1 -0
- package/dist/client/SessionConfirmation.js +15 -0
- package/dist/client/SessionConfirmation.js.map +1 -0
- package/dist/client/SessionListView.d.ts +11 -0
- package/dist/client/SessionListView.d.ts.map +1 -0
- package/dist/client/SessionListView.js +22 -0
- package/dist/client/SessionListView.js.map +1 -0
- package/dist/client/SessionPagination.d.ts +10 -0
- package/dist/client/SessionPagination.d.ts.map +1 -0
- package/dist/client/SessionPagination.js +9 -0
- package/dist/client/SessionPagination.js.map +1 -0
- package/dist/client/SessionsView.d.ts +21 -0
- package/dist/client/SessionsView.d.ts.map +1 -0
- package/dist/client/SessionsView.js +48 -0
- package/dist/client/SessionsView.js.map +1 -0
- package/dist/client/jobsTypes.d.ts +35 -0
- package/dist/client/jobsTypes.d.ts.map +1 -0
- package/dist/client/jobsTypes.js +2 -0
- package/dist/client/jobsTypes.js.map +1 -0
- package/dist/jobs/entry.d.ts +0 -1
- package/dist/jobs/entry.d.ts.map +1 -1
- package/dist/jobs/page.d.ts +50 -48
- package/dist/jobs/page.d.ts.map +1 -1
- package/dist/jobs/page.js +6 -1
- package/dist/jobs/page.js.map +1 -1
- package/dist/jobs/retryPage.d.ts +13 -11
- package/dist/jobs/retryPage.d.ts.map +1 -1
- package/dist/jobs/schemas.d.ts +3 -2
- package/dist/jobs/schemas.d.ts.map +1 -1
- package/dist/jobs/schemas.js +3 -2
- package/dist/jobs/schemas.js.map +1 -1
- package/dist/server/jobsHandlers.d.ts +5 -12
- package/dist/server/jobsHandlers.d.ts.map +1 -1
- package/dist/server/jobsHandlers.js +1 -10
- package/dist/server/jobsHandlers.js.map +1 -1
- package/dist/sessions/Page.d.ts +98 -0
- package/dist/sessions/Page.d.ts.map +1 -0
- package/dist/sessions/Page.js +10 -0
- package/dist/sessions/Page.js.map +1 -0
- package/dist/users/page.d.ts +1 -1
- package/dist/users/page.d.ts.map +1 -1
- package/dist/users/page.js +2 -1
- package/dist/users/page.js.map +1 -1
- package/package.json +10 -10
- package/src/client/JobButton.tsx +5 -0
- package/src/client/JobDetail.tsx +81 -0
- package/src/client/JobList.tsx +60 -0
- package/src/client/JobPagination.tsx +31 -0
- package/src/client/JobTable.tsx +48 -0
- package/src/client/JobsMetrics.tsx +37 -0
- package/src/client/JobsQueryPanel.tsx +23 -0
- package/src/client/JobsQueueView.tsx +74 -0
- package/src/client/JobsView.ts +34 -0
- package/src/client/SessionConfirmation.tsx +44 -0
- package/src/client/SessionListView.tsx +66 -0
- package/src/client/SessionPagination.tsx +40 -0
- package/src/client/SessionsView.ts +75 -0
- package/src/client/jobsTypes.ts +32 -0
- package/src/jobs/entry.ts +1 -1
- package/src/jobs/page.ts +6 -1
- package/src/jobs/schemas.ts +3 -2
- package/src/server/jobsHandlers.ts +1 -10
- package/src/sessions/Page.ts +10 -0
- package/src/users/page.ts +2 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { useQuery } from "@shivaedev/react/client/resultState.ts";
|
|
3
|
+
import { JobList } from "./JobList.tsx";
|
|
4
|
+
import { JobsMetrics } from "./JobsMetrics.tsx";
|
|
5
|
+
import { JobsQueryPanel } from "./JobsQueryPanel.tsx";
|
|
6
|
+
import type { JobsViewClient, RetryJob } from "./jobsTypes.ts";
|
|
7
|
+
|
|
8
|
+
export function JobsQueueView({ api, queue, retry }: { readonly api: JobsViewClient; readonly queue: string; readonly retry: RetryJob | undefined }) {
|
|
9
|
+
const [kind, setKind] = useState<"failed" | "deadLettered">("failed");
|
|
10
|
+
const counts = useQuery(api.counts.query({ queue }));
|
|
11
|
+
return (
|
|
12
|
+
<>
|
|
13
|
+
<section aria-label="Queue counts" className="space-y-4">
|
|
14
|
+
<h2 className="text-xl font-semibold">Queue counts</h2>
|
|
15
|
+
<JobsQueryPanel state={counts}>
|
|
16
|
+
{(value) => (
|
|
17
|
+
<JobsMetrics values={{ Active: value.activeCount, Failed: value.failedCount, Queued: value.queuedCount, Total: value.totalCount }} />
|
|
18
|
+
)}
|
|
19
|
+
</JobsQueryPanel>
|
|
20
|
+
</section>
|
|
21
|
+
<div aria-label="Job lists" className="flex flex-wrap gap-3" role="tablist">
|
|
22
|
+
{(
|
|
23
|
+
[
|
|
24
|
+
["failed", "Failed"],
|
|
25
|
+
["deadLettered", "Dead-lettered"],
|
|
26
|
+
] as const
|
|
27
|
+
).map(([value, label]) => (
|
|
28
|
+
<button
|
|
29
|
+
aria-controls={`jobs-${value}-panel`}
|
|
30
|
+
aria-selected={kind === value}
|
|
31
|
+
className="rounded-md border px-3 py-2"
|
|
32
|
+
id={`jobs-${value}-tab`}
|
|
33
|
+
key={value}
|
|
34
|
+
onClick={() => setKind(value)}
|
|
35
|
+
role="tab"
|
|
36
|
+
type="button"
|
|
37
|
+
>
|
|
38
|
+
{label}
|
|
39
|
+
</button>
|
|
40
|
+
))}
|
|
41
|
+
</div>
|
|
42
|
+
<div aria-labelledby={`jobs-${kind}-tab`} id={`jobs-${kind}-panel`} role="tabpanel">
|
|
43
|
+
<JobList api={api} key={kind} kind={kind} queue={queue} retry={retry} />
|
|
44
|
+
</div>
|
|
45
|
+
</>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function JobsQueuePicker({
|
|
50
|
+
queues,
|
|
51
|
+
select,
|
|
52
|
+
value,
|
|
53
|
+
}: {
|
|
54
|
+
readonly queues: readonly string[];
|
|
55
|
+
readonly select: (queue: string) => void;
|
|
56
|
+
readonly value: string;
|
|
57
|
+
}) {
|
|
58
|
+
return (
|
|
59
|
+
<label className="flex min-w-0 flex-col gap-2 text-sm sm:max-w-sm">
|
|
60
|
+
Queue
|
|
61
|
+
<select
|
|
62
|
+
className="bg-background h-10 w-full max-w-full min-w-0 rounded-md border px-3"
|
|
63
|
+
onChange={(event) => select(event.target.value)}
|
|
64
|
+
value={value}
|
|
65
|
+
>
|
|
66
|
+
{queues.map((name) => (
|
|
67
|
+
<option key={name} value={name}>
|
|
68
|
+
{name}
|
|
69
|
+
</option>
|
|
70
|
+
))}
|
|
71
|
+
</select>
|
|
72
|
+
</label>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Cause, Option, Predicate } from "effect";
|
|
2
|
+
import { createElement, useState } from "react";
|
|
3
|
+
import { useQuery } from "@shivaedev/react/client/resultState.ts";
|
|
4
|
+
import { JobsHealthMetrics } from "./JobsMetrics.tsx";
|
|
5
|
+
import { JobsQueuePicker, JobsQueueView } from "./JobsQueueView.tsx";
|
|
6
|
+
import type { JobsViewClient, RetryJob } from "./jobsTypes.ts";
|
|
7
|
+
|
|
8
|
+
export interface JobsViewProps {
|
|
9
|
+
readonly api: JobsViewClient;
|
|
10
|
+
readonly queues: readonly string[];
|
|
11
|
+
readonly retry?: RetryJob | undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function JobsView({ api, queues, retry }: JobsViewProps) {
|
|
15
|
+
const [queue, selectQueue] = useState(queues[0] ?? "");
|
|
16
|
+
const health = useQuery(api.health.query(undefined));
|
|
17
|
+
const denied = Option.exists(Option.flatMap(health.cause, Cause.findErrorOption), (error) => Predicate.isTagged(error, "Forbidden"));
|
|
18
|
+
if (denied) {
|
|
19
|
+
return createElement("p", { role: "alert" }, "Permission required to view jobs.");
|
|
20
|
+
}
|
|
21
|
+
return createElement(
|
|
22
|
+
"div",
|
|
23
|
+
{ className: "min-w-0 space-y-8" },
|
|
24
|
+
createElement(JobsHealthMetrics, { state: health }),
|
|
25
|
+
queues.length === 0
|
|
26
|
+
? createElement("p", null, "No queues or schedules registered.")
|
|
27
|
+
: createElement(
|
|
28
|
+
"div",
|
|
29
|
+
{ className: "min-w-0 space-y-6" },
|
|
30
|
+
createElement(JobsQueuePicker, { queues, select: selectQueue, value: queue }),
|
|
31
|
+
createElement(JobsQueueView, { api, key: queue, queue, retry }),
|
|
32
|
+
),
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import type { SignedInSession } from "@shivaedev/identity/sessions.ts";
|
|
3
|
+
|
|
4
|
+
export function SessionConfirmation({
|
|
5
|
+
selected,
|
|
6
|
+
currentSessionId,
|
|
7
|
+
pending,
|
|
8
|
+
onCancel,
|
|
9
|
+
onConfirm,
|
|
10
|
+
}: {
|
|
11
|
+
readonly selected: typeof SignedInSession.Type | undefined;
|
|
12
|
+
readonly currentSessionId: string | undefined;
|
|
13
|
+
readonly pending: boolean;
|
|
14
|
+
readonly onCancel: () => void;
|
|
15
|
+
readonly onConfirm: (input: { readonly id: string }) => void;
|
|
16
|
+
}) {
|
|
17
|
+
const confirmationRef = useRef<HTMLFieldSetElement>(null);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (selected !== undefined) {
|
|
20
|
+
confirmationRef.current?.focus();
|
|
21
|
+
}
|
|
22
|
+
}, [selected]);
|
|
23
|
+
if (selected === undefined) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return (
|
|
27
|
+
<fieldset
|
|
28
|
+
aria-label="Confirm session revocation"
|
|
29
|
+
className="min-w-0 space-y-3 rounded-md border p-4 wrap-anywhere"
|
|
30
|
+
ref={confirmationRef}
|
|
31
|
+
tabIndex={-1}
|
|
32
|
+
>
|
|
33
|
+
<p>{`End the session for ${selected.user.email}?${selected.id === currentSessionId ? " This signs you out." : ""}`}</p>
|
|
34
|
+
<div className="flex flex-wrap gap-3">
|
|
35
|
+
<button className="rounded-md border px-3 py-2" disabled={pending} onClick={onCancel} type="button">
|
|
36
|
+
Cancel
|
|
37
|
+
</button>
|
|
38
|
+
<button className="rounded-md border px-3 py-2" disabled={pending} onClick={() => onConfirm({ id: selected.id })} type="button">
|
|
39
|
+
{pending ? "Revoking…" : "Confirm revoke"}
|
|
40
|
+
</button>
|
|
41
|
+
</div>
|
|
42
|
+
</fieldset>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { DateTime } from "effect";
|
|
2
|
+
import type { SignedInSession } from "@shivaedev/identity/sessions.ts";
|
|
3
|
+
|
|
4
|
+
interface SessionControls {
|
|
5
|
+
readonly currentSessionId: string | undefined;
|
|
6
|
+
readonly pending: boolean;
|
|
7
|
+
readonly select: (session: typeof SignedInSession.Type) => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function SessionListView({ sessions, ...controls }: SessionControls & { readonly sessions: readonly (typeof SignedInSession.Type)[] }) {
|
|
11
|
+
if (sessions.length === 0) {
|
|
12
|
+
return <p>No signed-in sessions.</p>;
|
|
13
|
+
}
|
|
14
|
+
return (
|
|
15
|
+
<ul aria-label="Sessions" className="grid min-w-0 gap-4">
|
|
16
|
+
{sessions.map((session) => (
|
|
17
|
+
<SessionRow {...controls} key={session.id} session={session} />
|
|
18
|
+
))}
|
|
19
|
+
</ul>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function SessionRow({ session, currentSessionId, pending, select }: SessionControls & { readonly session: typeof SignedInSession.Type }) {
|
|
24
|
+
const current = session.id === currentSessionId && <p className="font-medium">Your current session</p>;
|
|
25
|
+
return (
|
|
26
|
+
<li className="min-w-0 space-y-3 rounded-md border p-4 wrap-anywhere">
|
|
27
|
+
<div className="flex flex-wrap items-start justify-between gap-3">
|
|
28
|
+
<div className="min-w-0">
|
|
29
|
+
<p className="font-medium">{session.user.name}</p>
|
|
30
|
+
<p>{session.user.email}</p>
|
|
31
|
+
{current}
|
|
32
|
+
</div>
|
|
33
|
+
<button
|
|
34
|
+
aria-label={`Revoke session for ${session.user.email}`}
|
|
35
|
+
className="rounded-md border px-3 py-2 disabled:opacity-50"
|
|
36
|
+
disabled={pending}
|
|
37
|
+
onClick={() => select(session)}
|
|
38
|
+
type="button"
|
|
39
|
+
>
|
|
40
|
+
Revoke session
|
|
41
|
+
</button>
|
|
42
|
+
</div>
|
|
43
|
+
<SessionTimes session={session} />
|
|
44
|
+
</li>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function SessionTimes({ session }: { readonly session: typeof SignedInSession.Type }) {
|
|
49
|
+
const times = [
|
|
50
|
+
["Started", session.startedAt],
|
|
51
|
+
["Last activity", session.lastActivityAt],
|
|
52
|
+
["Expires", session.expiresAt],
|
|
53
|
+
] as const;
|
|
54
|
+
return (
|
|
55
|
+
<dl className="grid min-w-0 gap-3 text-sm sm:grid-cols-3">
|
|
56
|
+
{times.map(([label, time]) => (
|
|
57
|
+
<div key={label}>
|
|
58
|
+
<dt className="text-muted-foreground">{label}</dt>
|
|
59
|
+
<dd>
|
|
60
|
+
<time dateTime={DateTime.formatIso(time)}>{DateTime.formatIso(time)}</time>
|
|
61
|
+
</dd>
|
|
62
|
+
</div>
|
|
63
|
+
))}
|
|
64
|
+
</dl>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Option } from "effect";
|
|
2
|
+
import type { SessionList, SessionListInput } from "@shivaedev/identity/sessions.ts";
|
|
3
|
+
|
|
4
|
+
type Cursor = NonNullable<typeof SessionListInput.Type.cursor>;
|
|
5
|
+
|
|
6
|
+
export function SessionPagination({
|
|
7
|
+
data,
|
|
8
|
+
cursors,
|
|
9
|
+
pending,
|
|
10
|
+
go,
|
|
11
|
+
}: {
|
|
12
|
+
readonly data: typeof SessionList.Type | undefined;
|
|
13
|
+
readonly cursors: readonly Cursor[];
|
|
14
|
+
readonly pending: boolean;
|
|
15
|
+
readonly go: (cursors: readonly Cursor[]) => void;
|
|
16
|
+
}) {
|
|
17
|
+
if (data === undefined) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return (
|
|
21
|
+
<nav aria-label="Session pages" className="flex flex-wrap gap-3">
|
|
22
|
+
<button
|
|
23
|
+
className="rounded-md border px-3 py-2 disabled:opacity-50"
|
|
24
|
+
disabled={cursors.length === 0 || pending}
|
|
25
|
+
onClick={() => go(cursors.slice(0, -1))}
|
|
26
|
+
type="button"
|
|
27
|
+
>
|
|
28
|
+
Previous sessions
|
|
29
|
+
</button>
|
|
30
|
+
<button
|
|
31
|
+
className="rounded-md border px-3 py-2 disabled:opacity-50"
|
|
32
|
+
disabled={Option.isNone(data.next) || pending}
|
|
33
|
+
onClick={() => Option.map(data.next, (next) => go([...cursors, next]))}
|
|
34
|
+
type="button"
|
|
35
|
+
>
|
|
36
|
+
Next sessions
|
|
37
|
+
</button>
|
|
38
|
+
</nav>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Cause, type Effect, Option, Predicate } from "effect";
|
|
2
|
+
import type * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
3
|
+
import type * as Atom from "effect/reactivity/Atom";
|
|
4
|
+
import { createElement, useState } from "react";
|
|
5
|
+
import type { SessionList, SessionListInput, SignedInSession } from "@shivaedev/identity/sessions.ts";
|
|
6
|
+
import { useAction, useQuery } from "@shivaedev/react/client/resultState.ts";
|
|
7
|
+
import type { AtomServices } from "@shivaedev/react/fieldRejection.ts";
|
|
8
|
+
import { SessionConfirmation } from "./SessionConfirmation.tsx";
|
|
9
|
+
import { SessionListView } from "./SessionListView.tsx";
|
|
10
|
+
import { SessionPagination } from "./SessionPagination.tsx";
|
|
11
|
+
|
|
12
|
+
export interface SessionsViewProps<R, E> {
|
|
13
|
+
readonly currentSessionId: string | undefined;
|
|
14
|
+
readonly list: (input: typeof SessionListInput.Type) => Atom.Atom<AsyncResult.AsyncResult<typeof SessionList.Type, unknown>>;
|
|
15
|
+
readonly onCurrentSessionRevoked: () => void;
|
|
16
|
+
readonly revoke: (input: { readonly id: string }) => Effect.Effect<void, unknown, AtomServices<R>>;
|
|
17
|
+
readonly runtime: Atom.AtomRuntime<R, E>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function forbidden(cause: Option.Option<Cause.Cause<unknown>>) {
|
|
21
|
+
return Option.exists(Option.flatMap(cause, Cause.findErrorOption), (error) => Predicate.isTagged(error, "Forbidden"));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function SessionsView<R, E>({ currentSessionId, list, onCurrentSessionRevoked, revoke, runtime }: SessionsViewProps<R, E>) {
|
|
25
|
+
const [cursors, setCursors] = useState<readonly NonNullable<typeof SessionListInput.Type.cursor>[]>([]);
|
|
26
|
+
const [selected, select] = useState<typeof SignedInSession.Type>();
|
|
27
|
+
const cursor = cursors.at(-1);
|
|
28
|
+
const state = useQuery(list({ ...(cursor === undefined ? {} : { cursor }), limit: 20 }));
|
|
29
|
+
const action = useAction(runtime, revoke, {
|
|
30
|
+
onSuccess: (_, { id }) => {
|
|
31
|
+
select(undefined);
|
|
32
|
+
if (id === currentSessionId) {
|
|
33
|
+
onCurrentSessionRevoked();
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
if (forbidden(state.cause)) {
|
|
38
|
+
return createElement("p", { role: "alert" }, "Permission required to manage sessions.");
|
|
39
|
+
}
|
|
40
|
+
const data = Option.getOrUndefined(state.data);
|
|
41
|
+
return createElement(
|
|
42
|
+
"section",
|
|
43
|
+
{ "aria-label": "Signed-in sessions", className: "min-w-0 space-y-4" },
|
|
44
|
+
createElement(
|
|
45
|
+
"button",
|
|
46
|
+
{
|
|
47
|
+
className: "rounded-md border px-3 py-2 disabled:opacity-50",
|
|
48
|
+
disabled: state.pending || action.pending,
|
|
49
|
+
onClick: state.refresh,
|
|
50
|
+
type: "button",
|
|
51
|
+
},
|
|
52
|
+
"Refresh sessions",
|
|
53
|
+
),
|
|
54
|
+
state.pending ? createElement("p", { role: "status" }, "Loading sessions…") : null,
|
|
55
|
+
Option.isSome(state.cause) ? createElement("p", { role: "alert" }, "Could not load sessions. Try refreshing.") : null,
|
|
56
|
+
Option.isSome(action.cause) ? createElement("p", { role: "alert" }, "Could not revoke the session. Refresh and try again.") : null,
|
|
57
|
+
createElement(SessionConfirmation, {
|
|
58
|
+
currentSessionId,
|
|
59
|
+
onCancel: () => select(undefined),
|
|
60
|
+
onConfirm: action.dispatch,
|
|
61
|
+
pending: action.pending,
|
|
62
|
+
selected,
|
|
63
|
+
}),
|
|
64
|
+
data === undefined ? null : createElement(SessionListView, { currentSessionId, pending: action.pending, select, sessions: data.sessions }),
|
|
65
|
+
createElement(SessionPagination, {
|
|
66
|
+
cursors,
|
|
67
|
+
data,
|
|
68
|
+
go: (next) => {
|
|
69
|
+
select(undefined);
|
|
70
|
+
setCursors(next);
|
|
71
|
+
},
|
|
72
|
+
pending: state.pending || action.pending,
|
|
73
|
+
}),
|
|
74
|
+
);
|
|
75
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Option, Schema } from "effect";
|
|
2
|
+
import type * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
3
|
+
import type * as Atom from "effect/reactivity/Atom";
|
|
4
|
+
import type { deadLetteredSchema, JobsHealth, jobSchema, QueueCounts } from "#jobs/schemas.ts";
|
|
5
|
+
|
|
6
|
+
type Job = ReturnType<typeof jobSchema<typeof Schema.Unknown>>["Type"];
|
|
7
|
+
type DeadLetter = ReturnType<typeof deadLetteredSchema<typeof Schema.Unknown>>["Type"];
|
|
8
|
+
export type AdminJob = Job | DeadLetter;
|
|
9
|
+
interface JobId {
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly queue: string;
|
|
12
|
+
}
|
|
13
|
+
interface PageInput {
|
|
14
|
+
readonly cursor?: string;
|
|
15
|
+
readonly limit: number;
|
|
16
|
+
readonly queue: string;
|
|
17
|
+
}
|
|
18
|
+
interface Page<A> {
|
|
19
|
+
readonly jobs: readonly A[];
|
|
20
|
+
readonly next: Option.Option<string>;
|
|
21
|
+
}
|
|
22
|
+
interface Query<TInput, A> {
|
|
23
|
+
readonly query: (input: TInput) => Atom.Atom<AsyncResult.AsyncResult<A, unknown>>;
|
|
24
|
+
}
|
|
25
|
+
export interface JobsViewClient {
|
|
26
|
+
readonly counts: Query<{ readonly queue: string }, typeof QueueCounts.Type>;
|
|
27
|
+
readonly deadLettered: Query<PageInput, Page<DeadLetter>>;
|
|
28
|
+
readonly failed: Query<PageInput, Page<Job>>;
|
|
29
|
+
readonly health: Query<void, typeof JobsHealth.Type>;
|
|
30
|
+
readonly job: Query<JobId, Option.Option<Job>>;
|
|
31
|
+
}
|
|
32
|
+
export type RetryJob = Atom.AtomResultFn<JobId, void, unknown>;
|
package/src/jobs/entry.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import type { JobsQueue } from "./schemas.ts";
|
|
3
3
|
|
|
4
|
-
export type JobsEntry = JobsQueue | { readonly
|
|
4
|
+
export type JobsEntry = JobsQueue | { readonly name: string };
|
|
5
5
|
|
|
6
6
|
export type JobsPayload<TEntry extends JobsEntry> = [TEntry] extends [never]
|
|
7
7
|
? typeof Schema.Never
|
package/src/jobs/page.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
2
|
import { contract } from "@shivaedev/contract/contract.ts";
|
|
3
3
|
import { query } from "@shivaedev/contract/operation.ts";
|
|
4
4
|
import { type JobsEntry, type JobsPayload, jobsQueue } from "#jobs/entry.ts";
|
|
@@ -15,30 +15,35 @@ export function jobsPage<const TQueues extends readonly JobsEntry[]>(...queues:
|
|
|
15
15
|
contract: contract("admin.jobs", {
|
|
16
16
|
queries: [
|
|
17
17
|
query("health", {
|
|
18
|
+
readPolicy: () => Effect.succeed(true),
|
|
18
19
|
reads: () => [jobsKeys.health.list],
|
|
19
20
|
rejections: JobsFailures,
|
|
20
21
|
success: JobsHealth,
|
|
21
22
|
}),
|
|
22
23
|
query("counts", {
|
|
23
24
|
payload: { queue: Schema.String },
|
|
25
|
+
readPolicy: () => Effect.succeed(true),
|
|
24
26
|
reads: ({ queue }) => [jobsKeys.counts.item(queue)],
|
|
25
27
|
rejections: JobsFailures,
|
|
26
28
|
success: QueueCounts,
|
|
27
29
|
}),
|
|
28
30
|
query("failed", {
|
|
29
31
|
payload: { ...PageFields, queue: Schema.String },
|
|
32
|
+
readPolicy: () => Effect.succeed(true),
|
|
30
33
|
reads: ({ queue }) => [jobsKeys.failed.item(queue)],
|
|
31
34
|
rejections: JobsFailures,
|
|
32
35
|
success: jobPage(Job),
|
|
33
36
|
}),
|
|
34
37
|
query("deadLettered", {
|
|
35
38
|
payload: { ...PageFields, queue: Schema.String },
|
|
39
|
+
readPolicy: () => Effect.succeed(true),
|
|
36
40
|
reads: ({ queue }) => [jobsKeys.deadLettered.item(queue)],
|
|
37
41
|
rejections: JobsFailures,
|
|
38
42
|
success: jobPage(DeadLettered),
|
|
39
43
|
}),
|
|
40
44
|
query("job", {
|
|
41
45
|
payload: { id: Schema.String, queue: Schema.String },
|
|
46
|
+
readPolicy: () => Effect.succeed(true),
|
|
42
47
|
reads: ({ queue, id }) => [jobsKeys.job(queue).item(id)],
|
|
43
48
|
rejections: JobsFailures,
|
|
44
49
|
success: Schema.OptionFromNullOr(Job),
|
package/src/jobs/schemas.ts
CHANGED
|
@@ -61,17 +61,18 @@ export const JobFields = {
|
|
|
61
61
|
export const PageFields = { cursor: Schema.optionalKey(Schema.String), limit: Schema.Number };
|
|
62
62
|
|
|
63
63
|
export function jobSchema<TPayload extends Schema.Top>(queue: { readonly name: string; readonly schema: TPayload }) {
|
|
64
|
-
return Schema.Struct({ ...JobFields, data:
|
|
64
|
+
return Schema.Struct({ ...JobFields, data: Schema.Unknown.annotate({ sensitive: true }), queue: Schema.Literal(queue.name) });
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
export function deadLetteredSchema<TPayload extends Schema.Top>(queue: { readonly name: string; readonly schema: TPayload }) {
|
|
68
68
|
const name: string = `${queue.name}-dlq`;
|
|
69
69
|
return Schema.Struct({
|
|
70
70
|
...JobFields,
|
|
71
|
-
data:
|
|
71
|
+
data: Schema.Unknown.annotate({ sensitive: true }),
|
|
72
72
|
queue: Schema.Literal(name),
|
|
73
73
|
sourceId: Schema.OptionFromNullOr(Schema.String),
|
|
74
74
|
sourceOutput: Schema.NullOr(JobFailure).annotate({ sensitive: true }),
|
|
75
|
+
sourceQueue: Schema.Literal(queue.name),
|
|
75
76
|
});
|
|
76
77
|
}
|
|
77
78
|
|
|
@@ -53,16 +53,7 @@ export function jobsReadHandlers<const TQueues extends readonly JobsEntry[], TSe
|
|
|
53
53
|
"admin.jobs.health": () =>
|
|
54
54
|
Effect.gen(function* () {
|
|
55
55
|
const jobs = yield* service;
|
|
56
|
-
|
|
57
|
-
const visible = health.jobs.filter((queue) => page.queues.some((candidate) => candidate.name === queue.name));
|
|
58
|
-
return {
|
|
59
|
-
activeTotal: visible.reduce((sum, queue) => sum + queue.activeCount, 0),
|
|
60
|
-
deadLetteredTotal: visible.reduce((sum, queue) => sum + queue.deadLetteredCount, 0),
|
|
61
|
-
failedTotal: visible.reduce((sum, queue) => sum + queue.failedCount, 0),
|
|
62
|
-
jobs: visible,
|
|
63
|
-
queuedTotal: visible.reduce((sum, queue) => sum + queue.queuedCount, 0),
|
|
64
|
-
readyTotal: visible.reduce((sum, queue) => sum + queue.readyCount, 0),
|
|
65
|
-
};
|
|
56
|
+
return yield* jobsFailures(jobs.health(page.queues));
|
|
66
57
|
}),
|
|
67
58
|
"admin.jobs.job": ({ id, queue }: { readonly id: string; readonly queue: string }) =>
|
|
68
59
|
Effect.gen(function* () {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SessionsPermission } from "@shivaedev/identity/sessionPermissions.ts";
|
|
2
|
+
import { Sessions } from "@shivaedev/identity/sessions.ts";
|
|
3
|
+
import { adminPage } from "#page.ts";
|
|
4
|
+
|
|
5
|
+
export const SessionsPage = adminPage({
|
|
6
|
+
contract: Sessions,
|
|
7
|
+
id: "sessions",
|
|
8
|
+
permission: SessionsPermission,
|
|
9
|
+
route: { path: "/admin/sessions", title: "Sessions" },
|
|
10
|
+
});
|
package/src/users/page.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
2
|
import type { AccessPolicy } from "@shivaedev/access/roleSet.ts";
|
|
3
3
|
import { LastRoleAssigner } from "@shivaedev/access/roles.ts";
|
|
4
4
|
import { collection } from "@shivaedev/changes/keys.ts";
|
|
@@ -25,6 +25,7 @@ export function usersPage<const TRole extends string>(access: Pick<AccessPolicy<
|
|
|
25
25
|
queries: [
|
|
26
26
|
query("list", {
|
|
27
27
|
payload: UserListInput.fields,
|
|
28
|
+
readPolicy: () => Effect.succeed(true),
|
|
28
29
|
reads: () => [users.list],
|
|
29
30
|
rejections: { AuthUnavailable, Forbidden },
|
|
30
31
|
success: UsersList,
|