From 82305e14401460233b85d45f151f2f8c960d205f Mon Sep 17 00:00:00 2001 From: Erik Taubeneck Date: Sat, 8 Jun 2024 17:49:34 -0700 Subject: [PATCH 1/5] add helper_parties and helper_party_network tables --- server/data/supabaseTypes.ts | 72 ++++++++++++++++++ .../20240608204813_helper_party.sql | 76 +++++++++++++++++++ server/supabase/seed.sql | 22 ++++++ 3 files changed, 170 insertions(+) create mode 100644 server/supabase/migrations/20240608204813_helper_party.sql diff --git a/server/data/supabaseTypes.ts b/server/data/supabaseTypes.ts index 45f8d3f..cffc714 100644 --- a/server/data/supabaseTypes.ts +++ b/server/data/supabaseTypes.ts @@ -34,6 +34,78 @@ export type Database = { } public: { Tables: { + helper_parties: { + Row: { + created_at: string + display_name: string + uuid: string + } + Insert: { + created_at?: string + display_name: string + uuid?: string + } + Update: { + created_at?: string + display_name?: string + uuid?: string + } + Relationships: [] + } + helper_party_network_members: { + Row: { + created_at: string + helper_party_network_uuid: string + helper_party_uuid: string + } + Insert: { + created_at?: string + helper_party_network_uuid: string + helper_party_uuid: string + } + Update: { + created_at?: string + helper_party_network_uuid?: string + helper_party_uuid?: string + } + Relationships: [ + { + foreignKeyName: "helper_party_network_members_helper_party_network_uuid_fkey" + columns: ["helper_party_network_uuid"] + isOneToOne: false + referencedRelation: "helper_party_networks" + referencedColumns: ["uuid"] + }, + { + foreignKeyName: "helper_party_network_members_helper_party_uuid_fkey" + columns: ["helper_party_uuid"] + isOneToOne: false + referencedRelation: "helper_parties" + referencedColumns: ["uuid"] + }, + ] + } + helper_party_networks: { + Row: { + created_at: string + display_name: string + size: number + uuid: string + } + Insert: { + created_at?: string + display_name: string + size: number + uuid?: string + } + Update: { + created_at?: string + display_name?: string + size?: number + uuid?: string + } + Relationships: [] + } queries: { Row: { created_at: string diff --git a/server/supabase/migrations/20240608204813_helper_party.sql b/server/supabase/migrations/20240608204813_helper_party.sql new file mode 100644 index 0000000..5f1f6ba --- /dev/null +++ b/server/supabase/migrations/20240608204813_helper_party.sql @@ -0,0 +1,76 @@ +create table +helper_parties ( +uuid uuid default gen_random_uuid() primary key, +display_name varchar(255) unique not null, +created_at timestamp default current_timestamp not null +); + +alter table helper_parties enable row level security; + +create policy "Helper Parties are visible to authenticated users" +on helper_parties for select +to authenticated +using ( true ); + +create policy "Helper Parties are only created by authenticated users" +on helper_parties for insert +to authenticated +with check ( true ); + +create policy "Helper Parties are only updated by authenticated users" +on helper_parties for update +to authenticated +using ( true ) +with check ( true ); + +create table +helper_party_networks ( +uuid uuid default gen_random_uuid() primary key, +display_name varchar(255) unique not null, +size smallint not null, +created_at timestamp default current_timestamp not null +); + +alter table helper_party_networks enable row level security; + +create policy "Helper Party Networks are visible to authenticated users" +on helper_party_networks for select +to authenticated +using ( true ); + +create policy "Helper Party Networks are only created by authenticated users" +on helper_party_networks for insert +to authenticated +with check ( true ); + +create policy "Helper Party Networks are only updated by authenticated users" +on helper_party_networks for update +to authenticated +using ( true ) +with check ( true ); + +create table +helper_party_network_members ( +helper_party_uuid uuid references helper_parties not null, +helper_party_network_uuid uuid references helper_party_networks not null, +created_at timestamp default current_timestamp not null, +primary key (helper_party_uuid, helper_party_network_uuid) +); + +alter table helper_party_network_members enable row level security; + +create policy "Helper Party Network Members are visible to authenticated users" +on helper_party_network_members for select +to authenticated +using ( true ); + +create policy "Helper Party Network Members are only created by authenticated users" +on helper_party_network_members for insert +to authenticated +with check ( true ); + +create policy "Helper Party Network Members are only updated by authenticated users" +on helper_party_network_members for update +to authenticated +using ( true ) +with check ( true ); diff --git a/server/supabase/seed.sql b/server/supabase/seed.sql index e69de29..1b8d898 100644 --- a/server/supabase/seed.sql +++ b/server/supabase/seed.sql @@ -0,0 +1,22 @@ +-- +-- Data for Name: helper_parties; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO public.helper_parties (uuid, display_name, created_at) VALUES ('de218b52-1ec7-4a4d-9bf9-f9070b2c3a93', 'Local test helper 1', '2024-06-05 20:37:32.472191'); +INSERT INTO public.helper_parties (uuid, display_name, created_at) VALUES ('b8848f0f-65c4-499f-82b4-1e3a119ba31e', 'Local test helper 2', '2024-06-05 20:37:45.47656'); +INSERT INTO public.helper_parties (uuid, display_name, created_at) VALUES ('91993b4a-4131-4b9f-a132-d4a5839e3c6c', 'Local test helper 3', '2024-06-05 20:37:53.375326'); + + +-- +-- Data for Name: helper_party_networks; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO public.helper_party_networks (uuid, display_name, size, created_at) VALUES ('a8c892ae-8cee-472f-95f0-e25b1fec9759', 'Local test network', 3, '2024-06-05 20:38:40.956239'); + +-- +-- Data for Name: helper_party_network_members; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO public.helper_party_network_members (helper_party_uuid, helper_party_network_uuid, created_at) VALUES ('de218b52-1ec7-4a4d-9bf9-f9070b2c3a93', 'a8c892ae-8cee-472f-95f0-e25b1fec9759', '2024-06-05 20:39:01.362579'); +INSERT INTO public.helper_party_network_members (helper_party_uuid, helper_party_network_uuid, created_at) VALUES ('b8848f0f-65c4-499f-82b4-1e3a119ba31e', 'a8c892ae-8cee-472f-95f0-e25b1fec9759', '2024-06-05 20:39:10.502079'); +INSERT INTO public.helper_party_network_members (helper_party_uuid, helper_party_network_uuid, created_at) VALUES ('91993b4a-4131-4b9f-a132-d4a5839e3c6c', 'a8c892ae-8cee-472f-95f0-e25b1fec9759', '2024-06-05 20:39:24.703602'); From 1253378c6f3e3774403a31471720f375a8183225 Mon Sep 17 00:00:00 2001 From: Erik Taubeneck Date: Sat, 8 Jun 2024 16:59:27 -0700 Subject: [PATCH 2/5] add helper_party_api_keys table --- server/data/supabaseTypes.ts | 35 +++++++++++++++++++ .../20240609010604_helper_party_api_keys.sql | 13 +++++++ server/supabase/seed.sql | 10 ++++++ 3 files changed, 58 insertions(+) create mode 100644 server/supabase/migrations/20240609010604_helper_party_api_keys.sql diff --git a/server/data/supabaseTypes.ts b/server/data/supabaseTypes.ts index cffc714..2986b33 100644 --- a/server/data/supabaseTypes.ts +++ b/server/data/supabaseTypes.ts @@ -52,6 +52,41 @@ export type Database = { } Relationships: [] } + helper_party_api_keys: { + Row: { + created_at: string + expires_at: string + hashed_api_key: string | null + helper_party_uuid: string + revoked: boolean + uuid: string + } + Insert: { + created_at?: string + expires_at?: string + hashed_api_key?: string | null + helper_party_uuid: string + revoked?: boolean + uuid?: string + } + Update: { + created_at?: string + expires_at?: string + hashed_api_key?: string | null + helper_party_uuid?: string + revoked?: boolean + uuid?: string + } + Relationships: [ + { + foreignKeyName: "helper_party_api_keys_helper_party_uuid_fkey" + columns: ["helper_party_uuid"] + isOneToOne: false + referencedRelation: "helper_parties" + referencedColumns: ["uuid"] + }, + ] + } helper_party_network_members: { Row: { created_at: string diff --git a/server/supabase/migrations/20240609010604_helper_party_api_keys.sql b/server/supabase/migrations/20240609010604_helper_party_api_keys.sql new file mode 100644 index 0000000..fedef01 --- /dev/null +++ b/server/supabase/migrations/20240609010604_helper_party_api_keys.sql @@ -0,0 +1,13 @@ +create table +helper_party_api_keys ( +uuid uuid default gen_random_uuid() primary key, +helper_party_uuid uuid references helper_parties not null, +hashed_api_key varchar(255), +created_at timestamp default current_timestamp not null, +expires_at timestamp default current_timestamp + interval '1 year' not null, +revoked boolean default false not null +); + +alter table helper_party_api_keys enable row level security; + +-- do not add any authenticated access to api_keys, require service_role and handle in application diff --git a/server/supabase/seed.sql b/server/supabase/seed.sql index 1b8d898..be0ae32 100644 --- a/server/supabase/seed.sql +++ b/server/supabase/seed.sql @@ -20,3 +20,13 @@ INSERT INTO public.helper_party_networks (uuid, display_name, size, created_at) INSERT INTO public.helper_party_network_members (helper_party_uuid, helper_party_network_uuid, created_at) VALUES ('de218b52-1ec7-4a4d-9bf9-f9070b2c3a93', 'a8c892ae-8cee-472f-95f0-e25b1fec9759', '2024-06-05 20:39:01.362579'); INSERT INTO public.helper_party_network_members (helper_party_uuid, helper_party_network_uuid, created_at) VALUES ('b8848f0f-65c4-499f-82b4-1e3a119ba31e', 'a8c892ae-8cee-472f-95f0-e25b1fec9759', '2024-06-05 20:39:10.502079'); INSERT INTO public.helper_party_network_members (helper_party_uuid, helper_party_network_uuid, created_at) VALUES ('91993b4a-4131-4b9f-a132-d4a5839e3c6c', 'a8c892ae-8cee-472f-95f0-e25b1fec9759', '2024-06-05 20:39:24.703602'); + + + +-- +-- Data for Name: helper_party_api_keys; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO public.helper_party_api_keys (uuid, helper_party_uuid, hashed_api_key) VALUES ('13d80a42-4b40-4987-a338-b394674ab399', 'de218b52-1ec7-4a4d-9bf9-f9070b2c3a93', '243262243130244470514a2e527665766e57614a4f5835782f505a534f6a674f335866444737505178585851656e3866796e52467563516d66414547'); +INSERT INTO public.helper_party_api_keys (uuid, helper_party_uuid, hashed_api_key) VALUES ('1d61b974-7ac8-4baa-b0b0-a83cd29c46e2', 'b8848f0f-65c4-499f-82b4-1e3a119ba31e', '243262243130247770623576564767534f61772f516441334a51734c2e7373494e3652714369355a554a414e2e7343796d4673394c475247584c5375'); +INSERT INTO public.helper_party_api_keys (uuid, helper_party_uuid, hashed_api_key) VALUES ('31c229e3-8150-4f9b-91e6-ac413198f4ff', '91993b4a-4131-4b9f-a132-d4a5839e3c6c', '24326224313024724746664c3146614b4b6e68715169714e6b58573165485a37662f6d3857563271364a336845564139352e5746465677616b774d71'); From 3b9474b51131ce333a28126614cd132b8c8be584 Mon Sep 17 00:00:00 2001 From: Erik Taubeneck Date: Sat, 8 Jun 2024 19:12:12 -0700 Subject: [PATCH 3/5] add development api keys to .env.development --- .gitignore | 2 +- server/.env.development | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 server/.env.development diff --git a/.gitignore b/.gitignore index fa86c33..ca32a63 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ IGNORE-ME* .draft # local env files -.env* +.env*.local # local certs local_dev/config/cert.pem diff --git a/server/.env.development b/server/.env.development new file mode 100644 index 0000000..51a97ca --- /dev/null +++ b/server/.env.development @@ -0,0 +1,12 @@ +# DO NOT ADD SECRETS TO THIS FILE. This is a good place for defaults. +# If you want to add secrets use `.env.development.local` instead. + +# local dev API keys +HELPER_PARTY_1_API_KEY="f9c1cced33c932da94d520682d30b1a558711865d32634008488abf38d6f75a0" +HELPER_PARTY_2_API_KEY="d64fd1cc084e2633d8e0719cb4691e81b1961949bc2aadecee14fdf53bd6f139" +HELPER_PARTY_3_API_KEY="46198655cdac1d67e3e6aaf905c9d6702c899c607c2baedf353fc3106ec92929" + + +# default supabase variables +NEXT_PUBLIC_SUPABASE_URL="http://localhost:54321" +NEXT_PUBLIC_SITE_URL="https://draft.test" From 1d6cb5c1e24e523bc50a310178e6f541d8ed9076 Mon Sep 17 00:00:00 2001 From: Erik Taubeneck Date: Sun, 9 Jun 2024 13:24:46 -0700 Subject: [PATCH 4/5] hashed_api_key should be non null --- server/data/supabaseTypes.ts | 45 +++++++++++++++++-- .../20240609010604_helper_party_api_keys.sql | 2 +- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/server/data/supabaseTypes.ts b/server/data/supabaseTypes.ts index 2986b33..992f057 100644 --- a/server/data/supabaseTypes.ts +++ b/server/data/supabaseTypes.ts @@ -56,7 +56,7 @@ export type Database = { Row: { created_at: string expires_at: string - hashed_api_key: string | null + hashed_api_key: string helper_party_uuid: string revoked: boolean uuid: string @@ -64,7 +64,7 @@ export type Database = { Insert: { created_at?: string expires_at?: string - hashed_api_key?: string | null + hashed_api_key: string helper_party_uuid: string revoked?: boolean uuid?: string @@ -72,7 +72,7 @@ export type Database = { Update: { created_at?: string expires_at?: string - hashed_api_key?: string | null + hashed_api_key?: string helper_party_uuid?: string revoked?: boolean uuid?: string @@ -141,6 +141,45 @@ export type Database = { } Relationships: [] } + helper_party_query_status_updates: { + Row: { + helper_party_uuid: string + query_uuid: string + started_at: string + status: Database["public"]["Enums"]["status"] + uuid: string + } + Insert: { + helper_party_uuid: string + query_uuid: string + started_at?: string + status: Database["public"]["Enums"]["status"] + uuid?: string + } + Update: { + helper_party_uuid?: string + query_uuid?: string + started_at?: string + status?: Database["public"]["Enums"]["status"] + uuid?: string + } + Relationships: [ + { + foreignKeyName: "helper_party_query_status_updates_helper_party_uuid_fkey" + columns: ["helper_party_uuid"] + isOneToOne: false + referencedRelation: "helper_parties" + referencedColumns: ["uuid"] + }, + { + foreignKeyName: "helper_party_query_status_updates_query_uuid_fkey" + columns: ["query_uuid"] + isOneToOne: false + referencedRelation: "queries" + referencedColumns: ["uuid"] + }, + ] + } queries: { Row: { created_at: string diff --git a/server/supabase/migrations/20240609010604_helper_party_api_keys.sql b/server/supabase/migrations/20240609010604_helper_party_api_keys.sql index fedef01..6cb77ae 100644 --- a/server/supabase/migrations/20240609010604_helper_party_api_keys.sql +++ b/server/supabase/migrations/20240609010604_helper_party_api_keys.sql @@ -2,7 +2,7 @@ create table helper_party_api_keys ( uuid uuid default gen_random_uuid() primary key, helper_party_uuid uuid references helper_parties not null, -hashed_api_key varchar(255), +hashed_api_key varchar(255) not null, created_at timestamp default current_timestamp not null, expires_at timestamp default current_timestamp + interval '1 year' not null, revoked boolean default false not null From 5de110138a072fdae55a0564221ec1b49a66fdb5 Mon Sep 17 00:00:00 2001 From: Erik Taubeneck Date: Thu, 13 Jun 2024 15:40:36 -0700 Subject: [PATCH 5/5] add modified_at and modified_reason to api keys --- server/data/supabaseTypes.ts | 48 +++---------------- .../20240609010604_helper_party_api_keys.sql | 5 +- 2 files changed, 9 insertions(+), 44 deletions(-) diff --git a/server/data/supabaseTypes.ts b/server/data/supabaseTypes.ts index 84658dc..4a5ab61 100644 --- a/server/data/supabaseTypes.ts +++ b/server/data/supabaseTypes.ts @@ -61,7 +61,8 @@ export type Database = { expires_at: string hashed_api_key: string helper_party_uuid: string - revoked: boolean + modified_at: string | null + modified_reason: string | null uuid: string } Insert: { @@ -69,7 +70,8 @@ export type Database = { expires_at?: string hashed_api_key: string helper_party_uuid: string - revoked?: boolean + modified_at?: string | null + modified_reason?: string | null uuid?: string } Update: { @@ -77,7 +79,8 @@ export type Database = { expires_at?: string hashed_api_key?: string helper_party_uuid?: string - revoked?: boolean + modified_at?: string | null + modified_reason?: string | null uuid?: string } Relationships: [ @@ -144,45 +147,6 @@ export type Database = { } Relationships: [] } - helper_party_query_status_updates: { - Row: { - helper_party_uuid: string - query_uuid: string - started_at: string - status: Database["public"]["Enums"]["status"] - uuid: string - } - Insert: { - helper_party_uuid: string - query_uuid: string - started_at?: string - status: Database["public"]["Enums"]["status"] - uuid?: string - } - Update: { - helper_party_uuid?: string - query_uuid?: string - started_at?: string - status?: Database["public"]["Enums"]["status"] - uuid?: string - } - Relationships: [ - { - foreignKeyName: "helper_party_query_status_updates_helper_party_uuid_fkey" - columns: ["helper_party_uuid"] - isOneToOne: false - referencedRelation: "helper_parties" - referencedColumns: ["uuid"] - }, - { - foreignKeyName: "helper_party_query_status_updates_query_uuid_fkey" - columns: ["query_uuid"] - isOneToOne: false - referencedRelation: "queries" - referencedColumns: ["uuid"] - }, - ] - } queries: { Row: { created_at: string diff --git a/server/supabase/migrations/20240609010604_helper_party_api_keys.sql b/server/supabase/migrations/20240609010604_helper_party_api_keys.sql index 6cb77ae..56f3b9a 100644 --- a/server/supabase/migrations/20240609010604_helper_party_api_keys.sql +++ b/server/supabase/migrations/20240609010604_helper_party_api_keys.sql @@ -2,10 +2,11 @@ create table helper_party_api_keys ( uuid uuid default gen_random_uuid() primary key, helper_party_uuid uuid references helper_parties not null, -hashed_api_key varchar(255) not null, +hashed_api_key text not null, created_at timestamp default current_timestamp not null, expires_at timestamp default current_timestamp + interval '1 year' not null, -revoked boolean default false not null +modified_at timestamp default null, +modified_reason text default null ); alter table helper_party_api_keys enable row level security;