@shivaedev/admin 0.6.0 → 0.8.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.
Files changed (75) hide show
  1. package/README.md +23 -12
  2. package/dist/client/UsersTable.d.ts +5 -4
  3. package/dist/client/UsersTable.d.ts.map +1 -1
  4. package/dist/client/UsersTable.js +13 -14
  5. package/dist/client/UsersTable.js.map +1 -1
  6. package/dist/client/UsersView.d.ts +4 -3
  7. package/dist/client/UsersView.d.ts.map +1 -1
  8. package/dist/client/UsersView.js +5 -5
  9. package/dist/client/UsersView.js.map +1 -1
  10. package/dist/jobs/entry.d.ts +12 -0
  11. package/dist/jobs/entry.d.ts.map +1 -0
  12. package/dist/jobs/entry.js +5 -0
  13. package/dist/jobs/entry.js.map +1 -0
  14. package/dist/jobs/keys.d.ts +5 -5
  15. package/dist/jobs/keys.js +1 -1
  16. package/dist/jobs/keys.js.map +1 -1
  17. package/dist/jobs/page.d.ts +36 -29
  18. package/dist/jobs/page.d.ts.map +1 -1
  19. package/dist/jobs/page.js +19 -4
  20. package/dist/jobs/page.js.map +1 -1
  21. package/dist/jobs/retryPage.d.ts +51 -44
  22. package/dist/jobs/retryPage.d.ts.map +1 -1
  23. package/dist/jobs/retryPage.js +2 -0
  24. package/dist/jobs/retryPage.js.map +1 -1
  25. package/dist/jobs/schemas.d.ts +2 -2
  26. package/dist/jobs/schemas.d.ts.map +1 -1
  27. package/dist/jobs/schemas.js.map +1 -1
  28. package/dist/page.d.ts +9 -5
  29. package/dist/page.d.ts.map +1 -1
  30. package/dist/page.js +6 -2
  31. package/dist/page.js.map +1 -1
  32. package/dist/permissions.d.ts +26 -5
  33. package/dist/permissions.d.ts.map +1 -1
  34. package/dist/permissions.js +6 -2
  35. package/dist/permissions.js.map +1 -1
  36. package/dist/server/jobsHandlers.d.ts +8 -7
  37. package/dist/server/jobsHandlers.d.ts.map +1 -1
  38. package/dist/server/jobsHandlers.js +2 -1
  39. package/dist/server/jobsHandlers.js.map +1 -1
  40. package/dist/server/jobsHandlersWithRetry.d.ts +2 -2
  41. package/dist/server/jobsHandlersWithRetry.d.ts.map +1 -1
  42. package/dist/server/jobsHandlersWithRetry.js +5 -2
  43. package/dist/server/jobsHandlersWithRetry.js.map +1 -1
  44. package/dist/server/users.d.ts +32 -10
  45. package/dist/server/users.d.ts.map +1 -1
  46. package/dist/server/users.js +17 -15
  47. package/dist/server/users.js.map +1 -1
  48. package/dist/server/usersHandlers.d.ts +3 -1
  49. package/dist/server/usersHandlers.d.ts.map +1 -1
  50. package/dist/server/usersHandlers.js +10 -9
  51. package/dist/server/usersHandlers.js.map +1 -1
  52. package/dist/users/page.d.ts +22 -15
  53. package/dist/users/page.d.ts.map +1 -1
  54. package/dist/users/page.js +31 -24
  55. package/dist/users/page.js.map +1 -1
  56. package/dist/users/roles.d.ts +8 -19
  57. package/dist/users/roles.d.ts.map +1 -1
  58. package/dist/users/roles.js +2 -6
  59. package/dist/users/roles.js.map +1 -1
  60. package/package.json +12 -11
  61. package/src/client/UsersTable.tsx +48 -51
  62. package/src/client/UsersView.ts +8 -7
  63. package/src/jobs/entry.ts +15 -0
  64. package/src/jobs/keys.ts +1 -1
  65. package/src/jobs/page.ts +21 -6
  66. package/src/jobs/retryPage.ts +5 -2
  67. package/src/jobs/schemas.ts +2 -2
  68. package/src/page.ts +13 -5
  69. package/src/permissions.ts +5 -2
  70. package/src/server/jobsHandlers.ts +8 -7
  71. package/src/server/jobsHandlersWithRetry.ts +8 -5
  72. package/src/server/users.ts +24 -15
  73. package/src/server/usersHandlers.ts +16 -10
  74. package/src/users/page.ts +32 -24
  75. package/src/users/roles.ts +6 -9
package/README.md CHANGED
@@ -7,13 +7,14 @@ Admin tooling starts with an explicit list of pages and the operations each page
7
7
  ```ts
8
8
  const Jobs = adminPage({
9
9
  id: "jobs",
10
+ permission: JobsPermission,
10
11
  route: { path: "/admin/jobs", title: "Jobs" },
11
12
  contract: contract("admin.jobs", { queries: [Failed] }),
12
13
  });
13
14
  const Admin = adminRegistry(Jobs);
14
15
  ```
15
16
 
