apps/product-analytics: a standalone Node 22 service (hono, pg, fflate, jose)
that speaks the public SDK capture protocol (/e/, /i/v0/e/, /batch/,
/capture/, /engage/, /groups/, /flags/?v=2, /decide/, /array/:token/config)
over JSON, gzip, base64 and form data, stores into Postgres (monthly
partitions, RLS on pa.project_id plus a bound project_id), resolves people
with identify/alias/merge semantics ported from the upstream persons code
(MIT, cbb1e9253027), applies the console caps (byte copy, drift-tested),
meters scribase.analytics.events behind RAILYARD_LIVE, drops IPs, runs
privacy deletions as visible jobs and trims to each plan's window.
Hand-offs created now (empty on purpose):
- src/routes.ts mounts src/insights/routes.ts -> A2
- src/routes.ts mounts src/{replay,heatmaps,surveys,experiments,exports}/routes.ts -> A3
- src/remote-config/sections.ts (replay, heatmaps, surveys providers) -> A3
- src/flags/variants.ts (returns null) -> A3
- src/replay/gdpr.ts and src/surveys/gdpr.ts privacy hooks -> A3
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
37 lines
1.3 KiB
SQL
37 lines
1.3 KiB
SQL
-- Row level security: every table is scoped to pa.current_project() for the
|
|
-- request role. The service also binds project_id in every query, so a
|
|
-- mistake in one guard is still caught by the other.
|
|
|
|
do $$
|
|
declare
|
|
t text;
|
|
begin
|
|
foreach t in array array[
|
|
'events', 'persons', 'person_distinct_ids', 'person_overrides', 'group_types', 'groups',
|
|
'ingest_receipts', 'usage_monthly', 'project_firsts', 'rollup_hourly', 'project_settings', 'gdpr_jobs'
|
|
]
|
|
loop
|
|
execute format('alter table pa.%I enable row level security', t);
|
|
execute format('drop policy if exists project_isolation on pa.%I', t);
|
|
execute format(
|
|
'create policy project_isolation on pa.%I for all to pa_app using (project_id = pa.current_project()) with check (project_id = pa.current_project())',
|
|
t
|
|
);
|
|
execute format('grant select, insert, update, delete on pa.%I to pa_app', t);
|
|
end loop;
|
|
end
|
|
$$;
|
|
|
|
do $$
|
|
begin
|
|
if exists (select 1 from pg_roles where rolname = 'anon') then
|
|
execute 'revoke all on all tables in schema pa from anon';
|
|
execute 'revoke usage on schema pa from anon';
|
|
end if;
|
|
if exists (select 1 from pg_roles where rolname = 'authenticated') then
|
|
execute 'revoke all on all tables in schema pa from authenticated';
|
|
execute 'revoke usage on schema pa from authenticated';
|
|
end if;
|
|
end
|
|
$$;
|