From bc52fb0bb2b87bf218b7bd1704adc9f17d73f434 Mon Sep 17 00:00:00 2001 From: lorinjameson Date: Wed, 25 Oct 2023 15:35:30 -0400 Subject: [PATCH] FCC Integration updates --- .github/workflows/production.yaml | 26 ---------------- .github/workflows/staging.yaml | 26 ---------------- supabase/config.toml | 2 +- supabase/functions/.env.example | 2 +- .../functions/fcc-get-document-url/index.ts | 17 ++++++++++ .../fcc-get-project-documents/index.ts | 31 +++++++++++++++++++ supabase/functions/fcc-list-projects/index.ts | 4 +-- supabase/functions/import_map.json | 3 +- 8 files changed, 54 insertions(+), 57 deletions(-) delete mode 100644 .github/workflows/production.yaml delete mode 100644 .github/workflows/staging.yaml create mode 100644 supabase/functions/fcc-get-document-url/index.ts create mode 100644 supabase/functions/fcc-get-project-documents/index.ts diff --git a/.github/workflows/production.yaml b/.github/workflows/production.yaml deleted file mode 100644 index 3d30f16..0000000 --- a/.github/workflows/production.yaml +++ /dev/null @@ -1,26 +0,0 @@ -name: Release - -on: - push: - branches: - - master - workflow_dispatch: - -jobs: - release: - runs-on: ubuntu-latest - - env: - SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }} - SUPABASE_DB_PASSWORD: ${{ secrets.PRODUCTION_DB_PASSWORD }} - SUPABASE_PROJECT_ID: ${{ secrets.PRODUCTION_PROJECT_ID }} - - steps: - - uses: actions/checkout@v3 - - - uses: supabase/setup-cli@v1 - with: - version: latest - - - run: supabase link --project-ref $SUPABASE_PROJECT_ID - - run: supabase db push diff --git a/.github/workflows/staging.yaml b/.github/workflows/staging.yaml deleted file mode 100644 index f1328d7..0000000 --- a/.github/workflows/staging.yaml +++ /dev/null @@ -1,26 +0,0 @@ -name: Deploy Migrations to Staging - -on: - push: - branches: - - develop - workflow_dispatch: - -jobs: - deploy: - runs-on: ubuntu-latest - - env: - SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }} - SUPABASE_DB_PASSWORD: ${{ secrets.STAGING_DB_PASSWORD }} - SUPABASE_PROJECT_ID: ${{ secrets.STAGING_PROJECT_ID }} - - steps: - - uses: actions/checkout@v3 - - - uses: supabase/setup-cli@v1 - with: - version: latest - - - run: supabase link --project-ref $SUPABASE_PROJECT_ID - - run: supabase db push \ No newline at end of file diff --git a/supabase/config.toml b/supabase/config.toml index 702e09a..b1d4da2 100644 --- a/supabase/config.toml +++ b/supabase/config.toml @@ -1,6 +1,6 @@ # A string used to distinguish different Supabase projects on the same host. Defaults to the working # directory name when running `supabase init`. -project_id = "recogito-bonn" +project_id = "recogito-server" [api] # Port to use for the API URL. diff --git a/supabase/functions/.env.example b/supabase/functions/.env.example index a546211..537da7b 100644 --- a/supabase/functions/.env.example +++ b/supabase/functions/.env.example @@ -1,2 +1,2 @@ -FCC_URL= +FCC_API_URL= FCC_SERVICE_KEY= \ No newline at end of file diff --git a/supabase/functions/fcc-get-document-url/index.ts b/supabase/functions/fcc-get-document-url/index.ts new file mode 100644 index 0000000..6b242da --- /dev/null +++ b/supabase/functions/fcc-get-document-url/index.ts @@ -0,0 +1,17 @@ +// Follow this setup guide to integrate the Deno language server with your editor: +// https://deno.land/manual/getting_started/setup_your_environment +// This enables autocomplete, go to definition, etc. + +import { serve } from 'server'; + +serve(async (req) => { + const { xml_id } = await req.json(); + + const data = { + xml_id: xml_id, + fcc_url: `${Deno.env.get('FCC_URL')}/documents/${xml_id}/tei`, + }; + return new Response(JSON.stringify(data), { + headers: { 'Content-Type': 'application/json' }, + }); +}); diff --git a/supabase/functions/fcc-get-project-documents/index.ts b/supabase/functions/fcc-get-project-documents/index.ts new file mode 100644 index 0000000..d5c5798 --- /dev/null +++ b/supabase/functions/fcc-get-project-documents/index.ts @@ -0,0 +1,31 @@ +// Follow this setup guide to integrate the Deno language server with your editor: +// https://deno.land/manual/getting_started/setup_your_environment +// This enables autocomplete, go to definition, etc. + +import { serve } from 'server'; +import { createClient } from 'supabase'; + +serve(async (req) => { + const { project_id } = await req.json(); + + const supabase = createClient( + Deno.env.get('FCC_API_URL'), + Deno.env.get('FCC_SERVICE_KEY'), + { + auth: { + persistSession: true, + autoRefreshToken: true, + detectSessionInUrl: false, + }, + } + ); + + const projectsResp = await supabase + .from('tei_documents') + .select('id, xml_id, name') + .eq('project_id', project_id); + + return new Response(JSON.stringify(projectsResp.data), { + headers: { 'Content-Type': 'application/json' }, + }); +}); diff --git a/supabase/functions/fcc-list-projects/index.ts b/supabase/functions/fcc-list-projects/index.ts index 7c46c58..c05ed82 100644 --- a/supabase/functions/fcc-list-projects/index.ts +++ b/supabase/functions/fcc-list-projects/index.ts @@ -2,12 +2,12 @@ // https://deno.land/manual/getting_started/setup_your_environment // This enables autocomplete, go to definition, etc. -import { serve } from 'https://deno.land/std@0.168.0/http/server.ts'; +import { serve } from 'server'; import { createClient } from 'supabase'; serve(async (req) => { const supabase = createClient( - Deno.env.get('FCC_URL'), + Deno.env.get('FCC_API_URL'), Deno.env.get('FCC_SERVICE_KEY'), { auth: { diff --git a/supabase/functions/import_map.json b/supabase/functions/import_map.json index ece9d82..0e2e08b 100644 --- a/supabase/functions/import_map.json +++ b/supabase/functions/import_map.json @@ -1,5 +1,6 @@ { "imports": { - "supabase": "https://esm.sh/@supabase/supabase-js@2" + "supabase": "https://esm.sh/@supabase/supabase-js@2", + "server": "https://deno.land/std@0.177.0/http/server.ts" } } \ No newline at end of file