16
- The page exposes `admin.jobs.failed` and the generated `admin.jobs.$changes` subscription. Both require `AdminPermission`, which checks the `OpenAdmin` permission (`admin.open`). A query-only contract has no command. The application grants this permission to its chosen roles.
17
+ The page exposes `admin.jobs.failed` and the generated `admin.jobs.$changes` subscription. Both require `JobsPermission`, which checks `ReadJobs` (`jobs.read`). A query-only contract has no command. The application grants this permission to its chosen roles.
17
18
 
18
19
  ## Use native contracts and Layers
19
20
 
@@ -21,6 +22,7 @@ Install `@shivaedev/admin` with `effect`, `react` and `@effect/atom-react`. Decl
21
22
 
22
23
  ```ts
23
24
  import { Schema } from "effect";
25
+ import { JobsPermission } from "@shivaedev/admin/permissions.ts";
24
26
  import { adminPage } from "@shivaedev/admin/page.ts";
25
27
  import { adminRegistry } from "@shivaedev/admin/registry.ts";
26
28
  import { contract } from "@shivaedev/contract/contract.ts";
@@ -32,6 +34,7 @@ const Failed = query("failed", {
32
34
  });
33
35
  const Jobs = adminPage({
34
36
  id: "jobs",
37
+ permission: JobsPermission,
35
38
  route: { path: "/admin/jobs", title: "Jobs" },
36
39
  contract: contract("admin.jobs", { queries: [Failed] }),
37
40
  });
@@ -45,7 +48,7 @@ Register server handler Layers by page id:
45
48
  ```ts
46
49
  import { Effect, Layer } from "effect";
47
50
  import { registerAdmin } from "@shivaedev/admin/server/registerAdmin.ts";
48
- import { AdminPermission, OpenAdmin } from "@shivaedev/admin/permissions.ts";
51
+ import { JobsPermission, ReadJobs } from "@shivaedev/admin/permissions.ts";
49
52
  import { permissionLayer } from "@shivaedev/identity/server/permissions.ts";
50
53
 
51
54
  const registration = registerAdmin(Admin, {
@@ -54,11 +57,11 @@ const registration = registerAdmin(Admin, {
54
57
  }),
55
58
  });
56
59
  const handlers = registration.handlers.pipe(
57
- Layer.provideMerge(permissionLayer(AdminPermission, sessions)),
60
+ Layer.provideMerge(permissionLayer(JobsPermission, sessions)),
58
61
  );
59
62
  ```
60
63
 
61
- Declare application roles with `@shivaedev/access`, grant `OpenAdmin` explicitly, and supply that role set through the session or auth configuration of `@shivaedev/identity`.
64
+ Declare application roles with `@shivaedev/access`, grant the relevant domain permissions explicitly, and supply that role set through the session or auth configuration of `@shivaedev/identity`.
62
65
 
63
66
  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.
64
67
 
@@ -91,6 +94,8 @@ const registration = registerAdmin(Admin, {
91
94
 
92
95
  The queries are `admin.jobs.health`, `admin.jobs.counts`, `admin.jobs.failed`, `admin.jobs.deadLettered` and `admin.jobs.job`. Counts take `{ queue }`; listings take `{ queue, limit, cursor? }` and return `{ jobs, next }`, where `next` is an `Option<string>`. Job lookup takes `{ queue, id }` and returns `Option<Job>`. Each job carries its queue, decoded payload, state, attempt and retry counts, output and timestamps. Dead-letter listings also carry `sourceId` and `sourceOutput`. Timestamps use UTC `DateTime` values; the RPC encodes timestamps as strings and Options as nullable values. The queue's original codec encodes and decodes its payload across RPC, preserving its service requirements.
93
96
 
97
+ Schedule definitions from `defineSchedule` can be passed beside queues. A browser declaration can share just `{ _tag: "ScheduleDefinition", name }`; scheduled runs use a null payload schema for failed and dead-letter listings and job lookup. Calling `jobsPage()` with no arguments registers the same read-only page and serves health with no jobs and zero totals.
98
+
94
99
  Health filters the runtime's monitor snapshot to the page's queues and recomputes totals from those queues. It has the same refresh timing as jobs health. Unregistered names, including dead-letter queue names passed directly, fail with `JobsQueueUnregistered`. Stored payload decoding failures become `JobsPayloadInvalid`; jobs operation failures become `JobsUnavailable`, carrying the operation name. These declared failures do not expose the original database error.
95
100
 
96
101
  The default `jobsPage` declares no commands, and its bound client has no retry operation. Handler registration performs no jobs read, and a failed jobs request leaves other pages available. PostgreSQL stories exercise these queries through serialized `/rpc` requests, including pagination, transformed payloads, missing jobs, queue restrictions and permission enforcement. The application supplies the Jobs view and mounts the registration on its existing RPC host.
@@ -110,15 +115,17 @@ const registration = registerAdmin(Admin, {
110
115
  });
111
116
  ```
112
117
 
113
- This variant adds only `admin.jobs.retry`, taking `{ queue, id }` and returning void. It requires `OpenAdmin`, through the same page middleware. The handler uses the jobs package'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.
118
+ This variant adds only `admin.jobs.retry`, taking `{ queue, id }` and returning void. It requires `ReadJobs`, through the same page middleware. The handler uses the jobs package'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.
114
119
 
