Onboarding PathIntegration Developer track

Integration Developer track

The generalist track teaches you the stack. This one teaches you its edges: the surfaces where something outside HiveCFM talks to it, and the database you will be asked to query the first time somebody says “the numbers look wrong”.

Eleven milestones. Four are SQL you run against a real database, four end in a request you send or a change you push, and three end in an answer you have to be able to defend from the file, with a line number. None of them is finished by having read something.

Prerequisite: the generalist track. Do Week 1 and Week 2 first. This page assumes you already have the stack up per Run it locally, have traced one browser response to a database insert, and have merged something. It does not repeat any of it.

Ground rules

Two databases, and they are not interchangeable. Both live in the container hivecfm-postgres-t3060, mapped to 127.0.0.1:5460.

  • devhub_ref carries the exact origin/development schema and zero rows. It is the schema authority. EXPLAIN here; never COUNT here.
  • hivecfm carries real rows — 1191 Survey, 70333 Contact, 1498 Response — on an older, migration-era schema. Use it to prove a query returns plausible rows, never to settle what a column is called. Two differences you will hit within an hour: "Response".answered_questions_count does not exist there, and the "Invitation" table still does.
  • Neither one is a client database. Nothing on this page needs a write, and nothing on this page should ever be pointed at a tenant’s environment.

Your local psql proves nothing about isolation. psql -U postgres connects as a superuser, and a superuser bypasses row-level security entirely. Even as a non-superuser, all 20 policies are FOR ALL, shaped current_setting('app.current_tenant', true) IS NULL OR <scope check>, with a USING clause and no WITH CHECK. Postgres reuses that USING expression as the new-row check, so an unset GUC does not just make every row of every tenant visible — it also lets a write name any tenant it likes. So: every query you write filters tenant explicitly. If you catch yourself leaning on RLS to scope a result, you have written a query that will hand back another client’s rows the first time it runs somewhere you did not expect.

Never paste a real API key or a real channels.config into a ticket, a chat message, or a commit. channels.config is the jsonb column holding per-channel connector settings, and channels is named in both RLS scripts and reached by neither, so it carries no row-level security at all — you reproduce that in milestone 4. It is not alone in having none: only 19 of the 47 tables end up with RLS enabled — channels is the only one the scripts reach for and miss, and the remaining 27 they never mention. Redact to the last four characters. To show someone a failing request, send it with x-api-key: <redacted> and say which environment the key was scoped to.

When a comment and the code disagree, the code wins. Two live examples are in this track: a TypeScriptTypeScriptJavaScript with a static type system. Every HiveCFM Node service, the frontend, and the dev hub are written in it. interface that does not describe the wire it claims to (milestone 7), and a SQL script whose last statement prints a success line after two of its earlier statements failed (milestone 4). Both are load-bearing.

The checklist

Integration track progress

0 of 11 complete

The queries the checklist asks you to run

Pipe SQL on stdin. Do not use psql -f with a Windows path — the container cannot see it, and Git Bash rewrites the path on the way in.

docker exec -i hivecfm-postgres-t3060 psql -U postgres -d devhub_ref

Milestone 1 — the table-naming trap

Which tables can be written unquoted. Returns 12 rows on devhub_ref.

SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
  AND table_name = lower(table_name)
ORDER BY table_name;

Milestone 1 — the column-naming trap

Which tables mix conventions. Returns 34 rows on devhub_ref, out of 47 tables.

SELECT table_name,
       count(*) FILTER (WHERE column_name <> lower(column_name)) AS camel_cols,
       count(*) FILTER (WHERE column_name  = lower(column_name)) AS snake_cols
FROM information_schema.columns
WHERE table_schema = 'public'
GROUP BY table_name
HAVING count(*) FILTER (WHERE column_name <> lower(column_name)) > 0
   AND count(*) FILTER (WHERE column_name  = lower(column_name)) > 0
ORDER BY table_name;

"Survey" comes back with 28 camelCase and 24 snake_case columns. There is nothing to memorise; read the catalog or Schema Viewer every time.

Milestone 3 — find the busiest element, then aggregate it

Run both against hivecfm, not devhub_ref — devhub_ref has no rows. :'environment_id' is the quoted-literal psql variable form the cookbook uses in Read this first; the bare :environment_id there interpolates a raw token and Postgres reads it as an identifier. Both blocks set it themselves so each runs as printed.

\set environment_id 'cmr0o5ivu000clc01glv55m4p'
SELECT jsonb_object_keys(r.data) AS element_id, count(*) AS answers
FROM "Response" r
JOIN "Survey" s ON s.id = r."surveyId"
WHERE s."environmentId" = :'environment_id'
GROUP BY 1
ORDER BY 2 DESC
LIMIT 3;

The JOIN looks like overhead on a “which key is busiest” question, and it is the ground rule doing its job: "Response" carries no environmentId, so without it you are counting every tenant’s keys together. Take the top element_id and aggregate it with the same filter in place.

