@shivaedev/admin 0.11.2 → 0.12.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 +1 -1
- package/dist/jobs/page.d.ts +41 -41
- package/dist/jobs/retryPage.d.ts +26 -26
- package/dist/permissions.d.ts +0 -8
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +0 -1
- package/dist/permissions.js.map +1 -1
- package/dist/server/users.d.ts +3 -3
- package/dist/server/users.d.ts.map +1 -1
- package/dist/server/users.js +6 -35
- package/dist/server/users.js.map +1 -1
- package/dist/server/usersHandlers.js +1 -1
- package/dist/server/usersHandlers.js.map +1 -1
- package/dist/users/page.d.ts +6 -6
- package/dist/users/page.d.ts.map +1 -1
- package/dist/users/page.js +2 -1
- package/dist/users/page.js.map +1 -1
- package/dist/users/roles.d.ts +0 -6
- package/dist/users/roles.d.ts.map +1 -1
- package/dist/users/roles.js +0 -2
- package/dist/users/roles.js.map +1 -1
- package/package.json +11 -12
- package/src/permissions.ts +0 -1
- package/src/server/users.ts +6 -35
- package/src/server/usersHandlers.ts +1 -1
- package/src/users/page.ts +2 -1
- package/src/users/roles.ts +0 -1
package/README.md
CHANGED
|
@@ -156,7 +156,7 @@ const changeRole = Client.runtime.fn(users.changeRole.run);
|
|
|
156
156
|
|
|
157
157
|
`admin.users.list` takes `{ limit, cursor? }` (1–100 users) and returns `{ users, next, canChangeRoles }` ordered by user id. Each user has id, name, email, role and a UTC sign-up time. The page's operations and generated subscription require `ReadUsers` (`users.read`), enforced by `UsersPermission`. Supply `permissionLayer(UsersPermission, sessions)` alongside the application's other handler Layers.
|
|
158
158
|
|
|
159
|
-
`admin.users.changeRole` takes `{ userId, role }`; its role Schema is the application's declared role union. The handler also requires `AssignRoles` (`roles.assign`). The view shows a role select only to callers with that permission. Role writes serialize in a transaction and return `LastRoleAssigner` if replacing the final holder's role would remove `roles.assign`, regardless of the role's name. A missing user returns `NotFound`. Changes invalidate the list after commit and emit an Effect log with actor id, target id, role and timestamp.
|
|
159
|
+
`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.
|
|
160
160
|
|
|
161
161
|
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.
|
|
162
162
|
|
package/dist/jobs/page.d.ts
CHANGED
|
@@ -139,7 +139,25 @@ export declare function jobsPage<const TQueues extends readonly JobsEntry[]>(...
|
|
|
139
139
|
readonly id: string;
|
|
140
140
|
readonly queue: string;
|
|
141
141
|
}, import("@shivaedev/errors/taxonomy.ts").BadRequest | import("#jobs/schemas.ts").JobsPayloadInvalid | import("#jobs/schemas.ts").JobsQueueUnregistered | import("#jobs/schemas.ts").JobsUnavailable, import("@shivaedev/identity/identity.ts").SessionUser>;
|
|
142
|
-
}], readonly [], import("effect/rpc/Rpc").Rpc<"admin.jobs
|
|
142
|
+
}], readonly [], import("effect/rpc/Rpc").Rpc<"admin.jobs.job", Schema.Struct<{
|
|
143
|
+
id: Schema.String;
|
|
144
|
+
queue: Schema.String;
|
|
145
|
+
}>, Schema.OptionFromNullOr<Schema.Union<Schema.Struct<{
|
|
146
|
+
readonly attempt: Schema.Number;
|
|
147
|
+
readonly completedOn: Schema.OptionFromNullOr<Schema.DateTimeUtcFromString>;
|
|
148
|
+
readonly createdOn: Schema.DateTimeUtcFromString;
|
|
149
|
+
readonly id: Schema.String;
|
|
150
|
+
readonly output: Schema.NullOr<Schema.Struct<{
|
|
151
|
+
readonly _tag: Schema.withDecodingDefaultKey<Schema.String, never>;
|
|
152
|
+
readonly message: Schema.decodeTo<Schema.String, Schema.String, never, never>;
|
|
153
|
+
}>>;
|
|
154
|
+
readonly retryCount: Schema.Number;
|
|
155
|
+
readonly retryLimit: Schema.Number;
|
|
156
|
+
readonly startedOn: Schema.OptionFromNullOr<Schema.DateTimeUtcFromString>;
|
|
157
|
+
readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
|
|
158
|
+
readonly data: JobsPayload<TQueues[number]>;
|
|
159
|
+
readonly queue: Schema.Literal<string>;
|
|
160
|
+
}>[]>>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("#jobs/schemas.ts").JobsUnavailable | typeof import("#jobs/schemas.ts").JobsPayloadInvalid | typeof import("#jobs/schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.$changes", Schema.Struct<{
|
|
143
161
|
queries: Schema.$Array<Schema.Union<readonly (Schema.Struct<{
|
|
144
162
|
query: Schema.Literal<"counts">;
|
|
145
163
|
payload: Schema.Struct<{
|
|
@@ -194,7 +212,21 @@ export declare function jobsPage<const TQueues extends readonly JobsEntry[]>(...
|
|
|
194
212
|
readonly failedCount: Schema.Number;
|
|
195
213
|
readonly queuedCount: Schema.Number;
|
|
196
214
|
readonly totalCount: Schema.Number;
|
|
197
|
-
}>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("#jobs/schemas.ts").JobsUnavailable | typeof import("#jobs/schemas.ts").JobsPayloadInvalid | typeof import("#jobs/schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.
|
|
215
|
+
}>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("#jobs/schemas.ts").JobsUnavailable | typeof import("#jobs/schemas.ts").JobsPayloadInvalid | typeof import("#jobs/schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.health", Schema.Void, Schema.Struct<{
|
|
216
|
+
readonly activeTotal: Schema.Number;
|
|
217
|
+
readonly deadLetteredTotal: Schema.Number;
|
|
218
|
+
readonly failedTotal: Schema.Number;
|
|
219
|
+
readonly jobs: Schema.$Array<Schema.Struct<{
|
|
220
|
+
readonly activeCount: Schema.Number;
|
|
221
|
+
readonly deadLetteredCount: Schema.Number;
|
|
222
|
+
readonly failedCount: Schema.Number;
|
|
223
|
+
readonly name: Schema.String;
|
|
224
|
+
readonly queuedCount: Schema.Number;
|
|
225
|
+
readonly readyCount: Schema.Number;
|
|
226
|
+
}>>;
|
|
227
|
+
readonly queuedTotal: Schema.Number;
|
|
228
|
+
readonly readyTotal: Schema.Number;
|
|
229
|
+
}>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("#jobs/schemas.ts").JobsUnavailable | typeof import("#jobs/schemas.ts").JobsPayloadInvalid | typeof import("#jobs/schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.failed", Schema.Struct<{
|
|
198
230
|
cursor: Schema.optionalKey<Schema.String>;
|
|
199
231
|
limit: Schema.Number;
|
|
200
232
|
queue: Schema.String;
|
|
@@ -214,14 +246,9 @@ export declare function jobsPage<const TQueues extends readonly JobsEntry[]>(...
|
|
|
214
246
|
readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
|
|
215
247
|
readonly data: JobsPayload<TQueues[number]>;
|
|
216
248
|
readonly queue: Schema.Literal<string>;
|
|
217
|
-
readonly sourceId: Schema.OptionFromNullOr<Schema.String>;
|
|
218
|
-
readonly sourceOutput: Schema.NullOr<Schema.Struct<{
|
|
219
|
-
readonly _tag: Schema.withDecodingDefaultKey<Schema.String, never>;
|
|
220
|
-
readonly message: Schema.decodeTo<Schema.String, Schema.String, never, never>;
|
|
221
|
-
}>>;
|
|
222
249
|
}>[]>>;
|
|
223
250
|
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
224
|
-
}>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("#jobs/schemas.ts").JobsUnavailable | typeof import("#jobs/schemas.ts").JobsPayloadInvalid | typeof import("#jobs/schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.
|
|
251
|
+
}>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("#jobs/schemas.ts").JobsUnavailable | typeof import("#jobs/schemas.ts").JobsPayloadInvalid | typeof import("#jobs/schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.deadLettered", Schema.Struct<{
|
|
225
252
|
cursor: Schema.optionalKey<Schema.String>;
|
|
226
253
|
limit: Schema.Number;
|
|
227
254
|
queue: Schema.String;
|
|
@@ -241,41 +268,14 @@ export declare function jobsPage<const TQueues extends readonly JobsEntry[]>(...
|
|
|
241
268
|
readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
|
|
242
269
|
readonly data: JobsPayload<TQueues[number]>;
|
|
243
270
|
readonly queue: Schema.Literal<string>;
|
|
271
|
+
readonly sourceId: Schema.OptionFromNullOr<Schema.String>;
|
|
272
|
+
readonly sourceOutput: Schema.NullOr<Schema.Struct<{
|
|
273
|
+
readonly _tag: Schema.withDecodingDefaultKey<Schema.String, never>;
|
|
274
|
+
readonly message: Schema.decodeTo<Schema.String, Schema.String, never, never>;
|
|
275
|
+
}>>;
|
|
244
276
|
}>[]>>;
|
|
245
277
|
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
246
|
-
}>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("#jobs/schemas.ts").JobsUnavailable | typeof import("#jobs/schemas.ts").JobsPayloadInvalid | typeof import("#jobs/schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never
|
|
247
|
-
readonly activeTotal: Schema.Number;
|
|
248
|
-
readonly deadLetteredTotal: Schema.Number;
|
|
249
|
-
readonly failedTotal: Schema.Number;
|
|
250
|
-
readonly jobs: Schema.$Array<Schema.Struct<{
|
|
251
|
-
readonly activeCount: Schema.Number;
|
|
252
|
-
readonly deadLetteredCount: Schema.Number;
|
|
253
|
-
readonly failedCount: Schema.Number;
|
|
254
|
-
readonly name: Schema.String;
|
|
255
|
-
readonly queuedCount: Schema.Number;
|
|
256
|
-
readonly readyCount: Schema.Number;
|
|
257
|
-
}>>;
|
|
258
|
-
readonly queuedTotal: Schema.Number;
|
|
259
|
-
readonly readyTotal: Schema.Number;
|
|
260
|
-
}>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("#jobs/schemas.ts").JobsUnavailable | typeof import("#jobs/schemas.ts").JobsPayloadInvalid | typeof import("#jobs/schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.job", Schema.Struct<{
|
|
261
|
-
id: Schema.String;
|
|
262
|
-
queue: Schema.String;
|
|
263
|
-
}>, Schema.OptionFromNullOr<Schema.Union<Schema.Struct<{
|
|
264
|
-
readonly attempt: Schema.Number;
|
|
265
|
-
readonly completedOn: Schema.OptionFromNullOr<Schema.DateTimeUtcFromString>;
|
|
266
|
-
readonly createdOn: Schema.DateTimeUtcFromString;
|
|
267
|
-
readonly id: Schema.String;
|
|
268
|
-
readonly output: Schema.NullOr<Schema.Struct<{
|
|
269
|
-
readonly _tag: Schema.withDecodingDefaultKey<Schema.String, never>;
|
|
270
|
-
readonly message: Schema.decodeTo<Schema.String, Schema.String, never, never>;
|
|
271
|
-
}>>;
|
|
272
|
-
readonly retryCount: Schema.Number;
|
|
273
|
-
readonly retryLimit: Schema.Number;
|
|
274
|
-
readonly startedOn: Schema.OptionFromNullOr<Schema.DateTimeUtcFromString>;
|
|
275
|
-
readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
|
|
276
|
-
readonly data: JobsPayload<TQueues[number]>;
|
|
277
|
-
readonly queue: Schema.Literal<string>;
|
|
278
|
-
}>[]>>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("#jobs/schemas.ts").JobsUnavailable | typeof import("#jobs/schemas.ts").JobsPayloadInvalid | typeof import("#jobs/schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never>, readonly [], undefined>;
|
|
278
|
+
}>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("#jobs/schemas.ts").JobsUnavailable | typeof import("#jobs/schemas.ts").JobsPayloadInvalid | typeof import("#jobs/schemas.ts").JobsQueueUnregistered)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof JobsPermission, never>, readonly [], undefined>;
|
|
279
279
|
} & {
|
|
280
280
|
queues: TQueues;
|
|
281
281
|
};
|
package/dist/jobs/retryPage.d.ts
CHANGED
|
@@ -227,17 +227,14 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsEnt
|
|
|
227
227
|
readonly queryIndexes: Schema.optional<Schema.$Array<Schema.Number>>;
|
|
228
228
|
}>, Schema.Struct<{
|
|
229
229
|
readonly _tag: Schema.Literal<"Resync">;
|
|
230
|
-
}>]>, ...never[]]>, Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, ...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.
|
|
231
|
-
id: Schema.String;
|
|
232
|
-
queue: Schema.String;
|
|
233
|
-
}>, 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<{
|
|
230
|
+
}>]>, ...never[]]>, Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, ...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.counts", Schema.Struct<{
|
|
234
231
|
queue: Schema.String;
|
|
235
232
|
}>, Schema.Struct<{
|
|
236
233
|
readonly activeCount: Schema.Number;
|
|
237
234
|
readonly failedCount: Schema.Number;
|
|
238
235
|
readonly queuedCount: Schema.Number;
|
|
239
236
|
readonly totalCount: Schema.Number;
|
|
240
|
-
}>, 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> | import("effect/rpc/Rpc").Rpc<"admin.jobs.
|
|
237
|
+
}>, 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> | import("effect/rpc/Rpc").Rpc<"admin.jobs.failed", Schema.Struct<{
|
|
241
238
|
cursor: Schema.optionalKey<Schema.String>;
|
|
242
239
|
limit: Schema.Number;
|
|
243
240
|
queue: Schema.String;
|
|
@@ -257,14 +254,9 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsEnt
|
|
|
257
254
|
readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
|
|
258
255
|
readonly data: import("./entry.ts").JobsPayload<[...TQueues][number]>;
|
|
259
256
|
readonly queue: Schema.Literal<string>;
|
|
260
|
-
readonly sourceId: Schema.OptionFromNullOr<Schema.String>;
|
|
261
|
-
readonly sourceOutput: Schema.NullOr<Schema.Struct<{
|
|
262
|
-
readonly _tag: Schema.withDecodingDefaultKey<Schema.String, never>;
|
|
263
|
-
readonly message: Schema.decodeTo<Schema.String, Schema.String, never, never>;
|
|
264
|
-
}>>;
|
|
265
257
|
}>[]>>;
|
|
266
258
|
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
267
|
-
}>, 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> | import("effect/rpc/Rpc").Rpc<"admin.jobs.
|
|
259
|
+
}>, 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> | import("effect/rpc/Rpc").Rpc<"admin.jobs.deadLettered", Schema.Struct<{
|
|
268
260
|
cursor: Schema.optionalKey<Schema.String>;
|
|
269
261
|
limit: Schema.Number;
|
|
270
262
|
queue: Schema.String;
|
|
@@ -284,22 +276,13 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsEnt
|
|
|
284
276
|
readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
|
|
285
277
|
readonly data: import("./entry.ts").JobsPayload<[...TQueues][number]>;
|
|
286
278
|
readonly queue: Schema.Literal<string>;
|
|
279
|
+
readonly sourceId: Schema.OptionFromNullOr<Schema.String>;
|
|
280
|
+
readonly sourceOutput: Schema.NullOr<Schema.Struct<{
|
|
281
|
+
readonly _tag: Schema.withDecodingDefaultKey<Schema.String, never>;
|
|
282
|
+
readonly message: Schema.decodeTo<Schema.String, Schema.String, never, never>;
|
|
283
|
+
}>>;
|
|
287
284
|
}>[]>>;
|
|
288
285
|
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
289
|
-
}>, 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> | import("effect/rpc/Rpc").Rpc<"admin.jobs.health", Schema.Void, Schema.Struct<{
|
|
290
|
-
readonly activeTotal: Schema.Number;
|
|
291
|
-
readonly deadLetteredTotal: Schema.Number;
|
|
292
|
-
readonly failedTotal: Schema.Number;
|
|
293
|
-
readonly jobs: Schema.$Array<Schema.Struct<{
|
|
294
|
-
readonly activeCount: Schema.Number;
|
|
295
|
-
readonly deadLetteredCount: Schema.Number;
|
|
296
|
-
readonly failedCount: Schema.Number;
|
|
297
|
-
readonly name: Schema.String;
|
|
298
|
-
readonly queuedCount: Schema.Number;
|
|
299
|
-
readonly readyCount: Schema.Number;
|
|
300
|
-
}>>;
|
|
301
|
-
readonly queuedTotal: Schema.Number;
|
|
302
|
-
readonly readyTotal: Schema.Number;
|
|
303
286
|
}>, 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> | import("effect/rpc/Rpc").Rpc<"admin.jobs.job", Schema.Struct<{
|
|
304
287
|
id: Schema.String;
|
|
305
288
|
queue: Schema.String;
|
|
@@ -318,7 +301,24 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsEnt
|
|
|
318
301
|
readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
|
|
319
302
|
readonly data: import("./entry.ts").JobsPayload<[...TQueues][number]>;
|
|
320
303
|
readonly queue: Schema.Literal<string>;
|
|
321
|
-
}>[]>>, 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
|
|
304
|
+
}>[]>>, 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> | import("effect/rpc/Rpc").Rpc<"admin.jobs.retry", Schema.Struct<{
|
|
305
|
+
id: Schema.String;
|
|
306
|
+
queue: Schema.String;
|
|
307
|
+
}>, 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.health", Schema.Void, Schema.Struct<{
|
|
308
|
+
readonly activeTotal: Schema.Number;
|
|
309
|
+
readonly deadLetteredTotal: Schema.Number;
|
|
310
|
+
readonly failedTotal: Schema.Number;
|
|
311
|
+
readonly jobs: Schema.$Array<Schema.Struct<{
|
|
312
|
+
readonly activeCount: Schema.Number;
|
|
313
|
+
readonly deadLetteredCount: Schema.Number;
|
|
314
|
+
readonly failedCount: Schema.Number;
|
|
315
|
+
readonly name: Schema.String;
|
|
316
|
+
readonly queuedCount: Schema.Number;
|
|
317
|
+
readonly readyCount: Schema.Number;
|
|
318
|
+
}>>;
|
|
319
|
+
readonly queuedTotal: Schema.Number;
|
|
320
|
+
readonly readyTotal: Schema.Number;
|
|
321
|
+
}>, 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>;
|
|
322
322
|
} & {
|
|
323
323
|
queues: TQueues;
|
|
324
324
|
};
|
package/dist/permissions.d.ts
CHANGED
|
@@ -6,14 +6,6 @@ export declare const ReadUsers: {
|
|
|
6
6
|
readonly name: "users.read";
|
|
7
7
|
readonly strength: "own";
|
|
8
8
|
};
|
|
9
|
-
export declare const AssignRoles: {
|
|
10
|
-
readonly any: {
|
|
11
|
-
readonly name: "roles.assign";
|
|
12
|
-
readonly strength: "any";
|
|
13
|
-
};
|
|
14
|
-
readonly name: "roles.assign";
|
|
15
|
-
readonly strength: "own";
|
|
16
|
-
};
|
|
17
9
|
export declare const ReadJobs: {
|
|
18
10
|
readonly any: {
|
|
19
11
|
readonly name: "jobs.read";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS;;;;;;;CAA2B,CAAC;AAClD,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS;;;;;;;CAA2B,CAAC;AAClD,eAAO,MAAM,QAAQ;;;;;;;CAA0B,CAAC;AAChD,eAAO,MAAM,SAAS;;;;;;;CAA2B,CAAC;;;;;;;AAClD,qBAAa,eAAgB,SAAQ,oBAAsF;CAAG;;;;;;;AAC9H,qBAAa,cAAe,SAAQ,mBAAmF;CAAG"}
|
package/dist/permissions.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { permission } from "@shivaedev/access/permission.ts";
|
|
2
2
|
import { permissionMiddleware } from "@shivaedev/identity/permission.ts";
|
|
3
3
|
export const ReadUsers = permission("users.read");
|
|
4
|
-
export const AssignRoles = permission("roles.assign");
|
|
5
4
|
export const ReadJobs = permission("jobs.read");
|
|
6
5
|
export const RetryJobs = permission("jobs.retry");
|
|
7
6
|
export class UsersPermission extends permissionMiddleware()("@shivaedev/admin/UsersPermission", ReadUsers) {
|
package/dist/permissions.js.map
CHANGED
|
@@ -1 +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,mCAAmC,CAAC;AAEzE,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;AAClD,MAAM,CAAC,MAAM,
|
|
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,mCAAmC,CAAC;AAEzE,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;AAClD,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;AAChD,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;AAClD,MAAM,OAAO,eAAgB,SAAQ,oBAAoB,EAAmB,CAAC,kCAAkC,EAAE,SAAS,CAAC;CAAG;AAC9H,MAAM,OAAO,cAAe,SAAQ,oBAAoB,EAAkB,CAAC,iCAAiC,EAAE,QAAQ,CAAC;CAAG"}
|
package/dist/server/users.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { DateTime, Effect, Option } from "effect";
|
|
2
2
|
import { SqlClient } from "effect/sql";
|
|
3
3
|
import type { AccessPolicy } from "@shivaedev/access/roleSet.ts";
|
|
4
|
-
import { AuthUnavailable
|
|
4
|
+
import { AuthUnavailable } from "@shivaedev/errors/taxonomy.ts";
|
|
5
5
|
import { SessionUser } from "@shivaedev/identity/identity.ts";
|
|
6
|
-
import { type ChangeRoleInput
|
|
6
|
+
import { type ChangeRoleInput } from "#users/roles.ts";
|
|
7
7
|
export declare const listUsers: <TRole extends string>(access: Pick<AccessPolicy<TRole>, "Role">, input: {
|
|
8
8
|
readonly cursor?: string;
|
|
9
9
|
readonly limit: number;
|
|
@@ -17,5 +17,5 @@ export declare const listUsers: <TRole extends string>(access: Pick<AccessPolicy
|
|
|
17
17
|
readonly role: TRole;
|
|
18
18
|
}[];
|
|
19
19
|
}, 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>) => Effect.Effect<void, AuthUnavailable | import("@shivaedev/errors/taxonomy.ts").Forbidden | LastRoleAssigner | NotFound, import("effect/reactivity/Reactivity").Reactivity | SessionUser | SqlClient.SqlClient>;
|
|
20
|
+
export declare const changeUserRole: <TRole extends string>(access: Pick<AccessPolicy<TRole>, "Role" | "hasPermission">, input: ChangeRoleInput<TRole>) => Effect.Effect<void, AuthUnavailable | import("@shivaedev/errors/taxonomy.ts").Forbidden | import("@shivaedev/access/roles.ts").LastRoleAssigner | import("@shivaedev/errors/taxonomy.ts").NotFound, import("effect/reactivity/Reactivity").Reactivity | SessionUser | SqlClient.SqlClient>;
|
|
21
21
|
//# 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;
|
|
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;AAG9D,OAAO,EAAW,KAAK,eAAe,EAAsB,MAAM,iBAAiB,CAAC;AAMpF,eAAO,MAAM,SAAS,GAA2C,KAAK,SAAS,MAAM;;;;;;;;;;;;0GAenF,CAAC;AAEH,eAAO,MAAM,cAAc,GAAgD,KAAK,SAAS,MAAM,2XAW7F,CAAC"}
|
package/dist/server/users.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { DateTime, Effect, Option, Schema } from "effect";
|
|
2
2
|
import { SqlClient, SqlSchema } from "effect/sql";
|
|
3
3
|
import { requirePermission } from "@shivaedev/access/requirePermission.ts";
|
|
4
|
-
import {
|
|
4
|
+
import { AssignRoles } from "@shivaedev/access/roles.ts";
|
|
5
|
+
import { AuthUnavailable } from "@shivaedev/errors/taxonomy.ts";
|
|
5
6
|
import { SessionUser } from "@shivaedev/identity/identity.ts";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { AppUser
|
|
7
|
+
import { assignRole } from "@shivaedev/identity/server/better-auth/assignRole.ts";
|
|
8
|
+
import { ReadUsers } from "#permissions.ts";
|
|
9
|
+
import { AppUser } from "#users/roles.ts";
|
|
9
10
|
function unavailable() {
|
|
10
11
|
return new AuthUnavailable({ message: "Could not access app users" });
|
|
11
12
|
}
|
|
@@ -25,37 +26,7 @@ export const listUsers = Effect.fn("Admin.listUsers")(function* (access, input)
|
|
|
25
26
|
export const changeUserRole = Effect.fn("Admin.changeUserRole")(function* (access, input) {
|
|
26
27
|
const actor = yield* SessionUser;
|
|
27
28
|
yield* requirePermission(actor, AssignRoles);
|
|
28
|
-
const
|
|
29
|
-
const changed = yield* Effect.gen(function* () {
|
|
30
|
-
yield* sql `select pg_advisory_xact_lock(hashtext('platform.auth.user-roles'))`;
|
|
31
|
-
const readTarget = SqlSchema.findOneOption({
|
|
32
|
-
execute: (id) => sql `select id, role from "user" where id = ${id} for update`,
|
|
33
|
-
Request: AppUser.fields.id,
|
|
34
|
-
Result: Schema.Struct({ id: AppUser.fields.id, role: Schema.NullOr(AppUser.fields.role) }),
|
|
35
|
-
});
|
|
36
|
-
const target = yield* readTarget(input.userId).pipe(Effect.mapError(unavailable));
|
|
37
|
-
if (Option.isNone(target)) {
|
|
38
|
-
return yield* Effect.fail(new NotFound({ message: "User not found" }));
|
|
39
|
-
}
|
|
40
|
-
if (target.value.role === input.role) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
const assigners = access.Role.literals.filter((role) => access.hasPermission(role, AssignRoles));
|
|
44
|
-
if (assigners.some((role) => role === target.value.role) && !access.hasPermission(input.role, AssignRoles)) {
|
|
45
|
-
const readHolders = SqlSchema.findAll({
|
|
46
|
-
execute: () => sql `select id from "user" where role in ${sql.in(assigners)}`,
|
|
47
|
-
Request: Schema.Void,
|
|
48
|
-
Result: Schema.Struct({ id: AppUser.fields.id }),
|
|
49
|
-
});
|
|
50
|
-
const holders = yield* readHolders(undefined).pipe(Effect.mapError(unavailable));
|
|
51
|
-
if (holders.length === 1) {
|
|
52
|
-
return yield* Effect.fail(new LastRoleAssigner({ userId: input.userId }));
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
yield* sql `update "user" set role = ${input.role}, "updatedAt" = now() where id = ${input.userId}`;
|
|
56
|
-
yield* invalidateOnCommit(["admin.users"]);
|
|
57
|
-
return true;
|
|
58
|
-
}).pipe(transact({ onSqlError: unavailable }));
|
|
29
|
+
const changed = yield* assignRole(access, input.userId, input.role);
|
|
59
30
|
if (changed) {
|
|
60
31
|
const changedAt = DateTime.formatIso(yield* DateTime.now);
|
|
61
32
|
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,
|
|
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;IAEhC,KAAK,CAAC,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IACxD,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC;IACvC,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC;QAC9B,OAAO,EAAE,GAAG,EAAE,CAAC,GAAG,CAAA;gBACJ,KAAK,CAAC,MAAM,IAAI,EAAE,sBAAsB,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE;QACvE,OAAO,EAAE,MAAM,CAAC,IAAI;QACpB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;KAC/D,CAAC,CAAC;IACH,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC;IACvE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IACzC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAU,EAAE,KAAK,EAAE,CAAC;AACtH,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,EAAE,CAAC,sBAAsB,CAAC,CAAC,QAAQ,CAAC,EACxE,MAA2D,EAC3D,KAA6B;IAE7B,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,WAAW,CAAC;IACjC,KAAK,CAAC,CAAC,iBAAiB,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAC7C,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IACpE,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,7 +1,7 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
+
import { AssignRoles } from "@shivaedev/access/roles.ts";
|
|
2
3
|
import { SessionUser } from "@shivaedev/identity/identity.ts";
|
|
3
4
|
import { hasPermission } from "@shivaedev/identity/permission.ts";
|
|
4
|
-
import { AssignRoles } from "#permissions.ts";
|
|
5
5
|
import { changeUserRole, listUsers } from "#server/users.ts";
|
|
6
6
|
export function usersHandlers(page, access) {
|
|
7
7
|
return page.contract.application.toLayer({
|
|
@@ -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,
|
|
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;AAClE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG7D,MAAM,UAAU,aAAa,CAC5B,IAAyC,EACzC,MAA2D;IAE3D,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC;QACxC,wBAAwB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC;QAClE,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,CAAC,CAAC,EAAE,cAAc,EAAE,aAAa,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,CAAC;QACnG,CAAC,CAAC;KACH,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/users/page.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import type { AccessPolicy } from "@shivaedev/access/roleSet.ts";
|
|
3
|
+
import { LastRoleAssigner } from "@shivaedev/access/roles.ts";
|
|
3
4
|
import { AuthUnavailable, Forbidden, NotFound } from "@shivaedev/errors/taxonomy.ts";
|
|
4
5
|
import { UsersPermission } from "#permissions.ts";
|
|
5
|
-
import { LastRoleAssigner } from "#users/roles.ts";
|
|
6
6
|
export declare const UsersList: Schema.Struct<{
|
|
7
7
|
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
8
8
|
readonly users: Schema.$Array<Schema.Struct<{
|
|
@@ -71,10 +71,7 @@ export declare function usersPage<const TRole extends string>(access: Pick<Acces
|
|
|
71
71
|
readonly queryIndexes: Schema.optional<Schema.$Array<Schema.Number>>;
|
|
72
72
|
}>, Schema.Struct<{
|
|
73
73
|
readonly _tag: Schema.Literal<"Resync">;
|
|
74
|
-
}>]>, ...never[]]>, Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, ...Schema.Union<readonly (typeof Forbidden | typeof AuthUnavailable)[]>[]]>>, Schema.Never, typeof UsersPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.users.
|
|
75
|
-
role: Schema.Literals<TRole[]>;
|
|
76
|
-
userId: Schema.String;
|
|
77
|
-
}>, 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<{
|
|
74
|
+
}>]>, ...never[]]>, Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, ...Schema.Union<readonly (typeof Forbidden | typeof AuthUnavailable)[]>[]]>>, Schema.Never, typeof UsersPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.users.list", Schema.Struct<{
|
|
78
75
|
readonly cursor: Schema.optionalKey<Schema.String>;
|
|
79
76
|
readonly limit: Schema.Number;
|
|
80
77
|
}>, Schema.Struct<{
|
|
@@ -87,6 +84,9 @@ export declare function usersPage<const TRole extends string>(access: Pick<Acces
|
|
|
87
84
|
readonly role: Schema.String;
|
|
88
85
|
}>>;
|
|
89
86
|
readonly canChangeRoles: Schema.Boolean;
|
|
90
|
-
}>, Schema.Union<readonly [Schema.Union<readonly (typeof Forbidden | typeof AuthUnavailable)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof UsersPermission, never
|
|
87
|
+
}>, Schema.Union<readonly [Schema.Union<readonly (typeof Forbidden | typeof AuthUnavailable)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, typeof UsersPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.users.changeRole", Schema.Struct<{
|
|
88
|
+
role: Schema.Literals<TRole[]>;
|
|
89
|
+
userId: Schema.String;
|
|
90
|
+
}>, Schema.Void, Schema.Union<readonly (typeof NotFound | typeof Forbidden | typeof AuthUnavailable | typeof LastRoleAssigner)[]>, typeof UsersPermission, never>, readonly [], undefined>;
|
|
91
91
|
};
|
|
92
92
|
//# sourceMappingURL=page.d.ts.map
|
package/dist/users/page.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../../src/users/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../../src/users/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAI9D,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAErF,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAKlD,eAAO,MAAM,SAAS;;;;;;;;;;EAAwE,CAAC;AAC/F,wBAAgB,SAAS,CAAC,KAAK,CAAC,KAAK,SAAS,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuB9F"}
|
package/dist/users/page.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
+
import { LastRoleAssigner } from "@shivaedev/access/roles.ts";
|
|
2
3
|
import { collection } from "@shivaedev/changes/keys.ts";
|
|
3
4
|
import { contract } from "@shivaedev/contract/contract.ts";
|
|
4
5
|
import { command, query } from "@shivaedev/contract/operation.ts";
|
|
5
6
|
import { AuthUnavailable, Forbidden, NotFound } from "@shivaedev/errors/taxonomy.ts";
|
|
6
7
|
import { adminPage } from "#page.ts";
|
|
7
8
|
import { UsersPermission } from "#permissions.ts";
|
|
8
|
-
import {
|
|
9
|
+
import { UserList, UserListInput } from "#users/roles.ts";
|
|
9
10
|
const users = collection("admin.users", Schema.String);
|
|
10
11
|
export const UsersList = Schema.Struct({ ...UserList.fields, canChangeRoles: Schema.Boolean });
|
|
11
12
|
export function usersPage(access) {
|
package/dist/users/page.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/users/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/users/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE1D,MAAM,KAAK,GAAG,UAAU,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;AAEvD,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,QAAQ,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;AAC/F,MAAM,UAAU,SAAS,CAA6B,MAAyC;IAC9F,OAAO,SAAS,CAAC;QAChB,QAAQ,EAAE,QAAQ,CAAC,aAAa,EAAE;YACjC,QAAQ,EAAE;gBACT,OAAO,CAAC,YAAY,EAAE;oBACrB,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;oBAC/B,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;oBACrD,UAAU,EAAE,EAAE,eAAe,EAAE,SAAS,EAAE,gBAAgB,EAAE,QAAQ,EAAE;iBACtE,CAAC;aACF;YACD,OAAO,EAAE;gBACR,KAAK,CAAC,MAAM,EAAE;oBACb,OAAO,EAAE,aAAa,CAAC,MAAM;oBAC7B,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;oBACzB,UAAU,EAAE,EAAE,eAAe,EAAE,SAAS,EAAE;oBAC1C,OAAO,EAAE,SAAS;iBAClB,CAAC;aACF;SACD,CAAC;QACF,EAAE,EAAE,OAAO;QACX,UAAU,EAAE,eAAe;QAC3B,KAAK,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,OAAO,EAAE;KAC/C,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/users/roles.d.ts
CHANGED
|
@@ -24,10 +24,4 @@ export interface ChangeRoleInput<TRole extends string = string> {
|
|
|
24
24
|
readonly role: TRole;
|
|
25
25
|
readonly userId: string;
|
|
26
26
|
}
|
|
27
|
-
declare const LastRoleAssigner_base: Schema.Class<LastRoleAssigner, Schema.TaggedStruct<"LastRoleAssigner", {
|
|
28
|
-
readonly userId: Schema.String;
|
|
29
|
-
}>, import("effect/Cause").YieldableError>;
|
|
30
|
-
export declare class LastRoleAssigner extends LastRoleAssigner_base {
|
|
31
|
-
}
|
|
32
|
-
export {};
|
|
33
27
|
//# sourceMappingURL=roles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../../src/users/roles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,eAAO,MAAM,OAAO;;;;;;EAMlB,CAAC;AAEH,eAAO,MAAM,aAAa;;;EAGxB,CAAC;AACH,eAAO,MAAM,QAAQ;;;;;;;;;EAAgG,CAAC;AACtH,MAAM,WAAW,eAAe,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM;IAC7D,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACxB
|
|
1
|
+
{"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../../src/users/roles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,eAAO,MAAM,OAAO;;;;;;EAMlB,CAAC;AAEH,eAAO,MAAM,aAAa;;;EAGxB,CAAC;AACH,eAAO,MAAM,QAAQ;;;;;;;;;EAAgG,CAAC;AACtH,MAAM,WAAW,eAAe,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM;IAC7D,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACxB"}
|
package/dist/users/roles.js
CHANGED
|
@@ -11,6 +11,4 @@ export const UserListInput = Schema.Struct({
|
|
|
11
11
|
limit: Schema.Number.check(Schema.isInt(), Schema.isBetween({ maximum: 100, minimum: 1 })),
|
|
12
12
|
});
|
|
13
13
|
export const UserList = Schema.Struct({ next: Schema.OptionFromNullOr(Schema.String), users: Schema.Array(AppUser) });
|
|
14
|
-
export class LastRoleAssigner extends Schema.TaggedError()("LastRoleAssigner", { userId: Schema.String }) {
|
|
15
|
-
}
|
|
16
14
|
//# sourceMappingURL=roles.js.map
|
package/dist/users/roles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"roles.js","sourceRoot":"","sources":["../../src/users/roles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;IACpC,SAAS,EAAE,MAAM,CAAC,mBAAmB;IACrC,KAAK,EAAE,MAAM,CAAC,MAAM;IACpB,EAAE,EAAE,MAAM,CAAC,MAAM;IACjB,IAAI,EAAE,MAAM,CAAC,MAAM;IACnB,IAAI,EAAE,MAAM,CAAC,MAAM;CACnB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;IAC1C,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC;IACzC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;CAC1F,CAAC,CAAC;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC
|
|
1
|
+
{"version":3,"file":"roles.js","sourceRoot":"","sources":["../../src/users/roles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;IACpC,SAAS,EAAE,MAAM,CAAC,mBAAmB;IACrC,KAAK,EAAE,MAAM,CAAC,MAAM;IACpB,EAAE,EAAE,MAAM,CAAC,MAAM;IACjB,IAAI,EAAE,MAAM,CAAC,MAAM;IACnB,IAAI,EAAE,MAAM,CAAC,MAAM;CACnB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;IAC1C,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC;IACzC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;CAC1F,CAAC,CAAC;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/admin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.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,21 +41,20 @@
|
|
|
41
41
|
"README.md"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@shivaedev/access": "0.
|
|
45
|
-
"@shivaedev/changes": "0.
|
|
46
|
-
"@shivaedev/contract": "0.24.
|
|
44
|
+
"@shivaedev/access": "0.3.0",
|
|
45
|
+
"@shivaedev/changes": "0.6.0",
|
|
46
|
+
"@shivaedev/contract": "0.24.1",
|
|
47
47
|
"@shivaedev/errors": "0.1.2",
|
|
48
|
-
"@shivaedev/identity": "0.
|
|
49
|
-
"@shivaedev/jobs": "0.23.
|
|
50
|
-
"@shivaedev/react": "0.
|
|
51
|
-
"@shivaedev/sql": "0.26.1"
|
|
48
|
+
"@shivaedev/identity": "0.9.0",
|
|
49
|
+
"@shivaedev/jobs": "0.23.2",
|
|
50
|
+
"@shivaedev/react": "0.24.0"
|
|
52
51
|
},
|
|
53
52
|
"devDependencies": {
|
|
54
53
|
"@effect/atom-react": "4.0.6",
|
|
55
|
-
"@shivaedev/quality": "0.
|
|
56
|
-
"@shivaedev/server": "0.9.
|
|
57
|
-
"@shivaedev/test-sql": "0.
|
|
58
|
-
"@shivaedev/test-story": "0.26.
|
|
54
|
+
"@shivaedev/quality": "0.48.0",
|
|
55
|
+
"@shivaedev/server": "0.9.1",
|
|
56
|
+
"@shivaedev/test-sql": "0.15.0",
|
|
57
|
+
"@shivaedev/test-story": "0.26.2",
|
|
59
58
|
"@types/node": "24.19.2",
|
|
60
59
|
"@types/react": "19.3.0",
|
|
61
60
|
"@types/react-dom": "19.3.0",
|
package/src/permissions.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { permission } from "@shivaedev/access/permission.ts";
|
|
|
2
2
|
import { permissionMiddleware } from "@shivaedev/identity/permission.ts";
|
|
3
3
|
|
|
4
4
|
export const ReadUsers = permission("users.read");
|
|
5
|
-
export const AssignRoles = permission("roles.assign");
|
|
6
5
|
export const ReadJobs = permission("jobs.read");
|
|
7
6
|
export const RetryJobs = permission("jobs.retry");
|
|
8
7
|
export class UsersPermission extends permissionMiddleware<UsersPermission>()("@shivaedev/admin/UsersPermission", ReadUsers) {}
|
package/src/server/users.ts
CHANGED
|
@@ -2,11 +2,12 @@ import { DateTime, Effect, Option, Schema } from "effect";
|
|
|
2
2
|
import { SqlClient, SqlSchema } from "effect/sql";
|
|
3
3
|
import { requirePermission } from "@shivaedev/access/requirePermission.ts";
|
|
4
4
|
import type { AccessPolicy } from "@shivaedev/access/roleSet.ts";
|
|
5
|
-
import {
|
|
5
|
+
import { AssignRoles } from "@shivaedev/access/roles.ts";
|
|
6
|
+
import { AuthUnavailable } from "@shivaedev/errors/taxonomy.ts";
|
|
6
7
|
import { SessionUser } from "@shivaedev/identity/identity.ts";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { AppUser, type ChangeRoleInput,
|
|
8
|
+
import { assignRole } from "@shivaedev/identity/server/better-auth/assignRole.ts";
|
|
9
|
+
import { ReadUsers } from "#permissions.ts";
|
|
10
|
+
import { AppUser, type ChangeRoleInput, type UserListInput } from "#users/roles.ts";
|
|
10
11
|
|
|
11
12
|
function unavailable() {
|
|
12
13
|
return new AuthUnavailable({ message: "Could not access app users" });
|
|
@@ -35,37 +36,7 @@ export const changeUserRole = Effect.fn("Admin.changeUserRole")(function* <TRole
|
|
|
35
36
|
) {
|
|
36
37
|
const actor = yield* SessionUser;
|
|
37
38
|
yield* requirePermission(actor, AssignRoles);
|
|
38
|
-
const
|
|
39
|
-
const changed = yield* Effect.gen(function* () {
|
|
40
|
-
yield* sql`select pg_advisory_xact_lock(hashtext('platform.auth.user-roles'))`;
|
|
41
|
-
const readTarget = SqlSchema.findOneOption({
|
|
42
|
-
execute: (id) => sql`select id, role from "user" where id = ${id} for update`,
|
|
43
|
-
Request: AppUser.fields.id,
|
|
44
|
-
Result: Schema.Struct({ id: AppUser.fields.id, role: Schema.NullOr(AppUser.fields.role) }),
|
|
45
|
-
});
|
|
46
|
-
const target = yield* readTarget(input.userId).pipe(Effect.mapError(unavailable));
|
|
47
|
-
if (Option.isNone(target)) {
|
|
48
|
-
return yield* Effect.fail(new NotFound({ message: "User not found" }));
|
|
49
|
-
}
|
|
50
|
-
if (target.value.role === input.role) {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
const assigners = access.Role.literals.filter((role) => access.hasPermission(role, AssignRoles));
|
|
54
|
-
if (assigners.some((role) => role === target.value.role) && !access.hasPermission(input.role, AssignRoles)) {
|
|
55
|
-
const readHolders = SqlSchema.findAll({
|
|
56
|
-
execute: () => sql`select id from "user" where role in ${sql.in(assigners)}`,
|
|
57
|
-
Request: Schema.Void,
|
|
58
|
-
Result: Schema.Struct({ id: AppUser.fields.id }),
|
|
59
|
-
});
|
|
60
|
-
const holders = yield* readHolders(undefined).pipe(Effect.mapError(unavailable));
|
|
61
|
-
if (holders.length === 1) {
|
|
62
|
-
return yield* Effect.fail(new LastRoleAssigner({ userId: input.userId }));
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
yield* sql`update "user" set role = ${input.role}, "updatedAt" = now() where id = ${input.userId}`;
|
|
66
|
-
yield* invalidateOnCommit(["admin.users"]);
|
|
67
|
-
return true;
|
|
68
|
-
}).pipe(transact({ onSqlError: unavailable }));
|
|
39
|
+
const changed = yield* assignRole(access, input.userId, input.role);
|
|
69
40
|
if (changed) {
|
|
70
41
|
const changedAt = DateTime.formatIso(yield* DateTime.now);
|
|
71
42
|
yield* Effect.logInfo("User role changed").pipe(Effect.annotateLogs({ actorId: actor.id, changedAt, ...input }));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import type { AccessPolicy } from "@shivaedev/access/roleSet.ts";
|
|
3
|
+
import { AssignRoles } from "@shivaedev/access/roles.ts";
|
|
3
4
|
import { SessionUser } from "@shivaedev/identity/identity.ts";
|
|
4
5
|
import { hasPermission } from "@shivaedev/identity/permission.ts";
|
|
5
|
-
import { AssignRoles } from "#permissions.ts";
|
|
6
6
|
import { changeUserRole, listUsers } from "#server/users.ts";
|
|
7
7
|
import type { usersPage } from "#users/page.ts";
|
|
8
8
|
|
package/src/users/page.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import type { AccessPolicy } from "@shivaedev/access/roleSet.ts";
|
|
3
|
+
import { LastRoleAssigner } from "@shivaedev/access/roles.ts";
|
|
3
4
|
import { collection } from "@shivaedev/changes/keys.ts";
|
|
4
5
|
import { contract } from "@shivaedev/contract/contract.ts";
|
|
5
6
|
import { command, query } from "@shivaedev/contract/operation.ts";
|
|
6
7
|
import { AuthUnavailable, Forbidden, NotFound } from "@shivaedev/errors/taxonomy.ts";
|
|
7
8
|
import { adminPage } from "#page.ts";
|
|
8
9
|
import { UsersPermission } from "#permissions.ts";
|
|
9
|
-
import {
|
|
10
|
+
import { UserList, UserListInput } from "#users/roles.ts";
|
|
10
11
|
|
|
11
12
|
const users = collection("admin.users", Schema.String);
|
|
12
13
|
|
package/src/users/roles.ts
CHANGED