Skip to content

Commit 5d40e4b

Browse files
API V1 with database access (#280)
* Adding db-v1 with util-v1 in tow * impl list connectorConfig * Partial listConnections * Adding neon serverless * Add test for neon driver against local neon proxy * slight test reorg * Adding jose for jwt generation * Add generate and export keys * expose jwts.json wellknown endpoint * adding bun to dev * fix types * fix missing runtimeEnv * Remove circular dep * tp.ts localtest * Add some db scripts * Escape env pulled from vercel * fix tests * Unsuccessfully testing neon authorize * Debug test * fix env pull and test * add health check * Skip all neon test for now * even more latency checks * test out edge runtime * Revert "test out edge runtime" This reverts commit 6a1974b. * proper latency check * Get test passing again * verified we can use neon non-interactive transaction for RLS * neon serverless vs. neon http test * Final approach via direct drizzle proxy * Add neon proxy service to github action * Add db-rls package * add viewer into api-v1 * Add authentication test * Split out test-utils * Get rid of neon rls postgres variables * Update lockfile * Remove neon rls related changes * Removing even more irrelevant stuff * Upgrade drizzle version across the board * Move neon test * Separate entrypoint but single implementation multiple db implementations * Add DrizzleExtension type to standardize difference across different drizzle postgres drivers * Moving files around in db * fix db/index test * Add fallback generate_ulid using uuid since pgcrypto is not available in pglite * Add ; --> statement-breakpoint to init sql file * Add ; --> statement-breakpoint rest of files and get migration via pglite to pass finally * Test migration with both pglite and pg * Add dbFactory and additional extension on top of driver specific extensions * Move truncate to after * Extract db test utils * test fetch handlers separately from elysia * Finally got test for authorization logic working * Extract into test-utils * Fully removing db-v1 by incorporating it all into db * Remove util-v1 also for simplicity * Add event router * fix typing * Resolve issues * Optionally enable extension to fix db/index test * Increase memory allocation for linter and move it to the end * Try to fix test * Do more debugging * Fix db.localtest * debug --------- Co-authored-by: Amadeo Pellicce <[email protected]>
1 parent 1e3ed19 commit 5d40e4b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2393
-3286
lines changed

.github/workflows/validate-workflow.yml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,17 @@ jobs:
3838
# image: inngest/inngest
3939
# ports:
4040
# - 8288:8288
41+
neon-proxy:
42+
image: ghcr.io/timowilhelm/local-neon-http-proxy:main
43+
env:
44+
PG_CONNECTION_STRING: postgres://postgres:[email protected]:5432/test
45+
ports:
46+
- '4444:4444'
4147

4248
env:
43-
NODE_OPTIONS: --max-old-space-size=4096
49+
NODE_OPTIONS: --max-old-space-size=8192
4450
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
45-
DATABASE_URL: postgres://postgres:test@localhost:5432/test
51+
DATABASE_URL: postgres://postgres:test@db.localtest.me:5432/test
4652

4753
steps:
4854
- name: Checkout
@@ -51,7 +57,7 @@ jobs:
5157
- name: Install Node.js
5258
uses: actions/setup-node@v3
5359
with:
54-
node-version: 20 # TODO: Can we get this from "engine" field in package.json?
60+
node-version: 22 # TODO: Can we get this from "engine" field in package.json?
5561

5662
- uses: pnpm/action-setup@v4
5763
name: Install pnpm
@@ -83,14 +89,12 @@ jobs:
8389
- name: Run type checks
8490
run: pnpm run typecheck
8591

86-
- name: Run lint
87-
run: pnpm run lint
88-
8992
- name: Download dev env vars from Vercel
9093
run: |
9194
npm install --global vercel@latest
9295
vercel link --token $VERCEL_TOKEN --scope openint-dev --yes
93-
vercel env pull --token $VERCEL_TOKEN ./apps/web/.env.local
96+
vercel env pull --token $VERCEL_TOKEN ./apps/web/.env.local.orig
97+
cat ./apps/web/.env.local.orig | pnpm --silent bun scripts/escape-env.ts > ./apps/web/.env.local
9498
9599
- name: Run migration and store the completed schema
96100
# TODO: consider diffing schema with stored schema?
@@ -129,9 +133,15 @@ jobs:
129133
npx inngest-cli@latest dev &
130134
pnpm wait-on tcp:8288
131135
136+
- name: Setup upterm session
137+
uses: lhotari/action-upterm@v1
138+
132139
- name: Run tests
133140
run: ./bin/shdotenv -q -e ./apps/web/.env.local pnpm run test::ci
134141

142+
- name: Run lint
143+
run: pnpm run lint
144+
135145
- name: Send Slack notification for job status
136146
uses: 8398a7/action-slack@v3
137147
with:

apps/web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"@types/react-dom": "18.0.10",
6666
"@types/swagger2openapi": "7.0.0",
6767
"autoprefixer": "*",
68-
"drizzle-orm": "0.38.2",
68+
"drizzle-orm": "^0.39.1",
6969
"jiti": "*",
7070
"node-loader": "2.0.0",
7171
"postcss": "^8.4.47",

bin/tp.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ const name = [label, `${url.username}@${url.hostname}${port ? `:${port}` : ''}`]
8484

8585
const {label: _, ...options} = args.values
8686

87-
if (url.hostname === 'localhost' || url.hostname === '127.0.0.1') {
87+
if (
88+
url.hostname === 'localhost' ||
89+
url.hostname === '127.0.0.1' ||
90+
url.hostname.includes('localtest.me')
91+
) {
8892
options.env = options.env || 'local'
8993
options.statusColor = options.statusColor || '007F3D'
9094
options.safeModeLevel = '0'

connectors/connector-postgres/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"@openint/cdk": "workspace:*",
88
"@openint/db": "workspace:*",
99
"@openint/util": "workspace:*",
10-
"drizzle-kit": "^0.30.1",
11-
"drizzle-orm": "^0.38.2",
10+
"drizzle-kit": "^0.30.4",
11+
"drizzle-orm": "^0.39.1",
1212
"handlebars": "4.7.7",
1313
"json-stable-stringify": "^1.1.1",
1414
"postgres": "^3.4.5",

docker-compose.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ services:
1212
POSTGRES_DB: postgres # Only database named `postgres` works with pg_cron by default
1313
POSTGRES_PASSWORD: password
1414
command: ["postgres", "-c", "log_statement=all", "-c", "max_connections=500"]
15+
healthcheck:
16+
test: ['CMD-SHELL', 'pg_isready -U postgres']
17+
interval: 10s
18+
timeout: 5s
19+
retries: 5
1520

1621
supabase:
1722
image: supabase/postgres:15.8.1.017 # For some reason "lastest tag" is having issues... so we pin to a specific version latest as of 2024-12-20_0055
@@ -24,7 +29,17 @@ services:
2429
POSTGRES_PASSWORD: password
2530

2631
inngest:
27-
image: inngest/inngest
28-
command: 'inngest dev'
29-
ports:
30-
- '8288:8288'
32+
image: inngest/inngest
33+
command: 'inngest dev'
34+
ports:
35+
- '8288:8288'
36+
37+
neon-proxy:
38+
image: ghcr.io/timowilhelm/local-neon-http-proxy:main
39+
environment:
40+
PG_CONNECTION_STRING: postgres://postgres:password@postgres:5432/postgres
41+
ports:
42+
- '4444:4444'
43+
depends_on:
44+
postgres:
45+
condition: service_healthy

kits/cdk/viewer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export function getExtCustomerId(
101101
*/
102102
export const zJwtPayload = z.object({
103103
/** Different meaning in different contexts */
104-
sub: z.string(),
104+
sub: z.string().nullish(),
105105
/**
106106
* Jwt role is different from viewer role because supabase uses `authenticated`
107107
* by default and it's a bit too much work right now to switch to `user` so we shall
@@ -134,7 +134,7 @@ export const zViewerFromJwtPayload = zJwtPayload
134134
}
135135
// good reason to rename customer to customer
136136
case 'customer': {
137-
const [orgId, customerId] = payload.sub.split('/') as [
137+
const [orgId, customerId] = (payload.sub?.split('/') ?? []) as [
138138
Id['org'],
139139
CustomerId,
140140
]

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@
2121
"validate": "run-s --silent typecheck lint test",
2222
"openint": "tsx ./bin/openint",
2323
"migrate": "pnpm --dir ./packages/db migrate",
24-
"pgdump": "pg_dump --schema public --schema-only --no-owner --exclude-schema=graphile_migrate --file=packages/db/schema.sql $DATABASE_URL",
24+
"pgdump": "pg_dump --schema public --schema-only --no-owner --exclude-schema=graphile_migrate --file=packages/db/__generated__/schema.sql $DATABASE_URL",
2525
"worker:setup": "tsx ./bin/openint setupWorker",
2626
"worker:run": "tsx ./bin/openint runWorker",
27-
"env:pull": "vercel env pull --environment development .env.dev && vercel env pull --environment preview --git-branch $(git rev-parse --abbrev-ref HEAD) .env.pre && vercel env pull --environment production .env.prod"
27+
"env:pull:development": "vercel env pull --environment development .env.dev.orig && cat .env.dev.orig | pnpm --silent bun scripts/escape-env.ts > .env.dev",
28+
"env:pull:preview": "vercel env pull --environment preview --git-branch $(git rev-parse --abbrev-ref HEAD) .env.pre.orig && cat .env.pre.orig | pnpm --silent bun scripts/escape-env.ts > .env.pre",
29+
"env:pull:production": "vercel env pull --environment production .env.prod.orig && cat .env.prod.orig | pnpm --silent bun scripts/escape-env.ts > .env.prod",
30+
"env:pull": "run-s env:pull:*"
2831
},
2932
"lint-staged": {
3033
"**/*.{js,ts,tsx,json,css,yml,yaml}": "prettier --write",
@@ -45,6 +48,7 @@
4548
"@types/prettier": "3.0.0",
4649
"@typescript-eslint/eslint-plugin": "6.21.0",
4750
"@typescript-eslint/parser": "6.21.0",
51+
"bun": "latest",
4852
"esbuild": "0.17.5",
4953
"esbuild-jest": "0.5.0",
5054
"eslint": "8.23.0",

0 commit comments

Comments
 (0)