Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: v0.6.0 #49

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,3 @@ export ERL_AFLAGS="-kernel shell_history enabled"
export LANG=en_US.UTF-8

use flake

# Setup postgresql
if test -d "/Applications/Postgres.app"; then
export DATABASE_USER="$(whoami)"
export DATABASE_PASSWORD=""
else
# postges related
export DATABASE_USER="supabase_potion"
export DATABASE_PASSWORD="supabase_potion"
export PG_DATABASE="supabase_potion_dev"
# keep all your db data in a folder inside the project
export PGHOST="$PWD/.postgres"
export PGDATA="$PGHOST/data"
export PGLOG="$PGHOST/server.log"

if [[ ! -d "$PGDATA" ]]; then
# initital set up of database server
initdb --auth=trust --no-locale --encoding=UTF8 -U=$DATABASE_USER >/dev/null

# point to correct unix sockets
echo "unix_socket_directories = '$PGHOST'" >> "$PGDATA/postgresql.conf"
# creates loacl database user
echo "CREATE USER $DATABASE_USER SUPERUSER;" | postgres --single -E postgres
# creates local databse
echo "CREATE DATABASE $PG_DATABASE;" | postgres --single -E postgres
fi
fi
2 changes: 1 addition & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,apps}/**/*.{ex,exs}"]
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ jobs:
lint:
runs-on: ubuntu-latest

env:
MIX_ENV: test

strategy:
matrix:
elixir: [1.17.0]
elixir: [1.18.1]
otp: [27.0]

steps:
Expand Down
30 changes: 0 additions & 30 deletions .github/workflows/release.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ result
# Nix files
result

# LSP files
.elixir_ls/
.elixir-tools/
.lexical/
140 changes: 140 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# Changelog

All notable changes to this project are documented in this file.

## [0.6.0] - 2025-01-10
### Added
- Enhanced HTTP handling with support for custom headers, streaming, and centralized error management.
- Improved test coverage and added dependency `mox` for mocking.
- CI/CD pipeline improvements with caching for faster builds.

### Fixed
- Resolved header merging issues and inconsistencies in JSON error handling.

### Removed
- Dropped `manage_clients` option; explicit OTP management required.

