B2: profile + notification_preferences + SMS consent capture (TCPA)

- notification_preferences table (user_id PK->users, email/sms toggles,
  sms_consent_at/source/ip evidence, quiet hours, digest) + migration 0002
- src/domain/consent.ts: pure TCPA rule (phoneChanged/buildConsent/resetConsent)
- src/db/profile.ts: updateProfile (partial update; resets consent on phone
  change) + setSmsConsent (opt-in) + getProfile
- PATCH/POST /api/dev/profile routes
- seed: per-user prefs row (email on, SMS off)
- 6 unit tests named after the rules
This commit is contained in:
Tiel Coder
2026-11-18 00:09:05 +00:00
parent 5f0b94af6a
commit 26b31978e2
10 changed files with 1398 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
CREATE TABLE "notification_preferences" (
"user_id" text PRIMARY KEY NOT NULL,
"email_enabled" boolean DEFAULT true NOT NULL,
"sms_enabled" boolean DEFAULT false NOT NULL,
"sms_consent_at" timestamp with time zone,
"sms_consent_source" text,
"sms_consent_ip" text,
"reminder_lead_days" integer DEFAULT 7 NOT NULL,
"quiet_hours_start" text DEFAULT '21:00' NOT NULL,
"quiet_hours_end" text DEFAULT '08:00' NOT NULL,
"digest_only" boolean DEFAULT false NOT NULL
);
--> statement-breakpoint
ALTER TABLE "notification_preferences" ADD CONSTRAINT "notification_preferences_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;