@yss123/cage-admin 0.0.0-stage → 0.2.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.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +49 -2
  3. package/dist/bootstrap.d.ts +17 -0
  4. package/dist/bootstrap.js +43 -0
  5. package/dist/bootstrap.js.map +1 -0
  6. package/dist/catalog.d.ts +43 -0
  7. package/dist/catalog.js +91 -0
  8. package/dist/catalog.js.map +1 -0
  9. package/dist/domain/constraints.d.ts +9 -0
  10. package/dist/domain/constraints.js +61 -0
  11. package/dist/domain/constraints.js.map +1 -0
  12. package/dist/domain/index.d.ts +1 -0
  13. package/dist/domain/index.js +5 -0
  14. package/dist/domain/index.js.map +1 -0
  15. package/dist/domain/org.d.ts +387 -0
  16. package/dist/domain/org.js +238 -0
  17. package/dist/domain/org.js.map +1 -0
  18. package/dist/http.d.ts +4 -0
  19. package/dist/http.js +150 -0
  20. package/dist/http.js.map +1 -0
  21. package/dist/index.d.ts +6 -0
  22. package/dist/index.js +8 -0
  23. package/dist/index.js.map +1 -0
  24. package/package.json +49 -3
  25. package/ui/dist/app/shell.js +110 -0
  26. package/ui/dist/app.js +24 -0
  27. package/ui/dist/modules/audit/audit-page.js +95 -0
  28. package/ui/dist/modules/audit/index.js +1 -0
  29. package/ui/dist/modules/auth/index.js +1 -0
  30. package/ui/dist/modules/auth/login-page.js +30 -0
  31. package/ui/dist/modules/operations/index.js +2 -0
  32. package/ui/dist/modules/operations/operations-page.js +95 -0
  33. package/ui/dist/modules/operations/sync-page.js +48 -0
  34. package/ui/dist/modules/org/index.js +1 -0
  35. package/ui/dist/modules/org/org-page.js +213 -0
  36. package/ui/dist/modules/roles/index.js +1 -0
  37. package/ui/dist/modules/roles/roles-page.js +308 -0
  38. package/ui/dist/modules/tasks/index.js +1 -0
  39. package/ui/dist/modules/tasks/tasks-page.js +60 -0
  40. package/ui/dist/shared/api.js +84 -0
  41. package/ui/dist/shared/dom.js +103 -0
  42. package/ui/dist/shared/labels.js +55 -0
  43. package/ui/dist/shared/navigation.js +7 -0
  44. package/ui/dist/shared/types.js +1 -0
  45. package/ui/index.html +14 -0
  46. package/ui/style.css +1577 -0
