# `Wise.Config`
[🔗](https://github.com/iamkanishka/wise/blob/v1.0.0/lib/wise/config.ex#L1)

Client configuration for the Wise Platform API.

Build a config struct using `new/1` and pass it to every service call,
or register it as a named config using `Wise.Application`.

## Required

At least one of `:personal_token`, `:client_id`+`:client_secret`,
or `:access_token` must be provided.

## Example

    config = Wise.Config.new!(
      personal_token: System.fetch_env!("WISE_API_TOKEN"),
      sandbox: true
    )

    {:ok, profiles} = Wise.Services.Profiles.list(config)

# `auth_mode`

```elixir
@type auth_mode() :: :personal_token | :client_credentials | :user_token
```

# `on_token_refresh`

```elixir
@type on_token_refresh() :: (refresh_token :: String.t() -&gt;
                         {:ok,
                          %{
                            access_token: String.t(),
                            refresh_token: String.t(),
                            expires_at: DateTime.t()
                          }}
                         | {:error, term()})
```

# `t`

```elixir
@type t() :: %Wise.Config{
  access_token: String.t() | nil,
  auth_mode: auth_mode(),
  base_url: String.t(),
  circuit_breaker: GenServer.server() | nil,
  client_id: String.t() | nil,
  client_secret: String.t() | nil,
  max_retries: non_neg_integer(),
  on_token_refresh: on_token_refresh() | nil,
  personal_token: String.t() | nil,
  rate_limiter: GenServer.server() | nil,
  recv_timeout: pos_integer(),
  refresh_token: String.t() | nil,
  request_hooks: [function()],
  response_hooks: [function()],
  retry_base_delay: pos_integer(),
  retry_max_delay: pos_integer(),
  timeout: pos_integer(),
  token_expires_at: DateTime.t() | nil,
  user_agent: String.t()
}
```

# `current_token`

```elixir
@spec current_token(t()) :: {:ok, String.t()} | {:error, Wise.Error.t()}
@spec current_token(t()) :: {:ok, String.t()} | {:error, atom()}
```

Returns the current Bearer token, refreshing if necessary.

# `new`

```elixir
@spec new(keyword()) :: {:ok, t()} | {:error, String.t()}
```

Creates a new config struct.

Returns `{:ok, config}` or `{:error, reason}`.

# `new!`

```elixir
@spec new!(keyword()) :: t()
```

Like `new/1` but raises on invalid configuration.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
