@abpjs/identity 0.7.6
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 +165 -0
- package/README.md +533 -0
- package/dist/index.d.mts +463 -0
- package/dist/index.d.ts +463 -0
- package/dist/index.js +1161 -0
- package/dist/index.mjs +1146 -0
- package/package.json +85 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
import { ABP, RestService } from '@abpjs/core';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Identity namespace containing all types related to identity management.
|
|
6
|
+
* Translated from @abp/ng.identity Identity namespace.
|
|
7
|
+
*/
|
|
8
|
+
declare namespace Identity {
|
|
9
|
+
/**
|
|
10
|
+
* Identity state shape for state management
|
|
11
|
+
*/
|
|
12
|
+
interface State {
|
|
13
|
+
roles: RoleResponse;
|
|
14
|
+
users: UserResponse;
|
|
15
|
+
selectedRole: RoleItem;
|
|
16
|
+
selectedUser: UserItem;
|
|
17
|
+
selectedUserRoles: RoleItem[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Paginated response for roles
|
|
21
|
+
*/
|
|
22
|
+
type RoleResponse = ABP.PagedResponse<RoleItem>;
|
|
23
|
+
/**
|
|
24
|
+
* Request payload for creating/updating a role
|
|
25
|
+
*/
|
|
26
|
+
interface RoleSaveRequest {
|
|
27
|
+
name: string;
|
|
28
|
+
isDefault: boolean;
|
|
29
|
+
isPublic: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Role item returned from the API
|
|
33
|
+
*/
|
|
34
|
+
interface RoleItem extends RoleSaveRequest {
|
|
35
|
+
isStatic: boolean;
|
|
36
|
+
concurrencyStamp: string;
|
|
37
|
+
id: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Paginated response for users
|
|
41
|
+
*/
|
|
42
|
+
type UserResponse = ABP.PagedResponse<UserItem>;
|
|
43
|
+
/**
|
|
44
|
+
* Base user properties
|
|
45
|
+
*/
|
|
46
|
+
interface User {
|
|
47
|
+
userName: string;
|
|
48
|
+
name: string;
|
|
49
|
+
surname: string;
|
|
50
|
+
email: string;
|
|
51
|
+
phoneNumber: string;
|
|
52
|
+
twoFactorEnabled: boolean;
|
|
53
|
+
lockoutEnabled: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* User item returned from the API
|
|
57
|
+
*/
|
|
58
|
+
interface UserItem extends User {
|
|
59
|
+
tenantId: string;
|
|
60
|
+
emailConfirmed: boolean;
|
|
61
|
+
phoneNumberConfirmed: boolean;
|
|
62
|
+
isLockedOut: boolean;
|
|
63
|
+
concurrencyStamp: string;
|
|
64
|
+
id: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Request payload for creating/updating a user
|
|
68
|
+
*/
|
|
69
|
+
interface UserSaveRequest extends User {
|
|
70
|
+
password: string;
|
|
71
|
+
roleNames: string[];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Service for managing identity-related API operations.
|
|
77
|
+
* Handles roles and users CRUD operations.
|
|
78
|
+
*
|
|
79
|
+
* Translated from @abp/ng.identity IdentityService
|
|
80
|
+
*/
|
|
81
|
+
declare class IdentityService {
|
|
82
|
+
private rest;
|
|
83
|
+
constructor(rest: RestService);
|
|
84
|
+
/**
|
|
85
|
+
* Get all roles
|
|
86
|
+
* @returns Promise with paginated role response
|
|
87
|
+
*/
|
|
88
|
+
getRoles(): Promise<Identity.RoleResponse>;
|
|
89
|
+
/**
|
|
90
|
+
* Get a role by ID
|
|
91
|
+
* @param id - The role ID
|
|
92
|
+
* @returns Promise with the role item
|
|
93
|
+
*/
|
|
94
|
+
getRoleById(id: string): Promise<Identity.RoleItem>;
|
|
95
|
+
/**
|
|
96
|
+
* Delete a role
|
|
97
|
+
* @param id - The role ID to delete
|
|
98
|
+
* @returns Promise with the deleted role
|
|
99
|
+
*/
|
|
100
|
+
deleteRole(id: string): Promise<Identity.RoleItem>;
|
|
101
|
+
/**
|
|
102
|
+
* Create a new role
|
|
103
|
+
* @param body - The role data to create
|
|
104
|
+
* @returns Promise with the created role
|
|
105
|
+
*/
|
|
106
|
+
createRole(body: Identity.RoleSaveRequest): Promise<Identity.RoleItem>;
|
|
107
|
+
/**
|
|
108
|
+
* Update an existing role
|
|
109
|
+
* @param id - The role ID to update
|
|
110
|
+
* @param body - The updated role data
|
|
111
|
+
* @returns Promise with the updated role
|
|
112
|
+
*/
|
|
113
|
+
updateRole(id: string, body: Identity.RoleSaveRequest): Promise<Identity.RoleItem>;
|
|
114
|
+
/**
|
|
115
|
+
* Get users with pagination and filtering
|
|
116
|
+
* @param params - Query parameters for pagination and filtering
|
|
117
|
+
* @returns Promise with paginated user response
|
|
118
|
+
*/
|
|
119
|
+
getUsers(params?: ABP.PageQueryParams): Promise<Identity.UserResponse>;
|
|
120
|
+
/**
|
|
121
|
+
* Get a user by ID
|
|
122
|
+
* @param id - The user ID
|
|
123
|
+
* @returns Promise with the user item
|
|
124
|
+
*/
|
|
125
|
+
getUserById(id: string): Promise<Identity.UserItem>;
|
|
126
|
+
/**
|
|
127
|
+
* Get roles assigned to a user
|
|
128
|
+
* @param id - The user ID
|
|
129
|
+
* @returns Promise with the user's roles
|
|
130
|
+
*/
|
|
131
|
+
getUserRoles(id: string): Promise<Identity.RoleResponse>;
|
|
132
|
+
/**
|
|
133
|
+
* Delete a user
|
|
134
|
+
* @param id - The user ID to delete
|
|
135
|
+
* @returns Promise resolving when complete
|
|
136
|
+
*/
|
|
137
|
+
deleteUser(id: string): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Create a new user
|
|
140
|
+
* @param body - The user data to create
|
|
141
|
+
* @returns Promise with the created user
|
|
142
|
+
*/
|
|
143
|
+
createUser(body: Identity.UserSaveRequest): Promise<Identity.UserItem>;
|
|
144
|
+
/**
|
|
145
|
+
* Update an existing user
|
|
146
|
+
* @param id - The user ID to update
|
|
147
|
+
* @param body - The updated user data
|
|
148
|
+
* @returns Promise with the updated user
|
|
149
|
+
*/
|
|
150
|
+
updateUser(id: string, body: Identity.UserSaveRequest): Promise<Identity.UserItem>;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Result from role operations
|
|
155
|
+
*/
|
|
156
|
+
interface RoleOperationResult {
|
|
157
|
+
success: boolean;
|
|
158
|
+
error?: string;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Return type for useRoles hook
|
|
162
|
+
*/
|
|
163
|
+
interface UseRolesReturn {
|
|
164
|
+
/** List of roles */
|
|
165
|
+
roles: Identity.RoleItem[];
|
|
166
|
+
/** Total count of roles */
|
|
167
|
+
totalCount: number;
|
|
168
|
+
/** Currently selected role for editing */
|
|
169
|
+
selectedRole: Identity.RoleItem | null;
|
|
170
|
+
/** Loading state */
|
|
171
|
+
isLoading: boolean;
|
|
172
|
+
/** Error message if any */
|
|
173
|
+
error: string | null;
|
|
174
|
+
/** Fetch all roles */
|
|
175
|
+
fetchRoles: () => Promise<RoleOperationResult>;
|
|
176
|
+
/** Get a role by ID and set it as selected */
|
|
177
|
+
getRoleById: (id: string) => Promise<RoleOperationResult>;
|
|
178
|
+
/** Create a new role */
|
|
179
|
+
createRole: (role: Identity.RoleSaveRequest) => Promise<RoleOperationResult>;
|
|
180
|
+
/** Update an existing role */
|
|
181
|
+
updateRole: (id: string, role: Identity.RoleSaveRequest) => Promise<RoleOperationResult>;
|
|
182
|
+
/** Delete a role */
|
|
183
|
+
deleteRole: (id: string) => Promise<RoleOperationResult>;
|
|
184
|
+
/** Set the selected role */
|
|
185
|
+
setSelectedRole: (role: Identity.RoleItem | null) => void;
|
|
186
|
+
/** Reset state */
|
|
187
|
+
reset: () => void;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Hook for managing roles
|
|
191
|
+
*
|
|
192
|
+
* This hook provides all the state and actions needed for role management.
|
|
193
|
+
* It handles fetching, creating, updating, and deleting roles.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```tsx
|
|
197
|
+
* function RolesPage() {
|
|
198
|
+
* const {
|
|
199
|
+
* roles,
|
|
200
|
+
* isLoading,
|
|
201
|
+
* fetchRoles,
|
|
202
|
+
* createRole,
|
|
203
|
+
* deleteRole,
|
|
204
|
+
* } = useRoles();
|
|
205
|
+
*
|
|
206
|
+
* useEffect(() => {
|
|
207
|
+
* fetchRoles();
|
|
208
|
+
* }, [fetchRoles]);
|
|
209
|
+
*
|
|
210
|
+
* const handleCreate = async (data: Identity.RoleSaveRequest) => {
|
|
211
|
+
* const result = await createRole(data);
|
|
212
|
+
* if (result.success) {
|
|
213
|
+
* // Handle success
|
|
214
|
+
* }
|
|
215
|
+
* };
|
|
216
|
+
*
|
|
217
|
+
* return (
|
|
218
|
+
* <div>
|
|
219
|
+
* {roles.map(role => (
|
|
220
|
+
* <div key={role.id}>{role.name}</div>
|
|
221
|
+
* ))}
|
|
222
|
+
* </div>
|
|
223
|
+
* );
|
|
224
|
+
* }
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
declare function useRoles(): UseRolesReturn;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Result from user operations
|
|
231
|
+
*/
|
|
232
|
+
interface UserOperationResult {
|
|
233
|
+
success: boolean;
|
|
234
|
+
error?: string;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Return type for useUsers hook
|
|
238
|
+
*/
|
|
239
|
+
interface UseUsersReturn {
|
|
240
|
+
/** List of users */
|
|
241
|
+
users: Identity.UserItem[];
|
|
242
|
+
/** Total count of users */
|
|
243
|
+
totalCount: number;
|
|
244
|
+
/** Currently selected user for editing */
|
|
245
|
+
selectedUser: Identity.UserItem | null;
|
|
246
|
+
/** Roles assigned to the selected user */
|
|
247
|
+
selectedUserRoles: Identity.RoleItem[];
|
|
248
|
+
/** Loading state */
|
|
249
|
+
isLoading: boolean;
|
|
250
|
+
/** Error message if any */
|
|
251
|
+
error: string | null;
|
|
252
|
+
/** Current page query parameters */
|
|
253
|
+
pageQuery: ABP.PageQueryParams;
|
|
254
|
+
/** Fetch users with pagination */
|
|
255
|
+
fetchUsers: (params?: ABP.PageQueryParams) => Promise<UserOperationResult>;
|
|
256
|
+
/** Get a user by ID and set it as selected */
|
|
257
|
+
getUserById: (id: string) => Promise<UserOperationResult>;
|
|
258
|
+
/** Get roles for a user */
|
|
259
|
+
getUserRoles: (id: string) => Promise<UserOperationResult>;
|
|
260
|
+
/** Create a new user */
|
|
261
|
+
createUser: (user: Identity.UserSaveRequest) => Promise<UserOperationResult>;
|
|
262
|
+
/** Update an existing user */
|
|
263
|
+
updateUser: (id: string, user: Identity.UserSaveRequest) => Promise<UserOperationResult>;
|
|
264
|
+
/** Delete a user */
|
|
265
|
+
deleteUser: (id: string) => Promise<UserOperationResult>;
|
|
266
|
+
/** Set the selected user */
|
|
267
|
+
setSelectedUser: (user: Identity.UserItem | null) => void;
|
|
268
|
+
/** Set page query parameters */
|
|
269
|
+
setPageQuery: (query: ABP.PageQueryParams) => void;
|
|
270
|
+
/** Reset state */
|
|
271
|
+
reset: () => void;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Hook for managing users
|
|
275
|
+
*
|
|
276
|
+
* This hook provides all the state and actions needed for user management.
|
|
277
|
+
* It handles fetching, creating, updating, and deleting users with pagination support.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```tsx
|
|
281
|
+
* function UsersPage() {
|
|
282
|
+
* const {
|
|
283
|
+
* users,
|
|
284
|
+
* totalCount,
|
|
285
|
+
* isLoading,
|
|
286
|
+
* pageQuery,
|
|
287
|
+
* fetchUsers,
|
|
288
|
+
* createUser,
|
|
289
|
+
* deleteUser,
|
|
290
|
+
* setPageQuery,
|
|
291
|
+
* } = useUsers();
|
|
292
|
+
*
|
|
293
|
+
* useEffect(() => {
|
|
294
|
+
* fetchUsers();
|
|
295
|
+
* }, [fetchUsers]);
|
|
296
|
+
*
|
|
297
|
+
* const handlePageChange = (page: number) => {
|
|
298
|
+
* setPageQuery({ ...pageQuery, skipCount: page * 10 });
|
|
299
|
+
* fetchUsers({ ...pageQuery, skipCount: page * 10 });
|
|
300
|
+
* };
|
|
301
|
+
*
|
|
302
|
+
* return (
|
|
303
|
+
* <div>
|
|
304
|
+
* {users.map(user => (
|
|
305
|
+
* <div key={user.id}>{user.userName}</div>
|
|
306
|
+
* ))}
|
|
307
|
+
* </div>
|
|
308
|
+
* );
|
|
309
|
+
* }
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
312
|
+
declare function useUsers(): UseUsersReturn;
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Combined identity management return type
|
|
316
|
+
*/
|
|
317
|
+
interface UseIdentityReturn {
|
|
318
|
+
/** Role management hook */
|
|
319
|
+
roles: UseRolesReturn;
|
|
320
|
+
/** User management hook */
|
|
321
|
+
users: UseUsersReturn;
|
|
322
|
+
/** Combined loading state */
|
|
323
|
+
isLoading: boolean;
|
|
324
|
+
/** Combined error state */
|
|
325
|
+
error: string | null;
|
|
326
|
+
/** Reset all state */
|
|
327
|
+
resetAll: () => void;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Hook that combines role and user management for identity operations
|
|
331
|
+
*
|
|
332
|
+
* This hook provides a unified interface for managing both roles and users.
|
|
333
|
+
* It combines the useRoles and useUsers hooks for convenience.
|
|
334
|
+
*
|
|
335
|
+
* @example
|
|
336
|
+
* ```tsx
|
|
337
|
+
* function IdentityManagement() {
|
|
338
|
+
* const { roles, users, isLoading } = useIdentity();
|
|
339
|
+
*
|
|
340
|
+
* useEffect(() => {
|
|
341
|
+
* roles.fetchRoles();
|
|
342
|
+
* users.fetchUsers();
|
|
343
|
+
* }, []);
|
|
344
|
+
*
|
|
345
|
+
* return (
|
|
346
|
+
* <div>
|
|
347
|
+
* <h2>Roles</h2>
|
|
348
|
+
* {roles.roles.map(role => <div key={role.id}>{role.name}</div>)}
|
|
349
|
+
*
|
|
350
|
+
* <h2>Users</h2>
|
|
351
|
+
* {users.users.map(user => <div key={user.id}>{user.userName}</div>)}
|
|
352
|
+
* </div>
|
|
353
|
+
* );
|
|
354
|
+
* }
|
|
355
|
+
* ```
|
|
356
|
+
*/
|
|
357
|
+
declare function useIdentity(): UseIdentityReturn;
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Props for RolesComponent
|
|
361
|
+
*/
|
|
362
|
+
interface RolesComponentProps {
|
|
363
|
+
/** Optional callback when a role is created */
|
|
364
|
+
onRoleCreated?: (role: Identity.RoleItem) => void;
|
|
365
|
+
/** Optional callback when a role is updated */
|
|
366
|
+
onRoleUpdated?: (role: Identity.RoleItem) => void;
|
|
367
|
+
/** Optional callback when a role is deleted */
|
|
368
|
+
onRoleDeleted?: (id: string) => void;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* RolesComponent - Component for managing roles
|
|
372
|
+
*
|
|
373
|
+
* This is the React equivalent of Angular's RolesComponent.
|
|
374
|
+
* It displays a table of roles with CRUD operations and permission management.
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* ```tsx
|
|
378
|
+
* function IdentityPage() {
|
|
379
|
+
* return (
|
|
380
|
+
* <RolesComponent
|
|
381
|
+
* onRoleCreated={(role) => console.log('Role created:', role)}
|
|
382
|
+
* onRoleDeleted={(id) => console.log('Role deleted:', id)}
|
|
383
|
+
* />
|
|
384
|
+
* );
|
|
385
|
+
* }
|
|
386
|
+
* ```
|
|
387
|
+
*/
|
|
388
|
+
declare function RolesComponent({ onRoleCreated, onRoleUpdated, onRoleDeleted, }: RolesComponentProps): React.ReactElement;
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Props for UsersComponent
|
|
392
|
+
*/
|
|
393
|
+
interface UsersComponentProps {
|
|
394
|
+
/** Optional callback when a user is created */
|
|
395
|
+
onUserCreated?: (user: Identity.UserItem) => void;
|
|
396
|
+
/** Optional callback when a user is updated */
|
|
397
|
+
onUserUpdated?: (user: Identity.UserItem) => void;
|
|
398
|
+
/** Optional callback when a user is deleted */
|
|
399
|
+
onUserDeleted?: (id: string) => void;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* UsersComponent - Component for managing users
|
|
403
|
+
*
|
|
404
|
+
* This is the React equivalent of Angular's UsersComponent.
|
|
405
|
+
* It displays a table of users with CRUD operations, role assignment, and permission management.
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
* ```tsx
|
|
409
|
+
* function IdentityPage() {
|
|
410
|
+
* return (
|
|
411
|
+
* <UsersComponent
|
|
412
|
+
* onUserCreated={(user) => console.log('User created:', user)}
|
|
413
|
+
* onUserDeleted={(id) => console.log('User deleted:', id)}
|
|
414
|
+
* />
|
|
415
|
+
* );
|
|
416
|
+
* }
|
|
417
|
+
* ```
|
|
418
|
+
*/
|
|
419
|
+
declare function UsersComponent({ onUserCreated, onUserUpdated, onUserDeleted, }: UsersComponentProps): React.ReactElement;
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Identity module routes configuration.
|
|
423
|
+
* Translated from @abp/ng.identity IDENTITY_ROUTES.
|
|
424
|
+
*
|
|
425
|
+
* These routes define the navigation structure for the identity module
|
|
426
|
+
* within the ABP Framework application.
|
|
427
|
+
*/
|
|
428
|
+
declare const IDENTITY_ROUTES: ABP.FullRoute[];
|
|
429
|
+
/**
|
|
430
|
+
* Route paths for the identity module.
|
|
431
|
+
* Use these constants for programmatic navigation.
|
|
432
|
+
*/
|
|
433
|
+
declare const IDENTITY_ROUTE_PATHS: {
|
|
434
|
+
/** Base path for identity module */
|
|
435
|
+
readonly BASE: "/identity";
|
|
436
|
+
/** Roles management path */
|
|
437
|
+
readonly ROLES: "/identity/roles";
|
|
438
|
+
/** Users management path */
|
|
439
|
+
readonly USERS: "/identity/users";
|
|
440
|
+
};
|
|
441
|
+
/**
|
|
442
|
+
* Required policies for identity module routes.
|
|
443
|
+
*/
|
|
444
|
+
declare const IDENTITY_POLICIES: {
|
|
445
|
+
/** Policy for roles management */
|
|
446
|
+
readonly ROLES: "AbpIdentity.Roles";
|
|
447
|
+
/** Policy for users management */
|
|
448
|
+
readonly USERS: "AbpIdentity.Users";
|
|
449
|
+
/** Policy for creating users */
|
|
450
|
+
readonly USERS_CREATE: "AbpIdentity.Users.Create";
|
|
451
|
+
/** Policy for updating users */
|
|
452
|
+
readonly USERS_UPDATE: "AbpIdentity.Users.Update";
|
|
453
|
+
/** Policy for deleting users */
|
|
454
|
+
readonly USERS_DELETE: "AbpIdentity.Users.Delete";
|
|
455
|
+
/** Policy for creating roles */
|
|
456
|
+
readonly ROLES_CREATE: "AbpIdentity.Roles.Create";
|
|
457
|
+
/** Policy for updating roles */
|
|
458
|
+
readonly ROLES_UPDATE: "AbpIdentity.Roles.Update";
|
|
459
|
+
/** Policy for deleting roles */
|
|
460
|
+
readonly ROLES_DELETE: "AbpIdentity.Roles.Delete";
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
export { IDENTITY_POLICIES, IDENTITY_ROUTES, IDENTITY_ROUTE_PATHS, Identity, IdentityService, type RoleOperationResult, RolesComponent, type RolesComponentProps, type UseIdentityReturn, type UseRolesReturn, type UseUsersReturn, type UserOperationResult, UsersComponent, type UsersComponentProps, useIdentity, useRoles, useUsers };
|