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

Headless Basejump migration #31

Merged
merged 78 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
6f7456a
Working towards supabase versions of all edge functions
tiniscule Apr 23, 2023
e8d3e24
Working towardsmigration billing functions to supabase
tiniscule Apr 23, 2023
625385d
Merge branch 'main' into supabase-functions
tiniscule Apr 25, 2023
2c2324a
cleanup edge functions
tiniscule May 10, 2023
74052a0
fix failing test
tiniscule May 10, 2023
3678826
Working plans edge function
tiniscule May 11, 2023
342948f
migrate tables into basejump schema and create public function calls
tiniscule May 21, 2023
011c1e3
Small fix to profiles schema
tiniscule May 21, 2023
64a5151
Tested database functions and v1 of edge functions
tiniscule May 29, 2023
998f471
Remove unused dependency
tiniscule May 29, 2023
9883797
Removed v1 basejump to prep for v2
tiniscule Jun 24, 2023
bd92086
Change team_name to name on accounts to prepare for removing profiles
tiniscule Jun 24, 2023
f3da07b
change deno packages dir
tiniscule Jun 24, 2023
04267c8
Working towards account selector edit
tiniscule Jun 25, 2023
45dfc5e
Working towards replacing profiles with personal accounts
tiniscule Jun 26, 2023
7a05b4a
Cleanup tests for new personal account handling
tiniscule Jun 26, 2023
7ef54da
Adding account members
tiniscule Jun 26, 2023
77d0071
Working towards edit account pages
tiniscule Jun 30, 2023
7359cd3
working towards release
tiniscule Aug 14, 2023
690fc28
Working towards installable release
tiniscule Aug 15, 2023
19ff0c0
add Stripe export to deps
tiniscule Aug 15, 2023
4f3819a
Resolve issue with re-exported renamed types in Deno
tiniscule Aug 15, 2023
76b0dc0
Remove type re-exports for now
tiniscule Aug 15, 2023
2c7863e
switch to all named exports
tiniscule Aug 15, 2023
10bcb50
no mas sync handler
tiniscule Aug 15, 2023
da74283
Working edge functions
tiniscule Aug 17, 2023
d89a652
Add additional testing to clear out TODO comments
tiniscule Aug 17, 2023
177921a
function updates
tiniscule Aug 18, 2023
5affe71
working towards react components being completed
tiniscule Aug 20, 2023
dd81773
working billing buttons in the react component library
tiniscule Aug 22, 2023
e47ae8f
working account invitation components
tiniscule Aug 24, 2023
6888d9c
Added friendlier error messages in a few cases
tiniscule Aug 24, 2023
2a5a422
Migrating ui components to basejump-js repo
tiniscule Aug 26, 2023
cee4659
migrate to new database.dev format
tiniscule Nov 26, 2023
4a02407
rename to make it easier to find
tiniscule Nov 26, 2023
ac7e719
Merge branch 'main' into supabase-functions
tiniscule Nov 26, 2023
a066e9d
Remove supabase folder from repo
tiniscule Nov 26, 2023
b71be8e
valid extension name
tiniscule Nov 26, 2023
213e138
add supabase test helpers
tiniscule Nov 26, 2023
52604a6
try installing dbdev inline
tiniscule Nov 26, 2023
f969fd9
move install to local file
tiniscule Nov 26, 2023
086eb79
enable extension for tests
tiniscule Nov 26, 2023
065d261
create not enable
tiniscule Nov 26, 2023
8a68e74
working enable
tiniscule Nov 26, 2023
52755b5
cleanup and working tests after extension move
tiniscule Nov 26, 2023
bce80b4
has to be created with extensions schema
tiniscule Nov 26, 2023
5a5a414
small changes and add tests
tiniscule Nov 27, 2023
3e8d3c2
cleanup tests to prepare for function tets
tiniscule Nov 27, 2023
6f786d8
check if types exist before creating, better support for future
tiniscule Nov 27, 2023
3f679f2
testing stripe functionality
tiniscule Dec 2, 2023
4eccda5
test unauthorized flows
tiniscule Dec 2, 2023
312cedb
Add test suites
tiniscule Dec 2, 2023
8d0b5cc
break out build form pg_tap
tiniscule Dec 2, 2023
3695420
split build and cache
tiniscule Dec 2, 2023
be9494b
remove action dependency
tiniscule Dec 2, 2023
945d927
check out
tiniscule Dec 2, 2023
394afec
dbdev workflow
tiniscule Dec 2, 2023
c0ba5f7
basic stripe tests
tiniscule Dec 2, 2023
926e60c
check for cache hit
tiniscule Dec 2, 2023
a9359c9
force
tiniscule Dec 2, 2023
5d8826a
combine tests and skip setup for now
tiniscule Dec 2, 2023
cb63f8d
restore to bin dir not nested
tiniscule Dec 2, 2023
a1bca40
executable
tiniscule Dec 2, 2023
2f19a7b
pg-tap dbdev executabel
tiniscule Dec 2, 2023
bb96709
add supabase env vars
tiniscule Dec 2, 2023
3af429f
stripe key
tiniscule Dec 2, 2023
b9576ae
add stripe token to webhook listen
tiniscule Dec 2, 2023
cb7cd1d
run webhook listener in same step
tiniscule Dec 2, 2023
8a316cb
don't require auth on webhooks endpoint
tiniscule Dec 2, 2023
3eac642
toml not yaml
tiniscule Dec 2, 2023
3343be5
config has to be on a newline
tiniscule Dec 2, 2023
7f9f9ff
cat out config
tiniscule Dec 2, 2023
46c990d
honor backslashes in echo
tiniscule Dec 2, 2023
97e5c71
add missing stripe env vars
tiniscule Dec 2, 2023
701f1a7
wrong env var for trial days
tiniscule Dec 2, 2023
2d01477
consolidate to PLAN_ID for tests
tiniscule Dec 2, 2023
95d9087
moving to just keeping deno functions nested in supabase dir to make …
tiniscule Dec 2, 2023
b83cc1e
move config out of table
tiniscule Dec 3, 2023
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
5 changes: 0 additions & 5 deletions .env.sample

