Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat: validate content type in action function and enhance notification SQL documentation

naveenkashd673aedca17a
diff --git a/apps/erp/app/root.tsx b/apps/erp/app/root.tsx
index 2a35432738..22791e6402 100644
--- a/apps/erp/app/root.tsx
+++ b/apps/erp/app/root.tsx
@@ -130,6 +130,14 @@ export async function loader({ request, context }: LoaderFunctionArgs) {
}
export async function action({ request }: ActionFunctionArgs) {
+ const contentType = request.headers.get("content-type") ?? "";
+ if (
+ !contentType.includes("multipart/form-data") &&
+ !contentType.includes("application/x-www-form-urlencoded")
+ ) {
+ return data({ error: "Invalid content type" }, { status: 400 });
+ }
+
const validation = await validator(modeValidator).validate(
await request.formData()
);
diff --git a/packages/database/supabase/migrations/20260508120000_notifications.sql b/packages/database/supabase/migrations/20260508120000_notifications.sql
index 445845e516..1467ec2963 100644
--- a/packages/database/supabase/migrations/20260508120000_notifications.sql
+++ b/packages/database/supabase/migrations/20260508120000_notifications.sql
@@ -1,6 +1,13 @@
-- In-app notification store. Replaces Novu cloud storage so we own the data
-- and can stream changes to clients via Supabase Realtime instead of Novu's
-- WebSocket service.
+--
+-- Grouping model: notifications can be flat or grouped under a "digest" row.
+-- A digest is itself a notification row (event = "digest"); its children point
+-- to it via "digestedInto". The user-facing list renders only top-level rows
+-- (digestedInto IS NULL) — digests render as expandable groups, everything
+-- else renders as a single leaf. See the partial index below, which mirrors
+-- this filter so unread/digest queries stay cheap.
CREATE TABLE "notification" (
"id" TEXT NOT NULL PRIMARY KEY DEFAULT xid(),
diff --git a/packages/jobs/src/inngest/functions/scheduled/notification-digest.ts b/packages/jobs/src/inngest/functions/scheduled/notification-digest.ts
index 55d018c24e..bf48b61f22 100644
--- a/packages/jobs/src/inngest/functions/scheduled/notification-digest.ts
+++ b/packages/jobs/src/inngest/functions/scheduled/notification-digest.ts
@@ -50,7 +50,8 @@ export const notificationDigestFunction = inngest.createFunction(
{ data: candidateRows, error: candidateErr },
{ data: digestRows, error: digestErr }
] = await Promise.all([
- (client.from as any)("notification")
+ client
+ .from("notification")
.select("id, userId, companyId, topic, createdAt")
.is("readAt", null)
.is("digestedInto", null)
@@ -58,7 +59,8 @@ export const notificationDigestFunction = inngest.createFunction(
.lt("createdAt", cutoff)
.order("createdAt", { ascending: true })
.limit(DIGEST_MAX_CANDIDATES),
- (client.from as any)("notification")
+ client
+ .from("notification")
.select("id, userId, companyId, topic, createdAt")
.is("readAt", null)
.is("digestedInto", null)
@@ -133,9 +135,8 @@ export const notificationDigestFunction = inngest.createFunction(
newChildren.length
);
- const { data: createdRow, error: insertError } = await (
- client.from as any
- )("notification")
+ const { data: createdRow, error: insertError } = await client
+ .from("notification")
.insert({
companyId: head.companyId,
event: NotificationEvent.Digest,
@@ -157,9 +158,8 @@ export const notificationDigestFunction = inngest.createFunction(
continue;
}
- const { error: updateError } = await (client.from as any)(
- "notification"
- )
+ const { error: updateError } = await client
+ .from("notification")
.update({ digestedInto: createdRow.id })
.in(
"id",
@@ -183,9 +183,8 @@ export const notificationDigestFunction = inngest.createFunction(
const others = existingDigests.slice(1);
if (others.length > 0) {
- const { error: repointErr } = await (client.from as any)(
- "notification"
- )
+ const { error: repointErr } = await client
+ .from("notification")
.update({ digestedInto: keeper.id })
.in(
"digestedInto",
@@ -199,9 +198,8 @@ export const notificationDigestFunction = inngest.createFunction(
continue;
}
- const { error: deleteErr } = await (client.from as any)(
- "notification"
- )
+ const { error: deleteErr } = await client
+ .from("notification")
.delete()
.in(
"id",
@@ -215,9 +213,8 @@ export const notificationDigestFunction = inngest.createFunction(
}
if (newChildren.length > 0) {
- const { error: absorbErr } = await (client.from as any)(
- "notification"
- )
+ const { error: absorbErr } = await client
+ .from("notification")
.update({ digestedInto: keeper.id })
.in(
"id",
@@ -231,9 +228,8 @@ export const notificationDigestFunction = inngest.createFunction(
}
// Refresh title/count from the authoritative child count.
- const { count: childCount, error: countErr } = await (
- client.from as any
- )("notification")
+ const { count: childCount, error: countErr } = await client
+ .from("notification")
.select("id", { count: "exact", head: true })
.eq("digestedInto", keeper.id);
@@ -244,7 +240,8 @@ export const notificationDigestFunction = inngest.createFunction(
const total = childCount ?? 0;
const description = getNotificationTopicPhrase(keeper.topic, total);
- const { error: titleErr } = await (client.from as any)("notification")
+ const { error: titleErr } = await client
+ .from("notification")
.update({
payload: {
count: total,