Pluggy.Session (PluggyAI v0.1.0)

Copy Markdown View Source

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

t()

@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

accounts(session, opts \\ [])

@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.

client(session)

@spec client(t()) :: Pluggy.Client.t()

Returns the underlying Pluggy.Client for direct API calls.

connect_token(session)

@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.

identity(session, opts \\ [])

@spec identity(
  t(),
  keyword()
) :: {:ok, term()} | {:error, Pluggy.Error.t() | :no_item}

Fetches identity data for the connected item.

investments(session, opts \\ [])

@spec investments(
  t(),
  keyword()
) :: {:ok, term()} | {:error, Pluggy.Error.t() | :no_item}

Fetches investments for the connected item.

loans(session, opts \\ [])

@spec loans(
  t(),
  keyword()
) :: {:ok, term()} | {:error, Pluggy.Error.t() | :no_item}

Fetches loans for the connected item.

new(client, opts \\ [])

@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.

refresh_connect_token(session)

@spec refresh_connect_token(t()) ::
  {:ok, String.t(), t()} | {:error, Pluggy.Error.t()}

Refreshes the connect token, ignoring any cached value.

transactions(session, account_id, opts \\ [])

@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.

with_item(session, item_data)

@spec with_item(t(), map()) :: t()

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.