-
Notifications
You must be signed in to change notification settings - Fork 12
feat(identity): add updateById, deleteById and create to Users service #617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/identity-users-getbyid
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,17 +3,37 @@ | |||||
| * interface that drives generated API documentation. | ||||||
| */ | ||||||
|
|
||||||
| import type { RawUserGetResponse } from './users.types'; | ||||||
| import type { | ||||||
| RawUserGetResponse, | ||||||
| UserCreateData, | ||||||
| UserCreateOptions, | ||||||
| UserOperationResult, | ||||||
| UserUpdateOptions, | ||||||
| UserUpdateResponse, | ||||||
| } from './users.types'; | ||||||
|
|
||||||
| /** | ||||||
| * User returned by the Users service. | ||||||
| * User with attached methods | ||||||
| */ | ||||||
| export interface UserGetResponse extends RawUserGetResponse {} | ||||||
| export type UserGetResponse = RawUserGetResponse & UserMethods; | ||||||
|
|
||||||
| /** | ||||||
| * Response from `create()`. | ||||||
| * | ||||||
| * `result` reflects the request as a whole; `users` contains the created users. | ||||||
| */ | ||||||
| export interface UserCreateResponse { | ||||||
| /** Overall outcome of the create request. */ | ||||||
| result: UserOperationResult; | ||||||
| /** The created users. */ | ||||||
| users: UserGetResponse[]; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Service model for managing users in a UiPath organization. | ||||||
| * | ||||||
| * Provides organization-level user administration. | ||||||
| * Provides organization-level user administration: retrieving, updating and | ||||||
| * deleting users, creating users in bulk, and inviting users by email. | ||||||
| * | ||||||
| * ### Usage | ||||||
| * | ||||||
|
|
@@ -31,16 +51,153 @@ export interface UserServiceModel { | |||||
| * Gets a user by ID. | ||||||
| * | ||||||
| * Returns the full user details including profile fields, group membership, | ||||||
| * activity flags and invitation state. | ||||||
| * activity flags and invitation state, with entity methods attached | ||||||
| * (`update`, `delete`). | ||||||
| * | ||||||
| * @param userId - User GUID | ||||||
| * @returns Promise resolving to a {@link UserGetResponse} with the user's profile fields, group membership, activity flags and invitation state | ||||||
| * @returns Promise resolving to a {@link UserGetResponse} with the user's profile fields, group membership, activity flags and invitation state, plus bound entity methods | ||||||
| * | ||||||
| * @example | ||||||
| * ```typescript | ||||||
| * const user = await users.getById('<userId>'); | ||||||
| * console.log(`${user.displayName} (${user.email}) — active: ${user.isActive}`); | ||||||
| * | ||||||
| * // Operate on the user directly via bound methods | ||||||
| * await user.update({ displayName: 'New Name' }); | ||||||
| * ``` | ||||||
| */ | ||||||
| getById(userId: string): Promise<UserGetResponse>; | ||||||
|
|
||||||
| /** | ||||||
| * Updates a user. Only the provided fields are changed. | ||||||
| * | ||||||
| * @param userId - User GUID | ||||||
| * @param options - Fields to update | ||||||
| * @returns Promise resolving to a {@link UserUpdateResponse} indicating whether the update succeeded and any errors | ||||||
| * | ||||||
| * @example | ||||||
| * ```typescript | ||||||
| * // First, get the user with users.getById() or from users.create() | ||||||
| * const result = await users.updateById('<userId>', { displayName: 'New Name' }); | ||||||
| * if (result.succeeded) { | ||||||
| * console.log('User updated'); | ||||||
| * } | ||||||
| * ``` | ||||||
| * | ||||||
| * @example Manage group membership | ||||||
| * ```typescript | ||||||
| * await users.updateById('<userId>', { | ||||||
| * groupIdsToAdd: ['<groupId-1>'], | ||||||
| * groupIdsToRemove: ['<groupId-2>'], | ||||||
| * }); | ||||||
| * ``` | ||||||
| */ | ||||||
| updateById(userId: string, options: UserUpdateOptions): Promise<UserUpdateResponse>; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per convention,
Same applies to
Suggested change
|
||||||
|
|
||||||
| /** | ||||||
| * Deletes a user. | ||||||
| * | ||||||
| * @param userId - User GUID | ||||||
| * @returns Promise that resolves when the user is deleted | ||||||
| * | ||||||
| * @example | ||||||
| * ```typescript | ||||||
| * await users.deleteById('<userId>'); | ||||||
| * ``` | ||||||
| */ | ||||||
| deleteById(userId: string): Promise<void>; | ||||||
|
|
||||||
| /** | ||||||
| * Creates users in bulk. | ||||||
| * | ||||||
| * Returns the created users with entity methods attached (`update`, `delete`). | ||||||
| * A single invalid user fails the whole request — check `result.errors` for | ||||||
| * the reason. | ||||||
| * | ||||||
| * @param users - Users to create | ||||||
| * @param organizationId - Organization GUID the users belong to | ||||||
| * @param options - Optional group assignment applied to every created user | ||||||
| * @returns Promise resolving to a {@link UserCreateResponse} with the overall outcome and the created users | ||||||
| * | ||||||
| * @example | ||||||
| * ```typescript | ||||||
| * const response = await users.create( | ||||||
| * [{ userName: 'jdoe', email: 'jdoe@acme.com', name: 'Jane', surname: 'Doe' }], | ||||||
| * '<organizationId>' | ||||||
| * ); | ||||||
| * if (response.result.succeeded) { | ||||||
| * console.log(`Created ${response.users[0].id}`); | ||||||
| * } | ||||||
| * ``` | ||||||
| * | ||||||
| * @example Add every created user to groups | ||||||
| * ```typescript | ||||||
| * const response = await users.create( | ||||||
| * [{ userName: 'jdoe', email: 'jdoe@acme.com' }], | ||||||
| * '<organizationId>', | ||||||
| * { groupIds: ['<groupId>'] } | ||||||
| * ); | ||||||
| * ``` | ||||||
| */ | ||||||
| create( | ||||||
| users: UserCreateData[], | ||||||
| organizationId: string, | ||||||
| options?: UserCreateOptions | ||||||
| ): Promise<UserCreateResponse>; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Methods attached to user objects returned by `getById()` and `create()`. | ||||||
| */ | ||||||
| export interface UserMethods { | ||||||
| /** | ||||||
| * Updates this user. Only the provided fields are changed. | ||||||
| * | ||||||
| * @param options - Fields to update | ||||||
| * @returns Promise resolving to the operation outcome | ||||||
| */ | ||||||
| update(options: UserUpdateOptions): Promise<UserUpdateResponse>; | ||||||
|
|
||||||
| /** | ||||||
| * Deletes this user. | ||||||
| * | ||||||
| * @returns Promise that resolves when the user is deleted | ||||||
| */ | ||||||
| delete(): Promise<void>; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Creates methods for a user | ||||||
| * | ||||||
| * @param userData - The user data (response from API) | ||||||
| * @param service - The user service instance | ||||||
| * @returns Object containing user methods | ||||||
| */ | ||||||
| function createUserMethods(userData: RawUserGetResponse, service: UserServiceModel): UserMethods { | ||||||
| return { | ||||||
| async update(options: UserUpdateOptions): Promise<UserUpdateResponse> { | ||||||
| if (!userData.id) throw new Error('User ID is undefined'); | ||||||
| return service.updateById(userData.id, options); | ||||||
| }, | ||||||
|
|
||||||
| async delete(): Promise<void> { | ||||||
| if (!userData.id) throw new Error('User ID is undefined'); | ||||||
| return service.deleteById(userData.id); | ||||||
| }, | ||||||
| }; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Attaches methods to a user object | ||||||
| * | ||||||
| * @param userData - The user data (response from API) | ||||||
| * @param service - The user service instance | ||||||
| * @returns User data with methods attached | ||||||
| */ | ||||||
| export function createUserWithMethods( | ||||||
| userData: RawUserGetResponse, | ||||||
| service: UserServiceModel | ||||||
| ): UserGetResponse { | ||||||
| const methods = createUserMethods(userData, service); | ||||||
| return Object.assign({}, userData, methods); | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||
| /** | ||||||
| * Identity user management types — response shapes and enums. | ||||||
| * Identity user management types — response shapes, request payloads and enums. | ||||||
| */ | ||||||
|
|
||||||
| /** | ||||||
|
|
@@ -72,3 +72,83 @@ export interface RawUserGetResponse { | |||||
| /** Whether the user has accepted their invitation. */ | ||||||
| invitationAccepted: boolean; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Error entry from a failed user operation. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Convention: "Always use (Note:
Suggested change
|
||||||
| */ | ||||||
| export interface UserOperationError { | ||||||
| /** Machine-readable error code (e.g. `InvalidUserName`). */ | ||||||
| code: string; | ||||||
| /** Human-readable error description. */ | ||||||
| description: string; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Overall outcome of a user operation. | ||||||
| */ | ||||||
| export interface UserOperationResult { | ||||||
| /** Whether the operation succeeded. */ | ||||||
| succeeded: boolean; | ||||||
| /** Errors that caused the operation to fail. Empty on success. */ | ||||||
| errors: UserOperationError[]; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Response from `updateById()`. | ||||||
| */ | ||||||
| export interface UserUpdateResponse extends UserOperationResult {} | ||||||
|
|
||||||
| /** | ||||||
| * Payload for `updateById()`. Only the provided fields are changed. | ||||||
| */ | ||||||
| export interface UserUpdateOptions { | ||||||
| /** New first name. */ | ||||||
| name?: string; | ||||||
| /** New last name. */ | ||||||
| surname?: string; | ||||||
| /** New display name. */ | ||||||
| displayName?: string; | ||||||
| /** New email address. */ | ||||||
| email?: string; | ||||||
| /** Activate (`true`) or deactivate (`false`) the user. */ | ||||||
| isActive?: boolean; | ||||||
| /** New password. */ | ||||||
| password?: string; | ||||||
| /** GUIDs of groups to add the user to. */ | ||||||
| groupIdsToAdd?: string[]; | ||||||
| /** GUIDs of groups to remove the user from. */ | ||||||
| groupIdsToRemove?: string[]; | ||||||
| /** Whether this user bypasses the basic authentication restriction. */ | ||||||
| bypassBasicAuthRestriction?: boolean; | ||||||
| /** Whether the user should be marked as having accepted their invitation. */ | ||||||
| invitationAccepted?: boolean; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * A user to create with `create()`. | ||||||
| */ | ||||||
| export interface UserCreateData { | ||||||
| /** Username — can only contain letters or digits. */ | ||||||
| userName: string; | ||||||
| /** Email address. */ | ||||||
| email?: string; | ||||||
| /** First name. */ | ||||||
| name?: string; | ||||||
| /** Last name. */ | ||||||
| surname?: string; | ||||||
| /** Display name. */ | ||||||
| displayName?: string; | ||||||
| /** Whether the user should be marked as having accepted their invitation. */ | ||||||
| invitationAccepted?: boolean; | ||||||
| /** Whether this user bypasses the basic authentication restriction. */ | ||||||
| bypassBasicAuthRestriction?: boolean; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Options for `create()`. | ||||||
| */ | ||||||
| export interface UserCreateOptions { | ||||||
| /** GUIDs of groups every created user is added to. */ | ||||||
| groupIds?: string[]; | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per convention, response types must use
type, notinterface:UserCreateResponseis a plain multi-field object type — it's not a single-type alias extending another type, so the TypeDoc exception doesn't apply.and close with
};on line 30.