Skip to content

Commit

Permalink
API (#46)
Browse files Browse the repository at this point in the history
* wip

* Structure

* wip

* Deploy

* Deploy

* Deploy

* DB and config

* Add avatar

* Cascade

* Team invites

* Add api tokens

* Use better auth

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* remove kv

* wip

* wip

* wip

* wip
  • Loading branch information
pontusab authored Jan 2, 2025
1 parent 2259a30 commit c45a69c
Show file tree
Hide file tree
Showing 101 changed files with 4,885 additions and 604 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/production-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: 🌟 Production Deployment - API

on:
push:
branches:
- main
paths:
- apps/api/**
jobs:
deploy-production:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: 📦 Install dependencies
run: bun install
- name: 🔦 Run type checking
run: bun turbo typecheck --filter=@languine/api
- name: 🔬 Run linting
run: bun turbo lint --filter=@languine/api
- name: 🧪 Run unit tests
run: bun turbo test --filter=@languine/api
- name: 🗃️ Apply database migrations
uses: cloudflare/wrangler-action@v3
with:
packageManager: bun
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
workingDirectory: "apps/api"
wranglerVersion: "latest"
command: d1 migrations apply languine-production --env production --remote
- name: 🚀 Deploy Project Artifacts to Cloudflare
uses: cloudflare/wrangler-action@v3
with:
packageManager: bun
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
workingDirectory: "apps/api"
wranglerVersion: "latest"
command: deploy --minify src/index.ts --env production
10 changes: 6 additions & 4 deletions .github/workflows/main.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: 🚀 Release Production
name: 📦 Release Packages

on:
push:
branches:
- main
paths-ignore:
- 'apps/**'

jobs:
test:
Expand All @@ -18,8 +20,8 @@ jobs:
run: bun install
- name: 🔍 Run type checking
run: bun run typecheck
# - name: 🔬 Run linting
# run: bun run lint
- name: 🔬 Run linting
run: bun run lint
- name: 🧪 Run unit tests
run: bun run test

Expand All @@ -41,7 +43,7 @@ jobs:
run: bun install
- name: 🏗️ Build packages
run: bun turbo build --filter=languine --filter=@languine/react-email
- name: 🚀 Create and publish versions
- name: 🔖 Create and publish versions
uses: changesets/action@master
with:
version: bun run changeset version
Expand Down
37 changes: 36 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,39 @@ yarn-error.log*

dist

.react-email
.react-email


# prod
dist/

# dev
.yarn/
!.yarn/releases
.vscode/*
!.vscode/launch.json
!.vscode/*.code-snippets
.idea/workspace.xml
.idea/usage.statistics.xml
.idea/shelf

# deps
node_modules/
.wrangler

# env
.env
.env.production
.dev.vars

# logs
logs/
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

# misc
.DS_Store
3 changes: 3 additions & 0 deletions apps/api/.dev.vars-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RESEND_API_KEY=
BETTER_AUTH_SECRET="<your-secret-here>"
BETTER_AUTH_TRUSTED_ORIGINS="<server-origin-1>,<server-origin-2>"
Empty file added apps/api/README.md
Empty file.
14 changes: 14 additions & 0 deletions apps/api/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from "drizzle-kit";

export default defineConfig({
dialect: "sqlite",
driver: "d1-http",
out: "drizzle",
schema: "./src/db/schema.ts",
// Only needed for drizzle studio
// dbCredentials: {
// accountId: Bun.env.DB_ACCOUNT_ID!,
// databaseId: Bun.env.DB_DATABASE_ID!,
// token: Bun.env.DB_TOKEN!,
// },
});
82 changes: 82 additions & 0 deletions apps/api/drizzle/0000_swift_jocasta.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
CREATE TABLE `accounts` (
`id` text PRIMARY KEY NOT NULL,
`account_id` text NOT NULL,
`provider_id` text NOT NULL,
`user_id` text NOT NULL,
`access_token` text,
`refresh_token` text,
`id_token` text,
`access_token_expires_at` integer,
`refresh_token_expires_at` integer,
`scope` text,
`password` text,
`created_at` integer NOT NULL,
`updated_at` integer NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `invitations` (
`id` text PRIMARY KEY NOT NULL,
`organization_id` text NOT NULL,
`email` text NOT NULL,
`role` text,
`status` text NOT NULL,
`expires_at` integer NOT NULL,
`inviter_id` text NOT NULL,
FOREIGN KEY (`organization_id`) REFERENCES `organizations`(`id`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`inviter_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `members` (
`id` text PRIMARY KEY NOT NULL,
`organization_id` text NOT NULL,
`user_id` text NOT NULL,
`role` text NOT NULL,
`created_at` integer NOT NULL,
FOREIGN KEY (`organization_id`) REFERENCES `organizations`(`id`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `organizations` (
`id` text PRIMARY KEY NOT NULL,
`name` text NOT NULL,
`slug` text,
`logo` text,
`created_at` integer NOT NULL,
`metadata` text
);
--> statement-breakpoint
CREATE UNIQUE INDEX `organizations_slug_unique` ON `organizations` (`slug`);--> statement-breakpoint
CREATE TABLE `sessions` (
`id` text PRIMARY KEY NOT NULL,
`expires_at` integer NOT NULL,
`token` text NOT NULL,
`created_at` integer NOT NULL,
`updated_at` integer NOT NULL,
`ip_address` text,
`user_agent` text,
`user_id` text NOT NULL,
`active_organization_id` text,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE UNIQUE INDEX `sessions_token_unique` ON `sessions` (`token`);--> statement-breakpoint
CREATE TABLE `users` (
`id` text PRIMARY KEY NOT NULL,
`name` text NOT NULL,
`email` text NOT NULL,
`email_verified` integer NOT NULL,
`image` text,
`created_at` integer NOT NULL,
`updated_at` integer NOT NULL
);
--> statement-breakpoint
CREATE UNIQUE INDEX `users_email_unique` ON `users` (`email`);--> statement-breakpoint
CREATE TABLE `verifications` (
`id` text PRIMARY KEY NOT NULL,
`identifier` text NOT NULL,
`value` text NOT NULL,
`expires_at` integer NOT NULL,
`created_at` integer,
`updated_at` integer
);
Loading

0 comments on commit c45a69c

Please sign in to comment.