@shivaedev/admin 0.5.0 → 0.6.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 +10 -8
- package/dist/client/UsersTable.d.ts +1 -1
- package/dist/client/UsersTable.d.ts.map +1 -1
- package/dist/client/UsersTable.js +1 -1
- package/dist/client/UsersTable.js.map +1 -1
- package/dist/client/UsersView.d.ts +1 -1
- package/dist/client/UsersView.d.ts.map +1 -1
- package/dist/client/UsersView.js +1 -1
- package/dist/client/UsersView.js.map +1 -1
- package/dist/jobs/keys.d.ts +5 -5
- package/dist/jobs/keys.js +1 -1
- package/dist/jobs/keys.js.map +1 -1
- package/dist/jobs/page.d.ts +5 -5
- package/dist/jobs/page.js +2 -2
- package/dist/jobs/page.js.map +1 -1
- package/dist/jobs/retryPage.d.ts +41 -41
- package/dist/jobs/retryPage.js +2 -2
- package/dist/jobs/retryPage.js.map +1 -1
- package/dist/page.d.ts +2 -2
- package/dist/page.d.ts.map +1 -1
- package/dist/permissions.d.ts +1 -1
- package/dist/permissions.js +1 -1
- package/dist/permissions.js.map +1 -1
- package/dist/server/jobsHandlers.d.ts +7 -7
- package/dist/server/jobsHandlers.d.ts.map +1 -1
- package/dist/server/jobsHandlersWithRetry.d.ts +2 -2
- package/dist/server/jobsHandlersWithRetry.d.ts.map +1 -1
- package/dist/server/users.d.ts +24 -0
- package/dist/server/users.d.ts.map +1 -0
- package/dist/server/users.js +65 -0
- package/dist/server/users.js.map +1 -0
- package/dist/server/usersHandlers.js +4 -4
- package/dist/server/usersHandlers.js.map +1 -1
- package/dist/users/page.d.ts +10 -10
- package/dist/users/page.d.ts.map +1 -1
- package/dist/users/page.js +5 -5
- package/dist/users/page.js.map +1 -1
- package/dist/users/roles.d.ts +44 -0
- package/dist/users/roles.d.ts.map +1 -0
- package/dist/users/roles.js +20 -0
- package/dist/users/roles.js.map +1 -0
- package/package.json +12 -9
- package/src/client/UsersTable.tsx +1 -1
- package/src/client/UsersView.ts +2 -2
- package/src/jobs/keys.ts +1 -1
- package/src/jobs/page.ts +2 -2
- package/src/jobs/retryPage.ts +2 -2
- package/src/page.ts +2 -2
- package/src/permissions.ts +1 -1
- package/src/server/jobsHandlers.ts +2 -2
- package/src/server/jobsHandlersWithRetry.ts +1 -1
- package/src/server/users.ts +67 -0
- package/src/server/usersHandlers.ts +4 -4
- package/src/users/page.ts +5 -5
- package/src/users/roles.ts +23 -0
package/README.md
CHANGED
|
@@ -17,14 +17,14 @@ The page exposes `admin.jobs.failed` and the generated `admin.jobs.$changes` sub
|
|
|
17
17
|
|
|
18
18
|
## Use native contracts and Layers
|
|
19
19
|
|
|
20
|
-
Install `@shivaedev/admin` with `effect`, `react` and `@effect/atom-react`. Declare each page's queries, commands and streams with `@shivaedev/
|
|
20
|
+
Install `@shivaedev/admin` with `effect`, `react` and `@effect/atom-react`. Declare each page's queries, commands and streams with `@shivaedev/contract`, then pass its native contract to `adminPage`. The stable id identifies the page at server registration; route metadata belongs to the application's view. Author RPC namespaces in the contract name, such as `admin.jobs`.
|
|
21
21
|
|
|
22
22
|
```ts
|
|
23
23
|
import { Schema } from "effect";
|
|
24
24
|
import { adminPage } from "@shivaedev/admin/page.ts";
|
|
25
25
|
import { adminRegistry } from "@shivaedev/admin/registry.ts";
|
|
26
|
-
import { contract } from "@shivaedev/
|
|
27
|
-
import { query } from "@shivaedev/
|
|
26
|
+
import { contract } from "@shivaedev/contract/contract.ts";
|
|
27
|
+
import { query } from "@shivaedev/contract/operation.ts";
|
|
28
28
|
|
|
29
29
|
const Failed = query("failed", {
|
|
30
30
|
reads: () => [],
|
|
@@ -46,7 +46,7 @@ Register server handler Layers by page id:
|
|
|
46
46
|
import { Effect, Layer } from "effect";
|
|
47
47
|
import { registerAdmin } from "@shivaedev/admin/server/registerAdmin.ts";
|
|
48
48
|
import { AdminPermission, OpenAdmin } from "@shivaedev/admin/permissions.ts";
|
|
49
|
-
import { permissionLayer } from "@shivaedev/
|
|
49
|
+
import { permissionLayer } from "@shivaedev/identity/server/permissions.ts";
|
|
50
50
|
|
|
51
51
|
const registration = registerAdmin(Admin, {
|
|
52
52
|
jobs: Jobs.contract.application.toLayer({
|
|
@@ -58,7 +58,7 @@ const handlers = registration.handlers.pipe(
|
|
|
58
58
|
);
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
Declare application roles with `@shivaedev/access`, grant `OpenAdmin` explicitly, and supply that role set through
|
|
61
|
+
Declare application roles with `@shivaedev/access`, grant `OpenAdmin` explicitly, and supply that role set through the session or auth configuration of `@shivaedev/identity`.
|
|
62
62
|
|
|
63
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.
|
|
64
64
|
|
|
@@ -91,7 +91,7 @@ const registration = registerAdmin(Admin, {
|
|
|
91
91
|
|
|
92
92
|
The queries are `admin.jobs.health`, `admin.jobs.counts`, `admin.jobs.failed`, `admin.jobs.deadLettered` and `admin.jobs.job`. Counts take `{ queue }`; listings take `{ queue, limit, cursor? }` and return `{ jobs, next }`, where `next` is an `Option<string>`. Job lookup takes `{ queue, id }` and returns `Option<Job>`. Each job carries its queue, decoded payload, state, attempt and retry counts, output and timestamps. Dead-letter listings also carry `sourceId` and `sourceOutput`. Timestamps use UTC `DateTime` values; the RPC encodes timestamps as strings and Options as nullable values. The queue's original codec encodes and decodes its payload across RPC, preserving its service requirements.
|
|
93
93
|
|
|
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
|
|
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 jobs health. Unregistered names, including dead-letter queue names passed directly, fail with `JobsQueueUnregistered`. Stored payload decoding failures become `JobsPayloadInvalid`; jobs operation failures become `JobsUnavailable`, carrying the operation name. These declared failures do not expose the original database error.
|
|
95
95
|
|
|
96
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.
|
|
97
97
|
|
|
@@ -110,7 +110,7 @@ const registration = registerAdmin(Admin, {
|
|
|
110
110
|
});
|
|
111
111
|
```
|
|
112
112
|
|
|
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
|
|
113
|
+
This variant adds only `admin.jobs.retry`, taking `{ queue, id }` and returning void. It requires `OpenAdmin`, through the same page middleware. The handler uses the jobs package's existing retry for a failed job in a declared queue. Missing jobs and jobs in other states fail with `JobsNotFailed`; unregistered queue names, including dead-letter queues, fail with `JobsQueueUnregistered`. A dead-letter copy's id cannot retry its original.
|
|
114
114
|
|
|
115
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.
|
|
116
116
|
|
|
@@ -129,7 +129,9 @@ const changeRole = Client.runtime.fn(users.changeRole.run);
|
|
|
129
129
|
<UsersView list={users.list.query} changeRole={changeRole} />;
|
|
130
130
|
```
|
|
131
131
|
|
|
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
|
|
132
|
+
`admin.users.list` takes `{ limit, cursor? }` (1–100 users), returns `{ users, next, canChangeRoles }`, and orders pages by user id. Each user has id, name, email, roles and a UTC sign-up time. All reads and subscriptions require `OpenAdmin`. Callers granted `ChangeUserRoles` (`users.roles.change`) from `@shivaedev/admin/users/roles.ts` see role controls. `admin.users.changeRole` takes `{ userId, role, grant }` for the `user`, `admin` and `owner` roles that module declares, with the browser-safe user schemas and the typed `LastOwner` failure. It returns typed `Forbidden` without that permission, `LastOwner` when revoking the final owner, and `NotFound` for a missing user. Role changes preserve other roles, invalidate the list after commit, and emit an Effect log with actor id, target id, role, action and timestamp. There is no durable audit-history store.
|
|
133
|
+
|
|
134
|
+
The handlers call `listUsers({ limit, cursor? })` and `changeUserRole({ userId, role, grant })` from `@shivaedev/admin/server/users.ts`, which an application can also call from its own server code. Role writes require an owner `SessionUser` and serialize role changes in a transaction.
|
|
133
135
|
|
|
134
136
|
Keep Better Auth cookie caching disabled so requests see current roles. Applications must route role writes through this operation to retain its permission and last-owner policy. The starter disables Better Auth's `/admin/set-role`, `/admin/update-user` and `/admin/create-user` browser endpoints; its server-side bootstrap API remains available.
|
|
135
137
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type ChangeRoleInput } from "@shivaedev/platform/rpc/userRoles.ts";
|
|
2
1
|
import type { UsersList } from "#users/page.ts";
|
|
2
|
+
import { type ChangeRoleInput } from "#users/roles.ts";
|
|
3
3
|
interface RoleControls {
|
|
4
4
|
readonly dispatch: (input: typeof ChangeRoleInput.Type) => void;
|
|
5
5
|
readonly pending: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UsersTable.d.ts","sourceRoot":"","sources":["../../src/client/UsersTable.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"UsersTable.d.ts","sourceRoot":"","sources":["../../src/client/UsersTable.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAgB,KAAK,eAAe,EAAY,MAAM,iBAAiB,CAAC;AAE/E,UAAU,YAAY;IACrB,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,eAAe,CAAC,IAAI,KAAK,IAAI,CAAC;IAChE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC1B;AAuFD,wBAAgB,UAAU,CAAC,EAAE,IAAI,EAAE,GAAG,QAAQ,EAAE,EAAE,YAAY,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,SAAS,CAAC,IAAI,CAAA;CAAE,+BAOxG"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createElement as _createElement } from "react";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { DateTime } from "effect";
|
|
4
|
-
import { UserRole } from "
|
|
4
|
+
import { UserRole } from "#users/roles.ts";
|
|
5
5
|
function UserHeaders() {
|
|
6
6
|
return (_jsx("tr", { children: ["Name", "Email", "Roles", "Signed up"].map((label) => (_jsx("th", { className: "whitespace-nowrap p-3", scope: "col", children: label }, label))) }));
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UsersTable.js","sourceRoot":"","sources":["../../src/client/UsersTable.tsx"],"names":[],"mappings":";;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"UsersTable.js","sourceRoot":"","sources":["../../src/client/UsersTable.tsx"],"names":[],"mappings":";;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,EAAsC,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAO/E,SAAS,WAAW;IACnB,OAAO,CACN,uBACE,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CACvD,aAAI,SAAS,EAAC,uBAAuB,EAAa,KAAK,EAAC,KAAK,YAC3D,KAAK,IADoC,KAAK,CAE3C,CACL,CAAC,GACE,CACL,CAAC;AACH,CAAC;AAED,SAAS,YAAY,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,Q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,SAAS,EAAC,uBAAuB,YACpC,eAAM,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,YAAG,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,GAAQ,GAC3F,IACD,CACL,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,EAAE,IAAI,EAAE,GAAG,QAAQ,EAA2D;IAC/F,OAAO,CACN,cAAK,SAAS,EAAC,mCAAmC,YACjD,iBAAO,SAAS,EAAC,0BAA0B,aAC1C,kBAAS,SAAS,EAAC,SAAS,oCAA8B,EAC1D,gBAAO,SAAS,EAAC,UAAU,YAC1B,KAAC,WAAW,KAAG,GACR,EACR,0BACE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CACzB,eAAC,OAAO,OAAK,QAAQ,EAAE,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,GAAI,CACxF,CAAC,GACK,IACD,GACH,CACN,CAAC;AACH,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,EAAE,IAAI,EAAE,GAAG,QAAQ,EAA2D;IACxG,OAAO,CACN,eAAK,SAAS,EAAC,WAAW,aACxB,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,wDAAoC,EACjE,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,oCAAgB,CAAC,CAAC,CAAC,KAAC,QAAQ,OAAK,QAAQ,EAAE,IAAI,EAAE,IAAI,GAAI,IAC/E,CACN,CAAC;AACH,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
2
2
|
import type * as Atom from "effect/reactivity/Atom";
|
|
3
|
-
import type { ChangeRoleInput, UserListInput } from "@shivaedev/platform/rpc/userRoles.ts";
|
|
4
3
|
import type { UsersList } from "#users/page.ts";
|
|
4
|
+
import type { ChangeRoleInput, UserListInput } from "#users/roles.ts";
|
|
5
5
|
export interface UsersViewProps {
|
|
6
6
|
readonly changeRole: Atom.AtomResultFn<typeof ChangeRoleInput.Type, void, unknown>;
|
|
7
7
|
readonly list: (input: typeof UserListInput.Type) => Atom.Atom<AsyncResult.AsyncResult<typeof UsersList.Type, unknown>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UsersView.d.ts","sourceRoot":"","sources":["../../src/client/UsersView.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAGpD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"UsersView.d.ts","sourceRoot":"","sources":["../../src/client/UsersView.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAGpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGtE,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,OAAO,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACnF,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,aAAa,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,OAAO,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;CACxH;AAaD,wBAAgB,SAAS,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,cAAc;;;gBA6C7D"}
|
package/dist/client/UsersView.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Cause, Option, Predicate } from "effect";
|
|
2
2
|
import { createElement, useState } from "react";
|
|
3
|
-
import { useAction, useQuery } from "@shivaedev/
|
|
3
|
+
import { useAction, useQuery } from "@shivaedev/react/client/resultState.ts";
|
|
4
4
|
import { UsersTable } from "./UsersTable.js";
|
|
5
5
|
function failure(cause) {
|
|
6
6
|
const error = Option.getOrUndefined(Cause.findErrorOption(cause));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UsersView.js","sourceRoot":"","sources":["../../src/client/UsersView.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGlD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"UsersView.js","sourceRoot":"","sources":["../../src/client/UsersView.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGlD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,wCAAwC,CAAC;AAG7E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAkB,CAAC;AAO9C,SAAS,OAAO,CAAC,KAA2B;IAC3C,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;IAClE,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,EAAE,CAAC;QAC5C,OAAO,sEAAsE,CAAC;IAC/E,CAAC;IACD,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,EAAE,CAAC;QAC5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@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare const jobsKeys: {
|
|
2
|
-
counts: import("@shivaedev/
|
|
3
|
-
deadLettered: import("@shivaedev/
|
|
4
|
-
failed: import("@shivaedev/
|
|
5
|
-
health: import("@shivaedev/
|
|
6
|
-
job: (queue: string) => import("@shivaedev/
|
|
2
|
+
counts: import("@shivaedev/contract/keys.ts").Collection<"admin.jobs.counts", string>;
|
|
3
|
+
deadLettered: import("@shivaedev/contract/keys.ts").Collection<"admin.jobs.deadLettered", string>;
|
|
4
|
+
failed: import("@shivaedev/contract/keys.ts").Collection<"admin.jobs.failed", string>;
|
|
5
|
+
health: import("@shivaedev/contract/keys.ts").Collection<"admin.jobs.health", string>;
|
|
6
|
+
job: (queue: string) => import("@shivaedev/contract/keys.ts").Collection<`admin.jobs.job.${string}`, string>;
|
|
7
7
|
};
|
|
8
8
|
//# sourceMappingURL=keys.d.ts.map
|
package/dist/jobs/keys.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
import { collection } from "@shivaedev/
|
|
2
|
+
import { collection } from "@shivaedev/contract/keys.ts";
|
|
3
3
|
export const jobsKeys = {
|
|
4
4
|
counts: collection("admin.jobs.counts", Schema.String),
|
|
5
5
|
deadLettered: collection("admin.jobs.deadLettered", Schema.String),
|
package/dist/jobs/keys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../src/jobs/keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../src/jobs/keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEzD,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB,MAAM,EAAE,UAAU,CAAC,mBAAmB,EAAE,MAAM,CAAC,MAAM,CAAC;IACtD,YAAY,EAAE,UAAU,CAAC,yBAAyB,EAAE,MAAM,CAAC,MAAM,CAAC;IAClE,MAAM,EAAE,UAAU,CAAC,mBAAmB,EAAE,MAAM,CAAC,MAAM,CAAC;IACtD,MAAM,EAAE,UAAU,CAAC,mBAAmB,EAAE,MAAM,CAAC,MAAM,CAAC;IACtD,GAAG,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,UAAU,CAAC,kBAAkB,KAAK,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC;CAC5E,CAAC"}
|
package/dist/jobs/page.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Schema } from "effect";
|
|
|
2
2
|
import { type JobsQueue } from "./schemas.ts";
|
|
3
3
|
export declare function jobsPage<const TQueues extends readonly JobsQueue[]>(...queues: TQueues): import("#page.ts").AdminPage & {
|
|
4
4
|
readonly id: "jobs";
|
|
5
|
-
readonly contract: import("@shivaedev/
|
|
5
|
+
readonly contract: import("@shivaedev/contract/contract.ts").Contract<"admin.jobs", readonly [NoInfer<import("@shivaedev/contract/operation.ts").Query<"health", Schema.Void, Schema.Struct<{
|
|
6
6
|
readonly activeTotal: Schema.Number;
|
|
7
7
|
readonly deadLetteredTotal: Schema.Number;
|
|
8
8
|
readonly failedTotal: Schema.Number;
|
|
@@ -20,7 +20,7 @@ export declare function jobsPage<const TQueues extends readonly JobsQueue[]>(...
|
|
|
20
20
|
JobsPayloadInvalid: typeof import("./schemas.ts").JobsPayloadInvalid;
|
|
21
21
|
JobsQueueUnregistered: typeof import("./schemas.ts").JobsQueueUnregistered;
|
|
22
22
|
JobsUnavailable: typeof import("./schemas.ts").JobsUnavailable;
|
|
23
|
-
}>>, NoInfer<import("@shivaedev/
|
|
23
|
+
}>>, NoInfer<import("@shivaedev/contract/operation.ts").Query<"counts", Schema.Struct<{
|
|
24
24
|
queue: Schema.String;
|
|
25
25
|
}>, Schema.Struct<{
|
|
26
26
|
readonly activeCount: Schema.Number;
|
|
@@ -31,7 +31,7 @@ export declare function jobsPage<const TQueues extends readonly JobsQueue[]>(...
|
|
|
31
31
|
JobsPayloadInvalid: typeof import("./schemas.ts").JobsPayloadInvalid;
|
|
32
32
|
JobsQueueUnregistered: typeof import("./schemas.ts").JobsQueueUnregistered;
|
|
33
33
|
JobsUnavailable: typeof import("./schemas.ts").JobsUnavailable;
|
|
34
|
-
}>>, NoInfer<import("@shivaedev/
|
|
34
|
+
}>>, NoInfer<import("@shivaedev/contract/operation.ts").Query<"failed", Schema.Struct<{
|
|
35
35
|
cursor: Schema.optionalKey<Schema.String>;
|
|
36
36
|
limit: Schema.Number;
|
|
37
37
|
queue: Schema.String;
|
|
@@ -54,7 +54,7 @@ export declare function jobsPage<const TQueues extends readonly JobsQueue[]>(...
|
|
|
54
54
|
JobsPayloadInvalid: typeof import("./schemas.ts").JobsPayloadInvalid;
|
|
55
55
|
JobsQueueUnregistered: typeof import("./schemas.ts").JobsQueueUnregistered;
|
|
56
56
|
JobsUnavailable: typeof import("./schemas.ts").JobsUnavailable;
|
|
57
|
-
}>>, NoInfer<import("@shivaedev/
|
|
57
|
+
}>>, NoInfer<import("@shivaedev/contract/operation.ts").Query<"deadLettered", Schema.Struct<{
|
|
58
58
|
cursor: Schema.optionalKey<Schema.String>;
|
|
59
59
|
limit: Schema.Number;
|
|
60
60
|
queue: Schema.String;
|
|
@@ -79,7 +79,7 @@ export declare function jobsPage<const TQueues extends readonly JobsQueue[]>(...
|
|
|
79
79
|
JobsPayloadInvalid: typeof import("./schemas.ts").JobsPayloadInvalid;
|
|
80
80
|
JobsQueueUnregistered: typeof import("./schemas.ts").JobsQueueUnregistered;
|
|
81
81
|
JobsUnavailable: typeof import("./schemas.ts").JobsUnavailable;
|
|
82
|
-
}>>, NoInfer<import("@shivaedev/
|
|
82
|
+
}>>, NoInfer<import("@shivaedev/contract/operation.ts").Query<"job", Schema.Struct<{
|
|
83
83
|
id: Schema.String;
|
|
84
84
|
queue: Schema.String;
|
|
85
85
|
}>, Schema.OptionFromNullOr<Schema.Union<Schema.Struct<{
|
package/dist/jobs/page.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
import { contract } from "@shivaedev/
|
|
3
|
-
import { query } from "@shivaedev/
|
|
2
|
+
import { contract } from "@shivaedev/contract/contract.ts";
|
|
3
|
+
import { query } from "@shivaedev/contract/operation.ts";
|
|
4
4
|
import { adminPage } from "#page.ts";
|
|
5
5
|
import { jobsKeys } from "./keys.js";
|
|
6
6
|
import { deadLetteredSchema, JobsFailures, JobsHealth, jobPage, jobSchema, PageFields, QueueCounts } from "./schemas.js";
|
package/dist/jobs/page.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/jobs/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/jobs/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,UAAU,EAAkB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEzI,MAAM,UAAU,QAAQ,CAA6C,GAAG,MAAe;IACtF,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,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E,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;oBACzD,UAAU,EAAE,YAAY;oBACxB,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC;iBAC9B,CAAC;gBACF,KAAK,CAAC,KAAK,EAAE;oBACZ,OAAO,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE;oBACpD,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;oBACxD,UAAU,EAAE,YAAY;oBACxB,OAAO,EAAE,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC;iBACrC,CAAC;aACF;SACD,CAAC;QACF,EAAE,EAAE,MAAM;QACV,KAAK,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE;KAC7C,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;AACxC,CAAC"}
|
package/dist/jobs/retryPage.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare class JobsNotFailed extends JobsNotFailed_base {
|
|
|
8
8
|
}
|
|
9
9
|
export declare function jobsPageWithRetry<const TQueues extends readonly JobsQueue[]>(...queues: TQueues): import("#page.ts").AdminPage & {
|
|
10
10
|
readonly id: "jobs";
|
|
11
|
-
readonly contract: import("@shivaedev/
|
|
11
|
+
readonly contract: import("@shivaedev/contract/contract.ts").Contract<"admin.jobs", readonly [NoInfer<import("@shivaedev/contract/operation.ts").Query<"health", Schema.Void, Schema.Struct<{
|
|
12
12
|
readonly activeTotal: Schema.Number;
|
|
13
13
|
readonly deadLetteredTotal: Schema.Number;
|
|
14
14
|
readonly failedTotal: Schema.Number;
|
|
@@ -26,7 +26,7 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsQue
|
|
|
26
26
|
JobsPayloadInvalid: typeof import("./schemas.ts").JobsPayloadInvalid;
|
|
27
27
|
JobsQueueUnregistered: typeof import("./schemas.ts").JobsQueueUnregistered;
|
|
28
28
|
JobsUnavailable: typeof import("./schemas.ts").JobsUnavailable;
|
|
29
|
-
}>>, NoInfer<import("@shivaedev/
|
|
29
|
+
}>>, NoInfer<import("@shivaedev/contract/operation.ts").Query<"counts", Schema.Struct<{
|
|
30
30
|
queue: Schema.String;
|
|
31
31
|
}>, Schema.Struct<{
|
|
32
32
|
readonly activeCount: Schema.Number;
|
|
@@ -37,7 +37,7 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsQue
|
|
|
37
37
|
JobsPayloadInvalid: typeof import("./schemas.ts").JobsPayloadInvalid;
|
|
38
38
|
JobsQueueUnregistered: typeof import("./schemas.ts").JobsQueueUnregistered;
|
|
39
39
|
JobsUnavailable: typeof import("./schemas.ts").JobsUnavailable;
|
|
40
|
-
}>>, NoInfer<import("@shivaedev/
|
|
40
|
+
}>>, NoInfer<import("@shivaedev/contract/operation.ts").Query<"failed", Schema.Struct<{
|
|
41
41
|
cursor: Schema.optionalKey<Schema.String>;
|
|
42
42
|
limit: Schema.Number;
|
|
43
43
|
queue: Schema.String;
|
|
@@ -60,7 +60,7 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsQue
|
|
|
60
60
|
JobsPayloadInvalid: typeof import("./schemas.ts").JobsPayloadInvalid;
|
|
61
61
|
JobsQueueUnregistered: typeof import("./schemas.ts").JobsQueueUnregistered;
|
|
62
62
|
JobsUnavailable: typeof import("./schemas.ts").JobsUnavailable;
|
|
63
|
-
}>>, NoInfer<import("@shivaedev/
|
|
63
|
+
}>>, NoInfer<import("@shivaedev/contract/operation.ts").Query<"deadLettered", Schema.Struct<{
|
|
64
64
|
cursor: Schema.optionalKey<Schema.String>;
|
|
65
65
|
limit: Schema.Number;
|
|
66
66
|
queue: Schema.String;
|
|
@@ -85,7 +85,7 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsQue
|
|
|
85
85
|
JobsPayloadInvalid: typeof import("./schemas.ts").JobsPayloadInvalid;
|
|
86
86
|
JobsQueueUnregistered: typeof import("./schemas.ts").JobsQueueUnregistered;
|
|
87
87
|
JobsUnavailable: typeof import("./schemas.ts").JobsUnavailable;
|
|
88
|
-
}>>, NoInfer<import("@shivaedev/
|
|
88
|
+
}>>, NoInfer<import("@shivaedev/contract/operation.ts").Query<"job", Schema.Struct<{
|
|
89
89
|
id: Schema.String;
|
|
90
90
|
queue: Schema.String;
|
|
91
91
|
}>, Schema.OptionFromNullOr<Schema.Union<Schema.Struct<{
|
|
@@ -104,7 +104,7 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsQue
|
|
|
104
104
|
JobsPayloadInvalid: typeof import("./schemas.ts").JobsPayloadInvalid;
|
|
105
105
|
JobsQueueUnregistered: typeof import("./schemas.ts").JobsQueueUnregistered;
|
|
106
106
|
JobsUnavailable: typeof import("./schemas.ts").JobsUnavailable;
|
|
107
|
-
}>>], readonly [NoInfer<import("@shivaedev/
|
|
107
|
+
}>>], readonly [NoInfer<import("@shivaedev/contract/operation.ts").Command<"retry", Schema.Struct<{
|
|
108
108
|
id: Schema.String;
|
|
109
109
|
queue: Schema.String;
|
|
110
110
|
}>, Schema.Void, {
|
|
@@ -112,7 +112,22 @@ 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
|
|
115
|
+
}>>], import("effect/rpc/Rpc").Rpc<"admin.jobs.job", Schema.Struct<{
|
|
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("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.$changes", Schema.Struct<{
|
|
116
131
|
queries: Schema.$Array<Schema.Union<readonly (Schema.Struct<{
|
|
117
132
|
query: Schema.Literal<"counts">;
|
|
118
133
|
payload: Schema.Struct<{
|
|
@@ -161,7 +176,21 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsQue
|
|
|
161
176
|
readonly failedCount: Schema.Number;
|
|
162
177
|
readonly queuedCount: Schema.Number;
|
|
163
178
|
readonly totalCount: Schema.Number;
|
|
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.
|
|
179
|
+
}>, 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<{
|
|
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("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.failed", Schema.Struct<{
|
|
165
194
|
cursor: Schema.optionalKey<Schema.String>;
|
|
166
195
|
limit: Schema.Number;
|
|
167
196
|
queue: Schema.String;
|
|
@@ -178,11 +207,9 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsQue
|
|
|
178
207
|
readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
|
|
179
208
|
readonly data: [...TQueues][number]["schema"];
|
|
180
209
|
readonly queue: Schema.Literal<string>;
|
|
181
|
-
readonly sourceId: Schema.OptionFromNullOr<Schema.String>;
|
|
182
|
-
readonly sourceOutput: Schema.Unknown;
|
|
183
210
|
}>[]>>;
|
|
184
211
|
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
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.
|
|
212
|
+
}>, 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<{
|
|
186
213
|
cursor: Schema.optionalKey<Schema.String>;
|
|
187
214
|
limit: Schema.Number;
|
|
188
215
|
queue: Schema.String;
|
|
@@ -199,38 +226,11 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsQue
|
|
|
199
226
|
readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
|
|
200
227
|
readonly data: [...TQueues][number]["schema"];
|
|
201
228
|
readonly queue: Schema.Literal<string>;
|
|
229
|
+
readonly sourceId: Schema.OptionFromNullOr<Schema.String>;
|
|
230
|
+
readonly sourceOutput: Schema.Unknown;
|
|
202
231
|
}>[]>>;
|
|
203
232
|
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
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.
|
|
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<{
|
|
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
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>;
|
package/dist/jobs/retryPage.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
import { contract } from "@shivaedev/
|
|
3
|
-
import { command } from "@shivaedev/
|
|
2
|
+
import { contract } from "@shivaedev/contract/contract.ts";
|
|
3
|
+
import { command } from "@shivaedev/contract/operation.ts";
|
|
4
4
|
import { adminPage } from "#page.ts";
|
|
5
5
|
import { jobsKeys } from "./keys.js";
|
|
6
6
|
import { jobsPage } from "./page.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryPage.js","sourceRoot":"","sources":["../../src/jobs/retryPage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"retryPage.js","sourceRoot":"","sources":["../../src/jobs/retryPage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,YAAY,EAAkB,MAA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type { Rpc, RpcGroup } from "effect/rpc";
|
|
2
|
-
import type { Contract } from "@shivaedev/
|
|
3
|
-
import type { CommandShape, QueryShape, StreamShape } from "@shivaedev/
|
|
2
|
+
import type { Contract } from "@shivaedev/contract/contract.ts";
|
|
3
|
+
import type { CommandShape, QueryShape, StreamShape } from "@shivaedev/contract/operation.ts";
|
|
4
4
|
import { AdminPermission } from "#permissions.ts";
|
|
5
5
|
export interface AdminRoute {
|
|
6
6
|
readonly path: string;
|
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,
|
|
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,iCAAiC,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC9F,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/permissions.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const OpenAdmin: {
|
|
|
6
6
|
readonly name: "admin.open";
|
|
7
7
|
readonly strength: "own";
|
|
8
8
|
};
|
|
9
|
-
declare const AdminPermission_base: import("effect/rpc/RpcMiddleware").ServiceClass<AdminPermission, "@shivaedev/admin/Permission", import("@shivaedev/
|
|
9
|
+
declare const AdminPermission_base: import("effect/rpc/RpcMiddleware").ServiceClass<AdminPermission, "@shivaedev/admin/Permission", import("@shivaedev/identity/identity.ts").Identity | import("@shivaedev/identity/identity.ts").SessionUser, import("effect/Schema").Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden]>, never, never, false> & {
|
|
10
10
|
permission: import("@shivaedev/access/permission.ts").Permission;
|
|
11
11
|
};
|
|
12
12
|
export declare class AdminPermission extends AdminPermission_base {
|
package/dist/permissions.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { permission } from "@shivaedev/access/permission.ts";
|
|
2
|
-
import { permissionMiddleware } from "@shivaedev/
|
|
2
|
+
import { permissionMiddleware } from "@shivaedev/identity/permission.ts";
|
|
3
3
|
export const OpenAdmin = permission("admin.open");
|
|
4
4
|
export class AdminPermission extends permissionMiddleware()("@shivaedev/admin/Permission", OpenAdmin) {
|
|
5
5
|
}
|
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,
|
|
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,OAAO,eAAgB,SAAQ,oBAAoB,EAAmB,CAAC,6BAA6B,EAAE,SAAS,CAAC;CAAG"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Context, DateTime, Effect, Option } from "effect";
|
|
2
|
-
import type { PgBossError, PgBossPayloadError } from "@shivaedev/
|
|
3
|
-
import type { PgBossService } from "@shivaedev/
|
|
2
|
+
import type { PgBossError, PgBossPayloadError } from "@shivaedev/jobs/server/error.ts";
|
|
3
|
+
import type { PgBossService } from "@shivaedev/jobs/server/service.ts";
|
|
4
4
|
import type { jobsPage } from "#jobs/page.ts";
|
|
5
5
|
import { JobsPayloadInvalid, type JobsQueue, JobsQueueUnregistered, JobsUnavailable } from "#jobs/schemas.ts";
|
|
6
6
|
export declare function jobsFailures<A, R>(effect: Effect.Effect<A, PgBossError | PgBossPayloadError, R>): Effect.Effect<A, JobsPayloadInvalid | JobsUnavailable, R>;
|
|
@@ -9,22 +9,22 @@ export declare function jobsReadHandlers<const TQueues extends readonly JobsQueu
|
|
|
9
9
|
}, service: Context.Service<TService, PgBossService>): {
|
|
10
10
|
"admin.jobs.counts": ({ queue }: {
|
|
11
11
|
readonly queue: string;
|
|
12
|
-
}) => Effect.Effect<import("@shivaedev/
|
|
12
|
+
}) => Effect.Effect<import("@shivaedev/jobs/server/health.ts").QueueCounts, JobsPayloadInvalid | JobsQueueUnregistered | JobsUnavailable, TService>;
|
|
13
13
|
"admin.jobs.deadLettered": ({ queue, ...options }: {
|
|
14
14
|
readonly queue: string;
|
|
15
15
|
readonly limit: number;
|
|
16
16
|
readonly cursor?: string;
|
|
17
|
-
}) => Effect.Effect<import("@shivaedev/
|
|
17
|
+
}) => Effect.Effect<import("@shivaedev/jobs/server/health.ts").JobPage<import("@shivaedev/jobs/server/health.ts").DeadLetteredJob<TQueues[number]["schema"]["Type"]>>, JobsPayloadInvalid | JobsQueueUnregistered | JobsUnavailable, TService | TQueues[number]["schema"]["DecodingServices"]>;
|
|
18
18
|
"admin.jobs.failed": ({ queue, ...options }: {
|
|
19
19
|
readonly queue: string;
|
|
20
20
|
readonly limit: number;
|
|
21
21
|
readonly cursor?: string;
|
|
22
|
-
}) => Effect.Effect<import("@shivaedev/
|
|
22
|
+
}) => Effect.Effect<import("@shivaedev/jobs/server/health.ts").JobPage<import("@shivaedev/jobs/server/health.ts").ListedJob<TQueues[number]["schema"]["Type"]>>, JobsPayloadInvalid | JobsQueueUnregistered | JobsUnavailable, TService | TQueues[number]["schema"]["DecodingServices"]>;
|
|
23
23
|
"admin.jobs.health": () => Effect.Effect<{
|
|
24
24
|
activeTotal: number;
|
|
25
25
|
deadLetteredTotal: number;
|
|
26
26
|
failedTotal: number;
|
|
27
|
-
jobs: import("@shivaedev/
|
|
27
|
+
jobs: import("@shivaedev/jobs/server/health.ts").QueueHealth[];
|
|
28
28
|
queuedTotal: number;
|
|
29
29
|
readyTotal: number;
|
|
30
30
|
}, JobsPayloadInvalid | JobsUnavailable, TService>;
|
|
@@ -45,5 +45,5 @@ export declare function jobsReadHandlers<const TQueues extends readonly JobsQueu
|
|
|
45
45
|
state: "active" | "cancelled" | "completed" | "created" | "failed" | "retry";
|
|
46
46
|
}>, JobsPayloadInvalid | JobsQueueUnregistered | JobsUnavailable, TService | TQueues[number]["schema"]["DecodingServices"]>;
|
|
47
47
|
};
|
|
48
|
-
export declare function jobsHandlers<const TQueues extends readonly JobsQueue[], TService>(page: ReturnType<typeof jobsPage<TQueues>>, service: Context.Service<TService, PgBossService>): import("effect/Layer").Layer<import("effect/rpc/Rpc").Handler<"admin.jobs.counts"> | import("effect/rpc/Rpc").Handler<"admin.jobs.deadLettered"> | import("effect/rpc/Rpc").Handler<"admin.jobs.failed"> | import("effect/rpc/Rpc").Handler<"admin.jobs.health"> | import("effect/rpc/Rpc").Handler<"admin.jobs.job">, never, Exclude<Exclude<TService, import("@shivaedev/
|
|
48
|
+
export declare function jobsHandlers<const TQueues extends readonly JobsQueue[], TService>(page: ReturnType<typeof jobsPage<TQueues>>, service: Context.Service<TService, PgBossService>): import("effect/Layer").Layer<import("effect/rpc/Rpc").Handler<"admin.jobs.counts"> | import("effect/rpc/Rpc").Handler<"admin.jobs.deadLettered"> | import("effect/rpc/Rpc").Handler<"admin.jobs.failed"> | import("effect/rpc/Rpc").Handler<"admin.jobs.health"> | import("effect/rpc/Rpc").Handler<"admin.jobs.job">, never, Exclude<Exclude<TService, import("@shivaedev/identity/identity.ts").Identity | import("@shivaedev/identity/identity.ts").SessionUser>, import("effect/Scope").Scope> | Exclude<Exclude<TService, import("@shivaedev/identity/identity.ts").Identity | import("@shivaedev/identity/identity.ts").SessionUser>, import("effect/Scope").Scope> | Exclude<Exclude<TQueues[number]["schema"]["DecodingServices"], import("@shivaedev/identity/identity.ts").Identity | import("@shivaedev/identity/identity.ts").SessionUser>, import("effect/Scope").Scope>>;
|
|
49
49
|
//# sourceMappingURL=jobsHandlers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jobsHandlers.d.ts","sourceRoot":"","sources":["../../src/server/jobsHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"jobsHandlers.d.ts","sourceRoot":"","sources":["../../src/server/jobsHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACvF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,KAAK,SAAS,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE9G,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,GAAG,kBAAkB,EAAE,CAAC,CAAC,6DAM/F;AAED,wBAAgB,gBAAgB,CAAC,KAAK,CAAC,OAAO,SAAS,SAAS,SAAS,EAAE,EAAE,QAAQ,EACpF,IAAI,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;CAAE,EAClC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,aAAa,CAAC;IAQhD,mBAAmB,cAAc;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE;IAM3D,yBAAyB,0BAA0B;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;IAM/H,mBAAmB,0BAA0B;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;IAMzH,mBAAmB;;;;;;;;IAcnB,gBAAgB,kBAAkB;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE;;;;;;;;;;;;;EAmBlF;AAED,wBAAgB,YAAY,CAAC,KAAK,CAAC,OAAO,SAAS,SAAS,SAAS,EAAE,EAAE,QAAQ,EAChF,IAAI,EAAE,UAAU,CAAC,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC,EAC1C,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,aAAa,CAAC,01BAGjD"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Context } from "effect";
|
|
2
|
-
import type { PgBossService } from "@shivaedev/
|
|
2
|
+
import type { PgBossService } from "@shivaedev/jobs/server/service.ts";
|
|
3
3
|
import { type jobsPageWithRetry } from "#jobs/retryPage.ts";
|
|
4
4
|
import { type JobsQueue } from "#jobs/schemas.ts";
|
|
5
|
-
export declare function jobsHandlersWithRetry<const TQueues extends readonly JobsQueue[], TService>(page: ReturnType<typeof jobsPageWithRetry<TQueues>>, service: Context.Service<TService, PgBossService>): import("effect/Layer").Layer<import("effect/rpc/Rpc").Handler<"admin.jobs.counts"> | import("effect/rpc/Rpc").Handler<"admin.jobs.deadLettered"> | import("effect/rpc/Rpc").Handler<"admin.jobs.failed"> | import("effect/rpc/Rpc").Handler<"admin.jobs.health"> | import("effect/rpc/Rpc").Handler<"admin.jobs.job"> | import("effect/rpc/Rpc").Handler<"admin.jobs.retry">, never, Exclude<Exclude<TService, import("@shivaedev/
|
|
5
|
+
export declare function jobsHandlersWithRetry<const TQueues extends readonly JobsQueue[], TService>(page: ReturnType<typeof jobsPageWithRetry<TQueues>>, service: Context.Service<TService, PgBossService>): import("effect/Layer").Layer<import("effect/rpc/Rpc").Handler<"admin.jobs.counts"> | import("effect/rpc/Rpc").Handler<"admin.jobs.deadLettered"> | import("effect/rpc/Rpc").Handler<"admin.jobs.failed"> | import("effect/rpc/Rpc").Handler<"admin.jobs.health"> | import("effect/rpc/Rpc").Handler<"admin.jobs.job"> | import("effect/rpc/Rpc").Handler<"admin.jobs.retry">, never, Exclude<Exclude<TService, import("@shivaedev/identity/identity.ts").Identity | import("@shivaedev/identity/identity.ts").SessionUser>, import("effect/Scope").Scope> | Exclude<Exclude<TService, import("@shivaedev/identity/identity.ts").Identity | import("@shivaedev/identity/identity.ts").SessionUser>, import("effect/Scope").Scope> | Exclude<Exclude<TQueues[number]["schema"]["DecodingServices"], import("@shivaedev/identity/identity.ts").Identity | import("@shivaedev/identity/identity.ts").SessionUser>, import("effect/Scope").Scope>>;
|
|
6
6
|
//# sourceMappingURL=jobsHandlersWithRetry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jobsHandlersWithRetry.d.ts","sourceRoot":"","sources":["../../src/server/jobsHandlersWithRetry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAkB,MAAM,QAAQ,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"jobsHandlersWithRetry.d.ts","sourceRoot":"","sources":["../../src/server/jobsHandlersWithRetry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAkB,MAAM,QAAQ,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,KAAK,SAAS,EAAyB,MAAM,kBAAkB,CAAC;AAGzE,wBAAgB,qBAAqB,CAAC,KAAK,CAAC,OAAO,SAAS,SAAS,SAAS,EAAE,EAAE,QAAQ,EACzF,IAAI,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,OAAO,CAAC,CAAC,EACnD,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,aAAa,CAAC,i5BAkBjD"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DateTime, Effect, Option } from "effect";
|
|
2
|
+
import { SqlClient } from "effect/sql";
|
|
3
|
+
import { AuthUnavailable, NotFound } from "@shivaedev/errors/taxonomy.ts";
|
|
4
|
+
import { SessionUser } from "@shivaedev/identity/identity.ts";
|
|
5
|
+
import { LastOwner } from "#users/roles.ts";
|
|
6
|
+
export declare const listUsers: (input: {
|
|
7
|
+
readonly cursor?: string;
|
|
8
|
+
readonly limit: number;
|
|
9
|
+
}) => Effect.Effect<{
|
|
10
|
+
next: Option.Option<string>;
|
|
11
|
+
users: {
|
|
12
|
+
email: string;
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
createdAt: DateTime.Utc;
|
|
16
|
+
roles: string[];
|
|
17
|
+
}[];
|
|
18
|
+
}, AuthUnavailable, SqlClient.SqlClient>;
|
|
19
|
+
export declare const changeUserRole: (input: {
|
|
20
|
+
readonly grant: boolean;
|
|
21
|
+
readonly role: "admin" | "owner" | "user";
|
|
22
|
+
readonly userId: string;
|
|
23
|
+
}) => Effect.Effect<void, AuthUnavailable | import("@shivaedev/errors/taxonomy.ts").Forbidden | LastOwner | NotFound, import("effect/reactivity/Reactivity").Reactivity | SessionUser | SqlClient.SqlClient>;
|
|
24
|
+
//# sourceMappingURL=users.d.ts.map
|
|
@@ -0,0 +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;AAClD,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAG9D,OAAO,EAAyC,SAAS,EAAsB,MAAM,iBAAiB,CAAC;AAavG,eAAO,MAAM,SAAS;;;;;;;;;;;;wCAepB,CAAC;AAEH,eAAO,MAAM,cAAc;;;;4MA8BzB,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { DateTime, Effect, Option, Schema } from "effect";
|
|
2
|
+
import { SqlClient, SqlSchema } from "effect/sql";
|
|
3
|
+
import { AuthUnavailable, NotFound } from "@shivaedev/errors/taxonomy.ts";
|
|
4
|
+
import { SessionUser } from "@shivaedev/identity/identity.ts";
|
|
5
|
+
import { requirePermission } from "@shivaedev/identity/permission.ts";
|
|
6
|
+
import { invalidateOnCommit, transact } from "@shivaedev/sql/transact.ts";
|
|
7
|
+
import { ChangeUserRoles, LastOwner } from "#users/roles.ts";
|
|
8
|
+
const StoredUser = Schema.Struct({
|
|
9
|
+
createdAt: Schema.Date,
|
|
10
|
+
email: Schema.String,
|
|
11
|
+
id: Schema.String,
|
|
12
|
+
name: Schema.String,
|
|
13
|
+
role: Schema.NullOr(Schema.String),
|
|
14
|
+
});
|
|
15
|
+
function unavailable() {
|
|
16
|
+
return new AuthUnavailable({ message: "Could not access app users" });
|
|
17
|
+
}
|
|
18
|
+
export const listUsers = Effect.fn("Platform.listUsers")(function* (input) {
|
|
19
|
+
const sql = yield* SqlClient.SqlClient;
|
|
20
|
+
const read = SqlSchema.findAll({
|
|
21
|
+
execute: () => sql `select id, name, email, role, "createdAt" from "user"
|
|
22
|
+
where id > ${input.cursor ?? ""} order by id limit ${input.limit + 1}`,
|
|
23
|
+
Request: Schema.Void,
|
|
24
|
+
Result: StoredUser,
|
|
25
|
+
});
|
|
26
|
+
const rows = yield* read(undefined).pipe(Effect.mapError(unavailable));
|
|
27
|
+
const users = rows.slice(0, input.limit).map(({ role, createdAt, ...user }) => ({
|
|
28
|
+
...user,
|
|
29
|
+
createdAt: DateTime.makeUnsafe(createdAt),
|
|
30
|
+
roles: role?.split(",").filter(Boolean) ?? [],
|
|
31
|
+
}));
|
|
32
|
+
return { next: rows.length > input.limit ? Option.fromUndefinedOr(users.at(-1)?.id) : Option.none(), users };
|
|
33
|
+
});
|
|
34
|
+
export const changeUserRole = Effect.fn("Platform.changeUserRole")(function* (input) {
|
|
35
|
+
const actor = yield* SessionUser;
|
|
36
|
+
yield* requirePermission(ChangeUserRoles);
|
|
37
|
+
const sql = yield* SqlClient.SqlClient;
|
|
38
|
+
const changed = yield* Effect.gen(function* () {
|
|
39
|
+
yield* sql `select pg_advisory_xact_lock(hashtext('platform.auth.user-roles'))`;
|
|
40
|
+
const rows = yield* sql `select id, role from "user" where id = ${input.userId} for update`;
|
|
41
|
+
const target = rows[0];
|
|
42
|
+
if (target === undefined) {
|
|
43
|
+
return yield* Effect.fail(new NotFound({ message: "User not found" }));
|
|
44
|
+
}
|
|
45
|
+
const roles = target.role?.split(",").filter(Boolean) ?? [];
|
|
46
|
+
if (input.grant === roles.includes(input.role)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (!input.grant && input.role === "owner") {
|
|
50
|
+
const owners = yield* sql `select id from "user" where 'owner' = any(string_to_array(role, ','))`;
|
|
51
|
+
if (owners.length === 1) {
|
|
52
|
+
return yield* Effect.fail(new LastOwner({ userId: input.userId }));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const next = input.grant ? [...roles, input.role] : roles.filter((role) => role !== input.role);
|
|
56
|
+
yield* sql `update "user" set role = ${next.join(",")}, "updatedAt" = now() where id = ${input.userId}`;
|
|
57
|
+
yield* invalidateOnCommit(["admin.users"]);
|
|
58
|
+
return true;
|
|
59
|
+
}).pipe(transact({ onSqlError: unavailable }));
|
|
60
|
+
if (changed) {
|
|
61
|
+
const changedAt = DateTime.formatIso(yield* DateTime.now);
|
|
62
|
+
yield* Effect.logInfo("User role changed").pipe(Effect.annotateLogs({ actorId: actor.id, changedAt, ...input }));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
//# sourceMappingURL=users.js.map
|
|
@@ -0,0 +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,eAAe,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAwB,eAAe,EAAE,SAAS,EAAsB,MAAM,iBAAiB,CAAC;AAEvG,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;IAChC,SAAS,EAAE,MAAM,CAAC,IAAI;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AAE,CAAC,CAAC,CAAC;IAClH,CAAC;AACF,CAAC,CAAC,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { SessionUser } from "@shivaedev/
|
|
3
|
-
import { hasPermission } from "@shivaedev/
|
|
4
|
-
import {
|
|
5
|
-
import { changeUserRole, listUsers } from "@shivaedev/platform/server/better-auth/users.ts";
|
|
2
|
+
import { SessionUser } from "@shivaedev/identity/identity.ts";
|
|
3
|
+
import { hasPermission } from "@shivaedev/identity/permission.ts";
|
|
4
|
+
import { changeUserRole, listUsers } from "#server/users.ts";
|
|
6
5
|
import { UsersPage } from "#users/page.ts";
|
|
6
|
+
import { ChangeUserRoles } from "#users/roles.ts";
|
|
7
7
|
export const usersHandlers = UsersPage.contract.application.toLayer({
|
|
8
8
|
"admin.users.changeRole": changeUserRole,
|
|
9
9
|
"admin.users.list": (input) => Effect.gen(function* () {
|
|
@@ -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,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;AAChC,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;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
import { AuthUnavailable, Forbidden, NotFound } from "@shivaedev/
|
|
3
|
-
import { LastOwner } from "
|
|
2
|
+
import { AuthUnavailable, Forbidden, NotFound } from "@shivaedev/errors/taxonomy.ts";
|
|
3
|
+
import { LastOwner } from "#users/roles.ts";
|
|
4
4
|
export declare const UsersList: Schema.Struct<{
|
|
5
5
|
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
6
6
|
readonly users: Schema.$Array<Schema.Struct<{
|
|
@@ -14,7 +14,7 @@ export declare const UsersList: Schema.Struct<{
|
|
|
14
14
|
}>;
|
|
15
15
|
export declare const UsersPage: import("#page.ts").AdminPage & {
|
|
16
16
|
readonly id: "users";
|
|
17
|
-
readonly contract: import("@shivaedev/
|
|
17
|
+
readonly contract: import("@shivaedev/contract/contract.ts").Contract<"admin.users", readonly [NoInfer<import("@shivaedev/contract/operation.ts").Query<"list", Schema.Struct<{
|
|
18
18
|
readonly cursor: Schema.optionalKey<Schema.String>;
|
|
19
19
|
readonly limit: Schema.Number;
|
|
20
20
|
}>, Schema.Struct<{
|
|
@@ -29,7 +29,7 @@ export declare const UsersPage: import("#page.ts").AdminPage & {
|
|
|
29
29
|
readonly canChangeRoles: Schema.Boolean;
|
|
30
30
|
}>, {
|
|
31
31
|
readonly AuthUnavailable: typeof AuthUnavailable;
|
|
32
|
-
}>>], readonly [NoInfer<import("@shivaedev/
|
|
32
|
+
}>>], readonly [NoInfer<import("@shivaedev/contract/operation.ts").Command<"changeRole", Schema.Struct<{
|
|
33
33
|
readonly grant: Schema.Boolean;
|
|
34
34
|
readonly role: Schema.Literals<readonly ["user", "admin", "owner"]>;
|
|
35
35
|
readonly userId: Schema.String;
|
|
@@ -58,11 +58,7 @@ 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("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.users.
|
|
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<{
|
|
61
|
+
}>]>, Schema.Never>, Schema.Never, typeof import("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.users.list", Schema.Struct<{
|
|
66
62
|
readonly cursor: Schema.optionalKey<Schema.String>;
|
|
67
63
|
readonly limit: Schema.Number;
|
|
68
64
|
}>, Schema.Struct<{
|
|
@@ -75,6 +71,10 @@ export declare const UsersPage: import("#page.ts").AdminPage & {
|
|
|
75
71
|
readonly roles: Schema.$Array<Schema.String>;
|
|
76
72
|
}>>;
|
|
77
73
|
readonly canChangeRoles: Schema.Boolean;
|
|
78
|
-
}>, Schema.Union<readonly (typeof AuthUnavailable)[]>, typeof import("../permissions.ts").AdminPermission, never
|
|
74
|
+
}>, Schema.Union<readonly (typeof AuthUnavailable)[]>, typeof import("../permissions.ts").AdminPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.users.changeRole", Schema.Struct<{
|
|
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("../permissions.ts").AdminPermission, never>, readonly [], undefined>;
|
|
79
79
|
};
|
|
80
80
|
//# 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;
|
|
1
|
+
{"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../../src/users/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAErF,OAAO,EAAmB,SAAS,EAA2B,MAAM,iBAAiB,CAAC;AAItF,eAAO,MAAM,SAAS;;;;;;;;;;EAAwE,CAAC;AAC/F,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoBpB,CAAC"}
|
package/dist/users/page.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
import { contract } from "@shivaedev/
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { ChangeRoleInput, LastOwner, UserList, UserListInput } from "@shivaedev/platform/rpc/userRoles.ts";
|
|
2
|
+
import { contract } from "@shivaedev/contract/contract.ts";
|
|
3
|
+
import { collection } from "@shivaedev/contract/keys.ts";
|
|
4
|
+
import { command, query } from "@shivaedev/contract/operation.ts";
|
|
5
|
+
import { AuthUnavailable, Forbidden, NotFound } from "@shivaedev/errors/taxonomy.ts";
|
|
7
6
|
import { adminPage } from "#page.ts";
|
|
7
|
+
import { ChangeRoleInput, LastOwner, UserList, UserListInput } from "#users/roles.ts";
|
|
8
8
|
const users = collection("admin.users", Schema.String);
|
|
9
9
|
export const UsersList = Schema.Struct({ ...UserList.fields, canChangeRoles: Schema.Boolean });
|
|
10
10
|
export const UsersPage = adminPage({
|
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;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/users/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,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,SAAS,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEtF,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,CAAC,MAAM,SAAS,GAAG,SAAS,CAAC;IAClC,QAAQ,EAAE,QAAQ,CAAC,aAAa,EAAE;QACjC,QAAQ,EAAE;YACT,OAAO,CAAC,YAAY,EAAE;gBACrB,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;gBAC/B,OAAO,EAAE,eAAe,CAAC,MAAM;gBAC/B,UAAU,EAAE,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE;aAC/D,CAAC;SACF;QACD,OAAO,EAAE;YACR,KAAK,CAAC,MAAM,EAAE;gBACb,OAAO,EAAE,aAAa,CAAC,MAAM;gBAC7B,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;gBACzB,UAAU,EAAE,EAAE,eAAe,EAAE;gBAC/B,OAAO,EAAE,SAAS;aAClB,CAAC;SACF;KACD,CAAC;IACF,EAAE,EAAE,OAAO;IACX,KAAK,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,OAAO,EAAE;CAC/C,CAAC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
export declare const UserRole: Schema.Literals<readonly ["user", "admin", "owner"]>;
|
|
3
|
+
export type UserRole = typeof UserRole.Type;
|
|
4
|
+
export declare const AppUser: Schema.Struct<{
|
|
5
|
+
readonly createdAt: Schema.DateTimeUtcFromString;
|
|
6
|
+
readonly email: Schema.String;
|
|
7
|
+
readonly id: Schema.String;
|
|
8
|
+
readonly name: Schema.String;
|
|
9
|
+
readonly roles: Schema.$Array<Schema.String>;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const UserListInput: Schema.Struct<{
|
|
12
|
+
readonly cursor: Schema.optionalKey<Schema.String>;
|
|
13
|
+
readonly limit: Schema.Number;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const UserList: Schema.Struct<{
|
|
16
|
+
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
17
|
+
readonly users: Schema.$Array<Schema.Struct<{
|
|
18
|
+
readonly createdAt: Schema.DateTimeUtcFromString;
|
|
19
|
+
readonly email: Schema.String;
|
|
20
|
+
readonly id: Schema.String;
|
|
21
|
+
readonly name: Schema.String;
|
|
22
|
+
readonly roles: Schema.$Array<Schema.String>;
|
|
23
|
+
}>>;
|
|
24
|
+
}>;
|
|
25
|
+
export declare const ChangeRoleInput: Schema.Struct<{
|
|
26
|
+
readonly grant: Schema.Boolean;
|
|
27
|
+
readonly role: Schema.Literals<readonly ["user", "admin", "owner"]>;
|
|
28
|
+
readonly userId: Schema.String;
|
|
29
|
+
}>;
|
|
30
|
+
declare const LastOwner_base: Schema.Class<LastOwner, Schema.TaggedStruct<"LastOwner", {
|
|
31
|
+
readonly userId: Schema.String;
|
|
32
|
+
}>, import("effect/Cause").YieldableError>;
|
|
33
|
+
export declare class LastOwner extends LastOwner_base {
|
|
34
|
+
}
|
|
35
|
+
export declare const ChangeUserRoles: {
|
|
36
|
+
readonly any: {
|
|
37
|
+
readonly name: "users.roles.change";
|
|
38
|
+
readonly strength: "any";
|
|
39
|
+
};
|
|
40
|
+
readonly name: "users.roles.change";
|
|
41
|
+
readonly strength: "own";
|
|
42
|
+
};
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=roles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../../src/users/roles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,eAAO,MAAM,QAAQ,sDAA8C,CAAC;AACpE,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,IAAI,CAAC;AAE5C,eAAO,MAAM,OAAO;;;;;;EAMlB,CAAC;AAEH,eAAO,MAAM,aAAa;;;EAGxB,CAAC;AACH,eAAO,MAAM,QAAQ;;;;;;;;;EAAgG,CAAC;AACtH,eAAO,MAAM,eAAe;;;;EAAkF,CAAC;;;;AAC/G,qBAAa,SAAU,SAAQ,cAAuE;CAAG;AAEzG,eAAO,MAAM,eAAe;;;;;;;CAAmC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { permission } from "@shivaedev/access/permission.ts";
|
|
3
|
+
export const UserRole = Schema.Literals(["user", "admin", "owner"]);
|
|
4
|
+
export const AppUser = Schema.Struct({
|
|
5
|
+
createdAt: Schema.DateTimeUtcFromString,
|
|
6
|
+
email: Schema.String,
|
|
7
|
+
id: Schema.String,
|
|
8
|
+
name: Schema.String,
|
|
9
|
+
roles: Schema.Array(Schema.String),
|
|
10
|
+
});
|
|
11
|
+
export const UserListInput = Schema.Struct({
|
|
12
|
+
cursor: Schema.optionalKey(Schema.String),
|
|
13
|
+
limit: Schema.Number.check(Schema.isInt(), Schema.isBetween({ maximum: 100, minimum: 1 })),
|
|
14
|
+
});
|
|
15
|
+
export const UserList = Schema.Struct({ next: Schema.OptionFromNullOr(Schema.String), users: Schema.Array(AppUser) });
|
|
16
|
+
export const ChangeRoleInput = Schema.Struct({ grant: Schema.Boolean, role: UserRole, userId: Schema.String });
|
|
17
|
+
export class LastOwner extends Schema.TaggedError()("LastOwner", { userId: Schema.String }) {
|
|
18
|
+
}
|
|
19
|
+
export const ChangeUserRoles = permission("users.roles.change");
|
|
20
|
+
//# sourceMappingURL=roles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles.js","sourceRoot":"","sources":["../../src/users/roles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAE7D,MAAM,CAAC,MAAM,QAAQ,GAAG,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AG,UAAU,CAAC,oBAAoB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/admin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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,17 +41,20 @@
|
|
|
41
41
|
"README.md"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@shivaedev/access": "0.1.
|
|
45
|
-
"@shivaedev/
|
|
46
|
-
"@shivaedev/
|
|
47
|
-
"@shivaedev/
|
|
48
|
-
"@shivaedev/
|
|
44
|
+
"@shivaedev/access": "0.1.1",
|
|
45
|
+
"@shivaedev/contract": "0.17.0",
|
|
46
|
+
"@shivaedev/errors": "0.1.0",
|
|
47
|
+
"@shivaedev/identity": "0.1.0",
|
|
48
|
+
"@shivaedev/jobs": "0.20.0",
|
|
49
|
+
"@shivaedev/react": "0.19.0",
|
|
50
|
+
"@shivaedev/sql": "0.22.0"
|
|
49
51
|
},
|
|
50
52
|
"devDependencies": {
|
|
51
53
|
"@effect/atom-react": "4.0.5",
|
|
52
|
-
"@shivaedev/
|
|
53
|
-
"@shivaedev/
|
|
54
|
-
"@shivaedev/test-
|
|
54
|
+
"@shivaedev/quality": "0.42.0",
|
|
55
|
+
"@shivaedev/server": "0.1.0",
|
|
56
|
+
"@shivaedev/test-sql": "0.10.0",
|
|
57
|
+
"@shivaedev/test-story": "0.21.0",
|
|
55
58
|
"@types/node": "24.19.2",
|
|
56
59
|
"@types/react": "19.3.0",
|
|
57
60
|
"@types/react-dom": "19.3.0",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DateTime } from "effect";
|
|
2
|
-
import { type AppUser, type ChangeRoleInput, UserRole } from "@shivaedev/platform/rpc/userRoles.ts";
|
|
3
2
|
import type { UsersList } from "#users/page.ts";
|
|
3
|
+
import { type AppUser, type ChangeRoleInput, UserRole } from "#users/roles.ts";
|
|
4
4
|
|
|
5
5
|
interface RoleControls {
|
|
6
6
|
readonly dispatch: (input: typeof ChangeRoleInput.Type) => void;
|
package/src/client/UsersView.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { Cause, Option, Predicate } from "effect";
|
|
|
2
2
|
import type * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
3
3
|
import type * as Atom from "effect/reactivity/Atom";
|
|
4
4
|
import { createElement, useState } from "react";
|
|
5
|
-
import { useAction, useQuery } from "@shivaedev/
|
|
6
|
-
import type { ChangeRoleInput, UserListInput } from "@shivaedev/platform/rpc/userRoles.ts";
|
|
5
|
+
import { useAction, useQuery } from "@shivaedev/react/client/resultState.ts";
|
|
7
6
|
import type { UsersList } from "#users/page.ts";
|
|
7
|
+
import type { ChangeRoleInput, UserListInput } from "#users/roles.ts";
|
|
8
8
|
import { UsersTable } from "./UsersTable.tsx";
|
|
9
9
|
|
|
10
10
|
export interface UsersViewProps {
|
package/src/jobs/keys.ts
CHANGED
package/src/jobs/page.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
import { contract } from "@shivaedev/
|
|
3
|
-
import { query } from "@shivaedev/
|
|
2
|
+
import { contract } from "@shivaedev/contract/contract.ts";
|
|
3
|
+
import { query } from "@shivaedev/contract/operation.ts";
|
|
4
4
|
import { adminPage } from "#page.ts";
|
|
5
5
|
import { jobsKeys } from "./keys.ts";
|
|
6
6
|
import { deadLetteredSchema, JobsFailures, JobsHealth, type JobsQueue, jobPage, jobSchema, PageFields, QueueCounts } from "./schemas.ts";
|
package/src/jobs/retryPage.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
import { contract } from "@shivaedev/
|
|
3
|
-
import { command } from "@shivaedev/
|
|
2
|
+
import { contract } from "@shivaedev/contract/contract.ts";
|
|
3
|
+
import { command } from "@shivaedev/contract/operation.ts";
|
|
4
4
|
import { adminPage } from "#page.ts";
|
|
5
5
|
import { jobsKeys } from "./keys.ts";
|
|
6
6
|
import { jobsPage } from "./page.ts";
|
package/src/page.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Rpc, RpcGroup } from "effect/rpc";
|
|
2
|
-
import type { Contract } from "@shivaedev/
|
|
3
|
-
import type { CommandShape, QueryShape, StreamShape } from "@shivaedev/
|
|
2
|
+
import type { Contract } from "@shivaedev/contract/contract.ts";
|
|
3
|
+
import type { CommandShape, QueryShape, StreamShape } from "@shivaedev/contract/operation.ts";
|
|
4
4
|
import { AdminPermission } from "#permissions.ts";
|
|
5
5
|
|
|
6
6
|
export interface AdminRoute {
|
package/src/permissions.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { permission } from "@shivaedev/access/permission.ts";
|
|
2
|
-
import { permissionMiddleware } from "@shivaedev/
|
|
2
|
+
import { permissionMiddleware } from "@shivaedev/identity/permission.ts";
|
|
3
3
|
|
|
4
4
|
export const OpenAdmin = permission("admin.open");
|
|
5
5
|
export class AdminPermission extends permissionMiddleware<AdminPermission>()("@shivaedev/admin/Permission", OpenAdmin) {}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Context, DateTime, Effect, Option } from "effect";
|
|
2
|
-
import type { PgBossError, PgBossPayloadError } from "@shivaedev/
|
|
3
|
-
import type { PgBossService } from "@shivaedev/
|
|
2
|
+
import type { PgBossError, PgBossPayloadError } from "@shivaedev/jobs/server/error.ts";
|
|
3
|
+
import type { PgBossService } from "@shivaedev/jobs/server/service.ts";
|
|
4
4
|
import type { jobsPage } from "#jobs/page.ts";
|
|
5
5
|
import { JobsPayloadInvalid, type JobsQueue, JobsQueueUnregistered, JobsUnavailable } from "#jobs/schemas.ts";
|
|
6
6
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Context, Effect, Option } from "effect";
|
|
2
|
-
import type { PgBossService } from "@shivaedev/
|
|
2
|
+
import type { PgBossService } from "@shivaedev/jobs/server/service.ts";
|
|
3
3
|
import { JobsNotFailed, type jobsPageWithRetry } from "#jobs/retryPage.ts";
|
|
4
4
|
import { type JobsQueue, JobsQueueUnregistered } from "#jobs/schemas.ts";
|
|
5
5
|
import { jobsFailures, jobsReadHandlers } from "./jobsHandlers.ts";
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { DateTime, Effect, Option, Schema } from "effect";
|
|
2
|
+
import { SqlClient, SqlSchema } from "effect/sql";
|
|
3
|
+
import { AuthUnavailable, NotFound } from "@shivaedev/errors/taxonomy.ts";
|
|
4
|
+
import { SessionUser } from "@shivaedev/identity/identity.ts";
|
|
5
|
+
import { requirePermission } from "@shivaedev/identity/permission.ts";
|
|
6
|
+
import { invalidateOnCommit, transact } from "@shivaedev/sql/transact.ts";
|
|
7
|
+
import { type ChangeRoleInput, ChangeUserRoles, LastOwner, type UserListInput } from "#users/roles.ts";
|
|
8
|
+
|
|
9
|
+
const StoredUser = Schema.Struct({
|
|
10
|
+
createdAt: Schema.Date,
|
|
11
|
+
email: Schema.String,
|
|
12
|
+
id: Schema.String,
|
|
13
|
+
name: Schema.String,
|
|
14
|
+
role: Schema.NullOr(Schema.String),
|
|
15
|
+
});
|
|
16
|
+
function unavailable() {
|
|
17
|
+
return new AuthUnavailable({ message: "Could not access app users" });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const listUsers = Effect.fn("Platform.listUsers")(function* (input: typeof UserListInput.Type) {
|
|
21
|
+
const sql = yield* SqlClient.SqlClient;
|
|
22
|
+
const read = SqlSchema.findAll({
|
|
23
|
+
execute: () => sql`select id, name, email, role, "createdAt" from "user"
|
|
24
|
+
where id > ${input.cursor ?? ""} order by id limit ${input.limit + 1}`,
|
|
25
|
+
Request: Schema.Void,
|
|
26
|
+
Result: StoredUser,
|
|
27
|
+
});
|
|
28
|
+
const rows = yield* read(undefined).pipe(Effect.mapError(unavailable));
|
|
29
|
+
const users = rows.slice(0, input.limit).map(({ role, createdAt, ...user }) => ({
|
|
30
|
+
...user,
|
|
31
|
+
createdAt: DateTime.makeUnsafe(createdAt),
|
|
32
|
+
roles: role?.split(",").filter(Boolean) ?? [],
|
|
33
|
+
}));
|
|
34
|
+
return { next: rows.length > input.limit ? Option.fromUndefinedOr(users.at(-1)?.id) : Option.none<string>(), users };
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export const changeUserRole = Effect.fn("Platform.changeUserRole")(function* (input: typeof ChangeRoleInput.Type) {
|
|
38
|
+
const actor = yield* SessionUser;
|
|
39
|
+
yield* requirePermission(ChangeUserRoles);
|
|
40
|
+
const sql = yield* SqlClient.SqlClient;
|
|
41
|
+
const changed = yield* Effect.gen(function* () {
|
|
42
|
+
yield* sql`select pg_advisory_xact_lock(hashtext('platform.auth.user-roles'))`;
|
|
43
|
+
const rows = yield* sql<{ readonly id: string; readonly role: string | null }>`select id, role from "user" where id = ${input.userId} for update`;
|
|
44
|
+
const target = rows[0];
|
|
45
|
+
if (target === undefined) {
|
|
46
|
+
return yield* Effect.fail(new NotFound({ message: "User not found" }));
|
|
47
|
+
}
|
|
48
|
+
const roles = target.role?.split(",").filter(Boolean) ?? [];
|
|
49
|
+
if (input.grant === roles.includes(input.role)) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (!input.grant && input.role === "owner") {
|
|
53
|
+
const owners = yield* sql<{ readonly id: string }>`select id from "user" where 'owner' = any(string_to_array(role, ','))`;
|
|
54
|
+
if (owners.length === 1) {
|
|
55
|
+
return yield* Effect.fail(new LastOwner({ userId: input.userId }));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const next = input.grant ? [...roles, input.role] : roles.filter((role) => role !== input.role);
|
|
59
|
+
yield* sql`update "user" set role = ${next.join(",")}, "updatedAt" = now() where id = ${input.userId}`;
|
|
60
|
+
yield* invalidateOnCommit(["admin.users"]);
|
|
61
|
+
return true;
|
|
62
|
+
}).pipe(transact({ onSqlError: unavailable }));
|
|
63
|
+
if (changed) {
|
|
64
|
+
const changedAt = DateTime.formatIso(yield* DateTime.now);
|
|
65
|
+
yield* Effect.logInfo("User role changed").pipe(Effect.annotateLogs({ actorId: actor.id, changedAt, ...input }));
|
|
66
|
+
}
|
|
67
|
+
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { SessionUser } from "@shivaedev/
|
|
3
|
-
import { hasPermission } from "@shivaedev/
|
|
4
|
-
import {
|
|
5
|
-
import { changeUserRole, listUsers } from "@shivaedev/platform/server/better-auth/users.ts";
|
|
2
|
+
import { SessionUser } from "@shivaedev/identity/identity.ts";
|
|
3
|
+
import { hasPermission } from "@shivaedev/identity/permission.ts";
|
|
4
|
+
import { changeUserRole, listUsers } from "#server/users.ts";
|
|
6
5
|
import { UsersPage } from "#users/page.ts";
|
|
6
|
+
import { ChangeUserRoles } from "#users/roles.ts";
|
|
7
7
|
|
|
8
8
|
export const usersHandlers = UsersPage.contract.application.toLayer({
|
|
9
9
|
"admin.users.changeRole": changeUserRole,
|
package/src/users/page.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
import { contract } from "@shivaedev/
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { ChangeRoleInput, LastOwner, UserList, UserListInput } from "@shivaedev/platform/rpc/userRoles.ts";
|
|
2
|
+
import { contract } from "@shivaedev/contract/contract.ts";
|
|
3
|
+
import { collection } from "@shivaedev/contract/keys.ts";
|
|
4
|
+
import { command, query } from "@shivaedev/contract/operation.ts";
|
|
5
|
+
import { AuthUnavailable, Forbidden, NotFound } from "@shivaedev/errors/taxonomy.ts";
|
|
7
6
|
import { adminPage } from "#page.ts";
|
|
7
|
+
import { ChangeRoleInput, LastOwner, UserList, UserListInput } from "#users/roles.ts";
|
|
8
8
|
|
|
9
9
|
const users = collection("admin.users", Schema.String);
|
|
10
10
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { permission } from "@shivaedev/access/permission.ts";
|
|
3
|
+
|
|
4
|
+
export const UserRole = Schema.Literals(["user", "admin", "owner"]);
|
|
5
|
+
export type UserRole = typeof UserRole.Type;
|
|
6
|
+
|
|
7
|
+
export const AppUser = Schema.Struct({
|
|
8
|
+
createdAt: Schema.DateTimeUtcFromString,
|
|
9
|
+
email: Schema.String,
|
|
10
|
+
id: Schema.String,
|
|
11
|
+
name: Schema.String,
|
|
12
|
+
roles: Schema.Array(Schema.String),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const UserListInput = Schema.Struct({
|
|
16
|
+
cursor: Schema.optionalKey(Schema.String),
|
|
17
|
+
limit: Schema.Number.check(Schema.isInt(), Schema.isBetween({ maximum: 100, minimum: 1 })),
|
|
18
|
+
});
|
|
19
|
+
export const UserList = Schema.Struct({ next: Schema.OptionFromNullOr(Schema.String), users: Schema.Array(AppUser) });
|
|
20
|
+
export const ChangeRoleInput = Schema.Struct({ grant: Schema.Boolean, role: UserRole, userId: Schema.String });
|
|
21
|
+
export class LastOwner extends Schema.TaggedError<LastOwner>()("LastOwner", { userId: Schema.String }) {}
|
|
22
|
+
|
|
23
|
+
export const ChangeUserRoles = permission("users.roles.change");
|