Skip to content

Commit

Permalink
feat: move integrations to separate repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
zoedsoupe committed Jan 13, 2024
1 parent 1f54ec8 commit 5b968d0
Show file tree
Hide file tree
Showing 82 changed files with 160 additions and 4,316 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: ci

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
env:
GHCR_USERNAME: ${{ github.actor }}
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
FORCE_COLOR: 1
steps:
- uses: actions/checkout@v3
- name: Put back the git branch into git (Earthly uses it for tagging)
run: |
branch=""
if [ -n "$GITHUB_HEAD_REF" ]; then
branch="$GITHUB_HEAD_REF"
else
branch="${GITHUB_REF##*/}"
fi
git checkout -b "$branch" || true
- name: Docker Login
run: docker login https://ghcr.io --username "$GHCR_USERNAME" --password "$GHCR_TOKEN"
- name: Download latest earthly
run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/latest/download/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"

- name: Earthly version
run: earthly --version

- name: Run CI
run: earthly -P +ci

- name: Run Tests
run: earthly -P +test
17 changes: 4 additions & 13 deletions Earthfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
VERSION 0.7

ARG MIX_ENV=test

deps:
ARG ELIXIR=1.15.7
ARG OTP=26.1.2
ARG MIX_ENV=test
FROM hexpm/elixir:${ELIXIR}-erlang-${OTP}-alpine-3.17.5
RUN apk add --no-cache build-base
WORKDIR /src
RUN mix local.rebar --force
RUN mix local.hex --force
COPY mix.exs mix.lock ./
COPY --dir apps . # check .earthlyignore
COPY --dir lib . # check .earthlyignore
RUN mix deps.get
RUN mix deps.compile --force
RUN mix compile
Expand All @@ -28,15 +29,5 @@ ci:
test:
FROM +deps
COPY mix.exs mix.lock ./
COPY --dir apps ./
COPY --dir lib ./
RUN mix test

docker:
FROM +deps
ENV MIX_ENV=dev
RUN mix deps.compile
COPY --dir apps ./
RUN mix compile
CMD ["iex", "-S", "mix"]
ARG GITHUB_REPO=zoedsoupe/supabase
SAVE IMAGE --push ghcr.io/$GITHUB_REPO:dev
144 changes: 59 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
# Supabase Elixir SDK
# Supabase Potion

