UNPKG

@bit-ui-libs/common

Version:
238 lines (196 loc) 7.93 kB
import { BaseService, BaseServiceOptions } from '../../api/services/base-service'; import { PagedResponse, createQueryParams } from '../../common'; import { UserTypeEnum } from '../enums'; import { BeingId, BitDocument, EndUser, FycDocument, User, UserOrganization } from '../interfaces'; import { AddressService } from './address.service'; import { WithAddress } from './address.service.interfaces'; import { Invite } from './invites'; import { ChangeEmailRequest, ChangePhoneRequest, CompleteFycOnboardingRequest, ConsentActionRequest, ConsentActionResponse, EditUserRequest, ExportListUsersRequest, FycDocumentsRequest, GetUserRolesResponse, ListInvitesRequest, IvdtRequestShareableRequest, IvdtRequestShareableResponse, IvdtShareableRequest, IvdtShareableResponse, ListUserDocumentsRequest, ListUsersRequest, ManageUserRolesRequest, RecalculateBeingIdRequest, SearchOrgsRequest, SearchOrgsResponse, SearchUserDocumentsRequest, SearchUsersRequest, SetBeingIdRequest, ShareUserDeepLinkRequest, VerifyCredentialsRequest, VerifyCredentialsResponse, VerifyCredentialsWitnessRequest, VerifyCredentialsWitnessResponse, VerifyEmailRequest, VerifyPhoneRequest, VerifyCodeRequest, SendVerificationCodeRequest, VerifyCodeResponse, } from './user.service.interfaces'; type UserServiceOptions = BaseServiceOptions & { userType: UserTypeEnum }; export class UserService extends BaseService implements WithAddress { protected usersApiUrl: string; private userType: UserTypeEnum; address: AddressService; constructor(opts: UserServiceOptions) { super(opts); this.userType = opts.userType; this.usersApiUrl = `${this.apiUrl}/users/v1/${opts.userType}/users`; this.address = new AddressService(opts); } getEndUser(id: string) { return this.get<EndUser>(`${this.apiUrl}/users/v1/end-user/users/${id}`, {}); } searchUsers(req: SearchUsersRequest) { return this.get<PagedResponse<User>>(this.usersApiUrl, req); } listUsers(req: ListUsersRequest) { return this.get<User[]>(`${this.usersApiUrl}/list`, req); } getUser(id: string) { return this.get<User>(`${this.usersApiUrl}/${id}`); } editUser(id: string, req: EditUserRequest) { return this.put<User, EditUserRequest>(`${this.usersApiUrl}/${id}`, req); } removeUser(id: string) { return this.delete<void>(`${this.usersApiUrl}/${id}`); } getUserRoles(id: string) { return this.get<GetUserRolesResponse>(`${this.usersApiUrl}/${id}/roles`); } changeEmail(id: string, req: ChangeEmailRequest) { return this.patch<void, ChangeEmailRequest>(`${this.usersApiUrl}/${id}/change-email`, req); } requestEmailVerification(id: string) { return this.patch<void, object>(`${this.usersApiUrl}/${id}/verify-email`, {}); } verifyEmail(id: string, req: VerifyEmailRequest) { const query = createQueryParams({ ticket: req.ticket }); return this.get<void>(`${this.usersApiUrl}/${id}/verify-email?${query}`); } changePhone(id: string, req: ChangePhoneRequest) { return this.patch<void, ChangePhoneRequest>(`${this.usersApiUrl}/${id}/change-phone`, req); } requestPhoneVerification(id: string) { return this.patch<void, object>(`${this.usersApiUrl}/${id}/verify-phone`, {}); } verifyPhone(id: string, req: VerifyPhoneRequest) { return this.post<void, VerifyPhoneRequest>(`${this.usersApiUrl}/${id}/verify-phone`, req); } assignRoles(id: string, req: ManageUserRolesRequest) { return this.patch<void, ManageUserRolesRequest>(`${this.usersApiUrl}/${id}/assign-roles`, req); } removeRoles(id: string, req: ManageUserRolesRequest) { return this.patch<void, ManageUserRolesRequest>(`${this.usersApiUrl}/${id}/remove-roles`, req); } requestResetPassword(id: string) { return this.patch<void, object>(`${this.usersApiUrl}/${id}/request-password`, {}); } blockUser(id: string): Promise<void> { return this.patch<void, object>(`${this.usersApiUrl}/${id}/block`, {}); } unblockUser(id: string): Promise<void> { return this.patch<void, object>(`${this.usersApiUrl}/${id}/unblock`, {}); } verifyCredentials(req: VerifyCredentialsRequest) { return this.post<VerifyCredentialsResponse, VerifyCredentialsRequest>( `${this.usersApiUrl}/verify-credentials`, req ); } verifyCredentialsWitness(req: VerifyCredentialsWitnessRequest) { return this.post<VerifyCredentialsWitnessResponse, VerifyCredentialsWitnessRequest>( `${this.usersApiUrl}/verify-credentials-witness`, req ); } getBeingId(id: string) { return this.get<BeingId>(`${this.usersApiUrl}/${id}/being-id`); } setBeingId(id: string, req: SetBeingIdRequest) { return this.patch<BeingId, SetBeingIdRequest>(`${this.usersApiUrl}/${id}/being-id`, req); } recalculateBeingId(id: string, req: RecalculateBeingIdRequest) { return this.patch<BeingId, RecalculateBeingIdRequest>(`${this.usersApiUrl}/${id}/being-id/calculate`, req); } completeFycOnboarding(id: string, req: CompleteFycOnboardingRequest) { return this.patch<void, CompleteFycOnboardingRequest>(`${this.usersApiUrl}/${id}/complete-onboarding`, req); } getPreviousSessionSelfie(id: string) { return this.get<string>(`${this.usersApiUrl}/${id}/prev-session-selfie`); } searchOrganizations(id: string, req: SearchOrgsRequest = {}) { return this.get<SearchOrgsResponse, SearchOrgsRequest>( `${this.apiUrl}/users/v1/${this.userType}/${id}/organizations`, req ); } getCurrentOrganization(id: string) { return this.get<UserOrganization>(`${this.apiUrl}/users/v1/${this.userType}/${id}/organizations/current`); } createConsent(req: ConsentActionRequest) { return this.post<ConsentActionResponse, ConsentActionRequest>(`${this.usersApiUrl}/consent-action`, req); } setPrivacy(id: string, isPublic: boolean) { return this.patch<void, object>(`${this.usersApiUrl}/${id}/public/${isPublic}`, {}); } getInviteById(id: string) { return this.get<Invite>(`${this.apiUrl}/users/v1/${this.userType}/invites/${id}`, {}); } listInvites(req: ListInvitesRequest) { return this.get<Invite[]>(`${this.apiUrl}/users/v1/${this.userType}/invites/list`, req); } exportList(req: ExportListUsersRequest) { return this.get<Blob>(`${this.apiUrl}/users/v1/${this.userType}/users/export`, req, { responseType: 'blob' }); } listFycDocuments(req?: FycDocumentsRequest) { return this.get<FycDocument[]>(`${this.apiUrl}/users/v1/${this.userType}/users/list-fyc-documents`, req); } searchDocuments(req: SearchUserDocumentsRequest) { return this.get<PagedResponse<BitDocument>>(`${this.apiUrl}/users/v1/documents/list`, req); } listDocuments(req: ListUserDocumentsRequest) { return this.get<BitDocument[]>(`${this.apiUrl}/users/v1/documents/list`, req); } shareDeepLink(userId: string, req: ShareUserDeepLinkRequest) { return this.post<void, ShareUserDeepLinkRequest>( `${this.apiUrl}/users/v1/${this.userType}/users/${userId}/share-deep-link`, req ); } ivdtRequestShareableInfo(req: IvdtRequestShareableRequest) { return this.post<IvdtRequestShareableResponse, IvdtRequestShareableRequest>( `${this.apiUrl}/users/v1/${this.userType}/users/request-ivdt-shareable`, req ); } ivdtShareableInfo(req: IvdtShareableRequest) { return this.get<IvdtShareableResponse>(`${this.apiUrl}/users/v1/${this.userType}/users/ivdt-shareable-info`, req); } sendVerificationCode(req: SendVerificationCodeRequest) { return this.post<void, SendVerificationCodeRequest>( `${this.apiUrl}/users/v1/${this.userType}/verifications/send-code`, req ); } verifyCode(req: VerifyCodeRequest) { return this.post<VerifyCodeResponse, VerifyCodeRequest>( `${this.apiUrl}/users/v1/${this.userType}/verifications/verify-code`, req ); } }