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: move edition enum to utils
Brad Barbin274ba5ef9c26
diff --git a/README.md b/README.mdindex e635335aba..25bf8ee10a 100644--- a/README.md+++ b/README.md@@ -4,6 +4,8 @@ Carbon is the open-source operating system for manufacturing.## Architecture+Carbon is designed to make it easy for you to extend the platform by building your own apps through our API.+Features:@@ -82,52 +84,21 @@ The monorepo follows the Turborepo convention of grouping packages into one of t| `@carbon/tsconfig` | Shared, extendable tsconfig configuration used across apps and packages || `@carbon/utils` | Shared utility functions used across apps and packages |-## API--The API documentation is located in the ERP app at `/x/api/js/intro`. It is auto-generated based on changes to the database.+## Development-### From another Codebase+### Setup-Navigate to settings in the ERP to generate an API key. If you're self-hosting you can also use the supabase service key instead of the public key for root access. In that case you don't needto include the `carbon-key` header.+1. Clone the repo into a public GitHub repository (or fork https://github.com/crbnos/carbon/fork). If you plan to distribute the code, keep the source code public to comply with [AGPLv3](https://github.com/crbnos/carbon/blob/main/LICENSE). To clone in a private repository, [acquire a commercial license](https://carbon.ms/sales)-```ts-import { Database } from "@carbon/database";-import { createClient } from "@supabase/supabase-js";--const apiKey = process.env.CARBON_API_KEY;-const apiUrl = process.env.CARBON_API_URL;-const publicKey = process.env.CARBON_PUBLIC_KEY;+ ```sh+ git clone https://github.com/crbnos/carbon.git+ ```-const carbon = createClient<Database>(apiUrl, publicKey, {- global: {- headers: {- "carbon-key": apiKey,- },- },-});+2. Go to the project folder-// returns items from the company associated with the api key-const { data, error } = await carbon.from("item").select("*");-```--### From the Monorepo--```tsx-import { getCarbonServiceRole } from "@carbon/auth";-const carbon = getCarbonServiceRole();--// returns all items across companies-const { data, error } = await carbon.from("item").select("*");--// returns items from a specific company-const companyId = "xyz";-const { data, error } = await carbon- .from("item")- .select("*")- .eq("companyId", companyId);-```--## Local Development+ ```sh+ cd carbon+ ```Make sure that you have [Docker installed](https://docs.docker.com/desktop/install/mac-install/) on your system since this monorepo uses the Docker for local development.@@ -236,16 +207,60 @@ For example, to run test command in the `@carbon/react` package you can run:$ npm run test -w @carbon/react```-### Restoring a Production Database Locally+## API-1. Download the production database backup from Supabase-2. Rename the migrations folder to `_migrations`-3. Restore the database using the following command:+The API documentation is located in the ERP app at `${ERP}/x/api/js/intro`. It is auto-generated based on changes to the database.-```bash-$ npm run db:build # this should error out at the seed step-PGPASSWORD=postgres psql -h localhost -p 54322 -U supabase_admin -d postgres < ~/Downloads/[email protected]-$ npm run dev+There are two ways to use the API:++1. From another codebase using a supabase client library:++- [Javascript](https://supabase.com/docs/reference/javascript/introduction)+- [Flutter](https://supabase.com/docs/reference/dart/introduction)+- [Python](https://supabase.com/docs/reference/python/introduction)+- [C#](https://supabase.com/docs/reference/csharp/introduction)+- [Swift](https://supabase.com/docs/reference/swift/introduction)+- [Kotlin](https://supabase.com/docs/reference/kotlin/introduction)++2. From within the codebase using our packages.++### From another Codebase++Navigate to settings in the ERP to generate an API key. If you're self-hosting you can also use the supabase service key instead of the public key for root access. In that case you don't needto include the `carbon-key` header.++```ts+import { Database } from "@carbon/database";+import { createClient } from "@supabase/supabase-js";++const apiKey = process.env.CARBON_API_KEY;+const apiUrl = process.env.CARBON_API_URL;+const publicKey = process.env.CARBON_PUBLIC_KEY;++const carbon = createClient<Database>(apiUrl, publicKey, {+ global: {+ headers: {+ "carbon-key": apiKey,+ },+ },+});++// returns items from the company associated with the api key+const { data, error } = await carbon.from("item").select("*");```-4. Rename the `_migrations` folder back to `migrations`+### From the Monorepo++```tsx+import { getCarbonServiceRole } from "@carbon/auth";+const carbon = getCarbonServiceRole();++// returns all items across companies+const { data, error } = await carbon.from("item").select("*");++// returns items from a specific company+const companyId = "xyz";+const { data, error } = await carbon+ .from("item")+ .select("*")+ .eq("companyId", companyId);+```diff --git a/apps/erp/app/hooks/useFlags.tsx b/apps/erp/app/hooks/useFlags.tsxindex 0f1a9c176f..5bcf28aee6 100644--- a/apps/erp/app/hooks/useFlags.tsx+++ b/apps/erp/app/hooks/useFlags.tsx@@ -1,5 +1,5 @@-import { Edition } from "@carbon/auth";import { useEdition } from "@carbon/remix";+import { Edition } from "@carbon/utils";import { useUser } from "./useUser";export function useFlags() {diff --git a/apps/erp/app/routes/onboarding+/_layout.tsx b/apps/erp/app/routes/onboarding+/_layout.tsxindex b5dc4e1ee4..ee5bb42d73 100644--- a/apps/erp/app/routes/onboarding+/_layout.tsx+++ b/apps/erp/app/routes/onboarding+/_layout.tsx@@ -1,15 +1,15 @@+import { CarbonEdition } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";+import { VStack } from "@carbon/react";+import { getStripeCustomerByCompanyId } from "@carbon/stripe/stripe.server";+import { Edition } from "@carbon/utils";+import type { ShouldRevalidateFunction } from "@remix-run/react";import { Outlet } from "@remix-run/react";import { redirect, type LoaderFunctionArgs } from "@vercel/remix";import { getLocationsList } from "~/modules/resources";import { getCompany } from "~/modules/settings";import { onboardingSequence, path } from "~/utils/path";-import { CarbonEdition, Edition } from "@carbon/auth";-import { VStack } from "@carbon/react";-import { getStripeCustomerByCompanyId } from "@carbon/stripe/stripe.server";-import type { ShouldRevalidateFunction } from "@remix-run/react";-export const shouldRevalidate: ShouldRevalidateFunction = () => true;export const config = {diff --git a/apps/erp/app/routes/onboarding+/plan.tsx b/apps/erp/app/routes/onboarding+/plan.tsxindex cf6a8db6fe..f46ca9b596 100644--- a/apps/erp/app/routes/onboarding+/plan.tsx+++ b/apps/erp/app/routes/onboarding+/plan.tsx@@ -1,4 +1,4 @@-import { CarbonEdition, Edition, getUser } from "@carbon/auth";+import { CarbonEdition, getUser } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import {Badge,@@ -12,6 +12,7 @@ import {IconButton,} from "@carbon/react";import { getCheckoutUrl } from "@carbon/stripe/stripe.server";+import { Edition } from "@carbon/utils";import { useLocale } from "@react-aria/i18n";import { Form, useFetcher, useLoaderData } from "@remix-run/react";import { json, redirect, type ActionFunctionArgs } from "@vercel/remix";diff --git a/apps/erp/app/routes/x+/_layout.tsx b/apps/erp/app/routes/x+/_layout.tsxindex 63d741bbd4..a02dea14e4 100644--- a/apps/erp/app/routes/x+/_layout.tsx+++ b/apps/erp/app/routes/x+/_layout.tsx@@ -1,15 +1,11 @@-import {- CarbonEdition,- CarbonProvider,- Edition,- getCarbon,-} from "@carbon/auth";+import { CarbonEdition, CarbonProvider, getCarbon } from "@carbon/auth";import {destroyAuthSession,requireAuthSession,} from "@carbon/auth/session.server";import { Button, IconButton, TooltipProvider, useMount } from "@carbon/react";import { getStripeCustomerByCompanyId } from "@carbon/stripe/stripe.server";+import { Edition } from "@carbon/utils";import type { ShouldRevalidateFunction } from "@remix-run/react";import {Outlet,diff --git a/apps/erp/app/routes/x+/settings+/company.tsx b/apps/erp/app/routes/x+/settings+/company.tsxindex 90d8150635..3be21e3ed5 100644--- a/apps/erp/app/routes/x+/settings+/company.tsx+++ b/apps/erp/app/routes/x+/settings+/company.tsx@@ -1,4 +1,4 @@-import { assertIsPost, Edition, error, success } from "@carbon/auth";+import { assertIsPost, error, success } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import {@@ -21,6 +21,7 @@ import {VStack,} from "@carbon/react";import { useEdition } from "@carbon/remix";+import { Edition } from "@carbon/utils";import { Form, useLoaderData } from "@remix-run/react";import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";import { json } from "@vercel/remix";diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.tsindex b4037efd1e..792782e7dc 100644--- a/apps/erp/app/utils/path.ts+++ b/apps/erp/app/utils/path.ts@@ -18,6 +18,7 @@ export const path = {accountingSubcategories: (id: string) =>generatePath(`${api}/accounting/subcategories?accountCategoryId=${id}`),assign: `${api}/assign`,+ autodeskToken: `${api}/autodesk/token`,batchNumbers: (itemId: string) =>generatePath(`${api}/inventory/batch-numbers?itemId=${itemId}`),billOfMaterials: (methodId: string, withOperations: boolean = false) =>diff --git a/apps/mes/app/routes/x+/_layout.tsx b/apps/mes/app/routes/x+/_layout.tsxindex 2cab151abd..27ad1d0dc0 100644--- a/apps/mes/app/routes/x+/_layout.tsx+++ b/apps/mes/app/routes/x+/_layout.tsx@@ -1,7 +1,6 @@import {CarbonEdition,CarbonProvider,- Edition,getCarbon,getCompanies,getUser,@@ -12,6 +11,7 @@ import {} from "@carbon/auth/session.server";import { SidebarProvider, TooltipProvider, useMount } from "@carbon/react";import { getStripeCustomerByCompanyId } from "@carbon/stripe/stripe.server";+import { Edition } from "@carbon/utils";import type { ShouldRevalidateFunction } from "@remix-run/react";import { Outlet, useLoaderData, useNavigation } from "@remix-run/react";import type { LoaderFunctionArgs } from "@vercel/remix";diff --git a/packages/auth/src/config/env.ts b/packages/auth/src/config/env.tsindex ec5b67e3db..3112cb3a46 100644--- a/packages/auth/src/config/env.ts+++ b/packages/auth/src/config/env.ts@@ -1,4 +1,4 @@-import { isBrowser } from "@carbon/utils";+import { Edition, isBrowser } from "@carbon/utils";declare global {interface Window {@@ -36,12 +36,6 @@ declare global {}}-export enum Edition {- Cloud = "cloud",- Enterprise = "enterprise",- Community = "community",-}-type EnvOptions = {isSecret?: boolean;isRequired?: boolean;diff --git a/packages/remix/src/hooks/useEdition.tsx b/packages/remix/src/hooks/useEdition.tsxindex db6c0510b1..7a743f3e0a 100644--- a/packages/remix/src/hooks/useEdition.tsx+++ b/packages/remix/src/hooks/useEdition.tsx@@ -1,5 +1,5 @@-import { Edition } from "@carbon/auth";import { useRouteData } from "@carbon/remix";+import { Edition } from "@carbon/utils";export function useEdition() {const routeData = useRouteData<{ env: { CARBON_EDITION: Edition } }>("/");diff --git a/packages/stripe/src/stripe.server.ts b/packages/stripe/src/stripe.server.tsindex 55bf71babd..06019ce9e0 100644--- a/packages/stripe/src/stripe.server.ts+++ b/packages/stripe/src/stripe.server.ts@@ -1,11 +1,7 @@-import {- CarbonEdition,- Edition,- getAppUrl,- getCarbonServiceRole,-} from "@carbon/auth";+import { CarbonEdition, getAppUrl, getCarbonServiceRole } from "@carbon/auth";import type { Database } from "@carbon/database";import { redis } from "@carbon/kv";+import { Edition } from "@carbon/utils";import type { SupabaseClient } from "@supabase/supabase-js";import { tasks } from "@trigger.dev/sdk/v3";import { Stripe } from "stripe";diff --git a/packages/utils/src/types.ts b/packages/utils/src/types.tsindex f12fb6af88..ab549df6f0 100644--- a/packages/utils/src/types.ts+++ b/packages/utils/src/types.ts@@ -1,5 +1,11 @@import { z } from "zod";+export enum Edition {+ Cloud = "cloud",+ Enterprise = "enterprise",+ Community = "community",+}+export type Mode = "light" | "dark";export const modeValidator = z.object({