@marktiderman/genesis-cli 1.21.0 → 1.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -179,10 +179,10 @@ manifest for the packages installed, export compliance and the fingerprint runti
179
179
  storage, copy the `genesis-support-notify` and `genesis-support-cleanup` templates: see "Support"
180
180
  in [`@marktiderman/genesis-supabase`](../../packages/supabase/README.md#support-the-support-block).
181
181
  - **Chat:** `supabase/migrations/20261025000000_genesis_chat.sql`,
182
- `20261025000050_genesis_chat_coaching.sql`, `20261025000060_genesis_chat_search_threads.sql` and
183
- `20261025000080_genesis_chat_tenants.sql` are genesis-chat's migrations 0001 to 0004 (topics,
184
- scheduled send, availability, broadcast, search, link previews, moderation; every conversation in
185
- a tenant), copied and drift-tested the same way. The starter is single-tenant:
182
+ `20261025000050_genesis_chat_coaching.sql`, `20261025000060_genesis_chat_search_threads.sql`,
183
+ `20261025000080_genesis_chat_tenants.sql` and `20261025000090_genesis_chat_attachment_paths.sql`
184
+ are genesis-chat's migrations 0001 to 0005 (topics, scheduled send, availability, broadcast,
185
+ search, link previews, moderation; every conversation in a tenant; tightened attachment paths), copied and drift-tested the same way. The starter is single-tenant:
186
186
  `20261025000070_starter_tenancy.sql` puts every login in one tenant
187
187
  (`private.genesis_viewer_people`); replace it when you add organizations. Scheduled messages, link previews, moderation and chat pushes are
188
188
  worked by genesis-chat's runner (`createChatRunner` from `@marktiderman/genesis-chat/server`),
@@ -407,6 +407,15 @@ describe("chat", () => {
407
407
  expect(order.indexOf(copies[0]!)).toBe(order.findIndex((f) => f.endsWith("_genesis_chat.sql")) + 1);
408
408
  });
409
409
 