This file was deleted.

7 changes: 0 additions & 7 deletions .eslintrc.json

This file was deleted.

2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

28 changes: 28 additions & 0 deletions .github/workflows/dbdev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build DBDev
on:
workflow_call:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Cache dbdev
id: cache-dbdev
uses: actions/cache@v2
with:
path: ~/.cargo/bin/dbdev
key: ${{ runner.os }}-dbdev

- name: Install dbdev
uses: actions-rs/cargo@v1
with:
command: install
args: --git https://github.com/supabase/dbdev.git dbdev --force
if: steps.cache-dbdev.outputs.cache-hit != 'true'
- name: Create build-output artifact
uses: actions/upload-artifact@master
with:
name: dbdev-output
path: ~/.cargo/bin/dbdev
16 changes: 0 additions & 16 deletions .github/workflows/pg_tests.yml

This file was deleted.

108 changes: 99 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,105 @@
name: Jest Tests and Linting
name: Tests
on:
pull_request:
branches: [ main ]
jobs:
build:
dbdev:
uses: ./.github/workflows/dbdev.yml
pg_tap_tests:
name: PGTap Tests
runs-on: ubuntu-latest
needs: dbdev
steps:
- uses: actions/checkout@v2
- name: Install modules
run: yarn install --frozen-lockfile
- name: Next Linting
run: yarn lint
- name: Run tests
run: yarn test
- name: Download DBDev
uses: actions/download-artifact@master
with:
name: dbdev-output
path: ~/.cargo/bin
- name: Make dbdev executable
run: chmod +x ~/.cargo/bin/dbdev
- uses: actions/checkout@v3
- uses: supabase/setup-cli@v1
with:
version: latest
- name: Supabase Start
run: supabase init && supabase start
- name: Install supabase_test_helpers from scripts/install-dbdev-with-test-helpers.sql (remove this once remote install enabled in dbdev CLI)
run: psql -v ON_ERROR_STOP=1 -U postgres -d postgres -h localhost -p 54322 -f ./scripts/install-dbdev-with-test-helpers.sql
env:
PGPASSWORD: postgres
- name: Install core extension using dbdev cli
run: |
~/.cargo/bin/dbdev install --connection postgres://postgres:postgres@localhost:54322/postgres --path .
psql -v ON_ERROR_STOP=1 -U postgres -d postgres -h localhost -p 54322 -c 'CREATE EXTENSION IF NOT EXISTS basejump_core with schema extensions;'
env:
PGPASSWORD: postgres
- name: Run Tests
run: supabase test db
stripe_tests:
name: Stripe Tests
runs-on: ubuntu-latest
needs: dbdev
steps:
- name: Download DBDev
uses: actions/download-artifact@master
with:
name: dbdev-output
path: ~/.cargo/bin
- name: Make dbdev executable
run: chmod +x ~/.cargo/bin/dbdev
- uses: actions/checkout@v3
- uses: supabase/setup-cli@v1
with:
version: latest
- name: Install stripe
run: |
# Download linux version as per Stripe documentation
curl -L https://github.com/stripe/stripe-cli/releases/download/v1.18.0/stripe_1.18.0_linux_x86_64.tar.gz --output stripe.tar.gz
# Unzip
tar -xvf stripe.tar.gz
- name: Create supabase/functions/.env including stripe webhook secrets
run: |
echo "STRIPE_WEBHOOK_SIGNING_SECRET=$(./stripe listen --print-secret)" >> supabase/functions/.env
echo "STRIPE_API_KEY=${{ secrets.STRIPE_API_KEY }}" >> supabase/functions/.env
echo "STRIPE_DEFAULT_PLAN_ID=${{ secrets.STRIPE_DEFAULT_PLAN_ID }}" >> supabase/functions/.env
echo "STRIPE_DEFAULT_TRIAL_DAYS=7" >> supabase/functions/.env
env:
STRIPE_API_KEY: ${{ secrets.STRIPE_API_KEY }}
STRIPE_DEFAULT_PLAN_ID: ${{ secrets.STRIPE_DEFAULT_PLAN_ID }}
- name: Setup and start Supabase
run: |
supabase init
echo -e "\n\n[functions.test-stripe-billing-webhooks]\nverify_jwt = false" >> supabase/config.toml
supabase start
- name: Install supabase_test_helpers from scripts/install-dbdev-with-test-helpers.sql (remove this once remote install enabled in dbdev CLI)
run: psql -v ON_ERROR_STOP=1 -U postgres -d postgres -h localhost -p 54322 -f ./scripts/install-dbdev-with-test-helpers.sql
env:
PGPASSWORD: postgres
- name: Install core extension using dbdev cli
run: |
~/.cargo/bin/dbdev install --connection postgres://postgres:postgres@localhost:54322/postgres --path .
psql -v ON_ERROR_STOP=1 -U postgres -d postgres -h localhost -p 54322 -c 'CREATE EXTENSION IF NOT EXISTS basejump_core with schema extensions;'
env:
PGPASSWORD: postgres
- name: Yarn install supabase/tests/integration
run: cd supabase/tests/integration && yarn --frozen-lockfile
- name: Install playwright browsers
run: cd supabase/tests/integration && yarn test:setup
- name: Run tests without webhooks
run: cd supabase/tests/integration && yarn test:invalid && yarn test:stripe-no-webhooks
env:
SUPABASE_URL: http://127.0.0.1:54321
SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}
STRIPE_API_KEY: ${{ secrets.STRIPE_API_KEY }}
STRIPE_DEFAULT_PLAN_ID: ${{ secrets.STRIPE_DEFAULT_PLAN_ID }}
STRIPE_DEFAULT_TRIAL_DAYS: 7
- name: Run tests with webhooks
run: |
./stripe listen --api-key ${{ secrets.STRIPE_API_KEY }} --forward-to http://127.0.0.1:54321/functions/v1/test-stripe-billing-webhooks &
cd supabase/tests/integration && yarn test:stripe-webhooks
env:
SUPABASE_URL: http://127.0.0.1:54321
SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}
STRIPE_API_KEY: ${{ secrets.STRIPE_API_KEY }}
STRIPE_DEFAULT_PLAN_ID: ${{ secrets.STRIPE_DEFAULT_PLAN_ID }}
STRIPE_DEFAULT_TRIAL_DAYS: 7
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

