import { RefreshAccessTokenCallback } from "../Coral" ; import { Decorator } from "./types" ; /**
 * Listen to `getRefreshAccessToken` requests, calls the
 * refreshAccessToken callback from config and sends a `refreshAccessToken`
 * response.
 */ const withRefreshAccessToken = ( refreshAccessToken = null ) : Decorator => ( pym ) => { pym . onMessage ( "getRefreshAccessToken" , ( ) => { if ( ! refreshAccessToken ) { pym . sendMessage ( "refreshAccessToken" , "" ) ; return ; } let called = false ; refreshAccessToken ( ( token ) => { if ( called ) { throw new Error ( "next access token has been already provided" ) ; } called = true ; pym . sendMessage ( "refreshAccessToken" , token ) ; } ) ; } ) ; } ; export default withRefreshAccessToken ;