feat: per-category email prefs, admin ops webhooks, per-user feature toggles (v0.61.0)
- Notification email preferences: every push category (follow, comment, reply, reaction, rating, mention, leftoverExpiring, shoppingList) now has an independent email toggle, plus a Weekly Digest toggle. Previously email sent unconditionally whenever the recipient had one; now gated the same way push already was. The weekly-digest cron route excludes opted-out users. - Admin-only site-wide webhooks (Admin → Webhooks): new signups, support tickets, and reports filed can now fire an HMAC-signed HTTP webhook (Slack/Discord/ops alerting), independent of the existing per-user webhooks (which stay scoped to a user's own recipe/meal-plan/shopping-list events). Signing/delivery logic factored into lib/webhook-delivery.ts and shared by both dispatchers instead of duplicated. - Settings → Features: users can hide Nutrition, Pantry, Meal Plan, Shopping Lists, Collections, or Messages from their own nav. Purely cosmetic — hidden pages stay reachable by direct link, nothing is access-restricted. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
ALTER TABLE "user_notification_prefs" ADD COLUMN "follow_email" boolean DEFAULT true NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "user_notification_prefs" ADD COLUMN "comment_email" boolean DEFAULT true NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "user_notification_prefs" ADD COLUMN "reply_email" boolean DEFAULT true NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "user_notification_prefs" ADD COLUMN "reaction_email" boolean DEFAULT true NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "user_notification_prefs" ADD COLUMN "rating_email" boolean DEFAULT true NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "user_notification_prefs" ADD COLUMN "mention_email" boolean DEFAULT true NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "user_notification_prefs" ADD COLUMN "leftover_expiring_email" boolean DEFAULT true NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "user_notification_prefs" ADD COLUMN "shopping_list_email" boolean DEFAULT true NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "user_notification_prefs" ADD COLUMN "weekly_digest_email" boolean DEFAULT true NOT NULL;
|
||||
@@ -0,0 +1,23 @@
|
||||
CREATE TABLE "admin_webhook_deliveries" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"webhook_id" text NOT NULL,
|
||||
"event" text NOT NULL,
|
||||
"payload" jsonb,
|
||||
"status_code" integer,
|
||||
"success" boolean DEFAULT false NOT NULL,
|
||||
"attempts" integer DEFAULT 0 NOT NULL,
|
||||
"created_at" timestamp DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "admin_webhooks" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"created_by_id" text,
|
||||
"url" text NOT NULL,
|
||||
"events" text[] DEFAULT '{}' NOT NULL,
|
||||
"secret" text NOT NULL,
|
||||
"active" boolean DEFAULT true NOT NULL,
|
||||
"created_at" timestamp DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "admin_webhook_deliveries" ADD CONSTRAINT "admin_webhook_deliveries_webhook_id_admin_webhooks_id_fk" FOREIGN KEY ("webhook_id") REFERENCES "public"."admin_webhooks"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "admin_webhooks" ADD CONSTRAINT "admin_webhooks_created_by_id_users_id_fk" FOREIGN KEY ("created_by_id") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;
|
||||
@@ -0,0 +1,14 @@
|
||||
CREATE TABLE "user_feature_prefs" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"user_id" text NOT NULL,
|
||||
"nutrition" boolean DEFAULT true NOT NULL,
|
||||
"pantry" boolean DEFAULT true NOT NULL,
|
||||
"meal_plan" boolean DEFAULT true NOT NULL,
|
||||
"shopping_lists" boolean DEFAULT true NOT NULL,
|
||||
"collections" boolean DEFAULT true NOT NULL,
|
||||
"messages" boolean DEFAULT true NOT NULL,
|
||||
"updated_at" timestamp DEFAULT now() NOT NULL,
|
||||
CONSTRAINT "user_feature_prefs_user_id_unique" UNIQUE("user_id")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "user_feature_prefs" ADD CONSTRAINT "user_feature_prefs_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -379,6 +379,27 @@
|
||||
"when": 1784571695517,
|
||||
"tag": "0053_square_morgan_stark",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 54,
|
||||
"version": "7",
|
||||
"when": 1784580458975,
|
||||
"tag": "0054_whole_rictor",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 55,
|
||||
"version": "7",
|
||||
"when": 1784580710902,
|
||||
"tag": "0055_zippy_shocker",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 56,
|
||||
"version": "7",
|
||||
"when": 1784581139361,
|
||||
"tag": "0056_shallow_brother_voodoo",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -174,6 +174,17 @@ export const userNotificationPrefs = pgTable("user_notification_prefs", {
|
||||
mention: boolean("mention").notNull().default(true),
|
||||
leftoverExpiring: boolean("leftover_expiring").notNull().default(true),
|
||||
shoppingList: boolean("shopping_list").notNull().default(true),
|
||||
// Email variants of the same categories — independent from the push
|
||||
// toggles above, so a user can get push but not email (or vice versa).
|
||||
followEmail: boolean("follow_email").notNull().default(true),
|
||||
commentEmail: boolean("comment_email").notNull().default(true),
|
||||
replyEmail: boolean("reply_email").notNull().default(true),
|
||||
reactionEmail: boolean("reaction_email").notNull().default(true),
|
||||
ratingEmail: boolean("rating_email").notNull().default(true),
|
||||
mentionEmail: boolean("mention_email").notNull().default(true),
|
||||
leftoverExpiringEmail: boolean("leftover_expiring_email").notNull().default(true),
|
||||
shoppingListEmail: boolean("shopping_list_email").notNull().default(true),
|
||||
weeklyDigestEmail: boolean("weekly_digest_email").notNull().default(true),
|
||||
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
||||
});
|
||||
|
||||
@@ -185,6 +196,25 @@ export const userNotificationPrefsRelations = relations(userNotificationPrefs, (
|
||||
user: one(users, { fields: [userNotificationPrefs.userId], references: [users.id] }),
|
||||
}));
|
||||
|
||||
// Lets a user hide optional features from their own nav — purely cosmetic
|
||||
// declutter, not an access restriction: the underlying pages/routes stay
|
||||
// reachable by direct URL even when hidden here.
|
||||
export const userFeaturePrefs = pgTable("user_feature_prefs", {
|
||||
id: text("id").primaryKey(),
|
||||
userId: text("user_id").notNull().references(() => users.id, { onDelete: "cascade" }).unique(),
|
||||
nutrition: boolean("nutrition").notNull().default(true),
|
||||
pantry: boolean("pantry").notNull().default(true),
|
||||
mealPlan: boolean("meal_plan").notNull().default(true),
|
||||
shoppingLists: boolean("shopping_lists").notNull().default(true),
|
||||
collections: boolean("collections").notNull().default(true),
|
||||
messages: boolean("messages").notNull().default(true),
|
||||
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
||||
});
|
||||
|
||||
export const userFeaturePrefsRelations = relations(userFeaturePrefs, ({ one }) => ({
|
||||
user: one(users, { fields: [userFeaturePrefs.userId], references: [users.id] }),
|
||||
}));
|
||||
|
||||
export const userNutritionGoalsRelations = relations(userNutritionGoals, ({ one }) => ({
|
||||
user: one(users, { fields: [userNutritionGoals.userId], references: [users.id] }),
|
||||
}));
|
||||
|
||||
@@ -31,3 +31,36 @@ export const webhooksRelations = relations(webhooks, ({ one, many }) => ({
|
||||
export const webhookDeliveriesRelations = relations(webhookDeliveries, ({ one }) => ({
|
||||
webhook: one(webhooks, { fields: [webhookDeliveries.webhookId], references: [webhooks.id] }),
|
||||
}));
|
||||
|
||||
// Site-wide ops webhooks (new signup, support ticket, report filed) — unlike
|
||||
// `webhooks` above, these aren't owned by a single user; any admin can manage
|
||||
// them and every active one fires regardless of who created it.
|
||||
export const adminWebhooks = pgTable("admin_webhooks", {
|
||||
id: text("id").primaryKey(),
|
||||
createdById: text("created_by_id").references(() => users.id, { onDelete: "set null" }),
|
||||
url: text("url").notNull(),
|
||||
events: text("events").array().notNull().default([]),
|
||||
secret: text("secret").notNull(),
|
||||
active: boolean("active").notNull().default(true),
|
||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||
});
|
||||
|
||||
export const adminWebhookDeliveries = pgTable("admin_webhook_deliveries", {
|
||||
id: text("id").primaryKey(),
|
||||
webhookId: text("webhook_id").notNull().references(() => adminWebhooks.id, { onDelete: "cascade" }),
|
||||
event: text("event").notNull(),
|
||||
payload: jsonb("payload"),
|
||||
statusCode: integer("status_code"),
|
||||
success: boolean("success").notNull().default(false),
|
||||
attempts: integer("attempts").notNull().default(0),
|
||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||
});
|
||||
|
||||
export const adminWebhooksRelations = relations(adminWebhooks, ({ one, many }) => ({
|
||||
createdBy: one(users, { fields: [adminWebhooks.createdById], references: [users.id] }),
|
||||
deliveries: many(adminWebhookDeliveries),
|
||||
}));
|
||||
|
||||
export const adminWebhookDeliveriesRelations = relations(adminWebhookDeliveries, ({ one }) => ({
|
||||
webhook: one(adminWebhooks, { fields: [adminWebhookDeliveries.webhookId], references: [adminWebhooks.id] }),
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user