115
120
  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.
116
121
 
117
122
  ## Built-in Users page
118
123
 
119
- `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.
124
+ Call `usersPage(AppAccess)` from `@shivaedev/admin/users/page.ts` with the application's code-defined role set. Add the returned page to the same registry as Jobs and register `users: usersHandlers(UsersPage, AppAccess)` from `@shivaedev/admin/server/usersHandlers.ts`. The handlers use the application's existing Effect SQL client against Better Auth's default PostgreSQL `user` table and its `role` column. Custom table or column names are not supported.
125
+
126
+ Each user stores one role string accepted by `AppAccess.Role`. Each role declares an explicit permission list in application code. The Users area assigns roles; it does not edit their grants.
120
127
 
121
- 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:
128
+ Bind the page's contract to the registry's native AtomRpc client, then mount the view in the application's admin shell. Tailwind applications include `@source "../../node_modules/@shivaedev/admin/src/client";` in `src/client/entry.css`:
122
129
 
123
130
  ```tsx
124
131
  import { UsersView } from "@shivaedev/admin/client/UsersView.ts";
@@ -126,13 +133,17 @@ import { UsersView } from "@shivaedev/admin/client/UsersView.ts";
126
133
  const users = bind(UsersPage.contract, Client);
127
134
  const changeRole = Client.runtime.fn(users.changeRole.run);
128
135
 
129
- <UsersView list={users.list.query} changeRole={changeRole} />;
136
+ <UsersView roles={AppAccess.Role.literals} list={users.list.query} changeRole={changeRole} />;
130
137
  ```
131
138
 
132
- `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 `OpenAdmin`. Callers granted `ChangeUserRoles` (`users.roles.change`) from `@shivaedev/admin/users/roles.ts` see role controls. `admin.users.changeRole` takes `{ userId, role, grant }` for the `user`, `admin` and `owner` roles that module declares, with the browser-safe user schemas and the typed `LastOwner` failure. It returns typed `Forbidden` without that permission, `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.
139
+ `admin.users.list` takes `{ limit, cursor? }` (1–100 users) and returns `{ users, next, canChangeRoles }` ordered by user id. Each user has id, name, email, role and a UTC sign-up time. The page's operations and generated subscription require `ReadUsers` (`users.read`), enforced by `UsersPermission`. Supply `permissionLayer(UsersPermission, sessions)` alongside the application's other handler Layers.
140
+
141
+ `admin.users.changeRole` takes `{ userId, role }`; its role Schema is the application's declared role union. The handler also requires `AssignRoles` (`roles.assign`). The view shows a role select only to callers with that permission. Role writes serialize in a transaction and return `LastRoleAssigner` if replacing the final holder's role would remove `roles.assign`, regardless of the role's name. A missing user returns `NotFound`. Changes invalidate the list after commit and emit an Effect log with actor id, target id, role and timestamp.
142
+
143
+ Applications can call `listUsers(AppAccess, input)` and `changeUserRole(AppAccess, input)` from `@shivaedev/admin/server/users.ts` on the server. These enforce their respective domain permissions using `SessionUser`.
133
144
 
134
- The handlers call `listUsers({ limit, cursor? })` and `changeUserRole({ userId, role, grant })` from `@shivaedev/admin/server/users.ts`, which an application can also call from its own server code. Role writes require an owner `SessionUser` and serialize role changes in a transaction.
145
+ Keep Better Auth cookie caching disabled so requests see current permissions. Route role writes through this operation to retain the final-assigner 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.
135
146
 
136
- Keep Better Auth cookie caching disabled so requests see current roles. Applications must route role writes through this operation to retain its permission 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.
147
+ ## Client permission routes
137
148
 
138
- 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`.
149
+ `adminPage` requires a permission middleware, including for custom pages. It applies that middleware to the whole contract and exposes its permission as `page.route.permission`. Set the React route's `staticData.permission` to that value. Use `permissionGuard` from `@shivaedev/react/permissionGuard.ts` in protected routes' `beforeLoad` and wrap the router in `PermissionBoundary` from `@shivaedev/react/client/permissionBoundary.ts` with the session and one application fallback. The starter uses this path for Users, Jobs and note statistics.
@@ -1,10 +1,11 @@
1
1
  import type { UsersList } from "#users/page.ts";
