@amaster.ai/admin-sdk 0.1.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/LICENSE +21 -0
- package/dist/index.cjs +730 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +719 -0
- package/dist/index.d.ts +719 -0
- package/dist/index.js +727 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,719 @@
|
|
|
1
|
+
interface RequestOptions {
|
|
2
|
+
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
3
|
+
path: string;
|
|
4
|
+
body?: unknown;
|
|
5
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
6
|
+
}
|
|
7
|
+
type RequestFn = <T>(options: RequestOptions) => Promise<T>;
|
|
8
|
+
|
|
9
|
+
interface AdminSDKOptions {
|
|
10
|
+
/** Runtime service base URL, e.g. http://runtime:3000 */
|
|
11
|
+
baseURL: string;
|
|
12
|
+
/** Application ID, sent as x-tenant-id header */
|
|
13
|
+
appId: string;
|
|
14
|
+
/** Environment identifier, sent as x-env header. Defaults to "dev" */
|
|
15
|
+
env?: string;
|
|
16
|
+
/** Service key for bypassing user-level auth checks */
|
|
17
|
+
serviceKey?: string;
|
|
18
|
+
}
|
|
19
|
+
interface CheckPermissionParams {
|
|
20
|
+
/** Resource type, e.g. "page", "order", "report" */
|
|
21
|
+
resource: string;
|
|
22
|
+
/** Action type, e.g. "access", "read", "write", "delete" */
|
|
23
|
+
action: string;
|
|
24
|
+
/**
|
|
25
|
+
* Specific resource key/ID for fine-grained data scope validation.
|
|
26
|
+
* Required when the role's scopeType is "own", "dep", or "custom".
|
|
27
|
+
*
|
|
28
|
+
* - all: not needed
|
|
29
|
+
* - own: owner uid of the resource
|
|
30
|
+
* - dep: department id of the resource
|
|
31
|
+
* - custom: resource key matched against the role's scopeFilter whitelist
|
|
32
|
+
*/
|
|
33
|
+
resourceId?: string;
|
|
34
|
+
}
|
|
35
|
+
interface CheckPermissionResult {
|
|
36
|
+
allow: boolean;
|
|
37
|
+
reason: string;
|
|
38
|
+
scope: "all" | "dep" | "own" | "custom" | null;
|
|
39
|
+
resourceId: string | null;
|
|
40
|
+
roles: string[];
|
|
41
|
+
permissions: Array<{
|
|
42
|
+
resource: string;
|
|
43
|
+
action: string;
|
|
44
|
+
scopeType: string;
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
interface AclRules {
|
|
48
|
+
appId: string;
|
|
49
|
+
env: string;
|
|
50
|
+
user: {
|
|
51
|
+
uid: string;
|
|
52
|
+
username: string | null;
|
|
53
|
+
};
|
|
54
|
+
permissions: Array<{
|
|
55
|
+
resource: string;
|
|
56
|
+
action: string;
|
|
57
|
+
scopeType: "all" | "dep" | "own" | "custom";
|
|
58
|
+
scopeFilter?: string;
|
|
59
|
+
}>;
|
|
60
|
+
roles: string[];
|
|
61
|
+
}
|
|
62
|
+
interface UserListItem {
|
|
63
|
+
/** Numeric database ID, used for role/department assignment */
|
|
64
|
+
id: number;
|
|
65
|
+
uid: string;
|
|
66
|
+
username: string | null;
|
|
67
|
+
email: string | null;
|
|
68
|
+
phone: string | null;
|
|
69
|
+
displayName: string | null;
|
|
70
|
+
avatarUrl: string | null;
|
|
71
|
+
createdAt: string;
|
|
72
|
+
}
|
|
73
|
+
interface UserDetail extends UserListItem {
|
|
74
|
+
updatedAt: string;
|
|
75
|
+
}
|
|
76
|
+
interface UserListResult {
|
|
77
|
+
list: UserListItem[];
|
|
78
|
+
total: number;
|
|
79
|
+
page: number;
|
|
80
|
+
pageSize: number;
|
|
81
|
+
}
|
|
82
|
+
interface UserListParams {
|
|
83
|
+
page?: number;
|
|
84
|
+
pageSize?: number;
|
|
85
|
+
/** Search by username, email, phone, or displayName */
|
|
86
|
+
query?: string;
|
|
87
|
+
}
|
|
88
|
+
interface CreateUserParams {
|
|
89
|
+
username?: string;
|
|
90
|
+
email?: string;
|
|
91
|
+
phone?: string;
|
|
92
|
+
/** Minimum 8 characters */
|
|
93
|
+
password: string;
|
|
94
|
+
displayName?: string;
|
|
95
|
+
}
|
|
96
|
+
interface CreateUserResult {
|
|
97
|
+
/** Numeric database ID, used for role/department assignment */
|
|
98
|
+
id: number;
|
|
99
|
+
uid: string;
|
|
100
|
+
username: string | null;
|
|
101
|
+
email: string | null;
|
|
102
|
+
displayName: string | null;
|
|
103
|
+
createdAt: string;
|
|
104
|
+
}
|
|
105
|
+
interface UpdateUserParams {
|
|
106
|
+
username?: string;
|
|
107
|
+
displayName?: string;
|
|
108
|
+
email?: string;
|
|
109
|
+
phone?: string;
|
|
110
|
+
avatarUrl?: string;
|
|
111
|
+
/** Reset password */
|
|
112
|
+
password?: string;
|
|
113
|
+
isSuperAdmin?: boolean;
|
|
114
|
+
}
|
|
115
|
+
interface UpdateUserResult {
|
|
116
|
+
uid: string;
|
|
117
|
+
displayName: string | null;
|
|
118
|
+
updatedAt: string;
|
|
119
|
+
}
|
|
120
|
+
interface Role {
|
|
121
|
+
id: number;
|
|
122
|
+
code: string;
|
|
123
|
+
displayName: string;
|
|
124
|
+
description: string;
|
|
125
|
+
isSystem: boolean;
|
|
126
|
+
createdAt: string;
|
|
127
|
+
}
|
|
128
|
+
interface CreateRoleParams {
|
|
129
|
+
code: string;
|
|
130
|
+
displayName?: string;
|
|
131
|
+
description?: string;
|
|
132
|
+
}
|
|
133
|
+
interface UpdateRoleParams {
|
|
134
|
+
code?: string;
|
|
135
|
+
displayName?: string;
|
|
136
|
+
description?: string;
|
|
137
|
+
}
|
|
138
|
+
type AssigneeType = "user" | "team" | "department" | "role";
|
|
139
|
+
interface RoleAssignParams {
|
|
140
|
+
assigneeType: AssigneeType;
|
|
141
|
+
/** Use assigneeUid for user type (preferred). assigneeId for department/role/team. */
|
|
142
|
+
assigneeUid?: string;
|
|
143
|
+
assigneeId?: number;
|
|
144
|
+
}
|
|
145
|
+
interface RoleAssignee {
|
|
146
|
+
id: number;
|
|
147
|
+
roleId: number;
|
|
148
|
+
assigneeType: AssigneeType;
|
|
149
|
+
assigneeId: number;
|
|
150
|
+
createdAt: string;
|
|
151
|
+
user?: {
|
|
152
|
+
id: number;
|
|
153
|
+
username: string | null;
|
|
154
|
+
displayName: string | null;
|
|
155
|
+
email: string | null;
|
|
156
|
+
};
|
|
157
|
+
department?: {
|
|
158
|
+
id: number;
|
|
159
|
+
name: string;
|
|
160
|
+
parentId: number | null;
|
|
161
|
+
};
|
|
162
|
+
assigneeRole?: {
|
|
163
|
+
id: number;
|
|
164
|
+
code: string;
|
|
165
|
+
displayName: string;
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
interface Permission {
|
|
169
|
+
id: number;
|
|
170
|
+
name: string;
|
|
171
|
+
resource: string;
|
|
172
|
+
action: string;
|
|
173
|
+
description: string;
|
|
174
|
+
sourceType: string;
|
|
175
|
+
createdAt: string;
|
|
176
|
+
}
|
|
177
|
+
interface CreatePermissionParams {
|
|
178
|
+
resource: string;
|
|
179
|
+
action: string;
|
|
180
|
+
name?: string;
|
|
181
|
+
description?: string;
|
|
182
|
+
}
|
|
183
|
+
interface UpdatePermissionParams {
|
|
184
|
+
resource?: string;
|
|
185
|
+
action?: string;
|
|
186
|
+
name?: string;
|
|
187
|
+
description?: string;
|
|
188
|
+
}
|
|
189
|
+
type ScopeType = "all" | "self" | "department" | "custom";
|
|
190
|
+
interface RolePermission {
|
|
191
|
+
id: number;
|
|
192
|
+
roleId: number;
|
|
193
|
+
permissionId: number;
|
|
194
|
+
scopeType: ScopeType;
|
|
195
|
+
scopeFilter?: string;
|
|
196
|
+
permission: {
|
|
197
|
+
resource: string;
|
|
198
|
+
action: string;
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
interface AssignPermissionToRoleParams {
|
|
202
|
+
permissionId: number;
|
|
203
|
+
/** Data scope type. Defaults to "all" */
|
|
204
|
+
scopeType?: ScopeType;
|
|
205
|
+
/** Custom filter condition (JSON string), used when scopeType is "custom" */
|
|
206
|
+
scopeFilter?: string;
|
|
207
|
+
}
|
|
208
|
+
interface UpdatePermissionScopeParams {
|
|
209
|
+
scopeType: ScopeType;
|
|
210
|
+
scopeFilter?: string;
|
|
211
|
+
}
|
|
212
|
+
interface AssignPermissionToUserParams {
|
|
213
|
+
permissionId: number;
|
|
214
|
+
/** Data scope type. Defaults to "all" */
|
|
215
|
+
scopeType?: ScopeType;
|
|
216
|
+
/** Custom filter condition (JSON string), used when scopeType is "custom" */
|
|
217
|
+
scopeFilter?: string;
|
|
218
|
+
}
|
|
219
|
+
interface UserPermissionException {
|
|
220
|
+
id: number;
|
|
221
|
+
userId: number;
|
|
222
|
+
permissionId: number;
|
|
223
|
+
scopeType: ScopeType;
|
|
224
|
+
scopeFilter?: string;
|
|
225
|
+
permission: {
|
|
226
|
+
resource: string;
|
|
227
|
+
action: string;
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
interface Department {
|
|
231
|
+
id: number;
|
|
232
|
+
code: string;
|
|
233
|
+
name: string;
|
|
234
|
+
parentId: number | null;
|
|
235
|
+
path: string | null;
|
|
236
|
+
level: number;
|
|
237
|
+
managerId: number | null;
|
|
238
|
+
createdAt: string;
|
|
239
|
+
}
|
|
240
|
+
interface CreateDepartmentParams {
|
|
241
|
+
name: string;
|
|
242
|
+
parentId?: number;
|
|
243
|
+
/** Department manager's numeric user ID */
|
|
244
|
+
managerId?: number;
|
|
245
|
+
}
|
|
246
|
+
interface UpdateDepartmentParams {
|
|
247
|
+
name?: string;
|
|
248
|
+
parentId?: number;
|
|
249
|
+
managerId?: number;
|
|
250
|
+
}
|
|
251
|
+
interface DepartmentMember {
|
|
252
|
+
id: number;
|
|
253
|
+
userId: number;
|
|
254
|
+
departmentId: number;
|
|
255
|
+
isPrimary: boolean;
|
|
256
|
+
position: string | null;
|
|
257
|
+
user: {
|
|
258
|
+
id: number;
|
|
259
|
+
username: string | null;
|
|
260
|
+
displayName: string | null;
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
interface AddDepartmentMemberParams {
|
|
264
|
+
/** User UID (UUID string) */
|
|
265
|
+
userUid: string;
|
|
266
|
+
position?: string;
|
|
267
|
+
isPrimary?: boolean;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
declare function createAuthModule(request: RequestFn): {
|
|
271
|
+
/**
|
|
272
|
+
* Check whether a user has a specific permission.
|
|
273
|
+
*
|
|
274
|
+
* Uses the Service Key to query on behalf of any user by UID —
|
|
275
|
+
* no user token required.
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```typescript
|
|
279
|
+
* // Check if user can access the dashboard page
|
|
280
|
+
* const result = await admin.auth.checkPermission('u-123456', {
|
|
281
|
+
* resource: 'page',
|
|
282
|
+
* action: 'access',
|
|
283
|
+
* resourceId: 'dashboard',
|
|
284
|
+
* });
|
|
285
|
+
* if (!result.allow) throw new Error('Forbidden');
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
checkPermission(uid: string, params: CheckPermissionParams): Promise<CheckPermissionResult>;
|
|
289
|
+
/**
|
|
290
|
+
* Get all ACL rules for a user.
|
|
291
|
+
*
|
|
292
|
+
* Returns the full set of permissions and roles. Useful when you need
|
|
293
|
+
* to perform multiple permission checks locally without making repeated
|
|
294
|
+
* network calls.
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* ```typescript
|
|
298
|
+
* const rules = await admin.auth.getRules('u-123456');
|
|
299
|
+
*
|
|
300
|
+
* // Check roles
|
|
301
|
+
* if (rules.roles.includes('admin')) { ... }
|
|
302
|
+
*
|
|
303
|
+
* // Check multiple permissions locally
|
|
304
|
+
* const canRead = rules.permissions.some(
|
|
305
|
+
* p => p.resource === 'order' && p.action === 'read'
|
|
306
|
+
* );
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
getRules(uid: string): Promise<AclRules>;
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
declare function createDepartmentsModule(request: RequestFn): {
|
|
313
|
+
/**
|
|
314
|
+
* List all departments (flat list).
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```typescript
|
|
318
|
+
* const depts = await admin.departments.list();
|
|
319
|
+
* const techDept = depts.find(d => d.name === '技术部');
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
list(): Promise<Department[]>;
|
|
323
|
+
/**
|
|
324
|
+
* Get a single department by ID.
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```typescript
|
|
328
|
+
* const dept = await admin.departments.get(1);
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
get(id: number): Promise<Department>;
|
|
332
|
+
/**
|
|
333
|
+
* Create a new department.
|
|
334
|
+
*
|
|
335
|
+
* @example
|
|
336
|
+
* ```typescript
|
|
337
|
+
* const dept = await admin.departments.create({
|
|
338
|
+
* name: '测试组',
|
|
339
|
+
* parentId: 1,
|
|
340
|
+
* });
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
create(params: CreateDepartmentParams): Promise<Department>;
|
|
344
|
+
/**
|
|
345
|
+
* Update a department.
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* ```typescript
|
|
349
|
+
* await admin.departments.update(3, { name: '质量保证组' });
|
|
350
|
+
* ```
|
|
351
|
+
*/
|
|
352
|
+
update(id: number, params: UpdateDepartmentParams): Promise<void>;
|
|
353
|
+
/**
|
|
354
|
+
* Delete a department.
|
|
355
|
+
* Note: departments with sub-departments or assigned users cannot be deleted directly.
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* ```typescript
|
|
359
|
+
* await admin.departments.delete(3);
|
|
360
|
+
* ```
|
|
361
|
+
*/
|
|
362
|
+
delete(id: number): Promise<void>;
|
|
363
|
+
/**
|
|
364
|
+
* List members of a department.
|
|
365
|
+
*
|
|
366
|
+
* @param includeChildren - Whether to include members from sub-departments. Defaults to false.
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```typescript
|
|
370
|
+
* const members = await admin.departments.listUsers(1);
|
|
371
|
+
* const allMembers = await admin.departments.listUsers(1, true);
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
listUsers(id: number, includeChildren?: boolean): Promise<DepartmentMember[]>;
|
|
375
|
+
/**
|
|
376
|
+
* Add a user to a department.
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* ```typescript
|
|
380
|
+
* await admin.departments.addUser(1, {
|
|
381
|
+
* userId: 123,
|
|
382
|
+
* isPrimary: true,
|
|
383
|
+
* position: '高级工程师',
|
|
384
|
+
* });
|
|
385
|
+
* ```
|
|
386
|
+
*/
|
|
387
|
+
addUser(deptId: number, params: AddDepartmentMemberParams): Promise<void>;
|
|
388
|
+
/**
|
|
389
|
+
* Remove a user from a department.
|
|
390
|
+
*
|
|
391
|
+
* @example
|
|
392
|
+
* ```typescript
|
|
393
|
+
* await admin.departments.removeUser(1, 123);
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
removeUser(deptId: number, userUid: string): Promise<void>;
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
declare function createPermissionsModule(request: RequestFn): {
|
|
400
|
+
/**
|
|
401
|
+
* List all defined permissions.
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* ```typescript
|
|
405
|
+
* const perms = await admin.permissions.list();
|
|
406
|
+
* const orderRead = perms.find(p => p.resource === 'order' && p.action === 'read');
|
|
407
|
+
* ```
|
|
408
|
+
*/
|
|
409
|
+
list(): Promise<Permission[]>;
|
|
410
|
+
/**
|
|
411
|
+
* Create a new permission definition.
|
|
412
|
+
*
|
|
413
|
+
* @example
|
|
414
|
+
* ```typescript
|
|
415
|
+
* const perm = await admin.permissions.create({
|
|
416
|
+
* resource: 'order',
|
|
417
|
+
* action: 'export',
|
|
418
|
+
* name: '导出订单',
|
|
419
|
+
* });
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
create(params: CreatePermissionParams): Promise<Permission>;
|
|
423
|
+
/**
|
|
424
|
+
* Update a permission definition.
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* ```typescript
|
|
428
|
+
* await admin.permissions.update(10, { name: '导出报表' });
|
|
429
|
+
* ```
|
|
430
|
+
*/
|
|
431
|
+
update(id: number, params: UpdatePermissionParams): Promise<void>;
|
|
432
|
+
/**
|
|
433
|
+
* Delete a permission definition.
|
|
434
|
+
*
|
|
435
|
+
* @example
|
|
436
|
+
* ```typescript
|
|
437
|
+
* await admin.permissions.delete(10);
|
|
438
|
+
* ```
|
|
439
|
+
*/
|
|
440
|
+
delete(id: number): Promise<void>;
|
|
441
|
+
/**
|
|
442
|
+
* List all permissions assigned to a role.
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
* ```typescript
|
|
446
|
+
* const perms = await admin.permissions.listForRole(roleId);
|
|
447
|
+
* ```
|
|
448
|
+
*/
|
|
449
|
+
listForRole(roleId: number): Promise<RolePermission[]>;
|
|
450
|
+
/**
|
|
451
|
+
* Assign a permission to a role with a data scope.
|
|
452
|
+
*
|
|
453
|
+
* @example
|
|
454
|
+
* ```typescript
|
|
455
|
+
* // Department-scoped permission
|
|
456
|
+
* await admin.permissions.assignToRole(roleId, {
|
|
457
|
+
* permissionId: 10,
|
|
458
|
+
* scopeType: 'department',
|
|
459
|
+
* });
|
|
460
|
+
*
|
|
461
|
+
* // Custom whitelist scope
|
|
462
|
+
* await admin.permissions.assignToRole(roleId, {
|
|
463
|
+
* permissionId: 20,
|
|
464
|
+
* scopeType: 'custom',
|
|
465
|
+
* scopeFilter: JSON.stringify({ id: [1, 2, 3] }),
|
|
466
|
+
* });
|
|
467
|
+
* ```
|
|
468
|
+
*/
|
|
469
|
+
assignToRole(roleId: number, params: AssignPermissionToRoleParams): Promise<void>;
|
|
470
|
+
/**
|
|
471
|
+
* Remove a permission from a role.
|
|
472
|
+
*
|
|
473
|
+
* @example
|
|
474
|
+
* ```typescript
|
|
475
|
+
* await admin.permissions.removeFromRole(roleId, permId);
|
|
476
|
+
* ```
|
|
477
|
+
*/
|
|
478
|
+
removeFromRole(roleId: number, permId: number): Promise<void>;
|
|
479
|
+
/**
|
|
480
|
+
* Update the data scope of a role–permission assignment.
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* ```typescript
|
|
484
|
+
* await admin.permissions.updateRolePermissionScope(roleId, permId, {
|
|
485
|
+
* scopeType: 'all',
|
|
486
|
+
* });
|
|
487
|
+
* ```
|
|
488
|
+
*/
|
|
489
|
+
updateRolePermissionScope(roleId: number, permId: number, params: UpdatePermissionScopeParams): Promise<void>;
|
|
490
|
+
/**
|
|
491
|
+
* Assign a direct (user-level) permission exception to a user.
|
|
492
|
+
*
|
|
493
|
+
* This bypasses role-based assignment and gives the user a direct
|
|
494
|
+
* data-scope override for the specified permission.
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* ```typescript
|
|
498
|
+
* await admin.permissions.assignToUser('u-123456', {
|
|
499
|
+
* permissionId: 10,
|
|
500
|
+
* scopeType: 'department',
|
|
501
|
+
* });
|
|
502
|
+
* ```
|
|
503
|
+
*/
|
|
504
|
+
assignToUser(uid: string, params: AssignPermissionToUserParams): Promise<void>;
|
|
505
|
+
/**
|
|
506
|
+
* Remove a direct permission exception from a user.
|
|
507
|
+
*
|
|
508
|
+
* @example
|
|
509
|
+
* ```typescript
|
|
510
|
+
* await admin.permissions.removeFromUser('u-123456', permId);
|
|
511
|
+
* ```
|
|
512
|
+
*/
|
|
513
|
+
removeFromUser(uid: string, permId: number): Promise<void>;
|
|
514
|
+
/**
|
|
515
|
+
* List permission exceptions for a specific user.
|
|
516
|
+
*
|
|
517
|
+
* @example
|
|
518
|
+
* ```typescript
|
|
519
|
+
* const exceptions = await admin.permissions.listForUser('u-123456');
|
|
520
|
+
* ```
|
|
521
|
+
*/
|
|
522
|
+
listForUser(uid: string): Promise<UserPermissionException[]>;
|
|
523
|
+
/**
|
|
524
|
+
* Update the data scope of a user-level permission exception.
|
|
525
|
+
*
|
|
526
|
+
* @example
|
|
527
|
+
* ```typescript
|
|
528
|
+
* await admin.permissions.updateUserPermissionScope('u-123456', permId, {
|
|
529
|
+
* scopeType: 'custom',
|
|
530
|
+
* scopeFilter: JSON.stringify({ id: [10, 20] }),
|
|
531
|
+
* });
|
|
532
|
+
* ```
|
|
533
|
+
*/
|
|
534
|
+
updateUserPermissionScope(uid: string, permId: number, params: UpdatePermissionScopeParams): Promise<void>;
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
declare function createRolesModule(request: RequestFn): {
|
|
538
|
+
/**
|
|
539
|
+
* List all roles.
|
|
540
|
+
*
|
|
541
|
+
* @example
|
|
542
|
+
* ```typescript
|
|
543
|
+
* const roles = await admin.roles.list();
|
|
544
|
+
* const managerRole = roles.find(r => r.code === 'manager');
|
|
545
|
+
* ```
|
|
546
|
+
*/
|
|
547
|
+
list(): Promise<Role[]>;
|
|
548
|
+
/**
|
|
549
|
+
* Get a role by its numeric ID.
|
|
550
|
+
*
|
|
551
|
+
* @example
|
|
552
|
+
* ```typescript
|
|
553
|
+
* const role = await admin.roles.get(1);
|
|
554
|
+
* ```
|
|
555
|
+
*/
|
|
556
|
+
get(id: number): Promise<Role>;
|
|
557
|
+
/**
|
|
558
|
+
* Create a new role.
|
|
559
|
+
*
|
|
560
|
+
* @example
|
|
561
|
+
* ```typescript
|
|
562
|
+
* const role = await admin.roles.create({
|
|
563
|
+
* code: 'editor',
|
|
564
|
+
* displayName: '编辑',
|
|
565
|
+
* description: '负责内容编辑',
|
|
566
|
+
* });
|
|
567
|
+
* ```
|
|
568
|
+
*/
|
|
569
|
+
create(params: CreateRoleParams): Promise<Role>;
|
|
570
|
+
/**
|
|
571
|
+
* Update a role.
|
|
572
|
+
* Note: system roles (isSystem=true) cannot be modified.
|
|
573
|
+
*
|
|
574
|
+
* @example
|
|
575
|
+
* ```typescript
|
|
576
|
+
* await admin.roles.update(3, { displayName: '高级编辑' });
|
|
577
|
+
* ```
|
|
578
|
+
*/
|
|
579
|
+
update(id: number, params: UpdateRoleParams): Promise<void>;
|
|
580
|
+
/**
|
|
581
|
+
* Delete a role.
|
|
582
|
+
* Note: system roles cannot be deleted.
|
|
583
|
+
*
|
|
584
|
+
* @example
|
|
585
|
+
* ```typescript
|
|
586
|
+
* await admin.roles.delete(3);
|
|
587
|
+
* ```
|
|
588
|
+
*/
|
|
589
|
+
delete(id: number): Promise<void>;
|
|
590
|
+
/**
|
|
591
|
+
* Assign a role to a user, department, team, or another role.
|
|
592
|
+
*
|
|
593
|
+
* @example
|
|
594
|
+
* ```typescript
|
|
595
|
+
* // Assign to a user
|
|
596
|
+
* await admin.roles.assign(roleId, { assigneeType: 'user', assigneeId: 123 });
|
|
597
|
+
*
|
|
598
|
+
* // Assign to an entire department
|
|
599
|
+
* await admin.roles.assign(roleId, { assigneeType: 'department', assigneeId: 5 });
|
|
600
|
+
* ```
|
|
601
|
+
*/
|
|
602
|
+
assign(roleId: number, params: RoleAssignParams): Promise<void>;
|
|
603
|
+
/**
|
|
604
|
+
* Remove a role assignment.
|
|
605
|
+
*
|
|
606
|
+
* @example
|
|
607
|
+
* ```typescript
|
|
608
|
+
* await admin.roles.unassign(roleId, { assigneeType: 'user', assigneeId: 123 });
|
|
609
|
+
* ```
|
|
610
|
+
*/
|
|
611
|
+
unassign(roleId: number, params: RoleAssignParams): Promise<void>;
|
|
612
|
+
/**
|
|
613
|
+
* List all assignees (users, departments, etc.) for a role.
|
|
614
|
+
*
|
|
615
|
+
* @example
|
|
616
|
+
* ```typescript
|
|
617
|
+
* const assignees = await admin.roles.listAssignees(roleId);
|
|
618
|
+
* const users = assignees.filter(a => a.assigneeType === 'user');
|
|
619
|
+
* ```
|
|
620
|
+
*/
|
|
621
|
+
listAssignees(roleId: number): Promise<RoleAssignee[]>;
|
|
622
|
+
/**
|
|
623
|
+
* Get all roles assigned to a user (by UID).
|
|
624
|
+
*
|
|
625
|
+
* Useful in Edge Functions to check what roles a user currently holds
|
|
626
|
+
* without making a full ACL check.
|
|
627
|
+
*
|
|
628
|
+
* @example
|
|
629
|
+
* ```typescript
|
|
630
|
+
* const roles = await admin.roles.getUserRoles('u-123456');
|
|
631
|
+
* if (roles.some(r => r.code === 'admin')) { ... }
|
|
632
|
+
* ```
|
|
633
|
+
*/
|
|
634
|
+
getUserRoles(uid: string): Promise<Role[]>;
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
declare function createUsersModule(request: RequestFn): {
|
|
638
|
+
/**
|
|
639
|
+
* List users with optional search and pagination.
|
|
640
|
+
*
|
|
641
|
+
* @example
|
|
642
|
+
* ```typescript
|
|
643
|
+
* const result = await admin.users.list({ query: 'zhang', pageSize: 50 });
|
|
644
|
+
* console.log(`Total: ${result.total}`);
|
|
645
|
+
* for (const user of result.list) {
|
|
646
|
+
* console.log(user.email);
|
|
647
|
+
* }
|
|
648
|
+
* ```
|
|
649
|
+
*/
|
|
650
|
+
list(params?: UserListParams): Promise<UserListResult>;
|
|
651
|
+
/**
|
|
652
|
+
* Get a single user by UID.
|
|
653
|
+
*
|
|
654
|
+
* @example
|
|
655
|
+
* ```typescript
|
|
656
|
+
* const user = await admin.users.get('u-123456');
|
|
657
|
+
* console.log(user.email);
|
|
658
|
+
* ```
|
|
659
|
+
*/
|
|
660
|
+
get(uid: string): Promise<UserDetail>;
|
|
661
|
+
/**
|
|
662
|
+
* Create a new user.
|
|
663
|
+
* At least one of username / email / phone must be provided.
|
|
664
|
+
*
|
|
665
|
+
* @example
|
|
666
|
+
* ```typescript
|
|
667
|
+
* const user = await admin.users.create({
|
|
668
|
+
* email: 'user@example.com',
|
|
669
|
+
* password: 'Secure@123',
|
|
670
|
+
* displayName: '张三',
|
|
671
|
+
* });
|
|
672
|
+
* ```
|
|
673
|
+
*/
|
|
674
|
+
create(params: CreateUserParams): Promise<CreateUserResult>;
|
|
675
|
+
/**
|
|
676
|
+
* Update an existing user.
|
|
677
|
+
*
|
|
678
|
+
* @example
|
|
679
|
+
* ```typescript
|
|
680
|
+
* // Reset password
|
|
681
|
+
* await admin.users.update('u-123456', { password: 'NewSecure@456' });
|
|
682
|
+
*
|
|
683
|
+
* // Grant super admin
|
|
684
|
+
* await admin.users.update('u-123456', { isSuperAdmin: true });
|
|
685
|
+
* ```
|
|
686
|
+
*/
|
|
687
|
+
update(uid: string, params: UpdateUserParams): Promise<UpdateUserResult>;
|
|
688
|
+
/**
|
|
689
|
+
* Delete a user.
|
|
690
|
+
*
|
|
691
|
+
* @example
|
|
692
|
+
* ```typescript
|
|
693
|
+
* await admin.users.delete('u-123456');
|
|
694
|
+
* ```
|
|
695
|
+
*/
|
|
696
|
+
delete(uid: string): Promise<void>;
|
|
697
|
+
};
|
|
698
|
+
|
|
699
|
+
declare class AdminSDK {
|
|
700
|
+
/** Check and query user permissions without requiring a user token */
|
|
701
|
+
readonly auth: ReturnType<typeof createAuthModule>;
|
|
702
|
+
/** User CRUD operations */
|
|
703
|
+
readonly users: ReturnType<typeof createUsersModule>;
|
|
704
|
+
/** Role management and assignment */
|
|
705
|
+
readonly roles: ReturnType<typeof createRolesModule>;
|
|
706
|
+
/** Permission definitions and role/user permission scopes */
|
|
707
|
+
readonly permissions: ReturnType<typeof createPermissionsModule>;
|
|
708
|
+
/** Department management and membership */
|
|
709
|
+
readonly departments: ReturnType<typeof createDepartmentsModule>;
|
|
710
|
+
constructor(options: AdminSDKOptions);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
declare class AdminSDKError extends Error {
|
|
714
|
+
readonly statusCode: number;
|
|
715
|
+
readonly response?: unknown | undefined;
|
|
716
|
+
constructor(message: string, statusCode: number, response?: unknown | undefined);
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
export { type AclRules, type AddDepartmentMemberParams, AdminSDK, AdminSDKError, type AdminSDKOptions, type AssignPermissionToRoleParams, type AssigneeType, type CheckPermissionParams, type CheckPermissionResult, type CreateDepartmentParams, type CreatePermissionParams, type CreateRoleParams, type CreateUserParams, type CreateUserResult, type Department, type DepartmentMember, type Permission, type Role, type RoleAssignParams, type RoleAssignee, type RolePermission, type ScopeType, type UpdateDepartmentParams, type UpdatePermissionParams, type UpdatePermissionScopeParams, type UpdateRoleParams, type UpdateUserParams, type UpdateUserResult, type UserDetail, type UserListItem, type UserListParams, type UserListResult, type UserPermissionException };
|