From 7be79cdd7e416a116580da08709d4937e06e04f2 Mon Sep 17 00:00:00 2001 From: Jonathan Beri Date: Thu, 26 Dec 2024 12:32:02 -0800 Subject: [PATCH 1/4] Add Supabase examples for REST & Edge Functions Signed-off-by: Jonathan Beri --- docs/data-routing/5-examples/24-supabase.md | 95 +++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 docs/data-routing/5-examples/24-supabase.md diff --git a/docs/data-routing/5-examples/24-supabase.md b/docs/data-routing/5-examples/24-supabase.md new file mode 100644 index 00000000..8205ceef --- /dev/null +++ b/docs/data-routing/5-examples/24-supabase.md @@ -0,0 +1,95 @@ +--- +title: Supabase +--- + +import Pipeline from '@site/src/components/usethispipeline' + +[Supabase](https://supabase.com/) is an open-source backend-as-a-service +platform designed to simplify the development of web and mobile applications. It +provides developers with a suite of tools including a Postgres database, +real-time subscriptions, authentication, storage, and serverless functions, all +managed through a single interface. Supabase provides multiple ways to consume +data from Golioth. + +The first example is the simplest and uses the REST API. Assuming a database +named `golioth_pipeline_basic` with the following columns: + +| id | created_at | temp | lat | long | +| -- | ---------- | ---- | --- | ---- | + +Create the following Pipeline: + + + +Create two [secrets](/data-routing/secrets) based on the +[Service Role Key](https://supabase.com/docs/guides/api/api-keys#the-servicerole-key). +`$SUPABASE_KEY` should be the the Server Role Key while `$SUPABASE_SERVICE_KEY` +should take the form of 'Bearer +$Service_Role_Key'. For example, if the `Service Role Key` is `12345` than the `$SUPABASE_SERVICE_KEY`should be set to`Bearer +12345`. + +The second example uses Edge Functions. While +[Transformers](/data-routing/transformers) can be used to modify data, Edge +Functions can be utilized further in the context of Supabase. + +Assuming a database named `golioth_pipeline_advanced` with the following +columns: + +| id | created_at | ce-time | ce-subject | ce-type | ce-source | temp | lat | long | +| -- | ---------- | ------- | ---------- | ------- | --------- | ---- | --- | ---- | + +Create the following Pipeline: + + + +Reuse or create two [secrets](/data-routing/secrets) based on the +[Service Role Key](https://supabase.com/docs/guides/api/api-keys#the-servicerole-key). +`$SUPABASE_KEY` should be the the Server Role Key while `$SUPABASE_SERVICE_KEY` +should take the form of 'Bearer +$Service_Role_Key'. For example, if the `Service Role Key` is `12345` than the `$SUPABASE_SERVICE_KEY`should be set to`Bearer +12345`. + +Create a new Edge Function called `golioth-pipelines` with the following code: + +```ts +import { createClient } from "jsr:@supabase/supabase-js@2"; + +Deno.serve(async (req) => { + try { + const supabase = createClient( + Deno.env.get("SUPABASE_URL") ?? "", + Deno.env.get("SUPABASE_ANON_KEY") ?? "", + { + global: { + headers: { Authorization: req.headers.get("Authorization")! }, + }, + }, + ); + + const body = await req.json(); + + const { error } = await supabase + .from("golioth_pipeline_advanced") + .insert({ + "ce-subject": req.headers.get("ce-subject"), + "ce-time": req.headers.get("ce-time"), + "ce-source": req.headers.get("ce-source"), + "ce-type": req.headers.get("ce-type"), + temp: body.temp, + lat: body.lat, + long: body.long, + }); + + if (error) { + throw error; + } + + return new Response(body, { + headers: { "Content-Type": "application/json" }, + status: 200, + }); + } catch (err) { + return new Response(String(err?.message ?? err), { status: 500 }); + } +}); +``` From ee2e8ee765dd3b29d22ddd7e208275e256beee8a Mon Sep 17 00:00:00 2001 From: Jonathan Beri Date: Thu, 26 Dec 2024 13:00:26 -0800 Subject: [PATCH 2/4] Update examples to use prod Signed-off-by: Jonathan Beri --- docs/data-routing/5-examples/24-supabase.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/data-routing/5-examples/24-supabase.md b/docs/data-routing/5-examples/24-supabase.md index 8205ceef..868a0a99 100644 --- a/docs/data-routing/5-examples/24-supabase.md +++ b/docs/data-routing/5-examples/24-supabase.md @@ -19,7 +19,7 @@ named `golioth_pipeline_basic` with the following columns: Create the following Pipeline: - + Create two [secrets](/data-routing/secrets) based on the [Service Role Key](https://supabase.com/docs/guides/api/api-keys#the-servicerole-key). @@ -40,7 +40,7 @@ columns: Create the following Pipeline: - + Reuse or create two [secrets](/data-routing/secrets) based on the [Service Role Key](https://supabase.com/docs/guides/api/api-keys#the-servicerole-key). From 986c508ffbddd5fb75c5a58995f1e88765909e00 Mon Sep 17 00:00:00 2001 From: Jonathan Beri Date: Thu, 26 Dec 2024 13:02:16 -0800 Subject: [PATCH 3/4] Add links to Supabase docs Signed-off-by: Jonathan Beri --- docs/data-routing/5-examples/24-supabase.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/data-routing/5-examples/24-supabase.md b/docs/data-routing/5-examples/24-supabase.md index 868a0a99..3e7e17b8 100644 --- a/docs/data-routing/5-examples/24-supabase.md +++ b/docs/data-routing/5-examples/24-supabase.md @@ -11,8 +11,9 @@ real-time subscriptions, authentication, storage, and serverless functions, all managed through a single interface. Supabase provides multiple ways to consume data from Golioth. -The first example is the simplest and uses the REST API. Assuming a database -named `golioth_pipeline_basic` with the following columns: +The first example is the simplest and uses the +[REST API](https://supabase.com/docs/guides/api). Assuming a database named +`golioth_pipeline_basic` with the following columns: | id | created_at | temp | lat | long | | -- | ---------- | ---- | --- | ---- | @@ -28,7 +29,8 @@ should take the form of 'Bearer $Service_Role_Key'. For example, if the `Service Role Key` is `12345` than the `$SUPABASE_SERVICE_KEY`should be set to`Bearer 12345`. -The second example uses Edge Functions. While +The second example uses +[Edge Functions](https://supabase.com/docs/guides/functions). While [Transformers](/data-routing/transformers) can be used to modify data, Edge Functions can be utilized further in the context of Supabase. From 7c60c62182d9e62f5ba0dfe3b8834c56d7ced587 Mon Sep 17 00:00:00 2001 From: Jonathan Beri Date: Thu, 26 Dec 2024 13:08:08 -0800 Subject: [PATCH 4/4] Mention secrets only once Signed-off-by: Jonathan Beri --- docs/data-routing/5-examples/24-supabase.md | 22 ++++++++------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/docs/data-routing/5-examples/24-supabase.md b/docs/data-routing/5-examples/24-supabase.md index 3e7e17b8..1963d2e0 100644 --- a/docs/data-routing/5-examples/24-supabase.md +++ b/docs/data-routing/5-examples/24-supabase.md @@ -11,6 +11,14 @@ real-time subscriptions, authentication, storage, and serverless functions, all managed through a single interface. Supabase provides multiple ways to consume data from Golioth. +The following examples will need credentials from Supabase. Create two +[secrets](/data-routing/secrets) based on the +[Service Role Key](https://supabase.com/docs/guides/api/api-keys#the-servicerole-key). +`$SUPABASE_KEY` should be the the Server Role Key while `$SUPABASE_SERVICE_KEY` +should take the form of 'Bearer +$Service_Role_Key'. For example, if the `Service Role Key` is `12345` than the `$SUPABASE_SERVICE_KEY`should be set to`Bearer +12345`. + The first example is the simplest and uses the [REST API](https://supabase.com/docs/guides/api). Assuming a database named `golioth_pipeline_basic` with the following columns: @@ -22,13 +30,6 @@ Create the following Pipeline: -Create two [secrets](/data-routing/secrets) based on the -[Service Role Key](https://supabase.com/docs/guides/api/api-keys#the-servicerole-key). -`$SUPABASE_KEY` should be the the Server Role Key while `$SUPABASE_SERVICE_KEY` -should take the form of 'Bearer -$Service_Role_Key'. For example, if the `Service Role Key` is `12345` than the `$SUPABASE_SERVICE_KEY`should be set to`Bearer -12345`. - The second example uses [Edge Functions](https://supabase.com/docs/guides/functions). While [Transformers](/data-routing/transformers) can be used to modify data, Edge @@ -44,13 +45,6 @@ Create the following Pipeline: -Reuse or create two [secrets](/data-routing/secrets) based on the -[Service Role Key](https://supabase.com/docs/guides/api/api-keys#the-servicerole-key). -`$SUPABASE_KEY` should be the the Server Role Key while `$SUPABASE_SERVICE_KEY` -should take the form of 'Bearer -$Service_Role_Key'. For example, if the `Service Role Key` is `12345` than the `$SUPABASE_SERVICE_KEY`should be set to`Bearer -12345`. - Create a new Edge Function called `golioth-pipelines` with the following code: ```ts