410
+ it.runIf(chat && database)("carries chat's 0005 migration and its pgTAP test unchanged, after 0004", () => {
411
+ const order = filesUnder("supabase/migrations").sort();
412
+ const paths = order.filter((f) => f.endsWith("_genesis_chat_attachment_paths.sql"));
413
+ expect(paths).toHaveLength(1);
414
+ expect(read(paths[0]!)).toBe(chatSql("0005_genesis_chat_attachment_paths.sql"));
415
+ expect(read("supabase/tests/database/genesis_chat_attachment_paths.test.sql")).toBe(chatSql("tests/0005_genesis_chat_attachment_paths.test.sql"));
416
+ expect(order.indexOf(paths[0]!)).toBeGreaterThan(order.findIndex((f) => f.endsWith("_genesis_chat_tenants.sql")));
417
+ });
418
+
410
419
  it.runIf(chat && database)("carries chat's 0003 and 0004 migrations and their pgTAP tests unchanged, with a single-tenant hook before 0004", () => {
411
420
  const order = filesUnder("supabase/migrations").sort();
412
421
  const search = order.filter((f) => f.endsWith("_genesis_chat_search_threads.sql"));
@@ -62,6 +62,28 @@ overrides:
62
62
  react-dom: 19.3.0
63
63
  "@types/react": 19.3.0
64
64
  react-native: 0.88.0
65
+ # Security floors for transitive dependencies (Dependabot). Each dependent's own range would
66
+ # hold the vulnerable version, or a fresh lockfile could fall back to it. A range-keyed override
67
+ # touches only the versions below the fix. Overrides apply at the workspace root only: a package
68
+ # consumer doesn't get them, but `genesis init` copies this block into a new native app's
69
+ # settings, where the same floors are just as welcome. Drop an entry when its dependents' own
70
+ # ranges exclude the vulnerable versions.
71
+ "@xmldom/xmldom@<0.8.15": ^0.8.15
72
+ "@xmldom/xmldom@>=0.9.0 <0.9.12": ^0.9.12
73
+ "brace-expansion@<1.1.21": ^1.1.21
74
+ "brace-expansion@>=2.0.0 <2.1.7": ^2.1.7
75
+ "brace-expansion@>=4.0.0 <5.0.12": ^5.0.12
76
+ "esbuild@>=0.27.3 <0.28.1": ^0.28.2
77
+ "fast-uri@>=3.0.0 <3.1.9": ^3.1.9
78
+ # glob 7 is not affected. 14 is a major, and the only change the dependents see is the fix.
79
+ "glob@>=9.0.0 <14.0.2": ^14.0.3
80
+ # @tiptap/html and @puckeditor/core ask for ^20; the fix only exists on 21.
81
+ "happy-dom@<21.0.4": ^21.0.4
82
+ "js-yaml@>=3.0.0 <3.15.2": ^3.15.2
83
+ "js-yaml@>=4.0.0 <4.3.2": ^4.3.2
84
+ "morgan@<1.12.1": ^1.12.1
85
+ # xcode only calls uuid.v4(), so the v3/v5/v6 flaw never ran; 11.1.1 is the first fixed version.
86
+ "uuid@<11.1.1": ^11.1.1
65
87
 
66
88
  patchedDependencies:
67
89
  # tsup 8.5.1's declaration build forces `baseUrl: "."` into the compiler options, and TypeScript 6
@@ -13,6 +13,7 @@ import AsyncStorage from "@react-native-async-storage/async-storage";
13
13
  import NetInfo from "@react-native-community/netinfo";
14
14
  import * as Crypto from "expo-crypto";
15
15
  import * as Haptics from "expo-haptics";
16
+ import { playHaptic, type GenesisHapticsModule } from "@marktiderman/genesis-ui-native/hooks";
16
17
  import * as ImagePicker from "expo-image-picker";
17
18
  import {
18
19
  createDraftStore,
@@ -78,8 +79,9 @@ NetInfo.addEventListener((state) => checkInOutbox.setOnline(state.isConnected !=
78
79
  export const checkInPhotos = createCheckInPhotos(ImagePicker.launchImageLibraryAsync as LaunchLibrary, stubUpload(Crypto.randomUUID));
79
80
 
80
81
  /** A pick, a sent check-in and a refused step, felt. */
82
+ const haptics = Haptics as unknown as GenesisHapticsModule;
81
83
  export const checkInHaptics: FormHaptics = {
82
- selection: () => void Haptics.selectionAsync(),
83
- success: () => void Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success),
84
- error: () => void Haptics.notificationAsync(Haptics.NotificationFeedbackType.Error),
84
+ selection: () => playHaptic(haptics, "select"),
85
+ success: () => playHaptic(haptics, "success"),
86
+ error: () => playHaptic(haptics, "error"),
85
87
  };
@@ -9,9 +9,10 @@
9
9
  * ThreadPage's composer. To fall back to plain
10
10
  * React Native for one, delete its line, its import below and its package.
11
11
  */
12
- import DateTimePicker from "@expo/ui/community/datetime-picker";
12
+ import { DateTimePicker } from "@expo/ui/community/datetime-picker";
13
13
  import { FlashList } from "@shopify/flash-list";
14
14
  import * as GlassEffect from "expo-glass-effect";
15
+ import * as Haptics from "expo-haptics";
15
16
  import { Image } from "expo-image";
16
17
  import { DarkTheme, DefaultTheme, ThemeProvider } from "expo-router";
17
18
  import { SymbolView } from "expo-symbols";
@@ -32,4 +33,6 @@ export const nativeModules: GenesisModules = {
32
33
  navigation: { ThemeProvider, DefaultTheme, DarkTheme },
33
34
  // ThreadPage's composer follows the keyboard frame by frame.
34
35
  keyboardAvoidingView: KeyboardAvoidingView,
36
+ // expo-haptics, once: useHaptics(), playHaptic and NativeButton's `haptic` play through it.
37
+ haptics: Haptics as unknown as GenesisModules["haptics"],
35
38
  };
@@ -0,0 +1,80 @@
1
+ -- Genesis Chat 0005: attachment paths are tightened
2
+ --
3
+ -- Builds on 0001–0004 (never edited once released). Needs nothing from your app, and no other
4
+ -- package's migrations depend on where it runs after chat 0001.
5
+ --
6
+ -- 1. An attachment has a `path` only when its provider is `storage`, by a check on the table.
7
+ -- send_message refuses anything else with 23514; a scheduled message holding one records that
8
+ -- as its `error` when it comes due, as with any refusal. Genesis's own clients never send one.
9
+ -- 2. Read access counts `path` only on storage attachments, and `poster_path` on any provider
10
+ -- (a hosted video's poster lives in the bucket).
11
+ -- 3. Paths on other providers are cleared, with the transcript of a voice row among them, and
12
+ -- kept in `genesis_chat.attachment_paths_cleared` for the service role. A link keeps its `url`,
13
+ -- and a video its provider id.
14
+ --
15
+ -- `attachment_paths_cleared` holds object paths, which contain user ids, and nothing removes them:
16
+ -- account deletion doesn't touch this table, and neither does retention. Look at it once after
17
+ -- this runs (usually it's empty), then drop it, `drop table genesis_chat.attachment_paths_cleared`,
18
+ -- and sooner if a person's data must go.
19
+
20
+ create table genesis_chat.attachment_paths_cleared (
21
+ attachment_id uuid primary key,
22
+ message_id uuid not null,
23
+ conversation_id uuid not null,
24
+ provider text not null,
25
+ path text not null,
26
+ cleared_at timestamptz not null default now()
27
+ );
28
+ alter table genesis_chat.attachment_paths_cleared enable row level security;
29
+ revoke all on genesis_chat.attachment_paths_cleared from public, anon, authenticated;
30
+ grant select on genesis_chat.attachment_paths_cleared to service_role;
31
+
32
+ -- A function so its test can run it: rows are refused once the check below is on. Returns how many it cleared.
33
+ create function genesis_chat.clear_paths_outside_storage()
34
+ returns integer
35
+ language plpgsql
36
+ set search_path = ''
37
+ as $$
38
+ declare
39
+ cleared integer;
40
+ begin
41
+ insert into genesis_chat.attachment_paths_cleared (attachment_id, message_id, conversation_id, provider, path)
42
+ select id, message_id, conversation_id, provider, path
43
+ from genesis_chat.attachments
44
+ where provider <> 'storage' and path is not null
45
+ on conflict (attachment_id) do nothing;
46
+ update genesis_chat.attachments
47
+ set path = null,
48
+ transcript = case when kind = 'voice' then null else transcript end
49
+ where provider <> 'storage' and path is not null;
50
+ get diagnostics cleared = row_count;
51
+ return cleared;
52
+ end;
53
+ $$;
54
+ revoke all on function genesis_chat.clear_paths_outside_storage() from public, anon, authenticated, service_role;
55
+
56
+ select genesis_chat.clear_paths_outside_storage();
57
+
58
+ alter table genesis_chat.attachments
59
+ add constraint attachments_path_only_in_storage check (provider = 'storage' or path is null);
60
+
61
+ -- May the signed-in person read `object_name`? Whoever reads a message that carries it as a file
62
+ -- in storage or a poster; its uploader for a day before it is sent.
63
+ create or replace function genesis_chat.can_read_object(object_name text, object_owner text, uploaded_at timestamptz)
64
+ returns boolean
65
+ language sql
66
+ stable
67
+ security definer
68
+ set search_path = ''
69
+ as $$
70
+ select auth.uid() is not null and (
71
+ exists (
72
+ select 1 from genesis_chat.attachments a
73
+ join genesis_chat.messages m on m.id = a.message_id
74
+ where ((a.provider = 'storage' and a.path = object_name) or a.poster_path = object_name)
75
+ and m.deleted_at is null
76
+ and genesis_chat.can_view(m.conversation_id)
77
+ and (m.visibility = 'everyone' or genesis_chat.observes(m.conversation_id)))
78
+ or (object_owner = auth.uid()::text and split_part(object_name, '/', 2) = auth.uid()::text
79
+ and uploaded_at > now() - interval '1 day'))
80
+ $$;
@@ -0,0 +1,111 @@
1
+ -- @feat:chat
2
+ -- pgTAP test for 0005_genesis_chat_attachment_paths.sql.
3
+ -- Copy into your app's `supabase/tests/database/` and run `supabase test db`.
4
+ -- It writes only its own users, kinds and conversations, and rolls everything back.
5
+ --
6
+ -- People: a1 and b2 talk directly and share a file; e5 and d4 talk directly, and aren't in it.
7
+ begin;
8
+ create extension if not exists pgtap with schema extensions;
9
+ select plan(18);
10
+
11
+ insert into auth.users (id, aud, role, email, instance_id)
12
+ select ('00000000-0000-4000-8000-00000000c0' || n)::uuid, 'authenticated', 'authenticated', 'genesis-chat-' || n || '@example.test', '00000000-0000-0000-0000-000000000000'
13
+ from unnest(array['a1', 'b2', 'd4', 'e5']) n;
14
+
15
+ create schema if not exists private;
16
+ create or replace function private.genesis_viewer_people(viewer uuid)
17
+ returns table (tenant_id uuid, person_id uuid) language sql stable set search_path = '' as $$
18
+ select '00000000-0000-4000-8000-0000000000f0'::uuid, viewer
19
+ $$;
20
+
21
+ create function pg_temp.person(n text) returns uuid language sql immutable as $$ select ('00000000-0000-4000-8000-00000000c0' || n)::uuid $$;
22
+ create function pg_temp.sign_in(n text) returns void language plpgsql as $$
23
+ begin
24
+ perform set_config('request.jwt.claims', json_build_object('sub', pg_temp.person(n), 'role', 'authenticated')::text, true);
25
+ perform set_config('request.jwt.claim.sub', pg_temp.person(n)::text, true);
26
+ perform set_config('role', 'authenticated', true);
27
+ end $$;
28
+ grant execute on function pg_temp.person(text), pg_temp.sign_in(text) to authenticated;
29
+
30
+ create temp table t (k text primary key, v uuid);
31
+ grant select, insert, update on t to authenticated;
32
+ create function pg_temp.v(k_ text) returns uuid language sql stable as $$ select v from t where k = k_ $$;
33
+ create function pg_temp.file(conv text, who text, name text) returns text language sql stable as $$
34
+ select pg_temp.v(conv) || '/' || pg_temp.person(who) || '/' || name
35
+ $$;
36
+ grant execute on function pg_temp.v(text), pg_temp.file(text, text, text) to authenticated;
37
+
38
+ create function public.genesis_chat_test_may_start(member_ids uuid[], subject_type text, subject_id text, user_id uuid)
39
+ returns boolean language sql stable set search_path = '' as $$ select true $$;
40
+ select genesis_chat.register_kind('direct', 'Direct message', p_max_members => 2,
41
+ p_start_check => 'public.genesis_chat_test_may_start(uuid[], text, text, uuid)');
42
+
43
+ select pg_temp.sign_in('a1');
44
+ insert into t select 'ab', genesis_chat.start_conversation('direct', array[pg_temp.person('b2')]);
45
+ select pg_temp.sign_in('e5');
46
+ insert into t select 'ed', genesis_chat.start_conversation('direct', array[pg_temp.person('d4')]);
47
+
48
+ reset role;
49
+ insert into storage.objects (bucket_id, name, owner_id) values
50
+ ('genesis-chat', pg_temp.file('ab', 'a1', 'photo.jpg'), pg_temp.person('a1')::text),
51
+ ('genesis-chat', pg_temp.file('ab', 'a1', 'poster.jpg'), pg_temp.person('a1')::text);
52
+
53
+ select pg_temp.sign_in('a1');
54
+ select lives_ok($$ select genesis_chat.send_message(pg_temp.v('ab'), gen_random_uuid(), '',
55
+ jsonb_build_array(jsonb_build_object('kind', 'image', 'path', pg_temp.file('ab', 'a1', 'photo.jpg')))) $$,
56
+ 'a file in storage still sends');
57
+ select lives_ok($$ select genesis_chat.send_message(pg_temp.v('ab'), gen_random_uuid(), '',
58
+ jsonb_build_array(jsonb_build_object('kind', 'video', 'provider', 'mux', 'provider_id', 'up_1', 'poster_path', pg_temp.file('ab', 'a1', 'poster.jpg')))) $$,
59
+ 'a hosted video with a poster still sends');
60
+ select lives_ok($$ select genesis_chat.send_message(pg_temp.v('ab'), gen_random_uuid(), '',
61
+ jsonb_build_array(jsonb_build_object('kind', 'link', 'provider', 'external', 'url', 'https://example.test/a'))) $$,
62
+ 'a link with no path still sends');
63
+
64
+ select pg_temp.sign_in('b2');
65
+ select ok(genesis_chat.can_read_object(pg_temp.file('ab', 'a1', 'photo.jpg'), pg_temp.person('a1')::text, now() - interval '2 days'),
66
+ 'a member reads a file in storage');
67
+ select ok(genesis_chat.can_read_object(pg_temp.file('ab', 'a1', 'poster.jpg'), pg_temp.person('a1')::text, now() - interval '2 days'),
68
+ 'and a hosted video''s poster');
69
+
70
+ select pg_temp.sign_in('e5');
71
+ select ok(not genesis_chat.can_read_object(pg_temp.file('ab', 'a1', 'photo.jpg'), pg_temp.person('a1')::text, now() - interval '2 days'),
72
+ 'someone outside the conversation doesn''t');
73
+ select throws_ok($$ select genesis_chat.send_message(pg_temp.v('ed'), gen_random_uuid(), '',
74
+ jsonb_build_array(jsonb_build_object('kind', 'file', 'provider', 'external', 'path', pg_temp.file('ab', 'a1', 'photo.jpg'), 'url', 'https://example.test/a'))) $$,
75
+ '23514', null, 'only a file in storage has a path');
76
+ select throws_ok($$ select genesis_chat.send_message(pg_temp.v('ed'), gen_random_uuid(), '',
77
+ jsonb_build_array(jsonb_build_object('kind', 'file', 'provider', 'none', 'path', pg_temp.file('ab', 'a1', 'photo.jpg')))) $$,
78
+ '23514', null, 'whatever the other provider');
79
+ select ok(not genesis_chat.can_read_object(pg_temp.file('ab', 'a1', 'photo.jpg'), pg_temp.person('a1')::text, now() - interval '2 days'),
80
+ 'and being refused grants nothing');
81
+
82
+ -- A row written before this migration, with the rule out of the way for the test.
83
+ reset role;
84
+ alter table genesis_chat.attachments drop constraint if exists attachments_path_only_in_storage;
85
+ select pg_temp.sign_in('e5');
86
+ insert into t select 'older', (genesis_chat.send_message(pg_temp.v('ed'), gen_random_uuid(), 'older')).id;
87
+ reset role;
88
+ insert into genesis_chat.attachments (message_id, conversation_id, position, kind, provider, path)
89
+ values (pg_temp.v('older'), pg_temp.v('ed'), 0, 'file', 'external', pg_temp.file('ab', 'a1', 'photo.jpg'));
90
+ select pg_temp.sign_in('e5');
91
+ select ok(not genesis_chat.can_read_object(pg_temp.file('ab', 'a1', 'photo.jpg'), pg_temp.person('a1')::text, now() - interval '2 days'),
92
+ 'an older row that isn''t in storage grants nothing either');
93
+ select throws_ok($$ select * from genesis_chat.attachment_paths_cleared $$, '42501', null, 'the record of cleared paths isn''t for people');
94
+ select pg_temp.sign_in('b2');
95
+ select ok(genesis_chat.can_read_object(pg_temp.file('ab', 'a1', 'photo.jpg'), pg_temp.person('a1')::text, now() - interval '2 days'),
96
+ 'and the member''s own access is unchanged');
97
+
98
+ -- What the migration clears, on rows the check would now refuse.
99
+ reset role;
100
+ insert into genesis_chat.attachments (message_id, conversation_id, position, kind, provider, path, url, transcript)
101
+ values (pg_temp.v('older'), pg_temp.v('ed'), 1, 'voice', 'none', 'x/y/voice.m4a', null, 'words'),
102
+ (pg_temp.v('older'), pg_temp.v('ed'), 2, 'link', 'external', 'x/y/link.jpg', 'https://example.test/keep', null);
103
+ select is(genesis_chat.clear_paths_outside_storage(), 3, 'the backfill clears every path outside storage');
104
+ select is((select count(*)::int from genesis_chat.attachments where provider <> 'storage' and path is not null), 0, 'and leaves none');
105
+ select is((select transcript from genesis_chat.attachments where message_id = pg_temp.v('older') and kind = 'voice'), null, 'a cleared voice row loses its transcript');
106
+ select is((select url from genesis_chat.attachments where message_id = pg_temp.v('older') and kind = 'link'), 'https://example.test/keep', 'a link keeps its url');
107
+ select is((select count(*)::int from genesis_chat.attachment_paths_cleared where message_id = pg_temp.v('older')), 3, 'and each is on record');
108
+ select ok(exists (select 1 from genesis_chat.attachments where provider = 'storage' and path = pg_temp.file('ab', 'a1', 'photo.jpg')), 'a file in storage keeps its path');
109
+
110
+ select * from finish();
111
+ rollback;