diff --git a/packages/data/constants.ts b/packages/data/constants.ts index fe271da98fe..6745aa3118d 100644 --- a/packages/data/constants.ts +++ b/packages/data/constants.ts @@ -57,7 +57,6 @@ export const OLD_LENS_RELAYER_ADDRESS = // URLs export const STATIC_ASSETS_URL = 'https://static-assets.lenster.xyz'; -export const SUPABASE_URL = 'https://nberpnnqcqfnrzjpnisb.supabase.co'; export const LENS_MEDIA_SNAPSHOT_URL = 'https://ik.imagekit.io/lens/media-snapshot'; export const STATIC_IMAGES_URL = `${STATIC_ASSETS_URL}/images`; diff --git a/packages/supabase/.eslintrc.js b/packages/supabase/.eslintrc.js new file mode 100644 index 00000000000..bb90ebe3548 --- /dev/null +++ b/packages/supabase/.eslintrc.js @@ -0,0 +1,3 @@ +module.exports = { + extends: [require.resolve('@lenster/config/eslint/base.js')] +}; diff --git a/packages/supabase/constants.ts b/packages/supabase/constants.ts new file mode 100644 index 00000000000..caa08767482 --- /dev/null +++ b/packages/supabase/constants.ts @@ -0,0 +1 @@ +export const SUPABASE_URL = 'https://nberpnnqcqfnrzjpnisb.supabase.co'; diff --git a/packages/supabase/createSupabaseClient.ts b/packages/supabase/createSupabaseClient.ts new file mode 100644 index 00000000000..8219e597061 --- /dev/null +++ b/packages/supabase/createSupabaseClient.ts @@ -0,0 +1,11 @@ +import { createClient } from '@supabase/supabase-js'; + +import { SUPABASE_URL } from './constants'; +// @ts-ignore +import type { Database } from './database.types'; + +const createSupabaseClient = (key: string) => { + return createClient(SUPABASE_URL, key); +}; + +export default createSupabaseClient; diff --git a/packages/workers/preferences/src/database.types.ts b/packages/supabase/database.types.ts similarity index 96% rename from packages/workers/preferences/src/database.types.ts rename to packages/supabase/database.types.ts index 1f62fa3e5b6..87ab446522e 100644 --- a/packages/workers/preferences/src/database.types.ts +++ b/packages/supabase/database.types.ts @@ -12,7 +12,6 @@ export interface Database { channels: { Row: { avatar: string; - cover: string; description: string; id: string; name: string; @@ -21,7 +20,6 @@ export interface Database { }; Insert: { avatar: string; - cover: string; description: string; id?: string; name: string; @@ -30,7 +28,6 @@ export interface Database { }; Update: { avatar?: string; - cover?: string; description?: string; id?: string; name?: string; diff --git a/packages/supabase/package.json b/packages/supabase/package.json new file mode 100644 index 00000000000..2ce999959e3 --- /dev/null +++ b/packages/supabase/package.json @@ -0,0 +1,21 @@ +{ + "name": "@lenster/supabase", + "version": "0.0.0", + "private": true, + "license": "AGPL-3.0", + "scripts": { + "codegen": "supabase gen types typescript --project-id nberpnnqcqfnrzjpnisb > database.types.ts; pnpm lint:fix", + "lint": "eslint . --ext .ts", + "lint:fix": "eslint . --fix --ext .ts", + "prettier": "prettier --check \"**/*.{js,ts,tsx,md}\" --cache", + "prettier:fix": "prettier --write \"**/*.{js,ts,tsx,md}\" --cache", + "typecheck": "tsc --pretty" + }, + "dependencies": { + "@supabase/supabase-js": "^2.33.1" + }, + "devDependencies": { + "@lenster/config": "workspace:*", + "typescript": "^5.2.2" + } +} diff --git a/packages/supabase/tsconfig.json b/packages/supabase/tsconfig.json new file mode 100644 index 00000000000..bb1c907b3cc --- /dev/null +++ b/packages/supabase/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "@lenster/config/base.tsconfig.json" +} diff --git a/packages/workers/channels/package.json b/packages/workers/channels/package.json index 16a831040d1..87360aa4c54 100644 --- a/packages/workers/channels/package.json +++ b/packages/workers/channels/package.json @@ -4,7 +4,6 @@ "private": true, "license": "AGPL-3.0", "scripts": { - "codegen": "supabase gen types typescript --project-id nberpnnqcqfnrzjpnisb > src/database.types.ts; pnpm lint:fix", "dev": "wrangler dev --port 8093", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --fix --ext .ts", @@ -16,8 +15,8 @@ "dependencies": { "@lenster/data": "workspace:*", "@lenster/lib": "workspace:*", + "@lenster/supabase": "workspace:*", "@sentry/tracing": "^7.66.0", - "@supabase/supabase-js": "^2.33.1", "itty-router": "^4.0.22", "toucan-js": "^3.2.3", "zod": "^3.22.2" diff --git a/packages/workers/channels/src/handlers/allChannels.ts b/packages/workers/channels/src/handlers/allChannels.ts index c525a0bd9fc..a5c98b2d954 100644 --- a/packages/workers/channels/src/handlers/allChannels.ts +++ b/packages/workers/channels/src/handlers/allChannels.ts @@ -1,8 +1,8 @@ import '@sentry/tracing'; import response from '@lenster/lib/response'; +import createSupabaseClient from '@lenster/supabase/createSupabaseClient'; -import createSupabaseClient from '../helpers/createSupabaseClient'; import type { WorkerRequest } from '../types'; export default async (request: WorkerRequest) => { @@ -14,7 +14,7 @@ export default async (request: WorkerRequest) => { const cache = await request.env.CHANNELS.get('channels-list'); if (!cache) { - const client = createSupabaseClient(request.env); + const client = createSupabaseClient(request.env.SUPABASE_KEY); const { data } = await client.from('channels').select('*'); await request.env.CHANNELS.put('channels-list', JSON.stringify(data)); diff --git a/packages/workers/channels/src/helpers/createSupabaseClient.ts b/packages/workers/channels/src/helpers/createSupabaseClient.ts deleted file mode 100644 index 3ef2d7a2abb..00000000000 --- a/packages/workers/channels/src/helpers/createSupabaseClient.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { SUPABASE_URL } from '@lenster/data/constants'; -import { createClient } from '@supabase/supabase-js'; - -// @ts-ignore -import type { Database } from '../database.types'; -import type { Env } from '../types'; - -const createSupabaseClient = (env: Env) => { - return createClient(SUPABASE_URL, env.SUPABASE_KEY); -}; - -export default createSupabaseClient; diff --git a/packages/workers/preferences/package.json b/packages/workers/preferences/package.json index 23c687dc8f4..509fded8b1e 100644 --- a/packages/workers/preferences/package.json +++ b/packages/workers/preferences/package.json @@ -4,7 +4,6 @@ "private": true, "license": "AGPL-3.0", "scripts": { - "codegen": "supabase gen types typescript --project-id nberpnnqcqfnrzjpnisb > src/database.types.ts; pnpm lint:fix", "dev": "wrangler dev --port 8092", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --fix --ext .ts", @@ -16,8 +15,8 @@ "dependencies": { "@lenster/data": "workspace:*", "@lenster/lib": "workspace:*", + "@lenster/supabase": "workspace:*", "@sentry/tracing": "^7.66.0", - "@supabase/supabase-js": "^2.33.1", "@tsndr/cloudflare-worker-jwt": "^2.2.2", "itty-router": "^4.0.22", "toucan-js": "^3.2.3", diff --git a/packages/workers/preferences/src/handlers/getPreferences.ts b/packages/workers/preferences/src/handlers/getPreferences.ts index edf5506421c..44ee575bc0e 100644 --- a/packages/workers/preferences/src/handlers/getPreferences.ts +++ b/packages/workers/preferences/src/handlers/getPreferences.ts @@ -2,8 +2,8 @@ import '@sentry/tracing'; import { Errors } from '@lenster/data/errors'; import response from '@lenster/lib/response'; +import createSupabaseClient from '@lenster/supabase/createSupabaseClient'; -import createSupabaseClient from '../helpers/createSupabaseClient'; import type { WorkerRequest } from '../types'; export default async (request: WorkerRequest) => { @@ -18,7 +18,7 @@ export default async (request: WorkerRequest) => { } try { - const client = createSupabaseClient(request.env); + const client = createSupabaseClient(request.env.SUPABASE_KEY); const { data } = await client .from('rights') diff --git a/packages/workers/preferences/src/handlers/getVerified.ts b/packages/workers/preferences/src/handlers/getVerified.ts index 97c3fd1f9eb..0c77be5fa95 100644 --- a/packages/workers/preferences/src/handlers/getVerified.ts +++ b/packages/workers/preferences/src/handlers/getVerified.ts @@ -1,8 +1,8 @@ import '@sentry/tracing'; import response from '@lenster/lib/response'; +import createSupabaseClient from '@lenster/supabase/createSupabaseClient'; -import createSupabaseClient from '../helpers/createSupabaseClient'; import type { WorkerRequest } from '../types'; export default async (request: WorkerRequest) => { @@ -14,7 +14,7 @@ export default async (request: WorkerRequest) => { const cache = await request.env.PREFERENCES.get('verified-list'); if (!cache) { - const client = createSupabaseClient(request.env); + const client = createSupabaseClient(request.env.SUPABASE_KEY); const { data } = await client .from('rights') diff --git a/packages/workers/preferences/src/handlers/updateGardenerMode.ts b/packages/workers/preferences/src/handlers/updateGardenerMode.ts index fe25111ba08..e5f0c481ec3 100644 --- a/packages/workers/preferences/src/handlers/updateGardenerMode.ts +++ b/packages/workers/preferences/src/handlers/updateGardenerMode.ts @@ -4,10 +4,10 @@ import { Errors } from '@lenster/data/errors'; import hasOwnedLensProfiles from '@lenster/lib/hasOwnedLensProfiles'; import response from '@lenster/lib/response'; import validateLensAccount from '@lenster/lib/validateLensAccount'; +import createSupabaseClient from '@lenster/supabase/createSupabaseClient'; import jwt from '@tsndr/cloudflare-worker-jwt'; import { boolean, object, string } from 'zod'; -import createSupabaseClient from '../helpers/createSupabaseClient'; import type { WorkerRequest } from '../types'; type ExtensionRequest = { @@ -57,7 +57,7 @@ export default async (request: WorkerRequest) => { ); } - const client = createSupabaseClient(request.env); + const client = createSupabaseClient(request.env.SUPABASE_KEY); const { data, error } = await client .from('rights') diff --git a/packages/workers/preferences/src/handlers/updatePreferences.ts b/packages/workers/preferences/src/handlers/updatePreferences.ts index d9ecddbcf63..c9eb3816298 100644 --- a/packages/workers/preferences/src/handlers/updatePreferences.ts +++ b/packages/workers/preferences/src/handlers/updatePreferences.ts @@ -5,10 +5,10 @@ import { adminAddresses } from '@lenster/data/staffs'; import hasOwnedLensProfiles from '@lenster/lib/hasOwnedLensProfiles'; import response from '@lenster/lib/response'; import validateLensAccount from '@lenster/lib/validateLensAccount'; +import createSupabaseClient from '@lenster/supabase/createSupabaseClient'; import jwt from '@tsndr/cloudflare-worker-jwt'; import { boolean, object, string } from 'zod'; -import createSupabaseClient from '../helpers/createSupabaseClient'; import type { WorkerRequest } from '../types'; type ExtensionRequest = { @@ -83,7 +83,7 @@ export default async (request: WorkerRequest) => { ); } - const client = createSupabaseClient(request.env); + const client = createSupabaseClient(request.env.SUPABASE_KEY); const { data, error } = await client .from('rights') diff --git a/packages/workers/preferences/src/handlers/updateStaffMode.ts b/packages/workers/preferences/src/handlers/updateStaffMode.ts index 6dd8670fa75..b0efea4980a 100644 --- a/packages/workers/preferences/src/handlers/updateStaffMode.ts +++ b/packages/workers/preferences/src/handlers/updateStaffMode.ts @@ -4,10 +4,10 @@ import { Errors } from '@lenster/data/errors'; import hasOwnedLensProfiles from '@lenster/lib/hasOwnedLensProfiles'; import response from '@lenster/lib/response'; import validateLensAccount from '@lenster/lib/validateLensAccount'; +import createSupabaseClient from '@lenster/supabase/createSupabaseClient'; import jwt from '@tsndr/cloudflare-worker-jwt'; import { boolean, object, string } from 'zod'; -import createSupabaseClient from '../helpers/createSupabaseClient'; import type { WorkerRequest } from '../types'; type ExtensionRequest = { @@ -57,7 +57,7 @@ export default async (request: WorkerRequest) => { ); } - const client = createSupabaseClient(request.env); + const client = createSupabaseClient(request.env.SUPABASE_KEY); const { data, error } = await client .from('rights') diff --git a/packages/workers/preferences/src/helpers/createSupabaseClient.ts b/packages/workers/preferences/src/helpers/createSupabaseClient.ts deleted file mode 100644 index 3ef2d7a2abb..00000000000 --- a/packages/workers/preferences/src/helpers/createSupabaseClient.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { SUPABASE_URL } from '@lenster/data/constants'; -import { createClient } from '@supabase/supabase-js'; - -// @ts-ignore -import type { Database } from '../database.types'; -import type { Env } from '../types'; - -const createSupabaseClient = (env: Env) => { - return createClient(SUPABASE_URL, env.SUPABASE_KEY); -}; - -export default createSupabaseClient; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 358118659f5..e4863c13a36 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -505,6 +505,19 @@ importers: specifier: ^5.2.2 version: 5.2.2 + packages/supabase: + dependencies: + '@supabase/supabase-js': + specifier: ^2.33.1 + version: 2.33.1 + devDependencies: + '@lenster/config': + specifier: workspace:* + version: link:../config + typescript: + specifier: ^5.2.2 + version: 5.2.2 + packages/types: dependencies: '@lenster/lens': @@ -606,12 +619,12 @@ importers: '@lenster/lib': specifier: workspace:* version: link:../../lib + '@lenster/supabase': + specifier: workspace:* + version: link:../../supabase '@sentry/tracing': specifier: ^7.66.0 version: 7.66.0 - '@supabase/supabase-js': - specifier: ^2.33.1 - version: 2.33.1 itty-router: specifier: ^4.0.22 version: 4.0.22 @@ -886,12 +899,12 @@ importers: '@lenster/lib': specifier: workspace:* version: link:../../lib + '@lenster/supabase': + specifier: workspace:* + version: link:../../supabase '@sentry/tracing': specifier: ^7.66.0 version: 7.66.0 - '@supabase/supabase-js': - specifier: ^2.33.1 - version: 2.33.1 '@tsndr/cloudflare-worker-jwt': specifier: ^2.2.2 version: 2.2.2