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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
fix(production): refuse a malformed bulk release body
naveenkashb93f3e13d210
diff --git a/apps/erp/app/routes/x+/job+/release.test.ts b/apps/erp/app/routes/x+/job+/release.test.tsindex b7812936b2..6338a1791e 100644--- a/apps/erp/app/routes/x+/job+/release.test.ts+++ b/apps/erp/app/routes/x+/job+/release.test.ts@@ -333,6 +333,30 @@ describe("bulk job release", () => {expect(released.slice(0, 3)).toEqual(["j0", "j1", "j2"]);});+ it("refuses a body that is not the table's shape", async () => {+ setup([]);+ const malformed = (body: string) =>+ action({+ request: new Request("http://localhost/x/job/release", {+ method: "POST",+ body,+ headers: { "Content-Type": "application/json" }+ }),+ params: {},+ context: {}+ } as any);++ expect(await malformed("not json")).toEqual({+ success: false,+ message: "Invalid request"+ });+ expect(await malformed(JSON.stringify({ jobIds: "j1" }))).toEqual({+ success: false,+ message: "Invalid request"+ });+ expect(releaseJobs).not.toHaveBeenCalled();+ });+it("refuses an empty selection", async () => {setup([]);expect(await run([])).toEqual({diff --git a/apps/erp/app/routes/x+/job+/release.tsx b/apps/erp/app/routes/x+/job+/release.tsxindex 1ad8300db3..4268b601cc 100644--- a/apps/erp/app/routes/x+/job+/release.tsx+++ b/apps/erp/app/routes/x+/job+/release.tsx@@ -9,6 +9,7 @@ import { getLogger } from "@carbon/logger";import { runLocationSchedule } from "@carbon/planning";import { chunkArray } from "@carbon/utils";import type { ActionFunctionArgs } from "react-router";+import { z } from "zod";import { getJobReleaseReadiness } from "~/modules/production";import { releaseJobs } from "~/modules/production/production.server";import { jobReleaseProblems } from "~/modules/production/ui/Jobs/job-release-logic";@@ -16,6 +17,8 @@ import { getDatabaseClient } from "~/services/database.server";const logger = getLogger("erp", "job-release");+const bodySchema = z.object({ jobIds: z.array(z.string()) });+// Bulk release — the jobs table's "Release Jobs" action. Each selected Draft /// Planned job goes through the job page's release path (releaseJobs) on its// own: a job that is not ready is reported in `failed` while the rest still@@ -29,8 +32,13 @@ export async function action({ request }: ActionFunctionArgs) {update: "production"});- const { jobIds } = (await request.json()) as { jobIds?: string[] };- const ids = [...new Set((jobIds ?? []).filter(Boolean))];+ // A body that is not JSON, or not the shape the table sends, is a plain+ // refusal rather than a 500.+ const body = bodySchema.safeParse(await request.json().catch(() => null));+ if (!body.success) {+ return { success: false as const, message: "Invalid request" };+ }+ const ids = [...new Set(body.data.jobIds.filter(Boolean))];if (ids.length === 0) {return { success: false as const, message: "No jobs selected" };}diff --git a/apps/erp/app/routes/x+/production+/batches.release.tsx b/apps/erp/app/routes/x+/production+/batches.release.tsxindex 1849777508..467c09548f 100644--- a/apps/erp/app/routes/x+/production+/batches.release.tsx+++ b/apps/erp/app/routes/x+/production+/batches.release.tsx@@ -6,6 +6,7 @@ import { assertIsPost } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { getErrorMessage } from "@carbon/utils";import type { ActionFunctionArgs } from "react-router";+import { z } from "zod";import {notifyScheduleInputsChanged,releaseJobOperationBatch@@ -19,14 +20,21 @@ import { getDatabaseClient } from "~/services/database.server";// released — the caller filters, and any non-Planned id is refused here too so a// stale selection can't flip an Active/Completing batch. Fetcher-driven; the// table toasts the summary and the loader revalidates.+const bodySchema = z.object({ batchIds: z.array(z.string()) });+export async function action({ request }: ActionFunctionArgs) {assertIsPost(request);const { client, companyId, userId } = await requirePermissions(request, {update: "production"});- const { batchIds } = (await request.json()) as { batchIds?: string[] };- const ids = [...new Set((batchIds ?? []).filter(Boolean))];+ // A body that is not JSON, or not the shape the table sends, is a plain+ // refusal rather than a 500.+ const body = bodySchema.safeParse(await request.json().catch(() => null));+ if (!body.success) {+ return { success: false, message: "Invalid request" };+ }+ const ids = [...new Set(body.data.batchIds.filter(Boolean))];if (ids.length === 0) {return { success: false, message: "No batches selected" };}