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
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.
import { requirePermissions } from "@carbon/auth/auth.server";
import { getOnshapeClient } from "@carbon/ee/onshape";
import { getLogger } from "@carbon/logger";
import type {
LoaderFunctionArgs,
ShouldRevalidateFunction
} from "react-router";
const logger = getLogger("erp", "integrations-onshape-documents");
export const shouldRevalidate: ShouldRevalidateFunction = () => {
return false;
};
export async function loader({ request }: LoaderFunctionArgs) {
const { client, companyId, userId } = await requirePermissions(request, {});
const result = await getOnshapeClient(client, companyId, userId);
if (result.error) {
return {
data: [],
error: result.error
};
}
const onshapeClient = result.client;
try {
let limit = 20;
let offset = 0;
let allDocuments: Array<{ id: string; name: string }> = [];
while (true) {
// @ts-expect-error TS18047 - TODO: fix type
const response = await onshapeClient.getDocuments(limit, offset);
if (!response.items || response.items.length === 0) {
break;
}
allDocuments.push(...response.items);
if (response.items.length < limit) {
break;
}
offset += limit;
}
return {
data: { items: allDocuments },
error: null
};
} catch (error) {
logger.error("Error", { error: error });
return {
data: null,
error:
error instanceof Error
? error.message
: "Failed to get documents from Onshape"
};
}
}