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.

feat: stub out integration with paperless parts

Brad Barbinbc24cd35bd31
diff --git a/apps/carbon/app/integrations/index.ts b/apps/carbon/app/integrations/index.ts
index d3c62be8de..156037f90b 100644
--- a/apps/carbon/app/integrations/index.ts
+++ b/apps/carbon/app/integrations/index.ts
@@ -1,4 +1,5 @@
import { ExchangeRates } from "./exchange-rates/config";
+import { PaperlessParts } from "./paperless-parts/config";
import { QuickBooks } from "./quickbooks/config";
import { Resend } from "./resend/config";
import { Slack } from "./slack/config";
@@ -7,6 +8,7 @@ import { Zapier } from "./zapier/config";
export const integrations = [
ExchangeRates,
+ PaperlessParts,
Resend,
Slack,
QuickBooks,
diff --git a/apps/carbon/app/integrations/paperless-parts/config.tsx b/apps/carbon/app/integrations/paperless-parts/config.tsx
new file mode 100644
index 0000000000..35e9164843
--- /dev/null
+++ b/apps/carbon/app/integrations/paperless-parts/config.tsx
@@ -0,0 +1,141 @@
+import { cn, Input, InputGroup, InputRightElement } from "@carbon/react";
+import { isBrowser } from "@carbon/utils";
+import type { SVGProps } from "react";
+import { z } from "zod";
+import { Copy } from "~/components";
+import type { IntegrationConfig } from "../types";
+
+export const PaperlessParts: IntegrationConfig = {
+ name: "Paperless Parts",
+ id: "paperless-parts",
+ active: true,
+ category: "Estimating & Quoting",
+ logo: Logo,
+ description:
+ "Paperless Parts is an estimating and quoting platform that uses advanced geometric interrogation to generate accurate estimates for sheet metal fabrication, CNC machining, and more. This integration will sync data from Paperless Parts to Carbon.",
+ shortDescription: "Sync data from Paperless Parts to Carbon.",
+ setupInstructions: SetupInstructions,
+ images: [],
+
+ settings: [
+ {
+ name: "apiKey",
+ label: "API Key",
+ type: "text",
+ required: true,
+ value: "",
+ },
+ {
+ name: "secretKey",
+ label: "Webhook Signing Secret",
+ type: "text",
+ required: true,
+ value: "",
+ },
+ ],
+ schema: z.object({
+ apiKey: z.string().min(1, { message: "API Key is required" }),
+ secretKey: z
+ .string()
+ .min(1, { message: "Webhook Signing Secret is required" }),
+ }),
+ onInitialize: () => {},
+ onUninstall: () => {},
+};
+
+function SetupInstructions({ companyId }: { companyId: string }) {
+ const webhookUrl = isBrowser
+ ? `${window.location.origin}/api/webhook/paperless-parts/${companyId}`
+ : "";
+ return (
+ <>
+ <p className="text-sm text-muted-foreground">
+ First, copy and paste the following URL into the Webhook URL field in
+ your Paperless Parts account:
+ </p>
+ <InputGroup className="mb-8">
+ <Input value={webhookUrl} />
+ <InputRightElement>
+ <Copy text={webhookUrl} />
+ </InputRightElement>
+ </InputGroup>
+ <p className="text-sm text-muted-foreground">
+ Next, copy the API Key and Webhook Signing Secret from your Paperless
+ Parts account and paste them into the API Key and Webhook Signing Secret
+ fields below:
+ </p>
+ </>
+ );
+}
+
+function Logo(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ {...props}
+ xmlns="http://www.w3.org/2000/svg"
+ width="558.86"
+ height="74.71"
+ viewBox="0 0 558.86 74.71"
+ fill="none"
+ className={cn("text-foreground", props.className)}
+ >
+ <g xmlns="http://www.w3.org/2000/svg">
+ <g>
+ <path
+ fill="currentColor"
+ d="M30.88,44.22a15.56,15.56,0,0,1-3.23,5.08A13.43,13.43,0,0,1,23,52.44a14.08,14.08,0,0,1-5.37,1.06,11.46,11.46,0,0,1-6.35-1.64A16.52,16.52,0,0,1,7.11,48l.06,14.22H0V21.83H7.17V27a15.54,15.54,0,0,1,4.22-4.14,11.06,11.06,0,0,1,6.27-1.68A14,14,0,0,1,23,22.24a13.6,13.6,0,0,1,4.6,3.15,15.77,15.77,0,0,1,3.25,5.08,18,18,0,0,1,1.23,6.87A18.4,18.4,0,0,1,30.88,44.22Zm-6.67-11a9.58,9.58,0,0,0-1.91-3.14,8.39,8.39,0,0,0-2.82-2A8.54,8.54,0,0,0,16,27.35a8.76,8.76,0,0,0-3.47.71,8.35,8.35,0,0,0-2.87,2,10,10,0,0,0-2,3.14,11.81,11.81,0,0,0,0,8.23,10,10,0,0,0,2,3.14,8.49,8.49,0,0,0,2.87,2,8.75,8.75,0,0,0,3.47.7,8.53,8.53,0,0,0,3.44-.7,8.39,8.39,0,0,0,2.82-2,9.58,9.58,0,0,0,1.91-3.14,12.62,12.62,0,0,0,0-8.29Z"
+ />
+ <path
+ fill="currentColor"
+ d="M57.29,52.86V49a13.38,13.38,0,0,1-4,3.17,12.85,12.85,0,0,1-6,1.29A14,14,0,0,1,43,52.88a10.18,10.18,0,0,1-3.49-1.82,8.82,8.82,0,0,1-3.32-7.14v-.11a9.68,9.68,0,0,1,.94-4.41,8.57,8.57,0,0,1,2.61-3.12,12,12,0,0,1,4-1.85,19.51,19.51,0,0,1,5-.61,28.22,28.22,0,0,1,4.79.35,28.75,28.75,0,0,1,3.79.94v-.76a6.19,6.19,0,0,0-2-4.94,8.44,8.44,0,0,0-5.67-1.7,18.6,18.6,0,0,0-4.7.53,30.13,30.13,0,0,0-4.17,1.41L38.9,24a31.74,31.74,0,0,1,5.29-1.88,26.08,26.08,0,0,1,6.52-.71q6.93,0,10.28,3.44t3.35,9.66v18.4Zm.18-13.17a19.06,19.06,0,0,0-3.21-.88,21.19,21.19,0,0,0-3.9-.35,9.13,9.13,0,0,0-5.23,1.29,4.21,4.21,0,0,0-1.88,3.7v.12A3.85,3.85,0,0,0,45,47a7.44,7.44,0,0,0,4.26,1.17,10.62,10.62,0,0,0,3.26-.47,8.38,8.38,0,0,0,2.62-1.32,6.06,6.06,0,0,0,1.73-2,5.84,5.84,0,0,0,.62-2.68Z"
+ />
+ <path
+ fill="currentColor"
+ d="M101.62,44.22a15.4,15.4,0,0,1-3.23,5.08,13.39,13.39,0,0,1-4.64,3.14,14.13,14.13,0,0,1-5.38,1.06A11.44,11.44,0,0,1,82,51.86,16.18,16.18,0,0,1,77.86,48l0,14.22H70.75V21.83h7.16V27a15.69,15.69,0,0,1,4.22-4.14,11.1,11.1,0,0,1,6.28-1.68,14,14,0,0,1,5.33,1.06,13.5,13.5,0,0,1,4.6,3.15,15.79,15.79,0,0,1,3.26,5.08,18,18,0,0,1,1.23,6.87A18.2,18.2,0,0,1,101.62,44.22ZM95,33.2A9.41,9.41,0,0,0,93,30.06a8.49,8.49,0,0,0-6.25-2.71,8.72,8.72,0,0,0-3.47.71,8.3,8.3,0,0,0-2.88,2,10.15,10.15,0,0,0-2,3.14,12,12,0,0,0,0,8.23,10.15,10.15,0,0,0,2,3.14,8.43,8.43,0,0,0,2.88,2,8.71,8.71,0,0,0,3.47.7A8.43,8.43,0,0,0,93,44.63,9.41,9.41,0,0,0,95,41.49a12.45,12.45,0,0,0,0-8.29Z"
+ />
+ <path
+ fill="currentColor"
+ d="M117.34,45.72a8.84,8.84,0,0,0,5.88,2,10.34,10.34,0,0,0,4.58-.94A14.58,14.58,0,0,0,131.62,44l4.17,3.7A16.94,16.94,0,0,1,130.47,52a15.88,15.88,0,0,1-7.37,1.59,16.64,16.64,0,0,1-6.26-1.17A15.09,15.09,0,0,1,108.41,44a17.11,17.11,0,0,1-1.23-6.61,17.67,17.67,0,0,1,1.11-6.29A15.86,15.86,0,0,1,111.44,26a15.09,15.09,0,0,1,4.78-3.49,14.31,14.31,0,0,1,6.12-1.3,14.62,14.62,0,0,1,6.49,1.36,13.27,13.27,0,0,1,4.64,3.64,15.76,15.76,0,0,1,2.79,5.35,21.5,21.5,0,0,1,.94,6.4c0,.31,0,.63,0,.94s0,.65-.09,1H114.29A9.36,9.36,0,0,0,117.34,45.72Zm12.81-10.55a12.27,12.27,0,0,0-.76-3.2,8.17,8.17,0,0,0-1.59-2.59,7.63,7.63,0,0,0-2.38-1.73,7.34,7.34,0,0,0-3.14-.65,7.2,7.2,0,0,0-5.44,2.26,10.21,10.21,0,0,0-2.61,5.91Z"
+ />
+ <path
+ fill="currentColor"
+ d="M150.89,52.86h-7.17v-31h7.17v7a13.68,13.68,0,0,1,4.17-5.64,10.06,10.06,0,0,1,6.82-1.94v7.52h-.41a11.58,11.58,0,0,0-4.29.77,9,9,0,0,0-3.35,2.29,10.36,10.36,0,0,0-2.17,3.85,17.18,17.18,0,0,0-.77,5.37Z"
+ />
+ <path fill="currentColor" d="M168.4,52.86V10h7.17v42.9Z" />
+ <path
+ fill="currentColor"
+ d="M191.91,45.72a8.8,8.8,0,0,0,5.87,2,10.42,10.42,0,0,0,4.59-.94A14.54,14.54,0,0,0,206.18,44l4.18,3.7A17.05,17.05,0,0,1,205,52a16,16,0,0,1-7.38,1.59,16.58,16.58,0,0,1-6.25-1.17A15.06,15.06,0,0,1,183,44a17.11,17.11,0,0,1-1.23-6.61,17.46,17.46,0,0,1,1.12-6.29A15.83,15.83,0,0,1,186,26a15.13,15.13,0,0,1,4.79-3.49,14.27,14.27,0,0,1,6.11-1.3,14.59,14.59,0,0,1,6.49,1.36A13.4,13.4,0,0,1,208,26.18a15.94,15.94,0,0,1,2.79,5.35,21.83,21.83,0,0,1,.94,6.4c0,.31,0,.63,0,.94s-.05.65-.09,1h-22.8A9.37,9.37,0,0,0,191.91,45.72Zm12.81-10.55A12.28,12.28,0,0,0,204,32a8.33,8.33,0,0,0-1.58-2.59A7.63,7.63,0,0,0,200,27.65a7.39,7.39,0,0,0-3.15-.65,7.19,7.19,0,0,0-5.43,2.26,10.22,10.22,0,0,0-2.62,5.91Z"
+ />
+ <path
+ fill="currentColor"
+ d="M240.21,48a8.38,8.38,0,0,1-2.44,3,11,11,0,0,1-3.68,1.83,16.08,16.08,0,0,1-4.52.61,21,21,0,0,1-6.79-1.17,21.63,21.63,0,0,1-6.37-3.47L219.58,44a20.24,20.24,0,0,0,5.14,2.85,14.39,14.39,0,0,0,5,1,6,6,0,0,0,3.55-.91,2.87,2.87,0,0,0,1.27-2.44v-.11a2.27,2.27,0,0,0-.56-1.53,5.07,5.07,0,0,0-1.53-1.15,14.2,14.2,0,0,0-2.23-.88L227.63,40c-1.13-.36-2.28-.75-3.44-1.18a12.68,12.68,0,0,1-3.11-1.67,8.56,8.56,0,0,1-2.26-2.53,7.23,7.23,0,0,1-.88-3.73v-.12a8.93,8.93,0,0,1,.85-3.94,8.8,8.8,0,0,1,2.35-3A10.52,10.52,0,0,1,224.66,22,14.15,14.15,0,0,1,229,21.3a20,20,0,0,1,5.94.94,21.13,21.13,0,0,1,5.46,2.59l-2.82,5.05A23.18,23.18,0,0,0,233,27.74a13,13,0,0,0-4.23-.8,5.21,5.21,0,0,0-3.21.88,2.73,2.73,0,0,0-1.14,2.24v.11a2,2,0,0,0,.59,1.44,5.58,5.58,0,0,0,1.55,1.12,17.62,17.62,0,0,0,2.23.94c.85.29,1.72.58,2.62.85,1.14.35,2.27.77,3.41,1.24a14.35,14.35,0,0,1,3.08,1.73,8.74,8.74,0,0,1,2.27,2.5,6.91,6.91,0,0,1,.88,3.58v.12A9.89,9.89,0,0,1,240.21,48Z"
+ />
+ <path
+ fill="currentColor"
+ d="M269,48a8.38,8.38,0,0,1-2.44,3,11,11,0,0,1-3.67,1.83,16.16,16.16,0,0,1-4.53.61,20.94,20.94,0,0,1-6.78-1.17,21.56,21.56,0,0,1-6.38-3.47L248.37,44a20.29,20.29,0,0,0,5.15,2.85,14.3,14.3,0,0,0,5,1,6,6,0,0,0,3.55-.91,2.85,2.85,0,0,0,1.27-2.44v-.11a2.27,2.27,0,0,0-.56-1.53,5,5,0,0,0-1.53-1.15,14.2,14.2,0,0,0-2.23-.88L256.42,40c-1.13-.36-2.28-.75-3.43-1.18a12.57,12.57,0,0,1-3.12-1.67,8.56,8.56,0,0,1-2.26-2.53,7.23,7.23,0,0,1-.88-3.73v-.12a8.93,8.93,0,0,1,.85-3.94,8.8,8.8,0,0,1,2.35-3A10.57,10.57,0,0,1,253.46,22a14.15,14.15,0,0,1,4.32-.65,20,20,0,0,1,5.93.94,21.13,21.13,0,0,1,5.46,2.59l-2.82,5.05a22.91,22.91,0,0,0-4.52-2.14,13,13,0,0,0-4.23-.8,5.18,5.18,0,0,0-3.2.88,2.71,2.71,0,0,0-1.15,2.24v.11a2,2,0,0,0,.59,1.44,5.49,5.49,0,0,0,1.56,1.12,17,17,0,0,0,2.23.94c.84.29,1.71.58,2.61.85,1.14.35,2.27.77,3.41,1.24a14.43,14.43,0,0,1,3.09,1.73A8.7,8.7,0,0,1,269,40a6.81,6.81,0,0,1,.88,3.58v.12A9.75,9.75,0,0,1,269,48Z"
+ />
+ <path
+ fill="currentColor"
+ d="M309.19,32.35a12.76,12.76,0,0,1-3.56,4.52,15.33,15.33,0,0,1-5.28,2.74,22.69,22.69,0,0,1-6.5.91H287V52.86h-9.05V11.72h16.81a19.94,19.94,0,0,1,6.61,1,14.19,14.19,0,0,1,4.93,2.91,12.73,12.73,0,0,1,3.12,4.5,15,15,0,0,1,1.08,5.78v.12A14.45,14.45,0,0,1,309.19,32.35Zm-7.87-6.23a5.61,5.61,0,0,0-2-4.64A8.33,8.33,0,0,0,294,19.89h-7V32.47h7.17a7.36,7.36,0,0,0,5.29-1.8,5.88,5.88,0,0,0,1.88-4.43Z"
+ />
+ <path
+ fill="currentColor"
+ d="M343.62,52.86l-3.76-9.23H322.47l-3.76,9.23h-9.23l17.63-41.43h8.35l17.62,41.43ZM331.17,22.3,325.7,35.64h10.93Z"
+ />
+ <path
+ fill="currentColor"
+ d="M383.46,52.86l-8.81-13.17h-7.11V52.86h-9.05V11.72h18.8q7.35,0,11.43,3.59t4.08,10v.11a12.92,12.92,0,0,1-2.43,8.14A14.18,14.18,0,0,1,384,38.17L394,52.86Zm.18-27.09a5.26,5.26,0,0,0-1.88-4.41,8.32,8.32,0,0,0-5.23-1.47h-9V31.7h9.16a7.57,7.57,0,0,0,5.15-1.58,5.4,5.4,0,0,0,1.79-4.24Z"
+ />
+ <path
+ fill="currentColor"
+ d="M419.3,20.07V52.86h-9.05V20.07H397.74V11.72h34.08v8.35Z"
+ />
+ <path
+ fill="currentColor"
+ d="M466.44,46.13a11.07,11.07,0,0,1-3.1,4,13.87,13.87,0,0,1-4.74,2.47,20.44,20.44,0,0,1-6.1.85,27.37,27.37,0,0,1-9.22-1.61,24.52,24.52,0,0,1-8.23-5l5.35-6.4a26.67,26.67,0,0,0,5.79,3.64,15.45,15.45,0,0,0,6.49,1.35,7.88,7.88,0,0,0,4.38-1,3.24,3.24,0,0,0,1.55-2.85v-.11a3.65,3.65,0,0,0-.32-1.56,3.28,3.28,0,0,0-1.24-1.26,12.39,12.39,0,0,0-2.53-1.18c-1.08-.39-2.49-.8-4.21-1.23a50.49,50.49,0,0,1-5.66-1.71,15.78,15.78,0,0,1-4.3-2.32,9.33,9.33,0,0,1-2.74-3.44,11.88,11.88,0,0,1-1-5.11v-.12a11.93,11.93,0,0,1,1.05-5.08,11.52,11.52,0,0,1,2.95-3.91A13.29,13.29,0,0,1,445.17,12a18.1,18.1,0,0,1,5.8-.88,24.65,24.65,0,0,1,8.32,1.35,23.83,23.83,0,0,1,7,3.88l-4.7,6.81a30.39,30.39,0,0,0-5.4-3,13.94,13.94,0,0,0-5.29-1.08,6.36,6.36,0,0,0-4,1,3.1,3.1,0,0,0-1.32,2.55v.12a3.74,3.74,0,0,0,.38,1.73,3.49,3.49,0,0,0,1.39,1.32A12.29,12.29,0,0,0,450.08,27c1.15.35,2.62.77,4.39,1.24A40.2,40.2,0,0,1,460,30.09a15.42,15.42,0,0,1,4.13,2.46,9.43,9.43,0,0,1,2.53,3.38,11.48,11.48,0,0,1,.85,4.64v.12A12.89,12.89,0,0,1,466.44,46.13Z"
+ />
+ </g>
+ </g>
+ </svg>
+ );
+}
diff --git a/apps/carbon/app/integrations/paperless-parts/lib/client.ts b/apps/carbon/app/integrations/paperless-parts/lib/client.ts
new file mode 100644
index 0000000000..98fc1ee326
--- /dev/null
+++ b/apps/carbon/app/integrations/paperless-parts/lib/client.ts
@@ -0,0 +1,117 @@
+type PaperlessPartsResponse<T extends object> =
+ | {
+ data: null;
+ error: string;
+ }
+ | {
+ data: T;
+ error: null;
+ };
+
+export class PaperlessPartsClient {
+ private readonly apiKey: string;
+ private readonly baseUrl: string;
+
+ constructor(apiKey: string) {
+ this.apiKey = apiKey;
+ this.baseUrl = "https://api.paperless-parts.com/";
+ }
+
+ async listNewOrders() {
+ return this._request("/orders/public/new");
+ }
+
+ async getOrderDetails(id: number) {
+ return this._request(`/orders/public/${id}`);
+ }
+
+ async listNewQuotesAndRevisions() {
+ return this._request("/quotes/public/new");
+ }
+
+ async listQuoteHeaders() {
+ return this._request("/quotes/public");
+ }
+
+ async getQuoteHeader(id: string) {
+ return this._request(`/quotes/public/${id}`);
+ }
+
+ async getQuoteDetails(id: number) {
+ return this._request(`/quotes/public/${id}`);
+ }
+
+ async getQuoteItem(id: number) {
+ return this._request(`/quotes/public/items/${id}`);
+ }
+
+ async getOperationDetails(id: string) {
+ return this._request(`/quotes/public/operations/${id}`);
+ }
+
+ async getAddOnDetails(id: string) {
+ return this._request(`/quotes/public/add_ons/${id}`);
+ }
+
+ async getDiscountDetails(id: string) {
+ return this._request(`/quotes/public/discounts/${id}`);
+ }
+
+ async getPricingItem(id: string) {
+ return this._request(`/quotes/public/pricing_items/${id}`);
+ }
+
+ async getQuoteFileDetails(quoteId: string, fileId: string) {
+ return this._request(`/quotes/public/${quoteId}/files/${fileId}`);
+ }
+
+ async getPricingItemQuantity(id: string) {
+ return this._request(`/quotes/public/pricing_item_quantities/${id}`);
+ }
+
+ async _request<T extends object>(
+ path: string,
+ args?: {
+ method?:
+ | "GET"
+ | "POST"
+ | "PUT"
+ | "DELETE"
+ | "get"
+ | "post"
+ | "put"
+ | "delete";
+ body?: any;
+ }
+ ): Promise<PaperlessPartsResponse<T>> {
+ const response = await fetch(`${this.baseUrl}${path}`, {
+ method: args?.method ?? "GET",
+ headers: {
+ Authorization: `API-Token ${this.apiKey}`,
+ "Content-Type": "application/json",
+ },
+ ...(args?.body && { body: JSON.stringify(args.body) }),
+ });
+
+ if (!response.ok) {
+ return { data: null, error: response.statusText };
+ }
+
+ try {
+ const data = await response.json();
+ if ("text/plain" in data?.content) {
+ return {
+ data: null,
+ error: data.content["text/plain"]?.schema?.title ?? "Unknown error",
+ };
+ }
+
+ return {
+ data: data?.content?.["application/json"]?.schema ?? {},
+ error: null,
+ };
+ } catch (error) {
+ return { data: null, error: "Failed to parse JSON response" };
+ }
+ }
+}
diff --git a/apps/carbon/app/integrations/types.ts b/apps/carbon/app/integrations/types.ts
index 160caf2ec4..a5186a9a4b 100644
--- a/apps/carbon/app/integrations/types.ts
+++ b/apps/carbon/app/integrations/types.ts
@@ -7,7 +7,8 @@ export type IntegrationConfig = {
category: string;
logo: React.FC<React.ComponentProps<"svg">>;
shortDescription: string;
- description: string | null;
+ description: string;
+ setupInstructions?: React.FC<{ companyId: string }>;
images: string[];
settings: {
name: string;
diff --git a/apps/carbon/app/modules/purchasing/ui/Supplier/SuppliersTable.tsx b/apps/carbon/app/modules/purchasing/ui/Supplier/SuppliersTable.tsx
index a2c6ce8176..e06373ac01 100644
--- a/apps/carbon/app/modules/purchasing/ui/Supplier/SuppliersTable.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/Supplier/SuppliersTable.tsx
@@ -230,7 +230,7 @@ const SuppliersTable = memo(
];
return [...defaultColumns, ...customColumns];
- }, [people, supplierStatuses, customColumns]);
+ }, [supplierStatuses, people, tags, customColumns]);
const renderContextMenu = useMemo(
// eslint-disable-next-line react/display-name
diff --git a/apps/carbon/app/modules/settings/ui/Integrations/IntegrationForm.tsx b/apps/carbon/app/modules/settings/ui/Integrations/IntegrationForm.tsx
index 6864c559d0..4d9dd4ac62 100644
--- a/apps/carbon/app/modules/settings/ui/Integrations/IntegrationForm.tsx
+++ b/apps/carbon/app/modules/settings/ui/Integrations/IntegrationForm.tsx
@@ -15,7 +15,7 @@ import {
} from "@carbon/react";
import { SUPPORT_EMAIL } from "@carbon/utils";
import { useParams } from "@remix-run/react";
-import { usePermissions } from "~/hooks";
+import { usePermissions, useUser } from "~/hooks";
import { integrations as availableIntegrations } from "~/integrations";
import { path } from "~/utils/path";
@@ -32,6 +32,9 @@ export function IntegrationForm({
}: IntegrationFormProps) {
const permissions = usePermissions();
const isDisabled = !permissions.can("update", "settings");
+ const {
+ company: { id: companyId },
+ } = useUser();
const { id: integrationId } = useParams();
if (!integrationId) {
@@ -77,7 +80,7 @@ export function IntegrationForm({
{installed && <Badge variant="green">Installed</Badge>}
</div>
- <span className="text-xs text-[#878787]">
+ <span className="text-xs text-[#878787] text-right">
<Badge variant="secondary">{integration.category}</Badge> •
Published by CarbonOS
</span>
@@ -85,12 +88,19 @@ export function IntegrationForm({
</VStack>
</DrawerHeader>
<DrawerBody>
- <ScrollArea className="h-[calc(100dvh-240px)]">
- <VStack spacing={2}>
+ <ScrollArea className="h-[calc(100dvh-240px)] -mx-2">
+ <VStack spacing={4} className="px-2">
<Heading size="h3">How it works</Heading>
- <p className="text-sm text-muted-foreground">
+ <div className="text-sm text-muted-foreground">
{integration.description}
- </p>
+ </div>
+
+ {integration.setupInstructions && (
+ <>
+ <Heading size="h3">Setup Instructions</Heading>
+ <integration.setupInstructions companyId={companyId} />
+ </>
+ )}
{integration.settings.map((setting) => {
switch (setting.type) {
@@ -120,7 +130,7 @@ export function IntegrationForm({
</ScrollArea>
<p className="text-sm text-muted-foreground">
Carbon Manufacturing Systems does not endorse any third-party
- software.Report any concerns about app content or behavior.
+ software. Report any concerns about app content or behavior.
</p>
<a
diff --git a/apps/carbon/app/routes/api+/webhook.paperless-parts.$companyId.ts b/apps/carbon/app/routes/api+/webhook.paperless-parts.$companyId.ts
new file mode 100644
index 0000000000..4ab37278e6
--- /dev/null
+++ b/apps/carbon/app/routes/api+/webhook.paperless-parts.$companyId.ts
@@ -0,0 +1,91 @@
+import { getCarbonServiceRole } from "@carbon/auth";
+import { tasks } from "@trigger.dev/sdk/v3";
+import { json, type ActionFunctionArgs } from "@vercel/remix";
+import crypto from "crypto";
+import { z } from "zod";
+import { getIntegration } from "~/modules/settings/settings.service";
+import type { paperlessPartsTask } from "~/trigger/paperless-parts";
+
+export const config = {
+ runtime: "nodejs",
+};
+
+const integrationValidator = z.object({
+ apiKey: z.string(),
+ secretKey: z.string(),
+});
+
+function createHmacSignature(
+ requestPayload: string,
+ signingSecret: string,
+ timestamp: number
+): string {
+ const message = `${timestamp}.${requestPayload}`;
+ const messageBytes = Buffer.from(message);
+ const signingSecretBytes = Buffer.from(signingSecret, "hex");
+
+ return crypto
+ .createHmac("sha256", signingSecretBytes)
+ .update(messageBytes)
+ .digest("hex");
+}
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ const { companyId } = params;
+ if (!companyId) {
+ return json({ success: false }, { status: 400 });
+ }
+
+ const serviceRole = await getCarbonServiceRole();
+ const paperlessPartsIntegration = await getIntegration(
+ serviceRole,
+ companyId,
+ "paperless-parts"
+ );
+
+ if (paperlessPartsIntegration.error || !paperlessPartsIntegration.data) {
+ return json({ success: false }, { status: 400 });
+ }
+
+ try {
+ const { apiKey, secretKey } = integrationValidator.parse(
+ paperlessPartsIntegration.data
+ );
+
+ const payloadText = await request.text();
+ const signatureHeader = request.headers.get("Paperless-Parts-Signature");
+
+ if (!signatureHeader) {
+ return json({ success: false }, { status: 401 });
+ }
+
+ // Parse timestamp and signature from header
+ const [timestampPart, signaturePart] = signatureHeader.split(",");
+ const timestamp = Number(timestampPart.replace("t=", ""));
+ const signature = signaturePart.replace("v1=", "");
+
+ if (!timestamp || !signature) {
+ return json({ success: false }, { status: 401 });
+ }
+
+ const expectedSignature = createHmacSignature(
+ payloadText,
+ secretKey,
+ timestamp
+ );
+
+ if (signature !== expectedSignature) {
+ return json({ success: false }, { status: 401 });
+ }
+
+ await tasks.trigger<typeof paperlessPartsTask>("paperless-parts", {
+ apiKey,
+ companyId,
+ payload: JSON.parse(payloadText),
+ });
+
+ return json({ success: true });
+ } catch (err) {
+ return json({ success: false }, { status: 500 });
+ }
+}
diff --git a/apps/carbon/app/routes/x+/settings+/_layout.tsx b/apps/carbon/app/routes/x+/settings+/_layout.tsx
index b8030216ed..f49f4429e5 100644
--- a/apps/carbon/app/routes/x+/settings+/_layout.tsx
+++ b/apps/carbon/app/routes/x+/settings+/_layout.tsx
@@ -36,7 +36,10 @@ export default function SettingsRoute() {
<CollapsibleSidebarProvider>
<div className="grid grid-cols-[auto_1fr] w-full h-full">
<GroupedContentSidebar groups={groups} />
- <VStack spacing={0} className="h-full">
+ <VStack
+ spacing={0}
+ className="overflow-y-auto scrollbar-hide h-[calc(100dvh-49px)]"
+ >
<Outlet />
</VStack>
</div>
diff --git a/apps/carbon/app/routes/x+/settings+/integrations.tsx b/apps/carbon/app/routes/x+/settings+/integrations.tsx
index 50b94362df..a3a48b606a 100644
--- a/apps/carbon/app/routes/x+/settings+/integrations.tsx
+++ b/apps/carbon/app/routes/x+/settings+/integrations.tsx
@@ -37,7 +37,9 @@ export default function IntegrationsRoute() {
<>
<IntegrationsList
installedIntegrations={installedIntegrations}
- availableIntegrations={availableIntegrations}
+ availableIntegrations={availableIntegrations.filter(
+ (i) => i.id !== "paperless-parts"
+ )}
/>
<Outlet />
</>
diff --git a/apps/carbon/app/trigger/paperless-parts.ts b/apps/carbon/app/trigger/paperless-parts.ts
new file mode 100644
index 0000000000..de0d9d0315
--- /dev/null
+++ b/apps/carbon/app/trigger/paperless-parts.ts
@@ -0,0 +1,138 @@
+import { task } from "@trigger.dev/sdk/v3";
+import { z } from "zod";
+
+import { getCarbonServiceRole } from "@carbon/auth";
+import { PaperlessPartsClient } from "~/integrations/paperless-parts/lib/client";
+import type { Result } from "~/types";
+
+const payloadSchema = z.discriminatedUnion("type", [
+ z.object({
+ type: z.literal("quote.created"),
+ data: z.any(),
+ }),
+ z.object({
+ type: z.literal("quote.status_changed"),
+ data: z.any(),
+ }),
+ z.object({
+ type: z.literal("quote.sent"),
+ data: z.any(),
+ }),
+ z.object({
+ type: z.literal("order.created"),
+ data: z.any(),
+ }),
+ z.object({
+ type: z.literal("order.status_changed"),
+ data: z.any(),
+ }),
+ z.object({
+ type: z.literal("integration_action.requested"),
+ data: z.any(),
+ }),
+ z.object({
+ type: z.literal("integration.turned_on"),
+ data: z.any(),
+ }),
+ z.object({
+ type: z.literal("integration.turned_off"),
+ data: z.any(),
+ }),
+]);
+
+const paperlessPartsSchema = z.object({
+ apiKey: z.string(),
+ companyId: z.string(),
+ payload: payloadSchema,
+});
+
+export const paperlessPartsTask = task({
+ id: "paperless-parts",
+ run: async (payload: z.infer<typeof paperlessPartsSchema>) => {
+ let result: Result;
+
+ console.info(
+ `🔰 Paperless Parts webhook received: ${payload.payload.type}`
+ );
+ console.info(`📦 Payload:`, payload);
+
+ const carbon = getCarbonServiceRole();
+ const paperless = new PaperlessPartsClient(payload.apiKey);
+
+ switch (payload.payload.type) {
+ case "quote.created":
+ console.info(`📫 Processing quote created event`);
+ result = {
+ success: true,
+ message: "Quote created event processed successfully",
+ };
+ break;
+ case "quote.status_changed":
+ console.info(`📫 Processing quote status changed event`);
+ result = {
+ success: true,
+ message: "Quote status changed event processed successfully",
+ };
+ break;
+ case "quote.sent":
+ console.info(`📫 Processing quote sent event`);
+ result = {
+ success: true,
+ message: "Quote sent event processed successfully",
+ };
+ break;
+ case "order.created":
+ console.info(`📫 Processing order created event`);
+ result = {
+ success: true,
+ message: "Order created event processed successfully",
+ };
+ break;
+ case "order.status_changed":
+ console.info(`📫 Processing order status changed event`);
+ result = {
+ success: true,
+ message: "Order status changed event processed successfully",
+ };
+ break;
+ case "integration_action.requested":
+ console.info(`📫 Processing integration action requested event`);
+ result = {
+ success: true,
+ message: "Integration action requested event processed successfully",
+ };
+ break;
+ case "integration.turned_on":
+ console.info(`📫 Processing integration turned on event`);
+ result = {
+ success: true,
+ message: "Integration turned on event processed successfully",
+ };
+ break;
+ case "integration.turned_off":
+ console.info(`📫 Processing integration turned off event`);
+ result = {
+ success: true,
+ message: "Integration turned off event processed successfully",
+ };
+ break;
+ default:
+ console.error(`❌ Unsupported event type: ${payload.payload}`);
+ result = {
+ success: false,
+ message: `Unsupported event type`,
+ };
+ break;
+ }
+
+ if (result.success) {
+ console.info(`✅ Successfully processed ${payload.payload.type} event`);
+ } else {
+ console.error(
+ `❌ Failed to process ${payload.payload.type} event: ${result.message}`
+ );
+ }
+
+ return result;
+ },
+});
diff --git a/packages/database/supabase/migrations/20241217161338_paperless-parts-integration.sql b/packages/database/supabase/migrations/20241217161338_paperless-parts-integration.sql
new file mode 100644
index 0000000000..9af23674a7
--- /dev/null
+++ b/packages/database/supabase/migrations/20241217161338_paperless-parts-integration.sql
@@ -0,0 +1,3 @@
+INSERT INTO "integration" ("id", "jsonschema")
+VALUES
+ ('paperless-parts', '{"type": "object", "properties": {"apiKey": {"type": "string"}, "secretKey": {"type": "string"}}, "required": ["apiKey", "secretKey"]}'::json);
\ No newline at end of file