Clix + Supabase Integration
This guide shows how to integrate Clix push notifications into a Supabase project using Edge Functions and Postgres triggers. You will:- Add a reusable
ClixClientinsidesupabase/functions/_shared - (Recommended) Create helper builders for
ClixNotificationpayloads - Deploy Edge Functions that send notifications
- Optionally wire automatic dispatch via database triggers with
pg_net
1. Prerequisites
- A Supabase project (with CLI installed) – https://supabase.com/docs/guides/cli
- A Clix project (obtain Project ID + Secret API Key)
- Supabase CLI authenticated:
supabase login - (If using triggers) Postgres extension
pg_netenabled (we’ll cover this below)
2. Configure Secrets / Environment Variables
Store credentials as Supabase Function secrets (never hard‑code keys):Set Supabase Edge Function secrets
- Secrets: https://supabase.com/docs/guides/functions/secrets
- Environment access in Deno: https://supabase.com/docs/guides/functions#environment-variables
3. Add the Shared Clix Client
Create the file below atsupabase/functions/_shared/clix_client.ts.
supabase/functions/_shared/clix_client.ts
4. (Recommended) Add Scenario Helper Builders
Instead of hand‑crafting notification objects each time, centralize builders for consistent structure and future enrichment.supabase/functions/_shared/notification_scenarios.ts
5. Edge Function: Notify Todo Completion
Minimal example: accept atodo_id and a target project_user_id, build a notification, and send it via ClixClient (no database lookup logic included here).
supabase/functions/notify-todo/index.ts
Deploy the Function
6. Calling the Edge Function (Invocation Options)
You can integratenotify-todo in three primary ways—choose based on coupling, complexity, and operational preferences. (Code snippets intentionally omitted.)
- Database Trigger (pg_net): Attach a lightweight trigger to the
todostable so when a row transitions tocompleted, Postgres performs an HTTP POST to the deployed Edge Function. Pros: automatic, low latency, no extra app call. Cons: trigger logic inside SQL, needspg_netand careful key handling. - Direct API Call: From your backend (or another Edge Function) perform an authenticated POST with the
todo_id. Pros: simplest to reason about in application code, easier to add conditional logic or retries. Cons: requires your app layer to explicitly invoke for every event. - Scheduled / Batch Orchestrator: Periodic job (cron, scheduled function, worker) queries for recently completed todos and sends notifications in batches (reduces per-event overhead). Pros: efficient for high volume; can deduplicate. Cons: not real-time; added scheduling complexity.
- Want instant, automatic dispatch on state change? Use a trigger.
- Need business rules (feature flags, throttling, analytics gating)? Use direct API call.
- Need aggregation (daily digests, rate limiting)? Use scheduled batch.
7. Testing the Flow
- Insert / update a
todoto statuscompleted - Confirm
notification_dispatch_logentries - Verify successful HTTP responses & Clix dashboard reception
- For manual test call the function:
8. Security & Best Practices
- Put your Clix Secret API Key only in Supabase secrets (never ship to clients)
- Prefer trigger-based automation for reliability; fall back to client calls when immediacy or dynamic logic is required
- Use structured builders to evolve payloads without touching every function
- Log responses (already in examples) for observability; consider adding retention policies
9. Useful Supabase Docs
- Edge Functions: https://supabase.com/docs/guides/functions
- Secrets: https://supabase.com/docs/guides/functions/secrets
- Supabase JS client: https://supabase.com/docs/reference/javascript/start
- Database Functions & Triggers: https://supabase.com/docs/guides/database/functions
- RLS: https://supabase.com/docs/guides/auth/row-level-security
pg_netExtension: https://supabase.com/docs/guides/database/extensions/pg_net
10. Summary
You now have:- A reusable
ClixClientconsuming environment secrets - Scenario helpers for consistent notifications
- Edge Functions (
notify-todo) to send messages - Optional Postgres triggers to automatically invoke those functions