import { gracely } from "gracely" import { authly } from "authly" import { http } from "cloudly-http" import { Realm } from "../Realm" import { User } from "../User" export class Me { constructor(private readonly client: http.Client) {} async updatePassword(creatable: User.Password.Creatable): Promise { return await this.client.put(`/me/password`, creatable) } async login( email: string, password: string, realm: Realm, totp?: User.mfa.Totp.Otp ): Promise { return await this.client.get(`/me/${realm}`, { authorization: `Basic ${authly.Base64.encode(email + ":" + password, "standard", "=")}`, ...(totp ? { totp } : undefined), }) } async setupMfa(totp: User.mfa.Totp, otp: User.mfa.Totp.Otp): Promise { return this.client.put(`/me/mfa/totp`, totp, { ...(otp ? { totp: otp } : undefined) }) } }