wacrm/supabase/migrations
Arnas Donauskas 456321a2f2
feat(api): public API groundwork — scoped API keys + /api/v1/me
Adds the machine-to-machine auth layer the public REST API needs so
external scripts and automations can drive wacrm (issue #245). This is
the groundwork release; data endpoints land one at a time on top of it.

- Migration 026: account-scoped `api_keys` table. SHA-256 hash at rest
  (plaintext shown once), display `key_prefix`, `scopes[]`, RLS via
  `is_account_member` (members read, admin+ manage).
- `src/lib/api-keys/`: key gen/hash (wacrm_live_ prefix, timing-safe),
  scope vocabulary, service-role auth-path store.
- `requireApiKey(request, scope?)` (src/lib/auth/api-context.ts):
  bearer parse -> hash lookup -> liveness -> per-key rate limit ->
  scopes-only authz. Returns a service-role-scoped account context.
- `/api/v1` envelope ({data} / {error:{code,message}}) + GET /api/v1/me
  reference endpoint that exercises the whole stack.
- Dashboard: admin+ key management routes + Settings -> API keys tab.
- Docs (docs/public-api.md), CHANGELOG, README, .env note.

Checks: typecheck clean, lint 0 errors, full suite green (+27 tests).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 15:35:43 +03:00
..
001_initial_schema.sql fix: make migration idempotent 2026-04-16 19:46:41 +03:00
002_pipelines_enhancements.sql feat(pipelines): Kanban drag-drop, analytics, deal sheet, contact deals tab 2026-04-16 22:38:45 +03:00
003_broadcast_recipient_wamid.sql fix(broadcasts): per-recipient variables, webhook status sync, rate limit 2026-04-17 11:22:38 +03:00
004_contact_delete_set_null.sql fix(contacts): allow deletion — SET NULL on broadcast_recipients, deals 2026-04-17 16:56:45 +03:00
005_broadcast_counts_incremental.sql fix(broadcasts): senior-review hardening pass 2026-04-17 17:38:52 +03:00
006_automations.sql feat(automations): visual flow builder, engine, and logs viewer 2026-04-17 19:39:02 +03:00
007_automations_increment_counter.sql fix(automations): atomic execution_count via SQL function (migration 007) 2026-04-17 21:45:27 +03:00
008_profile_avatars_storage.sql feat(settings): user profile management 2026-04-20 17:40:39 +03:00
009_message_actions.sql feat(inbox): reactions, reply-to, and copy on chat messages 2026-05-19 16:17:26 +03:00
010_flows.sql feat(flows): foundation for interactive WhatsApp messages (PR 1/4) 2026-05-22 13:12:27 +03:00
011_profile_beta_features.sql feat(beta): per-account beta_features flag on profiles, gating Flows 2026-05-22 12:57:33 +03:00
012_flows_increment_counter.sql fix(flows): atomic execution_count increment via SECURITY DEFINER RPC 2026-05-22 15:39:00 +03:00
013_whatsapp_config_phone_number_id_unique.sql fix(whatsapp): prevent silent inbound-message drop when two users share a phone_number_id 2026-05-26 10:35:59 +02:00
014_message_templates_meta_integration.sql fix(migration-014): drop subquery from buttons CHECK (Postgres disallows it) 2026-05-29 12:21:14 +02:00
015_whatsapp_config_registration.sql fix(whatsapp): register phone numbers on Meta + verify subscription state 2026-05-29 18:12:38 +02:00
016_flow_media.sql feat(flows): add send_media node for image / video / document sends 2026-05-29 19:11:29 +02:00
017_account_sharing.sql fix(migrations): make 017 RLS rewrite re-runnable 2026-06-22 09:48:47 +03:00
018_account_member_rpcs.sql feat(api): account + members management endpoints 2026-05-31 15:00:27 +03:00
019_invitation_rpcs.sql feat(api): invitation create + peek + redeem endpoints 2026-05-31 17:32:46 +03:00
020_account_sharing_followups.sql perf(db,webhook): backend follow-ups from the multi-user review 2026-05-31 19:18:58 +03:00
021_account_default_currency.sql feat(deals): make default deal currency configurable per account (#218) 2026-06-08 13:59:48 +03:00
022_contact_phone_dedup.sql feat(contacts): prevent duplicate phone numbers on create/import (#212) 2026-06-08 15:52:38 +03:00
023_chat_media.sql feat(inbox): send photo, video, document & voice in chat (#213) 2026-06-18 10:07:16 +03:00
024_member_presence.sql feat(team): member presence (online / away / offline) on the roster 2026-06-22 14:37:29 +03:00
025_filter_contacts_by_tags.sql feat(contacts): add filter_contacts_by_tags RPC migration 2026-06-22 15:50:40 +03:00
026_api_keys.sql feat(api): public API groundwork — scoped API keys + /api/v1/me 2026-06-23 15:35:43 +03:00