All files / app/service account.ts

28.75% Statements 23/80
0% Branches 0/2
0% Functions 0/17
28.75% Lines 23/80

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 14275x 75x                     75x           75x   75x 75x   74x         74x           74x                     74x               74x               74x           74x         74x                 74x               74x           74x           74x           74x                 74x             74x                   74x         74x      
import { Empty } from "google-protobuf/google/protobuf/empty_pb";
import { Timestamp } from "google-protobuf/google/protobuf/timestamp_pb";
import {
  ChangeEmailV2Req,
  ChangePasswordV2Req,
  ChangePhoneReq,
  DeleteAccountReq,
  FillContributorFormReq,
  ListActiveSessionsReq,
  LogOutOtherSessionsReq,
  LogOutSessionReq,
  VerifyPhoneReq,
} from "proto/account_pb";
import {
  CompletePasswordResetV2Req,
  ConfirmChangeEmailV2Req,
  ContributorForm as ContributorFormPb,
  ResetPasswordReq,
} from "proto/auth_pb";
 
import { contributorFormFromObject } from "./auth";
import client from "./client";
 
export async function getAccountInfo() {
  const res = await client.account.getAccountInfo(new Empty());
  return res.toObject();
}
 
export function resetPassword(userId: string) {
  const req = new ResetPasswordReq();
  req.setUser(userId);
  return client.auth.resetPassword(req);
}
 
export function CompletePasswordResetV2(
  resetToken: string,
  newPassword: string,
) {
  const req = new CompletePasswordResetV2Req();
  req.setPasswordResetToken(resetToken);
  req.setNewPassword(newPassword);
 
  return client.auth.completePasswordResetV2(req);
}
 
export function changePassword(oldPassword: string, newPassword: string) {
  const req = new ChangePasswordV2Req();
  req.setOldPassword(oldPassword);
  req.setNewPassword(newPassword);
 
  return client.account.changePasswordV2(req);
}
 
export function changeEmail(newEmail: string, currentPassword: string) {
  const req = new ChangeEmailV2Req();
  req.setNewEmail(newEmail);
  req.setPassword(currentPassword);
 
  return client.account.changeEmailV2(req);
}
 
export async function confirmChangeEmail(resetToken: string) {
  const req = new ConfirmChangeEmailV2Req();
  req.setChangeEmailToken(resetToken);
  return client.auth.confirmChangeEmailV2(req);
}
 
export async function getContributorFormInfo() {
  const res = await client.account.getContributorFormInfo(new Empty());
  return res.toObject();
}
 
export async function fillContributorForm(form: ContributorFormPb.AsObject) {
  const res = await client.account.fillContributorForm(
    new FillContributorFormReq().setContributorForm(
      contributorFormFromObject(form),
    ),
  );
  return res.toObject();
}
 
export function deleteAccount(confirm: boolean, reason?: string) {
  const req = new DeleteAccountReq();
  req.setConfirm(confirm);
  Iif (reason) {
    req.setReason(reason);
  }
  return client.account.deleteAccount(req);
}
export function changePhone(phone: string) {
  const req = new ChangePhoneReq();
  req.setPhone(phone);
  return client.account.changePhone(req);
}
 
export function removePhone() {
  const req = new ChangePhoneReq();
  req.setPhone("");
  return client.account.changePhone(req);
}
 
export function verifyPhone(code: string) {
  const req = new VerifyPhoneReq();
  req.setToken(code);
  return client.account.verifyPhone(req);
}
 
export async function listActiveSessions(pageToken?: string) {
  const req = new ListActiveSessionsReq();
  Iif (pageToken) {
    req.setPageToken(pageToken);
  }
  const response = await client.account.listActiveSessions(req);
  return response.toObject();
}
 
export async function logOutOtherSessions(confirm: boolean) {
  const req = new LogOutOtherSessionsReq();
  req.setConfirm(confirm);
  const response = await client.account.logOutOtherSessions(req);
  return response.toObject();
}
 
export async function logOutSession(created: Timestamp.AsObject) {
  const req = new LogOutSessionReq();
  const ts = new Timestamp();
  ts.setSeconds(created.seconds);
  ts.setNanos(created.nanos);
  req.setCreated(ts);
  const response = await client.account.logOutSession(req);
  return response.toObject();
}
 
export async function initiateStrongVerification() {
  const res = await client.account.initiateStrongVerification(new Empty());
  return res.toObject();
}
 
export async function deleteStrongVerificationData() {
  await client.account.deleteStrongVerificationData(new Empty());
}