format import os from 'os' ; import { UserNotSignedInError } from 'flipper-common' ; export type KeytarModule = { getPassword ( service , username ) : string ; deletePassword ( service , username ) : void ; setPassword ( service , username , password ) : void ; } ; export class KeytarManager { constructor ( private keytar ) { } public async writeKeychain ( service , password ) { if ( this . keytar == null ) { throw new Error ( 'Keytar is not available.' ) ; } await this . keytar . deletePassword ( service , os . userInfo ( ) . username ) ; await this . keytar . setPassword ( service , os . userInfo ( ) . username , password ) ; } public async unsetKeychain ( service ) { await this . keytar ?. deletePassword ( service , os . userInfo ( ) . username ) ; } public async retrieveToken ( service ) { if ( this . keytar == null ) { throw new Error ( 'Keytar is not available.' ) ; } const token = await this . keytar . getPassword ( service , os . userInfo ( ) . username ) ; if ( ! token ) { throw new UserNotSignedInError ( ) ; } return token ; } }