# project dependencies
.idea
.vscode

# dependencies
/node_modules
node_modules
/.pnp
.pnp.js

Expand Down Expand Up @@ -39,6 +41,6 @@ yarn-error.log*
*.tsbuildinfo
next-env.d.ts

# Supabase
**/supabase/.branches
**/supabase/.temp
# turbo
.turbo

10 changes: 0 additions & 10 deletions .vscode/settings.json

This file was deleted.

82 changes: 47 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,70 @@
# Basejump SaaS starter for Supabase
# Basejump

Basejump is an open source starter for Supabase. It provides personal accounts, shared team accounts, billing
subscriptions with Stripe and a dashboard template.
> If you're looking for the original Basejump which included a NextJS SaaS starter
> template, [check out the legacy repo](https://github.com/usebasejump/legacy-basejump-template).
Basejump adds personal accounts, team accounts, permissions and billing support to Supabase Auth.

[Learn more at usebasejump.com](https://usebasejump.com).

## Installation
## Features

```bash
yarn
yarn dev
```
- **Personal accounts**: Every user that signs up using Supabase auth automatically gets their own personal account.
Billing on personal accounts can be enabled/disabled.
- **Team accounts**: Team accounts are billable accounts that can be shared by multiple users. Team accounts can be
disabled if you only wish to allow personal accounts. Billing on team accounts can also be disabled.
- **Permissions**: Permissions are handled using RLS, just like you're used to with Supabase. Basejump provides
convenience methods that let you restrict access to rows based on a user's account access and role within an account
- **Billing**: Basejump provides out of the box billing support for Stripe, but you can add your own providers easily.
If you do, please consider contributing them so others can benefit!
- **Testing**: Basejump is fully tested itself, but also provides a suite of testing tools that make it easier to test
your own Supabase functions and schema. You can check it out
at [database.dev/basejump/supabase_test_helpers](https://database.dev/basejump/supabase_test_helpers). You do not need
to be using Basejump to use the testing tools.

## Typescript and generated types
## Quick Start (recommended)

We've implemented automatic type generation based off of your Supabase database config. You can learn more about this
setup [in the supabase docs on type generation](https://supabase.com/docs/guides/api/generating-types)
Check out the getting started guide at [usebasejump.com](https://usebasejump.com).

To update your types, run:
## Contributing

Yes please! Here's how you can get started locally

#### Initialize Supabase

```bash
yarn generate-types
supabase init && supabase start
```

You can then reference them as
#### Install dependencies using dbdev

```javascript
import Database from '@/types/supabase-types';
1. Install dbdev according to instructions on [database.dev](https://database.dev).
2. Install supabase_test_helpers

const profile: Database['public']['Tables']['profiles']['Row'] = {name: 'John Doe'};
```sql
select dbdev.install('basejump-supabase_test_helpers');
```

## Code Formatting and linting

The project is configured to use ESLint and Prettier. Prettier is run through ESLint, not on its own.
#### Install local version of basejump_core

* Prettier: [Prettier ESLint Plugin](https://github.com/prettier/eslint-plugin-prettier)
* ESLint: [NextJS ESLint](https://nextjs.org/docs/basic-features/eslint)
```bash
dbdev install --connection postgres://postgres:postgres@localhost:54322/postgres --path .
```

## Internationalizatoin and translations
#### Enable basejump_core

Basejump uses NextJS built in internationalization, and adds `next-translate` for translation support.
```sql
CREATE EXTENSION IF NOT EXISTS basejump_core with schema extensions;
```

* [NextJS Internationalization](https://nextjs.org/docs/basic-features/i18n)
* [next-translate](https://github.com/aralroca/next-translate)
#### Make sure tests can run

## Thanks & Credits
```bash
supabase test db
```

<p>Hosting has generously been provided by Vercel</p>
<a
href="https://vercel.com?utm_source=basejump&utm_campaign=oss"
target="_blank"
rel="noopener noreferrer"
>
<img src="public/images/vercel-logo.svg" alt="Powered by Vercel" />
</a>
### Add your changes and write tests.

Make sure you're following the database.dev upgrade guidelines. you should NEVER be updating/changing existing version
files. All changes should have valid migration files for postgres extensions. I'll try to flesh this section out more
later.
6 changes: 0 additions & 6 deletions __tests__/content/blog/en/article-1.md

This file was deleted.

9 changes: 0 additions & 9 deletions __tests__/content/blog/en/article-2.md

This file was deleted.

7 changes: 0 additions & 7 deletions __tests__/content/blog/en/unpublished-blog.md

This file was deleted.

7 changes: 0 additions & 7 deletions __tests__/content/docs/en/doc-2.md

This file was deleted.

10 changes: 0 additions & 10 deletions __tests__/content/docs/en/index.md

This file was deleted.

6 changes: 0 additions & 6 deletions __tests__/content/docs/en/unpublished-doc.md

This file was deleted.

Loading
Loading