// FIXME: Update this file to be type safe and remove this and next line // @ts-strict-ignore import { firstValueFrom, map } from "rxjs"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service"; import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status"; import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service"; import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction"; import { Response } from "../models/response"; import { TemplateResponse } from "../models/response/template.response"; export class StatusCommand { constructor( private envService: EnvironmentService, private syncService: SyncService, private accountService: AccountService, private authService: AuthService, ) {} async run(): Promise { try { const baseUrl = await this.baseUrl(); const status = await this.status(); const lastSync = await this.syncService.getLastSync(); const [userId, email] = await firstValueFrom( this.accountService.activeAccount$.pipe(map((a) => [a?.id, a?.email])), ); return Response.success( new TemplateResponse({ serverUrl: baseUrl, lastSync: lastSync, userEmail: email, userId: userId, status: status, }), ); } catch (e) { return Response.error(e); } } private async baseUrl(): Promise { const env = await firstValueFrom(this.envService.environment$); return env.getUrls().base; } private async status(): Promise<"unauthenticated" | "locked" | "unlocked"> { const authStatus = await this.authService.getAuthStatus(); if (authStatus === AuthenticationStatus.Unlocked) { return "unlocked"; } else if (authStatus === AuthenticationStatus.Locked) { return "locked"; } else { return "unauthenticated"; } } }