@shivaedev/admin 0.10.0 → 0.10.2
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 +51 -28
- package/dist/jobs/page.d.ts.map +1 -1
- package/dist/jobs/page.js +4 -11
- package/dist/jobs/page.js.map +1 -1
- package/dist/jobs/retryPage.d.ts +53 -7
- package/dist/jobs/retryPage.d.ts.map +1 -1
- package/dist/page.d.ts +11 -3
- package/dist/page.d.ts.map +1 -1
- package/dist/page.js +17 -1
- package/dist/page.js.map +1 -1
- package/dist/users/page.d.ts +8 -3
- package/dist/users/page.d.ts.map +1 -1
- package/dist/users/page.js +1 -4
- package/dist/users/page.js.map +1 -1
- package/package.json +8 -8
- package/src/jobs/page.ts +4 -11
- package/src/page.ts +54 -5
- package/src/users/page.ts +1 -4
package/README.md
CHANGED
|
@@ -164,7 +164,7 @@ Keep Better Auth cookie caching disabled so requests see current permissions. Ro
|
|
|
164
164
|
|
|
165
165
|
### Client permission routes
|
|
166
166
|
|
|
167
|
-
`adminPage` requires a permission middleware, including for custom pages. It applies that middleware to the whole contract and exposes its permission as `page.route.permission`. Set the React route's `staticData.permission` to that value. Use `permissionGuard` from `@shivaedev/react/permissionGuard.ts` in protected routes' `beforeLoad` and wrap the router in `PermissionBoundary` from `@shivaedev/react/client/permissionBoundary.ts` with the session and one application fallback.
|
|
167
|
+
`adminPage` requires a permission middleware, including for custom pages. It applies that middleware to the whole contract, installs a read policy checking the page grant on every query, and exposes its permission as `page.route.permission`. Queries need no repeated page-grant policy. An additional query policy can restrict access further. Bound live queries use the same page grant as one-off reads. Set the React route's `staticData.permission` to that value. Use `permissionGuard` from `@shivaedev/react/permissionGuard.ts` in protected routes' `beforeLoad` and wrap the router in `PermissionBoundary` from `@shivaedev/react/client/permissionBoundary.ts` with the session and one application fallback.
|
|
168
168
|
|
|
169
169
|
### Install and limits
|
|
170
170
|
|
package/dist/jobs/page.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
+
import { type JobsEntry, type JobsPayload } from "#jobs/entry.ts";
|
|
2
3
|
import { JobsPermission } from "#permissions.ts";
|
|
3
|
-
import { type JobsEntry, type JobsPayload } from "./entry.ts";
|
|
4
4
|
export declare function jobsPage<const TQueues extends readonly JobsEntry[]>(...queues: TQueues): import("#page.ts").AdminPage & {
|
|
5
5
|
readonly id: "jobs";
|
|
6
|
-
readonly contract: import("@shivaedev/contract/contract.ts").Contract<"admin.jobs", readonly [NoInfer<import("@shivaedev/contract/operation.ts").Query<"health", Schema.Void, Schema.Struct<{
|
|
6
|
+
readonly contract: import("@shivaedev/contract/contract.ts").Contract<"admin.jobs", readonly [Omit<NoInfer<import("@shivaedev/contract/operation.ts").Query<"health", Schema.Void, Schema.Struct<{
|
|
7
7
|
readonly activeTotal: Schema.Number;
|
|
8
8
|
readonly deadLetteredTotal: Schema.Number;
|
|
9
9
|
readonly failedTotal: Schema.Number;
|
|
@@ -19,10 +19,12 @@ export declare function jobsPage<const TQueues extends readonly JobsEntry[]>(...
|
|
|
19
19
|
readonly readyTotal: Schema.Number;
|
|
20
20
|
}>, {
|
|
21
21
|
BadRequest: typeof import("@shivaedev/errors/taxonomy.ts").BadRequest;
|
|
22
|
-
JobsPayloadInvalid: typeof import("
|
|
23
|
-
JobsQueueUnregistered: typeof import("
|
|
24
|
-
JobsUnavailable: typeof import("
|
|
25
|
-
}>>,
|
|
22
|
+
JobsPayloadInvalid: typeof import("#jobs/schemas.ts").JobsPayloadInvalid;
|
|
23
|
+
JobsQueueUnregistered: typeof import("#jobs/schemas.ts").JobsQueueUnregistered;
|
|
24
|
+
JobsUnavailable: typeof import("#jobs/schemas.ts").JobsUnavailable;
|
|
25
|
+
}, never>>, "readPolicy"> & {
|
|
26
|
+
readonly readPolicy: import("@shivaedev/contract/readPolicy.ts").QueryReadPolicy<void, 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>;
|
|
27
|
+
}, Omit<NoInfer<import("@shivaedev/contract/operation.ts").Query<"counts", Schema.Struct<{
|
|
26
28
|
queue: Schema.String;
|
|
27
29
|
}>, Schema.Struct<{
|
|
28
30
|
readonly activeCount: Schema.Number;
|
|
@@ -31,10 +33,14 @@ export declare function jobsPage<const TQueues extends readonly JobsEntry[]>(...
|
|
|
31
33
|
readonly totalCount: Schema.Number;
|
|
32
34
|
}>, {
|
|
33
35
|
BadRequest: typeof import("@shivaedev/errors/taxonomy.ts").BadRequest;
|
|
34
|
-
JobsPayloadInvalid: typeof import("
|
|
35
|
-
JobsQueueUnregistered: typeof import("
|
|
36
|
-
JobsUnavailable: typeof import("
|
|
37
|
-
}>>,
|
|
36
|
+
JobsPayloadInvalid: typeof import("#jobs/schemas.ts").JobsPayloadInvalid;
|
|
37
|
+
JobsQueueUnregistered: typeof import("#jobs/schemas.ts").JobsQueueUnregistered;
|
|
38
|
+
JobsUnavailable: typeof import("#jobs/schemas.ts").JobsUnavailable;
|
|
39
|
+
}, never>>, "readPolicy"> & {
|
|
40
|
+
readonly readPolicy: import("@shivaedev/contract/readPolicy.ts").QueryReadPolicy<{
|
|
41
|
+
readonly queue: string;
|
|
42
|
+
}, 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>;
|
|
43
|
+
}, Omit<NoInfer<import("@shivaedev/contract/operation.ts").Query<"failed", Schema.Struct<{
|
|
38
44
|
cursor: Schema.optionalKey<Schema.String>;
|
|
39
45
|
limit: Schema.Number;
|
|
40
46
|
queue: Schema.String;
|
|
@@ -58,10 +64,16 @@ export declare function jobsPage<const TQueues extends readonly JobsEntry[]>(...
|
|
|
58
64
|
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
59
65
|
}>, {
|
|
60
66
|
BadRequest: typeof import("@shivaedev/errors/taxonomy.ts").BadRequest;
|
|
61
|
-
JobsPayloadInvalid: typeof import("
|
|
62
|
-
JobsQueueUnregistered: typeof import("
|
|
63
|
-
JobsUnavailable: typeof import("
|
|
64
|
-
}>>,
|
|
67
|
+
JobsPayloadInvalid: typeof import("#jobs/schemas.ts").JobsPayloadInvalid;
|
|
68
|
+
JobsQueueUnregistered: typeof import("#jobs/schemas.ts").JobsQueueUnregistered;
|
|
69
|
+
JobsUnavailable: typeof import("#jobs/schemas.ts").JobsUnavailable;
|
|
70
|
+
}, never>>, "readPolicy"> & {
|
|
71
|
+
readonly readPolicy: import("@shivaedev/contract/readPolicy.ts").QueryReadPolicy<{
|
|
72
|
+
readonly cursor?: string;
|
|
73
|
+
readonly limit: number;
|
|
74
|
+
readonly queue: string;
|
|
75
|
+
}, 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>;
|
|
76
|
+
}, Omit<NoInfer<import("@shivaedev/contract/operation.ts").Query<"deadLettered", Schema.Struct<{
|
|
65
77
|
cursor: Schema.optionalKey<Schema.String>;
|
|
66
78
|
limit: Schema.Number;
|
|
67
79
|
queue: Schema.String;
|
|
@@ -90,10 +102,16 @@ export declare function jobsPage<const TQueues extends readonly JobsEntry[]>(...
|
|
|
90
102
|
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
91
103
|
}>, {
|
|
92
104
|
BadRequest: typeof import("@shivaedev/errors/taxonomy.ts").BadRequest;
|
|
93
|
-
JobsPayloadInvalid: typeof import("
|
|
94
|
-
JobsQueueUnregistered: typeof import("
|
|
95
|
-
JobsUnavailable: typeof import("
|
|
96
|
-
}>>,
|
|
105
|
+
JobsPayloadInvalid: typeof import("#jobs/schemas.ts").JobsPayloadInvalid;
|
|
106
|
+
JobsQueueUnregistered: typeof import("#jobs/schemas.ts").JobsQueueUnregistered;
|
|
107
|
+
JobsUnavailable: typeof import("#jobs/schemas.ts").JobsUnavailable;
|
|
108
|
+
}, never>>, "readPolicy"> & {
|
|
109
|
+
readonly readPolicy: import("@shivaedev/contract/readPolicy.ts").QueryReadPolicy<{
|
|
110
|
+
readonly cursor?: string;
|
|
111
|
+
readonly limit: number;
|
|
112
|
+
readonly queue: string;
|
|
113
|
+
}, 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>;
|
|
114
|
+
}, Omit<NoInfer<import("@shivaedev/contract/operation.ts").Query<"job", Schema.Struct<{
|
|
97
115
|
id: Schema.String;
|
|
98
116
|
queue: Schema.String;
|
|
99
117
|
}>, Schema.OptionFromNullOr<Schema.Union<Schema.Struct<{
|
|
@@ -113,10 +131,15 @@ export declare function jobsPage<const TQueues extends readonly JobsEntry[]>(...
|
|
|
113
131
|
readonly queue: Schema.Literal<string>;
|
|
114
132
|
}>[]>>, {
|
|
115
133
|
BadRequest: typeof import("@shivaedev/errors/taxonomy.ts").BadRequest;
|
|
116
|
-
JobsPayloadInvalid: typeof import("
|
|
117
|
-
JobsQueueUnregistered: typeof import("
|
|
118
|
-
JobsUnavailable: typeof import("
|
|
119
|
-
}
|
|
134
|
+
JobsPayloadInvalid: typeof import("#jobs/schemas.ts").JobsPayloadInvalid;
|
|
135
|
+
JobsQueueUnregistered: typeof import("#jobs/schemas.ts").JobsQueueUnregistered;
|
|
136
|
+
JobsUnavailable: typeof import("#jobs/schemas.ts").JobsUnavailable;
|
|
137
|
+
}, never>>, "readPolicy"> & {
|
|
138
|
+
readonly readPolicy: import("@shivaedev/contract/readPolicy.ts").QueryReadPolicy<{
|
|
139
|
+
readonly id: string;
|
|
140
|
+
readonly queue: string;
|
|
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.$changes", Schema.Struct<{
|
|
120
143
|
queries: Schema.$Array<Schema.Union<readonly (Schema.Struct<{
|
|
121
144
|
query: Schema.Literal<"counts">;
|
|
122
145
|
payload: Schema.Struct<{
|
|
@@ -164,14 +187,14 @@ export declare function jobsPage<const TQueues extends readonly JobsEntry[]>(...
|
|
|
164
187
|
readonly queryIndexes: Schema.optional<Schema.$Array<Schema.Number>>;
|
|
165
188
|
}>, Schema.Struct<{
|
|
166
189
|
readonly _tag: Schema.Literal<"Resync">;
|
|
167
|
-
}>]>, Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>>, Schema.Never, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.counts", Schema.Struct<{
|
|
190
|
+
}>]>, 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("#jobs/schemas.ts").JobsUnavailable | typeof import("#jobs/schemas.ts").JobsPayloadInvalid | typeof import("#jobs/schemas.ts").JobsQueueUnregistered)[]>[]]>>, Schema.Never, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.counts", Schema.Struct<{
|
|
168
191
|
queue: Schema.String;
|
|
169
192
|
}>, Schema.Struct<{
|
|
170
193
|
readonly activeCount: Schema.Number;
|
|
171
194
|
readonly failedCount: Schema.Number;
|
|
172
195
|
readonly queuedCount: Schema.Number;
|
|
173
196
|
readonly totalCount: Schema.Number;
|
|
174
|
-
}>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("
|
|
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.deadLettered", Schema.Struct<{
|
|
175
198
|
cursor: Schema.optionalKey<Schema.String>;
|
|
176
199
|
limit: Schema.Number;
|
|
177
200
|
queue: Schema.String;
|
|
@@ -198,7 +221,7 @@ export declare function jobsPage<const TQueues extends readonly JobsEntry[]>(...
|
|
|
198
221
|
}>>;
|
|
199
222
|
}>[]>>;
|
|
200
223
|
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
201
|
-
}>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("
|
|
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.failed", Schema.Struct<{
|
|
202
225
|
cursor: Schema.optionalKey<Schema.String>;
|
|
203
226
|
limit: Schema.Number;
|
|
204
227
|
queue: Schema.String;
|
|
@@ -220,7 +243,7 @@ export declare function jobsPage<const TQueues extends readonly JobsEntry[]>(...
|
|
|
220
243
|
readonly queue: Schema.Literal<string>;
|
|
221
244
|
}>[]>>;
|
|
222
245
|
readonly next: Schema.OptionFromNullOr<Schema.String>;
|
|
223
|
-
}>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("
|
|
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> | import("effect/rpc/Rpc").Rpc<"admin.jobs.health", Schema.Void, Schema.Struct<{
|
|
224
247
|
readonly activeTotal: Schema.Number;
|
|
225
248
|
readonly deadLetteredTotal: Schema.Number;
|
|
226
249
|
readonly failedTotal: Schema.Number;
|
|
@@ -234,7 +257,7 @@ export declare function jobsPage<const TQueues extends readonly JobsEntry[]>(...
|
|
|
234
257
|
}>>;
|
|
235
258
|
readonly queuedTotal: Schema.Number;
|
|
236
259
|
readonly readyTotal: Schema.Number;
|
|
237
|
-
}>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("
|
|
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<{
|
|
238
261
|
id: Schema.String;
|
|
239
262
|
queue: Schema.String;
|
|
240
263
|
}>, Schema.OptionFromNullOr<Schema.Union<Schema.Struct<{
|
|
@@ -252,7 +275,7 @@ export declare function jobsPage<const TQueues extends readonly JobsEntry[]>(...
|
|
|
252
275
|
readonly state: Schema.Literals<readonly ["created", "retry", "active", "completed", "cancelled", "failed"]>;
|
|
253
276
|
readonly data: JobsPayload<TQueues[number]>;
|
|
254
277
|
readonly queue: Schema.Literal<string>;
|
|
255
|
-
}>[]>>, Schema.Union<readonly [Schema.Union<readonly (typeof import("@shivaedev/errors/taxonomy.ts").BadRequest | typeof import("
|
|
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>;
|
|
256
279
|
} & {
|
|
257
280
|
queues: TQueues;
|
|
258
281
|
};
|
package/dist/jobs/page.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../../src/jobs/page.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../../src/jobs/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAa,MAAM,gBAAgB,CAAC;AAI7E,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,wBAAgB,QAAQ,CAAC,KAAK,CAAC,OAAO,SAAS,SAAS,SAAS,EAAE,EAAE,GAAG,MAAM,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2CtF"}
|
package/dist/jobs/page.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Schema } from "effect";
|
|
2
2
|
import { contract } from "@shivaedev/contract/contract.ts";
|
|
3
3
|
import { query } from "@shivaedev/contract/operation.ts";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { jobsQueue } from "#jobs/entry.ts";
|
|
5
|
+
import { jobsKeys } from "#jobs/keys.ts";
|
|
6
|
+
import { deadLetteredSchema, JobsFailures, JobsHealth, jobPage, jobSchema, PageFields, QueueCounts } from "#jobs/schemas.ts";
|
|
6
7
|
import { adminPage } from "#page.ts";
|
|
7
8
|
import { JobsPermission } from "#permissions.ts";
|
|
8
|
-
import { jobsQueue } from "./entry.js";
|
|
9
|
-
import { jobsKeys } from "./keys.js";
|
|
10
|
-
import { deadLetteredSchema, JobsFailures, JobsHealth, jobPage, jobSchema, PageFields, QueueCounts } from "./schemas.js";
|
|
11
9
|
export function jobsPage(...queues) {
|
|
12
10
|
const definitions = queues.map((queue) => jobsQueue(queue));
|
|
13
11
|
const Job = Schema.Union(definitions.map((queue) => jobSchema(queue)));
|
|
@@ -16,35 +14,30 @@ export function jobsPage(...queues) {
|
|
|
16
14
|
contract: contract("admin.jobs", {
|
|
17
15
|
queries: [
|
|
18
16
|
query("health", {
|
|
19
|
-
readPolicy: () => Effect.map(SessionUser, (user) => hasPermission(user, JobsPermission.permission)),
|
|
20
17
|
reads: () => [jobsKeys.health.list],
|
|
21
18
|
rejections: JobsFailures,
|
|
22
19
|
success: JobsHealth,
|
|
23
20
|
}),
|
|
24
21
|
query("counts", {
|
|
25
22
|
payload: { queue: Schema.String },
|
|
26
|
-
readPolicy: () => Effect.map(SessionUser, (user) => hasPermission(user, JobsPermission.permission)),
|
|
27
23
|
reads: ({ queue }) => [jobsKeys.counts.item(queue)],
|
|
28
24
|
rejections: JobsFailures,
|
|
29
25
|
success: QueueCounts,
|
|
30
26
|
}),
|
|
31
27
|
query("failed", {
|
|
32
28
|
payload: { ...PageFields, queue: Schema.String },
|
|
33
|
-
readPolicy: () => Effect.map(SessionUser, (user) => hasPermission(user, JobsPermission.permission)),
|
|
34
29
|
reads: ({ queue }) => [jobsKeys.failed.item(queue)],
|
|
35
30
|
rejections: JobsFailures,
|
|
36
31
|
success: jobPage(Job),
|
|
37
32
|
}),
|
|
38
33
|
query("deadLettered", {
|
|
39
34
|
payload: { ...PageFields, queue: Schema.String },
|
|
40
|
-
readPolicy: () => Effect.map(SessionUser, (user) => hasPermission(user, JobsPermission.permission)),
|
|
41
35
|
reads: ({ queue }) => [jobsKeys.deadLettered.item(queue)],
|
|
42
36
|
rejections: JobsFailures,
|
|
43
37
|
success: jobPage(DeadLettered),
|
|
44
38
|
}),
|
|
45
39
|
query("job", {
|
|
46
40
|
payload: { id: Schema.String, queue: Schema.String },
|
|
47
|
-
readPolicy: () => Effect.map(SessionUser, (user) => hasPermission(user, JobsPermission.permission)),
|
|
48
41
|
reads: ({ queue, id }) => [jobsKeys.job(queue).item(id)],
|
|
49
42
|
rejections: JobsFailures,
|
|
50
43
|
success: Schema.OptionFromNullOr(Job),
|
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,
|
|
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,iCA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QAC1B,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
|
@@ -10,7 +10,7 @@ export declare class JobsNotFailed extends JobsNotFailed_base {
|
|
|
10
10
|
}
|
|
11
11
|
export declare function jobsPageWithRetry<const TQueues extends readonly JobsEntry[]>(...queues: TQueues): import("#page.ts").AdminPage & {
|
|
12
12
|
readonly id: "jobs";
|
|
13
|
-
readonly contract: import("@shivaedev/contract/contract.ts").Contract<"admin.jobs", readonly [NoInfer<import("@shivaedev/contract/operation.ts").Query<"health", Schema.Void, Schema.Struct<{
|
|
13
|
+
readonly contract: import("@shivaedev/contract/contract.ts").Contract<"admin.jobs", readonly [Omit<Omit<NoInfer<import("@shivaedev/contract/operation.ts").Query<"health", Schema.Void, Schema.Struct<{
|
|
14
14
|
readonly activeTotal: Schema.Number;
|
|
15
15
|
readonly deadLetteredTotal: Schema.Number;
|
|
16
16
|
readonly failedTotal: Schema.Number;
|
|
@@ -29,7 +29,11 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsEnt
|
|
|
29
29
|
JobsPayloadInvalid: typeof import("./schemas.ts").JobsPayloadInvalid;
|
|
30
30
|
JobsQueueUnregistered: typeof import("./schemas.ts").JobsQueueUnregistered;
|
|
31
31
|
JobsUnavailable: typeof import("./schemas.ts").JobsUnavailable;
|
|
32
|
-
}>>,
|
|
32
|
+
}, never>>, "readPolicy"> & {
|
|
33
|
+
readonly readPolicy: import("@shivaedev/contract/readPolicy.ts").QueryReadPolicy<void, import("@shivaedev/errors/taxonomy.ts").BadRequest | import("./schemas.ts").JobsPayloadInvalid | import("./schemas.ts").JobsQueueUnregistered | import("./schemas.ts").JobsUnavailable, import("@shivaedev/identity/identity.ts").SessionUser>;
|
|
34
|
+
}, "readPolicy"> & {
|
|
35
|
+
readonly readPolicy: import("@shivaedev/contract/readPolicy.ts").QueryReadPolicy<void, import("@shivaedev/errors/taxonomy.ts").BadRequest | import("./schemas.ts").JobsPayloadInvalid | import("./schemas.ts").JobsQueueUnregistered | import("./schemas.ts").JobsUnavailable, import("@shivaedev/identity/identity.ts").SessionUser>;
|
|
36
|
+
}, Omit<Omit<NoInfer<import("@shivaedev/contract/operation.ts").Query<"counts", Schema.Struct<{
|
|
33
37
|
queue: Schema.String;
|
|
34
38
|
}>, Schema.Struct<{
|
|
35
39
|
readonly activeCount: Schema.Number;
|
|
@@ -41,7 +45,15 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsEnt
|
|
|
41
45
|
JobsPayloadInvalid: typeof import("./schemas.ts").JobsPayloadInvalid;
|
|
42
46
|
JobsQueueUnregistered: typeof import("./schemas.ts").JobsQueueUnregistered;
|
|
43
47
|
JobsUnavailable: typeof import("./schemas.ts").JobsUnavailable;
|
|
44
|
-
}>>,
|
|
48
|
+
}, never>>, "readPolicy"> & {
|
|
49
|
+
readonly readPolicy: import("@shivaedev/contract/readPolicy.ts").QueryReadPolicy<{
|
|
50
|
+
readonly queue: string;
|
|
51
|
+
}, import("@shivaedev/errors/taxonomy.ts").BadRequest | import("./schemas.ts").JobsPayloadInvalid | import("./schemas.ts").JobsQueueUnregistered | import("./schemas.ts").JobsUnavailable, import("@shivaedev/identity/identity.ts").SessionUser>;
|
|
52
|
+
}, "readPolicy"> & {
|
|
53
|
+
readonly readPolicy: import("@shivaedev/contract/readPolicy.ts").QueryReadPolicy<{
|
|
54
|
+
readonly queue: string;
|
|
55
|
+
}, import("@shivaedev/errors/taxonomy.ts").BadRequest | import("./schemas.ts").JobsPayloadInvalid | import("./schemas.ts").JobsQueueUnregistered | import("./schemas.ts").JobsUnavailable, import("@shivaedev/identity/identity.ts").SessionUser>;
|
|
56
|
+
}, Omit<Omit<NoInfer<import("@shivaedev/contract/operation.ts").Query<"failed", Schema.Struct<{
|
|
45
57
|
cursor: Schema.optionalKey<Schema.String>;
|
|
46
58
|
limit: Schema.Number;
|
|
47
59
|
queue: Schema.String;
|
|
@@ -68,7 +80,19 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsEnt
|
|
|
68
80
|
JobsPayloadInvalid: typeof import("./schemas.ts").JobsPayloadInvalid;
|
|
69
81
|
JobsQueueUnregistered: typeof import("./schemas.ts").JobsQueueUnregistered;
|
|
70
82
|
JobsUnavailable: typeof import("./schemas.ts").JobsUnavailable;
|
|
71
|
-
}>>,
|
|
83
|
+
}, never>>, "readPolicy"> & {
|
|
84
|
+
readonly readPolicy: import("@shivaedev/contract/readPolicy.ts").QueryReadPolicy<{
|
|
85
|
+
readonly cursor?: string;
|
|
86
|
+
readonly limit: number;
|
|
87
|
+
readonly queue: string;
|
|
88
|
+
}, import("@shivaedev/errors/taxonomy.ts").BadRequest | import("./schemas.ts").JobsPayloadInvalid | import("./schemas.ts").JobsQueueUnregistered | import("./schemas.ts").JobsUnavailable, import("@shivaedev/identity/identity.ts").SessionUser>;
|
|
89
|
+
}, "readPolicy"> & {
|
|
90
|
+
readonly readPolicy: import("@shivaedev/contract/readPolicy.ts").QueryReadPolicy<{
|
|
91
|
+
readonly cursor?: string;
|
|
92
|
+
readonly limit: number;
|
|
93
|
+
readonly queue: string;
|
|
94
|
+
}, import("@shivaedev/errors/taxonomy.ts").BadRequest | import("./schemas.ts").JobsPayloadInvalid | import("./schemas.ts").JobsQueueUnregistered | import("./schemas.ts").JobsUnavailable, import("@shivaedev/identity/identity.ts").SessionUser>;
|
|
95
|
+
}, Omit<Omit<NoInfer<import("@shivaedev/contract/operation.ts").Query<"deadLettered", Schema.Struct<{
|
|
72
96
|
cursor: Schema.optionalKey<Schema.String>;
|
|
73
97
|
limit: Schema.Number;
|
|
74
98
|
queue: Schema.String;
|
|
@@ -100,7 +124,19 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsEnt
|
|
|
100
124
|
JobsPayloadInvalid: typeof import("./schemas.ts").JobsPayloadInvalid;
|
|
101
125
|
JobsQueueUnregistered: typeof import("./schemas.ts").JobsQueueUnregistered;
|
|
102
126
|
JobsUnavailable: typeof import("./schemas.ts").JobsUnavailable;
|
|
103
|
-
}>>,
|
|
127
|
+
}, never>>, "readPolicy"> & {
|
|
128
|
+
readonly readPolicy: import("@shivaedev/contract/readPolicy.ts").QueryReadPolicy<{
|
|
129
|
+
readonly cursor?: string;
|
|
130
|
+
readonly limit: number;
|
|
131
|
+
readonly queue: string;
|
|
132
|
+
}, import("@shivaedev/errors/taxonomy.ts").BadRequest | import("./schemas.ts").JobsPayloadInvalid | import("./schemas.ts").JobsQueueUnregistered | import("./schemas.ts").JobsUnavailable, import("@shivaedev/identity/identity.ts").SessionUser>;
|
|
133
|
+
}, "readPolicy"> & {
|
|
134
|
+
readonly readPolicy: import("@shivaedev/contract/readPolicy.ts").QueryReadPolicy<{
|
|
135
|
+
readonly cursor?: string;
|
|
136
|
+
readonly limit: number;
|
|
137
|
+
readonly queue: string;
|
|
138
|
+
}, import("@shivaedev/errors/taxonomy.ts").BadRequest | import("./schemas.ts").JobsPayloadInvalid | import("./schemas.ts").JobsQueueUnregistered | import("./schemas.ts").JobsUnavailable, import("@shivaedev/identity/identity.ts").SessionUser>;
|
|
139
|
+
}, Omit<Omit<NoInfer<import("@shivaedev/contract/operation.ts").Query<"job", Schema.Struct<{
|
|
104
140
|
id: Schema.String;
|
|
105
141
|
queue: Schema.String;
|
|
106
142
|
}>, Schema.OptionFromNullOr<Schema.Union<Schema.Struct<{
|
|
@@ -123,7 +159,17 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsEnt
|
|
|
123
159
|
JobsPayloadInvalid: typeof import("./schemas.ts").JobsPayloadInvalid;
|
|
124
160
|
JobsQueueUnregistered: typeof import("./schemas.ts").JobsQueueUnregistered;
|
|
125
161
|
JobsUnavailable: typeof import("./schemas.ts").JobsUnavailable;
|
|
126
|
-
}
|
|
162
|
+
}, never>>, "readPolicy"> & {
|
|
163
|
+
readonly readPolicy: import("@shivaedev/contract/readPolicy.ts").QueryReadPolicy<{
|
|
164
|
+
readonly id: string;
|
|
165
|
+
readonly queue: string;
|
|
166
|
+
}, import("@shivaedev/errors/taxonomy.ts").BadRequest | import("./schemas.ts").JobsPayloadInvalid | import("./schemas.ts").JobsQueueUnregistered | import("./schemas.ts").JobsUnavailable, import("@shivaedev/identity/identity.ts").SessionUser>;
|
|
167
|
+
}, "readPolicy"> & {
|
|
168
|
+
readonly readPolicy: import("@shivaedev/contract/readPolicy.ts").QueryReadPolicy<{
|
|
169
|
+
readonly id: string;
|
|
170
|
+
readonly queue: string;
|
|
171
|
+
}, import("@shivaedev/errors/taxonomy.ts").BadRequest | import("./schemas.ts").JobsPayloadInvalid | import("./schemas.ts").JobsQueueUnregistered | import("./schemas.ts").JobsUnavailable, import("@shivaedev/identity/identity.ts").SessionUser>;
|
|
172
|
+
}], readonly [NoInfer<import("@shivaedev/contract/operation.ts").Command<"retry", Schema.Struct<{
|
|
127
173
|
id: Schema.String;
|
|
128
174
|
queue: Schema.String;
|
|
129
175
|
}>, Schema.Void, {
|
|
@@ -181,7 +227,7 @@ export declare function jobsPageWithRetry<const TQueues extends readonly JobsEnt
|
|
|
181
227
|
readonly queryIndexes: Schema.optional<Schema.$Array<Schema.Number>>;
|
|
182
228
|
}>, Schema.Struct<{
|
|
183
229
|
readonly _tag: Schema.Literal<"Resync">;
|
|
184
|
-
}>]>, Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>>, Schema.Never, typeof JobsPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.jobs.counts", Schema.Struct<{
|
|
230
|
+
}>]>, 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<{
|
|
185
231
|
queue: Schema.String;
|
|
186
232
|
}>, Schema.Struct<{
|
|
187
233
|
readonly activeCount: Schema.Number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryPage.d.ts","sourceRoot":"","sources":["../../src/jobs/retryPage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;;;;;AAK5C,qBAAa,aAAc,SAAQ,kBAGjC;CAAG;AAEL,wBAAgB,iBAAiB,CAAC,KAAK,CAAC,OAAO,SAAS,SAAS,SAAS,EAAE,EAAE,GAAG,MAAM,EAAE,OAAO
|
|
1
|
+
{"version":3,"file":"retryPage.d.ts","sourceRoot":"","sources":["../../src/jobs/retryPage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;;;;;AAK5C,qBAAa,aAAc,SAAQ,kBAGjC;CAAG;AAEL,wBAAgB,iBAAiB,CAAC,KAAK,CAAC,OAAO,SAAS,SAAS,SAAS,EAAE,EAAE,GAAG,MAAM,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0B/F"}
|
package/dist/page.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Rpc, RpcGroup, RpcMiddleware } from "effect/rpc";
|
|
2
2
|
import type { Permission } from "@shivaedev/access/permission.ts";
|
|
3
|
-
import type
|
|
3
|
+
import { type Contract, type QueryServices } from "@shivaedev/contract/contract.ts";
|
|
4
4
|
import type { CommandShape, QueryShape, StreamShape } from "@shivaedev/contract/operation.ts";
|
|
5
|
+
import type { QueryReadPolicy } from "@shivaedev/contract/readPolicy.ts";
|
|
6
|
+
import { SessionUser } from "@shivaedev/identity/identity.ts";
|
|
5
7
|
export interface AdminRoute {
|
|
6
8
|
readonly path: string;
|
|
7
9
|
readonly permission: Permission;
|
|
@@ -17,7 +19,13 @@ export interface AdminPage {
|
|
|
17
19
|
readonly route: AdminRoute;
|
|
18
20
|
readonly [AdminPageTypeId]: true;
|
|
19
21
|
}
|
|
20
|
-
|
|
22
|
+
type PageQueries<TQueries extends readonly QueryShape[]> = {
|
|
23
|
+
readonly [TIndex in keyof TQueries]: Omit<TQueries[TIndex], "readPolicy"> & {
|
|
24
|
+
readonly readPolicy: QueryReadPolicy<TQueries[TIndex]["payload"]["Type"], TQueries[TIndex]["error"]["Type"], QueryServices<TQueries[TIndex]> | SessionUser>;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
type PageRpcs<TRpc> = TRpc extends Rpc.Rpc<infer TTag, infer TPayload, infer TSuccess, infer TError, infer TMiddleware, infer R> ? Rpc.Rpc<TTag, TPayload, TSuccess, TError, TMiddleware, R | SessionUser> : never;
|
|
28
|
+
export declare function adminPage<const TId extends string, const TName extends string, const TQueries extends readonly QueryShape[], const TCommands extends readonly CommandShape[], TRpcs extends Rpc.AnyWithProps, const TStreams extends readonly StreamShape[], TMiddleware extends RpcMiddleware.AnyService & {
|
|
21
29
|
readonly permission: Permission;
|
|
22
30
|
}>(page: {
|
|
23
31
|
readonly id: TId;
|
|
@@ -26,7 +34,7 @@ export declare function adminPage<const TId extends string, const TName extends
|
|
|
26
34
|
readonly contract: Contract<TName, TQueries, TCommands, TRpcs, TStreams>;
|
|
27
35
|
}): AdminPage & {
|
|
28
36
|
readonly id: TId;
|
|
29
|
-
readonly contract: Contract<TName, TQueries
|
|
37
|
+
readonly contract: Contract<TName, PageQueries<TQueries>, TCommands, Rpc.AddMiddleware<PageRpcs<TRpcs>, TMiddleware>, TStreams>;
|
|
30
38
|
};
|
|
31
39
|
export {};
|
|
32
40
|
//# sourceMappingURL=page.d.ts.map
|
package/dist/page.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../src/page.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../src/page.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,KAAK,QAAQ,EAA2B,KAAK,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAC7G,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC9F,OAAO,KAAK,EAAE,eAAe,EAAU,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,MAAM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
import { hasPermission } from "@shivaedev/identity/permission.ts";
|
|
1
5
|
const AdminPageTypeId = Symbol.for("@shivaedev/admin/Page");
|
|
2
6
|
export function adminPage(page) {
|
|
7
|
+
const { declaration } = page.contract;
|
|
8
|
+
const queries = declaration.queries.map((query) => ({
|
|
9
|
+
...query,
|
|
10
|
+
readPolicy: (payload, viewer) => Effect.flatMap(SessionUser, (user) => hasPermission(user, page.permission.permission) ? (query.readPolicy?.(payload, viewer) ?? Effect.succeed(true)) : Effect.succeed(false)),
|
|
11
|
+
}));
|
|
12
|
+
let protectedContract = contract(declaration.name, { ...declaration, queries });
|
|
13
|
+
const original = page.contract.requests.values().next().value;
|
|
14
|
+
if (original !== undefined) {
|
|
15
|
+
for (const middleware of original.middlewares) {
|
|
16
|
+
protectedContract = protectedContract.middleware(middleware);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
3
19
|
return {
|
|
4
20
|
...page,
|
|
5
21
|
route: { ...page.route, permission: page.permission.permission },
|
|
6
22
|
[AdminPageTypeId]: true,
|
|
7
|
-
contract:
|
|
23
|
+
contract: protectedContract.middleware(page.permission),
|
|
8
24
|
};
|
|
9
25
|
}
|
|
10
26
|
//# sourceMappingURL=page.js.map
|
package/dist/page.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.js","sourceRoot":"","sources":["../src/page.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"page.js","sourceRoot":"","sources":["../src/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAe,MAAM,QAAQ,CAAC;AAG7C,OAAO,EAAiB,QAAQ,EAAqC,MAAM,iCAAiC,CAAC;AAG7G,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAQlE,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAkD5D,MAAM,UAAU,SAAS,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AAU,CAAC;KACvD,CAAC;AACH,CAAC"}
|
package/dist/users/page.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare const UsersList: Schema.Struct<{
|
|
|
16
16
|
}>;
|
|
17
17
|
export declare function usersPage<const TRole extends string>(access: Pick<AccessPolicy<TRole>, "Role">): import("#page.ts").AdminPage & {
|
|
18
18
|
readonly id: "users";
|
|
19
|
-
readonly contract: import("@shivaedev/contract/contract.ts").Contract<"admin.users", readonly [NoInfer<import("@shivaedev/contract/operation.ts").Query<"list", Schema.Struct<{
|
|
19
|
+
readonly contract: import("@shivaedev/contract/contract.ts").Contract<"admin.users", readonly [Omit<NoInfer<import("@shivaedev/contract/operation.ts").Query<"list", Schema.Struct<{
|
|
20
20
|
readonly cursor: Schema.optionalKey<Schema.String>;
|
|
21
21
|
readonly limit: Schema.Number;
|
|
22
22
|
}>, Schema.Struct<{
|
|
@@ -32,7 +32,12 @@ export declare function usersPage<const TRole extends string>(access: Pick<Acces
|
|
|
32
32
|
}>, {
|
|
33
33
|
readonly AuthUnavailable: typeof AuthUnavailable;
|
|
34
34
|
readonly Forbidden: typeof Forbidden;
|
|
35
|
-
}
|
|
35
|
+
}, never>>, "readPolicy"> & {
|
|
36
|
+
readonly readPolicy: import("@shivaedev/contract/readPolicy.ts").QueryReadPolicy<{
|
|
37
|
+
readonly cursor?: string;
|
|
38
|
+
readonly limit: number;
|
|
39
|
+
}, AuthUnavailable | Forbidden, import("@shivaedev/identity/identity.ts").SessionUser>;
|
|
40
|
+
}], readonly [NoInfer<import("@shivaedev/contract/operation.ts").Command<"changeRole", Schema.Struct<{
|
|
36
41
|
role: Schema.Literals<TRole[]>;
|
|
37
42
|
userId: Schema.String;
|
|
38
43
|
}>, Schema.Void, {
|
|
@@ -66,7 +71,7 @@ export declare function usersPage<const TRole extends string>(access: Pick<Acces
|
|
|
66
71
|
readonly queryIndexes: Schema.optional<Schema.$Array<Schema.Number>>;
|
|
67
72
|
}>, Schema.Struct<{
|
|
68
73
|
readonly _tag: Schema.Literal<"Resync">;
|
|
69
|
-
}>]>, Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>>, Schema.Never, typeof UsersPermission, never> | import("effect/rpc/Rpc").Rpc<"admin.users.changeRole", Schema.Struct<{
|
|
74
|
+
}>]>, 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.changeRole", Schema.Struct<{
|
|
70
75
|
role: Schema.Literals<TRole[]>;
|
|
71
76
|
userId: Schema.String;
|
|
72
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<{
|
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,
|
|
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;AAIjE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAErF,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAA2B,MAAM,iBAAiB,CAAC;AAI5E,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,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Schema } from "effect";
|
|
2
2
|
import { collection } from "@shivaedev/changes/keys.ts";
|
|
3
3
|
import { contract } from "@shivaedev/contract/contract.ts";
|
|
4
4
|
import { command, query } from "@shivaedev/contract/operation.ts";
|
|
5
5
|
import { AuthUnavailable, Forbidden, NotFound } from "@shivaedev/errors/taxonomy.ts";
|
|
6
|
-
import { SessionUser } from "@shivaedev/identity/identity.ts";
|
|
7
|
-
import { hasPermission } from "@shivaedev/identity/permission.ts";
|
|
8
6
|
import { adminPage } from "#page.ts";
|
|
9
7
|
import { UsersPermission } from "#permissions.ts";
|
|
10
8
|
import { LastRoleAssigner, UserList, UserListInput } from "#users/roles.ts";
|
|
@@ -23,7 +21,6 @@ export function usersPage(access) {
|
|
|
23
21
|
queries: [
|
|
24
22
|
query("list", {
|
|
25
23
|
payload: UserListInput.fields,
|
|
26
|
-
readPolicy: () => Effect.map(SessionUser, (user) => hasPermission(user, UsersPermission.permission)),
|
|
27
24
|
reads: () => [users.list],
|
|
28
25
|
rejections: { AuthUnavailable, Forbidden },
|
|
29
26
|
success: UsersList,
|
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,
|
|
1
|
+
{"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/users/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,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AAU,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/admin",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
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": {
|
|
@@ -45,17 +45,17 @@
|
|
|
45
45
|
"@shivaedev/changes": "0.5.1",
|
|
46
46
|
"@shivaedev/contract": "0.22.0",
|
|
47
47
|
"@shivaedev/errors": "0.1.2",
|
|
48
|
-
"@shivaedev/identity": "0.
|
|
49
|
-
"@shivaedev/jobs": "0.23.
|
|
48
|
+
"@shivaedev/identity": "0.6.0",
|
|
49
|
+
"@shivaedev/jobs": "0.23.1",
|
|
50
50
|
"@shivaedev/react": "0.23.0",
|
|
51
|
-
"@shivaedev/sql": "0.26.
|
|
51
|
+
"@shivaedev/sql": "0.26.1"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@effect/atom-react": "4.0.6",
|
|
55
|
-
"@shivaedev/quality": "0.
|
|
56
|
-
"@shivaedev/server": "0.
|
|
57
|
-
"@shivaedev/test-sql": "0.
|
|
58
|
-
"@shivaedev/test-story": "0.25.
|
|
55
|
+
"@shivaedev/quality": "0.47.0",
|
|
56
|
+
"@shivaedev/server": "0.7.0",
|
|
57
|
+
"@shivaedev/test-sql": "0.13.0",
|
|
58
|
+
"@shivaedev/test-story": "0.25.1",
|
|
59
59
|
"@types/node": "24.19.2",
|
|
60
60
|
"@types/react": "19.3.0",
|
|
61
61
|
"@types/react-dom": "19.3.0",
|
package/src/jobs/page.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Schema } from "effect";
|
|
2
2
|
import { contract } from "@shivaedev/contract/contract.ts";
|
|
3
3
|
import { query } from "@shivaedev/contract/operation.ts";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { type JobsEntry, type JobsPayload, jobsQueue } from "#jobs/entry.ts";
|
|
5
|
+
import { jobsKeys } from "#jobs/keys.ts";
|
|
6
|
+
import { deadLetteredSchema, JobsFailures, JobsHealth, jobPage, jobSchema, PageFields, QueueCounts } from "#jobs/schemas.ts";
|
|
6
7
|
import { adminPage } from "#page.ts";
|
|
7
8
|
import { JobsPermission } from "#permissions.ts";
|
|
8
|
-
import { type JobsEntry, type JobsPayload, jobsQueue } from "./entry.ts";
|
|
9
|
-
import { jobsKeys } from "./keys.ts";
|
|
10
|
-
import { deadLetteredSchema, JobsFailures, JobsHealth, jobPage, jobSchema, PageFields, QueueCounts } from "./schemas.ts";
|
|
11
9
|
|
|
12
10
|
export function jobsPage<const TQueues extends readonly JobsEntry[]>(...queues: TQueues) {
|
|
13
11
|
const definitions = queues.map((queue: TQueues[number]) => jobsQueue(queue));
|
|
@@ -17,35 +15,30 @@ export function jobsPage<const TQueues extends readonly JobsEntry[]>(...queues:
|
|
|
17
15
|
contract: contract("admin.jobs", {
|
|
18
16
|
queries: [
|
|
19
17
|
query("health", {
|
|
20
|
-
readPolicy: () => Effect.map(SessionUser, (user) => hasPermission(user, JobsPermission.permission)),
|
|
21
18
|
reads: () => [jobsKeys.health.list],
|
|
22
19
|
rejections: JobsFailures,
|
|
23
20
|
success: JobsHealth,
|
|
24
21
|
}),
|
|
25
22
|
query("counts", {
|
|
26
23
|
payload: { queue: Schema.String },
|
|
27
|
-
readPolicy: () => Effect.map(SessionUser, (user) => hasPermission(user, JobsPermission.permission)),
|
|
28
24
|
reads: ({ queue }) => [jobsKeys.counts.item(queue)],
|
|
29
25
|
rejections: JobsFailures,
|
|
30
26
|
success: QueueCounts,
|
|
31
27
|
}),
|
|
32
28
|
query("failed", {
|
|
33
29
|
payload: { ...PageFields, queue: Schema.String },
|
|
34
|
-
readPolicy: () => Effect.map(SessionUser, (user) => hasPermission(user, JobsPermission.permission)),
|
|
35
30
|
reads: ({ queue }) => [jobsKeys.failed.item(queue)],
|
|
36
31
|
rejections: JobsFailures,
|
|
37
32
|
success: jobPage(Job),
|
|
38
33
|
}),
|
|
39
34
|
query("deadLettered", {
|
|
40
35
|
payload: { ...PageFields, queue: Schema.String },
|
|
41
|
-
readPolicy: () => Effect.map(SessionUser, (user) => hasPermission(user, JobsPermission.permission)),
|
|
42
36
|
reads: ({ queue }) => [jobsKeys.deadLettered.item(queue)],
|
|
43
37
|
rejections: JobsFailures,
|
|
44
38
|
success: jobPage(DeadLettered),
|
|
45
39
|
}),
|
|
46
40
|
query("job", {
|
|
47
41
|
payload: { id: Schema.String, queue: Schema.String },
|
|
48
|
-
readPolicy: () => Effect.map(SessionUser, (user) => hasPermission(user, JobsPermission.permission)),
|
|
49
42
|
reads: ({ queue, id }) => [jobsKeys.job(queue).item(id)],
|
|
50
43
|
rejections: JobsFailures,
|
|
51
44
|
success: Schema.OptionFromNullOr(Job),
|
package/src/page.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { Effect, type Option } from "effect";
|
|
1
2
|
import type { Rpc, RpcGroup, RpcMiddleware } from "effect/rpc";
|
|
2
3
|
import type { Permission } from "@shivaedev/access/permission.ts";
|
|
3
|
-
import type
|
|
4
|
+
import { type Contract, contract, type Declared, type QueryServices } from "@shivaedev/contract/contract.ts";
|
|
4
5
|
import type { CommandShape, QueryShape, StreamShape } from "@shivaedev/contract/operation.ts";
|
|
6
|
+
import type { QueryReadPolicy, Viewer } from "@shivaedev/contract/readPolicy.ts";
|
|
7
|
+
import { SessionUser } from "@shivaedev/identity/identity.ts";
|
|
8
|
+
import { hasPermission } from "@shivaedev/identity/permission.ts";
|
|
5
9
|
|
|
6
10
|
export interface AdminRoute {
|
|
7
11
|
readonly path: string;
|
|
@@ -21,12 +25,33 @@ export interface AdminPage {
|
|
|
21
25
|
readonly [AdminPageTypeId]: true;
|
|
22
26
|
}
|
|
23
27
|
|
|
28
|
+
interface PageGroup extends RpcGroup.Any {
|
|
29
|
+
readonly application: RpcGroup.Any;
|
|
30
|
+
middleware: (middleware: RpcMiddleware.AnyService) => PageGroup;
|
|
31
|
+
readonly requests: ReadonlyMap<string, Rpc.Any>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type PageQueries<TQueries extends readonly QueryShape[]> = {
|
|
35
|
+
readonly [TIndex in keyof TQueries]: Omit<TQueries[TIndex], "readPolicy"> & {
|
|
36
|
+
readonly readPolicy: QueryReadPolicy<
|
|
37
|
+
TQueries[TIndex]["payload"]["Type"],
|
|
38
|
+
TQueries[TIndex]["error"]["Type"],
|
|
39
|
+
QueryServices<TQueries[TIndex]> | SessionUser
|
|
40
|
+
>;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
type PageRpcs<TRpc> =
|
|
45
|
+
TRpc extends Rpc.Rpc<infer TTag, infer TPayload, infer TSuccess, infer TError, infer TMiddleware, infer R>
|
|
46
|
+
? Rpc.Rpc<TTag, TPayload, TSuccess, TError, TMiddleware, R | SessionUser>
|
|
47
|
+
: never;
|
|
48
|
+
|
|
24
49
|
export function adminPage<
|
|
25
50
|
const TId extends string,
|
|
26
51
|
const TName extends string,
|
|
27
52
|
const TQueries extends readonly QueryShape[],
|
|
28
53
|
const TCommands extends readonly CommandShape[],
|
|
29
|
-
TRpcs extends Rpc.
|
|
54
|
+
TRpcs extends Rpc.AnyWithProps,
|
|
30
55
|
const TStreams extends readonly StreamShape[],
|
|
31
56
|
TMiddleware extends RpcMiddleware.AnyService & { readonly permission: Permission },
|
|
32
57
|
>(page: {
|
|
@@ -36,12 +61,36 @@ export function adminPage<
|
|
|
36
61
|
readonly contract: Contract<TName, TQueries, TCommands, TRpcs, TStreams>;
|
|
37
62
|
}): AdminPage & {
|
|
38
63
|
readonly id: TId;
|
|
39
|
-
readonly contract: Contract<TName, TQueries
|
|
40
|
-
}
|
|
64
|
+
readonly contract: Contract<TName, PageQueries<TQueries>, TCommands, Rpc.AddMiddleware<PageRpcs<TRpcs>, TMiddleware>, TStreams>;
|
|
65
|
+
};
|
|
66
|
+
export function adminPage(page: {
|
|
67
|
+
readonly id: string;
|
|
68
|
+
readonly route: Omit<AdminRoute, "permission">;
|
|
69
|
+
readonly permission: RpcMiddleware.AnyService & { readonly permission: Permission };
|
|
70
|
+
readonly contract: {
|
|
71
|
+
readonly declaration: Declared<string, readonly QueryShape[], readonly CommandShape[], readonly StreamShape[]>;
|
|
72
|
+
readonly requests: ReadonlyMap<string, Rpc.AnyWithProps>;
|
|
73
|
+
};
|
|
74
|
+
}): AdminPage {
|
|
75
|
+
const { declaration } = page.contract;
|
|
76
|
+
const queries = declaration.queries.map((query) => ({
|
|
77
|
+
...query,
|
|
78
|
+
readPolicy: (payload: unknown, viewer: Option.Option<Viewer>) =>
|
|
79
|
+
Effect.flatMap(SessionUser, (user) =>
|
|
80
|
+
hasPermission(user, page.permission.permission) ? (query.readPolicy?.(payload, viewer) ?? Effect.succeed(true)) : Effect.succeed(false),
|
|
81
|
+
),
|
|
82
|
+
}));
|
|
83
|
+
let protectedContract: PageGroup = contract(declaration.name, { ...declaration, queries });
|
|
84
|
+
const original = page.contract.requests.values().next().value;
|
|
85
|
+
if (original !== undefined) {
|
|
86
|
+
for (const middleware of original.middlewares) {
|
|
87
|
+
protectedContract = protectedContract.middleware(middleware);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
41
90
|
return {
|
|
42
91
|
...page,
|
|
43
92
|
route: { ...page.route, permission: page.permission.permission },
|
|
44
93
|
[AdminPageTypeId]: true as const,
|
|
45
|
-
contract:
|
|
94
|
+
contract: protectedContract.middleware(page.permission),
|
|
46
95
|
};
|
|
47
96
|
}
|
package/src/users/page.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Schema } from "effect";
|
|
2
2
|
import type { AccessPolicy } from "@shivaedev/access/roleSet.ts";
|
|
3
3
|
import { collection } from "@shivaedev/changes/keys.ts";
|
|
4
4
|
import { contract } from "@shivaedev/contract/contract.ts";
|
|
5
5
|
import { command, query } from "@shivaedev/contract/operation.ts";
|
|
6
6
|
import { AuthUnavailable, Forbidden, NotFound } from "@shivaedev/errors/taxonomy.ts";
|
|
7
|
-
import { SessionUser } from "@shivaedev/identity/identity.ts";
|
|
8
|
-
import { hasPermission } from "@shivaedev/identity/permission.ts";
|
|
9
7
|
import { adminPage } from "#page.ts";
|
|
10
8
|
import { UsersPermission } from "#permissions.ts";
|
|
11
9
|
import { LastRoleAssigner, UserList, UserListInput } from "#users/roles.ts";
|
|
@@ -26,7 +24,6 @@ export function usersPage<const TRole extends string>(access: Pick<AccessPolicy<
|
|
|
26
24
|
queries: [
|
|
27
25
|
query("list", {
|
|
28
26
|
payload: UserListInput.fields,
|
|
29
|
-
readPolicy: () => Effect.map(SessionUser, (user) => hasPermission(user, UsersPermission.permission)),
|
|
30
27
|
reads: () => [users.list],
|
|
31
28
|
rejections: { AuthUnavailable, Forbidden },
|
|
32
29
|
success: UsersList,
|