-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Package implementing core logic for refreshing of expiring access tokens
--   
--   This package can be used for renewal of expiring access tokens
--   according to user-provided actions. Tokens will be stored in a
--   transactional variable (TVar).
@package async-refresh-tokens
@version 0.3.0.1


-- | The async-refresh-tokens package is built on top of the async-refresh
--   package and provides the core logic for renewal of expiring access
--   tokens according to user-provided actions.
module Control.Concurrent.Async.Refresh.Tokens

-- | Type class for tokens.
class IsToken t

-- | Desired scopes for this configuration.
tokenScopes :: IsToken t => proxy t -> [Text]

-- | Human readable name for this token, including default implementation.
tokenName :: IsToken t => proxy t -> Text

-- | Type containing a token. <tt>t</tt> is a phantom type, which can be
--   used for making different tokens distinguishable at the type level.
newtype Token t
Token :: ByteString -> Token t
[unToken] :: Token t -> ByteString

-- | Type representing a running token refresher.
data TokenRefresher

-- | Extract the <a>Async</a> handle from the provided
--   <a>TokenRefresher</a>.
tokenRefresherAsync :: TokenRefresher -> Async ()

-- | Type wrapping a token request using existential quantification.
data RequestToken m
RequestToken :: TokenStore t -> m (RefreshResult (Token t)) -> RequestToken m

-- | Token store to use.
[requestTokenStore] :: RequestToken m -> TokenStore t

-- | Token refresh action.
[requestTokenAction] :: RequestToken m -> m (RefreshResult (Token t))

-- | Data type returned by async refresh actions.
data RefreshResult a :: * -> *
RefreshResult :: a -> Maybe Int -> RefreshResult a

-- | Actual result.
[refreshResult] :: RefreshResult a -> a

-- | In milliseconds.
[refreshExpiry] :: RefreshResult a -> Maybe Int

-- | Type synonym representing a token store, which is an <a>Either</a>
--   wrapped in a <a>TVar</a>.
type TokenStore t = TVar (Either SomeException (Token t))

-- | Type representing a configuration for this package.
data TokenConf m

-- | Start a new token refresher for the provided configuration. Returns a
--   <a>TokenRefresher</a> handle representing the running token refresher.
newTokenRefresher :: forall m. (MonadIO m, MonadBaseControl IO m, MonadMask m, MonadLogger m, Forall (Pure m)) => TokenConf m -> m TokenRefresher

-- | Create a new empty token store for the provided token type.
newEmptyTokenStore :: (MonadIO m, IsToken t) => m (TVar (Either SomeException (Token t)))

-- | Produce default token configuration.
defaultTokenConf :: TokenConf m

-- | Set the token refreshing factor, which is the factor in the closed
--   interval [0, 1] by which an "expires_in" duration is to be scaled. See
--   <a>defaultRefreshTimeFactor</a>.
tokenConfSetFactor :: Double -> TokenConf m -> TokenConf m

-- | Add a token request to the given token configuration.
tokenConfAddRequest :: RequestToken m -> TokenConf m -> TokenConf m