\set environment_id 'cmr0o5ivu000clc01glv55m4p'
\set element_id 'u3dkc8c037di1wkqwaauwnw7'
SELECT r.data->>:'element_id' AS answer, count(*)
FROM "Response" r
JOIN "Survey" s ON s.id = r."surveyId"
WHERE s."environmentId" = :'environment_id'
  AND r.data ? :'element_id'
GROUP BY 1
ORDER BY 2 DESC;

Add AND r.answered_questions_count > 0 and the same shape plans cleanly on devhub_ref; on hivecfm that column does not exist, so the honest version of this recipe and the version that returns rows are on different databases.

Milestone 4 — RLS enabled, policies missing

Run after piping both scripts/rls/*.sql into devhub_ref. One table comes back with 0.

SELECT c.relname, count(p.policyname) AS policies
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
LEFT JOIN pg_policies p ON p.tablename = c.relname AND p.schemaname = 'public'
WHERE n.nspname = 'public' AND c.relkind = 'r' AND c.relrowsecurity
GROUP BY c.relname
ORDER BY policies, c.relname;

Milestone 4 — a table both scripts named and neither reached

channels comes back f while its neighbours come back t.

SELECT relname, relrowsecurity AS rls_on
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE n.nspname = 'public'
  AND relkind = 'r'
  AND relname IN ('channels', 'ContactAttribute', 'Response', 'Survey');
⚠️

Both queries above report the catalog, not behaviour. As postgres you bypass RLS, so you will never see a row vanish no matter how broken a policy is. That is the point of the milestone: on this box, the catalog is the only evidence you have, and a passing script run is not evidence at all.

Check-in

Before you call this track done, answer these without looking:

  1. Which header authenticates an IVR POST, and which permission must the key hold on which scope?
  2. A row’s data reads {"u3dkc8c037di1wkqwaauwnw7": 2}. What was the question, and how do you find out?
  3. A receiver reports “signature invalid” for the Test Endpoint ping but valid for real deliveries. Is that a bug?
  4. Which four element types does a chat survey silently skip, and where is that list?
  5. Where does bot session state live, and what does botState mean on the wire?

If any of those is fuzzy, the milestone that covers it did not land — go back to it rather than reading about it.

Where to look in the code

Paths are relative to hivecfm-core at origin/development.

  • apps/web/app/api/v1/management/bot-connector/turn/route.ts — the 966-line bot handler; replymessages is assigned at line 291.
  • apps/web/app/api/v1/management/bot-connector/lib/types.ts — ZBotConnectorRequest, BOT_INTENTS, and the replyMessages interface that contradicts the wire (line 109).
  • apps/web/app/api/v1/management/bot-connector/lib/question-formatter.ts — formatQuestionAsReply, parseAnswer, and isSupportedInChat.
  • apps/web/app/api/v1/management/bot-connector/bots/route.ts — the hard-coded bot registry Genesys polls for the Bot Name dropdown.
  • apps/web/app/api/v1/client/[environmentId]/ivr/[surveyId]/responses/route.ts — ZIvrResponseInput, the callId → singleUseId merge, and meta.source.
  • apps/web/app/api/v1/client/[environmentId]/ivr/[surveyId]/lib/api-key-auth.ts — checkIvrApiKeyAccess, the per-environment permission gate for all four IVR routes.
  • apps/web/app/api/v1/auth.ts — where a v1 route reads x-api-key and resolves it to environmentPermissions.
  • apps/web/app/lib/pipelines.ts — sendToPipeline, and the .catch() that swallows a failed hand-off.
  • apps/web/app/api/(internal)/pipeline/route.ts — webhook selection, the Standard Webhooks headers, and the 5-second fetchWithTimeout.
  • apps/web/modules/api/v2/management/webhooks/route.ts, lib/webhook.ts and types/webhooks.ts — ZWebhookInput, which does not accept a secret, and the createWebhook that generates one. apps/web/app/api/v2/management/webhooks/route.ts is a three-line re-export; the URL comes from there.
  • apps/web/modules/integrations/webhooks/lib/webhook.ts — createWebhook and testEndpoint; the throwaway test secret is line 130.
  • apps/web/lib/crypto.ts — generateWebhookSecret and generateStandardWebhookSignature.
  • apps/web/lib/tenant/context.ts — withTenantContext(), which sets app.current_tenant to an organizationId per transaction.
  • scripts/rls/enable-rls.sql, scripts/rls/create-policies.sql, scripts/rls/test-rls.sql — the three RLS scripts; the first two are what milestone 4 breaks.
  • packages/types/surveys/elements.ts — TSurveyElementTypeEnum, the 15 element type strings.
  • packages/database/schema.prisma — 47 models, 12 of them @@map’d; Webhook.secret is nullable.

HiveCFM Developer Hub — internal team guide