@shivaedev/admin 0.17.0 → 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 +19 -0
- package/README.md +6 -6
- 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/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.js +1 -1
- package/dist/server/adminDocuments.js.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/dist/users/page.d.ts +5 -5
- 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 +1 -1
- package/src/server/users.ts +8 -3
- package/src/server/usersHandlers.ts +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
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
|
+
|
|
3
22
|
## 0.17.0 - 2026-11-01
|
|
4
23
|
|
|
5
24
|
### Changed
|
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ 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
|
|
|
@@ -77,9 +77,9 @@ Pass `registration.group` and `handlers` to the existing application's RPC host
|
|
|
77
77
|
|
|
78
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.
|
|
79
79
|
|
|
80
|
-
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.
|
|
81
81
|
|
|
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/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.
|
|
83
83
|
|
|
84
84
|
### Pages owned by modules
|
|
85
85
|
|
|
@@ -210,7 +210,7 @@ A successful bound retry invalidates health, the affected queue's counts and bot
|
|
|
210
210
|
|
|
211
211
|
### Built-in Users page
|
|
212
212
|
|
|
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
|
|
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.
|
|
214
214
|
|
|
215
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.
|
|
216
216
|
|
|
@@ -229,7 +229,7 @@ const changeRole = Client.runtime.fn(users.changeRole.run);
|
|
|
229
229
|
|
|
230
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.
|
|
231
231
|
|
|
232
|
-
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.
|
|
233
233
|
|
|
234
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.
|
|
235
235
|
|
|
@@ -255,7 +255,7 @@ The view lists signed-in sessions with the user's name and email, started, last
|
|
|
255
255
|
|
|
256
256
|
### Client permission routes
|
|
257
257
|
|
|
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/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.
|
|
259
259
|
|
|
260
260
|
### Install and limits
|
|
261
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,CAA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CAAC,CAAC,CAAC,CACnH,CAAC;QACH,CAAC,CAAC,CACF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateAdminRoutes.d.ts","sourceRoot":"","sources":["../../src/adapters/validateAdminRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,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,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChC,OAAO,CACN,QAAQ,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM;WAC9B,QAAQ,CAAC,KAAK,CAChB,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,KAAK,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,OAAO,KAAK,EAAE,CAAC,CACvI,CACD,CAAC;AACH,CAAC;AAED,SAAS,OAAO,CAAC,KAAiB;IACjC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC5C,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACjD,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC;QAC5D,MAAM,IAAI,KAAK,CAAC,qBAAqB,KAAK,CAAC,MAAM,4BAA4B,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5F,CAAC;IACD,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,MAA6B;IAChE,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5C,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,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/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,K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Q,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,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","sourceR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,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CACvI,EACF,KAAK,CAAC,UAAU,CAChB;KACD,CAAC,CAAC,CAAC;IACJ,IAAI,iBAAiB,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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AE,EACzF,GAAG,UAAU,EAAE,WAAW,GAAG,aAAa,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,GACpE,aAAa,CAAC,aAAa,CAAC,WAAW,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;
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAkCvE,MAAM,UAAU,oBAAoB,CAAC,GAAG,UAAuC;IAC9E,OAAO,aAAa,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,aAAa,CAA4C,GAAG,KAAqC;IAChH,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9B,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,SAAS,MAAM,CAAC,IAAiB,EAAE,KAAa,EAAE,IAAY;QAC7D,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC;QACtD,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;QAChC,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC;YACjD,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;QAC9B,CAAC;IACF,CAAC;IACD,mBAAmB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACrD,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;AACvF,CAAC"}
|
|
@@ -8,7 +8,7 @@ export function adminDocuments(registry, handler) {
|
|
|
8
8
|
return HttpRouter.use((router) => Effect.gen(function* () {
|
|
9
9
|
yield* router.add("GET", "/admin/*", (request) => {
|
|
10
10
|
const path = new URL(request.url, "http://localhost").pathname;
|
|
11
|
-
const route =
|
|
11
|
+
const route = matchAdminRoute(routes, path);
|
|
12
12
|
return route === undefined
|
|
13
13
|
? Effect.succeed(HttpServerResponse.empty({ status: HttpStatus.fromLiteral("NotFound") }))
|
|
14
14
|
: permissionRoute(route.permission)(handler)(request);
|
|
@@ -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;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,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AAM,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"}
|
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,iCAAiC,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,sDAAsD,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAA4C,MAAM,iBAAiB,CAAC;AAEpF,SAAS,WAAW;IACnB,OAAO,IAAI,eAAe,CAAC,EAAE,OAAO,EAAE,4BAA4B,EAAE,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC,QAAQ,CAAC,EAC9D,MAAyC,EACzC,KAAgC;
|
|
1
|
+
{"version":3,"file":"users.js","sourceRoot":"","sources":["../../src/server/users.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EA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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/dist/users/page.d.ts
CHANGED
|
@@ -78,7 +78,10 @@ export declare function usersPage<const TRole extends string>(access: Pick<Acces
|
|
|
78
78
|
readonly queryIndexes: Schema.optional<Schema.$Array<Schema.Number>>;
|
|
79
79
|
}>, Schema.Struct<{
|
|
80
80
|
readonly _tag: Schema.Literal<"Resync">;
|
|
81
|
-
}>]>, ...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 Forbidden | typeof AuthUnavailable)[]>[]]>>, Schema.Never, typeof UsersPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.users.
|
|
81
|
+
}>]>, ...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 Forbidden | typeof AuthUnavailable)[]>[]]>>, Schema.Never, typeof UsersPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.users.changeRole", Schema.Struct<{
|
|
82
|
+
role: Schema.Literals<TRole[]>;
|
|
83
|
+
userId: Schema.String;
|
|
84
|
+
}>, Schema.Void, Schema.Union<readonly (typeof NotFound | typeof Forbidden | typeof AuthUnavailable | typeof LastRoleAssigner)[]>, typeof UsersPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.users.list", Schema.Struct<{
|
|
82
85
|
readonly cursor: Schema.optionalKey<Schema.String>;
|
|
83
86
|
readonly limit: Schema.Number;
|
|
84
87
|
}>, Schema.Struct<{
|
|
@@ -91,9 +94,6 @@ export declare function usersPage<const TRole extends string>(access: Pick<Acces
|
|
|
91
94
|
readonly role: Schema.String;
|
|
92
95
|
}>>;
|
|
93
96
|
readonly canChangeRoles: Schema.Boolean;
|
|
94
|
-
}>, Schema.Union<readonly [Schema.Union<readonly (typeof Forbidden | typeof AuthUnavailable)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof UsersPermission, never
|
|
95
|
-
role: Schema.Literals<TRole[]>;
|
|
96
|
-
userId: Schema.String;
|
|
97
|
-
}>, Schema.Void, Schema.Union<readonly (typeof NotFound | typeof Forbidden | typeof AuthUnavailable | typeof LastRoleAssigner)[]>, typeof UsersPermission, never>, readonly [], undefined>;
|
|
97
|
+
}>, Schema.Union<readonly [Schema.Union<readonly (typeof Forbidden | typeof AuthUnavailable)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof UsersPermission, never>, readonly [], undefined>;
|
|
98
98
|
};
|
|
99
99
|
//# sourceMappingURL=page.d.ts.map
|
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
|
}
|
|
@@ -15,7 +15,7 @@ export function adminDocuments<E, R>(
|
|
|
15
15
|
Effect.gen(function* () {
|
|
16
16
|
yield* router.add("GET", "/admin/*", (request) => {
|
|
17
17
|
const path = new URL(request.url, "http://localhost").pathname;
|
|
18
|
-
const route =
|
|
18
|
+
const route = matchAdminRoute(routes, path);
|
|
19
19
|
return route === undefined
|
|
20
20
|
? Effect.succeed(HttpServerResponse.empty({ status: HttpStatus.fromLiteral("NotFound") }))
|
|
21
21
|
: permissionRoute(route.permission)(handler)(request);
|
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
|
}
|