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:
@@ -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