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
perf(erp): raise stream timeout + parallelize approval loaders (#687)
Sid22ed016a1c0c
diff --git a/apps/erp/app/entry.server.tsx b/apps/erp/app/entry.server.tsxindex d9e6605dfe..048b27f94c 100644--- a/apps/erp/app/entry.server.tsx+++ b/apps/erp/app/entry.server.tsx@@ -1,7 +1,7 @@import { handleRequest as vercelHandleRequest } from "@vercel/react-router/entry.server";import type { EntryContext, RouterContextProvider } from "react-router";-export const streamTimeout = 5_000;+export const streamTimeout = 35_000;export default function handleRequest(request: Request,diff --git a/apps/erp/app/routes/x+/account+/profile.tsx b/apps/erp/app/routes/x+/account+/profile.tsxindex a907a8f5e9..0ab3a191df 100644--- a/apps/erp/app/routes/x+/account+/profile.tsx+++ b/apps/erp/app/routes/x+/account+/profile.tsx@@ -39,7 +39,7 @@ export const handle: Handle = {export async function loader({ request }: LoaderFunctionArgs) {const { client, userId } = await requirePermissions(request, {});- const [user] = await Promise.all([getAccount(client, userId)]);+ const user = await getAccount(client, userId);if (user.error || !user.data) {throw redirect(diff --git a/apps/erp/app/routes/x+/accounting+/categories.tsx b/apps/erp/app/routes/x+/accounting+/categories.tsxindex deb35b17fc..967bb4314c 100644--- a/apps/erp/app/routes/x+/accounting+/categories.tsx+++ b/apps/erp/app/routes/x+/accounting+/categories.tsx@@ -28,16 +28,14 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const [categories] = await Promise.all([- getAccountCategories(client, companyId, {- search,+ const categories = await getAccountCategories(client, companyId, {+ search,- limit,- offset,- sorts,- filters- })- ]);+ limit,+ offset,+ sorts,+ filters+ });if (categories.error) {redirect(diff --git a/apps/erp/app/routes/x+/accounting+/defaults.tsx b/apps/erp/app/routes/x+/accounting+/defaults.tsxindex f6474c19ff..f3867d5942 100644--- a/apps/erp/app/routes/x+/accounting+/defaults.tsx+++ b/apps/erp/app/routes/x+/accounting+/defaults.tsx@@ -30,9 +30,7 @@ export async function loader({ request }: LoaderFunctionArgs) {view: "accounting"});- const [defaultAccounts] = await Promise.all([- getDefaultAccounts(client, companyId)- ]);+ const defaultAccounts = await getDefaultAccounts(client, companyId);if (defaultAccounts.error || !defaultAccounts.data) {throw redirect(diff --git a/apps/erp/app/routes/x+/consumable+/$itemId.purchasing.tsx b/apps/erp/app/routes/x+/consumable+/$itemId.purchasing.tsxindex c22f253134..7e5cb6084c 100644--- a/apps/erp/app/routes/x+/consumable+/$itemId.purchasing.tsx+++ b/apps/erp/app/routes/x+/consumable+/$itemId.purchasing.tsx@@ -26,9 +26,11 @@ export async function loader({ request, params }: LoaderFunctionArgs) {const { itemId } = params;if (!itemId) throw new Error("Could not find itemId");- const [consumablePurchasingResult] = await Promise.all([- getItemReplenishment(client, itemId, companyId)- ]);+ const consumablePurchasingResult = await getItemReplenishment(+ client,+ itemId,+ companyId+ );if (consumablePurchasingResult.error) {throw redirect(diff --git a/apps/erp/app/routes/x+/inventory+/receipts.tsx b/apps/erp/app/routes/x+/inventory+/receipts.tsxindex 024e109839..a6f2a5d255 100644--- a/apps/erp/app/routes/x+/inventory+/receipts.tsx+++ b/apps/erp/app/routes/x+/inventory+/receipts.tsx@@ -26,15 +26,13 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const [receipts] = await Promise.all([- getReceipts(client, companyId, {- search,- limit,- offset,- sorts,- filters- })- ]);+ const receipts = await getReceipts(client, companyId, {+ search,+ limit,+ offset,+ sorts,+ filters+ });if (receipts.error) {throw redirect(diff --git a/apps/erp/app/routes/x+/inventory+/shipments.tsx b/apps/erp/app/routes/x+/inventory+/shipments.tsxindex a68899f5bf..f431b02ebe 100644--- a/apps/erp/app/routes/x+/inventory+/shipments.tsx+++ b/apps/erp/app/routes/x+/inventory+/shipments.tsx@@ -27,15 +27,13 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const [shipments] = await Promise.all([- getShipments(client, companyId, {- search,- limit,- offset,- sorts,- filters- })- ]);+ const shipments = await getShipments(client, companyId, {+ search,+ limit,+ offset,+ sorts,+ filters+ });if (shipments.error) {throw redirect(diff --git a/apps/erp/app/routes/x+/inventory+/stock-transfers.tsx b/apps/erp/app/routes/x+/inventory+/stock-transfers.tsxindex 84d4a8e8ab..712e00eec5 100644--- a/apps/erp/app/routes/x+/inventory+/stock-transfers.tsx+++ b/apps/erp/app/routes/x+/inventory+/stock-transfers.tsx@@ -60,16 +60,14 @@ export async function loader({ request }: LoaderFunctionArgs) {locationId = locations.data?.[0].id as string;}- const [stockTransfers] = await Promise.all([- getStockTransfers(client, companyId, {- locationId,- search,- limit,- offset,- sorts,- filters- })- ]);+ const stockTransfers = await getStockTransfers(client, companyId, {+ locationId,+ search,+ limit,+ offset,+ sorts,+ filters+ });if (stockTransfers.error) {console.error(stockTransfers.error);diff --git a/apps/erp/app/routes/x+/inventory+/tracked-entities.tsx b/apps/erp/app/routes/x+/inventory+/tracked-entities.tsxindex 972ac4106e..fbf877cad9 100644--- a/apps/erp/app/routes/x+/inventory+/tracked-entities.tsx+++ b/apps/erp/app/routes/x+/inventory+/tracked-entities.tsx@@ -28,15 +28,13 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const [trackedEntities] = await Promise.all([- getTrackedEntities(client, companyId, {- search,- limit,- offset,- sorts,- filters- })- ]);+ const trackedEntities = await getTrackedEntities(client, companyId, {+ search,+ limit,+ offset,+ sorts,+ filters+ });if (trackedEntities.error) {throw redirect(diff --git a/apps/erp/app/routes/x+/inventory+/warehouse-transfers.tsx b/apps/erp/app/routes/x+/inventory+/warehouse-transfers.tsxindex 6b2b0c0fa6..34660b3e45 100644--- a/apps/erp/app/routes/x+/inventory+/warehouse-transfers.tsx+++ b/apps/erp/app/routes/x+/inventory+/warehouse-transfers.tsx@@ -27,15 +27,13 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const [warehouseTransfers] = await Promise.all([- getWarehouseTransfers(client, companyId, {- search,- limit,- offset,- sorts,- filters- })- ]);+ const warehouseTransfers = await getWarehouseTransfers(client, companyId, {+ search,+ limit,+ offset,+ sorts,+ filters+ });if (warehouseTransfers.error) {throw redirect(diff --git a/apps/erp/app/routes/x+/issue+/$id.status.tsx b/apps/erp/app/routes/x+/issue+/$id.status.tsxindex 7d24eecd40..ad7a71fd0d 100644--- a/apps/erp/app/routes/x+/issue+/$id.status.tsx+++ b/apps/erp/app/routes/x+/issue+/$id.status.tsx@@ -29,15 +29,13 @@ export async function action({ request, params }: ActionFunctionArgs) {);}- const [update] = await Promise.all([- updateIssueStatus(client, {- id,- status,- assignee: ["Closed"].includes(status) ? null : undefined,- closeDate: ["Closed"].includes(status) ? new Date().toISOString() : null,- updatedBy: userId- })- ]);+ const update = await updateIssueStatus(client, {+ id,+ status,+ assignee: ["Closed"].includes(status) ? null : undefined,+ closeDate: ["Closed"].includes(status) ? new Date().toISOString() : null,+ updatedBy: userId+ });if (update.error) {throw redirect(requestReferrer(request) ?? path.to.issueDetails(id),diff --git a/apps/erp/app/routes/x+/items+/dimensions.tsx b/apps/erp/app/routes/x+/items+/dimensions.tsxindex 55f463fb5b..173373fee5 100644--- a/apps/erp/app/routes/x+/items+/dimensions.tsx+++ b/apps/erp/app/routes/x+/items+/dimensions.tsx@@ -31,16 +31,14 @@ export async function loader({ request }: LoaderFunctionArgs) {const settings = await getCompanySettings(client, companyId);- const [materialDimensions] = await Promise.all([- getMaterialDimensions(client, companyId, {- limit,- offset,- sorts,- search,- filters,- isMetric: settings?.data?.useMetric ?? false- })- ]);+ const materialDimensions = await getMaterialDimensions(client, companyId, {+ limit,+ offset,+ sorts,+ search,+ filters,+ isMetric: settings?.data?.useMetric ?? false+ });if (materialDimensions.error) {console.error(materialDimensions.error);diff --git a/apps/erp/app/routes/x+/items+/finishes.tsx b/apps/erp/app/routes/x+/items+/finishes.tsxindex 689cbbb6b0..fdd8314442 100644--- a/apps/erp/app/routes/x+/items+/finishes.tsx+++ b/apps/erp/app/routes/x+/items+/finishes.tsx@@ -28,15 +28,13 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const [materialFinishes] = await Promise.all([- getMaterialFinishes(client, companyId, {- limit,- offset,- sorts,- search,- filters- })- ]);+ const materialFinishes = await getMaterialFinishes(client, companyId, {+ limit,+ offset,+ sorts,+ search,+ filters+ });if (materialFinishes.error) {console.error(materialFinishes.error);diff --git a/apps/erp/app/routes/x+/items+/forms.tsx b/apps/erp/app/routes/x+/items+/forms.tsxindex 5971ab3b0f..d2695f3d39 100644--- a/apps/erp/app/routes/x+/items+/forms.tsx+++ b/apps/erp/app/routes/x+/items+/forms.tsx@@ -28,15 +28,13 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const [materialForms] = await Promise.all([- getMaterialForms(client, companyId, {- limit,- offset,- sorts,- search,- filters- })- ]);+ const materialForms = await getMaterialForms(client, companyId, {+ limit,+ offset,+ sorts,+ search,+ filters+ });if (materialForms.error) {throw redirect(diff --git a/apps/erp/app/routes/x+/items+/grades.tsx b/apps/erp/app/routes/x+/items+/grades.tsxindex 7aabc247cc..401cf4cbd2 100644--- a/apps/erp/app/routes/x+/items+/grades.tsx+++ b/apps/erp/app/routes/x+/items+/grades.tsx@@ -28,15 +28,13 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const [materialGrades] = await Promise.all([- getMaterialGrades(client, companyId, {- limit,- offset,- sorts,- search,- filters- })- ]);+ const materialGrades = await getMaterialGrades(client, companyId, {+ limit,+ offset,+ sorts,+ search,+ filters+ });if (materialGrades.error) {console.error(materialGrades.error);diff --git a/apps/erp/app/routes/x+/items+/substances.tsx b/apps/erp/app/routes/x+/items+/substances.tsxindex 64edffc992..7282570fb7 100644--- a/apps/erp/app/routes/x+/items+/substances.tsx+++ b/apps/erp/app/routes/x+/items+/substances.tsx@@ -28,15 +28,13 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const [materialSubstances] = await Promise.all([- getMaterialSubstances(client, companyId, {- limit,- offset,- sorts,- search,- filters- })- ]);+ const materialSubstances = await getMaterialSubstances(client, companyId, {+ limit,+ offset,+ sorts,+ search,+ filters+ });if (materialSubstances.error) {throw redirect(diff --git a/apps/erp/app/routes/x+/items+/types.tsx b/apps/erp/app/routes/x+/items+/types.tsxindex 60ff73367a..2f0616e660 100644--- a/apps/erp/app/routes/x+/items+/types.tsx+++ b/apps/erp/app/routes/x+/items+/types.tsx@@ -28,15 +28,13 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const [materialTypes] = await Promise.all([- getMaterialTypes(client, companyId, {- limit,- offset,- sorts,- search,- filters- })- ]);+ const materialTypes = await getMaterialTypes(client, companyId, {+ limit,+ offset,+ sorts,+ search,+ filters+ });if (materialTypes.error) {console.error(materialTypes.error);diff --git a/apps/erp/app/routes/x+/job+/$jobId.events.new.tsx b/apps/erp/app/routes/x+/job+/$jobId.events.new.tsxindex d26b340c0d..cf61f07721 100644--- a/apps/erp/app/routes/x+/job+/$jobId.events.new.tsx+++ b/apps/erp/app/routes/x+/job+/$jobId.events.new.tsx@@ -23,7 +23,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {const { jobId } = params;if (!jobId) throw notFound("jobId not found");- const [jobOperations] = await Promise.all([getJobOperations(client, jobId)]);+ const jobOperations = await getJobOperations(client, jobId);const operationOptions =jobOperations.data?.map((operation) => ({diff --git a/apps/erp/app/routes/x+/job+/$jobId.quantities.new.tsx b/apps/erp/app/routes/x+/job+/$jobId.quantities.new.tsxindex 0114e130dd..48f2f75c17 100644--- a/apps/erp/app/routes/x+/job+/$jobId.quantities.new.tsx+++ b/apps/erp/app/routes/x+/job+/$jobId.quantities.new.tsx@@ -23,7 +23,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {const { jobId } = params;if (!jobId) throw notFound("jobId not found");- const [jobOperations] = await Promise.all([getJobOperations(client, jobId)]);+ const jobOperations = await getJobOperations(client, jobId);const operationOptions =jobOperations.data?.map((operation) => ({diff --git a/apps/erp/app/routes/x+/production+/planning.tsx b/apps/erp/app/routes/x+/production+/planning.tsxindex 4d8a86f400..fb878a8a41 100644--- a/apps/erp/app/routes/x+/production+/planning.tsx+++ b/apps/erp/app/routes/x+/production+/planning.tsx@@ -72,21 +72,19 @@ export async function loader({ request }: LoaderFunctionArgs) {WEEKS_TO_PLAN);- const [items] = await Promise.all([- getProductionPlanning(- client,- locationId,- companyId,- periods.map((p) => p.id),- {- search,- limit,- offset,- sorts,- filters- }- )- ]);+ const items = await getProductionPlanning(+ client,+ locationId,+ companyId,+ periods.map((p) => p.id),+ {+ search,+ limit,+ offset,+ sorts,+ filters+ }+ );if (items.error) {redirect(diff --git a/apps/erp/app/routes/x+/purchase-invoice+/$invoiceId.status.tsx b/apps/erp/app/routes/x+/purchase-invoice+/$invoiceId.status.tsxindex c7ef3654d0..6a07098821 100644--- a/apps/erp/app/routes/x+/purchase-invoice+/$invoiceId.status.tsx+++ b/apps/erp/app/routes/x+/purchase-invoice+/$invoiceId.status.tsx@@ -56,14 +56,12 @@ export async function action({ request, params }: ActionFunctionArgs) {);}- const [update] = await Promise.all([- updatePurchaseInvoiceStatus(client, {- id,- status,- assignee: !["Partially Paid"].includes(status) ? null : undefined,- updatedBy: userId- })- ]);+ const update = await updatePurchaseInvoiceStatus(client, {+ id,+ status,+ assignee: !["Partially Paid"].includes(status) ? null : undefined,+ updatedBy: userId+ });if (update.error) {throw redirect(requestReferrer(request) ?? path.to.purchaseInvoiceDetails(id),diff --git a/apps/erp/app/routes/x+/purchasing+/invoices.tsx b/apps/erp/app/routes/x+/purchasing+/invoices.tsxindex 6adf71b463..08acbb0432 100644--- a/apps/erp/app/routes/x+/purchasing+/invoices.tsx+++ b/apps/erp/app/routes/x+/purchasing+/invoices.tsx@@ -31,16 +31,14 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const [purchaseInvoices] = await Promise.all([- getPurchaseInvoices(client, companyId, {- search,- supplierId,- limit,- offset,- sorts,- filters- })- ]);+ const purchaseInvoices = await getPurchaseInvoices(client, companyId, {+ search,+ supplierId,+ limit,+ offset,+ sorts,+ filters+ });if (purchaseInvoices.error) {redirect(diff --git a/apps/erp/app/routes/x+/purchasing+/orders.tsx b/apps/erp/app/routes/x+/purchasing+/orders.tsxindex 2cff45637a..1a7876f359 100644--- a/apps/erp/app/routes/x+/purchasing+/orders.tsx+++ b/apps/erp/app/routes/x+/purchasing+/orders.tsx@@ -31,17 +31,15 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const [purchasOrders] = await Promise.all([- getPurchaseOrders(client, companyId, {- search,- status,- supplierId,- limit,- offset,- sorts,- filters- })- ]);+ const purchasOrders = await getPurchaseOrders(client, companyId, {+ search,+ status,+ supplierId,+ limit,+ offset,+ sorts,+ filters+ });if (purchasOrders.error) {redirect(diff --git a/apps/erp/app/routes/x+/purchasing+/planning.tsx b/apps/erp/app/routes/x+/purchasing+/planning.tsxindex 427f79017f..5228078858 100644--- a/apps/erp/app/routes/x+/purchasing+/planning.tsx+++ b/apps/erp/app/routes/x+/purchasing+/planning.tsx@@ -72,21 +72,19 @@ export async function loader({ request }: LoaderFunctionArgs) {WEEKS_TO_PLAN);- const [items] = await Promise.all([- getPurchasingPlanning(- client,- locationId,- companyId,- periods.map((p) => p.id),- {- search,- limit,- offset,- sorts,- filters- }- )- ]);+ const items = await getPurchasingPlanning(+ client,+ locationId,+ companyId,+ periods.map((p) => p.id),+ {+ search,+ limit,+ offset,+ sorts,+ filters+ }+ );if (items.error) {redirect(diff --git a/apps/erp/app/routes/x+/purchasing+/quotes.tsx b/apps/erp/app/routes/x+/purchasing+/quotes.tsxindex 6245991caa..a97129499f 100644--- a/apps/erp/app/routes/x+/purchasing+/quotes.tsx+++ b/apps/erp/app/routes/x+/purchasing+/quotes.tsx@@ -29,15 +29,13 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const [quotes] = await Promise.all([- getSupplierQuotes(client, companyId, {- search,- limit,- offset,- sorts,- filters- })- ]);+ const quotes = await getSupplierQuotes(client, companyId, {+ search,+ limit,+ offset,+ sorts,+ filters+ });if (quotes.error) {redirect(diff --git a/apps/erp/app/routes/x+/purchasing+/rfqs.tsx b/apps/erp/app/routes/x+/purchasing+/rfqs.tsxindex 3ae34750f2..79b6f67142 100644--- a/apps/erp/app/routes/x+/purchasing+/rfqs.tsx+++ b/apps/erp/app/routes/x+/purchasing+/rfqs.tsx@@ -29,15 +29,13 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const [rfqs] = await Promise.all([- getPurchasingRFQs(client, companyId, {- search,- limit,- offset,- sorts,- filters- })- ]);+ const rfqs = await getPurchasingRFQs(client, companyId, {+ search,+ limit,+ offset,+ sorts,+ filters+ });if (rfqs.error) {redirect(diff --git a/apps/erp/app/routes/x+/purchasing-rfq+/$rfqId.$lineId.details.tsx b/apps/erp/app/routes/x+/purchasing-rfq+/$rfqId.$lineId.details.tsxindex ef7a30462e..bfad5e4ecb 100644--- a/apps/erp/app/routes/x+/purchasing-rfq+/$rfqId.$lineId.details.tsx+++ b/apps/erp/app/routes/x+/purchasing-rfq+/$rfqId.$lineId.details.tsx@@ -43,9 +43,9 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {if (!rfqId) throw new Error("Could not find rfqId");if (!lineId) throw new Error("Could not find lineId");- const serviceRole = await getCarbonServiceRole();+ const serviceRole = getCarbonServiceRole();- const [line] = await Promise.all([getPurchasingRFQLine(serviceRole, lineId)]);+ const line = await getPurchasingRFQLine(serviceRole, lineId);if (line.error) {throw redirect(diff --git a/apps/erp/app/routes/x+/quality+/gauges.$id.tsx b/apps/erp/app/routes/x+/quality+/gauges.$id.tsxindex 079cd6c8d9..c9d615674d 100644--- a/apps/erp/app/routes/x+/quality+/gauges.$id.tsx+++ b/apps/erp/app/routes/x+/quality+/gauges.$id.tsx@@ -34,7 +34,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {const { id } = params;if (!id) throw new Error("Could not find id");- const [gauge] = await Promise.all([getGauge(serviceRole, id)]);+ const gauge = await getGauge(serviceRole, id);if (gauge.error) {throw redirect(diff --git a/apps/erp/app/routes/x+/quality-document+/$id.tsx b/apps/erp/app/routes/x+/quality-document+/$id.tsxindex baf9869d56..b22599ff93 100644--- a/apps/erp/app/routes/x+/quality-document+/$id.tsx+++ b/apps/erp/app/routes/x+/quality-document+/$id.tsx@@ -216,9 +216,22 @@ export async function loader({ request, params }: LoaderFunctionArgs) {const { id } = params;if (!id) throw new Error("Could not find id");- const [document, tags] = await Promise.all([- getQualityDocument(client, id),- getTagsList(client, companyId, "qualityDocument")+ const serviceRole = getCarbonServiceRole();+ // Kick off approval in parallel — it only needs document.status, so we chain+ // off the document fetch rather than waiting for Promise.all to settle.+ const documentPromise = getQualityDocument(client, id);+ const [document, tags, approval] = await Promise.all([+ documentPromise,+ getTagsList(client, companyId, "qualityDocument"),+ documentPromise.then((d) =>+ getQualityDocumentApprovalContext(+ serviceRole,+ id,+ d.data?.status ?? null,+ companyId,+ userId+ )+ )]);if (document.error) {@@ -228,16 +241,6 @@ export async function loader({ request, params }: LoaderFunctionArgs) {);}- const serviceRole = getCarbonServiceRole();- const status = document.data?.status ?? null;- const approval = await getQualityDocumentApprovalContext(- serviceRole,- id,- status,- companyId,- userId- );-return {document: document.data,versions: getQualityDocumentVersions(client, document.data, companyId),diff --git a/apps/erp/app/routes/x+/quote+/$quoteId.finalize.tsx b/apps/erp/app/routes/x+/quote+/$quoteId.finalize.tsxindex c965944e6d..8e12e606fb 100644--- a/apps/erp/app/routes/x+/quote+/$quoteId.finalize.tsx+++ b/apps/erp/app/routes/x+/quote+/$quoteId.finalize.tsx@@ -40,7 +40,7 @@ export async function action(args: ActionFunctionArgs) {let fileName: string;let documentFilePath: string;- const [quote] = await Promise.all([getQuote(client, quoteId)]);+ const quote = await getQuote(client, quoteId);if (quote.error) {throw redirect(path.to.quote(quoteId),@@ -48,16 +48,14 @@ export async function action(args: ActionFunctionArgs) {);}- const [externalLink] = await Promise.all([- upsertExternalLink(client, {- id: quote.data.externalLinkId ?? undefined, // TODO- documentType: "Quote",- documentId: quoteId,- customerId: quote.data.customerId,- expiresAt: quote.data.expirationDate,- companyId- })- ]);+ const externalLink = await upsertExternalLink(client, {+ id: quote.data.externalLinkId ?? undefined, // TODO+ documentType: "Quote",+ documentId: quoteId,+ customerId: quote.data.customerId,+ expiresAt: quote.data.expirationDate,+ companyId+ });if (externalLink.data && quote.data.externalLinkId !== externalLink.data.id) {await clientdiff --git a/apps/erp/app/routes/x+/sales+/invoices.tsx b/apps/erp/app/routes/x+/sales+/invoices.tsxindex 0bb72f3951..dc83e85e6f 100644--- a/apps/erp/app/routes/x+/sales+/invoices.tsx+++ b/apps/erp/app/routes/x+/sales+/invoices.tsx@@ -29,16 +29,14 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const [salesInvoices] = await Promise.all([- getSalesInvoices(client, companyId, {- search,- customerId,- limit,- offset,- sorts,- filters- })- ]);+ const salesInvoices = await getSalesInvoices(client, companyId, {+ search,+ customerId,+ limit,+ offset,+ sorts,+ filters+ });if (salesInvoices.error) {redirect(diff --git a/apps/erp/app/routes/x+/sales+/orders.tsx b/apps/erp/app/routes/x+/sales+/orders.tsxindex 1353e3a019..6420aae015 100644--- a/apps/erp/app/routes/x+/sales+/orders.tsx+++ b/apps/erp/app/routes/x+/sales+/orders.tsx@@ -31,17 +31,15 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const [salesOrders] = await Promise.all([- getSalesOrders(client, companyId, {- search,- status,- customerId,- limit,- offset,- sorts,- filters- })- ]);+ const salesOrders = await getSalesOrders(client, companyId, {+ search,+ status,+ customerId,+ limit,+ offset,+ sorts,+ filters+ });if (salesOrders.error) {redirect(diff --git a/apps/erp/app/routes/x+/sales+/quotes.tsx b/apps/erp/app/routes/x+/sales+/quotes.tsxindex 3547885803..0438f1992a 100644--- a/apps/erp/app/routes/x+/sales+/quotes.tsx+++ b/apps/erp/app/routes/x+/sales+/quotes.tsx@@ -29,15 +29,13 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const [quotes] = await Promise.all([- getQuotes(client, companyId, {- search,- limit,- offset,- sorts,- filters- })- ]);+ const quotes = await getQuotes(client, companyId, {+ search,+ limit,+ offset,+ sorts,+ filters+ });if (quotes.error) {redirect(diff --git a/apps/erp/app/routes/x+/sales+/rfqs.tsx b/apps/erp/app/routes/x+/sales+/rfqs.tsxindex 66c30a7c3e..c1779358cc 100644--- a/apps/erp/app/routes/x+/sales+/rfqs.tsx+++ b/apps/erp/app/routes/x+/sales+/rfqs.tsx@@ -29,15 +29,13 @@ export async function loader({ request }: LoaderFunctionArgs) {const { limit, offset, sorts, filters } =getGenericQueryFilters(searchParams);- const [rfqs] = await Promise.all([- getSalesRFQs(client, companyId, {- search,- limit,- offset,- sorts,- filters- })- ]);+ const rfqs = await getSalesRFQs(client, companyId, {+ search,+ limit,+ offset,+ sorts,+ filters+ });if (rfqs.error) {redirect(diff --git a/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.post.tsx b/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.post.tsxindex b7c37916cb..5c972112d6 100644--- a/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.post.tsx+++ b/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.post.tsx@@ -100,9 +100,7 @@ export async function action(args: ActionFunctionArgs) {};}- const [salesInvoice] = await Promise.all([- getSalesInvoice(serviceRole, invoiceId)- ]);+ const salesInvoice = await getSalesInvoice(serviceRole, invoiceId);if (salesInvoice.error) {return {success: false,diff --git a/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.status.tsx b/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.status.tsxindex 08533397aa..e03efc1227 100644--- a/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.status.tsx+++ b/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.status.tsx@@ -28,14 +28,12 @@ export async function action({ request, params }: ActionFunctionArgs) {);}- const [update] = await Promise.all([- updateSalesInvoiceStatus(client, {- id,- status,- assignee: !["Partially Paid"].includes(status) ? null : undefined,- updatedBy: userId- })- ]);+ const update = await updateSalesInvoiceStatus(client, {+ id,+ status,+ assignee: !["Partially Paid"].includes(status) ? null : undefined,+ updatedBy: userId+ });if (update.error) {throw redirect(diff --git a/apps/erp/app/routes/x+/sales-order+/$orderId.confirm.tsx b/apps/erp/app/routes/x+/sales-order+/$orderId.confirm.tsxindex d4b1459690..3b7c9845b1 100644--- a/apps/erp/app/routes/x+/sales-order+/$orderId.confirm.tsx+++ b/apps/erp/app/routes/x+/sales-order+/$orderId.confirm.tsx@@ -39,9 +39,7 @@ export async function action(args: ActionFunctionArgs) {const serviceRole = getCarbonServiceRole();- const [salesOrder] = await Promise.all([- getSalesOrder(serviceRole, orderId)- ]);+ const salesOrder = await getSalesOrder(serviceRole, orderId);if (salesOrder.error) {return {success: false,diff --git a/apps/erp/app/routes/x+/sales-order+/$orderId.status.tsx b/apps/erp/app/routes/x+/sales-order+/$orderId.status.tsxindex 7e995122d9..02b06256ec 100644--- a/apps/erp/app/routes/x+/sales-order+/$orderId.status.tsx+++ b/apps/erp/app/routes/x+/sales-order+/$orderId.status.tsx@@ -27,14 +27,12 @@ export async function action({ request, params }: ActionFunctionArgs) {);}- const [update] = await Promise.all([- updateSalesOrderStatus(client, {- id,- status,- assignee: ["Closed"].includes(status) ? null : undefined,- updatedBy: userId- })- ]);+ const update = await updateSalesOrderStatus(client, {+ id,+ status,+ assignee: ["Closed"].includes(status) ? null : undefined,+ updatedBy: userId+ });if (update.error) {throw redirect(requestReferrer(request) ?? path.to.salesOrderDetails(id),diff --git a/apps/erp/app/routes/x+/sales-rfq+/$rfqId.$lineId.details.tsx b/apps/erp/app/routes/x+/sales-rfq+/$rfqId.$lineId.details.tsxindex d3f9e6fc59..836ea741b9 100644--- a/apps/erp/app/routes/x+/sales-rfq+/$rfqId.$lineId.details.tsx+++ b/apps/erp/app/routes/x+/sales-rfq+/$rfqId.$lineId.details.tsx@@ -46,7 +46,7 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {const serviceRole = await getCarbonServiceRole();- const [line] = await Promise.all([getSalesRFQLine(serviceRole, lineId)]);+ const line = await getSalesRFQLine(serviceRole, lineId);if (line.error) {throw redirect(diff --git a/apps/erp/app/routes/x+/sales-rfq+/$rfqId.status.tsx b/apps/erp/app/routes/x+/sales-rfq+/$rfqId.status.tsxindex 9d7f33c728..ca277bf0ec 100644--- a/apps/erp/app/routes/x+/sales-rfq+/$rfqId.status.tsx+++ b/apps/erp/app/routes/x+/sales-rfq+/$rfqId.status.tsx@@ -57,15 +57,13 @@ export async function action({ request, params }: ActionFunctionArgs) {}}- const [update] = await Promise.all([- updateSalesRFQStatus(client, {- id,- status,- noQuoteReasonId,- assignee: status === "Closed" ? null : undefined,- updatedBy: userId- })- ]);+ const update = await updateSalesRFQStatus(client, {+ id,+ status,+ noQuoteReasonId,+ assignee: status === "Closed" ? null : undefined,+ updatedBy: userId+ });if (update.error) {throw redirect(diff --git a/apps/erp/app/routes/x+/settings+/company.new.tsx b/apps/erp/app/routes/x+/settings+/company.new.tsxindex 85e43176d4..f8c3031873 100644--- a/apps/erp/app/routes/x+/settings+/company.new.tsx+++ b/apps/erp/app/routes/x+/settings+/company.new.tsx@@ -51,15 +51,13 @@ export async function action({ request }: ActionFunctionArgs) {// TODO: move all of this to transaction// biome-ignore lint/correctness/noUnusedVariables: suppressed due to migrationconst { baseCurrencyCode, ...locationData } = validation.data;- const [locationInsert] = await Promise.all([- upsertLocation(client, {- ...locationData,- name: "Headquarters",- companyId,- timezone: getLocalTimeZone(),- createdBy: userId- })- ]);+ const locationInsert = await upsertLocation(client, {+ ...locationData,+ name: "Headquarters",+ companyId,+ timezone: getLocalTimeZone(),+ createdBy: userId+ });if (locationInsert.error) {console.error(locationInsert.error);diff --git a/apps/erp/app/routes/x+/settings+/inventory.tsx b/apps/erp/app/routes/x+/settings+/inventory.tsxindex c80e2b84c0..273c40d187 100644--- a/apps/erp/app/routes/x+/settings+/inventory.tsx+++ b/apps/erp/app/routes/x+/settings+/inventory.tsx@@ -39,9 +39,7 @@ export async function loader({ request }: LoaderFunctionArgs) {view: "settings"});- const [companySettings] = await Promise.all([- getCompanySettings(client, companyId)- ]);+ const companySettings = await getCompanySettings(client, companyId);if (!companySettings.data)throw redirect(path.to.settings,diff --git a/apps/erp/app/routes/x+/settings+/items.tsx b/apps/erp/app/routes/x+/settings+/items.tsxindex 272d4310b1..5edb6143e3 100644--- a/apps/erp/app/routes/x+/settings+/items.tsx+++ b/apps/erp/app/routes/x+/settings+/items.tsx@@ -38,9 +38,7 @@ export async function loader({ request }: LoaderFunctionArgs) {view: "settings"});- const [companySettings] = await Promise.all([- getCompanySettings(client, companyId)- ]);+ const companySettings = await getCompanySettings(client, companyId);if (!companySettings.data)throw redirect(path.to.settings,diff --git a/apps/erp/app/routes/x+/settings+/labels.tsx b/apps/erp/app/routes/x+/settings+/labels.tsxindex 45fe72d864..5081d1ff30 100644--- a/apps/erp/app/routes/x+/settings+/labels.tsx+++ b/apps/erp/app/routes/x+/settings+/labels.tsx@@ -37,9 +37,7 @@ export async function loader({ request }: LoaderFunctionArgs) {view: "settings"});- const [companySettings] = await Promise.all([- getCompanySettings(client, companyId)- ]);+ const companySettings = await getCompanySettings(client, companyId);if (!companySettings.data)throw redirect(path.to.settings,diff --git a/apps/erp/app/routes/x+/stock-transfer+/$id.status.tsx b/apps/erp/app/routes/x+/stock-transfer+/$id.status.tsxindex 0641393865..eda412838e 100644--- a/apps/erp/app/routes/x+/stock-transfer+/$id.status.tsx+++ b/apps/erp/app/routes/x+/stock-transfer+/$id.status.tsx@@ -30,17 +30,15 @@ export async function action({ request, params }: ActionFunctionArgs) {);}- const [update] = await Promise.all([- updateStockTransferStatus(client, {- id,- status,- assignee: ["Completed"].includes(status) ? null : undefined,- completedAt: ["Completed"].includes(status)- ? new Date().toISOString()- : null,- updatedBy: userId- })- ]);+ const update = await updateStockTransferStatus(client, {+ id,+ status,+ assignee: ["Completed"].includes(status) ? null : undefined,+ completedAt: ["Completed"].includes(status)+ ? new Date().toISOString()+ : null,+ updatedBy: userId+ });if (update.error) {throw redirect(requestReferrer(request) ?? path.to.stockTransfer(id),diff --git a/apps/erp/app/routes/x+/supplier+/$supplierId.tsx b/apps/erp/app/routes/x+/supplier+/$supplierId.tsxindex 9e58543c0e..64e4953d6f 100644--- a/apps/erp/app/routes/x+/supplier+/$supplierId.tsx+++ b/apps/erp/app/routes/x+/supplier+/$supplierId.tsx@@ -30,11 +30,25 @@ export async function loader({ request, params }: LoaderFunctionArgs) {const { supplierId } = params;if (!supplierId) throw new Error("Could not find supplierId");- const [supplier, contacts, locations, tags] = await Promise.all([- getSupplier(client, supplierId),+ const serviceRole = getCarbonServiceRole();+ // Kick off approval in parallel — it only needs supplier.status, so we chain+ // off the supplier fetch rather than waiting for the whole Promise.all to+ // settle.+ const supplierPromise = getSupplier(client, supplierId);+ const [supplier, contacts, locations, tags, approval] = await Promise.all([+ supplierPromise,getSupplierContacts(client, supplierId),getSupplierLocations(client, supplierId),- getTagsList(client, companyId, "supplier")+ getTagsList(client, companyId, "supplier"),+ supplierPromise.then((s) =>+ getSupplierApprovalContext(+ serviceRole,+ supplierId,+ s.data?.status ?? null,+ companyId,+ userId+ )+ )]);if (supplier.error) {@@ -47,16 +61,6 @@ export async function loader({ request, params }: LoaderFunctionArgs) {);}- const serviceRole = getCarbonServiceRole();- const status = supplier.data?.status ?? null;- const approval = await getSupplierApprovalContext(- serviceRole,- supplierId,- status,- companyId,- userId- );-return {supplier: supplier.data,contacts: contacts.data ?? [],diff --git a/apps/erp/app/routes/x+/supplier-quote+/$id.finalize.tsx b/apps/erp/app/routes/x+/supplier-quote+/$id.finalize.tsxindex 5dc26ff22f..613a42ab66 100644--- a/apps/erp/app/routes/x+/supplier-quote+/$id.finalize.tsx+++ b/apps/erp/app/routes/x+/supplier-quote+/$id.finalize.tsx@@ -25,7 +25,7 @@ export async function action(args: ActionFunctionArgs) {const { id } = params;if (!id) throw new Error("Could not find supplier quote id");- const [quote] = await Promise.all([getSupplierQuote(client, id)]);+ const quote = await getSupplierQuote(client, id);if (quote.error) {throw redirect(path.to.supplierQuote(id),@@ -34,16 +34,14 @@ export async function action(args: ActionFunctionArgs) {}// Reuse existing external link or create one if it doesn't exist- const [externalLink] = await Promise.all([- upsertExternalLink(client, {- id: quote.data.externalLinkId ?? undefined,- documentType: "SupplierQuote",- documentId: id,- supplierId: quote.data.supplierId,- expiresAt: quote.data.expirationDate,- companyId- })- ]);+ const externalLink = await upsertExternalLink(client, {+ id: quote.data.externalLinkId ?? undefined,+ documentType: "SupplierQuote",+ documentId: id,+ supplierId: quote.data.supplierId,+ expiresAt: quote.data.expirationDate,+ companyId+ });if (externalLink.data && quote.data.externalLinkId !== externalLink.data.id) {await clientdiff --git a/apps/erp/app/routes/x+/supplier-quote+/$id.send.tsx b/apps/erp/app/routes/x+/supplier-quote+/$id.send.tsxindex b253ac9b0d..04e7f9d33f 100644--- a/apps/erp/app/routes/x+/supplier-quote+/$id.send.tsx+++ b/apps/erp/app/routes/x+/supplier-quote+/$id.send.tsx@@ -32,7 +32,7 @@ export async function action(args: ActionFunctionArgs) {const { id } = params;if (!id) throw new Error("Could not find supplier quote id");- const [quote] = await Promise.all([getSupplierQuote(client, id)]);+ const quote = await getSupplierQuote(client, id);if (quote.error) {throw redirect(path.to.supplierQuote(id),@@ -41,16 +41,14 @@ export async function action(args: ActionFunctionArgs) {}// Reuse existing external link or create one if it doesn't exist- const [externalLink] = await Promise.all([- upsertExternalLink(client, {- id: quote.data.externalLinkId ?? undefined,- documentType: "SupplierQuote",- documentId: id,- supplierId: quote.data.supplierId,- expiresAt: quote.data.expirationDate,- companyId- })- ]);+ const externalLink = await upsertExternalLink(client, {+ id: quote.data.externalLinkId ?? undefined,+ documentType: "SupplierQuote",+ documentId: id,+ supplierId: quote.data.supplierId,+ expiresAt: quote.data.expirationDate,+ companyId+ });if (externalLink.data && quote.data.externalLinkId !== externalLink.data.id) {await clientdiff --git a/apps/mes/app/entry.server.tsx b/apps/mes/app/entry.server.tsxindex d9e6605dfe..048b27f94c 100644--- a/apps/mes/app/entry.server.tsx+++ b/apps/mes/app/entry.server.tsx@@ -1,7 +1,7 @@import { handleRequest as vercelHandleRequest } from "@vercel/react-router/entry.server";import type { EntryContext, RouterContextProvider } from "react-router";-export const streamTimeout = 5_000;+export const streamTimeout = 35_000;export default function handleRequest(request: Request,diff --git a/packages/auth/src/lib/supabase/client.ts b/packages/auth/src/lib/supabase/client.tsindex c99b964c56..25c049ceab 100644--- a/packages/auth/src/lib/supabase/client.ts+++ b/packages/auth/src/lib/supabase/client.ts@@ -5,26 +5,45 @@ import type { MutableRefObject } from "react";import type { StoreApi } from "zustand";import { SUPABASE_ANON_KEY, SUPABASE_URL } from "../../config/env";+const STORAGE_TIMEOUT_MS = 30_000;++const fetchWithStorageTimeout: typeof fetch = (input, init) => {+ const url =+ typeof input === "string"+ ? input+ : input instanceof URL+ ? input.href+ : input.url;++ if (!url.includes("/storage/v1/")) {+ return fetch(input, init);+ }++ const timeoutSignal = AbortSignal.timeout(STORAGE_TIMEOUT_MS);+ const signal = init?.signal+ ? AbortSignal.any([init.signal, timeoutSignal])+ : timeoutSignal;++ return fetch(input, { ...init, signal });+};+export const getCarbonClient = (supabaseKey: string,accessToken?: string): SupabaseClient<Database, "public"> => {- const global = accessToken- ? {- global: {- headers: {- Authorization: `Bearer ${accessToken}`- }- }- }- : {};+ const headers = accessToken+ ? { Authorization: `Bearer ${accessToken}` }+ : undefined;const client = createClient<Database, "public">(SUPABASE_URL!, supabaseKey, {auth: {autoRefreshToken: false,persistSession: false},- ...global+ global: {+ fetch: fetchWithStorageTimeout,+ ...(headers ? { headers } : {})+ }});return client;@@ -36,6 +55,7 @@ export const getCarbonAPIKeyClient = (apiKey: string) => {SUPABASE_ANON_KEY!,{global: {+ fetch: fetchWithStorageTimeout,headers: {"carbon-key": apiKey}@@ -54,6 +74,9 @@ export const createCarbonWithAuthGetter = (autoRefreshToken: false,persistSession: false},+ global: {+ fetch: fetchWithStorageTimeout+ },async accessToken() {if (!store.current) return null;const state = store.current.getState();