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
refactor: use axios to fetch from onshape
Brad Barbin29fe03c108ae
diff --git a/apps/erp/app/integrations/onshape/lib/client.ts b/apps/erp/app/integrations/onshape/lib/client.tsindex b6a2e16f44..0defb9ac8e 100644--- a/apps/erp/app/integrations/onshape/lib/client.ts+++ b/apps/erp/app/integrations/onshape/lib/client.ts@@ -1,3 +1,5 @@+import axios from "axios";+interface OnshapeClientConfig {baseUrl: string;accessKey: string;@@ -17,11 +19,17 @@ export class OnshapeClient {private baseUrl: string;private accessKey: string;private secretKey: string;+ private axiosInstance: ReturnType<typeof axios.create>;constructor(config: OnshapeClientConfig) {this.baseUrl = config.baseUrl;this.accessKey = config.accessKey;this.secretKey = config.secretKey;++ this.axiosInstance = axios.create({+ baseURL: this.baseUrl,+ headers: this.getAuthHeaders(),+ });}/**@@ -31,7 +39,7 @@ export class OnshapeClient {const auth = Buffer.from(`${this.accessKey}:${this.secretKey}`).toString("base64");- console.log("onshapedauth", auth);+return {"Content-Type": "application/json",Accept: "application/json;charset=UTF-8; qs=0.09",@@ -47,23 +55,22 @@ export class OnshapeClient {path: string,body?: Record<string, unknown>): Promise<T> {- const headers = this.getAuthHeaders();- const url = `${this.baseUrl}${path}`;- console.log("onshapedurl", url);-- const response = await fetch(url, {- method,- headers,- body: body ? JSON.stringify(body) : undefined,- });-- if (!response.ok) {- const errorText = await response.text();- console.log("Onshape API error headers:", headers);- throw new Error(`Onshape API error (${response.status}): ${errorText}`);+ try {+ const response = await this.axiosInstance.request<T>({+ method,+ url: path,+ data: body,+ });+ return response.data;+ } catch (error) {+ if (axios.isAxiosError(error)) {+ console.log("Onshape API error headers:", error.config?.headers);+ throw new Error(+ `Onshape API error (${error.response?.status}): ${error.response?.data}`+ );+ }+ throw error;}-- return response.json();}/**diff --git a/apps/erp/app/routes/api+/integrations.onshape.d.$did.v.$vid.e.$eid.bom.ts b/apps/erp/app/routes/api+/integrations.onshape.d.$did.v.$vid.e.$eid.bom.tsindex 0579ebc8b7..81e6c378df 100644--- a/apps/erp/app/routes/api+/integrations.onshape.d.$did.v.$vid.e.$eid.bom.ts+++ b/apps/erp/app/routes/api+/integrations.onshape.d.$did.v.$vid.e.$eid.bom.ts@@ -13,7 +13,7 @@ export const shouldRevalidate: ShouldRevalidateFunction = () => {export const config = {maxDuration: 300,- runtime: "node",+ runtime: "nodejs",};export async function loader({ request, params }: LoaderFunctionArgs) {diff --git a/apps/erp/app/routes/api+/integrations.onshape.d.$did.v.$vid.elements.ts b/apps/erp/app/routes/api+/integrations.onshape.d.$did.v.$vid.elements.tsindex dce72831ae..833d96233f 100644--- a/apps/erp/app/routes/api+/integrations.onshape.d.$did.v.$vid.elements.ts+++ b/apps/erp/app/routes/api+/integrations.onshape.d.$did.v.$vid.elements.ts@@ -10,6 +10,10 @@ export const shouldRevalidate: ShouldRevalidateFunction = () => {return false;};+export const config = {+ runtime: "nodejs",+};+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {});diff --git a/apps/erp/app/routes/api+/integrations.onshape.d.$did.versions.ts b/apps/erp/app/routes/api+/integrations.onshape.d.$did.versions.tsindex 10c505f60e..86d1ec923d 100644--- a/apps/erp/app/routes/api+/integrations.onshape.d.$did.versions.ts+++ b/apps/erp/app/routes/api+/integrations.onshape.d.$did.versions.ts@@ -10,6 +10,10 @@ export const shouldRevalidate: ShouldRevalidateFunction = () => {return false;};+export const config = {+ runtime: "nodejs",+};+export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {});diff --git a/apps/erp/app/routes/api+/integrations.onshape.documents.ts b/apps/erp/app/routes/api+/integrations.onshape.documents.tsindex 69532f84d2..288da9b697 100644--- a/apps/erp/app/routes/api+/integrations.onshape.documents.ts+++ b/apps/erp/app/routes/api+/integrations.onshape.documents.ts@@ -10,6 +10,10 @@ export const shouldRevalidate: ShouldRevalidateFunction = () => {return false;};+export const config = {+ runtime: "nodejs",+};+export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {});diff --git a/apps/erp/app/routes/api+/integrations.onshape.sync.ts b/apps/erp/app/routes/api+/integrations.onshape.sync.tsindex 56a61dd6f2..8de031b259 100644--- a/apps/erp/app/routes/api+/integrations.onshape.sync.ts+++ b/apps/erp/app/routes/api+/integrations.onshape.sync.ts@@ -4,7 +4,8 @@ import { json, type ActionFunctionArgs } from "@vercel/remix";import { onShapeDataValidator } from "~/integrations/onshape/lib/data";export const config = {- maxDuration: 90,+ runtime: "nodejs",+ maxDuration: 300,};export async function action({ request }: ActionFunctionArgs) {