@shivaedev/admin 0.16.3 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/README.md +13 -12
- package/dist/adapters/matchAdminRoute.d.ts.map +1 -1
- package/dist/adapters/matchAdminRoute.js +4 -1
- package/dist/adapters/matchAdminRoute.js.map +1 -1
- package/dist/adapters/validateAdminRoutes.d.ts +3 -0
- package/dist/adapters/validateAdminRoutes.d.ts.map +1 -0
- package/dist/adapters/validateAdminRoutes.js +29 -0
- package/dist/adapters/validateAdminRoutes.js.map +1 -0
- package/dist/jobs/page.d.ts +23 -23
- package/dist/jobs/retryPage.d.ts +5 -5
- package/dist/page.d.ts +3 -3
- package/dist/page.d.ts.map +1 -1
- package/dist/page.js +1 -1
- package/dist/page.js.map +1 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +2 -4
- package/dist/registry.js.map +1 -1
- package/dist/server/adminDocuments.d.ts +1 -2
- package/dist/server/adminDocuments.d.ts.map +1 -1
- package/dist/server/adminDocuments.js +2 -4
- package/dist/server/adminDocuments.js.map +1 -1
- package/dist/server/pagePermissions.d.ts +1 -2
- package/dist/server/pagePermissions.d.ts.map +1 -1
- package/dist/server/pagePermissions.js +4 -13
- package/dist/server/pagePermissions.js.map +1 -1
- package/dist/server/registerAdmin.d.ts +2 -2
- package/dist/server/registerAdmin.d.ts.map +1 -1
- package/dist/server/users.d.ts +3 -2
- package/dist/server/users.d.ts.map +1 -1
- package/dist/server/users.js +8 -5
- package/dist/server/users.js.map +1 -1
- package/dist/server/usersHandlers.d.ts +2 -1
- package/dist/server/usersHandlers.d.ts.map +1 -1
- package/dist/server/usersHandlers.js +3 -3
- package/dist/server/usersHandlers.js.map +1 -1
- package/package.json +13 -12
- package/src/adapters/matchAdminRoute.ts +4 -1
- package/src/adapters/validateAdminRoutes.ts +36 -0
- package/src/page.ts +11 -7
- package/src/registry.ts +2 -4
- package/src/server/adminDocuments.ts +2 -4
- package/src/server/pagePermissions.ts +6 -21
- package/src/server/registerAdmin.ts +2 -2
- package/src/server/users.ts +8 -3
- package/src/server/usersHandlers.ts +4 -2
- package/dist/server/AdminSessions.d.ts +0 -7
- package/dist/server/AdminSessions.d.ts.map +0 -1
- package/dist/server/AdminSessions.js +0 -4
- package/dist/server/AdminSessions.js.map +0 -1
- package/src/server/AdminSessions.ts +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.18.0 - 2026-11-02
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Accept the application's Better Auth options in role assignment, provider-account role seeds and admin Users handlers to follow custom table and column mappings. Existing calls retain the default mapping.
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Preserve permission read policies on admin page queries so live collection reads load and refresh after writes across tenants, while retaining the page grant and query restrictions.
|
|
12
|
+
- Apply the first registered page's permission to `/admin` and `/admin/` in both the client and server guards.
|
|
13
|
+
- Match detail routes with a declared trailing slash consistently with page routes.
|
|
14
|
+
- Accept session-scoped contracts in `adminPage` and preserve their scope through middleware and client binding, including queries using `readsCollections`.
|
|
15
|
+
- Redact scheduled worker logs using the same diagnostic policy as queue workers. Job details sanitize stored failure output and source failure output through the same schema as job listings, including native pg-boss timeout records.
|
|
16
|
+
- Preserve the configured role column when mounting stored roles, generating role-aware migrations and checking the auth schema.
|
|
17
|
+
|
|
18
|
+
### Breaking
|
|
19
|
+
|
|
20
|
+
- Reject overlapping admin route patterns and detail paths outside their page at registry composition. Move colliding pages to distinct routes and place each detail under its page path.
|
|
21
|
+
|
|
22
|
+
## 0.17.0 - 2026-11-01
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
|
|
26
|
+
- Identity operation spans use the `Identity` prefix, including `Identity.resolveSession` and `Identity.betterAuthSession`. Adjust trace queries that used `Platform` or `PlatformRpc` names.
|
|
27
|
+
|
|
28
|
+
### Breaking
|
|
29
|
+
|
|
30
|
+
- Identity reads `SessionPolicy` from the Effect environment. Import the service from `@shivaedev/identity/server/SessionPolicy.ts` and construct one `Layer.succeed(SessionPolicy, { origin, provider, roles, streamRevalidationInterval })`, omitting optional fields as needed. Replace `SessionPolicy<TSession>` annotations with `SessionPolicy["Service"]`; provider-specific types remain on `SessionProvider<TSession>`. Remove policy arguments from session middleware constructors, `resolveSession`, `withSessionUser`, `permissionLayer`, `permissionRoute`, session lookup, rechecks and stream revalidation; provide the policy Layer to the composed readers. Profiles and provider accounts are decoded at their middleware boundaries from the shared provider.
|
|
31
|
+
- Server's `appHost` `sessions` option accepts that Layer and supplies it to middleware, application routes, sockets and change subscriptions. Wrap the previous policy object in `Layer.succeed(SessionPolicy, policy)`. Remove the session-shape generic from host option and factory types, and remove the policy argument from `hostChanges` and `bearerSocketRpc`.
|
|
32
|
+
- Admin uses identity's `SessionPolicy` directly. Replace `AdminSessions` imports and Layers with the identity service, and provide the policy once through the host instead of separately to admin handlers and documents.
|
|
33
|
+
- MCP's `mcpRoutes` reads `SessionPolicy` from the environment. Remove its `sessions` option and the session-shape generic from `McpOptions`; `betterAuthMcp` now returns `sessions` as a policy Layer, which can be passed to the host or supplied to MCP routes with `HttpRouter.provideRequest(oauth.sessions)` when the host also serves cookie-authenticated RPC.
|
|
34
|
+
|
|
3
35
|
## 0.16.3 - 2026-11-01
|
|
4
36
|
|
|
5
37
|
### Changed
|
package/README.md
CHANGED
|
@@ -51,21 +51,22 @@ export const Jobs = adminPage({
|
|
|
51
51
|
export const Admin = adminRegistry(Jobs);
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
`Jobs.contract` keeps the native `.declaration` and `.application.toLayer` APIs. `adminRegistry(...pages)` returns `pages` and a native `group`. Duplicate page ids
|
|
54
|
+
`Jobs.contract` keeps the native `.declaration` and `.application.toLayer` APIs. `adminRegistry(...pages)` returns `pages` and a native `group`. Duplicate page ids and RPC tags, including generated subscriptions, fail when the registry is created. Route patterns that can match the same path also fail, including a static page that overlaps another page's `$` detail parameter. Choose distinct routes rather than relying on route order.
|
|
55
55
|
|
|
56
56
|
Register server handler Layers by page id in `src/modules/admin/jobs/server/registration.ts`, importing `Admin` and `Jobs` from that module's `pages.ts`:
|
|
57
57
|
|
|
58
58
|
```ts
|
|
59
59
|
import { Effect, Layer } from "effect";
|
|
60
60
|
import { registerAdmin } from "@shivaedev/admin/server/registerAdmin.ts";
|
|
61
|
-
import {
|
|
61
|
+
import { SessionPolicy } from "@shivaedev/identity/server/SessionPolicy.ts";
|
|
62
62
|
|
|
63
63
|
const registration = registerAdmin(Admin, {
|
|
64
64
|
jobs: Jobs.contract.application.toLayer({
|
|
65
65
|
"admin.jobs.failed": () => Effect.succeed(["mail-42"]),
|
|
66
66
|
}),
|
|
67
67
|
});
|
|
68
|
-
const
|
|
68
|
+
const sessions = Layer.succeed(SessionPolicy, { origin, provider, roles: Access });
|
|
69
|
+
const handlers = registration.handlers;
|
|
69
70
|
```
|
|
70
71
|
|
|
71
72
|
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`.
|
|
@@ -74,11 +75,11 @@ Pass `registration.group` and `handlers` to the existing application's RPC host
|
|
|
74
75
|
|
|
75
76
|
### Protect documents and detail routes
|
|
76
77
|
|
|
77
|
-
Provide the application's session policy through `
|
|
78
|
+
Provide the application's session policy through `SessionPolicy` once. Registration builds each page's permission layer with that policy. The handler Layer requires identity's `SessionPolicy` service.
|
|
78
79
|
|
|
79
|
-
A page can declare `route: { path: "/admin/workspaces", detail: "/admin/workspaces/$id", title: "Workspaces" }`. The detail must be
|
|
80
|
+
A page can declare `route: { path: "/admin/workspaces", detail: "/admin/workspaces/$id", title: "Workspaces" }`. The detail must be a descendant of the page's path; composition rejects a detail elsewhere or equal to the page path. Mount `adminDocuments(registration, handler)` from `@shivaedev/admin/server/adminDocuments.ts` beside the application's public document routes and provide the same `SessionPolicy` layer. The handler serves the application's document; the guard checks the matched page's permission first. Unregistered admin paths return 404. `/admin` and `/admin/` use the first registered page's permission.
|
|
80
81
|
|
|
81
|
-
Use `adminPermissionGuard(registration.pages, permissionGuard({ session, signIn: "/sign-in" }))` from `@shivaedev/admin/client/adapters/adminPermissionGuard.ts` as the client root route's `beforeLoad`, using the native `permissionGuard` from `@shivaedev/react/permissionGuard.ts`. It applies the matched list or detail page's permission together with other route permissions. The application still declares the detail component in its router.
|
|
82
|
+
Use `adminPermissionGuard(registration.pages, permissionGuard({ session, signIn: "/sign-in" }))` from `@shivaedev/admin/client/adapters/adminPermissionGuard.ts` as the client root route's `beforeLoad`, using the native `permissionGuard` from `@shivaedev/react/adapters/permissionGuard.ts`. It applies the matched list or detail page's permission together with other route permissions. Like the document guard, `/admin` and `/admin/` use the first registered page's permission. The application still declares the detail component in its router.
|
|
82
83
|
|
|
83
84
|
### Pages owned by modules
|
|
84
85
|
|
|
@@ -90,7 +91,7 @@ import { mergeAdminRegistrations } from "@shivaedev/admin/server/mergeAdminRegis
|
|
|
90
91
|
const admin = mergeAdminRegistrations(foundation.admin, catalog.admin);
|
|
91
92
|
```
|
|
92
93
|
|
|
93
|
-
|
|
94
|
+
Pass the policy Layer once as `appHost({ sessions, handlers: admin.handlers, group: admin.group })`. Custom hosts provide it to their composed middleware and routes with `Layer.provide(sessions)`. The combined registration exposes `pages` for navigation and preserves the handler Layers' errors and service requirements. Duplicate page ids across modules fail at the type level; duplicate paths and RPC tags fail at composition. A module cannot register a page without its handlers.
|
|
94
95
|
|
|
95
96
|
Browser composition uses `mergeAdminRegistries` from `@shivaedev/admin/registry.ts` with the modules' browser-safe registries. A client module can also contribute its registry's `pages` directly to the application's navigation. A feature module adds pages to its own registry and handlers to its own registration; the foundation does not import feature pages.
|
|
96
97
|
|
|
@@ -209,7 +210,7 @@ A successful bound retry invalidates health, the affected queue's counts and bot
|
|
|
209
210
|
|
|
210
211
|
### Built-in Users page
|
|
211
212
|
|
|
212
|
-
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
|
|
213
|
+
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. For custom auth tables, pass the same Better Auth options used by `betterAuthMount` as the third argument: `usersHandlers(UsersPage, AppAccess, authOptions)`. The list follows `user.modelName`, `user.fields.name`, `email` and `createdAt`, and `user.additionalFields.role.fieldName`; role changes also follow `user.fields.updatedAt`. Omitting the options keeps the default PostgreSQL `user` table and column names.
|
|
213
214
|
|
|
214
215
|
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.
|
|
215
216
|
|
|
@@ -224,17 +225,17 @@ const changeRole = Client.runtime.fn(users.changeRole.run);
|
|
|
224
225
|
<UsersView roles={AppAccess.Role.literals} list={users.list.query} changeRole={changeRole} />;
|
|
225
226
|
```
|
|
226
227
|
|
|
227
|
-
`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`. Registration installs this middleware using `
|
|
228
|
+
`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`. Registration installs this middleware using `SessionPolicy`.
|
|
228
229
|
|
|
229
230
|
`admin.users.changeRole` takes `{ userId, role }`; its role Schema is the application's declared role union. The handler also requires `AssignRoles` (`roles.assign`) from `@shivaedev/access/roles.ts`. The view shows a role select only to callers with that permission. Role writes use identity’s `assignRole` verb, serialize in a transaction and return `LastRoleAssigner` (from `@shivaedev/access/roles.ts`) 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.
|
|
230
231
|
|
|
231
|
-
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`. Decode untrusted role input with `AppAccess.Role` before calling `changeUserRole` directly; native RPC performs that decode at the contract boundary. Identity resolves the caller's stored role through the session policy.
|
|
232
|
+
Applications can call `listUsers(AppAccess, input)` and `changeUserRole(AppAccess, input)` from `@shivaedev/admin/server/users.ts` on the server. Both also accept `authOptions` as a third argument for custom mappings. These enforce their respective domain permissions using `SessionUser`. Decode untrusted role input with `AppAccess.Role` before calling `changeUserRole` directly; native RPC performs that decode at the contract boundary. Identity resolves the caller's stored role through the session policy.
|
|
232
233
|
|
|
233
234
|
Keep Better Auth cookie caching disabled so requests see current permissions. Route role writes through this operation to retain the final-assigner policy: the policy covers only `admin.users.changeRole`, so disable Better Auth's `/admin/set-role`, `/admin/update-user` and `/admin/create-user` browser endpoints, which write roles outside it. Better Auth's server-side APIs stay available for trusted code such as a bootstrap command.
|
|
234
235
|
|
|
235
236
|
### Built-in Sessions page
|
|
236
237
|
|
|
237
|
-
Add `SessionsPage` from `@shivaedev/admin/sessions/Page.ts` to the admin registry and register `sessions: sessionsHandlers` from `@shivaedev/identity/server/better-auth/sessionsHandlers.ts`. Registration installs this middleware using `
|
|
238
|
+
Add `SessionsPage` from `@shivaedev/admin/sessions/Page.ts` to the admin registry and register `sessions: sessionsHandlers` from `@shivaedev/identity/server/better-auth/sessionsHandlers.ts`. Registration installs this middleware using `SessionPolicy`. The page uses identity's `identity.sessions` contract and `sessions.manage` permission.
|
|
238
239
|
|
|
239
240
|
```tsx
|
|
240
241
|
import { SessionsView } from "@shivaedev/admin/client/SessionsView.ts";
|
|
@@ -254,7 +255,7 @@ The view lists signed-in sessions with the user's name and email, started, last
|
|
|
254
255
|
|
|
255
256
|
### Client permission routes
|
|
256
257
|
|
|
257
|
-
`adminPage` requires a permission middleware, including for custom pages. It applies that middleware to the whole contract, installs a read policy checking the page grant on every query, and exposes its permission as `page.route.permission`. Queries need no repeated page-grant policy. An additional query policy can restrict access further. Bound live queries use the same page grant as one-off reads. 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/
|
|
258
|
+
`adminPage` requires a permission middleware, including for custom pages. It applies that middleware to the whole contract, installs a read policy checking the page grant on every query, and exposes its permission as `page.route.permission`. Queries need no repeated page-grant policy. An additional query policy can restrict access further. Bound live queries use the same page grant as one-off reads. Set the React route's `staticData.permission` to that value. Use `permissionGuard` from `@shivaedev/react/adapters/permissionGuard.ts` in protected routes' `beforeLoad` and wrap the router in `PermissionBoundary` from `@shivaedev/react/adapters/permissionBoundary.ts` with the session and one application fallback.
|
|
258
259
|
|
|
259
260
|
### Install and limits
|
|
260
261
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matchAdminRoute.d.ts","sourceRoot":"","sources":["../../src/adapters/matchAdminRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"matchAdminRoute.d.ts","sourceRoot":"","sources":["../../src/adapters/matchAdminRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAmBvG"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
export function matchAdminRoute(routes, pathname) {
|
|
2
2
|
const path = pathname.replace(/\/$/u, "");
|
|
3
|
+
if (path === "/admin") {
|
|
4
|
+
return routes[0];
|
|
5
|
+
}
|
|
3
6
|
return (routes.find((route) => route.path.replace(/\/$/u, "") === path)
|
|
4
7
|
?? routes.find((route) => {
|
|
5
8
|
if (route.detail === undefined) {
|
|
6
9
|
return false;
|
|
7
10
|
}
|
|
8
|
-
const expected = route.detail.split("/");
|
|
11
|
+
const expected = route.detail.replace(/\/$/u, "").split("/");
|
|
9
12
|
const actual = path.split("/");
|
|
10
13
|
return (expected.length === actual.length
|
|
11
14
|
&& expected.every((segment, index) => (segment.startsWith("$") ? actual[index] !== "" : segment === actual[index])));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matchAdminRoute.js","sourceRoot":"","sources":["../../src/adapters/matchAdminRoute.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,eAAe,CAAC,MAA6B,EAAE,QAAgB;IAC9E,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC1C,OAAO,CACN,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC;WAC5D,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;YACxB,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;gBAChC,OAAO,KAAK,CAAC;YACd,CAAC;YACD,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"matchAdminRoute.js","sourceRoot":"","sources":["../../src/adapters/matchAdminRoute.ts"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AE,MAAM,UAAU,CAAC;AAsB3C,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,GAAG,IAAI,CAavE"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function overlaps(left, right) {
|
|
2
|
+
const expected = left.split("/");
|
|
3
|
+
const actual = right.split("/");
|
|
4
|
+
return (expected.length === actual.length
|
|
5
|
+
&& expected.every((segment, index) => segment === actual[index] || (segment === "$" && actual[index] !== "") || (actual[index] === "$" && segment !== "")));
|
|
6
|
+
}
|
|
7
|
+
function pathsOf(route) {
|
|
8
|
+
const page = route.path.replace(/\/$/u, "");
|
|
9
|
+
const detail = route.detail?.replace(/\/$/u, "");
|
|
10
|
+
if (detail !== undefined && !detail.startsWith(`${page}/`)) {
|
|
11
|
+
throw new Error(`Admin detail path ${route.detail} must be under page path ${route.path}`);
|
|
12
|
+
}
|
|
13
|
+
return detail === undefined ? [page] : [page, detail];
|
|
14
|
+
}
|
|
15
|
+
export function validateAdminRoutes(routes) {
|
|
16
|
+
const paths = [];
|
|
17
|
+
for (const path of routes.flatMap(pathsOf)) {
|
|
18
|
+
const normalized = path.replace(/\$[^/]+/gu, "$");
|
|
19
|
+
if (paths.includes(normalized)) {
|
|
20
|
+
throw new Error(`Duplicate admin path: ${normalized}`);
|
|
21
|
+
}
|
|
22
|
+
const existing = paths.find((candidate) => overlaps(candidate, normalized));
|
|
23
|
+
if (existing !== undefined) {
|
|
24
|
+
throw new Error(`Overlapping admin paths: ${existing} and ${normalized}`);
|
|
25
|
+
}
|
|
26
|
+
paths.push(normalized);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=validateAdminRoutes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateAdminRoutes.js","sourceRoot":"","sources":["../../src/adapters/validateAdminRoutes.ts"],"names":[],"mappings":"AAEA,SAAS,QAAQ,CAAC,IAAY,EAAE,KAAa;IAC5C,MAAM,QAAQ,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,WAAW,EAAE,GAAG,CAAC,CAAC;QAClD,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,yBAAyB,UAAU,EAAE,CAAC,CAAC;QACxD,CAAC;QACD,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC;QAC5E,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,4BAA4B,QAAQ,QAAQ,UAAU,EAAE,CAAC,CAAC;QAC3E,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACxB,CAAC;AACF,CAAC"}
|
package/dist/jobs/page.d.ts
CHANGED
|
@@ -202,7 +202,7 @@ export declare function jobsPage<const TQueues extends readonly JobsEntry[]>(...
|
|
|
202
202
|
readonly failedCount: Schema.Number;
|
|
203
203
|
readonly queuedCount: Schema.Number;
|
|
204
204
|
readonly totalCount: Schema.Number;
|
|
205
|
-
}>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("#jobs/schemas.ts").JobsUnavailable | typeof import("#jobs/schemas.ts").JobsPayloadInvalid | typeof import("#jobs/schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.
|
|
205
|
+
}>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("#jobs/schemas.ts").JobsUnavailable | typeof import("#jobs/schemas.ts").JobsPayloadInvalid | typeof import("#jobs/schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.deadLettered", Schema.Struct<{
|
|
206
206
|
cursor: Schema.optionalKey<Schema.String>;
|
|
207
207
|
limit: Schema.Number;
|
|
208
208
|
queue: Schema.String;
|
|
@@ -222,9 +222,15 @@ export declare function jobsPage<const TQueues extends readonly JobsEntry[]>(...
|
|
|
222
222
|
readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
|
|
223
223
|
readonly data: Schema.Unknown;
|
|
224
224
|
readonly queue: Schema.Literal<string>;
|
|
225
|
+
readonly sourceId: Schema.OptionFromNullOr<Schema.String>;
|
|
226
|
+
readonly sourceOutput: Schema.NullOr<Schema.Struct<{
|
|
227
|
+
readonly _tag: Schema.withDecodingDefaultKey<Schema.String, never>;
|
|
228
|
+
readonly message: Schema.decodeTo<Schema.String, Schema.String, never, never>;
|
|
229
|
+
}>>;
|
|
230
|
+
readonly sourceQueue: Schema.Literal<string>;
|
|
225
231
|
}>[]>>;
|
|
226
232
|
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
227
|
-
}>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("#jobs/schemas.ts").JobsUnavailable | typeof import("#jobs/schemas.ts").JobsPayloadInvalid | typeof import("#jobs/schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.
|
|
233
|
+
}>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("#jobs/schemas.ts").JobsUnavailable | typeof import("#jobs/schemas.ts").JobsPayloadInvalid | typeof import("#jobs/schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.failed", Schema.Struct<{
|
|
228
234
|
cursor: Schema.optionalKey<Schema.String>;
|
|
229
235
|
limit: Schema.Number;
|
|
230
236
|
queue: Schema.String;
|
|
@@ -244,14 +250,22 @@ export declare function jobsPage<const TQueues extends readonly JobsEntry[]>(...
|
|
|
244
250
|
readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
|
|
245
251
|
readonly data: Schema.Unknown;
|
|
246
252
|
readonly queue: Schema.Literal<string>;
|
|
247
|
-
readonly sourceId: Schema.OptionFromNullOr<Schema.String>;
|
|
248
|
-
readonly sourceOutput: Schema.NullOr<Schema.Struct<{
|
|
249
|
-
readonly _tag: Schema.withDecodingDefaultKey<Schema.String, never>;
|
|
250
|
-
readonly message: Schema.decodeTo<Schema.String, Schema.String, never, never>;
|
|
251
|
-
}>>;
|
|
252
|
-
readonly sourceQueue: Schema.Literal<string>;
|
|
253
253
|
}>[]>>;
|
|
254
254
|
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
255
|
+
}>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("#jobs/schemas.ts").JobsUnavailable | typeof import("#jobs/schemas.ts").JobsPayloadInvalid | typeof import("#jobs/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<{
|
|
256
|
+
readonly activeTotal: Schema.Number;
|
|
257
|
+
readonly deadLetteredTotal: Schema.Number;
|
|
258
|
+
readonly failedTotal: Schema.Number;
|
|
259
|
+
readonly jobs: Schema.$Array<Schema.Struct<{
|
|
260
|
+
readonly activeCount: Schema.Number;
|
|
261
|
+
readonly deadLetteredCount: Schema.Number;
|
|
262
|
+
readonly failedCount: Schema.Number;
|
|
263
|
+
readonly name: Schema.String;
|
|
264
|
+
readonly queuedCount: Schema.Number;
|
|
265
|
+
readonly readyCount: Schema.Number;
|
|
266
|
+
}>>;
|
|
267
|
+
readonly queuedTotal: Schema.Number;
|
|
268
|
+
readonly readyTotal: Schema.Number;
|
|
255
269
|
}>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("#jobs/schemas.ts").JobsUnavailable | typeof import("#jobs/schemas.ts").JobsPayloadInvalid | typeof import("#jobs/schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.job", Schema.Struct<{
|
|
256
270
|
id: Schema.String;
|
|
257
271
|
queue: Schema.String;
|
|
@@ -270,21 +284,7 @@ export declare function jobsPage<const TQueues extends readonly JobsEntry[]>(...
|
|
|
270
284
|
readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
|
|
271
285
|
readonly data: Schema.Unknown;
|
|
272
286
|
readonly queue: Schema.Literal<string>;
|
|
273
|
-
}>[]>>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("#jobs/schemas.ts").JobsUnavailable | typeof import("#jobs/schemas.ts").JobsPayloadInvalid | typeof import("#jobs/schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never
|
|
274
|
-
readonly activeTotal: Schema.Number;
|
|
275
|
-
readonly deadLetteredTotal: Schema.Number;
|
|
276
|
-
readonly failedTotal: Schema.Number;
|
|
277
|
-
readonly jobs: Schema.$Array<Schema.Struct<{
|
|
278
|
-
readonly activeCount: Schema.Number;
|
|
279
|
-
readonly deadLetteredCount: Schema.Number;
|
|
280
|
-
readonly failedCount: Schema.Number;
|
|
281
|
-
readonly name: Schema.String;
|
|
282
|
-
readonly queuedCount: Schema.Number;
|
|
283
|
-
readonly readyCount: Schema.Number;
|
|
284
|
-
}>>;
|
|
285
|
-
readonly queuedTotal: Schema.Number;
|
|
286
|
-
readonly readyTotal: Schema.Number;
|
|
287
|
-
}>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("#jobs/schemas.ts").JobsUnavailable | typeof import("#jobs/schemas.ts").JobsPayloadInvalid | typeof import("#jobs/schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never>, readonly [], undefined>;
|
|
287
|
+
}>[]>>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("#jobs/schemas.ts").JobsUnavailable | typeof import("#jobs/schemas.ts").JobsPayloadInvalid | typeof import("#jobs/schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never>, readonly [], undefined>;
|
|
288
288
|
} & {
|
|
289
289
|
queues: TQueues;
|
|
290
290
|
};
|
package/dist/jobs/retryPage.d.ts
CHANGED
|
@@ -235,7 +235,10 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsEnt
|
|
|
235
235
|
readonly queryIndexes: Schema.optional<Schema.$Array<Schema.Number>>;
|
|
236
236
|
}>, Schema.Struct<{
|
|
237
237
|
readonly _tag: Schema.Literal<"Resync">;
|
|
238
|
-
}>]>, ...never[]]>, Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, typeof import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired, ...Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>[]]>>, Schema.Never, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.
|
|
238
|
+
}>]>, ...never[]]>, Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, typeof import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired, ...Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>[]]>>, Schema.Never, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.retry", Schema.Struct<{
|
|
239
|
+
id: Schema.String;
|
|
240
|
+
queue: Schema.String;
|
|
241
|
+
}>, Schema.Void, Schema.Union<readonly (typeof Forbidden | typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered | typeof JobsNotFailed)[]>, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.counts", Schema.Struct<{
|
|
239
242
|
queue: Schema.String;
|
|
240
243
|
}>, Schema.Struct<{
|
|
241
244
|
readonly activeCount: Schema.Number;
|
|
@@ -324,10 +327,7 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsEnt
|
|
|
324
327
|
readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
|
|
325
328
|
readonly data: Schema.Unknown;
|
|
326
329
|
readonly queue: Schema.Literal<string>;
|
|
327
|
-
}>[]>>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | 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
|
|
328
|
-
id: Schema.String;
|
|
329
|
-
queue: Schema.String;
|
|
330
|
-
}>, Schema.Void, Schema.Union<readonly (typeof Forbidden | typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered | typeof JobsNotFailed)[]>, typeof JobsPermission, never>, readonly [], undefined>;
|
|
330
|
+
}>[]>>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | 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>;
|
|
331
331
|
} & {
|
|
332
332
|
queues: TQueues;
|
|
333
333
|
};
|
package/dist/page.d.ts
CHANGED
|
@@ -32,18 +32,18 @@ type PageQueries<TQueries extends readonly QueryShape[]> = {
|
|
|
32
32
|
};
|
|
33
33
|
};
|
|
34
34
|
type PageRpcs<TRpc> = TRpc extends Rpc.Rpc<infer TTag, infer TPayload, infer TSuccess, infer TError, infer TMiddleware, infer R> ? Rpc.Rpc<TTag, TPayload, TSuccess, TError, TMiddleware, R | SessionUser> : never;
|
|
35
|
-
export declare function adminPage<const TId extends string, const TRoute extends Omit<AdminRoute, "permission">, const TName extends string, const TQueries extends readonly QueryShape[], const TCommands extends readonly CommandShape[], TRpcs extends Rpc.AnyWithProps, const TStreams extends readonly StreamShape[], TMiddleware extends RpcMiddleware.AnyService & PagePermission>(page: {
|
|
35
|
+
export declare function adminPage<const TId extends string, const TRoute extends Omit<AdminRoute, "permission">, const TName extends string, const TQueries extends readonly QueryShape[], const TCommands extends readonly CommandShape[], TRpcs extends Rpc.AnyWithProps, const TStreams extends readonly StreamShape[], TMiddleware extends RpcMiddleware.AnyService & PagePermission, const TScope extends "session" | undefined = undefined>(page: {
|
|
36
36
|
readonly id: TId;
|
|
37
37
|
readonly route: TRoute;
|
|
38
38
|
readonly permission: TMiddleware;
|
|
39
|
-
readonly contract: Contract<TName, TQueries, TCommands, TRpcs, TStreams>;
|
|
39
|
+
readonly contract: Contract<TName, TQueries, TCommands, TRpcs, TStreams, TScope>;
|
|
40
40
|
}): AdminPage & {
|
|
41
41
|
readonly route: TRoute & {
|
|
42
42
|
readonly permission: Permission;
|
|
43
43
|
};
|
|
44
44
|
readonly id: TId;
|
|
45
45
|
readonly permissionKey: TMiddleware["key"];
|
|
46
|
-
readonly contract: Contract<TName, PageQueries<TQueries>, TCommands, Rpc.AddMiddleware<PageRpcs<TRpcs>, TMiddleware>, TStreams>;
|
|
46
|
+
readonly contract: Contract<TName, PageQueries<TQueries>, TCommands, Rpc.AddMiddleware<PageRpcs<TRpcs>, TMiddleware>, TStreams, TScope>;
|
|
47
47
|
};
|
|
48
48
|
export {};
|
|
49
49
|
//# sourceMappingURL=page.d.ts.map
|
package/dist/page.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../src/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAuB,MAAM,QAAQ,CAAC;AAC3D,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,KAAK,QAAQ,EAA2B,KAAK,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAC7G,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC9F,OAAO,KAAK,EAAE,eAAe,EAAU,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,KAAK,QAAQ,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAG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,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;CACjF,GAAG,SAAS,GAAG;IACf,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAA;KAAE,CAAC;IAC7D,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC;IACjB,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC;IAC3C,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,QAAQ,CAAC,EAAE,SAAS,EAAE,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;CACxI,CAAC"}
|
package/dist/page.js
CHANGED
|
@@ -7,7 +7,7 @@ export function adminPage(page) {
|
|
|
7
7
|
const { declaration } = page.contract;
|
|
8
8
|
const queries = declaration.queries.map((query) => ({
|
|
9
9
|
...query,
|
|
10
|
-
readPolicy: (payload, viewer) => Effect.flatMap(SessionUser, (user) => hasPermission(user, page.permission.permission) ? (query.readPolicy?.(payload, viewer) ?? Effect.succeed(true)) : Effect.succeed(false)),
|
|
10
|
+
readPolicy: Object.assign((payload, viewer) => Effect.flatMap(SessionUser, (user) => hasPermission(user, page.permission.permission) ? (query.readPolicy?.(payload, viewer) ?? Effect.succeed(true)) : Effect.succeed(false)), query.readPolicy),
|
|
11
11
|
}));
|
|
12
12
|
let protectedContract = contract(declaration.name, { ...declaration, queries });
|
|
13
13
|
const original = page.contract.requests.values().next().value;
|
package/dist/page.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.js","sourceRoot":"","sources":["../src/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAe,MAAM,QAAQ,CAAC;AAG3D,OAAO,EAAiB,QAAQ,E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,GAAc,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,GAAG,WAAW,EAAE,OAAO,EAAE,CAAC,CAAC;IAC3F,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;IAC9D,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC5B,KAAK,MAAM,UAAU,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;YAC/C,iBAAiB,GAAG,iBAAiB,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAC9D,CAAC;IACF,CAAC;IACD,MAAM,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE,GAAG,IAAI,CAAC;IAC3C,OAAO;QACN,GAAG,UAAU;QACb,aAAa,EAAE,UAAU,CAAC,GAAG;QAC7B,KAAK,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE;QAChE,CAAC,eAAe,CAAC,EAAE,IAAa;QAChC,QAAQ,EAAE,iBAAiB,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC;KACvD,CAAC;AACH,CAAC"}
|
package/dist/registry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,MAAM,WAAW,aAAa,CAAC,MAAM,SAAS,SAAS,SAAS,EAAE;IACjE,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,QAAQ,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AW,CAAC,CAAC,CAAC;AAK7C,wBAAgB,aAAa,CAAC,KAAK,CAAC,MAAM,SAAS,SAAS,SAAS,EAAE,EAAE,GAAG,KAAK,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,CAiBxI"}
|
package/dist/registry.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { RpcGroup } from "effect/rpc";
|
|
2
|
+
import { validateAdminRoutes } from "#adapters/validateAdminRoutes.ts";
|
|
2
3
|
export function mergeAdminRegistries(...registries) {
|
|
3
4
|
return adminRegistry(...registries.flatMap((registry) => registry.pages));
|
|
4
5
|
}
|
|
5
6
|
export function adminRegistry(...pages) {
|
|
6
7
|
const ids = new Set();
|
|
7
|
-
const paths = new Set();
|
|
8
8
|
const tags = new Set();
|
|
9
9
|
function unique(seen, value, kind) {
|
|
10
10
|
if (seen.has(value)) {
|
|
@@ -14,13 +14,11 @@ export function adminRegistry(...pages) {
|
|
|
14
14
|
}
|
|
15
15
|
for (const page of pages) {
|
|
16
16
|
unique(ids, page.id, "page id");
|
|
17
|
-
for (const path of [page.route.path, ...(page.route.detail === undefined ? [] : [page.route.detail])]) {
|
|
18
|
-
unique(paths, path.replace(/\$[^/]+/gu, "$").replace(/\/$/u, ""), "path");
|
|
19
|
-
}
|
|
20
17
|
for (const tag of page.contract.requests.keys()) {
|
|
21
18
|
unique(tags, tag, "RPC tag");
|
|
22
19
|
}
|
|
23
20
|
}
|
|
21
|
+
validateAdminRoutes(pages.map((page) => page.route));
|
|
24
22
|
return { group: RpcGroup.make().merge(...pages.map((page) => page.contract)), pages };
|
|
25
23
|
}
|
|
26
24
|
//# sourceMappingURL=registry.js.map
|
package/dist/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
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AAK,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;AACvF,CAAC"}
|
|
@@ -2,6 +2,5 @@ import { Effect } from "effect";
|
|
|
2
2
|
import type { HttpServerRequest } from "effect/http";
|
|
3
3
|
import { HttpRouter, HttpServerResponse } from "effect/http";
|
|
4
4
|
import type { AnyAdminRegistry } from "#registry.ts";
|
|
5
|
-
import
|
|
6
|
-
export declare function adminDocuments<E, R>(registry: AnyAdminRegistry, handler: (request: HttpServerRequest.HttpServerRequest) => Effect.Effect<HttpServerResponse.HttpServerResponse, E, R>): import("effect/Layer").Layer<never, never, AdminSessions | HttpRouter.HttpRouter | Exclude<HttpRouter.Request.From<"Error", E>, import("effect/Scope").Scope> | Exclude<HttpRouter.Request.From<"Requires", Exclude<Exclude<R, import("@shivaedev/identity/identity.ts").Identity | import("@shivaedev/identity/identity.ts").SessionUser>, HttpRouter.Provided>>, import("effect/Scope").Scope>>;
|
|
5
|
+
export declare function adminDocuments<E, R>(registry: AnyAdminRegistry, handler: (request: HttpServerRequest.HttpServerRequest) => Effect.Effect<HttpServerResponse.HttpServerResponse, E, R>): import("effect/Layer").Layer<never, never, HttpRouter.HttpRouter | HttpRouter.Request<"Requires", import("@shivaedev/identity/server/SessionPolicy.ts").SessionPolicy> | Exclude<HttpRouter.Request.From<"Error", E>, import("effect/Scope").Scope> | Exclude<HttpRouter.Request.From<"Requires", Exclude<Exclude<R, import("@shivaedev/identity/identity.ts").Identity | import("@shivaedev/identity/identity.ts").SessionUser>, HttpRouter.Provided>>, import("effect/Scope").Scope>>;
|
|
7
6
|
//# sourceMappingURL=adminDocuments.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adminDocuments.d.ts","sourceRoot":"","sources":["../../src/server/adminDocuments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAI7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"adminDocuments.d.ts","sourceRoot":"","sources":["../../src/server/adminDocuments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAI7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,EAClC,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,CAAC,OAAO,EAAE,iBAAiB,CAAC,iBAAiB,KAAK,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,kBAAkB,EAAE,CAAC,EAAE,CAAC,CAAC,2dAcrH"}
|
|
@@ -3,17 +3,15 @@ import { HttpRouter, HttpServerResponse } from "effect/http";
|
|
|
3
3
|
import * as HttpStatus from "effect/http/HttpStatus";
|
|
4
4
|
import { permissionRoute } from "@shivaedev/identity/server/permissions.ts";
|
|
5
5
|
import { matchAdminRoute } from "#adapters/matchAdminRoute.ts";
|
|
6
|
-
import { AdminSessions } from "./AdminSessions.js";
|
|
7
6
|
export function adminDocuments(registry, handler) {
|
|
8
7
|
const routes = registry.pages.map((page) => page.route);
|
|
9
8
|
return HttpRouter.use((router) => Effect.gen(function* () {
|
|
10
|
-
const sessions = yield* AdminSessions;
|
|
11
9
|
yield* router.add("GET", "/admin/*", (request) => {
|
|
12
10
|
const path = new URL(request.url, "http://localhost").pathname;
|
|
13
|
-
const route =
|
|
11
|
+
const route = matchAdminRoute(routes, path);
|
|
14
12
|
return route === undefined
|
|
15
13
|
? Effect.succeed(HttpServerResponse.empty({ status: HttpStatus.fromLiteral("NotFound") }))
|
|
16
|
-
: permissionRoute(
|
|
14
|
+
: permissionRoute(route.permission)(handler)(request);
|
|
17
15
|
});
|
|
18
16
|
}));
|
|
19
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adminDocuments.js","sourceRoot":"","sources":["../../src/server/adminDocuments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"adminDocuments.js","sourceRoot":"","sources":["../../src/server/adminDocuments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAG/D,MAAM,UAAU,cAAc,CAC7B,QAA0B,EAC1B,OAAqH;IAErH,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxD,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAChC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QACnB,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,EAAE,CAAC,OAAO,EAAE,EAAE;YAChD,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC,QAAQ,CAAC;YAC/D,MAAM,KAAK,GAAG,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAC5C,OAAO,KAAK,KAAK,SAAS;gBACzB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;gBAC1F,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CACF,CAAC;AACH,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Layer } from "effect";
|
|
2
2
|
import type { AnyAdminRegistry } from "#registry.ts";
|
|
3
|
-
|
|
4
|
-
export declare function pagePermissions(registry: AnyAdminRegistry): Layer.Layer<unknown, never, AdminSessions>;
|
|
3
|
+
export declare function pagePermissions(registry: AnyAdminRegistry): Layer.Layer<unknown, never, import("@shivaedev/identity/server/SessionPolicy.ts").SessionPolicy>;
|
|
5
4
|
//# sourceMappingURL=pagePermissions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagePermissions.d.ts","sourceRoot":"","sources":["../../src/server/pagePermissions.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"pagePermissions.d.ts","sourceRoot":"","sources":["../../src/server/pagePermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,EAAE,MAAM,QAAQ,CAAC;AAKxC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,gBAAgB,oGAQzD"}
|
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
import { Context,
|
|
1
|
+
import { Context, Layer } from "effect";
|
|
2
2
|
import { permissionLayer } from "@shivaedev/identity/server/permissions.ts";
|
|
3
|
-
import { AdminSessions } from "./AdminSessions.js";
|
|
4
3
|
export function pagePermissions(registry) {
|
|
5
|
-
return Layer.
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
if (Option.isNone(sessions)) {
|
|
9
|
-
const page = registry.pages[0];
|
|
10
|
-
return yield* Effect.die(new Error(`Missing admin permission policy: page ${page?.id}, permission ${page?.route.permission.name}; provide AdminSessions`));
|
|
11
|
-
}
|
|
12
|
-
return Layer.mergeAll(Layer.empty, ...registry.pages.map((page) => {
|
|
13
|
-
const middleware = Context.Service(page.permissionKey);
|
|
14
|
-
return permissionLayer(Object.assign(middleware, { permission: page.route.permission }), sessions.value);
|
|
15
|
-
}));
|
|
4
|
+
return Layer.mergeAll(Layer.empty, ...registry.pages.map((page) => {
|
|
5
|
+
const middleware = Context.Service(page.permissionKey);
|
|
6
|
+
return permissionLayer(Object.assign(middleware, { permission: page.route.permission }));
|
|
16
7
|
}));
|
|
17
8
|
}
|
|
18
9
|
//# sourceMappingURL=pagePermissions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagePermissions.js","sourceRoot":"","sources":["../../src/server/pagePermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"pagePermissions.js","sourceRoot":"","sources":["../../src/server/pagePermissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAIxC,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAG5E,MAAM,UAAU,eAAe,CAAC,QAA0B;IACzD,OAAO,KAAK,CAAC,QAAQ,CACpB,KAAK,CAAC,KAAK,EACX,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAC9B,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAwF,IAAI,CAAC,aAAa,CAAC,CAAC;QAC9I,OAAO,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IAC1F,CAAC,CAAC,CACF,CAAC;AACH,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Layer } from "effect";
|
|
2
2
|
import type { Rpc, RpcGroup } from "effect/rpc";
|
|
3
|
+
import type { SessionPolicy } from "@shivaedev/identity/server/SessionPolicy.ts";
|
|
3
4
|
import type { AdminPage } from "#page.ts";
|
|
4
5
|
import type { AdminRegistry } from "#registry.ts";
|
|
5
|
-
import type { AdminSessions } from "./AdminSessions.ts";
|
|
6
6
|
type HandlerLayers<TPages extends readonly AdminPage[]> = {
|
|
7
7
|
readonly [TPage in TPages[number] as TPage["id"]]: Layer.Layer<Rpc.ToHandler<RpcGroup.Rpcs<TPage["contract"]["application"]>>, unknown, unknown>;
|
|
8
8
|
};
|
|
@@ -12,7 +12,7 @@ export declare function registerAdmin<const TPages extends readonly AdminPage[],
|
|
|
12
12
|
readonly pages: TPages;
|
|
13
13
|
readonly handlers: Layer.Layer<Layer.Success<RegisteredLayers<THandlers>> | Extract<Rpc.Middleware<RpcGroup.Rpcs<TPages[number]["contract"]>>, {
|
|
14
14
|
readonly key: TPages[number]["permissionKey"];
|
|
15
|
-
}>, Layer.Error<RegisteredLayers<THandlers>>, Layer.Services<RegisteredLayers<THandlers>> |
|
|
15
|
+
}>, Layer.Error<RegisteredLayers<THandlers>>, Layer.Services<RegisteredLayers<THandlers>> | SessionPolicy>;
|
|
16
16
|
};
|
|
17
17
|
export {};
|
|
18
18
|
//# sourceMappingURL=registerAdmin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerAdmin.d.ts","sourceRoot":"","sources":["../../src/server/registerAdmin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"registerAdmin.d.ts","sourceRoot":"","sources":["../../src/server/registerAdmin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AACjF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGlD,KAAK,aAAa,CAAC,MAAM,SAAS,SAAS,SAAS,EAAE,IAAI;IACzD,QAAQ,EAAE,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC;CAChJ,CAAC;AAEF,KAAK,gBAAgB,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC,MAAM,SAAS,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;AAElF,wBAAgB,aAAa,CAAC,KAAK,CAAC,MAAM,SAAS,SAAS,SAAS,EAAE,EAAE,SAAS,SAAS,aAAa,CAAC,MAAM,CAAC,EAC/G,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,EAC/B,QAAQ,EAAE,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,GACjF;IACF,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC;IAC/C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,CAC3B,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,GAC1C,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAA;KAAE,CAAC,EACvH,KAAK,CAAC,KAAK,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,EACxC,KAAK,CAAC,QAAQ,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,GAAG,aAAa,CAC3D,CAAC;CACF,CAAC"}
|
package/dist/server/users.d.ts
CHANGED
|
@@ -3,11 +3,12 @@ import { SqlClient } from "effect/sql";
|
|
|
3
3
|
import type { AccessPolicy } from "@shivaedev/access/roleSet.ts";
|
|
4
4
|
import { AuthUnavailable } from "@shivaedev/errors/taxonomy.ts";
|
|
5
5
|
import { SessionUser } from "@shivaedev/identity/identity.ts";
|
|
6
|
+
import { type AuthTableOptions } from "@shivaedev/identity/server/better-auth/tables.ts";
|
|
6
7
|
import { type ChangeRoleInput } from "#users/roles.ts";
|
|
7
8
|
export declare const listUsers: <TRole extends string>(access: Pick<AccessPolicy<TRole>, "Role">, input: {
|
|
8
9
|
readonly cursor?: string;
|
|
9
10
|
readonly limit: number;
|
|
10
|
-
}) => Effect.Effect<{
|
|
11
|
+
}, options?: AuthTableOptions | undefined) => Effect.Effect<{
|
|
11
12
|
next: Option.Option<string>;
|
|
12
13
|
users: {
|
|
13
14
|
readonly createdAt: DateTime.Utc;
|
|
@@ -17,5 +18,5 @@ export declare const listUsers: <TRole extends string>(access: Pick<AccessPolicy
|
|
|
17
18
|
readonly role: TRole;
|
|
18
19
|
}[];
|
|
19
20
|
}, AuthUnavailable | import("@shivaedev/errors/taxonomy.ts").Forbidden, SessionUser | SqlClient.SqlClient>;
|
|
20
|
-
export declare const changeUserRole: <TRole extends string>(access: Pick<AccessPolicy<TRole>, "Role" | "hasPermission">, input: ChangeRoleInput<TRole
|
|
21
|
+
export declare const changeUserRole: <TRole extends string>(access: Pick<AccessPolicy<TRole>, "Role" | "hasPermission">, input: ChangeRoleInput<TRole>, options?: AuthTableOptions | undefined) => Effect.Effect<void, AuthUnavailable | import("@shivaedev/errors/taxonomy.ts").Forbidden | import("@shivaedev/access/roles.ts").LastRoleAssigner | import("@shivaedev/errors/taxonomy.ts").NotFound, SessionUser | SqlClient.SqlClient>;
|
|
21
22
|
//# sourceMappingURL=users.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../src/server/users.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAa,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../src/server/users.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAa,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,KAAK,gBAAgB,EAAU,MAAM,kDAAkD,CAAC;AAEjG,OAAO,EAAW,KAAK,eAAe,EAAsB,MAAM,iBAAiB,CAAC;AAMpF,eAAO,MAAM,SAAS,GAA2C,KAAK,SAAS,MAAM;;;;;;;;;;;;0GAkBnF,CAAC;AAEH,eAAO,MAAM,cAAc,GAAgD,KAAK,SAAS,MAAM,+WAY7F,CAAC"}
|
package/dist/server/users.js
CHANGED
|
@@ -5,16 +5,19 @@ import { AssignRoles } from "@shivaedev/access/roles.ts";
|
|
|
5
5
|
import { AuthUnavailable } from "@shivaedev/errors/taxonomy.ts";
|
|
6
6
|
import { SessionUser } from "@shivaedev/identity/identity.ts";
|
|
7
7
|
import { assignRole } from "@shivaedev/identity/server/better-auth/assignRole.ts";
|
|
8
|
+
import { tables } from "@shivaedev/identity/server/better-auth/tables.ts";
|
|
8
9
|
import { ReadUsers } from "#permissions.ts";
|
|
9
10
|
import { AppUser } from "#users/roles.ts";
|
|
10
11
|
function unavailable() {
|
|
11
12
|
return new AuthUnavailable({ message: "Could not access app users" });
|
|
12
13
|
}
|
|
13
|
-
export const listUsers = Effect.fn("Admin.listUsers")(function* (access, input) {
|
|
14
|
+
export const listUsers = Effect.fn("Admin.listUsers")(function* (access, input, options) {
|
|
14
15
|
yield* requirePermission(yield* SessionUser, ReadUsers);
|
|
15
|
-
const sql = yield* SqlClient.SqlClient;
|
|
16
|
+
const sql = (yield* SqlClient.SqlClient).withoutTransforms();
|
|
17
|
+
const { user } = tables(options);
|
|
16
18
|
const read = SqlSchema.findAll({
|
|
17
|
-
execute: () => sql `select id, name
|
|
19
|
+
execute: () => sql `select id, ${sql(user.name)} as name, ${sql(user.email)} as email,
|
|
20
|
+
${sql(user.role)} as role, ${sql(user.createdAt)} as "createdAt" from ${sql(user.table)}
|
|
18
21
|
where id > ${input.cursor ?? ""} order by id limit ${input.limit + 1}`,
|
|
19
22
|
Request: Schema.Void,
|
|
20
23
|
Result: Schema.Struct({ ...AppUser.fields, role: access.Role }),
|
|
@@ -23,10 +26,10 @@ export const listUsers = Effect.fn("Admin.listUsers")(function* (access, input)
|
|
|
23
26
|
const users = rows.slice(0, input.limit);
|
|
24
27
|
return { next: rows.length > input.limit ? Option.fromUndefinedOr(users.at(-1)?.id) : Option.none(), users };
|
|
25
28
|
});
|
|
26
|
-
export const changeUserRole = Effect.fn("Admin.changeUserRole")(function* (access, input) {
|
|
29
|
+
export const changeUserRole = Effect.fn("Admin.changeUserRole")(function* (access, input, options) {
|
|
27
30
|
const actor = yield* SessionUser;
|
|
28
31
|
yield* requirePermission(actor, AssignRoles);
|
|
29
|
-
const changed = yield* assignRole(access, input.userId, input.role);
|
|
32
|
+
const changed = yield* assignRole(access, input.userId, input.role, options);
|
|
30
33
|
if (changed) {
|
|
31
34
|
const changedAt = DateTime.formatIso(yield* DateTime.now);
|
|
32
35
|
yield* Effect.logInfo("User role changed").pipe(Effect.annotateLogs({ actorId: actor.id, changedAt, ...input }));
|
package/dist/server/users.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.js","sourceRoot":"","sources":["../../src/server/users.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAE3E,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM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C,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAU,EAAE,KAAK,EAAE,CAAC;AACtH,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,EAAE,CAAC,sBAAsB,CAAC,CAAC,QAAQ,CAAC,EACxE,MAA2D,EAC3D,KAA6B,EAC7B,OAA0B;IAE1B,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,WAAW,CAAC;IACjC,KAAK,CAAC,CAAC,iBAAiB,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAC7C,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC7E,IAAI,OAAO,EAAE,CAAC;QACb,MAAM,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC1D,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC;IAClH,CAAC;AACF,CAAC,CAAC,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AccessPolicy } from "@shivaedev/access/roleSet.ts";
|
|
2
|
+
import type { AuthTableOptions } from "@shivaedev/identity/server/better-auth/tables.ts";
|
|
2
3
|
import type { usersPage } from "#users/page.ts";
|
|
3
|
-
export declare function usersHandlers<const TRole extends string>(page: ReturnType<typeof usersPage<TRole>>, access: Pick<AccessPolicy<TRole>, "Role" | "hasPermission"
|
|
4
|
+
export declare function usersHandlers<const TRole extends string>(page: ReturnType<typeof usersPage<TRole>>, access: Pick<AccessPolicy<TRole>, "Role" | "hasPermission">, options?: AuthTableOptions): import("effect/Layer").Layer<import("effect/rpc/Rpc").Handler<"admin.users.changeRole"> | import("effect/rpc/Rpc").Handler<"admin.users.list">, never, import("effect/sql/SqlClient").SqlClient>;
|
|
4
5
|
//# sourceMappingURL=usersHandlers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usersHandlers.d.ts","sourceRoot":"","sources":["../../src/server/usersHandlers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"usersHandlers.d.ts","sourceRoot":"","sources":["../../src/server/usersHandlers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAIjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kDAAkD,CAAC;AAEzF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,wBAAgB,aAAa,CAAC,KAAK,CAAC,KAAK,SAAS,MAAM,EACvD,IAAI,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC,EACzC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,eAAe,CAAC,EAC3D,OAAO,CAAC,EAAE,gBAAgB,oMAU1B"}
|
|
@@ -3,12 +3,12 @@ import { AssignRoles } from "@shivaedev/access/roles.ts";
|
|
|
3
3
|
import { SessionUser } from "@shivaedev/identity/identity.ts";
|
|
4
4
|
import { hasPermission } from "@shivaedev/identity/permission.ts";
|
|
5
5
|
import { changeUserRole, listUsers } from "#server/users.ts";
|
|
6
|
-
export function usersHandlers(page, access) {
|
|
6
|
+
export function usersHandlers(page, access, options) {
|
|
7
7
|
return page.contract.application.toLayer({
|
|
8
|
-
"admin.users.changeRole": (input) => changeUserRole(access, input),
|
|
8
|
+
"admin.users.changeRole": (input) => changeUserRole(access, input, options),
|
|
9
9
|
"admin.users.list": (input) => Effect.gen(function* () {
|
|
10
10
|
const user = yield* SessionUser;
|
|
11
|
-
return { ...(yield* listUsers(access, input)), canChangeRoles: hasPermission(user, AssignRoles) };
|
|
11
|
+
return { ...(yield* listUsers(access, input, options)), canChangeRoles: hasPermission(user, AssignRoles) };
|
|
12
12
|
}),
|
|
13
13
|
});
|
|
14
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usersHandlers.js","sourceRoot":"","sources":["../../src/server/usersHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"usersHandlers.js","sourceRoot":"","sources":["../../src/server/usersHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAElE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG7D,MAAM,UAAU,aAAa,CAC5B,IAAyC,EACzC,MAA2D,EAC3D,OAA0B;IAE1B,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC;QACxC,wBAAwB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC;QAC3E,kBAAkB,EAAE,CAAC,KAAK,EAAE,EAAE,CAC7B,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;YACnB,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,WAAW,CAAC;YAChC,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,EAAE,cAAc,EAAE,aAAa,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,CAAC;QAC5G,CAAC,CAAC;KACH,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/admin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.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": {
|
|
@@ -42,20 +42,21 @@
|
|
|
42
42
|
"README.md"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@shivaedev/access": "0.3.
|
|
46
|
-
"@shivaedev/changes": "0.
|
|
47
|
-
"@shivaedev/contract": "0.30.
|
|
48
|
-
"@shivaedev/errors": "0.
|
|
49
|
-
"@shivaedev/identity": "0.
|
|
50
|
-
"@shivaedev/jobs": "0.29.
|
|
51
|
-
"@shivaedev/react": "0.
|
|
45
|
+
"@shivaedev/access": "0.3.6",
|
|
46
|
+
"@shivaedev/changes": "0.7.0",
|
|
47
|
+
"@shivaedev/contract": "0.30.2",
|
|
48
|
+
"@shivaedev/errors": "0.5.0",
|
|
49
|
+
"@shivaedev/identity": "0.18.0",
|
|
50
|
+
"@shivaedev/jobs": "0.29.2",
|
|
51
|
+
"@shivaedev/react": "0.33.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@effect/atom-react": "4.0.6",
|
|
55
|
-
"@shivaedev/quality": "0.
|
|
56
|
-
"@shivaedev/server": "0.
|
|
57
|
-
"@shivaedev/
|
|
58
|
-
"@shivaedev/test-
|
|
55
|
+
"@shivaedev/quality": "0.55.0",
|
|
56
|
+
"@shivaedev/server": "0.18.0",
|
|
57
|
+
"@shivaedev/sql": "0.32.0",
|
|
58
|
+
"@shivaedev/test-sql": "0.16.1",
|
|
59
|
+
"@shivaedev/test-story": "0.33.0",
|
|
59
60
|
"@types/node": "24.19.2",
|
|
60
61
|
"@types/react": "19.3.0",
|
|
61
62
|
"@types/react-dom": "19.3.0",
|
|
@@ -2,13 +2,16 @@ import type { AdminRoute } from "#page.ts";
|
|
|
2
2
|
|
|
3
3
|
export function matchAdminRoute(routes: readonly AdminRoute[], pathname: string): AdminRoute | undefined {
|
|
4
4
|
const path = pathname.replace(/\/$/u, "");
|
|
5
|
+
if (path === "/admin") {
|
|
6
|
+
return routes[0];
|
|
7
|
+
}
|
|
5
8
|
return (
|
|
6
9
|
routes.find((route) => route.path.replace(/\/$/u, "") === path)
|
|
7
10
|
?? routes.find((route) => {
|
|
8
11
|
if (route.detail === undefined) {
|
|
9
12
|
return false;
|
|
10
13
|
}
|
|
11
|
-
const expected = route.detail.split("/");
|
|
14
|
+
const expected = route.detail.replace(/\/$/u, "").split("/");
|
|
12
15
|
const actual = path.split("/");
|
|
13
16
|
return (
|
|
14
17
|
expected.length === actual.length
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { AdminRoute } from "#page.ts";
|
|
2
|
+
|
|
3
|
+
function overlaps(left: string, right: string): boolean {
|
|
4
|
+
const expected = left.split("/");
|
|
5
|
+
const actual = right.split("/");
|
|
6
|
+
return (
|
|
7
|
+
expected.length === actual.length
|
|
8
|
+
&& expected.every(
|
|
9
|
+
(segment, index) => segment === actual[index] || (segment === "$" && actual[index] !== "") || (actual[index] === "$" && segment !== ""),
|
|
10
|
+
)
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function pathsOf(route: AdminRoute): readonly string[] {
|
|
15
|
+
const page = route.path.replace(/\/$/u, "");
|
|
16
|
+
const detail = route.detail?.replace(/\/$/u, "");
|
|
17
|
+
if (detail !== undefined && !detail.startsWith(`${page}/`)) {
|
|
18
|
+
throw new Error(`Admin detail path ${route.detail} must be under page path ${route.path}`);
|
|
19
|
+
}
|
|
20
|
+
return detail === undefined ? [page] : [page, detail];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function validateAdminRoutes(routes: readonly AdminRoute[]): void {
|
|
24
|
+
const paths: string[] = [];
|
|
25
|
+
for (const path of routes.flatMap(pathsOf)) {
|
|
26
|
+
const normalized = path.replace(/\$[^/]+/gu, "$");
|
|
27
|
+
if (paths.includes(normalized)) {
|
|
28
|
+
throw new Error(`Duplicate admin path: ${normalized}`);
|
|
29
|
+
}
|
|
30
|
+
const existing = paths.find((candidate) => overlaps(candidate, normalized));
|
|
31
|
+
if (existing !== undefined) {
|
|
32
|
+
throw new Error(`Overlapping admin paths: ${existing} and ${normalized}`);
|
|
33
|
+
}
|
|
34
|
+
paths.push(normalized);
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/page.ts
CHANGED
|
@@ -62,33 +62,37 @@ export function adminPage<
|
|
|
62
62
|
TRpcs extends Rpc.AnyWithProps,
|
|
63
63
|
const TStreams extends readonly StreamShape[],
|
|
64
64
|
TMiddleware extends RpcMiddleware.AnyService & PagePermission,
|
|
65
|
+
const TScope extends "session" | undefined = undefined,
|
|
65
66
|
>(page: {
|
|
66
67
|
readonly id: TId;
|
|
67
68
|
readonly route: TRoute;
|
|
68
69
|
readonly permission: TMiddleware;
|
|
69
|
-
readonly contract: Contract<TName, TQueries, TCommands, TRpcs, TStreams>;
|
|
70
|
+
readonly contract: Contract<TName, TQueries, TCommands, TRpcs, TStreams, TScope>;
|
|
70
71
|
}): AdminPage & {
|
|
71
72
|
readonly route: TRoute & { readonly permission: Permission };
|
|
72
73
|
readonly id: TId;
|
|
73
74
|
readonly permissionKey: TMiddleware["key"];
|
|
74
|
-
readonly contract: Contract<TName, PageQueries<TQueries>, TCommands, Rpc.AddMiddleware<PageRpcs<TRpcs>, TMiddleware>, TStreams>;
|
|
75
|
+
readonly contract: Contract<TName, PageQueries<TQueries>, TCommands, Rpc.AddMiddleware<PageRpcs<TRpcs>, TMiddleware>, TStreams, TScope>;
|
|
75
76
|
};
|
|
76
77
|
export function adminPage(page: {
|
|
77
78
|
readonly id: string;
|
|
78
79
|
readonly route: Omit<AdminRoute, "permission">;
|
|
79
80
|
readonly permission: PagePermission & RpcMiddleware.AnyService;
|
|
80
81
|
readonly contract: {
|
|
81
|
-
readonly declaration: Declared<string, readonly QueryShape[], readonly CommandShape[], readonly StreamShape[]>;
|
|
82
|
+
readonly declaration: Declared<string, readonly QueryShape[], readonly CommandShape[], readonly StreamShape[], "session" | undefined>;
|
|
82
83
|
readonly requests: ReadonlyMap<string, Rpc.AnyWithProps>;
|
|
83
84
|
};
|
|
84
85
|
}): AdminPage {
|
|
85
86
|
const { declaration } = page.contract;
|
|
86
87
|
const queries = declaration.queries.map((query) => ({
|
|
87
88
|
...query,
|
|
88
|
-
readPolicy: (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
readPolicy: Object.assign(
|
|
90
|
+
(payload: unknown, viewer: Option.Option<Viewer>) =>
|
|
91
|
+
Effect.flatMap(SessionUser, (user) =>
|
|
92
|
+
hasPermission(user, page.permission.permission) ? (query.readPolicy?.(payload, viewer) ?? Effect.succeed(true)) : Effect.succeed(false),
|
|
93
|
+
),
|
|
94
|
+
query.readPolicy,
|
|
95
|
+
),
|
|
92
96
|
}));
|
|
93
97
|
let protectedContract: PageGroup = contract(declaration.name, { ...declaration, queries });
|
|
94
98
|
const original = page.contract.requests.values().next().value;
|
package/src/registry.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RpcGroup } from "effect/rpc";
|
|
2
|
+
import { validateAdminRoutes } from "#adapters/validateAdminRoutes.ts";
|
|
2
3
|
import type { AdminPage } from "./page.ts";
|
|
3
4
|
|
|
4
5
|
export interface AdminRegistry<TPages extends readonly AdminPage[]> {
|
|
@@ -38,7 +39,6 @@ export function mergeAdminRegistries(...registries: readonly AnyAdminRegistry[])
|
|
|
38
39
|
|
|
39
40
|
export function adminRegistry<const TPages extends readonly AdminPage[]>(...pages: TPages & UniquePageIds<TPages>): AdminRegistry<TPages> {
|
|
40
41
|
const ids = new Set<string>();
|
|
41
|
-
const paths = new Set<string>();
|
|
42
42
|
const tags = new Set<string>();
|
|
43
43
|
function unique(seen: Set<string>, value: string, kind: string) {
|
|
44
44
|
if (seen.has(value)) {
|
|
@@ -48,12 +48,10 @@ export function adminRegistry<const TPages extends readonly AdminPage[]>(...page
|
|
|
48
48
|
}
|
|
49
49
|
for (const page of pages) {
|
|
50
50
|
unique(ids, page.id, "page id");
|
|
51
|
-
for (const path of [page.route.path, ...(page.route.detail === undefined ? [] : [page.route.detail])]) {
|
|
52
|
-
unique(paths, path.replace(/\$[^/]+/gu, "$").replace(/\/$/u, ""), "path");
|
|
53
|
-
}
|
|
54
51
|
for (const tag of page.contract.requests.keys()) {
|
|
55
52
|
unique(tags, tag, "RPC tag");
|
|
56
53
|
}
|
|
57
54
|
}
|
|
55
|
+
validateAdminRoutes(pages.map((page) => page.route));
|
|
58
56
|
return { group: RpcGroup.make().merge(...pages.map((page) => page.contract)), pages };
|
|
59
57
|
}
|
|
@@ -5,7 +5,6 @@ import * as HttpStatus from "effect/http/HttpStatus";
|
|
|
5
5
|
import { permissionRoute } from "@shivaedev/identity/server/permissions.ts";
|
|
6
6
|
import { matchAdminRoute } from "#adapters/matchAdminRoute.ts";
|
|
7
7
|
import type { AnyAdminRegistry } from "#registry.ts";
|
|
8
|
-
import { AdminSessions } from "./AdminSessions.ts";
|
|
9
8
|
|
|
10
9
|
export function adminDocuments<E, R>(
|
|
11
10
|
registry: AnyAdminRegistry,
|
|
@@ -14,13 +13,12 @@ export function adminDocuments<E, R>(
|
|
|
14
13
|
const routes = registry.pages.map((page) => page.route);
|
|
15
14
|
return HttpRouter.use((router) =>
|
|
16
15
|
Effect.gen(function* () {
|
|
17
|
-
const sessions = yield* AdminSessions;
|
|
18
16
|
yield* router.add("GET", "/admin/*", (request) => {
|
|
19
17
|
const path = new URL(request.url, "http://localhost").pathname;
|
|
20
|
-
const route =
|
|
18
|
+
const route = matchAdminRoute(routes, path);
|
|
21
19
|
return route === undefined
|
|
22
20
|
? Effect.succeed(HttpServerResponse.empty({ status: HttpStatus.fromLiteral("NotFound") }))
|
|
23
|
-
: permissionRoute(
|
|
21
|
+
: permissionRoute(route.permission)(handler)(request);
|
|
24
22
|
});
|
|
25
23
|
}),
|
|
26
24
|
);
|
|
@@ -1,31 +1,16 @@
|
|
|
1
|
-
import { Context,
|
|
1
|
+
import { Context, Layer } from "effect";
|
|
2
2
|
import type { RpcMiddleware } from "effect/rpc";
|
|
3
3
|
import type { Identity, SessionUser } from "@shivaedev/identity/identity.ts";
|
|
4
4
|
import type { IdentityFailures } from "@shivaedev/identity/middleware.ts";
|
|
5
5
|
import { permissionLayer } from "@shivaedev/identity/server/permissions.ts";
|
|
6
6
|
import type { AnyAdminRegistry } from "#registry.ts";
|
|
7
|
-
import { AdminSessions } from "./AdminSessions.ts";
|
|
8
7
|
|
|
9
8
|
export function pagePermissions(registry: AnyAdminRegistry) {
|
|
10
|
-
return Layer.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const page = registry.pages[0];
|
|
16
|
-
return yield* Effect.die(
|
|
17
|
-
new Error(`Missing admin permission policy: page ${page?.id}, permission ${page?.route.permission.name}; provide AdminSessions`),
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
return Layer.mergeAll(
|
|
21
|
-
Layer.empty,
|
|
22
|
-
...registry.pages.map((page) => {
|
|
23
|
-
const middleware = Context.Service<unknown, RpcMiddleware.RpcMiddleware<Identity | SessionUser, IdentityFailures, never>>(
|
|
24
|
-
page.permissionKey,
|
|
25
|
-
);
|
|
26
|
-
return permissionLayer(Object.assign(middleware, { permission: page.route.permission }), sessions.value);
|
|
27
|
-
}),
|
|
28
|
-
);
|
|
9
|
+
return Layer.mergeAll(
|
|
10
|
+
Layer.empty,
|
|
11
|
+
...registry.pages.map((page) => {
|
|
12
|
+
const middleware = Context.Service<unknown, RpcMiddleware.RpcMiddleware<Identity | SessionUser, IdentityFailures, never>>(page.permissionKey);
|
|
13
|
+
return permissionLayer(Object.assign(middleware, { permission: page.route.permission }));
|
|
29
14
|
}),
|
|
30
15
|
);
|
|
31
16
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Effect, Layer } from "effect";
|
|
2
2
|
import type { Rpc, RpcGroup } from "effect/rpc";
|
|
3
|
+
import type { SessionPolicy } from "@shivaedev/identity/server/SessionPolicy.ts";
|
|
3
4
|
import type { AdminPage } from "#page.ts";
|
|
4
5
|
import type { AdminRegistry } from "#registry.ts";
|
|
5
|
-
import type { AdminSessions } from "./AdminSessions.ts";
|
|
6
6
|
import { pagePermissions } from "./pagePermissions.ts";
|
|
7
7
|
|
|
8
8
|
type HandlerLayers<TPages extends readonly AdminPage[]> = {
|
|
@@ -21,7 +21,7 @@ export function registerAdmin<const TPages extends readonly AdminPage[], THandle
|
|
|
21
21
|
| Layer.Success<RegisteredLayers<THandlers>>
|
|
22
22
|
| Extract<Rpc.Middleware<RpcGroup.Rpcs<TPages[number]["contract"]>>, { readonly key: TPages[number]["permissionKey"] }>,
|
|
23
23
|
Layer.Error<RegisteredLayers<THandlers>>,
|
|
24
|
-
Layer.Services<RegisteredLayers<THandlers>> |
|
|
24
|
+
Layer.Services<RegisteredLayers<THandlers>> | SessionPolicy
|
|
25
25
|
>;
|
|
26
26
|
};
|
|
27
27
|
export function registerAdmin(
|
package/src/server/users.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { AssignRoles } from "@shivaedev/access/roles.ts";
|
|
|
6
6
|
import { AuthUnavailable } from "@shivaedev/errors/taxonomy.ts";
|
|
7
7
|
import { SessionUser } from "@shivaedev/identity/identity.ts";
|
|
8
8
|
import { assignRole } from "@shivaedev/identity/server/better-auth/assignRole.ts";
|
|
9
|
+
import { type AuthTableOptions, tables } from "@shivaedev/identity/server/better-auth/tables.ts";
|
|
9
10
|
import { ReadUsers } from "#permissions.ts";
|
|
10
11
|
import { AppUser, type ChangeRoleInput, type UserListInput } from "#users/roles.ts";
|
|
11
12
|
|
|
@@ -16,11 +17,14 @@ function unavailable() {
|
|
|
16
17
|
export const listUsers = Effect.fn("Admin.listUsers")(function* <TRole extends string>(
|
|
17
18
|
access: Pick<AccessPolicy<TRole>, "Role">,
|
|
18
19
|
input: typeof UserListInput.Type,
|
|
20
|
+
options?: AuthTableOptions,
|
|
19
21
|
) {
|
|
20
22
|
yield* requirePermission(yield* SessionUser, ReadUsers);
|
|
21
|
-
const sql = yield* SqlClient.SqlClient;
|
|
23
|
+
const sql = (yield* SqlClient.SqlClient).withoutTransforms();
|
|
24
|
+
const { user } = tables(options);
|
|
22
25
|
const read = SqlSchema.findAll({
|
|
23
|
-
execute: () => sql`select id, name
|
|
26
|
+
execute: () => sql`select id, ${sql(user.name)} as name, ${sql(user.email)} as email,
|
|
27
|
+
${sql(user.role)} as role, ${sql(user.createdAt)} as "createdAt" from ${sql(user.table)}
|
|
24
28
|
where id > ${input.cursor ?? ""} order by id limit ${input.limit + 1}`,
|
|
25
29
|
Request: Schema.Void,
|
|
26
30
|
Result: Schema.Struct({ ...AppUser.fields, role: access.Role }),
|
|
@@ -33,10 +37,11 @@ export const listUsers = Effect.fn("Admin.listUsers")(function* <TRole extends s
|
|
|
33
37
|
export const changeUserRole = Effect.fn("Admin.changeUserRole")(function* <TRole extends string>(
|
|
34
38
|
access: Pick<AccessPolicy<TRole>, "Role" | "hasPermission">,
|
|
35
39
|
input: ChangeRoleInput<TRole>,
|
|
40
|
+
options?: AuthTableOptions,
|
|
36
41
|
) {
|
|
37
42
|
const actor = yield* SessionUser;
|
|
38
43
|
yield* requirePermission(actor, AssignRoles);
|
|
39
|
-
const changed = yield* assignRole(access, input.userId, input.role);
|
|
44
|
+
const changed = yield* assignRole(access, input.userId, input.role, options);
|
|
40
45
|
if (changed) {
|
|
41
46
|
const changedAt = DateTime.formatIso(yield* DateTime.now);
|
|
42
47
|
yield* Effect.logInfo("User role changed").pipe(Effect.annotateLogs({ actorId: actor.id, changedAt, ...input }));
|
|
@@ -3,19 +3,21 @@ import type { AccessPolicy } from "@shivaedev/access/roleSet.ts";
|
|
|
3
3
|
import { AssignRoles } from "@shivaedev/access/roles.ts";
|
|
4
4
|
import { SessionUser } from "@shivaedev/identity/identity.ts";
|
|
5
5
|
import { hasPermission } from "@shivaedev/identity/permission.ts";
|
|
6
|
+
import type { AuthTableOptions } from "@shivaedev/identity/server/better-auth/tables.ts";
|
|
6
7
|
import { changeUserRole, listUsers } from "#server/users.ts";
|
|
7
8
|
import type { usersPage } from "#users/page.ts";
|
|
8
9
|
|
|
9
10
|
export function usersHandlers<const TRole extends string>(
|
|
10
11
|
page: ReturnType<typeof usersPage<TRole>>,
|
|
11
12
|
access: Pick<AccessPolicy<TRole>, "Role" | "hasPermission">,
|
|
13
|
+
options?: AuthTableOptions,
|
|
12
14
|
) {
|
|
13
15
|
return page.contract.application.toLayer({
|
|
14
|
-
"admin.users.changeRole": (input) => changeUserRole(access, input),
|
|
16
|
+
"admin.users.changeRole": (input) => changeUserRole(access, input, options),
|
|
15
17
|
"admin.users.list": (input) =>
|
|
16
18
|
Effect.gen(function* () {
|
|
17
19
|
const user = yield* SessionUser;
|
|
18
|
-
return { ...(yield* listUsers(access, input)), canChangeRoles: hasPermission(user, AssignRoles) };
|
|
20
|
+
return { ...(yield* listUsers(access, input, options)), canChangeRoles: hasPermission(user, AssignRoles) };
|
|
19
21
|
}),
|
|
20
22
|
});
|
|
21
23
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Context } from "effect";
|
|
2
|
-
import type { SessionPolicy, UserSessionShape } from "@shivaedev/identity/server/session.ts";
|
|
3
|
-
declare const AdminSessions_base: Context.ServiceClass<AdminSessions, "@shivaedev/admin/AdminSessions", SessionPolicy<UserSessionShape>>;
|
|
4
|
-
export declare class AdminSessions extends AdminSessions_base {
|
|
5
|
-
}
|
|
6
|
-
export {};
|
|
7
|
-
//# sourceMappingURL=AdminSessions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AdminSessions.d.ts","sourceRoot":"","sources":["../../src/server/AdminSessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;;AAE7F,qBAAa,aAAc,SAAQ,kBAAmG;CAAG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AdminSessions.js","sourceRoot":"","sources":["../../src/server/AdminSessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGjC,MAAM,OAAO,aAAc,SAAQ,OAAO,CAAC,OAAO,EAAkD,CAAC,gCAAgC,CAAC;CAAG"}
|