@marktiderman/genesis-cli 1.26.1 → 1.28.0
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.
- package/README.md +20 -1
- package/dist/cli.js +1129 -450
- package/dist/cli.js.map +1 -1
- package/dist/{config-ARs2YQ60.d.ts → config-BmMsEWU-.d.ts} +7 -0
- package/dist/doctor.d.ts +3 -3
- package/dist/doctor.js +492 -33
- package/dist/doctor.js.map +1 -1
- package/dist/expo.d.ts +2 -2
- package/dist/expo.js +11 -0
- package/dist/expo.js.map +1 -1
- package/dist/genesis-catalog.json +36 -12
- package/dist/index.d.ts +11 -5
- package/dist/index.js +493 -34
- package/dist/index.js.map +1 -1
- package/dist/starter/package.json +5 -5
- package/dist/starter/supabase/migrations/20261025000095_genesis_support_ticket_fixes.sql +115 -0
- package/dist/starter/supabase/tests/database/genesis_support_ticket_fixes.test.sql +121 -0
- package/dist/vite.js +490 -31
- package/dist/vite.js.map +1 -1
- package/package.json +4 -4
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
"@marktiderman/genesis-support": "workspace:^",
|
|
33
33
|
"@marktiderman/genesis-ui-native": "workspace:^",
|
|
34
34
|
"@react-native-async-storage/async-storage": "2.2.0",
|
|
35
|
-
"@react-native-community/datetimepicker": "9.
|
|
35
|
+
"@react-native-community/datetimepicker": "9.3.0",
|
|
36
36
|
"@react-native-community/netinfo": "12.0.1",
|
|
37
|
-
"@sentry/react-native": "~8.
|
|
37
|
+
"@sentry/react-native": "~8.34.0",
|
|
38
38
|
"@shopify/flash-list": "2.3.3",
|
|
39
39
|
"@supabase/supabase-js": "^2.118.0",
|
|
40
|
-
"@tanstack/query-async-storage-persister": "5.
|
|
41
|
-
"@tanstack/query-persist-client-core": "5.
|
|
42
|
-
"@tanstack/react-query": "5.
|
|
40
|
+
"@tanstack/query-async-storage-persister": "5.107.1",
|
|
41
|
+
"@tanstack/query-persist-client-core": "5.107.1",
|
|
42
|
+
"@tanstack/react-query": "5.107.1",
|
|
43
43
|
"clsx": "^2.1.1",
|
|
44
44
|
"expo": "~58.0.19",
|
|
45
45
|
"expo-apple-authentication": "~58.0.2",
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
-- @feat:support-feedback
|
|
2
|
+
-- Genesis support 0016: fixes to tickets (after 0004_genesis_support_tickets.sql).
|
|
3
|
+
--
|
|
4
|
+
-- 1. The Data Studio's records of support rows follow the rename. 0004 renamed
|
|
5
|
+
-- public.support_reports to public.tickets and public.support_attachments to
|
|
6
|
+
-- public.ticket_attachments; the Data Studio (genesis-studio-server) still keyed its rows by
|
|
7
|
+
-- the old names, so a ticket's history and comments stopped at the rename.
|
|
8
|
+
-- private.genesis_support_rename_studio_keys() rewrites `resource` in genesis_studio.audit_log,
|
|
9
|
+
-- comments, outbox and outbox_dead_letter, and the `resource` inside the outbox's and dead
|
|
10
|
+
-- letter's `payload` (what a delivery sends downstream), only where those tables exist
|
|
11
|
+
-- (to_regclass), and returns how many rows moved. It runs once here; running it again changes nothing.
|
|
12
|
+
-- 2. public.support_agent_unread_count(tenant) returns how many open tickets of a tenant hold a
|
|
13
|
+
-- message from the requester no agent has read: an agent's badge without reading the queue.
|
|
14
|
+
-- A null tenant means the app's own. Only an agent of the tenant may ask (42501 otherwise),
|
|
15
|
+
-- and an agent's own ticket isn't counted, as they can't handle it.
|
|
16
|
+
--
|
|
17
|
+
-- A notification for the verify prompt (0003: support_replies.prompt = 'verify') keys on that
|
|
18
|
+
-- column, never on the reply's words: the words are a sentence an app may translate or change.
|
|
19
|
+
--
|
|
20
|
+
-- Use: copy this file into your app's `supabase/migrations/` under a new timestamped name
|
|
21
|
+
-- (`genesis migrate` does it). Never edit it once applied; change it with a new migration.
|
|
22
|
+
--
|
|
23
|
+
-- Verify: the pgTAP test beside this file (`tests/0016_genesis_support_ticket_fixes.test.sql`).
|
|
24
|
+
|
|
25
|
+
create schema if not exists private;
|
|
26
|
+
|
|
27
|
+
-- 1. The Data Studio's keys --------------------------------------------------------------------
|
|
28
|
+
|
|
29
|
+
create or replace function private.genesis_support_rename_studio_keys()
|
|
30
|
+
returns integer
|
|
31
|
+
language plpgsql
|
|
32
|
+
security definer
|
|
33
|
+
set search_path = ''
|
|
34
|
+
as $$
|
|
35
|
+
declare
|
|
36
|
+
moved integer := 0;
|
|
37
|
+
n integer;
|
|
38
|
+
t text;
|
|
39
|
+
begin
|
|
40
|
+
foreach t in array array['genesis_studio.audit_log', 'genesis_studio.comments', 'genesis_studio.outbox', 'genesis_studio.outbox_dead_letter'] loop
|
|
41
|
+
if to_regclass(t) is null then
|
|
42
|
+
continue;
|
|
43
|
+
end if;
|
|
44
|
+
execute format(
|
|
45
|
+
'update %s set resource = case resource
|
|
46
|
+
when ''public.support_reports'' then ''public.tickets''
|
|
47
|
+
when ''support_reports'' then ''tickets''
|
|
48
|
+
when ''public.support_attachments'' then ''public.ticket_attachments''
|
|
49
|
+
when ''support_attachments'' then ''ticket_attachments''
|
|
50
|
+
end
|
|
51
|
+
where resource in (''public.support_reports'', ''support_reports'', ''public.support_attachments'', ''support_attachments'')',
|
|
52
|
+
t);
|
|
53
|
+
get diagnostics n = row_count;
|
|
54
|
+
moved := moved + n;
|
|
55
|
+
end loop;
|
|
56
|
+
-- What a delivery carries downstream names the resource too.
|
|
57
|
+
foreach t in array array['genesis_studio.outbox', 'genesis_studio.outbox_dead_letter'] loop
|
|
58
|
+
if to_regclass(t) is null then
|
|
59
|
+
continue;
|
|
60
|
+
end if;
|
|
61
|
+
execute format(
|
|
62
|
+
'update %s set payload = jsonb_set(payload, ''{resource}'', to_jsonb(case payload ->> ''resource''
|
|
63
|
+
when ''public.support_reports'' then ''public.tickets''
|
|
64
|
+
when ''support_reports'' then ''tickets''
|
|
65
|
+
when ''public.support_attachments'' then ''public.ticket_attachments''
|
|
66
|
+
when ''support_attachments'' then ''ticket_attachments''
|
|
67
|
+
end))
|
|
68
|
+
where payload ->> ''resource'' in (''public.support_reports'', ''support_reports'', ''public.support_attachments'', ''support_attachments'')',
|
|
69
|
+
t);
|
|
70
|
+
get diagnostics n = row_count;
|
|
71
|
+
moved := moved + n;
|
|
72
|
+
end loop;
|
|
73
|
+
return moved;
|
|
74
|
+
end;
|
|
75
|
+
$$;
|
|
76
|
+
|
|
77
|
+
comment on function private.genesis_support_rename_studio_keys() is
|
|
78
|
+
'Moves the Data Studio''s audit and outbox rows from the old support table names to tickets and ticket_attachments. Genesis support.';
|
|
79
|
+
revoke execute on function private.genesis_support_rename_studio_keys() from public, anon, authenticated;
|
|
80
|
+
|
|
81
|
+
select private.genesis_support_rename_studio_keys();
|
|
82
|
+
|
|
83
|
+
-- 2. An agent's unread count -------------------------------------------------------------------
|
|
84
|
+
|
|
85
|
+
create or replace function public.support_agent_unread_count(tenant uuid default null)
|
|
86
|
+
returns integer
|
|
87
|
+
language plpgsql
|
|
88
|
+
stable
|
|
89
|
+
security definer
|
|
90
|
+
set search_path = ''
|
|
91
|
+
as $$
|
|
92
|
+
declare
|
|
93
|
+
me uuid := auth.uid();
|
|
94
|
+
resolved uuid := coalesce(tenant, private.genesis_support_default_tenant_id());
|
|
95
|
+
begin
|
|
96
|
+
if me is null or not private.genesis_support_agent(resolved, me) then
|
|
97
|
+
raise exception 'support_agent_unread_count: only an agent of this tenant' using errcode = '42501';
|
|
98
|
+
end if;
|
|
99
|
+
return (
|
|
100
|
+
select count(*)::integer
|
|
101
|
+
from public.tickets t
|
|
102
|
+
where t.tenant_id = resolved
|
|
103
|
+
and t.user_id is distinct from me
|
|
104
|
+
-- Active tickets only, as 0013's queues count them: not pending (waiting on the requester),
|
|
105
|
+
-- not closed.
|
|
106
|
+
and t.status not in ('pending', 'addressed', 'wont_fix')
|
|
107
|
+
and (t.staff_read_at is null or coalesce(t.last_user_reply_at > t.staff_read_at, false))
|
|
108
|
+
);
|
|
109
|
+
end;
|
|
110
|
+
$$;
|
|
111
|
+
|
|
112
|
+
comment on function public.support_agent_unread_count(uuid) is
|
|
113
|
+
'How many active tickets (not pending, not closed) of a tenant hold a requester''s message no agent has read, for its agents. Genesis support.';
|
|
114
|
+
revoke execute on function public.support_agent_unread_count(uuid) from public, anon;
|
|
115
|
+
grant execute on function public.support_agent_unread_count(uuid) to authenticated;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
-- @feat:support-feedback
|
|
2
|
+
-- pgTAP test for 0016_genesis_support_ticket_fixes.sql: the Data Studio's keys follow the rename,
|
|
3
|
+
-- and an agent's unread count. Copy into your app's `supabase/tests/database/` and run
|
|
4
|
+
-- `supabase test db`. Rolls everything back; the app's hooks are replaced inside this transaction.
|
|
5
|
+
--
|
|
6
|
+
-- Tenants: d (the app's own), ta and tb. People: a1 a client of ta; b2 a client of tb; c3 an agent
|
|
7
|
+
-- of ta; e5 an agent of tb.
|
|
8
|
+
begin;
|
|
9
|
+
create extension if not exists pgtap with schema extensions;
|
|
10
|
+
select plan(14);
|
|
11
|
+
|
|
12
|
+
create function pg_temp.tenant(n text) returns uuid language sql immutable as $$
|
|
13
|
+
select case n when 'd' then '00000000-0000-4000-8000-00000000000f'::uuid
|
|
14
|
+
when 'ta' then '00000000-0000-4000-8000-0000000000a0'::uuid
|
|
15
|
+
else '00000000-0000-4000-8000-0000000000b0'::uuid end $$;
|
|
16
|
+
create function pg_temp.person(n text) returns uuid language sql immutable as $$
|
|
17
|
+
select ('00000000-0000-4000-8000-0000000004' || n)::uuid $$;
|
|
18
|
+
create function pg_temp.sign_in(n text) returns void language plpgsql as $$
|
|
19
|
+
begin
|
|
20
|
+
perform set_config('request.jwt.claims', json_build_object('sub', pg_temp.person(n), 'role', 'authenticated')::text, true);
|
|
21
|
+
perform set_config('request.jwt.claim.sub', pg_temp.person(n)::text, true);
|
|
22
|
+
end $$;
|
|
23
|
+
|
|
24
|
+
insert into auth.users (id, aud, role, email, instance_id)
|
|
25
|
+
select pg_temp.person(n), 'authenticated', 'authenticated', 'genesis-fixes-' || n || '@example.test',
|
|
26
|
+
'00000000-0000-0000-0000-000000000000'
|
|
27
|
+
from unnest(array['a1', 'b2', 'c3', 'e5']) n;
|
|
28
|
+
|
|
29
|
+
create or replace function private.genesis_support_default_tenant() returns uuid
|
|
30
|
+
language sql stable set search_path = '' as $$ select '00000000-0000-4000-8000-00000000000f'::uuid $$;
|
|
31
|
+
create or replace function private.genesis_viewer_people(viewer uuid)
|
|
32
|
+
returns table (tenant_id uuid, person_id uuid) language sql stable set search_path = '' as $$
|
|
33
|
+
select t.tenant_id, viewer from (values
|
|
34
|
+
('00000000-0000-4000-8000-0000000004a1'::uuid, '00000000-0000-4000-8000-0000000000a0'::uuid),
|
|
35
|
+
('00000000-0000-4000-8000-0000000004c3', '00000000-0000-4000-8000-0000000000a0'),
|
|
36
|
+
('00000000-0000-4000-8000-0000000004b2', '00000000-0000-4000-8000-0000000000b0'),
|
|
37
|
+
('00000000-0000-4000-8000-0000000004e5', '00000000-0000-4000-8000-0000000000b0')
|
|
38
|
+
) as t(login, tenant_id) where t.login = viewer $$;
|
|
39
|
+
drop function if exists private.genesis_tenant_admin(uuid, uuid);
|
|
40
|
+
drop function if exists private.genesis_support_report_handler(uuid, uuid);
|
|
41
|
+
revoke execute on function private.genesis_support_default_tenant() from public, anon, authenticated;
|
|
42
|
+
revoke execute on function private.genesis_viewer_people(uuid) from public, anon, authenticated;
|
|
43
|
+
|
|
44
|
+
insert into public.ticket_agents (tenant_id, person_id, role) values
|
|
45
|
+
(pg_temp.tenant('ta'), pg_temp.person('c3'), 'agent'),
|
|
46
|
+
(pg_temp.tenant('tb'), pg_temp.person('e5'), 'agent');
|
|
47
|
+
|
|
48
|
+
create table if not exists public.tenant_features (
|
|
49
|
+
tenant_id uuid not null, feature_id text not null, enabled boolean not null, reason text not null,
|
|
50
|
+
primary key (tenant_id, feature_id));
|
|
51
|
+
insert into public.tenant_features (tenant_id, feature_id, enabled, reason) values
|
|
52
|
+
(pg_temp.tenant('ta'), 'support-helpdesk', true, 'test'),
|
|
53
|
+
(pg_temp.tenant('tb'), 'support-helpdesk', true, 'test')
|
|
54
|
+
on conflict (tenant_id, feature_id) do update set enabled = true;
|
|
55
|
+
|
|
56
|
+
-- 1. The Data Studio's keys ---------------------------------------------------------------------
|
|
57
|
+
|
|
58
|
+
select ok(not has_function_privilege('authenticated', 'private.genesis_support_rename_studio_keys()', 'execute'), 'nobody signed in rewrites the studio''s keys');
|
|
59
|
+
|
|
60
|
+
create schema if not exists genesis_studio;
|
|
61
|
+
create table if not exists genesis_studio.audit_log (
|
|
62
|
+
id uuid primary key default gen_random_uuid(), occurred_at timestamptz not null default clock_timestamp(),
|
|
63
|
+
actor text, actor_claims jsonb, resource text not null, record_key jsonb not null, action text not null, before jsonb, after jsonb);
|
|
64
|
+
create table if not exists genesis_studio.comments (
|
|
65
|
+
id uuid primary key default gen_random_uuid(), resource text not null, record_key jsonb not null, author text, body text not null,
|
|
66
|
+
created_at timestamptz not null default now());
|
|
67
|
+
create table if not exists genesis_studio.outbox (
|
|
68
|
+
id uuid primary key default gen_random_uuid(), seq bigserial, resource text not null, record_key jsonb not null, payload jsonb not null);
|
|
69
|
+
create table if not exists genesis_studio.outbox_dead_letter (
|
|
70
|
+
id uuid primary key default gen_random_uuid(), resource text not null, record_key jsonb not null, payload jsonb not null);
|
|
71
|
+
insert into genesis_studio.audit_log (resource, record_key, action) values
|
|
72
|
+
('public.support_reports', '"r1"', 'update'),
|
|
73
|
+
('public.support_attachments', '"a1"', 'create'),
|
|
74
|
+
('public.goals', '"g1"', 'update');
|
|
75
|
+
insert into genesis_studio.comments (resource, record_key, body) values ('public.support_reports', '"r1"', 'A note on the old name');
|
|
76
|
+
insert into genesis_studio.outbox (resource, record_key, payload) values ('public.support_reports', '"r1"', '{"resource": "public.support_reports", "action": "update"}');
|
|
77
|
+
insert into genesis_studio.outbox_dead_letter (resource, record_key, payload) values ('support_attachments', '"a1"', '{"resource": "support_attachments"}');
|
|
78
|
+
|
|
79
|
+
select is(private.genesis_support_rename_studio_keys(), 7, 'the old names move: three columns and two payloads besides the audit log');
|
|
80
|
+
select is((select array_agg(resource order by resource) from genesis_studio.audit_log where record_key in ('"r1"', '"a1"', '"g1"')),
|
|
81
|
+
array['public.goals', 'public.ticket_attachments', 'public.tickets'], '... to tickets and ticket_attachments, and nothing else moves');
|
|
82
|
+
select is((select resource from genesis_studio.comments where record_key = '"r1"'), 'public.tickets', 'a comment follows the rename');
|
|
83
|
+
select is((select resource || ' ' || (payload ->> 'resource') from genesis_studio.outbox where record_key = '"r1"'), 'public.tickets public.tickets', 'an outbox row and the payload it delivers follow it');
|
|
84
|
+
select is((select resource || ' ' || (payload ->> 'resource') from genesis_studio.outbox_dead_letter where record_key = '"a1"'), 'ticket_attachments ticket_attachments', 'a dead letter and its payload follow it');
|
|
85
|
+
select is(private.genesis_support_rename_studio_keys(), 0, 'running it again changes nothing');
|
|
86
|
+
|
|
87
|
+
-- 2. An agent's unread count --------------------------------------------------------------------
|
|
88
|
+
|
|
89
|
+
select pg_temp.sign_in('a1');
|
|
90
|
+
set local role authenticated;
|
|
91
|
+
insert into public.tickets (type, title, message, tenant_id) values ('question', 'fix-ta1', 'Unread in ta', pg_temp.tenant('ta'));
|
|
92
|
+
insert into public.tickets (type, title, message, tenant_id) values ('question', 'fix-ta2', 'Read in ta', pg_temp.tenant('ta'));
|
|
93
|
+
insert into public.tickets (type, title, message, tenant_id) values ('question', 'fix-ta3', 'Closed in ta', pg_temp.tenant('ta'));
|
|
94
|
+
select pg_temp.sign_in('b2');
|
|
95
|
+
insert into public.tickets (type, title, message, tenant_id) values ('question', 'fix-tb1', 'Unread in tb', pg_temp.tenant('tb'));
|
|
96
|
+
reset role;
|
|
97
|
+
update public.tickets set staff_read_at = now() + interval '1 minute' where title = 'fix-ta2';
|
|
98
|
+
update public.tickets set status = 'addressed' where title = 'fix-ta3';
|
|
99
|
+
|
|
100
|
+
set local role authenticated;
|
|
101
|
+
select pg_temp.sign_in('c3');
|
|
102
|
+
select is(public.support_agent_unread_count(pg_temp.tenant('ta')), 1, 'an agent counts the open tickets nobody has read');
|
|
103
|
+
select pg_temp.sign_in('e5');
|
|
104
|
+
select is(public.support_agent_unread_count(pg_temp.tenant('tb')), 1, 'each tenant its own');
|
|
105
|
+
select throws_ok($$ select public.support_agent_unread_count('00000000-0000-4000-8000-0000000000a0') $$, '42501', null, 'an agent of another tenant can''t ask');
|
|
106
|
+
select pg_temp.sign_in('a1');
|
|
107
|
+
select throws_ok($$ select public.support_agent_unread_count('00000000-0000-4000-8000-0000000000a0') $$, '42501', null, 'nor can a requester');
|
|
108
|
+
reset role;
|
|
109
|
+
|
|
110
|
+
-- A requester's new message makes a read ticket unread again.
|
|
111
|
+
update public.tickets set last_user_reply_at = now() + interval '2 minutes' where title = 'fix-ta2';
|
|
112
|
+
set local role authenticated;
|
|
113
|
+
select pg_temp.sign_in('c3');
|
|
114
|
+
select is(public.support_agent_unread_count(pg_temp.tenant('ta')), 2, 'a new message from the requester is unread again');
|
|
115
|
+
reset role;
|
|
116
|
+
|
|
117
|
+
select ok(not has_function_privilege('anon', 'public.support_agent_unread_count(uuid)', 'execute'), 'anon can''t ask');
|
|
118
|
+
select ok(has_function_privilege('authenticated', 'public.support_agent_unread_count(uuid)', 'execute'), 'a signed-in agent can');
|
|
119
|
+
|
|
120
|
+
select * from finish();
|
|
121
|
+
rollback;
|