2
- import { type ChangeRoleInput } from "#users/roles.ts";
3
- interface RoleControls {
4
- readonly dispatch: (input: typeof ChangeRoleInput.Type) => void;
2
+ import type { ChangeRoleInput } from "#users/roles.ts";
3
+ interface RoleControls<TRole extends string> {
4
+ readonly dispatch: (input: ChangeRoleInput<TRole>) => void;
5
5
  readonly pending: boolean;
6
+ readonly roles: readonly TRole[];
6
7
  }
7
- export declare function UsersTable({ data, ...controls }: RoleControls & {
8
+ export declare function UsersTable<TRole extends string>({ data, ...controls }: RoleControls<TRole> & {
8
9
  readonly data: typeof UsersList.Type;
9
10
  }): import("react").JSX.Element;
10
11
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"UsersTable.d.ts","sourceRoot":"","sources":["../../src/client/UsersTable.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAgB,KAAK,eAAe,EAAY,MAAM,iBAAiB,CAAC;AAE/E,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"}
1
+ {"version":3,"file":"UsersTable.d.ts","sourceRoot":"","sources":["../../src/client/UsersTable.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAW,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEhE,UAAU,YAAY,CAAC,KAAK,SAAS,MAAM;IAC1C,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;IAC3D,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,SAAS,KAAK,EAAE,CAAC;CACjC;AAuED,wBAAgB,UAAU,CAAC,KAAK,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,GAAG,QAAQ,EAAE,EAAE,YAAY,CAAC,KAAK,CAAC,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,SAAS,CAAC,IAAI,CAAA;CAAE,+BAOrI"}
@@ -1,25 +1,24 @@
1
1
  import { createElement as _createElement } from "react";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { DateTime } from "effect";
4
- import { UserRole } from "#users/roles.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] }));
4
+ function UserRole({ user, canChangeRoles, roles, pending, dispatch, }) {
5
+ return canChangeRoles ? (_jsx("select", { "aria-label": `Role for ${user.email}`, className: "rounded-md border bg-background p-2", disabled: pending, onChange: (event) => {
6
+ const role = roles.find((candidate) => candidate === event.target.value);
7
+ if (role !== undefined) {
8
+ dispatch({ role, userId: user.id });
9
+ }
10
+ }, value: user.role, children: roles.map((role) => (_jsx("option", { value: role, children: role }, role))) })) : (user.role);
15
11
  }
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) }) })] }));
12
+ function UserRow({ user, canChangeRoles, ...controls }) {
13
+ 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(UserRole, { ...controls, canChangeRoles: canChangeRoles, user: user }) }), _jsx("td", { className: "whitespace-nowrap p-3", children: _jsx("time", { dateTime: DateTime.formatIso(user.createdAt), children: DateTime.formatIso(user.createdAt) }) })] }));
18
14
  }
19
15
  function UserRows({ data, ...controls }) {
20
16
  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
17
  }
22
18
  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 })] }));
19
+ return (_jsxs("div", { className: "space-y-4", children: [data.canChangeRoles ? null : _jsx("p", { children: "Permission to assign roles is required to change roles." }), data.users.length === 0 ? _jsx("p", { children: "No users." }) : _jsx(UserRows, { ...controls, data: data })] }));
20
+ }
21
+ function UserHeaders() {
22
+ return (_jsx("tr", { children: ["Name", "Email", "Role", "Signed up"].map((label) => (_jsx("th", { className: "whitespace-nowrap p-3", scope: "col", children: label }, label))) }));
24
23
  }
25
24
  //# sourceMappingURL=UsersTable.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"UsersTable.js","sourceRoot":"","sources":["../../src/client/UsersTable.tsx"],"names":[],"mappings":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AAM,KAAK,CAAC,CAAC,CAAC,CAAC,oCAAgB,CAAC,CAAC,CAAC,KAAC,QAAQ,OAAK,QAAQ,EAAE,IAAI,EAAE,IAAI,GAAI,IAC/E,CACN,CAAC;AACH,CAAC;AAED,SAAS,WAAW;IACnB,OAAO,CACN,uBACE,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CACtD,aAAI,SAAS,EAAC,uBAAuB,EAAa,KAAK,EAAC,KAAK,YAC3D,KAAK,IADoC,KAAK,CAE3C,CACL,CAAC,GACE,CACL,CAAC;AACH,CAAC"}
@@ -2,11 +2,12 @@ import type * as AsyncResult from "effect/reactivity/AsyncResult";
2
2
  import type * as Atom from "effect/reactivity/Atom";
3
3
  import type { UsersList } from "#users/page.ts";
4
4
  import type { ChangeRoleInput, UserListInput } from "#users/roles.ts";
