@shivaedev/admin 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -9
- package/dist/jobs/page.d.ts +6 -6
- package/dist/jobs/retryPage.d.ts +37 -37
- package/dist/page.d.ts +2 -2
- package/dist/page.d.ts.map +1 -1
- package/dist/page.js +2 -2
- package/dist/page.js.map +1 -1
- package/dist/permissions.d.ts +15 -0
- package/dist/permissions.d.ts.map +1 -0
- package/dist/permissions.js +6 -0
- package/dist/permissions.js.map +1 -0
- package/dist/server/usersHandlers.d.ts.map +1 -1
- package/dist/server/usersHandlers.js +3 -2
- package/dist/server/usersHandlers.js.map +1 -1
- package/dist/users/page.d.ts +6 -6
- package/package.json +3 -2
- package/src/page.ts +3 -3
- package/src/permissions.ts +5 -0
- package/src/server/usersHandlers.ts +3 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @shivaedev/admin
|
|
2
2
|
|
|
3
|
-
Admin tooling starts with an explicit list of pages and the operations each page needs. This package collects native Effect contracts behind
|
|
3
|
+
Admin tooling starts with an explicit list of pages and the operations each page needs. This package collects native Effect contracts behind a declared permission, so every page operation shares the same boundary.
|
|
4
4
|
|
|
5
5
|
## Declare the tools operators can use
|
|
6
6
|
|
|
@@ -13,7 +13,7 @@ const Jobs = adminPage({
|
|
|
13
13
|
const Admin = adminRegistry(Jobs);
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
The page exposes `admin.jobs.failed` and the generated `admin.jobs.$changes` subscription. Both require `
|
|
16
|
+
The page exposes `admin.jobs.failed` and the generated `admin.jobs.$changes` subscription. Both require `AdminPermission`, which checks the `OpenAdmin` permission (`admin.open`). A query-only contract has no command. The application grants this permission to its chosen roles.
|
|
17
17
|
|
|
18
18
|
## Use native contracts and Layers
|
|
19
19
|
|
|
@@ -45,7 +45,8 @@ Register server handler Layers by page id:
|
|
|
45
45
|
```ts
|
|
46
46
|
import { Effect, Layer } from "effect";
|
|
47
47
|
import { registerAdmin } from "@shivaedev/admin/server/registerAdmin.ts";
|
|
48
|
-
import {
|
|
48
|
+
import { AdminPermission, OpenAdmin } from "@shivaedev/admin/permissions.ts";
|
|
49
|
+
import { permissionLayer } from "@shivaedev/platform/server/rpc-server/permissions.ts";
|
|
49
50
|
|
|
50
51
|
const registration = registerAdmin(Admin, {
|
|
51
52
|
jobs: Jobs.contract.application.toLayer({
|
|
@@ -53,13 +54,15 @@ const registration = registerAdmin(Admin, {
|
|
|
53
54
|
}),
|
|
54
55
|
});
|
|
55
56
|
const handlers = registration.handlers.pipe(
|
|
56
|
-
Layer.provideMerge(
|
|
57
|
+
Layer.provideMerge(permissionLayer(AdminPermission, sessions)),
|
|
57
58
|
);
|
|
58
59
|
```
|
|
59
60
|
|
|
61
|
+
Declare application roles with `@shivaedev/access`, grant `OpenAdmin` explicitly, and supply that role set through Platform's session or auth configuration.
|
|
62
|
+
|
|
60
63
|
Pass `registration.group` and `handlers` to the existing application's RPC host on `/rpc`, merging them with its other groups and Layers as needed. The Platform host supplies generated change handlers; registration requires the page's application handlers. Handler Layer errors and service requirements remain inferred. Missing or extra page ids fail at registration; TypeScript also checks each Layer provides the handlers for its page.
|
|
61
64
|
|
|
62
|
-
Page declarations and the registry are browser-safe. Server registration lives under `/server`; applications own route composition and styling. The built-in Users view uses React; server declarations add no transport. The package's stories prove
|
|
65
|
+
Page declarations and the registry are browser-safe. Server registration lives under `/server`; applications own route composition and styling. The built-in Users view uses React; server declarations add no transport. The package's stories prove permission enforcement through native in-process RPC, with an already resolved session as a precondition.
|
|
63
66
|
|
|
64
67
|
## Built-in Jobs page
|
|
65
68
|
|
|
@@ -90,7 +93,7 @@ The queries are `admin.jobs.health`, `admin.jobs.counts`, `admin.jobs.failed`, `
|
|
|
90
93
|
|
|
91
94
|
Health filters the runtime's monitor snapshot to the page's queues and recomputes totals from those queues. It has the same refresh timing as effect-pg-boss health. Unregistered names, including dead-letter queue names passed directly, fail with `JobsQueueUnregistered`. Stored payload decoding failures become `JobsPayloadInvalid`; jobs operation failures become `JobsUnavailable`, carrying the operation name. These declared failures do not expose the original database error.
|
|
92
95
|
|
|
93
|
-
The default `jobsPage` declares no commands, and its bound client has no retry operation. Handler registration performs no jobs read, and a failed jobs request leaves other pages available. PostgreSQL stories exercise these queries through serialized `/rpc` requests, including pagination, transformed payloads, missing jobs, queue restrictions and
|
|
96
|
+
The default `jobsPage` declares no commands, and its bound client has no retry operation. Handler registration performs no jobs read, and a failed jobs request leaves other pages available. PostgreSQL stories exercise these queries through serialized `/rpc` requests, including pagination, transformed payloads, missing jobs, queue restrictions and permission enforcement. The application supplies the Jobs view and mounts the registration on its existing RPC host.
|
|
94
97
|
|
|
95
98
|
### Declare retry explicitly
|
|
96
99
|
|
|
@@ -107,7 +110,7 @@ const registration = registerAdmin(Admin, {
|
|
|
107
110
|
});
|
|
108
111
|
```
|
|
109
112
|
|
|
110
|
-
This variant adds only `admin.jobs.retry`, taking `{ queue, id }` and returning void. It requires
|
|
113
|
+
This variant adds only `admin.jobs.retry`, taking `{ queue, id }` and returning void. It requires `OpenAdmin`, through the same page middleware. The handler uses effect-pg-boss's existing retry for a failed job in a declared queue. Missing jobs and jobs in other states fail with `JobsNotFailed`; unregistered queue names, including dead-letter queues, fail with `JobsQueueUnregistered`. A dead-letter copy's id cannot retry its original.
|
|
111
114
|
|
|
112
115
|
A successful bound retry invalidates health, the affected queue's counts and both listings, and the original job's detail. PostgreSQL stories mount these query atoms, retry through authenticated serialized RPC, and observe refetching and a second worker execution. Health retains the runtime monitor's refresh timing.
|
|
113
116
|
|
|
@@ -126,8 +129,8 @@ const changeRole = Client.runtime.fn(users.changeRole.run);
|
|
|
126
129
|
<UsersView list={users.list.query} changeRole={changeRole} />;
|
|
127
130
|
```
|
|
128
131
|
|
|
129
|
-
`admin.users.list` takes `{ limit, cursor? }` (1–100 users), returns `{ users, next, canChangeRoles }`, and orders pages by user id. Each user has id, name, email, roles and a UTC sign-up time. All reads and subscriptions require `
|
|
132
|
+
`admin.users.list` takes `{ limit, cursor? }` (1–100 users), returns `{ users, next, canChangeRoles }`, and orders pages by user id. Each user has id, name, email, roles and a UTC sign-up time. All reads and subscriptions require `OpenAdmin`. Callers granted `ChangeUserRoles` (`users.roles.change`) from Platform's `rpc/userRoles.ts` see role controls. `admin.users.changeRole` takes `{ userId, role, grant }` for Platform's `user`, `admin` and `owner` roles. It returns typed `Forbidden` without that permission, `LastOwner` when revoking the final owner, and `NotFound` for a missing user. Role changes preserve other roles, invalidate the list after commit, and emit an Effect log with actor id, target id, role, action and timestamp. There is no durable audit-history store.
|
|
130
133
|
|
|
131
|
-
Keep Better Auth cookie caching disabled so requests see current roles. Applications must route role writes through this operation to retain its
|
|
134
|
+
Keep Better Auth cookie caching disabled so requests see current roles. Applications must route role writes through this operation to retain its permission and last-owner policy. The starter disables Better Auth's `/admin/set-role`, `/admin/update-user` and `/admin/create-user` browser endpoints; its server-side bootstrap API remains available.
|
|
132
135
|
|
|
133
136
|
The starter mounts Users beside Jobs and bootstraps new administrators with both `admin` and `owner`. Existing generated apps receive this wiring through `pnpm dlx @shivaedev/create-app@latest update` after release; review conflicts and install dependencies. For an existing database with no owner, bootstrap a new administrator with `pnpm admin:create`.
|
package/dist/jobs/page.d.ts
CHANGED
|
@@ -140,14 +140,14 @@ export declare function jobsPage<const TQueues extends readonly JobsQueue[]>(...
|
|
|
140
140
|
}>]>>;
|
|
141
141
|
}>, Schema.Struct<{
|
|
142
142
|
readonly _tag: Schema.Literal<"Resync">;
|
|
143
|
-
}>]>, Schema.Never>, Schema.Never, typeof import("
|
|
143
|
+
}>]>, Schema.Never>, Schema.Never, typeof import("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.counts", Schema.Struct<{
|
|
144
144
|
queue: Schema.String;
|
|
145
145
|
}>, Schema.Struct<{
|
|
146
146
|
readonly activeCount: Schema.Number;
|
|
147
147
|
readonly failedCount: Schema.Number;
|
|
148
148
|
readonly queuedCount: Schema.Number;
|
|
149
149
|
readonly totalCount: Schema.Number;
|
|
150
|
-
}>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("
|
|
150
|
+
}>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.deadLettered", Schema.Struct<{
|
|
151
151
|
cursor: Schema.optionalKey<Schema.String>;
|
|
152
152
|
limit: Schema.Number;
|
|
153
153
|
queue: Schema.String;
|
|
@@ -168,7 +168,7 @@ export declare function jobsPage<const TQueues extends readonly JobsQueue[]>(...
|
|
|
168
168
|
readonly sourceOutput: Schema.Unknown;
|
|
169
169
|
}>[]>>;
|
|
170
170
|
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
171
|
-
}>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("
|
|
171
|
+
}>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.failed", Schema.Struct<{
|
|
172
172
|
cursor: Schema.optionalKey<Schema.String>;
|
|
173
173
|
limit: Schema.Number;
|
|
174
174
|
queue: Schema.String;
|
|
@@ -187,7 +187,7 @@ export declare function jobsPage<const TQueues extends readonly JobsQueue[]>(...
|
|
|
187
187
|
readonly queue: Schema.Literal<string>;
|
|
188
188
|
}>[]>>;
|
|
189
189
|
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
190
|
-
}>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("
|
|
190
|
+
}>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.health", Schema.Void, Schema.Struct<{
|
|
191
191
|
readonly activeTotal: Schema.Number;
|
|
192
192
|
readonly deadLetteredTotal: Schema.Number;
|
|
193
193
|
readonly failedTotal: Schema.Number;
|
|
@@ -201,7 +201,7 @@ export declare function jobsPage<const TQueues extends readonly JobsQueue[]>(...
|
|
|
201
201
|
}>>;
|
|
202
202
|
readonly queuedTotal: Schema.Number;
|
|
203
203
|
readonly readyTotal: Schema.Number;
|
|
204
|
-
}>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("
|
|
204
|
+
}>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.job", Schema.Struct<{
|
|
205
205
|
id: Schema.String;
|
|
206
206
|
queue: Schema.String;
|
|
207
207
|
}>, Schema.OptionFromNullOr<Schema.Union<Schema.Struct<{
|
|
@@ -216,7 +216,7 @@ export declare function jobsPage<const TQueues extends readonly JobsQueue[]>(...
|
|
|
216
216
|
readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
|
|
217
217
|
readonly data: TQueues[number]["schema"];
|
|
218
218
|
readonly queue: Schema.Literal<string>;
|
|
219
|
-
}>[]>>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("
|
|
219
|
+
}>[]>>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("../permissions.ts").AdminPermission, never>, readonly [], undefined>;
|
|
220
220
|
} & {
|
|
221
221
|
queues: TQueues;
|
|
222
222
|
};
|
package/dist/jobs/retryPage.d.ts
CHANGED
|
@@ -112,22 +112,7 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsQue
|
|
|
112
112
|
readonly JobsQueueUnregistered: typeof import("./schemas.ts").JobsQueueUnregistered;
|
|
113
113
|
readonly JobsUnavailable: typeof import("./schemas.ts").JobsUnavailable;
|
|
114
114
|
readonly JobsNotFailed: typeof JobsNotFailed;
|
|
115
|
-
}>>], import("effect/rpc/Rpc").Rpc<"admin.jobs
|
|
116
|
-
id: Schema.String;
|
|
117
|
-
queue: Schema.String;
|
|
118
|
-
}>, Schema.OptionFromNullOr<Schema.Union<Schema.Struct<{
|
|
119
|
-
readonly attempt: Schema.Number;
|
|
120
|
-
readonly completedOn: Schema.OptionFromNullOr<Schema.DateTimeUtcFromString>;
|
|
121
|
-
readonly createdOn: Schema.DateTimeUtcFromString;
|
|
122
|
-
readonly id: Schema.String;
|
|
123
|
-
readonly output: Schema.Unknown;
|
|
124
|
-
readonly retryCount: Schema.Number;
|
|
125
|
-
readonly retryLimit: Schema.Number;
|
|
126
|
-
readonly startedOn: Schema.OptionFromNullOr<Schema.DateTimeUtcFromString>;
|
|
127
|
-
readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
|
|
128
|
-
readonly data: [...TQueues][number]["schema"];
|
|
129
|
-
readonly queue: Schema.Literal<string>;
|
|
130
|
-
}>[]>>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/platform/rpc/middleware.ts").AuthenticatedAdmin, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.$changes", Schema.Struct<{
|
|
115
|
+
}>>], import("effect/rpc/Rpc").Rpc<"admin.jobs.$changes", Schema.Struct<{
|
|
131
116
|
queries: Schema.$Array<Schema.Union<readonly (Schema.Struct<{
|
|
132
117
|
query: Schema.Literal<"counts">;
|
|
133
118
|
payload: Schema.Struct<{
|
|
@@ -169,28 +154,14 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsQue
|
|
|
169
154
|
}>]>>;
|
|
170
155
|
}>, Schema.Struct<{
|
|
171
156
|
readonly _tag: Schema.Literal<"Resync">;
|
|
172
|
-
}>]>, Schema.Never>, Schema.Never, typeof import("
|
|
157
|
+
}>]>, Schema.Never>, Schema.Never, typeof import("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.counts", Schema.Struct<{
|
|
173
158
|
queue: Schema.String;
|
|
174
159
|
}>, Schema.Struct<{
|
|
175
160
|
readonly activeCount: Schema.Number;
|
|
176
161
|
readonly failedCount: Schema.Number;
|
|
177
162
|
readonly queuedCount: Schema.Number;
|
|
178
163
|
readonly totalCount: Schema.Number;
|
|
179
|
-
}>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("
|
|
180
|
-
readonly activeTotal: Schema.Number;
|
|
181
|
-
readonly deadLetteredTotal: Schema.Number;
|
|
182
|
-
readonly failedTotal: Schema.Number;
|
|
183
|
-
readonly jobs: Schema.$Array<Schema.Struct<{
|
|
184
|
-
readonly activeCount: Schema.Number;
|
|
185
|
-
readonly deadLetteredCount: Schema.Number;
|
|
186
|
-
readonly failedCount: Schema.Number;
|
|
187
|
-
readonly name: Schema.String;
|
|
188
|
-
readonly queuedCount: Schema.Number;
|
|
189
|
-
readonly readyCount: Schema.Number;
|
|
190
|
-
}>>;
|
|
191
|
-
readonly queuedTotal: Schema.Number;
|
|
192
|
-
readonly readyTotal: Schema.Number;
|
|
193
|
-
}>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/platform/rpc/middleware.ts").AuthenticatedAdmin, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.failed", Schema.Struct<{
|
|
164
|
+
}>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.deadLettered", Schema.Struct<{
|
|
194
165
|
cursor: Schema.optionalKey<Schema.String>;
|
|
195
166
|
limit: Schema.Number;
|
|
196
167
|
queue: Schema.String;
|
|
@@ -207,9 +178,11 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsQue
|
|
|
207
178
|
readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
|
|
208
179
|
readonly data: [...TQueues][number]["schema"];
|
|
209
180
|
readonly queue: Schema.Literal<string>;
|
|
181
|
+
readonly sourceId: Schema.OptionFromNullOr<Schema.String>;
|
|
182
|
+
readonly sourceOutput: Schema.Unknown;
|
|
210
183
|
}>[]>>;
|
|
211
184
|
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
212
|
-
}>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("
|
|
185
|
+
}>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.failed", Schema.Struct<{
|
|
213
186
|
cursor: Schema.optionalKey<Schema.String>;
|
|
214
187
|
limit: Schema.Number;
|
|
215
188
|
queue: Schema.String;
|
|
@@ -226,14 +199,41 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsQue
|
|
|
226
199
|
readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
|
|
227
200
|
readonly data: [...TQueues][number]["schema"];
|
|
228
201
|
readonly queue: Schema.Literal<string>;
|
|
229
|
-
readonly sourceId: Schema.OptionFromNullOr<Schema.String>;
|
|
230
|
-
readonly sourceOutput: Schema.Unknown;
|
|
231
202
|
}>[]>>;
|
|
232
203
|
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
233
|
-
}>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("
|
|
204
|
+
}>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.health", Schema.Void, Schema.Struct<{
|
|
205
|
+
readonly activeTotal: Schema.Number;
|
|
206
|
+
readonly deadLetteredTotal: Schema.Number;
|
|
207
|
+
readonly failedTotal: Schema.Number;
|
|
208
|
+
readonly jobs: Schema.$Array<Schema.Struct<{
|
|
209
|
+
readonly activeCount: Schema.Number;
|
|
210
|
+
readonly deadLetteredCount: Schema.Number;
|
|
211
|
+
readonly failedCount: Schema.Number;
|
|
212
|
+
readonly name: Schema.String;
|
|
213
|
+
readonly queuedCount: Schema.Number;
|
|
214
|
+
readonly readyCount: Schema.Number;
|
|
215
|
+
}>>;
|
|
216
|
+
readonly queuedTotal: Schema.Number;
|
|
217
|
+
readonly readyTotal: Schema.Number;
|
|
218
|
+
}>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.job", Schema.Struct<{
|
|
219
|
+
id: Schema.String;
|
|
220
|
+
queue: Schema.String;
|
|
221
|
+
}>, Schema.OptionFromNullOr<Schema.Union<Schema.Struct<{
|
|
222
|
+
readonly attempt: Schema.Number;
|
|
223
|
+
readonly completedOn: Schema.OptionFromNullOr<Schema.DateTimeUtcFromString>;
|
|
224
|
+
readonly createdOn: Schema.DateTimeUtcFromString;
|
|
225
|
+
readonly id: Schema.String;
|
|
226
|
+
readonly output: Schema.Unknown;
|
|
227
|
+
readonly retryCount: Schema.Number;
|
|
228
|
+
readonly retryLimit: Schema.Number;
|
|
229
|
+
readonly startedOn: Schema.OptionFromNullOr<Schema.DateTimeUtcFromString>;
|
|
230
|
+
readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
|
|
231
|
+
readonly data: [...TQueues][number]["schema"];
|
|
232
|
+
readonly queue: Schema.Literal<string>;
|
|
233
|
+
}>[]>>, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered)[]>, typeof import("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.retry", Schema.Struct<{
|
|
234
234
|
id: Schema.String;
|
|
235
235
|
queue: Schema.String;
|
|
236
|
-
}>, Schema.Void, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered | typeof JobsNotFailed)[]>, typeof import("
|
|
236
|
+
}>, Schema.Void, Schema.Union<readonly (typeof import("./schemas.ts").JobsUnavailable | typeof import("./schemas.ts").JobsPayloadInvalid | typeof import("./schemas.ts").JobsQueueUnregistered | typeof JobsNotFailed)[]>, typeof import("../permissions.ts").AdminPermission, never>, readonly [], undefined>;
|
|
237
237
|
} & {
|
|
238
238
|
queues: TQueues;
|
|
239
239
|
};
|
package/dist/page.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Rpc, RpcGroup } from "effect/rpc";
|
|
2
2
|
import type { Contract } from "@shivaedev/effect-contract/contract.ts";
|
|
3
3
|
import type { CommandShape, QueryShape, StreamShape } from "@shivaedev/effect-contract/operation.ts";
|
|
4
|
-
import {
|
|
4
|
+
import { AdminPermission } from "#permissions.ts";
|
|
5
5
|
export interface AdminRoute {
|
|
6
6
|
readonly path: string;
|
|
7
7
|
readonly title: string;
|
|
@@ -22,7 +22,7 @@ export declare function adminPage<const TId extends string, const TName extends
|
|
|
22
22
|
readonly contract: Contract<TName, TQueries, TCommands, TRpcs, TStreams>;
|
|
23
23
|
}): AdminPage & {
|
|
24
24
|
readonly id: TId;
|
|
25
|
-
readonly contract: Contract<TName, TQueries, TCommands, Rpc.AddMiddleware<TRpcs, typeof
|
|
25
|
+
readonly contract: Contract<TName, TQueries, TCommands, Rpc.AddMiddleware<TRpcs, typeof AdminPermission>, TStreams>;
|
|
26
26
|
};
|
|
27
27
|
export {};
|
|
28
28
|
//# 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,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wCAAwC,CAAC;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AACrG,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../src/page.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wCAAwC,CAAC;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AACrG,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACvB;AAED,QAAA,MAAM,eAAe,eAAsC,CAAC;AAE5D,MAAM,WAAW,SAAS;IACzB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,GAAG;QACjC,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,GAAG,CAAC;QACnC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;KAChD,CAAC;IACF,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,CAAC,eAAe,CAAC,EAAE,IAAI,CAAC;CACjC;AAED,wBAAgB,SAAS,CACxB,KAAK,CAAC,GAAG,SAAS,MAAM,EACxB,KAAK,CAAC,KAAK,SAAS,MAAM,EAC1B,KAAK,CAAC,QAAQ,SAAS,SAAS,UAAU,EAAE,EAC5C,KAAK,CAAC,SAAS,SAAS,SAAS,YAAY,EAAE,EAC/C,KAAK,SAAS,GAAG,CAAC,GAAG,EACrB,KAAK,CAAC,QAAQ,SAAS,SAAS,WAAW,EAAE,EAC5C,IAAI,EAAE;IACP,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC;IACjB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;CACzE,GAAG,SAAS,GAAG;IACf,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC;IACjB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,eAAe,CAAC,EAAE,QAAQ,CAAC,CAAC;CACpH,CAEA"}
|
package/dist/page.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AdminPermission } from "#permissions.ts";
|
|
2
2
|
const AdminPageTypeId = Symbol.for("@shivaedev/admin/Page");
|
|
3
3
|
export function adminPage(page) {
|
|
4
|
-
return { ...page, [AdminPageTypeId]: true, contract: page.contract.middleware(
|
|
4
|
+
return { ...page, [AdminPageTypeId]: true, contract: page.contract.middleware(AdminPermission) };
|
|
5
5
|
}
|
|
6
6
|
//# sourceMappingURL=page.js.map
|
package/dist/page.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.js","sourceRoot":"","sources":["../src/page.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"page.js","sourceRoot":"","sources":["../src/page.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAOlD,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAY5D,MAAM,UAAU,SAAS,CAOvB,IAID;IAIA,OAAO,EAAE,GAAG,IAAI,EAAE,CAAC,eAAe,CAAC,EAAE,IAAa,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;AAC3G,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const OpenAdmin: {
|
|
2
|
+
readonly any: {
|
|
3
|
+
readonly name: "admin.open";
|
|
4
|
+
readonly strength: "any";
|
|
5
|
+
};
|
|
6
|
+
readonly name: "admin.open";
|
|
7
|
+
readonly strength: "own";
|
|
8
|
+
};
|
|
9
|
+
declare const AdminPermission_base: import("effect/rpc/RpcMiddleware").ServiceClass<AdminPermission, "@shivaedev/admin/Permission", import("@shivaedev/platform/rpc/identity.ts").Identity | import("@shivaedev/platform/rpc/identity.ts").SessionUser, import("effect/Schema").Union<readonly [typeof import("@shivaedev/effect-contract/errors/taxonomy.ts").Unauthorized, typeof import("@shivaedev/effect-contract/errors/taxonomy.ts").AuthUnavailable, typeof import("@shivaedev/effect-contract/errors/taxonomy.ts").Forbidden]>, never, never, false> & {
|
|
10
|
+
permission: import("@shivaedev/access/permission.ts").Permission;
|
|
11
|
+
};
|
|
12
|
+
export declare class AdminPermission extends AdminPermission_base {
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=permissions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS;;;;;;;CAA2B,CAAC;;;;AAClD,qBAAa,eAAgB,SAAQ,oBAAiF;CAAG"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { permission } from "@shivaedev/access/permission.ts";
|
|
2
|
+
import { permissionMiddleware } from "@shivaedev/platform/rpc/permission.ts";
|
|
3
|
+
export const OpenAdmin = permission("admin.open");
|
|
4
|
+
export class AdminPermission extends permissionMiddleware()("@shivaedev/admin/Permission", OpenAdmin) {
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=permissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.js","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAE7E,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;AAClD,MAAM,OAAO,eAAgB,SAAQ,oBAAoB,EAAmB,CAAC,6BAA6B,EAAE,SAAS,CAAC;CAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usersHandlers.d.ts","sourceRoot":"","sources":["../../src/server/usersHandlers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usersHandlers.d.ts","sourceRoot":"","sources":["../../src/server/usersHandlers.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,aAAa,sPAOxB,CAAC"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { hasRole } from "@shivaedev/platform/rpc/hasRole.ts";
|
|
3
2
|
import { SessionUser } from "@shivaedev/platform/rpc/identity.ts";
|
|
3
|
+
import { hasPermission } from "@shivaedev/platform/rpc/permission.ts";
|
|
4
|
+
import { ChangeUserRoles } from "@shivaedev/platform/rpc/userRoles.ts";
|
|
4
5
|
import { changeUserRole, listUsers } from "@shivaedev/platform/server/better-auth/users.ts";
|
|
5
6
|
import { UsersPage } from "#users/page.ts";
|
|
6
7
|
export const usersHandlers = UsersPage.contract.application.toLayer({
|
|
7
8
|
"admin.users.changeRole": changeUserRole,
|
|
8
9
|
"admin.users.list": (input) => Effect.gen(function* () {
|
|
9
10
|
const user = yield* SessionUser;
|
|
10
|
-
return { ...(yield* listUsers(input)), canChangeRoles:
|
|
11
|
+
return { ...(yield* listUsers(input)), canChangeRoles: hasPermission(user, ChangeUserRoles) };
|
|
11
12
|
}),
|
|
12
13
|
});
|
|
13
14
|
//# sourceMappingURL=usersHandlers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usersHandlers.js","sourceRoot":"","sources":["../../src/server/usersHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"usersHandlers.js","sourceRoot":"","sources":["../../src/server/usersHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,iDAAiD,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC;IACnE,wBAAwB,EAAE,cAAc;IACxC,kBAAkB,EAAE,CAAC,KAAK,EAAE,EAAE,CAC7B,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QACnB,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,WAAW,CAAC;QAChC,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,EAAE,aAAa,CAAC,IAAI,EAAE,eAAe,CAAC,EAAE,CAAC;IAC/F,CAAC,CAAC;CACH,CAAC,CAAC"}
|
package/dist/users/page.d.ts
CHANGED
|
@@ -58,7 +58,11 @@ export declare const UsersPage: import("#page.ts").AdminPage & {
|
|
|
58
58
|
}>]>>;
|
|
59
59
|
}>, Schema.Struct<{
|
|
60
60
|
readonly _tag: Schema.Literal<"Resync">;
|
|
61
|
-
}>]>, Schema.Never>, Schema.Never, typeof import("
|
|
61
|
+
}>]>, Schema.Never>, Schema.Never, typeof import("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.users.changeRole", Schema.Struct<{
|
|
62
|
+
readonly grant: Schema.Boolean;
|
|
63
|
+
readonly role: Schema.Literals<readonly ["user", "admin", "owner"]>;
|
|
64
|
+
readonly userId: Schema.String;
|
|
65
|
+
}>, Schema.Void, Schema.Union<readonly (typeof NotFound | typeof Forbidden | typeof AuthUnavailable | typeof LastOwner)[]>, typeof import("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.users.list", Schema.Struct<{
|
|
62
66
|
readonly cursor: Schema.optionalKey<Schema.String>;
|
|
63
67
|
readonly limit: Schema.Number;
|
|
64
68
|
}>, Schema.Struct<{
|
|
@@ -71,10 +75,6 @@ export declare const UsersPage: import("#page.ts").AdminPage & {
|
|
|
71
75
|
readonly roles: Schema.$Array<Schema.String>;
|
|
72
76
|
}>>;
|
|
73
77
|
readonly canChangeRoles: Schema.Boolean;
|
|
74
|
-
}>, Schema.Union<readonly (typeof AuthUnavailable)[]>, typeof import("
|
|
75
|
-
readonly grant: Schema.Boolean;
|
|
76
|
-
readonly role: Schema.Literals<readonly ["user", "admin", "owner"]>;
|
|
77
|
-
readonly userId: Schema.String;
|
|
78
|
-
}>, Schema.Void, Schema.Union<readonly (typeof NotFound | typeof Forbidden | typeof AuthUnavailable | typeof LastOwner)[]>, typeof import("@shivaedev/platform/rpc/middleware.ts").AuthenticatedAdmin, never>, readonly [], undefined>;
|
|
78
|
+
}>, Schema.Union<readonly (typeof AuthUnavailable)[]>, typeof import("../permissions.ts").AdminPermission, never>, readonly [], undefined>;
|
|
79
79
|
};
|
|
80
80
|
//# 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.5.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": {
|
|
@@ -41,10 +41,11 @@
|
|
|
41
41
|
"README.md"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
+
"@shivaedev/access": "0.1.0",
|
|
44
45
|
"@shivaedev/effect-contract": "0.16.0",
|
|
45
46
|
"@shivaedev/effect-pg-boss": "0.19.0",
|
|
46
47
|
"@shivaedev/effect-react": "0.18.1",
|
|
47
|
-
"@shivaedev/platform": "0.
|
|
48
|
+
"@shivaedev/platform": "0.34.0"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
51
|
"@effect/atom-react": "4.0.5",
|
package/src/page.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Rpc, RpcGroup } from "effect/rpc";
|
|
2
2
|
import type { Contract } from "@shivaedev/effect-contract/contract.ts";
|
|
3
3
|
import type { CommandShape, QueryShape, StreamShape } from "@shivaedev/effect-contract/operation.ts";
|
|
4
|
-
import {
|
|
4
|
+
import { AdminPermission } from "#permissions.ts";
|
|
5
5
|
|
|
6
6
|
export interface AdminRoute {
|
|
7
7
|
readonly path: string;
|
|
@@ -33,7 +33,7 @@ export function adminPage<
|
|
|
33
33
|
readonly contract: Contract<TName, TQueries, TCommands, TRpcs, TStreams>;
|
|
34
34
|
}): AdminPage & {
|
|
35
35
|
readonly id: TId;
|
|
36
|
-
readonly contract: Contract<TName, TQueries, TCommands, Rpc.AddMiddleware<TRpcs, typeof
|
|
36
|
+
readonly contract: Contract<TName, TQueries, TCommands, Rpc.AddMiddleware<TRpcs, typeof AdminPermission>, TStreams>;
|
|
37
37
|
} {
|
|
38
|
-
return { ...page, [AdminPageTypeId]: true as const, contract: page.contract.middleware(
|
|
38
|
+
return { ...page, [AdminPageTypeId]: true as const, contract: page.contract.middleware(AdminPermission) };
|
|
39
39
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { permission } from "@shivaedev/access/permission.ts";
|
|
2
|
+
import { permissionMiddleware } from "@shivaedev/platform/rpc/permission.ts";
|
|
3
|
+
|
|
4
|
+
export const OpenAdmin = permission("admin.open");
|
|
5
|
+
export class AdminPermission extends permissionMiddleware<AdminPermission>()("@shivaedev/admin/Permission", OpenAdmin) {}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { hasRole } from "@shivaedev/platform/rpc/hasRole.ts";
|
|
3
2
|
import { SessionUser } from "@shivaedev/platform/rpc/identity.ts";
|
|
3
|
+
import { hasPermission } from "@shivaedev/platform/rpc/permission.ts";
|
|
4
|
+
import { ChangeUserRoles } from "@shivaedev/platform/rpc/userRoles.ts";
|
|
4
5
|
import { changeUserRole, listUsers } from "@shivaedev/platform/server/better-auth/users.ts";
|
|
5
6
|
import { UsersPage } from "#users/page.ts";
|
|
6
7
|
|
|
@@ -9,6 +10,6 @@ export const usersHandlers = UsersPage.contract.application.toLayer({
|
|
|
9
10
|
"admin.users.list": (input) =>
|
|
10
11
|
Effect.gen(function* () {
|
|
11
12
|
const user = yield* SessionUser;
|
|
12
|
-
return { ...(yield* listUsers(input)), canChangeRoles:
|
|
13
|
+
return { ...(yield* listUsers(input)), canChangeRoles: hasPermission(user, ChangeUserRoles) };
|
|
13
14
|
}),
|
|
14
15
|
});
|