@@ -0,0 +1,387 @@
1
+ import { z } from 'zod';
2
+ export declare const Dept: import("@yss123/cage-kernel").Aggregate<"Dept", {
3
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
4
+ code: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
5
+ parentId: import("@yss123/cage-kernel").Field<z.ZodString, true, "ref">;
6
+ ancestors: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
7
+ leaderId: import("@yss123/cage-kernel").Field<z.ZodString, true, "id">;
8
+ }, string>;
9
+ export declare const User: import("@yss123/cage-kernel").Aggregate<"User", {
10
+ username: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
11
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
12
+ deptId: import("@yss123/cage-kernel").Field<z.ZodString, false, "ref">;
13
+ roleIds: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodString>, false, import("@yss123/cage-kernel").FieldKind>;
14
+ phone: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
15
+ email: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
16
+ ssoSubject: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
17
+ passwordHash: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
18
+ }, string>;
19
+ export declare const Role: import("@yss123/cage-kernel").Aggregate<"Role", {
20
+ code: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
21
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
22
+ capabilities: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodObject<{
23
+ capability: z.ZodString;
24
+ params: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
25
+ }, z.core.$strip>>, false, import("@yss123/cage-kernel").FieldKind>;
26
+ scopes: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodObject<{
27
+ aggregate: z.ZodString;
28
+ combinator: z.ZodEnum<{
29
+ all: "all";
30
+ self: "self";
31
+ dept: "dept";
32
+ deptSubtree: "deptSubtree";
33
+ deptSet: "deptSet";
34
+ }>;
35
+ deptIds: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
36
+ }, z.core.$strip>>, false, import("@yss123/cage-kernel").FieldKind>;
37
+ }, string>;
38
+ export declare const createDept: import("@yss123/cage-kernel").Command<import("@yss123/cage-kernel").Aggregate<"Dept", {
39
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
40
+ code: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
41
+ parentId: import("@yss123/cage-kernel").Field<z.ZodString, true, "ref">;
42
+ ancestors: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
43
+ leaderId: import("@yss123/cage-kernel").Field<z.ZodString, true, "id">;
44
+ }, string>, {
45
+ depts: import("@yss123/cage-kernel").Aggregate<"Dept", {
46
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
47
+ code: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
48
+ parentId: import("@yss123/cage-kernel").Field<z.ZodString, true, "ref">;
49
+ ancestors: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
50
+ leaderId: import("@yss123/cage-kernel").Field<z.ZodString, true, "id">;
51
+ }, string>;
52
+ }, z.ZodObject<{
53
+ name: z.ZodString;
54
+ code: z.ZodOptional<z.ZodString>;
55
+ parentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
56
+ leaderId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
57
+ }, z.core.$strip>>;
58
+ export declare const updateDept: import("@yss123/cage-kernel").Command<import("@yss123/cage-kernel").Aggregate<"Dept", {
59
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
60
+ code: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
61
+ parentId: import("@yss123/cage-kernel").Field<z.ZodString, true, "ref">;
62
+ ancestors: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
63
+ leaderId: import("@yss123/cage-kernel").Field<z.ZodString, true, "id">;
64
+ }, string>, {}, z.ZodObject<{
65
+ id: z.ZodString;
66
+ name: z.ZodOptional<z.ZodString>;
67
+ code: z.ZodOptional<z.ZodNullable<z.ZodString>>;
68
+ leaderId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
69
+ }, z.core.$strip>>;
70
+ export declare const archiveDept: import("@yss123/cage-kernel").Command<import("@yss123/cage-kernel").Aggregate<"Dept", {
71
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
72
+ code: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
73
+ parentId: import("@yss123/cage-kernel").Field<z.ZodString, true, "ref">;
74
+ ancestors: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
75
+ leaderId: import("@yss123/cage-kernel").Field<z.ZodString, true, "id">;
76
+ }, string>, {
77
+ users: import("@yss123/cage-kernel").Aggregate<"User", {
78
+ username: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
79
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
80
+ deptId: import("@yss123/cage-kernel").Field<z.ZodString, false, "ref">;
81
+ roleIds: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodString>, false, import("@yss123/cage-kernel").FieldKind>;
82
+ phone: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
83
+ email: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
84
+ ssoSubject: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
85
+ passwordHash: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
86
+ }, string>;
87
+ depts: import("@yss123/cage-kernel").Aggregate<"Dept", {
88
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
89
+ code: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
90
+ parentId: import("@yss123/cage-kernel").Field<z.ZodString, true, "ref">;
91
+ ancestors: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
92
+ leaderId: import("@yss123/cage-kernel").Field<z.ZodString, true, "id">;
93
+ }, string>;
94
+ }, z.ZodObject<{
95
+ id: z.ZodString;
96
+ }, z.core.$strip>>;
97
+ export declare const createUser: import("@yss123/cage-kernel").Command<import("@yss123/cage-kernel").Aggregate<"User", {
98
+ username: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
99
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
100
+ deptId: import("@yss123/cage-kernel").Field<z.ZodString, false, "ref">;
101
+ roleIds: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodString>, false, import("@yss123/cage-kernel").FieldKind>;
102
+ phone: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
103
+ email: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
104
+ ssoSubject: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
105
+ passwordHash: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
106
+ }, string>, {
107
+ users: import("@yss123/cage-kernel").Aggregate<"User", {
108
+ username: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
109
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
110
+ deptId: import("@yss123/cage-kernel").Field<z.ZodString, false, "ref">;
111
+ roleIds: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodString>, false, import("@yss123/cage-kernel").FieldKind>;
112
+ phone: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
113
+ email: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
114
+ ssoSubject: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
115
+ passwordHash: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
116
+ }, string>;
117
+ depts: import("@yss123/cage-kernel").Aggregate<"Dept", {
118
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
119
+ code: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
120
+ parentId: import("@yss123/cage-kernel").Field<z.ZodString, true, "ref">;
121
+ ancestors: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
122
+ leaderId: import("@yss123/cage-kernel").Field<z.ZodString, true, "id">;
123
+ }, string>;
124
+ }, z.ZodObject<{
125
+ ssoSubject: z.ZodOptional<z.ZodNullable<z.ZodString>>;
126
+ name: z.ZodString;
127
+ deptId: z.ZodString;
128
+ phone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
129
+ email: z.ZodOptional<z.ZodNullable<z.ZodString>>;
130
+ username: z.ZodString;
131
+ }, z.core.$strip>>;
132
+ export declare const updateUser: import("@yss123/cage-kernel").Command<import("@yss123/cage-kernel").Aggregate<"User", {
133
+ username: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
134
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
135
+ deptId: import("@yss123/cage-kernel").Field<z.ZodString, false, "ref">;
136
+ roleIds: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodString>, false, import("@yss123/cage-kernel").FieldKind>;
137
+ phone: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
138
+ email: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
139
+ ssoSubject: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
140
+ passwordHash: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
141
+ }, string>, {
142
+ depts: import("@yss123/cage-kernel").Aggregate<"Dept", {
143
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
144
+ code: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
145
+ parentId: import("@yss123/cage-kernel").Field<z.ZodString, true, "ref">;
146
+ ancestors: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
147
+ leaderId: import("@yss123/cage-kernel").Field<z.ZodString, true, "id">;
148
+ }, string>;
149
+ }, z.ZodObject<{
150
+ id: z.ZodString;
151
+ name: z.ZodOptional<z.ZodString>;
152
+ deptId: z.ZodOptional<z.ZodString>;
153
+ phone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
154
+ email: z.ZodOptional<z.ZodNullable<z.ZodString>>;
155
+ }, z.core.$strip>>;
156
+ export declare const assignRoles: import("@yss123/cage-kernel").Command<import("@yss123/cage-kernel").Aggregate<"User", {
157
+ username: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
158
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
159
+ deptId: import("@yss123/cage-kernel").Field<z.ZodString, false, "ref">;
160
+ roleIds: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodString>, false, import("@yss123/cage-kernel").FieldKind>;
161
+ phone: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
162
+ email: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
163
+ ssoSubject: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
164
+ passwordHash: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
165
+ }, string>, {
166
+ roles: import("@yss123/cage-kernel").Aggregate<"Role", {
167
+ code: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
168
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
169
+ capabilities: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodObject<{
170
+ capability: z.ZodString;
171
+ params: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
172
+ }, z.core.$strip>>, false, import("@yss123/cage-kernel").FieldKind>;
173
+ scopes: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodObject<{
174
+ aggregate: z.ZodString;
175
+ combinator: z.ZodEnum<{
176
+ all: "all";
177
+ self: "self";
178
+ dept: "dept";
179
+ deptSubtree: "deptSubtree";
180
+ deptSet: "deptSet";
181
+ }>;
182
+ deptIds: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
183
+ }, z.core.$strip>>, false, import("@yss123/cage-kernel").FieldKind>;
184
+ }, string>;
185
+ }, z.ZodObject<{
186
+ id: z.ZodString;
187
+ roleIds: z.ZodArray<z.ZodString>;
188
+ }, z.core.$strip>>;
189
+ export declare const disableUser: import("@yss123/cage-kernel").Command<import("@yss123/cage-kernel").Aggregate<"User", {
190
+ username: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
191
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
192
+ deptId: import("@yss123/cage-kernel").Field<z.ZodString, false, "ref">;
193
+ roleIds: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodString>, false, import("@yss123/cage-kernel").FieldKind>;
194
+ phone: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
195
+ email: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
196
+ ssoSubject: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
197
+ passwordHash: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
198
+ }, string>, {}, z.ZodObject<{
199
+ id: z.ZodString;
200
+ }, z.core.$strip>>;
201
+ export declare const enableUser: import("@yss123/cage-kernel").Command<import("@yss123/cage-kernel").Aggregate<"User", {
202
+ username: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
203
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
204
+ deptId: import("@yss123/cage-kernel").Field<z.ZodString, false, "ref">;
205
+ roleIds: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodString>, false, import("@yss123/cage-kernel").FieldKind>;
206
+ phone: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
207
+ email: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
208
+ ssoSubject: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
209
+ passwordHash: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
210
+ }, string>, {}, z.ZodObject<{
211
+ id: z.ZodString;
212
+ }, z.core.$strip>>;
213
+ /** 密码哈希:scrypt$盐$哈希(纯计算,不做 IO) */
214
+ export declare function hashPassword(pw: string): string;
215
+ export declare const setPassword: import("@yss123/cage-kernel").Command<import("@yss123/cage-kernel").Aggregate<"User", {
216
+ username: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
217
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
218
+ deptId: import("@yss123/cage-kernel").Field<z.ZodString, false, "ref">;
219
+ roleIds: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodString>, false, import("@yss123/cage-kernel").FieldKind>;
220
+ phone: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
221
+ email: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
222
+ ssoSubject: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
223
+ passwordHash: import("@yss123/cage-kernel").Field<z.ZodString, true, "text">;
224
+ }, string>, {}, z.ZodObject<{
225
+ id: z.ZodString;
226
+ password: z.ZodString;
227
+ }, z.core.$strip>>;
228
+ export declare const createRole: import("@yss123/cage-kernel").Command<import("@yss123/cage-kernel").Aggregate<"Role", {
229
+ code: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
230
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
231
+ capabilities: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodObject<{
232
+ capability: z.ZodString;
233
+ params: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
234
+ }, z.core.$strip>>, false, import("@yss123/cage-kernel").FieldKind>;
235
+ scopes: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodObject<{
236
+ aggregate: z.ZodString;
237
+ combinator: z.ZodEnum<{
238
+ all: "all";
239
+ self: "self";
240
+ dept: "dept";
241
+ deptSubtree: "deptSubtree";
242
+ deptSet: "deptSet";
243
+ }>;
244
+ deptIds: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
245
+ }, z.core.$strip>>, false, import("@yss123/cage-kernel").FieldKind>;
246
+ }, string>, {
247
+ roles: import("@yss123/cage-kernel").Aggregate<"Role", {
248
+ code: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
249
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
250
+ capabilities: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodObject<{
251
+ capability: z.ZodString;
252
+ params: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
253
+ }, z.core.$strip>>, false, import("@yss123/cage-kernel").FieldKind>;
254
+ scopes: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodObject<{
255
+ aggregate: z.ZodString;
256
+ combinator: z.ZodEnum<{
257
+ all: "all";
258
+ self: "self";
259
+ dept: "dept";
260
+ deptSubtree: "deptSubtree";
261
+ deptSet: "deptSet";
262
+ }>;
263
+ deptIds: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
264
+ }, z.core.$strip>>, false, import("@yss123/cage-kernel").FieldKind>;
265
+ }, string>;
266
+ }, z.ZodObject<{
267
+ code: z.ZodString;
268
+ name: z.ZodString;
269
+ }, z.core.$strip>>;
270
+ export declare const renameRole: import("@yss123/cage-kernel").Command<import("@yss123/cage-kernel").Aggregate<"Role", {
271
+ code: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
272
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
273
+ capabilities: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodObject<{
274
+ capability: z.ZodString;
275
+ params: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
276
+ }, z.core.$strip>>, false, import("@yss123/cage-kernel").FieldKind>;
277
+ scopes: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodObject<{
278
+ aggregate: z.ZodString;
279
+ combinator: z.ZodEnum<{
280
+ all: "all";
281
+ self: "self";
282
+ dept: "dept";
283
+ deptSubtree: "deptSubtree";
284
+ deptSet: "deptSet";
285
+ }>;
286
+ deptIds: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
287
+ }, z.core.$strip>>, false, import("@yss123/cage-kernel").FieldKind>;
288
+ }, string>, {}, z.ZodObject<{
289
+ id: z.ZodString;
290
+ name: z.ZodString;
291
+ }, z.core.$strip>>;
292
+ export declare const grantCapability: import("@yss123/cage-kernel").Command<import("@yss123/cage-kernel").Aggregate<"Role", {
293
+ code: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
294
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
295
+ capabilities: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodObject<{
296
+ capability: z.ZodString;
297
+ params: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
298
+ }, z.core.$strip>>, false, import("@yss123/cage-kernel").FieldKind>;
299
+ scopes: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodObject<{
300
+ aggregate: z.ZodString;
301
+ combinator: z.ZodEnum<{
302
+ all: "all";
303
+ self: "self";
304
+ dept: "dept";
305
+ deptSubtree: "deptSubtree";
306
+ deptSet: "deptSet";
307
+ }>;
308
+ deptIds: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
309
+ }, z.core.$strip>>, false, import("@yss123/cage-kernel").FieldKind>;
310
+ }, string>, {}, z.ZodObject<{
311
+ id: z.ZodString;
312
+ capability: z.ZodString;
313
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
314
+ }, z.core.$strip>>;
315
+ export declare const revokeCapability: import("@yss123/cage-kernel").Command<import("@yss123/cage-kernel").Aggregate<"Role", {
316
+ code: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
317
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
318
+ capabilities: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodObject<{
319
+ capability: z.ZodString;
320
+ params: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
321
+ }, z.core.$strip>>, false, import("@yss123/cage-kernel").FieldKind>;
322
+ scopes: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodObject<{
323
+ aggregate: z.ZodString;
324
+ combinator: z.ZodEnum<{
325
+ all: "all";
326
+ self: "self";
327
+ dept: "dept";
328
+ deptSubtree: "deptSubtree";
329
+ deptSet: "deptSet";
330
+ }>;
331
+ deptIds: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
332
+ }, z.core.$strip>>, false, import("@yss123/cage-kernel").FieldKind>;
333
+ }, string>, {}, z.ZodObject<{
334
+ id: z.ZodString;
335
+ capability: z.ZodString;
336
+ }, z.core.$strip>>;
337
+ export declare const setScope: import("@yss123/cage-kernel").Command<import("@yss123/cage-kernel").Aggregate<"Role", {
338
+ code: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
339
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
340
+ capabilities: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodObject<{
341
+ capability: z.ZodString;
342
+ params: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
343
+ }, z.core.$strip>>, false, import("@yss123/cage-kernel").FieldKind>;
344
+ scopes: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodObject<{
345
+ aggregate: z.ZodString;
346
+ combinator: z.ZodEnum<{
347
+ all: "all";
348
+ self: "self";
349
+ dept: "dept";
350
+ deptSubtree: "deptSubtree";
351
+ deptSet: "deptSet";
352
+ }>;
353
+ deptIds: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
354
+ }, z.core.$strip>>, false, import("@yss123/cage-kernel").FieldKind>;
355
+ }, string>, {}, z.ZodObject<{
356
+ id: z.ZodString;
357
+ aggregate: z.ZodString;
358
+ combinator: z.ZodNullable<z.ZodEnum<{
359
+ all: "all";
360
+ self: "self";
361
+ dept: "dept";
362
+ deptSubtree: "deptSubtree";
363
+ deptSet: "deptSet";
364
+ }>>;
365
+ deptIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
366
+ }, z.core.$strip>>;
367
+ export declare const archiveRole: import("@yss123/cage-kernel").Command<import("@yss123/cage-kernel").Aggregate<"Role", {
368
+ code: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
369
+ name: import("@yss123/cage-kernel").Field<z.ZodString, false, "text">;
370
+ capabilities: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodObject<{
371
+ capability: z.ZodString;
372
+ params: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
373
+ }, z.core.$strip>>, false, import("@yss123/cage-kernel").FieldKind>;
374
+ scopes: import("@yss123/cage-kernel").Field<z.ZodArray<z.ZodObject<{
375
+ aggregate: z.ZodString;
376
+ combinator: z.ZodEnum<{
377
+ all: "all";
378
+ self: "self";
379
+ dept: "dept";
380
+ deptSubtree: "deptSubtree";
381
+ deptSet: "deptSet";
382
+ }>;
383
+ deptIds: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
384
+ }, z.core.$strip>>, false, import("@yss123/cage-kernel").FieldKind>;
385
+ }, string>, {}, z.ZodObject<{
386
+ id: z.ZodString;
387
+ }, z.core.$strip>>;
@@ -0,0 +1,238 @@
1
+ // 组织模型:部门、用户、角色。它们本身也是聚合,增删改都是命令,同样被鉴权、写审计。
2
+ // 业务 domain 包通过 export * from '@yss123/cage-admin/domain' 把它们纳入注册表。
3
+ import { scryptSync, randomBytes } from 'node:crypto';
4
+ import { aggregate, command, enumOf, fail, id, json, list, ref, scope, states, text, COMBINATORS, } from '@yss123/cage-kernel';
5
+ import { z } from 'zod';
6
+ import { noEscalation, noEscalationViaRoles, noWiderScope, knownCapability } from './constraints.js';
7
+ // ---------------- 部门 ----------------
8
+ export const Dept = aggregate('Dept', {
9
+ description: '部门',
10
+ fields: {
11
+ name: text(100),
12
+ code: text(64).optional(),
13
+ parentId: ref('Dept').optional(),
14
+ /** 祖先路径(含自己),例如 /根id/采购部id/,「本部门及下级」按前缀匹配 */
15
+ ancestors: text(4000),
16
+ /** 部门负责人(审批路由 approver.deptLeader 使用) */
17
+ leaderId: id().optional(),
18
+ },
19
+ states: states('active', 'archived', { terminal: ['archived'] }),
20
+ scope: scope.of({ dept: 'id' }),
21
+ table: { schema: 'sys', name: 'dept' },
22
+ options: { grants: 'all' },
23
+ });
24
+ export const User = aggregate('User', {
25
+ description: '用户',
26
+ fields: {
27
+ username: text(64).unique(),
28
+ name: text(100).sensitive('name'),
29
+ deptId: ref(Dept),
30
+ roleIds: list(id()),
31
+ phone: text(32).sensitive('phone').optional(),
32
+ email: text(200).sensitive('email').optional(),
33
+ /** SSO 主体标识 */
34
+ ssoSubject: text(200).optional(),
35
+ /** 密码哈希:隐藏字段,不进入读侧、审计、事件和前端契约 */
36
+ passwordHash: text(500).hidden().optional(),
37
+ },
38
+ states: states('active', 'disabled'),
39
+ scope: scope.of({ dept: 'deptId' }),
40
+ table: { schema: 'sys', name: 'user' },
41
+ options: { grants: 'self' },
42
+ });
43
+ export const Role = aggregate('Role', {
44
+ description: '角色',
45
+ fields: {
46
+ code: text(64).unique(),
47
+ name: text(100),
48
+ /** 能力点及参数,例如 { capability: 'PurchaseOrder.approve', params: { ceiling: 50000 } } */
49
+ capabilities: list({ capability: text(200), params: json().optional() }),
50
+ /** 各聚合上的数据范围;aggregate 为 * 表示所有聚合 */
51
+ scopes: list({ aggregate: text(100), combinator: enumOf(...COMBINATORS), deptIds: list(id()).optional() }),
52
+ },
53
+ states: states('active', 'archived', { terminal: ['archived'] }),
54
+ scope: scope.none(),
55
+ table: { schema: 'sys', name: 'role' },
56
+ options: { grants: 'all' },
57
+ });
58
+ // ---------------- 部门命令 ----------------
59
+ export const createDept = command(Dept, {
60
+ name: 'create',
61
+ description: '新建部门',
62
+ from: 'new',
63
+ to: 'active',
64
+ input: z.object({ name: z.string().min(1).max(100), code: z.string().max(64).optional(), parentId: z.string().uuid().nullable().optional(), leaderId: z.string().uuid().nullable().optional() }),
65
+ reads: { depts: Dept },
66
+ handler: async (o, input, { depts }) => {
67
+ const parent = input.parentId ? await depts.get(input.parentId) : null;
68
+ if (input.parentId && !parent)
69
+ return fail('PARENT_NOT_FOUND');
70
+ return { ancestors: `${parent?.ancestors ?? '/'}${o.id}/` };
71
+ },
72
+ });
73
+ export const updateDept = command(Dept, {
74
+ name: 'update',
75
+ description: '修改部门名称、编码、负责人',
76
+ from: 'active',
77
+ to: 'active',
78
+ input: z.object({ id: z.string().uuid(), name: z.string().min(1).max(100).optional(), code: z.string().max(64).nullable().optional(), leaderId: z.string().uuid().nullable().optional() }),
79
+ handler: (o, input) => ({
80
+ name: input.name ?? o.name,
81
+ code: input.code === undefined ? o.code : input.code,
82
+ leaderId: input.leaderId === undefined ? o.leaderId : input.leaderId,
83
+ }),
84
+ });
85
+ export const archiveDept = command(Dept, {
86
+ name: 'archive',
87
+ description: '停用部门(没有在职用户和下级部门时)',
88
+ from: 'active',
89
+ to: 'archived',
90
+ reads: { users: User, depts: Dept },
91
+ handler: async (o, _input, deps) => {
92
+ if ((await deps.depts.count({ parentId: o.id, status: 'active' })) > 0)
93
+ return fail('HAS_CHILDREN');
94
+ if ((await deps.users.count({ deptId: o.id, status: 'active' })) > 0)
95
+ return fail('HAS_USERS');
96
+ return {};
97
+ },
98
+ });
99
+ // ---------------- 用户 ----------------
100
+ const userInput = {
101
+ name: z.string().min(1).max(100),
102
+ deptId: z.string().uuid(),
103
+ phone: z.string().max(32).nullable().optional(),
104
+ email: z.string().email().max(200).nullable().optional(),
105
+ };
106
+ export const createUser = command(User, {
107
+ name: 'create',
108
+ description: '新建用户(默认没有任何角色)',
109
+ from: 'new',
110
+ to: 'active',
111
+ input: z.object({ username: z.string().min(2).max(64).regex(/^[A-Za-z0-9_.@-]+$/), ...userInput, ssoSubject: z.string().max(200).nullable().optional() }),
112
+ reads: { users: User, depts: Dept },
113
+ handler: async (o, input, { users, depts }) => {
114
+ if (await users.findOne({ username: input.username }))
115
+ return fail('USERNAME_TAKEN');
116
+ if (!(await depts.get(input.deptId)))
117
+ return fail('DEPT_NOT_FOUND');
118
+ return { roleIds: [] };
119
+ },
120
+ });
121
+ export const updateUser = command(User, {
122
+ name: 'update',
123
+ description: '修改用户信息',
124
+ from: 'active',
125
+ to: 'active',
126
+ input: z.object({ id: z.string().uuid(), name: userInput.name.optional(), deptId: userInput.deptId.optional(), phone: userInput.phone, email: userInput.email }),
127
+ reads: { depts: Dept },
128
+ handler: async (o, input, { depts }) => {
129
+ if (input.deptId && !(await depts.get(input.deptId)))
130
+ return fail('DEPT_NOT_FOUND');
131
+ return {
132
+ name: input.name ?? o.name,
133
+ deptId: input.deptId ?? o.deptId,
134
+ phone: input.phone === undefined ? o.phone : input.phone,
135
+ email: input.email === undefined ? o.email : input.email,
136
+ };
137
+ },
138
+ });
139
+ export const assignRoles = command(User, {
140
+ name: 'assignRoles',
141
+ description: '设置用户的角色(不能分配包含自己没有的能力的角色)',
142
+ from: 'active',
143
+ to: 'active',
144
+ input: z.object({ id: z.string().uuid(), roleIds: z.array(z.string().uuid()).max(50) }),
145
+ constraints: [noEscalationViaRoles()],
146
+ reads: { roles: Role },
147
+ handler: async (_o, input, deps) => {
148
+ for (const rid of input.roleIds) {
149
+ const r = await deps.roles.get(rid);
150
+ if (!r || r.status !== 'active')
151
+ return fail('ROLE_NOT_FOUND', { roleId: rid });
152
+ }
153
+ return { roleIds: [...new Set(input.roleIds)] };
154
+ },
155
+ });
156
+ export const disableUser = command(User, { name: 'disable', description: '停用用户', from: 'active', to: 'disabled', handler: () => ({}) });
157
+ export const enableUser = command(User, { name: 'enable', description: '启用用户', from: 'disabled', to: 'active', handler: () => ({}) });
158
+ /** 密码哈希:scrypt$盐$哈希(纯计算,不做 IO) */
159
+ export function hashPassword(pw) {
160
+ const salt = randomBytes(16).toString('hex');
161
+ return `scrypt$${salt}$${scryptSync(pw, salt, 32).toString('hex')}`;
162
+ }
163
+ export const setPassword = command(User, {
164
+ name: 'setPassword',
165
+ description: '重置密码',
166
+ from: 'active',
167
+ to: 'active',
168
+ input: z.object({ id: z.string().uuid(), password: z.string().min(8).max(200) }),
169
+ handler: (_o, input) => ({ passwordHash: hashPassword(input.password) }),
170
+ });
171
+ // ---------------- 角色命令 ----------------
172
+ export const createRole = command(Role, {
173
+ name: 'create',
174
+ description: '新建角色(默认没有任何能力)',
175
+ from: 'new',
176
+ to: 'active',
177
+ input: z.object({ code: z.string().min(1).max(64).regex(/^[a-z][a-z0-9_]*$/), name: z.string().min(1).max(100) }),
178
+ reads: { roles: Role },
179
+ handler: async (_o, input, { roles }) => {
180
+ if (await roles.findOne({ code: input.code }))
181
+ return fail('CODE_TAKEN');
182
+ return { capabilities: [], scopes: [] };
183
+ },
184
+ });
185
+ export const renameRole = command(Role, {
186
+ name: 'rename',
187
+ description: '修改角色名称',
188
+ from: 'active',
189
+ to: 'active',
190
+ input: z.object({ id: z.string().uuid(), name: z.string().min(1).max(100) }),
191
+ handler: (_o, input) => ({ name: input.name }),
192
+ });
193
+ export const grantCapability = command(Role, {
194
+ name: 'grantCapability',
195
+ description: '给角色授予能力点(不能授出自己没有的能力点)',
196
+ from: 'active',
197
+ to: 'active',
198
+ input: z.object({ id: z.string().uuid(), capability: z.string().min(1).max(200), params: z.record(z.string(), z.unknown()).optional() }),
199
+ constraints: [knownCapability(), noEscalation()],
200
+ handler: (role, input) => ({
201
+ capabilities: [
202
+ ...role.capabilities.filter((c) => c.capability !== input.capability),
203
+ { capability: input.capability, params: input.params ?? null },
204
+ ].sort((a, b) => a.capability.localeCompare(b.capability)),
205
+ }),
206
+ });
207
+ export const revokeCapability = command(Role, {
208
+ name: 'revokeCapability',
209
+ description: '收回角色的能力点',
210
+ from: 'active',
211
+ to: 'active',
212
+ input: z.object({ id: z.string().uuid(), capability: z.string().min(1).max(200) }),
213
+ handler: (role, input) => ({ capabilities: role.capabilities.filter((c) => c.capability !== input.capability) }),
214
+ });
215
+ export const setScope = command(Role, {
216
+ name: 'setScope',
217
+ description: '设置角色在某个聚合上的数据范围(不能授出比自己更宽的范围)',
218
+ from: 'active',
219
+ to: 'active',
220
+ input: z.object({
221
+ id: z.string().uuid(),
222
+ aggregate: z.string().min(1).max(100),
223
+ combinator: z.enum(['all', 'self', 'dept', 'deptSubtree', 'deptSet']).nullable(),
224
+ deptIds: z.array(z.string().uuid()).optional(),
225
+ }),
226
+ constraints: [noWiderScope()],
227
+ handler: (role, input) => {
228
+ const rest = role.scopes.filter((s) => s.aggregate !== input.aggregate);
229
+ if (input.combinator === null)
230
+ return { scopes: rest };
231
+ return {
232
+ scopes: [...rest, { aggregate: input.aggregate, combinator: input.combinator, deptIds: input.combinator === 'deptSet' ? input.deptIds ?? [] : null }]
233
+ .sort((a, b) => a.aggregate.localeCompare(b.aggregate)),
234
+ };
235
+ },
236
+ });
237
+ export const archiveRole = command(Role, { name: 'archive', description: '停用角色', from: 'active', to: 'archived', handler: () => ({}) });
238
+ //# sourceMappingURL=org.js.map