A plain struct with functional API for managing a Pluggy connection session.
A session holds a client, an optional connect token, and the connected item data. State lives in the caller's process (LiveView socket, Livebook cell, etc.) — no GenServer is used.
Usage
{:ok, client} = Pluggy.Client.new("client_id", "client_secret")
session = Pluggy.Session.new(client)
# Get a connect token for the widget
{:ok, token, session} = Pluggy.Session.connect_token(session)
# After widget connection completes
session = Pluggy.Session.with_item(session, item_data)
# Fetch resources
{:ok, accounts} = Pluggy.Session.accounts(session)
{:ok, txns} = Pluggy.Session.transactions(session, account_id)
Summary
Functions
Fetches accounts for the connected item.
Returns the underlying Pluggy.Client for direct API calls.
Fetches a connect token for this session.
Fetches identity data for the connected item.
Fetches investments for the connected item.
Fetches loans for the connected item.
Creates a new session from a Pluggy.Client.
Refreshes the connect token, ignoring any cached value.
Fetches transactions for a given account ID.
Sets the connected item data on the session.
Types
@type t() :: %Pluggy.Session{ client: Pluggy.Client.t(), connect_token: String.t() | nil, connect_token_opts: keyword(), item: map() | nil, item_id: String.t() | nil }
Functions
@spec accounts( t(), keyword() ) :: {:ok, term()} | {:error, Pluggy.Error.t() | :no_item}
Fetches accounts for the connected item.
Returns {:error, :no_item} if no item has been set.
@spec client(t()) :: Pluggy.Client.t()
Returns the underlying Pluggy.Client for direct API calls.
@spec connect_token(t()) :: {:ok, String.t(), t()} | {:error, Pluggy.Error.t()}
Fetches a connect token for this session.
Returns {:ok, token, updated_session} where the updated session caches the token.
If a token is already cached, returns it without making a new request.
@spec identity( t(), keyword() ) :: {:ok, term()} | {:error, Pluggy.Error.t() | :no_item}
Fetches identity data for the connected item.
@spec investments( t(), keyword() ) :: {:ok, term()} | {:error, Pluggy.Error.t() | :no_item}
Fetches investments for the connected item.
@spec loans( t(), keyword() ) :: {:ok, term()} | {:error, Pluggy.Error.t() | :no_item}
Fetches loans for the connected item.
@spec new( Pluggy.Client.t(), keyword() ) :: t()
Creates a new session from a Pluggy.Client.
Options
:webhook_url- URL for webhook notifications (passed as connect token option)- Any other options are stored and passed when creating connect tokens.
@spec refresh_connect_token(t()) :: {:ok, String.t(), t()} | {:error, Pluggy.Error.t()}
Refreshes the connect token, ignoring any cached value.
@spec transactions(t(), String.t(), keyword()) :: {:ok, term()} | {:error, Pluggy.Error.t() | :no_item}
Fetches transactions for a given account ID.
Returns {:error, :no_item} if no item has been set.
Sets the connected item data on the session.
The item_data map should contain the item information returned by the
Pluggy Connect widget's onSuccess callback.