### Issues
- Fixed "[Fetcher] Extract error parsing to its own module" [#23](https://github.com/supabase-community/supabase-ex/issues/23)
- Fixed "Unable to pass `auth` key inside options to `init_client`" [#45](https://github.com/supabase-community/supabase-ex/issues/45)
- Fixed "Proposal to refactor and simplify the `Supabase.Fetcher` module" [#51](https://github.com/supabase-community/supabase-ex/issues/51)
- Fixed "Invalid Unicode error during file uploads (affets `storage-ex`)" [#52](https://github.com/supabase-community/supabase-ex/issues/52)

---

## [0.5.1] - 2024-09-21
### Added
- Improved error handling for HTTP fetch operations.
- Added optional retry policies for idempotent requests.

### Fixed
- Resolved race conditions in streaming functionality.

---

## [0.5.0] - 2024-09-21
### Added
- Support for direct file uploads to cloud storage.
- Enhanced real-time subscription management.

### Fixed
- Corrected WebSocket reconnection logic under high load.

---

## [0.4.1] - 2024-08-30
### Changed
- Performance optimizations in JSON encoding and decoding.
- Improved logging for debugging.

### Fixed
- Addressed memory leaks in connection pooling.

---

## [0.4.0] - 2024-08-30
### Added
- Introduced WebSocket monitoring tools.
- Support for encrypted token storage.

---

## [0.3.7] - 2024-05-14
### Added
- Initial implementation of streaming API for large datasets.

### Fixed
- Bug fixes in the pagination logic.

---

## [0.3.6] - 2024-04-28
### Added
- Experimental support for Ecto integration.

---

## [0.3.5] - 2024-04-21
### Fixed
- Addressed intermittent crashes when initializing connections.

---

## [0.3.4] - 2024-04-21
### Changed
- Optimized internal handling of database transactions.

---

## [0.3.3] - 2024-04-21
### Added
- Support for preflight HTTP requests.

---

## [0.3.2] - 2024-04-16
### Fixed
- Resolved issues with JSON payload validation.

---

## [0.3.1] - 2024-04-15
### Fixed
- Resolved inconsistent query results in edge cases.

---

## [0.3.0] - 2023-11-20
### Added
- Major refactor introducing modular architecture.
- Support for real-time database change notifications.

---

## [0.2.3] - 2023-10-11
### Fixed
- Patched security vulnerabilities in session handling.

---

## [0.2.2] - 2023-10-10
### Added
- Middleware support for request customization.

---

## [0.2.1] - 2023-10-10
### Fixed
- Corrected behavior for long-lived connections.

---

## [0.2.0] - 2023-10-05
### Added
- Initial implementation of role-based access control.

---

## [0.1.0] - 2023-09-18
### Added
- Initial release with core features: database access, authentication, and storage support.
63 changes: 46 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Where the magic starts!

> [!WARNING]
> This project is still in high development, expect breaking changes.
> This project is still in high development, expect breaking changes and unexpected behaviour.

## Getting Started

Expand All @@ -13,14 +13,22 @@ This repository contains a few examples with sample apps to help you get started

#### Gotrue/Auth examples

TODO

<!--
- [Plug based auth](https://github.com/zoedsoupe/supabase-ex/tree/main/examples/auth/plug)
- [Phoenix LiveView based auth](https://github.com/zoedsoupe/supabase-ex/tree/main/examples/auth/phoenix_live_view)
- [User management](https://github.com/zoedsoupe/supabase-ex/tree/main/examples/auth/user_management)
-->

#### Storage examples

TODO

<!--
- [Plug based upload](https://github.com/zoedsoupe/supabase-ex/tree/main/examples/storage/plug)
- [Phoenix LiveView upload](https://github.com/zoedsoupe/supabase-ex/tree/main/examples/storage/phoenix_live_view)
-->

### Installation

Expand All @@ -39,9 +47,9 @@ end
This library per si is the base foundation to user Supabase services from Elixir, so to integrate with specific services you need to add each client library you want to use.

Available client services are:
- [PostgREST](https://github.com/zoedsoupe/postgres-ex)
- [Storage](https://github.com/zoedsoupe/storage-ex)
- [Auth/GoTrue](https://github.com/zoedsoupe/gotrue-ex)
- [PostgREST](https://github.com/supabase-community/postgres-ex)
- [Storage](https://github.com/supabase-community/storage-ex)
- [Auth/GoTrue](https://github.com/supabase-community/auth-ex)

So if you wanna use the Storage and Auth/GoTrue services, your `mix.exs` should look like that:

Expand All @@ -51,6 +59,7 @@ def deps do
{:supabase_potion, "~> 0.5"}, # base SDK
{:supabase_storage, "~> 0.3"}, # storage integration
{:supabase_gotrue, "~> 0.3"}, # auth integration
{:supabase_postgrest, "~> 0.2"}, # postgrest integration
]
end
```
Expand All @@ -61,10 +70,9 @@ A `Supabase.Client` holds general information about Supabase, that can be used t

`Supabase.Client` is defined as:

- `:conn` - connection information, the only required option as it is vital to the `Supabase.Client`.
- `:base_url` - The base url of the Supabase API, it is usually in the form `https://<app-name>.supabase.io`.
- `:api_key` - The API key used to authenticate requests to the Supabase API.
- `:access_token` - Token with specific permissions to access the Supabase API, it is usually the same as the API key.
- `:base_url` - The base url of the Supabase API, it is usually in the form `https://<app-name>.supabase.io`.
- `:api_key` - The API key used to authenticate requests to the Supabase API.
- `:access_token` - Token with specific permissions to access the Supabase API, it is usually the same as the API key.
- `:db` - default database options
- `:schema` - default schema to use, defaults to `"public"`
- `:global` - global options config
Expand All @@ -75,7 +83,6 @@ A `Supabase.Client` holds general information about Supabase, that can be used t
- `:detect_session_in_url` - detect session in URL, defaults to `true`
- `:flow_type` - authentication flow type, defaults to `"web"`
- `:persist_session` - persist session, defaults to `true`
- `:storage` - storage type
- `:storage_key` - storage key

### Usage
Expand All @@ -93,13 +100,19 @@ iex> Supabase.init_client("https://<supabase-url>", "<supabase-api-key>")
iex> {:ok, %Supabase.Client{}}
```

Any additional config can be passed as the third argument:
Any additional config can be passed as the third argument as an [Enumerable](https://hexdocs.pm/elixir/Enumerable.html):

```elixir
iex> Supabase.init_client("https://<supabase-url>", "<supabase-api-key>", %{db: %{schema: "another"}}})
iex> Supabase.init_client("https://<supabase-url>", "<supabase-api-key>",
db: [schema: "another"],
auth: [flow_type: :pkce],
global: [headers: %{"custom-header" => "custom-value"}]
)
iex> {:ok, %Supabase.Client{}}
```

> Note that one off clients are just raw elixir structs and therefore don't manage any state

For more information on the available options, see the [Supabase.Client](https://hexdocs.pm/supabase_potion/Supabase.Client.html) module documentation.

> There's also a bang version of `Supabase.init_client/3` that will raise an error if the client can't be created.
Expand Down Expand Up @@ -139,27 +152,31 @@ If you don't have experience with processes or is a Elixir begginner, you should
- [GenServer getting started](https://hexdocs.pm/elixir/genservers.html)
- [Supervison trees getting started](https://hexdocs.pm/elixir/supervisor-and-application.html)

So, to define a self managed client, you need to define a module that will hold the client state and the client process.
So, to define a self managed client, you need to define a module that will hold the client state and the client process as an [Agent](https://hexdocs.pm/elixir/Agent.html).

```elixir
defmodule MyApp.Supabase.Client do
use Supabase.Client, otp_app: :my_app
end
```

For that to work, you also need to configure the client in your `config.exs`:
For that to work, you also need to configure the client in your app configuration, it can be a compile-time config on `config.exs` or a runtime config in `runtime.exs`:

```elixir
import Config

# `:my_app` here is the same `otp_app` option you passed
config :my_app, MyApp.Supabase.Client,
base_url: "https://<supabase-url>", # required
api_key: "<supabase-api-key>", # required
conn: %{access_token: "<supabase-token>"}, # optional
db: %{schema: "another"} # additional options
access_token: "<supabase-token>", # optional
# additional options
db: [schema: "another"],
auth: [flow_type: :implicit, debug: true],
global: [headers: %{"custom-header" => "custom-value"}]
```

Then, you can start the client process in your application supervision tree:
Then, you can start the client process in your application supervision tree, generally in your `application.ex` module:

```elixir
defmodule MyApp.Application do
Expand All @@ -176,15 +193,27 @@ defmodule MyApp.Application do
end
```

> Of course, you can spawn as many clients you wanna, with different configurations if you need

Now you can interact with the client process:

```elixir
iex> {:ok, %Supabase.Client{} = client} = MyApp.Supabase.Client.get_client()
iex> Supabase.GoTrue.sign_in_with_password(client, email: "", password: "")
```

You can also update the `access_token` for it:

```elixir
iex> {:ok, %Supabase.Client{} = client} = MyApp.Supabase.Client.get_client()
iex> client.access_token == client.api_key
iex> :ok = MyApp.Supabase.Client.set_auth("new-access-token")
iex> {:ok, %Supabase.Client{} = client} = MyApp.Supabase.Client.get_client()
iex> client.access_token == "new-access-token"
```

For more examples on how to use the client, check clients implementations docs:
- [Supabase.GoTrue](https://hexdocs.pm/supabase_go_true)
- [Supabase.GoTrue](https://hexdocs.pm/supabase_gotrue)
- [Supabase.Storage](https://hexdocs.pm/supabase_storage)
- [Supabase.PostgREST](https://hexdocs.pm/supabase_postgrest)

Expand Down
Loading
Loading