5
- export interface UsersViewProps {
6
- readonly changeRole: Atom.AtomResultFn<typeof ChangeRoleInput.Type, void, unknown>;
5
+ export interface UsersViewProps<TRole extends string> {
6
+ readonly changeRole: Atom.AtomResultFn<ChangeRoleInput<TRole>, void, unknown>;
7
7
  readonly list: (input: typeof UserListInput.Type) => Atom.Atom<AsyncResult.AsyncResult<typeof UsersList.Type, unknown>>;
8
+ readonly roles: readonly TRole[];
8
9
  }
9
- export declare function UsersView({ list, changeRole }: UsersViewProps): import("react").DetailedReactHTMLElement<{
10
+ export declare function UsersView<TRole extends string>({ list, changeRole, roles }: UsersViewProps<TRole>): import("react").DetailedReactHTMLElement<{
10
11
  "aria-label": string;
11
12
  className: string;
12
13
  }, HTMLElement>;
@@ -1 +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,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ACjC;AAaD,wBAAgB,SAAS,CAAC,KAAK,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,cAAc,CAAC,KAAK,CAAC;;;gBA6CjG"}
@@ -4,21 +4,21 @@ import { useAction, useQuery } from "@shivaedev/react/client/resultState.ts";
4
4
  import { UsersTable } from "./UsersTable.js";
5
5
  function failure(cause) {
6
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.";
7
+ if (Predicate.isTagged(error, "LastRoleAssigner")) {
8
+ return "The last user who can assign roles cannot be removed. Assign another user permission to change roles first.";
9
9
  }
10
10
  if (Predicate.isTagged(error, "Forbidden")) {
11
- return "Owner role required to change roles.";
11
+ return "Permission required to assign roles.";
12
12
  }
13
13
  return "Could not change the role. Try again.";
14
14
  }
15
- export function UsersView({ list, changeRole }) {
15
+ export function UsersView({ list, changeRole, roles }) {
16
16
  const [cursors, setCursors] = useState([]);
17
17
  const cursor = cursors.at(-1);
18
18
  const state = useQuery(list({ ...(cursor === undefined ? {} : { cursor }), limit: 20 }));
19
19
  const action = useAction(changeRole);
20
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
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, roles }), data === undefined
22
22
  ? null
23
23
  : createElement("nav", { "aria-label": "User pages", className: "flex gap-4" }, createElement("button", {
24
24
  className: "rounded-md border px-3 py-2 disabled:opacity-50",
@@ -1 +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,wCAAwC,CAAC;AAG7E,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,sCAAsC,CAAC;IAC/C,CAAC;IACD,OAAO,uCAAuC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,EAAE,IAAI,EAAE,UAAU,EAAkB;IAC7D,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAoB,EAAE,CAAC,CAAC;IAC9D,MAAM,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC,C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AQ,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,OAAO;YACnD,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;YAC9E,IAAI,EAAE,QAAQ;SACd,EACD,YAAY,CACZ,CACD,CACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { Schema } from "effect";
2
+ import type { JobsQueue } from "./schemas.ts";
3
+ export type JobsEntry = JobsQueue | {
4
+ readonly _tag: "ScheduleDefinition";
5
+ readonly name: string;
6
+ };
7
+ export type JobsPayload<TEntry extends JobsEntry> = [TEntry] extends [never] ? typeof Schema.Never : TEntry extends JobsQueue ? TEntry["schema"] : typeof Schema.Null;
8
+ export declare function jobsQueue<TEntry extends JobsEntry>(entry: TEntry): {
9
+ readonly name: string;
10
+ readonly schema: JobsPayload<TEntry>;
11
+ };
12
+ //# sourceMappingURL=entry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../../src/jobs/entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnG,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,SAAS,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,GACzE,OAAO,MAAM,CAAC,KAAK,GACnB,MAAM,SAAS,SAAS,GACvB,MAAM,CAAC,QAAQ,CAAC,GAChB,OAAO,MAAM,CAAC,IAAI,CAAC;AAEvB,wBAAgB,SAAS,CAAC,MAAM,SAAS,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { Schema } from "effect";
2
+ export function jobsQueue(entry) {
3
+ return { name: entry.name, schema: "schema" in entry ? entry.schema : Schema.Null };
4
+ }
5
+ //# sourceMappingURL=entry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry.js","sourceRoot":"","sources":["../../src/jobs/entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAYhC,MAAM,UAAU,SAAS,CAAC,KAAgB;IACzC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;AACrF,CAAC"}
@@ -1,8 +1,8 @@
1
1
  export declare const jobsKeys: {
2
- counts: import("@shivaedev/contract/keys.ts").Collection<"admin.jobs.counts", string>;
3
- deadLettered: import("@shivaedev/contract/keys.ts").Collection<"admin.jobs.deadLettered", string>;
4
- failed: import("@shivaedev/contract/keys.ts").Collection<"admin.jobs.failed", string>;
5
- health: import("@shivaedev/contract/keys.ts").Collection<"admin.jobs.health", string>;
6
- job: (queue: string) => import("@shivaedev/contract/keys.ts").Collection<`admin.jobs.job.${string}`, string>;
2
+ counts: import("@shivaedev/changes/keys.ts").Collection<"admin.jobs.counts", string, Record<never, never>>;
3
+ deadLettered: import("@shivaedev/changes/keys.ts").Collection<"admin.jobs.deadLettered", string, Record<never, never>>;
4
+ failed: import("@shivaedev/changes/keys.ts").Collection<"admin.jobs.failed", string, Record<never, never>>;
5
+ health: import("@shivaedev/changes/keys.ts").Collection<"admin.jobs.health", string, Record<never, never>>;
6
+ job: (queue: string) => import("@shivaedev/changes/keys.ts").Collection<`admin.jobs.job.${string}`, string, Record<never, never>>;
7
7
  };
8
8
  //# sourceMappingURL=keys.d.ts.map
package/dist/jobs/keys.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Schema } from "effect";
2
- import { collection } from "@shivaedev/contract/keys.ts";
2
+ import { collection } from "@shivaedev/changes/keys.ts";
3
3
  export const jobsKeys = {
4
4
  counts: collection("admin.jobs.counts", Schema.String),
5
5
  deadLettered: collection("admin.jobs.deadLettered", Schema.String),
@@ -1 +1 @@
1
- {"version":3,"file":"keys.js","sourceRoot":"","sources":["../../src/jobs/keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEzD,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB,MAAM,EAAE,UAAU,CAAC,mBAAmB,EAAE,MAAM,CAAC,MAAM,CAAC;IACtD,YAAY,EAAE,UAAU,CAAC,yBAAyB,EAAE,MAAM,CAAC,MAAM,CAAC;IAClE,MAAM,EAAE,UAAU,CAAC,mBAAmB,EAAE,MAAM,CAAC,MAAM,CAAC;IACtD,MAAM,EAAE,UAAU,CAAC,mBAAmB,EAAE,MAAM,CAAC,MAAM,CAAC;IACtD,GAAG,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,UAAU,CAAC,kBAAkB,KAAK,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC;CAC5E,CAAC"}
1
+ {"version":3,"file":"keys.js","sourceRoot":"","sources":["../../src/jobs/keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAExD,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB,MAAM,EAAE,UAAU,CAAC,mBAAmB,EAAE,MAAM,CAAC,MAAM,CAAC;IACtD,YAAY,EAAE,UAAU,CAAC,yBAAyB,EAAE,MAAM,CAAC,MAAM,CAAC;IAClE,MAAM,EAAE,UAAU,CAAC,mBAAmB,EAAE,MAAM,CAAC,MAAM,CAAC;IACtD,MAAM,EAAE,UAAU,CAAC,mBAAmB,EAAE,MAAM,CAAC,MAAM,CAAC;IACtD,GAAG,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,UAAU,CAAC,kBAAkB,KAAK,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC;CAC5E,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import { Schema } from "effect";
2
- import { type JobsQueue } from "./schemas.ts";
3
- export declare function jobsPage<const TQueues extends readonly JobsQueue[]>(...queues: TQueues): import("#page.ts").AdminPage & {
2
+ import { JobsPermission } from "#permissions.ts";
3
+ import { type JobsEntry, type JobsPayload } from "./entry.ts";
4
+ export declare function jobsPage<const TQueues extends readonly JobsEntry[]>(...queues: TQueues): import("#page.ts").AdminPage & {
4
5
  readonly id: "jobs";
5
6
  readonly contract: import("@shivaedev/contract/contract.ts").Contract<"admin.jobs", readonly [NoInfer<import("@shivaedev/contract/operation.ts").Query<"health", Schema.Void, Schema.Struct<{
6
7
  readonly activeTotal: Schema.Number;
@@ -46,7 +47,7 @@ export declare function jobsPage<const TQueues extends readonly JobsQueue[]>(...
46
47
  readonly retryLimit: Schema.Number;
47
48
  readonly startedOn: Schema.OptionFromNullOr<Schema.DateTimeUtcFromString>;
48
49
  readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
49
- readonly data: TQueues[number]["schema"];
50
+ readonly data: JobsPayload<TQueues[number]>;
50
51
  readonly queue: Schema.Literal<string>;
51
52
  }>[]>>;
52
53
  readonly next: Schema.OptionFromNullOr<Schema.String>;
@@ -69,7 +70,7 @@ export declare function jobsPage<const TQueues extends readonly JobsQueue[]>(...
69
70
  readonly retryLimit: Schema.Number;
70
71
  readonly startedOn: Schema.OptionFromNullOr<Schema.DateTimeUtcFromString>;
71
72
  readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
72
- readonly data: TQueues[number]["schema"];
73
+ readonly data: JobsPayload<TQueues[number]>;
73
74
  readonly queue: Schema.Literal<string>;
74
75
  readonly sourceId: Schema.OptionFromNullOr<Schema.String>;
75
76
  readonly sourceOutput: Schema.Unknown;
@@ -92,7 +93,7 @@ export declare function jobsPage<const TQueues extends readonly JobsQueue[]>(...
92
93
  readonly retryLimit: Schema.Number;
93
94
  readonly startedOn: Schema.OptionFromNullOr<Schema.DateTimeUtcFromString>;
94
95
  readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
95
- readonly data: TQueues[number]["schema"];
96
+ readonly data: JobsPayload<TQueues[number]>;
96
97
  readonly queue: Schema.Literal<string>;
97
98
  }>[]>>, {
98
99
  JobsPayloadInvalid: typeof import("./schemas.ts").JobsPayloadInvalid;
@@ -131,6 +132,11 @@ export declare function jobsPage<const TQueues extends readonly JobsQueue[]>(...
131
132
  }>, import("effect/rpc/RpcSchema").Stream<Schema.Union<readonly [Schema.Struct<{
132
133
  readonly _tag: Schema.Literal<"Changed">;
133
134
  readonly keys: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
135
+ readonly _tag: Schema.Literal<"Bucket">;
136
+ readonly collection: Schema.String;
137
+ readonly field: Schema.String;
138
+ readonly value: Schema.Union<readonly [Schema.String, Schema.Number]>;
139
+ }>, Schema.Struct<{
134
140
  readonly _tag: Schema.Literal<"List">;
135
141
  readonly collection: Schema.String;
136
142
  }>, Schema.Struct<{
@@ -138,16 +144,17 @@ export declare function jobsPage<const TQueues extends readonly JobsQueue[]>(...
138
144
  readonly collection: Schema.String;
139
145
  readonly id: Schema.Union<readonly [Schema.String, Schema.Number]>;
140
146
  }>]>>;
147
+ readonly queryIndexes: Schema.optional<Schema.$Array<Schema.Number>>;
141
148
  }>, Schema.Struct<{
142
149
  readonly _tag: Schema.Literal<"Resync">;
143
- }>]>, Schema.Never>, Schema.Never, typeof import("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.counts", Schema.Struct<{
150
+ }>]>, Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>>, Schema.Never, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.counts", Schema.Struct<{
144
151
  queue: Schema.String;
145
152
  }>, Schema.Struct<{
146
153
  readonly activeCount: Schema.Number;
147
154
  readonly failedCount: Schema.Number;
148
155
  readonly queuedCount: Schema.Number;
149
156
  readonly totalCount: Schema.Number;
150
- }>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.deadLettered", Schema.Struct<{
157
+ }>, Schema.Union<readonly [Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.failed", Schema.Struct<{
151
158
  cursor: Schema.optionalKey<Schema.String>;
152
159
  limit: Schema.Number;
153
160
  queue: Schema.String;
@@ -162,13 +169,11 @@ export declare function jobsPage<const TQueues extends readonly JobsQueue[]>(...
162
169
  readonly retryLimit: Schema.Number;
163
170
  readonly startedOn: Schema.OptionFromNullOr<Schema.DateTimeUtcFromString>;
164
171
  readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
165
- readonly data: TQueues[number]["schema"];
172
+ readonly data: JobsPayload<TQueues[number]>;
166
173
  readonly queue: Schema.Literal<string>;
167
- readonly sourceId: Schema.OptionFromNullOr<Schema.String>;
168
- readonly sourceOutput: Schema.Unknown;
169
174
  }>[]>>;
170
175
  readonly next: Schema.OptionFromNullOr<Schema.String>;
171
- }>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.failed", Schema.Struct<{
176
+ }>, Schema.Union<readonly [Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.deadLettered", Schema.Struct<{
172
177
  cursor: Schema.optionalKey<Schema.String>;
173
178
  limit: Schema.Number;
174
179
  queue: Schema.String;
@@ -183,25 +188,13 @@ export declare function jobsPage<const TQueues extends readonly JobsQueue[]>(...
183
188
  readonly retryLimit: Schema.Number;
184
189
  readonly startedOn: Schema.OptionFromNullOr<Schema.DateTimeUtcFromString>;
185
190
  readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
186
- readonly data: TQueues[number]["schema"];
191
+ readonly data: JobsPayload<TQueues[number]>;
187
192
  readonly queue: Schema.Literal<string>;
193
+ readonly sourceId: Schema.OptionFromNullOr<Schema.String>;
194
+ readonly sourceOutput: Schema.Unknown;
188
195
  }>[]>>;
189
196
  readonly next: Schema.OptionFromNullOr<Schema.String>;
190
- }>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.health", Schema.Void, Schema.Struct<{
191
- readonly activeTotal: Schema.Number;
192
- readonly deadLetteredTotal: Schema.Number;
193
- readonly failedTotal: Schema.Number;
194
- readonly jobs: Schema.$Array<Schema.Struct<{
195
- readonly activeCount: Schema.Number;
196
- readonly deadLetteredCount: Schema.Number;
197
- readonly failedCount: Schema.Number;
198
- readonly name: Schema.String;
199
- readonly queuedCount: Schema.Number;
200
- readonly readyCount: Schema.Number;
201
- }>>;
202
- readonly queuedTotal: Schema.Number;
203
- readonly readyTotal: Schema.Number;
204
- }>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.job", Schema.Struct<{
197
+ }>, Schema.Union<readonly [Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.job", Schema.Struct<{
205
198
  id: Schema.String;
206
199
  queue: Schema.String;
207
200
  }>, Schema.OptionFromNullOr<Schema.Union<Schema.Struct<{
@@ -214,9 +207,23 @@ export declare function jobsPage<const TQueues extends readonly JobsQueue[]>(...
214
207
  readonly retryLimit: Schema.Number;
215
208
  readonly startedOn: Schema.OptionFromNullOr<Schema.DateTimeUtcFromString>;
216
209
  readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
217
- readonly data: TQueues[number]["schema"];
210
+ readonly data: JobsPayload<TQueues[number]>;
218
211
  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("../permissions.ts").AdminPermission, never>, readonly [], undefined>;
212
+ }>[]>>, Schema.Union<readonly [Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.health", Schema.Void, Schema.Struct<{
213
+ readonly activeTotal: Schema.Number;
214
+ readonly deadLetteredTotal: Schema.Number;
215
+ readonly failedTotal: Schema.Number;
216
+ readonly jobs: Schema.$Array<Schema.Struct<{
217
+ readonly activeCount: Schema.Number;
218
+ readonly deadLetteredCount: Schema.Number;
219
+ readonly failedCount: Schema.Number;
220
+ readonly name: Schema.String;
221
+ readonly queuedCount: Schema.Number;
222
+ readonly readyCount: Schema.Number;
223
+ }>>;
224
+ readonly queuedTotal: Schema.Number;
225
+ readonly readyTotal: Schema.Number;
226
+ }>, Schema.Union<readonly [Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never>, readonly [], undefined>;
220
227
  } & {
221
228
  queues: TQueues;
222
229
  };
@@ -1 +1 @@
1
- {"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../../src/jobs/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKhC,OAAO,EAAgD,KAAK,SAAS,EAA+C,MAAM,cAAc,CAAC;AAEzI,wBAAgB,QAAQ,CAAC,KAAK,CAAC,OAAO,SAAS,SAAS,SAAS,EAAE,EAAE,GAAG,MAAM,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqCtF"}
1
+ {"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../../src/jobs/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMxC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAa,MAAM,YAAY,CAAC;AAIzE,wBAAgB,QAAQ,CAAC,KAAK,CAAC,OAAO,SAAS,SAAS,SAAS,EAAE,EAAE,GAAG,MAAM,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgDtF"}
package/dist/jobs/page.js CHANGED
@@ -1,36 +1,50 @@
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
+ import { SessionUser } from "@shivaedev/identity/identity.ts";
5
+ import { hasPermission } from "@shivaedev/identity/permission.ts";
4
6
  import { adminPage } from "#page.ts";
7
+ import { JobsPermission } from "#permissions.ts";
8
+ import { jobsQueue } from "./entry.js";
5
9
  import { jobsKeys } from "./keys.js";
6
10
  import { deadLetteredSchema, JobsFailures, JobsHealth, jobPage, jobSchema, PageFields, QueueCounts } from "./schemas.js";
7
11
  export function jobsPage(...queues) {
8
- const Job = Schema.Union(queues.map((queue) => jobSchema(queue)));
9
- const DeadLettered = Schema.Union(queues.map((queue) => deadLetteredSchema(queue)));
12
+ const definitions = queues.map((queue) => jobsQueue(queue));
13
+ const Job = Schema.Union(definitions.map((queue) => jobSchema(queue)));
14
+ const DeadLettered = Schema.Union(definitions.map((queue) => deadLetteredSchema(queue)));
10
15
  const page = adminPage({
11
16
  contract: contract("admin.jobs", {
12
17
  queries: [
13
- query("health", { reads: () => [jobsKeys.health.list], rejections: JobsFailures, success: JobsHealth }),
18
+ query("health", {
19
+ readPolicy: () => Effect.map(SessionUser, (user) => hasPermission(user, JobsPermission.permission)),
20
+ reads: () => [jobsKeys.health.list],
21
+ rejections: JobsFailures,
22
+ success: JobsHealth,
23
+ }),
14
24
  query("counts", {
15
25
  payload: { queue: Schema.String },
26
+ readPolicy: () => Effect.map(SessionUser, (user) => hasPermission(user, JobsPermission.permission)),
16
27
  reads: ({ queue }) => [jobsKeys.counts.item(queue)],
17
28
  rejections: JobsFailures,
18
29
  success: QueueCounts,
19
30
  }),
20
31
  query("failed", {
21
32
  payload: { ...PageFields, queue: Schema.String },
33
+ readPolicy: () => Effect.map(SessionUser, (user) => hasPermission(user, JobsPermission.permission)),
22
34
  reads: ({ queue }) => [jobsKeys.failed.item(queue)],
23
35
  rejections: JobsFailures,
24
36
  success: jobPage(Job),
25
37
  }),
26
38
  query("deadLettered", {
27
39
  payload: { ...PageFields, queue: Schema.String },
40
+ readPolicy: () => Effect.map(SessionUser, (user) => hasPermission(user, JobsPermission.permission)),
28
41
  reads: ({ queue }) => [jobsKeys.deadLettered.item(queue)],
29
42
  rejections: JobsFailures,
30
43
  success: jobPage(DeadLettered),
31
44
  }),
32
45
  query("job", {
33
46
  payload: { id: Schema.String, queue: Schema.String },
47
+ readPolicy: () => Effect.map(SessionUser, (user) => hasPermission(user, JobsPermission.permission)),
34
48
  reads: ({ queue, id }) => [jobsKeys.job(queue).item(id)],
35
49
  rejections: JobsFailures,
36
50
  success: Schema.OptionFromNullOr(Job),
@@ -38,6 +52,7 @@ export function jobsPage(...queues) {
38
52
  ],
39
53
  }),
40
54
  id: "jobs",
55
+ permission: JobsPermission,
41
56
  route: { path: "/admin/jobs", title: "Jobs" },
42
57
  });
43
58
  return Object.assign(page, { queues });
@@ -1 +1 @@
1
- {"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/jobs/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,UAAU,EAAkB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEzI,MAAM,UAAU,QAAQ,CAA6C,GAAG,MAAe;IACtF,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAsB,EAAE,EAAE,CAAC,SAAS,CAA4B,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9G,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAsB,EAAE,EAAE,CAAC,kBAAkB,CAA4B,KAAK,CAAC,CAAC,CAAC,CAAC;IAChI,MAAM,IAAI,GAAG,SAAS,CAAC;QACtB,QAAQ,EAAE,QAAQ,CAAC,YAAY,EAAE;YAChC,OAAO,EAAE;gBACR,KAAK,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,YAAY,EAAE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