[![Hex.pm](https://img.shields.io/hexpm/v/supabase_potion.svg)](https://hex.pm/packages/supabase_potion)
[![Downloads](https://img.shields.io/hexpm/dt/supabase_potion.svg)](https://hex.pm/packages/supabase_potion)
[![Documentation](https://img.shields.io/badge/documentation-gray)](https://hexdocs.pm/supabase_potion)
[![lint](https://github.com/zoedsoupe/supabase/actions/workflows/lint.yml/badge.svg)](https://github.com/zoedsoupe/supabase/actions/workflows/lint.yml)
[![test](https://github.com/zoedsoupe/supabase/actions/workflows/test.yml/badge.svg)](https://github.com/zoedsoupe/supabase/actions/workflows/test.yml)

> Complete SDK and APIs integrations with Supabase
This monorepo houses the collection of Elixir SDK packages for integrating with Supabase, the open-source Firebase alternative. Our goal is to offer developers a seamless integration experience with Supabase services using Elixir.

## Packages Overview

- **Supabase Potion**: Main entrypoint for the Supabase SDK library, providing easy management for Supabase clients and connections. [Guide](./apps/supabase_potion/README.md).
- **Supabase Storage**: Offers developers a way to store large objects like images, videos, and other files. [Guide](./guides/storage.md)
- **Supabase PostgREST**: Directly turns your PostgreSQL database into a RESTful API using PostgREST. [Guide](#)
- **Supabase Realtime**: Provides a realtime websocket API, enabling listening to database changes. [Guide](#)
- **Supabase Auth**: A comprehensive user authentication system, complete with email sign-in, password recovery, session management, and more. [Guide](./apps/supabase_auth/README.md)
- **Supabase UI**: UI components to help build Supabase-powered applications quickly. [Guide](#)
- **Supabase Fetcher**: Customized HTTP client for making requests to Supabase APIs. [Guide](./guides/fetcher.md)
Where the magic starts!

## Getting Started

Expand All @@ -34,89 +16,81 @@ def deps do
end
```

Then you can each package for the service you want to use. For example, if you want to use only the `Storage` integration:

```elixir
def deps do
[
{:supabase_potion, "~> 0.3"},
{:supabase_storage, "~> 0.2"}
]
end
```

## Starting a Client

```elixir
iex> Supabase.Client.init_client!(%{conn: %{base_url: "<supa-url>", api_key: "<supa-key>"}, name: MyClient})
{:ok, #PID<0.123.0>}
```

For more information, refer to the [supabase_potion](./apps/supabase_potion/README.md) readme!

## Supabase Services

The Supabase Elixir SDK allows you to interact with various Supabase services:

### Supabase Storage

Supabase Storage is a service for storing large objects like images, videos, and other files. It provides a simple API with strong consistency, similar to AWS S3.

### Supabase PostgREST

PostgREST is a web server that turns your PostgreSQL database into a RESTful API. It automatically generates API endpoints and operations based on your database's structure and permissions.

### Supabase Realtime
### Clients

Supabase Realtime offers a realtime WebSocket API powered by PostgreSQL notifications. You can use it to listen to changes in your database and receive updates instantly as they happen.
A `Supabase.Client` is an Agent that holds general information about Supabase, that can be used to intereact with any of the children integrations, for example: `Supabase.Storage` or `Supabase.UI`.

### Supabase Auth
`Supabase.Client` is defined as:

Supabase Auth is a comprehensive user authentication system that includes features like email and password sign-in, email verification, password recovery, session management, and more, out of the box.
- `:name` - the name of the client, started by `start_link/1`
- `: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.
- `:db` - default database options
- `:schema` - default schema to use, defaults to `"public"`
- `:global` - global options config
- `:headers` - additional headers to use on each request
- `:auth` - authentication options
- `:auto_refresh_token` - automatically refresh the token when it expires, defaults to `true`
- `:debug` - enable debug mode, defaults to `false`
- `: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

### Supabase UI
## Usage

Supabase UI provides a set of UI components to help you build Supabase-powered applications quickly. It's built on top of Tailwind CSS and Headless UI, and it's fully customizable. The package even includes `Phoenix.LiveView` components!
The Supabase Elixir SDK provides a flexible way to manage `Supabase.Client` instances, which can, in turn, manage multiple `Supabase.Client` instances. Here's a brief overview of the key concepts:

### Supabase Fetcher
### Starting a Client

Supabase Fetcher is a customized HTTP client for Supabase, mainly used in Supabase Potion. It gives you complete control over how you make requests to any Supabase API.

## General Roadmap

If you want to track integration-specific roadmaps, check their own README.

- [x] Fetcher to interact with the Supabase API in a low-level way
- [x] Supabase Storage integration
- [ ] Supabase UI for Phoenix Live View
- [ ] Supabase Postgrest integration
- [x] Supabase Auth integration
- [ ] Supabase Realtime API integration
You can start a client using the `Supabase.Client.start_link/1` function. However, it's recommended to use `Supabase.init_client!/1`, which allows you to pass client options and automatically manage `Supabase.Client` processes.

```elixir
iex> Supabase.Client.init_client!(%{conn: %{base_url: "<supa-url>", api_key: "<supa-key>"}})
{:ok, #PID<0.123.0>}
```

## Why another Supabase package?
## Configuration

Well, I tried to to use the [supabase-elixir](https://github.com/treebee/supabase-elixir) package but I had some strange behaviour and it didn't match some requirements of my project. So I started to search about Elixir-Supabase integrations and found some old, non-maintained packages that doesn't match some Elixir "idioms" and don't leverage the BEAM for a more integrated experience.
Ensure your Supabase configurations are set:

Also I would like to contribute to OSS in some way and gain more experience with the BEAM and HTTP integrations too. So feel free to not to use, give some counter arguments and also contribute to these packages!
```elixir
import Config

## Credits & Inspirations
config :supabase,
manage_clients: false,
supabase_base_url: System.fetch_env!("SUPABASE_BASE_URL"),
supabase_api_key: System.fetch_env!("SUPABASE_API_KEY"),
```

- [supabase-elixir](https://github.com/treebee/supabase-elixir)
- [storage-js](https://github.com/supabase/storage-js)
- `supabase_base_url`: The base URL of your Supabase project! More information on how to find it can be seen on the [next section](#how-to-find-my-supabase-base-url?)
- `supabase_api_key`: The secret of your Supabase project! More information on how to find it can be seen on the [next section](#how-to-find-my-supabase-api-key?)
- `manage_clients`: Enable or disable the internal client management by the library. Defauls to `true`, see more on the [library supervisor documentation](https://hexdocs.pm/supabase_potion/Supabase.ClientSupervisor.html).

## Contributing
Make sure to set the environment variables `SUPABASE_BASE_URL` and `SUPABASE_API_KEY`.

Contributions, issues, and feature requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
### How to find my Supabase base URL?

## Acknowledgements
You can find your Supabase base URL in the Settings page of your project.
Firstly select your project from the initial Dashboard.
On the left sidebar, click on the Settings icon, then select API.
The base URL is the first field on the page.

This SDK is a comprehensive representation of Supabase's client integrations. Thanks to the Supabase community for their support and collaboration.
### How to find my Supabase API Key?

## License
You can find your Supabase API key in the Settings page of your project.
Firstly select your project from the initial Dashboard.
On the left sidebar, click on the Settings icon, then select API.
The API key is the second field on the page.

[MIT](LICENSE)
There two types of API keys, the public and the private. The last one
bypass any Row Level Security (RLS) rules you have set up.
So you shouldn't use it in your frontend application.

---
If you don't know what RLS is, you can read more about it here:
https://supabase.com/docs/guides/auth/row-level-security

With the Supabase Elixir SDK, you have the tools you need to supercharge your Elixir applications by seamlessly integrating them with Supabase's powerful cloud services. Happy coding! 😄
For most cases you should prefer to use the public "anon" Key.
4 changes: 0 additions & 4 deletions apps/supabase_auth/.formatter.exs

This file was deleted.

40 changes: 0 additions & 40 deletions apps/supabase_auth/.gitignore

This file was deleted.

13 changes: 0 additions & 13 deletions apps/supabase_auth/LICENSE

This file was deleted.

1 change: 0 additions & 1 deletion apps/supabase_auth/README.md

This file was deleted.

41 changes: 0 additions & 41 deletions apps/supabase_auth/lib/supabase/go_true.ex

This file was deleted.

Loading

0 comments on commit 5b968d0

Please sign in to comment.