@shivaedev/admin 0.3.0 → 0.4.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/README.md +23 -2
- package/dist/client/UsersTable.d.ts +11 -0
- package/dist/client/UsersTable.d.ts.map +1 -0
- package/dist/client/UsersTable.js +25 -0
- package/dist/client/UsersTable.js.map +1 -0
- package/dist/client/UsersView.d.ts +13 -0
- package/dist/client/UsersView.d.ts.map +1 -0
- package/dist/client/UsersView.js +35 -0
- package/dist/client/UsersView.js.map +1 -0
- package/dist/jobs/retryPage.d.ts +32 -32
- package/dist/server/usersHandlers.d.ts +2 -0
- package/dist/server/usersHandlers.d.ts.map +1 -0
- package/dist/server/usersHandlers.js +13 -0
- package/dist/server/usersHandlers.js.map +1 -0
- package/dist/users/page.d.ts +80 -0
- package/dist/users/page.d.ts.map +1 -0
- package/dist/users/page.js +31 -0
- package/dist/users/page.js.map +1 -0
- package/package.json +17 -6
- package/src/client/UsersTable.tsx +102 -0
- package/src/client/UsersView.ts +71 -0
- package/src/server/usersHandlers.ts +14 -0
- package/src/users/page.ts +32 -0
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ The page exposes `admin.jobs.failed` and the generated `admin.jobs.$changes` sub
|
|
|
17
17
|
|
|
18
18
|
## Use native contracts and Layers
|
|
19
19
|
|
|
20
|
-
Install `@shivaedev/admin` with `effect`. Declare each page's queries, commands and streams with `@shivaedev/effect-contract`, then pass its native contract to `adminPage`. The stable id identifies the page at server registration; route metadata belongs to the application's view. Author RPC namespaces in the contract name, such as `admin.jobs`.
|
|
20
|
+
Install `@shivaedev/admin` with `effect`, `react` and `@effect/atom-react`. Declare each page's queries, commands and streams with `@shivaedev/effect-contract`, then pass its native contract to `adminPage`. The stable id identifies the page at server registration; route metadata belongs to the application's view. Author RPC namespaces in the contract name, such as `admin.jobs`.
|
|
21
21
|
|
|
22
22
|
```ts
|
|
23
23
|
import { Schema } from "effect";
|
|
@@ -59,7 +59,7 @@ const handlers = registration.handlers.pipe(
|
|
|
59
59
|
|
|
60
60
|
Pass `registration.group` and `handlers` to the existing application's RPC host on `/rpc`, merging them with its other groups and Layers as needed. The Platform host supplies generated change handlers; registration requires the page's application handlers. Handler Layer errors and service requirements remain inferred. Missing or extra page ids fail at registration; TypeScript also checks each Layer provides the handlers for its page.
|
|
61
61
|
|
|
62
|
-
Page declarations and the registry are browser-safe. Server registration lives under `/server`;
|
|
62
|
+
Page declarations and the registry are browser-safe. Server registration lives under `/server`; applications own route composition and styling. The built-in Users view uses React; server declarations add no transport. The package's stories prove role enforcement through native in-process RPC, with an already resolved session as a precondition.
|
|
63
63
|
|
|
64
64
|
## Built-in Jobs page
|
|
65
65
|
|
|
@@ -110,3 +110,24 @@ const registration = registerAdmin(Admin, {
|
|
|
110
110
|
This variant adds only `admin.jobs.retry`, taking `{ queue, id }` and returning void. It requires the `admin` role, including when the caller has the `owner` role. The handler uses effect-pg-boss's existing retry for a failed job in a declared queue. Missing jobs and jobs in other states fail with `JobsNotFailed`; unregistered queue names, including dead-letter queues, fail with `JobsQueueUnregistered`. A dead-letter copy's id cannot retry its original.
|
|
111
111
|
|
|
112
112
|
A successful bound retry invalidates health, the affected queue's counts and both listings, and the original job's detail. PostgreSQL stories mount these query atoms, retry through authenticated serialized RPC, and observe refetching and a second worker execution. Health retains the runtime monitor's refresh timing.
|
|
113
|
+
|
|
114
|
+
## Built-in Users page
|
|
115
|
+
|
|
116
|
+
`UsersPage` from `@shivaedev/admin/users/page.ts` declares `/admin/users`. Add it to the same registry as Jobs and register `users: usersHandlers` from `@shivaedev/admin/server/usersHandlers.ts`. The handlers use the application's existing Effect SQL client against Better Auth's default PostgreSQL `user` table, with the admin plugin's `role` column. They do not create another user store. Custom Better Auth table or column names are not supported by these handlers.
|
|
117
|
+
|
|
118
|
+
Bind `UsersPage.contract` to the registry's native AtomRpc client, then mount the package view in the application's admin shell. The view uses semantic HTML and Tailwind utility classes; Tailwind applications include `@source "../../node_modules/@shivaedev/admin/src/client";` in `src/client/entry.css`, as the starter does:
|
|
119
|
+
|
|
120
|
+
```tsx
|
|
121
|
+
import { UsersView } from "@shivaedev/admin/client/UsersView.ts";
|
|
122
|
+
|
|
123
|
+
const users = bind(UsersPage.contract, Client);
|
|
124
|
+
const changeRole = Client.runtime.fn(users.changeRole.run);
|
|
125
|
+
|
|
126
|
+
<UsersView list={users.list.query} changeRole={changeRole} />;
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
`admin.users.list` takes `{ limit, cursor? }` (1–100 users), returns `{ users, next, canChangeRoles }`, and orders pages by user id. Each user has id, name, email, roles and a UTC sign-up time. All reads and subscriptions require `admin`. Only callers who also have `owner` see role controls. `admin.users.changeRole` takes `{ userId, role, grant }` for Platform's `user`, `admin` and `owner` roles. It returns typed `Forbidden` for a non-owner, `LastOwner` when revoking the final owner, and `NotFound` for a missing user. Role changes preserve other roles, invalidate the list after commit, and emit an Effect log with actor id, target id, role, action and timestamp. There is no durable audit-history store.
|
|
130
|
+
|
|
131
|
+
Keep Better Auth cookie caching disabled so requests see current roles. Applications must route role writes through this operation to retain its owner and last-owner policy. The starter disables Better Auth's `/admin/set-role`, `/admin/update-user` and `/admin/create-user` browser endpoints; its server-side bootstrap API remains available.
|
|
132
|
+
|
|
133
|
+
The starter mounts Users beside Jobs and bootstraps new administrators with both `admin` and `owner`. Existing generated apps receive this wiring through `pnpm dlx @shivaedev/create-app@latest update` after release; review conflicts and install dependencies. For an existing database with no owner, bootstrap a new administrator with `pnpm admin:create`.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ChangeRoleInput } from "@shivaedev/platform/rpc/userRoles.ts";
|
|
2
|
+
import type { UsersList } from "#users/page.ts";
|
|
3
|
+
interface RoleControls {
|
|
4
|
+
readonly dispatch: (input: typeof ChangeRoleInput.Type) => void;
|
|
5
|
+
readonly pending: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function UsersTable({ data, ...controls }: RoleControls & {
|
|
8
|
+
readonly data: typeof UsersList.Type;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=UsersTable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UsersTable.d.ts","sourceRoot":"","sources":["../../src/client/UsersTable.tsx"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,eAAe,EAAY,MAAM,sCAAsC,CAAC;AACpG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,UAAU,YAAY;IACrB,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,eAAe,CAAC,IAAI,KAAK,IAAI,CAAC;IAChE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC1B;AAuFD,wBAAgB,UAAU,CAAC,EAAE,IAAI,EAAE,GAAG,QAAQ,EAAE,EAAE,YAAY,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,SAAS,CAAC,IAAI,CAAA;CAAE,+BAOxG"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createElement as _createElement } from "react";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { DateTime } from "effect";
|
|
4
|
+
import { UserRole } from "@shivaedev/platform/rpc/userRoles.ts";
|
|
5
|
+
function UserHeaders() {
|
|
6
|
+
return (_jsx("tr", { children: ["Name", "Email", "Roles", "Signed up"].map((label) => (_jsx("th", { className: "whitespace-nowrap p-3", scope: "col", children: label }, label))) }));
|
|
7
|
+
}
|
|
8
|
+
function RoleCheckbox({ user, role, pending, dispatch }) {
|
|
9
|
+
return (_jsxs("label", { className: "mr-3 inline-flex gap-1", children: [_jsx("input", { "aria-label": `${role} for ${user.email}`, checked: user.roles.includes(role), disabled: pending, onChange: (event) => dispatch({ grant: event.target.checked, role, userId: user.id }), type: "checkbox" }), role] }));
|
|
10
|
+
}
|
|
11
|
+
function UserRoles({ user, canChangeRoles, dispatch, pending, }) {
|
|
12
|
+
return (_jsxs("div", { children: [_jsx("p", { children: user.roles.join(", ") || "No roles" }), canChangeRoles
|
|
13
|
+
? UserRole.literals.map((role) => _jsx(RoleCheckbox, { dispatch: dispatch, pending: pending, role: role, user: user }, role))
|
|
14
|
+
: null] }));
|
|
15
|
+
}
|
|
16
|
+
function UserRow({ user, ...controls }) {
|
|
17
|
+
return (_jsxs("tr", { className: "border-b", children: [_jsx("td", { className: "p-3", children: user.name }), _jsx("td", { className: "p-3", children: user.email }), _jsx("td", { className: "p-3", children: _jsx(UserRoles, { ...controls, user: user }) }), _jsx("td", { className: "whitespace-nowrap p-3", children: _jsx("time", { dateTime: DateTime.formatIso(user.createdAt), children: DateTime.formatIso(user.createdAt) }) })] }));
|
|
18
|
+
}
|
|
19
|
+
function UserRows({ data, ...controls }) {
|
|
20
|
+
return (_jsx("div", { className: "overflow-x-auto rounded-md border", children: _jsxs("table", { className: "w-full text-left text-sm", children: [_jsx("caption", { className: "sr-only", children: "App users and roles" }), _jsx("thead", { className: "bg-muted", children: _jsx(UserHeaders, {}) }), _jsx("tbody", { children: data.users.map((user) => (_createElement(UserRow, { ...controls, canChangeRoles: data.canChangeRoles, key: user.id, user: user }))) })] }) }));
|
|
21
|
+
}
|
|
22
|
+
export function UsersTable({ data, ...controls }) {
|
|
23
|
+
return (_jsxs("div", { className: "space-y-4", children: [data.canChangeRoles ? null : _jsx("p", { children: "Only owners can change roles." }), data.users.length === 0 ? _jsx("p", { children: "No users." }) : _jsx(UserRows, { ...controls, data: data })] }));
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=UsersTable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UsersTable.js","sourceRoot":"","sources":["../../src/client/UsersTable.tsx"],"names":[],"mappings":";;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAsC,QAAQ,EAAE,MAAM,sC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,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,oCAAgB,CAAC,CAAC,CAAC,KAAC,QAAQ,OAAK,QAAQ,EAAE,IAAI,EAAE,IAAI,GAAI,IAC/E,CACN,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
2
|
+
import type * as Atom from "effect/reactivity/Atom";
|
|
3
|
+
import type { ChangeRoleInput, UserListInput } from "@shivaedev/platform/rpc/userRoles.ts";
|
|
4
|
+
import type { UsersList } from "#users/page.ts";
|
|
5
|
+
export interface UsersViewProps {
|
|
6
|
+
readonly changeRole: Atom.AtomResultFn<typeof ChangeRoleInput.Type, void, unknown>;
|
|
7
|
+
readonly list: (input: typeof UserListInput.Type) => Atom.Atom<AsyncResult.AsyncResult<typeof UsersList.Type, unknown>>;
|
|
8
|
+
}
|
|
9
|
+
export declare function UsersView({ list, changeRole }: UsersViewProps): import("react").DetailedReactHTMLElement<{
|
|
10
|
+
"aria-label": string;
|
|
11
|
+
className: string;
|
|
12
|
+
}, HTMLElement>;
|
|
13
|
+
//# sourceMappingURL=UsersView.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UsersView.d.ts","sourceRoot":"","sources":["../../src/client/UsersView.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAGpD,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAC3F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,OAAO,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACnF,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,aAAa,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,OAAO,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;CACxH;AAaD,wBAAgB,SAAS,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,cAAc;;;gBA6C7D"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Cause, Option, Predicate } from "effect";
|
|
2
|
+
import { createElement, useState } from "react";
|
|
3
|
+
import { useAction, useQuery } from "@shivaedev/effect-react/client/resultState.ts";
|
|
4
|
+
import { UsersTable } from "./UsersTable.js";
|
|
5
|
+
function failure(cause) {
|
|
6
|
+
const error = Option.getOrUndefined(Cause.findErrorOption(cause));
|
|
7
|
+
if (Predicate.isTagged(error, "LastOwner")) {
|
|
8
|
+
return "The last owner cannot be demoted. Grant owner to another user first.";
|
|
9
|
+
}
|
|
10
|
+
if (Predicate.isTagged(error, "Forbidden")) {
|
|
11
|
+
return "Owner role required to change roles.";
|
|
12
|
+
}
|
|
13
|
+
return "Could not change the role. Try again.";
|
|
14
|
+
}
|
|
15
|
+
export function UsersView({ list, changeRole }) {
|
|
16
|
+
const [cursors, setCursors] = useState([]);
|
|
17
|
+
const cursor = cursors.at(-1);
|
|
18
|
+
const state = useQuery(list({ ...(cursor === undefined ? {} : { cursor }), limit: 20 }));
|
|
19
|
+
const action = useAction(changeRole);
|
|
20
|
+
const data = Option.getOrUndefined(state.data);
|
|
21
|
+
return createElement("section", { "aria-label": "App users", className: "space-y-4" }, createElement("button", { className: "rounded-md border px-3 py-2 disabled:opacity-50", disabled: state.pending, onClick: state.refresh, type: "button" }, "Refresh users"), state.pending ? createElement("p", { role: "status" }, "Loading users…") : null, Option.isSome(state.cause) ? createElement("p", { role: "alert" }, "Could not load users. Try refreshing.") : null, Option.isSome(action.cause) ? createElement("p", { role: "alert" }, failure(action.cause.value)) : null, data === undefined ? null : createElement(UsersTable, { data, dispatch: action.dispatch, pending: action.pending }), data === undefined
|
|
22
|
+
? null
|
|
23
|
+
: createElement("nav", { "aria-label": "User pages", className: "flex gap-4" }, createElement("button", {
|
|
24
|
+
className: "rounded-md border px-3 py-2 disabled:opacity-50",
|
|
25
|
+
disabled: cursors.length === 0 || state.pending,
|
|
26
|
+
onClick: () => setCursors(cursors.slice(0, -1)),
|
|
27
|
+
type: "button",
|
|
28
|
+
}, "Previous users"), createElement("button", {
|
|
29
|
+
className: "rounded-md border px-3 py-2 disabled:opacity-50",
|
|
30
|
+
disabled: Option.isNone(data.next) || state.pending,
|
|
31
|
+
onClick: () => Option.map(data.next, (next) => setCursors([...cursors, next])),
|
|
32
|
+
type: "button",
|
|
33
|
+
}, "Next users")));
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=UsersView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UsersView.js","sourceRoot":"","sources":["../../src/client/UsersView.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGlD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;AAGpF,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAkB,CAAC;AAO9C,SAAS,OAAO,CAAC,KAA2B;IAC3C,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;IAClE,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,EAAE,CAAC;QAC5C,OAAO,sEAAsE,CAAC;IAC/E,CAAC;IACD,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,EAAE,CAAC;QAC5C,OAAO,sC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 +112,22 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsQue
|
|
|
112
112
|
readonly JobsQueueUnregistered: typeof import("./schemas.ts").JobsQueueUnregistered;
|
|
113
113
|
readonly JobsUnavailable: typeof import("./schemas.ts").JobsUnavailable;
|
|
114
114
|
readonly JobsNotFailed: typeof JobsNotFailed;
|
|
115
|
-
}>>], import("effect/rpc/Rpc").Rpc<"admin.jobs
|
|
115
|
+
}>>], import("effect/rpc/Rpc").Rpc<"admin.jobs.job", Schema.Struct<{
|
|
116
|
+
id: Schema.String;
|
|
117
|
+
queue: Schema.String;
|
|
118
|
+
}>, Schema.OptionFromNullOr<Schema.Union<Schema.Struct<{
|
|
119
|
+
readonly attempt: Schema.Number;
|
|
120
|
+
readonly completedOn: Schema.OptionFromNullOr<Schema.DateTimeUtcFromString>;
|
|
121
|
+
readonly createdOn: Schema.DateTimeUtcFromString;
|
|
122
|
+
readonly id: Schema.String;
|
|
123
|
+
readonly output: Schema.Unknown;
|
|
124
|
+
readonly retryCount: Schema.Number;
|
|
125
|
+
readonly retryLimit: Schema.Number;
|
|
126
|
+
readonly startedOn: Schema.OptionFromNullOr<Schema.DateTimeUtcFromString>;
|
|
127
|
+
readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
|
|
128
|
+
readonly data: [...TQueues][number]["schema"];
|
|
129
|
+
readonly queue: Schema.Literal<string>;
|
|
130
|
+
}>[]>>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/platform/rpc/middleware.ts").AuthenticatedAdmin, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.$changes", Schema.Struct<{
|
|
116
131
|
queries: Schema.$Array<Schema.Union<readonly (Schema.Struct<{
|
|
117
132
|
query: Schema.Literal<"counts">;
|
|
118
133
|
payload: Schema.Struct<{
|
|
@@ -161,6 +176,20 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsQue
|
|
|
161
176
|
readonly failedCount: Schema.Number;
|
|
162
177
|
readonly queuedCount: Schema.Number;
|
|
163
178
|
readonly totalCount: Schema.Number;
|
|
179
|
+
}>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/platform/rpc/middleware.ts").AuthenticatedAdmin, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.health", Schema.Void, Schema.Struct<{
|
|
180
|
+
readonly activeTotal: Schema.Number;
|
|
181
|
+
readonly deadLetteredTotal: Schema.Number;
|
|
182
|
+
readonly failedTotal: Schema.Number;
|
|
183
|
+
readonly jobs: Schema.$Array<Schema.Struct<{
|
|
184
|
+
readonly activeCount: Schema.Number;
|
|
185
|
+
readonly deadLetteredCount: Schema.Number;
|
|
186
|
+
readonly failedCount: Schema.Number;
|
|
187
|
+
readonly name: Schema.String;
|
|
188
|
+
readonly queuedCount: Schema.Number;
|
|
189
|
+
readonly readyCount: Schema.Number;
|
|
190
|
+
}>>;
|
|
191
|
+
readonly queuedTotal: Schema.Number;
|
|
192
|
+
readonly readyTotal: Schema.Number;
|
|
164
193
|
}>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/platform/rpc/middleware.ts").AuthenticatedAdmin, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.failed", Schema.Struct<{
|
|
165
194
|
cursor: Schema.optionalKey<Schema.String>;
|
|
166
195
|
limit: Schema.Number;
|
|
@@ -201,39 +230,10 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsQue
|
|
|
201
230
|
readonly sourceOutput: Schema.Unknown;
|
|
202
231
|
}>[]>>;
|
|
203
232
|
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
204
|
-
}>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/platform/rpc/middleware.ts").AuthenticatedAdmin, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.
|
|
233
|
+
}>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/platform/rpc/middleware.ts").AuthenticatedAdmin, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.retry", Schema.Struct<{
|
|
205
234
|
id: Schema.String;
|
|
206
235
|
queue: Schema.String;
|
|
207
|
-
}>, Schema.
|
|
208
|
-
readonly attempt: Schema.Number;
|
|
209
|
-
readonly completedOn: Schema.OptionFromNullOr<Schema.DateTimeUtcFromString>;
|
|
210
|
-
readonly createdOn: Schema.DateTimeUtcFromString;
|
|
211
|
-
readonly id: Schema.String;
|
|
212
|
-
readonly output: Schema.Unknown;
|
|
213
|
-
readonly retryCount: Schema.Number;
|
|
214
|
-
readonly retryLimit: Schema.Number;
|
|
215
|
-
readonly startedOn: Schema.OptionFromNullOr<Schema.DateTimeUtcFromString>;
|
|
216
|
-
readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
|
|
217
|
-
readonly data: [...TQueues][number]["schema"];
|
|
218
|
-
readonly queue: Schema.Literal<string>;
|
|
219
|
-
}>[]>>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/platform/rpc/middleware.ts").AuthenticatedAdmin, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.retry", Schema.Struct<{
|
|
220
|
-
id: Schema.String;
|
|
221
|
-
queue: Schema.String;
|
|
222
|
-
}>, Schema.Void, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered | typeof JobsNotFailed)[]>, typeof import("@shivaedev/platform/rpc/middleware.ts").AuthenticatedAdmin, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.health", Schema.Void, Schema.Struct<{
|
|
223
|
-
readonly activeTotal: Schema.Number;
|
|
224
|
-
readonly deadLetteredTotal: Schema.Number;
|
|
225
|
-
readonly failedTotal: Schema.Number;
|
|
226
|
-
readonly jobs: Schema.$Array<Schema.Struct<{
|
|
227
|
-
readonly activeCount: Schema.Number;
|
|
228
|
-
readonly deadLetteredCount: Schema.Number;
|
|
229
|
-
readonly failedCount: Schema.Number;
|
|
230
|
-
readonly name: Schema.String;
|
|
231
|
-
readonly queuedCount: Schema.Number;
|
|
232
|
-
readonly readyCount: Schema.Number;
|
|
233
|
-
}>>;
|
|
234
|
-
readonly queuedTotal: Schema.Number;
|
|
235
|
-
readonly readyTotal: Schema.Number;
|
|
236
|
-
}>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/platform/rpc/middleware.ts").AuthenticatedAdmin, never>, readonly [], undefined>;
|
|
236
|
+
}>, Schema.Void, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered | typeof JobsNotFailed)[]>, typeof import("@shivaedev/platform/rpc/middleware.ts").AuthenticatedAdmin, never>, readonly [], undefined>;
|
|
237
237
|
} & {
|
|
238
238
|
queues: TQueues;
|
|
239
239
|
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const usersHandlers: import("effect/Layer").Layer<import("effect/rpc/Rpc").Handler<"admin.users.changeRole"> | import("effect/rpc/Rpc").Handler<"admin.users.list">, never, import("effect/reactivity/Reactivity").Reactivity | import("effect/sql/SqlClient").SqlClient>;
|
|
2
|
+
//# sourceMappingURL=usersHandlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usersHandlers.d.ts","sourceRoot":"","sources":["../../src/server/usersHandlers.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,aAAa,sPAOxB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { hasRole } from "@shivaedev/platform/rpc/hasRole.ts";
|
|
3
|
+
import { SessionUser } from "@shivaedev/platform/rpc/identity.ts";
|
|
4
|
+
import { changeUserRole, listUsers } from "@shivaedev/platform/server/better-auth/users.ts";
|
|
5
|
+
import { UsersPage } from "#users/page.ts";
|
|
6
|
+
export const usersHandlers = UsersPage.contract.application.toLayer({
|
|
7
|
+
"admin.users.changeRole": changeUserRole,
|
|
8
|
+
"admin.users.list": (input) => Effect.gen(function* () {
|
|
9
|
+
const user = yield* SessionUser;
|
|
10
|
+
return { ...(yield* listUsers(input)), canChangeRoles: hasRole(user, "owner") };
|
|
11
|
+
}),
|
|
12
|
+
});
|
|
13
|
+
//# sourceMappingURL=usersHandlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usersHandlers.js","sourceRoot":"","sources":["../../src/server/usersHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,iDAAiD,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC;IACnE,wBAAwB,EAAE,cAAc;IACxC,kBAAkB,EAAE,CAAC,KAAK,EAAE,EAAE,CAC7B,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QACnB,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,WAAW,CAAC;QAChC,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC;IACjF,CAAC,CAAC;CACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { AuthUnavailable, Forbidden, NotFound } from "@shivaedev/effect-contract/errors/taxonomy.ts";
|
|
3
|
+
import { LastOwner } from "@shivaedev/platform/rpc/userRoles.ts";
|
|
4
|
+
export declare const UsersList: Schema.Struct<{
|
|
5
|
+
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
6
|
+
readonly users: Schema.$Array<Schema.Struct<{
|
|
7
|
+
readonly createdAt: Schema.DateTimeUtcFromString;
|
|
8
|
+
readonly email: Schema.String;
|
|
9
|
+
readonly id: Schema.String;
|
|
10
|
+
readonly name: Schema.String;
|
|
11
|
+
readonly roles: Schema.$Array<Schema.String>;
|
|
12
|
+
}>>;
|
|
13
|
+
readonly canChangeRoles: Schema.Boolean;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const UsersPage: import("#page.ts").AdminPage & {
|
|
16
|
+
readonly id: "users";
|
|
17
|
+
readonly contract: import("@shivaedev/effect-contract/contract.ts").Contract<"admin.users", readonly [NoInfer<import("@shivaedev/effect-contract/operation.ts").Query<"list", Schema.Struct<{
|
|
18
|
+
readonly cursor: Schema.optionalKey<Schema.String>;
|
|
19
|
+
readonly limit: Schema.Number;
|
|
20
|
+
}>, Schema.Struct<{
|
|
21
|
+
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
22
|
+
readonly users: Schema.$Array<Schema.Struct<{
|
|
23
|
+
readonly createdAt: Schema.DateTimeUtcFromString;
|
|
24
|
+
readonly email: Schema.String;
|
|
25
|
+
readonly id: Schema.String;
|
|
26
|
+
readonly name: Schema.String;
|
|
27
|
+
readonly roles: Schema.$Array<Schema.String>;
|
|
28
|
+
}>>;
|
|
29
|
+
readonly canChangeRoles: Schema.Boolean;
|
|
30
|
+
}>, {
|
|
31
|
+
readonly AuthUnavailable: typeof AuthUnavailable;
|
|
32
|
+
}>>], readonly [NoInfer<import("@shivaedev/effect-contract/operation.ts").Command<"changeRole", Schema.Struct<{
|
|
33
|
+
readonly grant: Schema.Boolean;
|
|
34
|
+
readonly role: Schema.Literals<readonly ["user", "admin", "owner"]>;
|
|
35
|
+
readonly userId: Schema.String;
|
|
36
|
+
}>, Schema.Void, {
|
|
37
|
+
readonly AuthUnavailable: typeof AuthUnavailable;
|
|
38
|
+
readonly Forbidden: typeof Forbidden;
|
|
39
|
+
readonly LastOwner: typeof LastOwner;
|
|
40
|
+
readonly NotFound: typeof NotFound;
|
|
41
|
+
}>>], import("effect/rpc/Rpc").Rpc<"admin.users.$changes", Schema.Struct<{
|
|
42
|
+
queries: Schema.$Array<Schema.Union<readonly Schema.Struct<{
|
|
43
|
+
query: Schema.Literal<"list">;
|
|
44
|
+
payload: Schema.Struct<{
|
|
45
|
+
readonly cursor: Schema.optionalKey<Schema.String>;
|
|
46
|
+
readonly limit: Schema.Number;
|
|
47
|
+
}>;
|
|
48
|
+
}>[]>>;
|
|
49
|
+
}>, import("effect/rpc/RpcSchema").Stream<Schema.Union<readonly [Schema.Struct<{
|
|
50
|
+
readonly _tag: Schema.Literal<"Changed">;
|
|
51
|
+
readonly keys: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
52
|
+
readonly _tag: Schema.Literal<"List">;
|
|
53
|
+
readonly collection: Schema.String;
|
|
54
|
+
}>, Schema.Struct<{
|
|
55
|
+
readonly _tag: Schema.Literal<"Item">;
|
|
56
|
+
readonly collection: Schema.String;
|
|
57
|
+
readonly id: Schema.Union<readonly [Schema.String, Schema.Number]>;
|
|
58
|
+
}>]>>;
|
|
59
|
+
}>, Schema.Struct<{
|
|
60
|
+
readonly _tag: Schema.Literal<"Resync">;
|
|
61
|
+
}>]>, Schema.Never>, Schema.Never, typeof import("@shivaedev/platform/rpc/middleware.ts").AuthenticatedAdmin, never> | import("effect/rpc/Rpc").Rpc<"admin.users.list", Schema.Struct<{
|
|
62
|
+
readonly cursor: Schema.optionalKey<Schema.String>;
|
|
63
|
+
readonly limit: Schema.Number;
|
|
64
|
+
}>, Schema.Struct<{
|
|
65
|
+
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
66
|
+
readonly users: Schema.$Array<Schema.Struct<{
|
|
67
|
+
readonly createdAt: Schema.DateTimeUtcFromString;
|
|
68
|
+
readonly email: Schema.String;
|
|
69
|
+
readonly id: Schema.String;
|
|
70
|
+
readonly name: Schema.String;
|
|
71
|
+
readonly roles: Schema.$Array<Schema.String>;
|
|
72
|
+
}>>;
|
|
73
|
+
readonly canChangeRoles: Schema.Boolean;
|
|
74
|
+
}>, Schema.Union<readonly (typeof AuthUnavailable)[]>, typeof import("@shivaedev/platform/rpc/middleware.ts").AuthenticatedAdmin, never> | import("effect/rpc/Rpc").Rpc<"admin.users.changeRole", Schema.Struct<{
|
|
75
|
+
readonly grant: Schema.Boolean;
|
|
76
|
+
readonly role: Schema.Literals<readonly ["user", "admin", "owner"]>;
|
|
77
|
+
readonly userId: Schema.String;
|
|
78
|
+
}>, Schema.Void, Schema.Union<readonly (typeof NotFound | typeof Forbidden | typeof AuthUnavailable | typeof LastOwner)[]>, typeof import("@shivaedev/platform/rpc/middleware.ts").AuthenticatedAdmin, never>, readonly [], undefined>;
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=page.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../../src/users/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;AAGrG,OAAO,EAAmB,SAAS,EAA2B,MAAM,sCAAsC,CAAC;AAK3G,eAAO,MAAM,SAAS;;;;;;;;;;EAAwE,CAAC;AAC/F,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoBpB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { contract } from "@shivaedev/effect-contract/contract.ts";
|
|
3
|
+
import { AuthUnavailable, Forbidden, NotFound } from "@shivaedev/effect-contract/errors/taxonomy.ts";
|
|
4
|
+
import { collection } from "@shivaedev/effect-contract/keys.ts";
|
|
5
|
+
import { command, query } from "@shivaedev/effect-contract/operation.ts";
|
|
6
|
+
import { ChangeRoleInput, LastOwner, UserList, UserListInput } from "@shivaedev/platform/rpc/userRoles.ts";
|
|
7
|
+
import { adminPage } from "#page.ts";
|
|
8
|
+
const users = collection("admin.users", Schema.String);
|
|
9
|
+
export const UsersList = Schema.Struct({ ...UserList.fields, canChangeRoles: Schema.Boolean });
|
|
10
|
+
export const UsersPage = adminPage({
|
|
11
|
+
contract: contract("admin.users", {
|
|
12
|
+
commands: [
|
|
13
|
+
command("changeRole", {
|
|
14
|
+
invalidates: () => [users.list],
|
|
15
|
+
payload: ChangeRoleInput.fields,
|
|
16
|
+
rejections: { AuthUnavailable, Forbidden, LastOwner, NotFound },
|
|
17
|
+
}),
|
|
18
|
+
],
|
|
19
|
+
queries: [
|
|
20
|
+
query("list", {
|
|
21
|
+
payload: UserListInput.fields,
|
|
22
|
+
reads: () => [users.list],
|
|
23
|
+
rejections: { AuthUnavailable },
|
|
24
|
+
success: UsersList,
|
|
25
|
+
}),
|
|
26
|
+
],
|
|
27
|
+
}),
|
|
28
|
+
id: "users",
|
|
29
|
+
route: { path: "/admin/users", title: "Users" },
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/users/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,wCAAwC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;AACrG,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAC3G,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,MAAM,KAAK,GAAG,UAAU,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;AAEvD,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,QAAQ,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;AAC/F,MAAM,CAAC,MAAM,SAAS,GAAG,SAAS,CAAC;IAClC,QAAQ,EAAE,QAAQ,CAAC,aAAa,EAAE;QACjC,QAAQ,EAAE;YACT,OAAO,CAAC,YAAY,EAAE;gBACrB,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;gBAC/B,OAAO,EAAE,eAAe,CAAC,MAAM;gBAC/B,UAAU,EAAE,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE;aAC/D,CAAC;SACF;QACD,OAAO,EAAE;YACR,KAAK,CAAC,MAAM,EAAE;gBACb,OAAO,EAAE,aAAa,CAAC,MAAM;gBAC7B,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;gBACzB,UAAU,EAAE,EAAE,eAAe,EAAE;gBAC/B,OAAO,EAAE,SAAS;aAClB,CAAC;SACF;KACD,CAAC;IACF,EAAE,EAAE,OAAO;IACX,KAAK,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,OAAO,EAAE;CAC/C,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/admin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Explicit admin page contracts and a protected native Effect RPC registry",
|
|
5
5
|
"homepage": "https://github.com/ShivaeDev/platform/tree/main/packages/admin#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -34,26 +34,37 @@
|
|
|
34
34
|
"dist",
|
|
35
35
|
"src",
|
|
36
36
|
"!src/**/*.test.ts",
|
|
37
|
+
"!src/**/*.test.tsx",
|
|
37
38
|
"!src/**/*.spec.ts",
|
|
39
|
+
"!src/**/*.spec.tsx",
|
|
38
40
|
"!src/**/test-support",
|
|
39
41
|
"README.md"
|
|
40
42
|
],
|
|
41
43
|
"dependencies": {
|
|
42
|
-
"@shivaedev/effect-contract": "0.
|
|
44
|
+
"@shivaedev/effect-contract": "0.16.0",
|
|
43
45
|
"@shivaedev/effect-pg-boss": "0.19.0",
|
|
44
|
-
"@shivaedev/
|
|
46
|
+
"@shivaedev/effect-react": "0.18.1",
|
|
47
|
+
"@shivaedev/platform": "0.33.0"
|
|
45
48
|
},
|
|
46
49
|
"devDependencies": {
|
|
50
|
+
"@effect/atom-react": "4.0.5",
|
|
47
51
|
"@shivaedev/effect-test-sql": "0.9.3",
|
|
48
|
-
"@shivaedev/quality": "0.
|
|
49
|
-
"@shivaedev/test-story": "0.20.
|
|
52
|
+
"@shivaedev/quality": "0.41.1",
|
|
53
|
+
"@shivaedev/test-story": "0.20.1",
|
|
50
54
|
"@types/node": "24.19.2",
|
|
55
|
+
"@types/react": "19.3.0",
|
|
56
|
+
"@types/react-dom": "19.3.0",
|
|
51
57
|
"effect": "4.0.5",
|
|
58
|
+
"happy-dom": "21.0.3",
|
|
59
|
+
"react": "19.3.1",
|
|
60
|
+
"react-dom": "19.3.1",
|
|
52
61
|
"typescript": "7.0.2",
|
|
53
62
|
"vitest": "5.0.5"
|
|
54
63
|
},
|
|
55
64
|
"peerDependencies": {
|
|
56
|
-
"effect": "4.0.5"
|
|
65
|
+
"@effect/atom-react": "4.0.5",
|
|
66
|
+
"effect": "4.0.5",
|
|
67
|
+
"react": "19.3.1"
|
|
57
68
|
},
|
|
58
69
|
"engines": {
|
|
59
70
|
"node": ">=24"
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { DateTime } from "effect";
|
|
2
|
+
import { type AppUser, type ChangeRoleInput, UserRole } from "@shivaedev/platform/rpc/userRoles.ts";
|
|
3
|
+
import type { UsersList } from "#users/page.ts";
|
|
4
|
+
|
|
5
|
+
interface RoleControls {
|
|
6
|
+
readonly dispatch: (input: typeof ChangeRoleInput.Type) => void;
|
|
7
|
+
readonly pending: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function UserHeaders() {
|
|
11
|
+
return (
|
|
12
|
+
<tr>
|
|
13
|
+
{["Name", "Email", "Roles", "Signed up"].map((label) => (
|
|
14
|
+
<th className="whitespace-nowrap p-3" key={label} scope="col">
|
|
15
|
+
{label}
|
|
16
|
+
</th>
|
|
17
|
+
))}
|
|
18
|
+
</tr>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function RoleCheckbox({ user, role, pending, dispatch }: RoleControls & { readonly user: typeof AppUser.Type; readonly role: typeof UserRole.Type }) {
|
|
23
|
+
return (
|
|
24
|
+
<label className="mr-3 inline-flex gap-1">
|
|
25
|
+
<input
|
|
26
|
+
aria-label={`${role} for ${user.email}`}
|
|
27
|
+
checked={user.roles.includes(role)}
|
|
28
|
+
disabled={pending}
|
|
29
|
+
onChange={(event) => dispatch({ grant: event.target.checked, role, userId: user.id })}
|
|
30
|
+
type="checkbox"
|
|
31
|
+
/>
|
|
32
|
+
{role}
|
|
33
|
+
</label>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function UserRoles({
|
|
38
|
+
user,
|
|
39
|
+
canChangeRoles,
|
|
40
|
+
dispatch,
|
|
41
|
+
pending,
|
|
42
|
+
}: RoleControls & {
|
|
43
|
+
readonly user: typeof AppUser.Type;
|
|
44
|
+
readonly canChangeRoles: boolean;
|
|
45
|
+
}) {
|
|
46
|
+
return (
|
|
47
|
+
<div>
|
|
48
|
+
<p>{user.roles.join(", ") || "No roles"}</p>
|
|
49
|
+
{canChangeRoles
|
|
50
|
+
? UserRole.literals.map((role) => <RoleCheckbox dispatch={dispatch} key={role} pending={pending} role={role} user={user} />)
|
|
51
|
+
: null}
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function UserRow({
|
|
57
|
+
user,
|
|
58
|
+
...controls
|
|
59
|
+
}: RoleControls & {
|
|
60
|
+
readonly user: typeof AppUser.Type;
|
|
61
|
+
readonly canChangeRoles: boolean;
|
|
62
|
+
}) {
|
|
63
|
+
return (
|
|
64
|
+
<tr className="border-b">
|
|
65
|
+
<td className="p-3">{user.name}</td>
|
|
66
|
+
<td className="p-3">{user.email}</td>
|
|
67
|
+
<td className="p-3">
|
|
68
|
+
<UserRoles {...controls} user={user} />
|
|
69
|
+
</td>
|
|
70
|
+
<td className="whitespace-nowrap p-3">
|
|
71
|
+
<time dateTime={DateTime.formatIso(user.createdAt)}>{DateTime.formatIso(user.createdAt)}</time>
|
|
72
|
+
</td>
|
|
73
|
+
</tr>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function UserRows({ data, ...controls }: RoleControls & { readonly data: typeof UsersList.Type }) {
|
|
78
|
+
return (
|
|
79
|
+
<div className="overflow-x-auto rounded-md border">
|
|
80
|
+
<table className="w-full text-left text-sm">
|
|
81
|
+
<caption className="sr-only">App users and roles</caption>
|
|
82
|
+
<thead className="bg-muted">
|
|
83
|
+
<UserHeaders />
|
|
84
|
+
</thead>
|
|
85
|
+
<tbody>
|
|
86
|
+
{data.users.map((user) => (
|
|
87
|
+
<UserRow {...controls} canChangeRoles={data.canChangeRoles} key={user.id} user={user} />
|
|
88
|
+
))}
|
|
89
|
+
</tbody>
|
|
90
|
+
</table>
|
|
91
|
+
</div>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function UsersTable({ data, ...controls }: RoleControls & { readonly data: typeof UsersList.Type }) {
|
|
96
|
+
return (
|
|
97
|
+
<div className="space-y-4">
|
|
98
|
+
{data.canChangeRoles ? null : <p>Only owners can change roles.</p>}
|
|
99
|
+
{data.users.length === 0 ? <p>No users.</p> : <UserRows {...controls} data={data} />}
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Cause, 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 { useAction, useQuery } from "@shivaedev/effect-react/client/resultState.ts";
|
|
6
|
+
import type { ChangeRoleInput, UserListInput } from "@shivaedev/platform/rpc/userRoles.ts";
|
|
7
|
+
import type { UsersList } from "#users/page.ts";
|
|
8
|
+
import { UsersTable } from "./UsersTable.tsx";
|
|
9
|
+
|
|
10
|
+
export interface UsersViewProps {
|
|
11
|
+
readonly changeRole: Atom.AtomResultFn<typeof ChangeRoleInput.Type, void, unknown>;
|
|
12
|
+
readonly list: (input: typeof UserListInput.Type) => Atom.Atom<AsyncResult.AsyncResult<typeof UsersList.Type, unknown>>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function failure(cause: Cause.Cause<unknown>): string {
|
|
16
|
+
const error = Option.getOrUndefined(Cause.findErrorOption(cause));
|
|
17
|
+
if (Predicate.isTagged(error, "LastOwner")) {
|
|
18
|
+
return "The last owner cannot be demoted. Grant owner to another user first.";
|
|
19
|
+
}
|
|
20
|
+
if (Predicate.isTagged(error, "Forbidden")) {
|
|
21
|
+
return "Owner role required to change roles.";
|
|
22
|
+
}
|
|
23
|
+
return "Could not change the role. Try again.";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function UsersView({ list, changeRole }: UsersViewProps) {
|
|
27
|
+
const [cursors, setCursors] = useState<readonly string[]>([]);
|
|
28
|
+
const cursor = cursors.at(-1);
|
|
29
|
+
const state = useQuery(list({ ...(cursor === undefined ? {} : { cursor }), limit: 20 }));
|
|
30
|
+
const action = useAction(changeRole);
|
|
31
|
+
const data = Option.getOrUndefined(state.data);
|
|
32
|
+
return createElement(
|
|
33
|
+
"section",
|
|
34
|
+
{ "aria-label": "App users", className: "space-y-4" },
|
|
35
|
+
createElement(
|
|
36
|
+
"button",
|
|
37
|
+
{ className: "rounded-md border px-3 py-2 disabled:opacity-50", disabled: state.pending, onClick: state.refresh, type: "button" },
|
|
38
|
+
"Refresh users",
|
|
39
|
+
),
|
|
40
|
+
state.pending ? createElement("p", { role: "status" }, "Loading users…") : null,
|
|
41
|
+
Option.isSome(state.cause) ? createElement("p", { role: "alert" }, "Could not load users. Try refreshing.") : null,
|
|
42
|
+
Option.isSome(action.cause) ? createElement("p", { role: "alert" }, failure(action.cause.value)) : null,
|
|
43
|
+
data === undefined ? null : createElement(UsersTable, { data, dispatch: action.dispatch, pending: action.pending }),
|
|
44
|
+
data === undefined
|
|
45
|
+
? null
|
|
46
|
+
: createElement(
|
|
47
|
+
"nav",
|
|
48
|
+
{ "aria-label": "User pages", className: "flex gap-4" },
|
|
49
|
+
createElement(
|
|
50
|
+
"button",
|
|
51
|
+
{
|
|
52
|
+
className: "rounded-md border px-3 py-2 disabled:opacity-50",
|
|
53
|
+
disabled: cursors.length === 0 || state.pending,
|
|
54
|
+
onClick: () => setCursors(cursors.slice(0, -1)),
|
|
55
|
+
type: "button",
|
|
56
|
+
},
|
|
57
|
+
"Previous users",
|
|
58
|
+
),
|
|
59
|
+
createElement(
|
|
60
|
+
"button",
|
|
61
|
+
{
|
|
62
|
+
className: "rounded-md border px-3 py-2 disabled:opacity-50",
|
|
63
|
+
disabled: Option.isNone(data.next) || state.pending,
|
|
64
|
+
onClick: () => Option.map(data.next, (next) => setCursors([...cursors, next])),
|
|
65
|
+
type: "button",
|
|
66
|
+
},
|
|
67
|
+
"Next users",
|
|
68
|
+
),
|
|
69
|
+
),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { hasRole } from "@shivaedev/platform/rpc/hasRole.ts";
|
|
3
|
+
import { SessionUser } from "@shivaedev/platform/rpc/identity.ts";
|
|
4
|
+
import { changeUserRole, listUsers } from "@shivaedev/platform/server/better-auth/users.ts";
|
|
5
|
+
import { UsersPage } from "#users/page.ts";
|
|
6
|
+
|
|
7
|
+
export const usersHandlers = UsersPage.contract.application.toLayer({
|
|
8
|
+
"admin.users.changeRole": changeUserRole,
|
|
9
|
+
"admin.users.list": (input) =>
|
|
10
|
+
Effect.gen(function* () {
|
|
11
|
+
const user = yield* SessionUser;
|
|
12
|
+
return { ...(yield* listUsers(input)), canChangeRoles: hasRole(user, "owner") };
|
|
13
|
+
}),
|
|
14
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { contract } from "@shivaedev/effect-contract/contract.ts";
|
|
3
|
+
import { AuthUnavailable, Forbidden, NotFound } from "@shivaedev/effect-contract/errors/taxonomy.ts";
|
|
4
|
+
import { collection } from "@shivaedev/effect-contract/keys.ts";
|
|
5
|
+
import { command, query } from "@shivaedev/effect-contract/operation.ts";
|
|
6
|
+
import { ChangeRoleInput, LastOwner, UserList, UserListInput } from "@shivaedev/platform/rpc/userRoles.ts";
|
|
7
|
+
import { adminPage } from "#page.ts";
|
|
8
|
+
|
|
9
|
+
const users = collection("admin.users", Schema.String);
|
|
10
|
+
|
|
11
|
+
export const UsersList = Schema.Struct({ ...UserList.fields, canChangeRoles: Schema.Boolean });
|
|
12
|
+
export const UsersPage = adminPage({
|
|
13
|
+
contract: contract("admin.users", {
|
|
14
|
+
commands: [
|
|
15
|
+
command("changeRole", {
|
|
16
|
+
invalidates: () => [users.list],
|
|
17
|
+
payload: ChangeRoleInput.fields,
|
|
18
|
+
rejections: { AuthUnavailable, Forbidden, LastOwner, NotFound },
|
|
19
|
+
}),
|
|
20
|
+
],
|
|
21
|
+
queries: [
|
|
22
|
+
query("list", {
|
|
23
|
+
payload: UserListInput.fields,
|
|
24
|
+
reads: () => [users.list],
|
|
25
|
+
rejections: { AuthUnavailable },
|
|
26
|
+
success: UsersList,
|
|
27
|
+
}),
|
|
28
|
+
],
|
|
29
|
+
}),
|
|
30
|
+
id: "users",
|
|
31
|
+
route: { path: "/admin/users", title: "Users" },
|
|
32
|
+
});
|