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.

Onshape: Fix element type for BOM (#641)

dmzaitsev40b3b792b87b
diff --git a/apps/erp/app/components/OnshapeSync.tsx b/apps/erp/app/components/OnshapeSync.tsx
index 02bbff2b3b..945c1a5e88 100644
--- a/apps/erp/app/components/OnshapeSync.tsx
+++ b/apps/erp/app/components/OnshapeSync.tsx
@@ -290,7 +290,7 @@ export const OnshapeSync = ({
</div>
<div className="flex w-full items-center justify-between gap-2">
- <span className="text-xs text-muted-foreground">Element:</span>
+ <span className="text-xs text-muted-foreground">Assembly:</span>
<div className="w-[180px]">
<Combobox
isLoading={elementsFetcher.state === "loading"}
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.ts
index 2d67692eff..ea6ba73620 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
@@ -1,5 +1,10 @@
import { requirePermissions } from "@carbon/auth/auth.server";
-import { getOnshapeClient } from "@carbon/ee/onshape";
+import {
+ getOnshapeClient,
+ OnshapeDocument,
+ OnshapeElementType,
+ OnshapeWVMType
+} from "@carbon/ee/onshape";
import type {
LoaderFunctionArgs,
ShouldRevalidateFunction
@@ -38,30 +43,17 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
}
const onshapeClient = result.client;
+ const document: OnshapeDocument = {
+ documentId: did,
+ wvm: OnshapeWVMType.VERSION,
+ wvmId: vid
+ };
try {
- let limit = 20;
- let offset = 0;
- let allDocuments: Array<{ id: string; name: string }> = [];
-
- while (true && offset < 100) {
- const response = await onshapeClient.getElements(did, vid, limit, offset);
-
- if (!response || response.length === 0) {
- break;
- }
-
- allDocuments.push(...response);
-
- if (response.length < limit) {
- break;
- }
-
- offset += limit;
- }
+ const documentAssemblies = await onshapeClient.getElements(document, OnshapeElementType.ASSEMBLY);
return {
- data: allDocuments,
+ data: documentAssemblies,
error: null
};
} catch (error) {
@@ -71,7 +63,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
error:
error instanceof Error
? error.message
- : "Failed to get versions from Onshape"
+ : "Failed to get assemblies from Onshape"
};
}
}
diff --git a/packages/ee/src/onshape/lib/client.ts b/packages/ee/src/onshape/lib/client.ts
index 0beb693019..2c76f73ccc 100644
--- a/packages/ee/src/onshape/lib/client.ts
+++ b/packages/ee/src/onshape/lib/client.ts
@@ -2,6 +2,8 @@ import { ONSHAPE_CLIENT_ID, ONSHAPE_CLIENT_SECRET } from "@carbon/auth";
import type { Database } from "@carbon/database";
import type { SupabaseClient } from "@supabase/supabase-js";
import axios from "axios";
+import { OnshapeDocument } from "./document.type";
+import { OnshapeElementType } from "./element.type";
interface OnshapeClientConfig {
baseUrl: string;
@@ -85,14 +87,12 @@ export class OnshapeClient {
}
async getElements(
- documentId: string,
- versionId: string,
- limit: number = 20,
- offset: number = 0
+ document: OnshapeDocument,
+ elementType?: OnshapeElementType
): Promise<any> {
return this.request(
"GET",
- `/api/v10/documents/d/${documentId}/v/${versionId}/elements`
+ `/api/v10/documents/d/${document.documentId}/${document.wvm}/${document.wvmId}/elements${elementType ? '?elementType=' + elementType : '' }`
);
}
diff --git a/packages/ee/src/onshape/lib/document.type.ts b/packages/ee/src/onshape/lib/document.type.ts
new file mode 100644
index 0000000000..c1aeab9f28
--- /dev/null
+++ b/packages/ee/src/onshape/lib/document.type.ts
@@ -0,0 +1,11 @@
+export enum OnshapeWVMType {
+ WORKSPACE = 'w',
+ VERSION = 'v',
+ MICROVERSION = 'm'
+}
+
+export interface OnshapeDocument {
+ documentId: string
+ wvm: OnshapeWVMType;
+ wvmId: string;
+}
diff --git a/packages/ee/src/onshape/lib/element.type.ts b/packages/ee/src/onshape/lib/element.type.ts
new file mode 100644
index 0000000000..f63d76ea65
--- /dev/null
+++ b/packages/ee/src/onshape/lib/element.type.ts
@@ -0,0 +1,13 @@
+import { OnshapeDocument } from "./document.type";
+
+export interface OnshapeElement extends OnshapeDocument {
+ elementId: string;
+ linkDocumentId?: string;
+ configuration?: string;
+ partId?: string;
+}
+
+export enum OnshapeElementType {
+ ASSEMBLY = 'ASSEMBLY',
+ PART_STUDIO = 'PARTSTUDIO'
+}
\ No newline at end of file
diff --git a/packages/ee/src/onshape/lib/index.ts b/packages/ee/src/onshape/lib/index.ts
index 3d6600311d..70162ef793 100644
--- a/packages/ee/src/onshape/lib/index.ts
+++ b/packages/ee/src/onshape/lib/index.ts
@@ -1,2 +1,4 @@
export * from "./client";
export * from "./data";
+export * from "./document.type"
+export * from "./element.type"
\ No newline at end of file