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
Merge branch 'main' into feat/add-quantity-price-breaks
Gaurav Bhattcd7b97dd88fa
diff --cc apps/erp/app/components/Icons.tsxindex c3b11d82d0,29f9641715..8c1ffb2c49--- a/apps/erp/app/components/Icons.tsx+++ b/apps/erp/app/components/Icons.tsx@@@ -478,3 -478,68 +478,80 @@@ export const LinearIssueStateBadge = (p</Badge>);};++ export const JiraIcon = (props: React.SVGProps<SVGSVGElement>) => {+ return (+ <svg+ xmlns="http://www.w3.org/2000/svg"+ viewBox="0 0 65 65"+ fill="currentColor"+ className={props.className}+ {...props}+ >+ <defs>- <linearGradient id="jira-gradient-1" x1="98.03%" y1="0.16%" x2="58.89%" y2="40.53%">++ <linearGradient++ id="jira-gradient-1"++ x1="98.03%"++ y1="0.16%"++ x2="58.89%"++ y2="40.53%"++ >+ <stop offset="0.18" stopColor="currentColor" stopOpacity="0.4" />+ <stop offset="1" stopColor="currentColor" />+ </linearGradient>- <linearGradient id="jira-gradient-2" x1="100.17%" y1="0.05%" x2="55.99%" y2="44.23%">++ <linearGradient++ id="jira-gradient-2"++ x1="100.17%"++ y1="0.05%"++ x2="55.99%"++ y2="44.23%"++ >+ <stop offset="0.18" stopColor="currentColor" stopOpacity="0.4" />+ <stop offset="1" stopColor="currentColor" />+ </linearGradient>+ </defs>+ <path+ d="M62.75 30.02L35.58 2.85 32.5 0 12.77 19.73 1.25 31.25a1.69 1.69 0 0 0 0 2.39L20 52.11l12.5 12.5 19.73-19.73.62-.62 9.9-9.9a1.69 1.69 0 0 0 0-2.34zM32.5 42.15l-9.65-9.65 9.65-9.65 9.65 9.65z"+ fill="currentColor"+ />+ <path+ d="M32.5 22.85A13.85 13.85 0 0 1 32.4 3L12.65 22.77l9.85 9.85z"+ fill="url(#jira-gradient-1)"+ />+ <path+ d="M42.17 32.48L32.5 42.15a13.86 13.86 0 0 1 0 19.6l19.77-19.75z"+ fill="url(#jira-gradient-2)"+ />+ </svg>+ );+ };++ export const JiraIssueStatusBadge = (props: {+ status: { name: string; category: "new" | "indeterminate" | "done" };+ className?: string;+ }) => {+ let className = props.className;++ let icon: React.ReactNode = (+ <LuCircleDashed className={cn("text-foreground", className)} />+ );++ switch (props.status.category) {+ case "new":+ icon = <LuCircleDashed className={cn("text-foreground", className)} />;+ break;+ case "indeterminate":+ icon = <AlmostDoneIcon className={className} />;+ break;+ case "done":+ icon = <LuCircleCheck className={cn("text-emerald-600", className)} />;+ break;+ }++ return (+ <Badge variant={"secondary"} className="py-1 bg-transparent">+ {icon}+ <span className="ml-1">{props.status.name}</span>+ </Badge>+ );+ };diff --cc packages/ee/src/jira/lib/richtext.tsindex 0000000000,a0a437193a..26e3341f9amode 000000,100644..100644--- a/packages/ee/src/jira/lib/richtext.ts+++ b/packages/ee/src/jira/lib/richtext.ts@@@ -1,0 -1,344 +1,404 @@@+ /**+ * Utilities for bidirectional conversion between Atlassian Document Format (ADF)+ * and Tiptap JSON (Carbon's rich text format).+ *+ * Jira Cloud uses ADF for rich text fields like description.+ * Carbon uses Tiptap/ProseMirror JSON for rich text editing.+ *+ * ADF documentation: https://developer.atlassian.com/cloud/jira/platform/apis/document/structure/+ */++ // Tiptap (ProseMirror) JSON format+ export type TiptapNode = {+ type: string;+ attrs?: Record<string, any>;+ content?: TiptapNode[];+ text?: string;+ marks?: { type: string; attrs?: Record<string, any> }[];+ };++ export type TiptapDocument = {+ type: "doc";+ content: TiptapNode[];+ };++ // ADF (Atlassian Document Format) types+ export type ADFNode = {+ type: string;+ attrs?: Record<string, any>;+ content?: ADFNode[];+ text?: string;+ marks?: { type: string; attrs?: Record<string, any> }[];+ };++ export type ADFDocument = {+ version: 1;+ type: "doc";+ content: ADFNode[];+ };++ /**+ * Convert ADF (Atlassian Document Format) to Tiptap JSON.+ * Used when syncing from Jira → Carbon.+ */-export function adfToTiptap(adf: ADFDocument | null | undefined): TiptapDocument {++export function adfToTiptap(++ adf: ADFDocument | null | undefined++): TiptapDocument {+ if (!adf || !adf.content || adf.content.length === 0) {+ return { type: "doc", content: [{ type: "paragraph" }] };+ }+- const content = adf.content.map(convertADFNodeToTiptap).filter(Boolean) as TiptapNode[];++ const content = adf.content++ .map(convertADFNodeToTiptap)++ .filter(Boolean) as TiptapNode[];++ if (content.length === 0) {+ return { type: "doc", content: [{ type: "paragraph" }] };+ }++ return { type: "doc", content };+ }++ function convertADFNodeToTiptap(node: ADFNode): TiptapNode | null {+ switch (node.type) {+ case "paragraph":+ return {+ type: "paragraph",- content: node.content?.map(convertADFNodeToTiptap).filter(Boolean) as TiptapNode[] || []++ content:++ (node.content++ ?.map(convertADFNodeToTiptap)++ .filter(Boolean) as TiptapNode[]) || []+ };++ case "heading":+ return {+ type: "heading",+ attrs: { level: node.attrs?.level ?? 1 },- content: node.content?.map(convertADFNodeToTiptap).filter(Boolean) as TiptapNode[] || []++ content:++ (node.content++ ?.map(convertADFNodeToTiptap)++ .filter(Boolean) as TiptapNode[]) || []+ };++ case "bulletList":+ return {+ type: "bulletList",- content: node.content?.map(convertADFNodeToTiptap).filter(Boolean) as TiptapNode[] || []++ content:++ (node.content++ ?.map(convertADFNodeToTiptap)++ .filter(Boolean) as TiptapNode[]) || []+ };++ case "orderedList":+ return {+ type: "orderedList",- content: node.content?.map(convertADFNodeToTiptap).filter(Boolean) as TiptapNode[] || []++ content:++ (node.content++ ?.map(convertADFNodeToTiptap)++ .filter(Boolean) as TiptapNode[]) || []+ };++ case "listItem":+ return {+ type: "listItem",- content: node.content?.map(convertADFNodeToTiptap).filter(Boolean) as TiptapNode[] || []++ content:++ (node.content++ ?.map(convertADFNodeToTiptap)++ .filter(Boolean) as TiptapNode[]) || []+ };++ case "blockquote":+ return {+ type: "blockquote",- content: node.content?.map(convertADFNodeToTiptap).filter(Boolean) as TiptapNode[] || []++ content:++ (node.content++ ?.map(convertADFNodeToTiptap)++ .filter(Boolean) as TiptapNode[]) || []+ };++ case "codeBlock":+ return {+ type: "codeBlock",- attrs: node.attrs?.language ? { language: node.attrs.language } : undefined,- content: node.content?.map(convertADFNodeToTiptap).filter(Boolean) as TiptapNode[] || []++ attrs: node.attrs?.language++ ? { language: node.attrs.language }++ : undefined,++ content:++ (node.content++ ?.map(convertADFNodeToTiptap)++ .filter(Boolean) as TiptapNode[]) || []+ };++ case "rule":+ return { type: "horizontalRule" };++ case "hardBreak":+ return { type: "hardBreak" };++ case "text":+ return {+ type: "text",+ text: node.text ?? "",- marks: node.marks?.map(convertADFMarkToTiptap).filter(Boolean) as TiptapNode["marks"]++ marks: node.marks++ ?.map(convertADFMarkToTiptap)++ .filter(Boolean) as TiptapNode["marks"]+ };++ case "mention":+ // Convert Jira mentions to plain text+ return {+ type: "text",+ text: node.attrs?.text || "@mention"+ };++ case "emoji":+ return {+ type: "text",+ text: node.attrs?.shortName || node.attrs?.text || ""+ };++ case "inlineCard":+ case "blockCard":+ // Convert Jira cards to links+ return {+ type: "text",+ text: node.attrs?.url || "",+ marks: node.attrs?.url+ ? [{ type: "link", attrs: { href: node.attrs.url } }]+ : undefined+ };++ case "mediaGroup":+ case "mediaSingle":+ // Skip media for now - could be enhanced to handle attachments+ return null;++ case "table":+ case "tableRow":+ case "tableCell":+ case "tableHeader":+ // Tables are complex - skip for now+ return null;++ default:+ // For unknown types, try to extract text content+ if (node.content) {+ return {+ type: "paragraph",- content: node.content.map(convertADFNodeToTiptap).filter(Boolean) as TiptapNode[]++ content: node.content++ .map(convertADFNodeToTiptap)++ .filter(Boolean) as TiptapNode[]+ };+ }+ return null;+ }+ }++ function convertADFMarkToTiptap(+ mark: NonNullable<ADFNode["marks"]>[number]+ ): NonNullable<TiptapNode["marks"]>[number] | null {+ switch (mark.type) {+ case "strong":+ return { type: "bold" };+ case "em":+ return { type: "italic" };+ case "strike":+ return { type: "strike" };+ case "code":+ return { type: "code" };+ case "link":+ return { type: "link", attrs: { href: mark.attrs?.href } };+ case "underline":+ return { type: "underline" };+ case "textColor":+ return { type: "textStyle", attrs: { color: mark.attrs?.color } };+ case "subsup":+ // Subscript/superscript - map to appropriate type or skip+ return null;+ default:+ return null;+ }+ }++ /**+ * Convert Tiptap JSON to ADF (Atlassian Document Format).+ * Used when syncing from Carbon → Jira.+ */-export function tiptapToAdf(tiptapDoc: TiptapDocument | null | undefined): ADFDocument {++export function tiptapToAdf(++ tiptapDoc: TiptapDocument | null | undefined++): ADFDocument {+ if (!tiptapDoc || !tiptapDoc.content || tiptapDoc.content.length === 0) {+ return {+ version: 1,+ type: "doc",+ content: [{ type: "paragraph", content: [] }]+ };+ }+- const content = tiptapDoc.content.map(convertTiptapNodeToADF).filter(Boolean) as ADFNode[];++ const content = tiptapDoc.content++ .map(convertTiptapNodeToADF)++ .filter(Boolean) as ADFNode[];++ if (content.length === 0) {+ return {+ version: 1,+ type: "doc",+ content: [{ type: "paragraph", content: [] }]+ };+ }++ return { version: 1, type: "doc", content };+ }++ function convertTiptapNodeToADF(node: TiptapNode): ADFNode | null {+ switch (node.type) {+ case "paragraph":+ return {+ type: "paragraph",- content: node.content?.map(convertTiptapNodeToADF).filter(Boolean) as ADFNode[] || []++ content:++ (node.content++ ?.map(convertTiptapNodeToADF)++ .filter(Boolean) as ADFNode[]) || []+ };++ case "heading":+ return {+ type: "heading",+ attrs: { level: node.attrs?.level ?? 1 },- content: node.content?.map(convertTiptapNodeToADF).filter(Boolean) as ADFNode[] || []++ content:++ (node.content++ ?.map(convertTiptapNodeToADF)++ .filter(Boolean) as ADFNode[]) || []+ };++ case "bulletList":+ return {+ type: "bulletList",- content: node.content?.map(convertTiptapNodeToADF).filter(Boolean) as ADFNode[] || []++ content:++ (node.content++ ?.map(convertTiptapNodeToADF)++ .filter(Boolean) as ADFNode[]) || []+ };++ case "orderedList":+ return {+ type: "orderedList",- content: node.content?.map(convertTiptapNodeToADF).filter(Boolean) as ADFNode[] || []++ content:++ (node.content++ ?.map(convertTiptapNodeToADF)++ .filter(Boolean) as ADFNode[]) || []+ };++ case "listItem":+ return {+ type: "listItem",- content: node.content?.map(convertTiptapNodeToADF).filter(Boolean) as ADFNode[] || []++ content:++ (node.content++ ?.map(convertTiptapNodeToADF)++ .filter(Boolean) as ADFNode[]) || []+ };++ case "blockquote":+ return {+ type: "blockquote",- content: node.content?.map(convertTiptapNodeToADF).filter(Boolean) as ADFNode[] || []++ content:++ (node.content++ ?.map(convertTiptapNodeToADF)++ .filter(Boolean) as ADFNode[]) || []+ };++ case "codeBlock":+ return {+ type: "codeBlock",+ attrs: node.attrs?.language ? { language: node.attrs.language } : {},- content: node.content?.map(convertTiptapNodeToADF).filter(Boolean) as ADFNode[] || []++ content:++ (node.content++ ?.map(convertTiptapNodeToADF)++ .filter(Boolean) as ADFNode[]) || []+ };++ case "horizontalRule":+ return { type: "rule" };++ case "hardBreak":+ return { type: "hardBreak" };++ case "text":+ return {+ type: "text",+ text: node.text ?? "",- marks: node.marks?.map(convertTiptapMarkToADF).filter(Boolean) as ADFNode["marks"]++ marks: node.marks++ ?.map(convertTiptapMarkToADF)++ .filter(Boolean) as ADFNode["marks"]+ };++ default:+ // For unknown types, try to extract text content+ if (node.content) {+ return {+ type: "paragraph",- content: node.content.map(convertTiptapNodeToADF).filter(Boolean) as ADFNode[]++ content: node.content++ .map(convertTiptapNodeToADF)++ .filter(Boolean) as ADFNode[]+ };+ }+ return null;+ }+ }++ function convertTiptapMarkToADF(+ mark: NonNullable<TiptapNode["marks"]>[number]+ ): NonNullable<ADFNode["marks"]>[number] | null {+ switch (mark.type) {+ case "bold":+ return { type: "strong" };+ case "italic":+ return { type: "em" };+ case "strike":+ return { type: "strike" };+ case "code":+ return { type: "code" };+ case "link":+ return { type: "link", attrs: { href: mark.attrs?.href } };+ case "underline":+ return { type: "underline" };+ case "textStyle":+ if (mark.attrs?.color) {+ return { type: "textColor", attrs: { color: mark.attrs.color } };+ }+ return null;+ default:+ return null;+ }+ }++ /**+ * Check if two Tiptap documents have the same content.+ * Used to prevent unnecessary syncs when content hasn't changed.+ */+ export function tiptapDocumentsEqual(+ a: TiptapDocument | null | undefined,+ b: TiptapDocument | null | undefined+ ): boolean {+ if (!a && !b) return true;+ if (!a || !b) return false;++ return JSON.stringify(a) === JSON.stringify(b);+ }++ /**+ * Check if a Tiptap document is empty (no meaningful content).+ */+ export function isTiptapEmpty(doc: TiptapDocument | null | undefined): boolean {+ if (!doc || !doc.content) return true;++ const hasContent = doc.content.some((node) => {+ if (node.type === "paragraph" && node.content) {+ return node.content.some(+ (inline) => inline.type === "text" && inline.text?.trim()+ );+ }+ return node.content && node.content.length > 0;+ });++ return !hasContent;+ }diff --cc packages/ee/src/notifications/services/jira.tsindex 0000000000,ca14395716..206765bd14mode 000000,100644..100644--- a/packages/ee/src/notifications/services/jira.ts+++ b/packages/ee/src/notifications/services/jira.ts@@@ -1,0 -1,107 +1,107 @@@+ import { getUser } from "@carbon/auth";+ import type { Database } from "@carbon/database";+ import type { SupabaseClient } from "@supabase/supabase-js";-import type { TiptapDocument } from "../../jira/lib/richtext";+ import {+ getJiraClient,+ getJiraIssueFromExternalId,+ mapCarbonStatusToJiraCategory,+ tiptapToAdf+ } from "../../jira/lib";++import type { TiptapDocument } from "../../jira/lib/richtext";+ import type { NotificationEvent, NotificationService } from "../types";++ const jira = getJiraClient();++ /**+ * Jira Notification Service+ * Updates Jira issues based on Carbon notification events+ */+ export class JiraNotificationService implements NotificationService {+ id = "jira";+ name = "Jira";++ async send(+ event: NotificationEvent,+ context: { serviceRole: SupabaseClient<Database> }+ ): Promise<void> {+ switch (event.type) {+ case "task.status.changed": {+ if (!["action", "investigation"].includes(event.data.type)) return;++ const issue = await getJiraIssueFromExternalId(+ context.serviceRole,+ event.companyId,+ event.data.id+ );++ if (!issue) return;++ const targetCategory = mapCarbonStatusToJiraCategory(event.data.status);++ await jira.transitionIssue(event.companyId, issue.id, targetCategory);++ break;+ }++ case "task.assigned": {+ if (event.data.table !== "nonConformanceActionTask") return;++ const issue = await getJiraIssueFromExternalId(+ context.serviceRole,+ event.companyId,+ event.data.id+ );++ if (!issue) return; // No linked Jira issue++ const { data: user } = await getUser(+ context.serviceRole,+ event.data.assignee+ );++ if (!user) return; // No assignee user++ // Find the Jira user by email+ const jiraUser = await jira.findUserByEmail(+ event.companyId,+ user.email+ );++ if (!jiraUser) return;++ await jira.updateIssue(event.companyId, issue.id, {+ assigneeId: jiraUser.accountId+ });+ break;+ }++ case "task.notes.changed": {+ if (event.data.table !== "nonConformanceActionTask") return;++ const issue = await getJiraIssueFromExternalId(+ context.serviceRole,+ event.companyId,+ event.data.id+ );++ if (!issue) return; // No linked Jira issue++ // Convert Tiptap notes to ADF for Jira+ const notes = event.data.notes as TiptapDocument | null | undefined;+ if (!notes) return;++ try {+ const description = tiptapToAdf(notes);++ await jira.updateIssue(event.companyId, issue.id, {+ description+ });+ } catch (e) {+ console.error("Failed to sync notes to Jira:", e);+ }+ break;+ }+ }+ return;+ }+ }