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: add ui for selecting a plan

Brad Barbin325400c05aaa
diff --git a/apps/erp/app/lib/stripe/stripe.server.ts b/apps/erp/app/lib/stripe.server.ts
similarity index 95%
rename from apps/erp/app/lib/stripe/stripe.server.ts
rename to apps/erp/app/lib/stripe.server.ts
index f2ad5ba8b5..5c092456be 100644
--- a/apps/erp/app/lib/stripe/stripe.server.ts
+++ b/apps/erp/app/lib/stripe.server.ts
@@ -1,12 +1,10 @@
-/**
- * Integrate Stripe with a KV store.
- */
+import { getPlanById } from "@carbon/auth/auth.server";
import { redis } from "@carbon/kv";
import { redirect } from "@vercel/remix";
import { Stripe } from "stripe";
import { z } from "zod";
import { path } from "~/utils/path";
-import { getPlans } from "./plans";
+import { getCarbonServiceRole } from "../../../../packages/auth/src/lib/supabase/client";
if (!process.env.STRIPE_SECRET_KEY) {
throw new Error("process.env.STRIPE_SECRET_KEY not defined");
@@ -211,11 +209,13 @@ function getStripeWebhookEvent({
}
}
-export async function redirectToCheckout({
+export async function getCheckoutUrl({
+ planId,
companyId,
email,
name,
}: {
+ planId: string;
companyId: string;
email: string;
name?: string | null;
@@ -233,12 +233,13 @@ export async function redirectToCheckout({
stripeCustomerId = customer.id;
}
- const plans = await getPlans();
+ const serviceRole = await getCarbonServiceRole();
+ const plan = await getPlanById(serviceRole, planId);
const checkoutSession = await stripe.checkout.sessions.create({
customer: stripeCustomerId,
line_items: [
{
- price: plans.find((plan) => plan.id === "PRO")?.priceId,
+ price: plan.data.stripePriceId,
quantity: 1,
},
],
diff --git a/apps/erp/app/lib/stripe/plans.ts b/apps/erp/app/lib/stripe/plans.ts
deleted file mode 100644
index 8f38b3c668..0000000000
--- a/apps/erp/app/lib/stripe/plans.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-import { getStripeCustomer, getStripeCustomerId } from "./stripe.server";
-
-// Add new plans here
-const defaultPlans = [
- {
- id: "FREE",
- priceId: undefined,
- messageLimit: 10,
- },
- {
- id: "PRO",
- priceId: "price_1R3aDvLxBMFKq9DZn1vkvwwW",
- messageLimit: 100,
- },
-];
-
-export async function getPlans() {
- return defaultPlans;
-}
-
-export async function getStripePlan(companyId: string) {
- const plans = await getPlans();
- const freePlan = plans.find((plan) => plan.priceId === undefined) ?? plans[0];
-
- const customerId = await getStripeCustomerId(companyId);
- if (!customerId) {
- return freePlan;
- }
-
- const subData = await getStripeCustomer(customerId);
- if (!subData || subData.status !== "active") {
- // Inactive subscriptions happen after canceling, once the billing period ends
- return freePlan;
- }
-
- return plans.find((plan) => plan.priceId === subData.priceId) ?? freePlan;
-}
diff --git a/apps/erp/app/routes/_public+/callback.tsx b/apps/erp/app/routes/_public+/callback.tsx
index 1bc61622db..0ba2ce86bb 100644
--- a/apps/erp/app/routes/_public+/callback.tsx
+++ b/apps/erp/app/routes/_public+/callback.tsx
@@ -145,15 +145,20 @@ export default function AuthCallback() {
{error.includes("expired") && (
<>
<p className="text-sm text-muted-foreground">
- But don't worry. You can use the forgot password flow to
- request a new magic link.
+ Something went wrong. Please try again.
</p>
</>
)}
</VStack>
</div>
) : (
- <p className="text-muted-foreground">Loading...</p>
+ <div className="circle-loader-container">
+ <div className="circle-loader">
+ <div className="circle" />
+ <div className="circle" />
+ <div className="circle" />
+ </div>
+ </div>
)}
</div>
);
diff --git a/apps/erp/app/routes/onboarding+/_index.tsx b/apps/erp/app/routes/onboarding+/_index.tsx
index 0a3e84aa7c..dba39849ae 100644
--- a/apps/erp/app/routes/onboarding+/_index.tsx
+++ b/apps/erp/app/routes/onboarding+/_index.tsx
@@ -40,7 +40,7 @@ export default function GetStarted() {
transition={{ duration: 0.8, ease: "easeInOut", delay: 0.7 }}
className="text-muted-foreground text-balance text-sm pb-4"
>
- Carbon is the operational system for manufacturing
+ Carbon is the new standard for tech-enabled manufacturing
</motion.p>
<Button
diff --git a/apps/erp/app/routes/onboarding+/_layout.tsx b/apps/erp/app/routes/onboarding+/_layout.tsx
index 847173cd69..4baedf7359 100644
--- a/apps/erp/app/routes/onboarding+/_layout.tsx
+++ b/apps/erp/app/routes/onboarding+/_layout.tsx
@@ -1,5 +1,5 @@
-import { requirePermissions } from "@carbon/auth/auth.server";
-import { Outlet, useLoaderData } from "@remix-run/react";
+import { getCompanyPlan, requirePermissions } from "@carbon/auth/auth.server";
+import { Outlet } from "@remix-run/react";
import { redirect, type LoaderFunctionArgs } from "@vercel/remix";
import { getLocationsList } from "~/modules/resources";
import { getCompany } from "~/modules/settings";
@@ -15,9 +15,7 @@ export const config = {
};
export async function loader({ request }: LoaderFunctionArgs) {
- const { client, companyId } = await requirePermissions(request, {
- update: "settings",
- });
+ const { client, companyId } = await requirePermissions(request, {});
const [company, plan, locations] = await Promise.all([
getCompany(client, companyId),
@@ -25,15 +23,18 @@ export async function loader({ request }: LoaderFunctionArgs) {
getLocationsList(client, companyId),
]);
- // we don't need to do onboarding if we have a company name or locations
+ const pathname = new URL(request.url).pathname;
+ const isOnPlanRoute = pathname === path.to.onboarding.plan;
+
+ // Only redirect to plan page if we're not already on it
if (company.data?.name && locations.data?.length) {
- if (!plan.data?.planId) {
+ if (!plan.data?.id && !isOnPlanRoute) {
throw redirect(path.to.onboarding.plan);
+ } else if (plan.data?.id) {
+ throw redirect(path.to.authenticatedRoot);
}
- throw redirect(path.to.authenticatedRoot);
}
- const pathname = new URL(request.url).pathname;
const pathIndex = onboardingSequence.findIndex((p) => p === pathname);
const previousPath =
@@ -53,8 +54,6 @@ export async function loader({ request }: LoaderFunctionArgs) {
}
export default function OnboardingLayout() {
- const loaderData = useLoaderData<typeof loader>();
- console.log(loaderData);
return (
<VStack
spacing={4}
diff --git a/apps/erp/app/routes/onboarding+/company.tsx b/apps/erp/app/routes/onboarding+/company.tsx
index 42ff9b3fd1..99df9c419d 100644
--- a/apps/erp/app/routes/onboarding+/company.tsx
+++ b/apps/erp/app/routes/onboarding+/company.tsx
@@ -31,9 +31,7 @@ import {
} from "~/modules/settings";
export async function loader({ request }: ActionFunctionArgs) {
- const { client, companyId } = await requirePermissions(request, {
- update: "settings",
- });
+ const { client, companyId } = await requirePermissions(request, {});
const company = await getCompany(client, companyId ?? 1);
@@ -48,9 +46,7 @@ export async function loader({ request }: ActionFunctionArgs) {
export async function action({ request }: ActionFunctionArgs) {
assertIsPost(request);
- const { client, userId } = await requirePermissions(request, {
- update: "settings",
- });
+ const { client, userId } = await requirePermissions(request, {});
// there are no entries in the userToCompany table which
// dictates RLS for the company table
diff --git a/apps/erp/app/routes/onboarding+/plan.tsx b/apps/erp/app/routes/onboarding+/plan.tsx
index e69de29bb2..b313e03988 100644
--- a/apps/erp/app/routes/onboarding+/plan.tsx
+++ b/apps/erp/app/routes/onboarding+/plan.tsx
@@ -0,0 +1,208 @@
+import { getUser } from "@carbon/auth";
+import { getPlans, requirePermissions } from "@carbon/auth/auth.server";
+import {
+ Badge,
+ Button,
+ Card,
+ CardContent,
+ CardDescription,
+ CardFooter,
+ CardHeader,
+ CardTitle,
+ IconButton,
+} from "@carbon/react";
+import { useLocale } from "@react-aria/i18n";
+import { Form, useFetcher, useLoaderData } from "@remix-run/react";
+import { json, redirect, type ActionFunctionArgs } from "@vercel/remix";
+import { useMemo } from "react";
+import { LuMoveLeft } from "react-icons/lu";
+import { getCheckoutUrl } from "~/lib/stripe.server";
+import { getCompany } from "~/modules/settings";
+import { path } from "~/utils/path";
+
+const FEATURED_PLAN = "BUSINESS";
+const PLANS = {
+ STARTER: {
+ price: 30,
+ description: "Perfect for tech-forward businesses and small teams",
+ features: [
+ "ERP, MES, QMS",
+ "Cloud-Hosted",
+ "Self-Onboarding with Carbon University",
+ ],
+ },
+ BUSINESS: {
+ price: 90,
+ description: "For growing businesses that need dedicated support",
+ features: [
+ "Everything from Starter",
+ "Implementation Support",
+ "Unlimited Functional Support",
+ <div key="ai-agents" className="flex items-center gap-2">
+ <span>AI Agents</span>
+ <Badge variant="outline">Beta</Badge>
+ </div>,
+ ],
+ },
+} as const;
+
+export async function loader({ request }: ActionFunctionArgs) {
+ const { client, companyId } = await requirePermissions(request, {});
+ const plans = await getPlans(client);
+
+ if (!companyId) {
+ throw redirect(path.to.onboarding.company);
+ }
+
+ if (plans.error || !plans.data) {
+ throw new Error("Failed to load plans");
+ }
+
+ return json({ plans: plans.data?.filter((p) => p.public) });
+}
+
+export async function action({ request }: ActionFunctionArgs) {
+ const { client, companyId, userId } = await requirePermissions(request, {});
+ const formData = await request.formData();
+ const planId = String(formData.get("planId"));
+
+ if (!planId) {
+ throw new Error("Plan ID is required");
+ }
+
+ if (!(planId in PLANS) || planId === "PARTNER") {
+ throw new Error("Invalid plan ID");
+ }
+
+ const [user, company] = await Promise.all([
+ getUser(client, userId),
+ getCompany(client, companyId),
+ ]);
+
+ if (!user.data) {
+ throw new Error("User not found");
+ }
+
+ if (!company.data) {
+ throw new Error("Company not found");
+ }
+
+ const url = await getCheckoutUrl({
+ planId,
+ companyId,
+ name: company.data?.name,
+ email: user.data?.email,
+ });
+
+ throw redirect(url);
+}
+
+export default function OnboardingPlan() {
+ const { plans } = useLoaderData<typeof loader>();
+ const { locale } = useLocale();
+ const formatter = useMemo(
+ () =>
+ new Intl.NumberFormat(locale, {
+ style: "currency",
+ currency: "USD",
+ minimumFractionDigits: 0,
+ maximumFractionDigits: 0,
+ }),
+ [locale]
+ );
+
+ const fetcher = useFetcher<typeof action>();
+
+ return (
+ <>
+ <div className="flex flex-col max-w-2xl w-full min-h-screen md:min-h-0">
+ <div className="sticky top-0 bg-background z-10 pb-4">
+ <CardHeader>
+ <CardTitle>Select a plan</CardTitle>
+ <CardDescription>
+ Select a plan to get started. You won't be charged for the first
+ 14 days. Cancel anytime.
+ </CardDescription>
+ </CardHeader>
+ </div>
+
+ <CardContent className="flex-1">
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
+ {plans
+ .sort((a, b) => {
+ const priceA = PLANS[a.id as keyof typeof PLANS]?.price || 0;
+ const priceB = PLANS[b.id as keyof typeof PLANS]?.price || 0;
+ return priceA - priceB;
+ })
+ .map((plan) => {
+ const planDetails = PLANS[plan.id as keyof typeof PLANS];
+ const isFeatured = plan.id === FEATURED_PLAN;
+
+ return (
+ <Card
+ key={plan.id}
+ className={`relative ${isFeatured ? "border-primary" : ""}`}
+ >
+ <CardHeader>
+ <CardTitle>{plan.name}</CardTitle>
+ <CardDescription>
+ {planDetails?.description}
+ </CardDescription>
+ </CardHeader>
+ <CardContent>
+ <div className="flex items-baseline">
+ <span className="text-5xl font-bold tracking-tighter">
+ {formatter.format(planDetails?.price)}
+ </span>
+ <span className="ml-1 text-sm text-muted-foreground tracking-tighter">
+ /month/user
+ </span>
+ </div>
+ <ul className="mt-6 space-y-3">
+ {planDetails?.features.map((feature, index) => (
+ <li
+ key={index}
+ className="flex items-center justify-start gap-2"
+ >
+ <span className="text-sm">{feature}</span>
+ </li>
+ ))}
+ </ul>
+ </CardContent>
+ <CardFooter>
+ <fetcher.Form method="post">
+ <input type="hidden" name="planId" value={plan.id} />
+ <Button
+ className="w-full"
+ variant={isFeatured ? "primary" : "secondary"}
+ type="submit"
+ isDisabled={fetcher.state !== "idle"}
+ isLoading={
+ fetcher.state !== "idle" &&
+ fetcher.formData?.get("planId") === plan.id
+ }
+ >
+ Start {plan.stripeTrialPeriodDays} day free trial
+ </Button>
+ </fetcher.Form>
+ </CardFooter>
+ </Card>
+ );
+ })}
+ </div>
+ </CardContent>
+ </div>
+ <div className="fixed top-0 left-2 z-10">
+ <Form method="post" action={path.to.logout}>
+ <IconButton
+ size="lg"
+ type="submit"
+ variant="ghost"
+ icon={<LuMoveLeft />}
+ aria-label="Back"
+ />
+ </Form>
+ </div>
+ </>
+ );
+}
diff --git a/apps/erp/app/routes/onboarding+/user.tsx b/apps/erp/app/routes/onboarding+/user.tsx
index c7dc920ea6..e0591d19cc 100644
--- a/apps/erp/app/routes/onboarding+/user.tsx
+++ b/apps/erp/app/routes/onboarding+/user.tsx
@@ -24,9 +24,7 @@ import {
import { getUser } from "~/modules/users/users.server";
export async function loader({ request }: ActionFunctionArgs) {
- const { client, userId } = await requirePermissions(request, {
- update: "users",
- });
+ const { client, userId } = await requirePermissions(request, {});
const user = await getUser(client, userId);
if (user.error || !user.data) {
@@ -38,9 +36,7 @@ export async function loader({ request }: ActionFunctionArgs) {
export async function action({ request }: ActionFunctionArgs) {
assertIsPost(request);
- const { client, userId } = await requirePermissions(request, {
- update: "users",
- });
+ const { client, userId } = await requirePermissions(request, {});
const validation = await validator(onboardingUserValidator).validate(
await request.formData()
diff --git a/apps/erp/app/routes/x+/_layout.tsx b/apps/erp/app/routes/x+/_layout.tsx
index a9969e22f7..e7b32e9cd4 100644
--- a/apps/erp/app/routes/x+/_layout.tsx
+++ b/apps/erp/app/routes/x+/_layout.tsx
@@ -22,6 +22,7 @@ import {
} from "~/modules/users/users.server";
import { path } from "~/utils/path";
+import { getCompanyPlan } from "@carbon/auth/auth.server";
import type { ShouldRevalidateFunction } from "@remix-run/react";
import posthog from "posthog-js";
import { useUser } from "~/hooks";
@@ -43,10 +44,6 @@ export const shouldRevalidate: ShouldRevalidateFunction = ({
return defaultShouldRevalidate;
};
-export const config = {
- runtime: "nodejs",
-};
-
export async function loader({ request }: LoaderFunctionArgs) {
const { accessToken, companyId, expiresAt, expiresIn, userId } =
await requireAuthSession(request, { verify: true });
@@ -65,6 +62,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
// parallelize the requests
const [
companies,
+ companyPlan,
customFields,
integrations,
savedViews,
@@ -74,6 +72,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
defaults,
] = await Promise.all([
getCompanies(client, userId),
+ getCompanyPlan(client, companyId),
getCustomFieldsSchemas(client, { companyId }),
getCompanyIntegrations(client, companyId),
getSavedViews(client, userId, companyId),
@@ -89,7 +88,8 @@ export async function loader({ request }: LoaderFunctionArgs) {
const company = companies.data?.find((c) => c.companyId === companyId);
- const requiresOnboarding = !companies.data?.[0]?.name;
+ const requiresOnboarding =
+ !companies.data?.[0]?.name || !companyPlan.data?.id;
if (requiresOnboarding) {
throw redirect(path.to.onboarding.root);
}
diff --git a/apps/erp/app/styles/tailwind.css b/apps/erp/app/styles/tailwind.css
index 6f1bb83c09..4c315b6eab 100644
--- a/apps/erp/app/styles/tailwind.css
+++ b/apps/erp/app/styles/tailwind.css
@@ -156,3 +156,51 @@ p.is-editor-empty:first-child:before {
.loading-dot:nth-child(3) {
animation-delay: 0.4s;
}
+
+.circle-loader-container {
+ @apply relative w-full py-4;
+}
+
+.circle-loader {
+ position: relative;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ width: 100%;
+ height: 40px;
+}
+/* Three dot loading animation */
+.circle {
+ display: inline-block;
+ position: relative;
+ width: 16px;
+ height: 16px;
+ background-color: #5fe4d3;
+ border-radius: 50%;
+ animation: dotloader 1.4s infinite ease-in-out;
+}
+
+.circle + .circle {
+ margin-left: 12px;
+ animation: dotloader 1.4s 0.2s infinite ease-in-out;
+ background-color: #4faade;
+}
+
+.circle + .circle + .circle {
+ margin-left: 12px;
+ animation: dotloader 1.4s 0.4s infinite ease-in-out;
+ background-color: #6041d0;
+}
+
+@keyframes dotloader {
+ 0%,
+ 80%,
+ 100% {
+ transform: scale(0.5);
+ opacity: 0;
+ }
+ 40% {
+ transform: scale(1.2);
+ opacity: 1;
+ }
+}
diff --git a/apps/mes/app/routes/_public+/callback.tsx b/apps/mes/app/routes/_public+/callback.tsx
index f3411f6855..8afdfa807a 100644
--- a/apps/mes/app/routes/_public+/callback.tsx
+++ b/apps/mes/app/routes/_public+/callback.tsx
@@ -162,7 +162,13 @@ export default function AuthCallback() {
</VStack>
</div>
) : (
- <p className="text-muted-foreground">Loading...</p>
+ <div className="circle-loader-container">
+ <div className="circle-loader">
+ <div className="circle" />
+ <div className="circle" />
+ <div className="circle" />
+ </div>
+ </div>
)}
</div>
);
diff --git a/apps/mes/app/routes/x+/_layout.tsx b/apps/mes/app/routes/x+/_layout.tsx
index 9b140124ea..c235e73a24 100644
--- a/apps/mes/app/routes/x+/_layout.tsx
+++ b/apps/mes/app/routes/x+/_layout.tsx
@@ -1,4 +1,5 @@
import { CarbonProvider, getCarbon, getCompanies, getUser } from "@carbon/auth";
+import { getCompanyPlan } from "@carbon/auth/auth.server";
import {
destroyAuthSession,
requireAuthSession,
@@ -57,17 +58,23 @@ export async function loader({ request }: LoaderFunctionArgs) {
throw redirect(path.to.accountSettings);
}
- let [storedLocations, locations, activeEvents] = await Promise.all([
- getLocation(request, client, {
- companyId,
- userId,
- }),
- getLocationsByCompany(client, companyId),
- getActiveJobCount(client, {
- employeeId: userId,
- companyId,
- }),
- ]);
+ let [storedLocations, companyPlan, locations, activeEvents] =
+ await Promise.all([
+ getLocation(request, client, {
+ companyId,
+ userId,
+ }),
+ getCompanyPlan(client, companyId),
+ getLocationsByCompany(client, companyId),
+ getActiveJobCount(client, {
+ employeeId: userId,
+ companyId,
+ }),
+ ]);
+
+ if (!companyPlan.data?.id) {
+ throw redirect(path.to.onboarding);
+ }
if (!locations.data || locations.data.length === 0) {
throw new Error(`No locations found for ${company.name}`);
diff --git a/apps/mes/app/styles/tailwind.css b/apps/mes/app/styles/tailwind.css
index 6fe9d70921..23b9d392d1 100644
--- a/apps/mes/app/styles/tailwind.css
+++ b/apps/mes/app/styles/tailwind.css
@@ -120,3 +120,51 @@ p.is-editor-empty:first-child:before {
.tiptap.ProseMirror-selectedNode div[data-video-embed] {
@apply ring-2 ring-primary cursor-move p-2 rounded-lg;
}
+
+.circle-loader-container {
+ @apply relative w-full py-4;
+}
+
+.circle-loader {
+ position: relative;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ width: 100%;
+ height: 40px;
+}
+/* Three dot loading animation */
+.circle {
+ display: inline-block;
+ position: relative;
+ width: 16px;
+ height: 16px;
+ background-color: #5fe4d3;
+ border-radius: 50%;
+ animation: dotloader 1.4s infinite ease-in-out;
+}
+
+.circle + .circle {
+ margin-left: 12px;
+ animation: dotloader 1.4s 0.2s infinite ease-in-out;
+ background-color: #4faade;
+}
+
+.circle + .circle + .circle {
+ margin-left: 12px;
+ animation: dotloader 1.4s 0.4s infinite ease-in-out;
+ background-color: #6041d0;
+}
+
+@keyframes dotloader {
+ 0%,
+ 80%,
+ 100% {
+ transform: scale(0.5);
+ opacity: 0;
+ }
+ 40% {
+ transform: scale(1.2);
+ opacity: 1;
+ }
+}
diff --git a/apps/mes/app/utils/path.ts b/apps/mes/app/utils/path.ts
index 0b936e376e..38c1e82531 100644
--- a/apps/mes/app/utils/path.ts
+++ b/apps/mes/app/utils/path.ts
@@ -77,6 +77,7 @@ export const path = {
login: "/login",
logout: "/logout",
messagingNotify: `${x}/proxy/api/messaging/notify`,
+ onboarding: `${ERP_URL}/onboarding`,
operation: (id: string) => generatePath(`${x}/operation/${id}`),
operations: `${x}/operations?saved=1`,
productionEvent: `${x}/event`,
diff --git a/apps/starter/app/routes/_public+/callback.tsx b/apps/starter/app/routes/_public+/callback.tsx
index f3411f6855..8afdfa807a 100644
--- a/apps/starter/app/routes/_public+/callback.tsx
+++ b/apps/starter/app/routes/_public+/callback.tsx
@@ -162,7 +162,13 @@ export default function AuthCallback() {
</VStack>
</div>
) : (
- <p className="text-muted-foreground">Loading...</p>
+ <div className="circle-loader-container">
+ <div className="circle-loader">
+ <div className="circle" />
+ <div className="circle" />
+ <div className="circle" />
+ </div>
+ </div>
)}
</div>
);
diff --git a/apps/starter/app/routes/x+/_layout.tsx b/apps/starter/app/routes/x+/_layout.tsx
index f6d52a55e7..57e886a3bb 100644
--- a/apps/starter/app/routes/x+/_layout.tsx
+++ b/apps/starter/app/routes/x+/_layout.tsx
@@ -12,10 +12,12 @@ import {
getCompanies,
getUser,
} from "@carbon/auth";
+import { getCompanyPlan } from "@carbon/auth/auth.server";
import {
destroyAuthSession,
requireAuthSession,
} from "@carbon/auth/session.server";
+import { path } from "~/utils/path";
export async function loader({ request }: LoaderFunctionArgs) {
const { accessToken, companyId, expiresAt, expiresIn, userId } =
@@ -39,6 +41,11 @@ export async function loader({ request }: LoaderFunctionArgs) {
throw redirect(getAppUrl());
}
+ const companyPlan = await getCompanyPlan(client, companyId);
+ if (!companyPlan.data?.id) {
+ throw redirect(path.to.onboarding);
+ }
+
return json({
session: {
accessToken,
diff --git a/apps/starter/app/styles/tailwind.css b/apps/starter/app/styles/tailwind.css
index 04374ffdb9..22fe89ff9c 100644
--- a/apps/starter/app/styles/tailwind.css
+++ b/apps/starter/app/styles/tailwind.css
@@ -130,3 +130,51 @@ p.is-editor-empty:first-child:before {
.tiptap.ProseMirror-selectedNode div[data-video-embed] {
@apply ring-2 ring-primary cursor-move p-2 rounded-lg;
}
+
+.circle-loader-container {
+ @apply relative w-full py-4;
+}
+
+.circle-loader {
+ position: relative;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ width: 100%;
+ height: 40px;
+}
+/* Three dot loading animation */
+.circle {
+ display: inline-block;
+ position: relative;
+ width: 16px;
+ height: 16px;
+ background-color: #5fe4d3;
+ border-radius: 50%;
+ animation: dotloader 1.4s infinite ease-in-out;
+}
+
+.circle + .circle {
+ margin-left: 12px;
+ animation: dotloader 1.4s 0.2s infinite ease-in-out;
+ background-color: #4faade;
+}
+
+.circle + .circle + .circle {
+ margin-left: 12px;
+ animation: dotloader 1.4s 0.4s infinite ease-in-out;
+ background-color: #6041d0;
+}
+
+@keyframes dotloader {
+ 0%,
+ 80%,
+ 100% {
+ transform: scale(0.5);
+ opacity: 0;
+ }
+ 40% {
+ transform: scale(1.2);
+ opacity: 1;
+ }
+}
diff --git a/apps/starter/app/utils/path.ts b/apps/starter/app/utils/path.ts
index d0dbd338d7..f24bda4b3b 100644
--- a/apps/starter/app/utils/path.ts
+++ b/apps/starter/app/utils/path.ts
@@ -17,6 +17,7 @@ export const path = {
healthcheck: "/healthcheck",
login: "/login",
logout: "/logout",
+ onboarding: `${ERP_URL}/onboarding`,
refreshSession: "/refresh-session",
requestAccess: "/request-access",
root: "/",
diff --git a/apps/university/app/routes/_auth+/callback.tsx b/apps/university/app/routes/_auth+/callback.tsx
index 3c78c61b22..05c7275678 100644
--- a/apps/university/app/routes/_auth+/callback.tsx
+++ b/apps/university/app/routes/_auth+/callback.tsx
@@ -162,7 +162,13 @@ export default function AuthCallback() {
</VStack>
</div>
) : (
- <p className="text-muted-foreground">Loading...</p>
+ <div className="circle-loader-container">
+ <div className="circle-loader">
+ <div className="circle" />
+ <div className="circle" />
+ <div className="circle" />
+ </div>
+ </div>
)}
</div>
);
diff --git a/apps/university/app/styles/tailwind.css b/apps/university/app/styles/tailwind.css
index e789136442..e972f3ebb5 100644
--- a/apps/university/app/styles/tailwind.css
+++ b/apps/university/app/styles/tailwind.css
@@ -136,3 +136,51 @@
a.active {
font-weight: 600;
}
+
+.circle-loader-container {
+ @apply relative w-full py-4;
+}
+
+.circle-loader {
+ position: relative;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ width: 100%;
+ height: 40px;
+}
+/* Three dot loading animation */
+.circle {
+ display: inline-block;
+ position: relative;
+ width: 16px;
+ height: 16px;
+ background-color: #5fe4d3;
+ border-radius: 50%;
+ animation: dotloader 1.4s infinite ease-in-out;
+}
+
+.circle + .circle {
+ margin-left: 12px;
+ animation: dotloader 1.4s 0.2s infinite ease-in-out;
+ background-color: #4faade;
+}
+
+.circle + .circle + .circle {
+ margin-left: 12px;
+ animation: dotloader 1.4s 0.4s infinite ease-in-out;
+ background-color: #6041d0;
+}
+
+@keyframes dotloader {
+ 0%,
+ 80%,
+ 100% {
+ transform: scale(0.5);
+ opacity: 0;
+ }
+ 40% {
+ transform: scale(1.2);
+ opacity: 1;
+ }
+}
diff --git a/packages/auth/src/services/auth.server.ts b/packages/auth/src/services/auth.server.ts
index 2d5095b2f2..d40a3f7512 100644
--- a/packages/auth/src/services/auth.server.ts
+++ b/packages/auth/src/services/auth.server.ts
@@ -38,6 +38,21 @@ export async function createEmailAuthAccount(
return data.user;
}
+export async function getCompanyPlan(
+ client: SupabaseClient,
+ companyId: string
+) {
+ return client.from("companyPlan").select("*").eq("id", companyId).single();
+}
+
+export async function getPlanById(client: SupabaseClient, planId: string) {
+ return client.from("plan").select("*").eq("id", planId).single();
+}
+
+export async function getPlans(client: SupabaseClient) {
+ return client.from("plan").select("*");
+}
+
export async function deleteAuthAccount(
client: SupabaseClient<Database>,
userId: string
diff --git a/packages/database/src/seed.ts b/packages/database/src/seed.ts
index 425b0f2950..52ddbe7641 100644
--- a/packages/database/src/seed.ts
+++ b/packages/database/src/seed.ts
@@ -1,9 +1,7 @@
// import type { User } from "@supabase/supabase-js";
import { createClient } from "@supabase/supabase-js";
import * as dotenv from "dotenv";
-import {
- admin, // , claims, permissions
-} from "./seed/index";
+import { admin, devPrices } from "./seed/index";
import type { Database } from "./types";
dotenv.config();
@@ -59,6 +57,17 @@ async function seed() {
]);
if (upsertConfig.error) throw upsertConfig.error;
+ const upsertPlans = await supabaseAdmin.from("plan").upsert(
+ Object.entries(devPrices).map(([id, { stripePriceId, name }]) => ({
+ id,
+ stripePriceId,
+ name,
+ })),
+ { onConflict: "id" }
+ );
+
+ if (upsertPlans.error) throw upsertPlans.error;
+
// const upsertAdmin = await supabaseAdmin.from("user").upsert([
// {
// id,
diff --git a/packages/database/src/seed/index.ts b/packages/database/src/seed/index.ts
index 330b288a38..8112ac2996 100644
--- a/packages/database/src/seed/index.ts
+++ b/packages/database/src/seed/index.ts
@@ -1,2 +1,3 @@
export * from "./admin";
export * from "./modules";
+export * from "./stripe";
diff --git a/packages/database/src/seed/stripe.ts b/packages/database/src/seed/stripe.ts
new file mode 100644
index 0000000000..2d07e18ac0
--- /dev/null
+++ b/packages/database/src/seed/stripe.ts
@@ -0,0 +1,14 @@
+export const devPrices = {
+ STARTER: {
+ stripePriceId: "price_1RgZsyFV6ecOa0XvwTRRqqaR",
+ name: "Starter (Dev)",
+ },
+ BUSINESS: {
+ stripePriceId: "price_1RgZtlFV6ecOa0Xv30ClxYOe",
+ name: "Business (Dev)",
+ },
+ PARTNER: {
+ stripePriceId: "price_1RgZuKFV6ecOa0Xvv0RpaJUr",
+ name: "Design Partner (Dev)",
+ },
+};
diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.ts
index 4322c3a930..36a959775b 100644
--- a/packages/database/src/swagger-docs-schema.ts
+++ b/packages/database/src/swagger-docs-schema.ts
@@ -3558,6 +3558,168 @@ export default {
tags: ["scrapReason"],
},
},
+ "/companyUsage": {
+ get: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.users",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.tasks",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.aiTokens",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.nextResetDatetime",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.companyId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.updatedAt",
+ },
+ {
+ $ref: "#/parameters/select",
+ },
+ {
+ $ref: "#/parameters/order",
+ },
+ {
+ $ref: "#/parameters/range",
+ },
+ {
+ $ref: "#/parameters/rangeUnit",
+ },
+ {
+ $ref: "#/parameters/offset",
+ },
+ {
+ $ref: "#/parameters/limit",
+ },
+ {
+ $ref: "#/parameters/preferCount",
+ },
+ ],
+ responses: {
+ "200": {
+ description: "OK",
+ schema: {
+ items: {
+ $ref: "#/definitions/companyUsage",
+ },
+ type: "array",
+ },
+ },
+ "206": {
+ description: "Partial Content",
+ },
+ },
+ tags: ["companyUsage"],
+ },
+ post: {
+ parameters: [
+ {
+ $ref: "#/parameters/body.companyUsage",
+ },
+ {
+ $ref: "#/parameters/select",
+ },
+ {
+ $ref: "#/parameters/preferPost",
+ },
+ ],
+ responses: {
+ "201": {
+ description: "Created",
+ },
+ },
+ tags: ["companyUsage"],
+ },
+ delete: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.users",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.tasks",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.aiTokens",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.nextResetDatetime",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.companyId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.updatedAt",
+ },
+ {
+ $ref: "#/parameters/preferReturn",
+ },
+ ],
+ responses: {
+ "204": {
+ description: "No Content",
+ },
+ },
+ tags: ["companyUsage"],
+ },
+ patch: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.users",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.tasks",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.aiTokens",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.nextResetDatetime",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.companyId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyUsage.updatedAt",
+ },
+ {
+ $ref: "#/parameters/body.companyUsage",
+ },
+ {
+ $ref: "#/parameters/preferReturn",
+ },
+ ],
+ responses: {
+ "204": {
+ description: "No Content",
+ },
+ },
+ tags: ["companyUsage"],
+ },
+ },
"/jobOperationsWithDependencies": {
get: {
parameters: [
@@ -12999,6 +13161,186 @@ export default {
tags: ["customFieldTable"],
},
},
+ "/plan": {
+ get: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.plan.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.name",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.userBasedPricing",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.stripePriceId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.tasksLimit",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.aiTokensLimit",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.stripeTrialPeriodDays",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.public",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.updatedAt",
+ },
+ {
+ $ref: "#/parameters/select",
+ },
+ {
+ $ref: "#/parameters/order",
+ },
+ {
+ $ref: "#/parameters/range",
+ },
+ {
+ $ref: "#/parameters/rangeUnit",
+ },
+ {
+ $ref: "#/parameters/offset",
+ },
+ {
+ $ref: "#/parameters/limit",
+ },
+ {
+ $ref: "#/parameters/preferCount",
+ },
+ ],
+ responses: {
+ "200": {
+ description: "OK",
+ schema: {
+ items: {
+ $ref: "#/definitions/plan",
+ },
+ type: "array",
+ },
+ },
+ "206": {
+ description: "Partial Content",
+ },
+ },
+ tags: ["plan"],
+ },
+ post: {
+ parameters: [
+ {
+ $ref: "#/parameters/body.plan",
+ },
+ {
+ $ref: "#/parameters/select",
+ },
+ {
+ $ref: "#/parameters/preferPost",
+ },
+ ],
+ responses: {
+ "201": {
+ description: "Created",
+ },
+ },
+ tags: ["plan"],
+ },
+ delete: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.plan.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.name",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.userBasedPricing",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.stripePriceId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.tasksLimit",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.aiTokensLimit",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.stripeTrialPeriodDays",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.public",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.updatedAt",
+ },
+ {
+ $ref: "#/parameters/preferReturn",
+ },
+ ],
+ responses: {
+ "204": {
+ description: "No Content",
+ },
+ },
+ tags: ["plan"],
+ },
+ patch: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.plan.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.name",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.userBasedPricing",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.stripePriceId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.tasksLimit",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.aiTokensLimit",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.stripeTrialPeriodDays",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.public",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.plan.updatedAt",
+ },
+ {
+ $ref: "#/parameters/body.plan",
+ },
+ {
+ $ref: "#/parameters/preferReturn",
+ },
+ ],
+ responses: {
+ "204": {
+ description: "No Content",
+ },
+ },
+ tags: ["plan"],
+ },
+ },
"/location": {
get: {
parameters: [
@@ -32910,6 +33252,204 @@ export default {
tags: ["trackedEntity"],
},
},
+ "/companyPlan": {
+ get: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.planId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.tasksLimit",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.aiTokensLimit",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.usersLimit",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.subscriptionStartDate",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.stripeCustomerId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.stripeSubscriptionId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.stripeSubscriptionStatus",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.trialPeriodEndsAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.updatedAt",
+ },
+ {
+ $ref: "#/parameters/select",
+ },
+ {
+ $ref: "#/parameters/order",
+ },
+ {
+ $ref: "#/parameters/range",
+ },
+ {
+ $ref: "#/parameters/rangeUnit",
+ },
+ {
+ $ref: "#/parameters/offset",
+ },
+ {
+ $ref: "#/parameters/limit",
+ },
+ {
+ $ref: "#/parameters/preferCount",
+ },
+ ],
+ responses: {
+ "200": {
+ description: "OK",
+ schema: {
+ items: {
+ $ref: "#/definitions/companyPlan",
+ },
+ type: "array",
+ },
+ },
+ "206": {
+ description: "Partial Content",
+ },
+ },
+ tags: ["companyPlan"],
+ },
+ post: {
+ parameters: [
+ {
+ $ref: "#/parameters/body.companyPlan",
+ },
+ {
+ $ref: "#/parameters/select",
+ },
+ {
+ $ref: "#/parameters/preferPost",
+ },
+ ],
+ responses: {
+ "201": {
+ description: "Created",
+ },
+ },
+ tags: ["companyPlan"],
+ },
+ delete: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.planId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.tasksLimit",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.aiTokensLimit",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.usersLimit",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.subscriptionStartDate",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.stripeCustomerId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.stripeSubscriptionId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.stripeSubscriptionStatus",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.trialPeriodEndsAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.updatedAt",
+ },
+ {
+ $ref: "#/parameters/preferReturn",
+ },
+ ],
+ responses: {
+ "204": {
+ description: "No Content",
+ },
+ },
+ tags: ["companyPlan"],
+ },
+ patch: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.planId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.tasksLimit",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.aiTokensLimit",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.usersLimit",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.subscriptionStartDate",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.stripeCustomerId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.stripeSubscriptionId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.stripeSubscriptionStatus",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.trialPeriodEndsAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.companyPlan.updatedAt",
+ },
+ {
+ $ref: "#/parameters/body.companyPlan",
+ },
+ {
+ $ref: "#/parameters/preferReturn",
+ },
+ ],
+ responses: {
+ "204": {
+ description: "No Content",
+ },
+ },
+ tags: ["companyPlan"],
+ },
+ },
"/salesRfqLines": {
get: {
parameters: [
@@ -58485,6 +59025,62 @@ export default {
},
type: "object",
},
+ companyUsage: {
+ required: [
+ "id",
+ "users",
+ "tasks",
+ "aiTokens",
+ "nextResetDatetime",
+ "companyId",
+ "createdAt",
+ "updatedAt",
+ ],
+ properties: {
+ id: {
+ default: "public.xid()",
+ description: "Note:\nThis is a Primary Key.<pk/>",
+ format: "text",
+ type: "string",
+ },
+ users: {
+ default: 0,
+ format: "integer",
+ type: "integer",
+ },
+ tasks: {
+ default: 0,
+ format: "integer",
+ type: "integer",
+ },
+ aiTokens: {
+ default: 0,
+ format: "integer",
+ type: "integer",
+ },
+ nextResetDatetime: {
+ format: "timestamp with time zone",
+ type: "string",
+ },
+ companyId: {
+ description:
+ "Note:\nThis is a Foreign Key to `company.id`.<fk table='company' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ createdAt: {
+ default: "now()",
+ format: "timestamp with time zone",
+ type: "string",
+ },
+ updatedAt: {
+ default: "now()",
+ format: "timestamp with time zone",
+ type: "string",
+ },
+ },
+ type: "object",
+ },
jobOperationsWithDependencies: {
properties: {
id: {
@@ -63099,6 +63695,72 @@ export default {
},
type: "object",
},
+ plan: {
+ required: [
+ "id",
+ "name",
+ "userBasedPricing",
+ "stripePriceId",
+ "tasksLimit",
+ "aiTokensLimit",
+ "stripeTrialPeriodDays",
+ "public",
+ "createdAt",
+ "updatedAt",
+ ],
+ properties: {
+ id: {
+ default: "public.xid()",
+ description: "Note:\nThis is a Primary Key.<pk/>",
+ format: "text",
+ type: "string",
+ },
+ name: {
+ format: "text",
+ type: "string",
+ },
+ userBasedPricing: {
+ default: true,
+ format: "boolean",
+ type: "boolean",
+ },
+ stripePriceId: {
+ format: "text",
+ type: "string",
+ },
+ tasksLimit: {
+ default: 10000,
+ format: "integer",
+ type: "integer",
+ },
+ aiTokensLimit: {
+ default: 1000000,
+ format: "integer",
+ type: "integer",
+ },
+ stripeTrialPeriodDays: {
+ default: 7,
+ format: "integer",
+ type: "integer",
+ },
+ public: {
+ default: true,
+ format: "boolean",
+ type: "boolean",
+ },
+ createdAt: {
+ default: "now()",
+ format: "timestamp with time zone",
+ type: "string",
+ },
+ updatedAt: {
+ default: "now()",
+ format: "timestamp with time zone",
+ type: "string",
+ },
+ },
+ type: "object",
+ },
location: {
required: [
"id",
@@ -72125,6 +72787,82 @@ export default {
},
type: "object",
},
+ companyPlan: {
+ required: [
+ "id",
+ "planId",
+ "tasksLimit",
+ "aiTokensLimit",
+ "usersLimit",
+ "subscriptionStartDate",
+ "stripeSubscriptionId",
+ "stripeSubscriptionStatus",
+ "createdAt",
+ "updatedAt",
+ ],
+ properties: {
+ id: {
+ default: "public.xid()",
+ description:
+ "Note:\nThis is a Primary Key.<pk/>\nThis is a Foreign Key to `company.id`.<fk table='company' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ planId: {
+ description:
+ "Note:\nThis is a Foreign Key to `plan.id`.<fk table='plan' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ tasksLimit: {
+ default: 10000,
+ format: "integer",
+ type: "integer",
+ },
+ aiTokensLimit: {
+ default: 1000000,
+ format: "integer",
+ type: "integer",
+ },
+ usersLimit: {
+ default: 10,
+ format: "integer",
+ type: "integer",
+ },
+ subscriptionStartDate: {
+ format: "timestamp with time zone",
+ type: "string",
+ },
+ stripeCustomerId: {
+ format: "text",
+ type: "string",
+ },
+ stripeSubscriptionId: {
+ format: "text",
+ type: "string",
+ },
+ stripeSubscriptionStatus: {
+ default: "ACTIVE",
+ format: "text",
+ type: "string",
+ },
+ trialPeriodEndsAt: {
+ format: "timestamp with time zone",
+ type: "string",
+ },
+ createdAt: {
+ default: "now()",
+ format: "timestamp with time zone",
+ type: "string",
+ },
+ updatedAt: {
+ default: "now()",
+ format: "timestamp with time zone",
+ type: "string",
+ },
+ },
+ type: "object",
+ },
salesRfqLines: {
properties: {
id: {
@@ -83295,6 +84033,63 @@ export default {
in: "query",
type: "string",
},
+ "body.companyUsage": {
+ name: "companyUsage",
+ description: "companyUsage",
+ required: false,
+ in: "body",
+ schema: {
+ $ref: "#/definitions/companyUsage",
+ },
+ },
+ "rowFilter.companyUsage.id": {
+ name: "id",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.companyUsage.users": {
+ name: "users",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.companyUsage.tasks": {
+ name: "tasks",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.companyUsage.aiTokens": {
+ name: "aiTokens",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.companyUsage.nextResetDatetime": {
+ name: "nextResetDatetime",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.companyUsage.companyId": {
+ name: "companyId",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.companyUsage.createdAt": {
+ name: "createdAt",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.companyUsage.updatedAt": {
+ name: "updatedAt",
+ required: false,
+ in: "query",
+ type: "string",
+ },
"body.jobOperationsWithDependencies": {
name: "jobOperationsWithDependencies",
description: "jobOperationsWithDependencies",
@@ -88416,6 +89211,75 @@ export default {
in: "query",
type: "string",
},
+ "body.plan": {
+ name: "plan",
+ description: "plan",
+ required: false,
+ in: "body",
+ schema: {
+ $ref: "#/definitions/plan",
+ },
+ },
+ "rowFilter.plan.id": {
+ name: "id",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.plan.name": {
+ name: "name",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.plan.userBasedPricing": {
+ name: "userBasedPricing",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.plan.stripePriceId": {
+ name: "stripePriceId",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.plan.tasksLimit": {
+ name: "tasksLimit",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.plan.aiTokensLimit": {
+ name: "aiTokensLimit",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.plan.stripeTrialPeriodDays": {
+ name: "stripeTrialPeriodDays",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.plan.public": {
+ name: "public",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.plan.createdAt": {
+ name: "createdAt",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.plan.updatedAt": {
+ name: "updatedAt",
+ required: false,
+ in: "query",
+ type: "string",
+ },
"body.location": {
name: "location",
description: "location",
@@ -98676,6 +99540,87 @@ export default {
in: "query",
type: "string",
},
+ "body.companyPlan": {
+ name: "companyPlan",
+ description: "companyPlan",
+ required: false,
+ in: "body",
+ schema: {
+ $ref: "#/definitions/companyPlan",
+ },
+ },
+ "rowFilter.companyPlan.id": {
+ name: "id",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.companyPlan.planId": {
+ name: "planId",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.companyPlan.tasksLimit": {
+ name: "tasksLimit",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.companyPlan.aiTokensLimit": {
+ name: "aiTokensLimit",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.companyPlan.usersLimit": {
+ name: "usersLimit",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.companyPlan.subscriptionStartDate": {
+ name: "subscriptionStartDate",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.companyPlan.stripeCustomerId": {
+ name: "stripeCustomerId",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.companyPlan.stripeSubscriptionId": {
+ name: "stripeSubscriptionId",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.companyPlan.stripeSubscriptionStatus": {
+ name: "stripeSubscriptionStatus",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.companyPlan.trialPeriodEndsAt": {
+ name: "trialPeriodEndsAt",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.companyPlan.createdAt": {
+ name: "createdAt",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.companyPlan.updatedAt": {
+ name: "updatedAt",
+ required: false,
+ in: "query",
+ type: "string",
+ },
"body.salesRfqLines": {
name: "salesRfqLines",
description: "salesRfqLines",
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 491337b943..01b24f9038 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -2187,6 +2187,87 @@ export type Database = {
},
]
}
+ companyPlan: {
+ Row: {
+ aiTokensLimit: number
+ createdAt: string
+ id: string
+ planId: string
+ stripeCustomerId: string | null
+ stripeSubscriptionId: string
+ stripeSubscriptionStatus: string
+ subscriptionStartDate: string
+ tasksLimit: number
+ trialPeriodEndsAt: string | null
+ updatedAt: string
+ usersLimit: number
+ }
+ Insert: {
+ aiTokensLimit?: number
+ createdAt?: string
+ id?: string
+ planId: string
+ stripeCustomerId?: string | null
+ stripeSubscriptionId: string
+ stripeSubscriptionStatus?: string
+ subscriptionStartDate: string
+ tasksLimit?: number
+ trialPeriodEndsAt?: string | null
+ updatedAt?: string
+ usersLimit?: number
+ }
+ Update: {
+ aiTokensLimit?: number
+ createdAt?: string
+ id?: string
+ planId?: string
+ stripeCustomerId?: string | null
+ stripeSubscriptionId?: string
+ stripeSubscriptionStatus?: string
+ subscriptionStartDate?: string
+ tasksLimit?: number
+ trialPeriodEndsAt?: string | null
+ updatedAt?: string
+ usersLimit?: number
+ }
+ Relationships: [
+ {
+ foreignKeyName: "fk_companyPlan_company"
+ columns: ["id"]
+ isOneToOne: true
+ referencedRelation: "companies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "fk_companyPlan_company"
+ columns: ["id"]
+ isOneToOne: true
+ referencedRelation: "company"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "fk_companyPlan_company"
+ columns: ["id"]
+ isOneToOne: true
+ referencedRelation: "customFieldTables"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "fk_companyPlan_company"
+ columns: ["id"]
+ isOneToOne: true
+ referencedRelation: "integrations"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "fk_companyPlan_plan"
+ columns: ["planId"]
+ isOneToOne: false
+ referencedRelation: "plan"
+ referencedColumns: ["id"]
+ },
+ ]
+ }
companySettings: {
Row: {
digitalQuoteEnabled: boolean
@@ -2252,6 +2333,68 @@ export type Database = {
},
]
}
+ companyUsage: {
+ Row: {
+ aiTokens: number
+ companyId: string
+ createdAt: string
+ id: string
+ nextResetDatetime: string
+ tasks: number
+ updatedAt: string
+ users: number
+ }
+ Insert: {
+ aiTokens?: number
+ companyId: string
+ createdAt?: string
+ id?: string
+ nextResetDatetime: string
+ tasks?: number
+ updatedAt?: string
+ users?: number
+ }
+ Update: {
+ aiTokens?: number
+ companyId?: string
+ createdAt?: string
+ id?: string
+ nextResetDatetime?: string
+ tasks?: number
+ updatedAt?: string
+ users?: number
+ }
+ Relationships: [
+ {
+ foreignKeyName: "fk_companyUsage_company"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "companies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "fk_companyUsage_company"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "company"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "fk_companyUsage_company"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "customFieldTables"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "fk_companyUsage_company"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "integrations"
+ referencedColumns: ["companyId"]
+ },
+ ]
+ }
config: {
Row: {
anonKey: string
@@ -17475,6 +17618,45 @@ export type Database = {
},
]
}
+ plan: {
+ Row: {
+ aiTokensLimit: number
+ createdAt: string
+ id: string
+ name: string
+ public: boolean
+ stripePriceId: string
+ stripeTrialPeriodDays: number
+ tasksLimit: number
+ updatedAt: string
+ userBasedPricing: boolean
+ }
+ Insert: {
+ aiTokensLimit?: number
+ createdAt?: string
+ id?: string
+ name: string
+ public?: boolean
+ stripePriceId: string
+ stripeTrialPeriodDays?: number
+ tasksLimit?: number
+ updatedAt?: string
+ userBasedPricing?: boolean
+ }
+ Update: {
+ aiTokensLimit?: number
+ createdAt?: string
+ id?: string
+ name?: string
+ public?: boolean
+ stripePriceId?: string
+ stripeTrialPeriodDays?: number
+ tasksLimit?: number
+ updatedAt?: string
+ userBasedPricing?: boolean
+ }
+ Relationships: []
+ }
postingGroupInventory: {
Row: {
capacityVarianceAccount: string
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 491337b943..01b24f9038 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -2187,6 +2187,87 @@ export type Database = {
},
]
}
+ companyPlan: {
+ Row: {
+ aiTokensLimit: number
+ createdAt: string
+ id: string
+ planId: string
+ stripeCustomerId: string | null
+ stripeSubscriptionId: string
+ stripeSubscriptionStatus: string
+ subscriptionStartDate: string
+ tasksLimit: number
+ trialPeriodEndsAt: string | null
+ updatedAt: string
+ usersLimit: number
+ }
+ Insert: {
+ aiTokensLimit?: number
+ createdAt?: string
+ id?: string
+ planId: string
+ stripeCustomerId?: string | null
+ stripeSubscriptionId: string
+ stripeSubscriptionStatus?: string
+ subscriptionStartDate: string
+ tasksLimit?: number
+ trialPeriodEndsAt?: string | null
+ updatedAt?: string
+ usersLimit?: number
+ }
+ Update: {
+ aiTokensLimit?: number
+ createdAt?: string
+ id?: string
+ planId?: string
+ stripeCustomerId?: string | null
+ stripeSubscriptionId?: string
+ stripeSubscriptionStatus?: string
+ subscriptionStartDate?: string
+ tasksLimit?: number
+ trialPeriodEndsAt?: string | null
+ updatedAt?: string
+ usersLimit?: number
+ }
+ Relationships: [
+ {
+ foreignKeyName: "fk_companyPlan_company"
+ columns: ["id"]
+ isOneToOne: true
+ referencedRelation: "companies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "fk_companyPlan_company"
+ columns: ["id"]
+ isOneToOne: true
+ referencedRelation: "company"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "fk_companyPlan_company"
+ columns: ["id"]
+ isOneToOne: true
+ referencedRelation: "customFieldTables"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "fk_companyPlan_company"
+ columns: ["id"]
+ isOneToOne: true
+ referencedRelation: "integrations"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "fk_companyPlan_plan"
+ columns: ["planId"]
+ isOneToOne: false
+ referencedRelation: "plan"
+ referencedColumns: ["id"]
+ },
+ ]
+ }
companySettings: {
Row: {
digitalQuoteEnabled: boolean
@@ -2252,6 +2333,68 @@ export type Database = {
},
]
}
+ companyUsage: {
+ Row: {
+ aiTokens: number
+ companyId: string
+ createdAt: string
+ id: string
+ nextResetDatetime: string
+ tasks: number
+ updatedAt: string
+ users: number
+ }
+ Insert: {
+ aiTokens?: number
+ companyId: string
+ createdAt?: string
+ id?: string
+ nextResetDatetime: string
+ tasks?: number
+ updatedAt?: string
+ users?: number
+ }
+ Update: {
+ aiTokens?: number
+ companyId?: string
+ createdAt?: string
+ id?: string
+ nextResetDatetime?: string
+ tasks?: number
+ updatedAt?: string
+ users?: number
+ }
+ Relationships: [
+ {
+ foreignKeyName: "fk_companyUsage_company"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "companies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "fk_companyUsage_company"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "company"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "fk_companyUsage_company"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "customFieldTables"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "fk_companyUsage_company"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "integrations"
+ referencedColumns: ["companyId"]
+ },
+ ]
+ }
config: {
Row: {
anonKey: string
@@ -17475,6 +17618,45 @@ export type Database = {
},
]
}
+ plan: {
+ Row: {
+ aiTokensLimit: number
+ createdAt: string
+ id: string
+ name: string
+ public: boolean
+ stripePriceId: string
+ stripeTrialPeriodDays: number
+ tasksLimit: number
+ updatedAt: string
+ userBasedPricing: boolean
+ }
+ Insert: {
+ aiTokensLimit?: number
+ createdAt?: string
+ id?: string
+ name: string
+ public?: boolean
+ stripePriceId: string
+ stripeTrialPeriodDays?: number
+ tasksLimit?: number
+ updatedAt?: string
+ userBasedPricing?: boolean
+ }
+ Update: {
+ aiTokensLimit?: number
+ createdAt?: string
+ id?: string
+ name?: string
+ public?: boolean
+ stripePriceId?: string
+ stripeTrialPeriodDays?: number
+ tasksLimit?: number
+ updatedAt?: string
+ userBasedPricing?: boolean
+ }
+ Relationships: []
+ }
postingGroupInventory: {
Row: {
capacityVarianceAccount: string
diff --git a/packages/database/supabase/migrations/20250619100940_billing.sql b/packages/database/supabase/migrations/20250619100940_billing.sql
new file mode 100644
index 0000000000..7756b3bcf1
--- /dev/null
+++ b/packages/database/supabase/migrations/20250619100940_billing.sql
@@ -0,0 +1,81 @@
+ALTER TABLE "company" ADD COLUMN "ownerId" TEXT REFERENCES "user"("id") ON DELETE SET NULL;
+
+CREATE TABLE "plan" (
+ "id" TEXT NOT NULL DEFAULT xid(),
+ "name" TEXT NOT NULL,
+ "userBasedPricing" BOOLEAN NOT NULL DEFAULT TRUE,
+ "stripePriceId" TEXT NOT NULL,
+ "tasksLimit" INTEGER NOT NULL DEFAULT 10000,
+ "aiTokensLimit" INTEGER NOT NULL DEFAULT 1000000,
+ "stripeTrialPeriodDays" INTEGER NOT NULL DEFAULT 7,
+ "public" BOOLEAN NOT NULL DEFAULT TRUE,
+ "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
+ "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
+ CONSTRAINT "pk_plan" PRIMARY KEY ("id"),
+ CONSTRAINT "uq_plan_stripePriceId" UNIQUE ("stripePriceId")
+);
+
+ALTER TABLE "plan" ENABLE ROW LEVEL SECURITY;
+
+CREATE POLICY "SELECT" ON "plan"
+ FOR SELECT
+ USING (
+ auth.role() = 'authenticated'
+ );
+
+
+INSERT INTO "plan" ("id", "name", "userBasedPricing", "stripePriceId", "tasksLimit", "aiTokensLimit", "stripeTrialPeriodDays", "public") VALUES
+ ('STARTER', 'Starter', TRUE, 'price_1RgUYhFV6ecOa0XvD37hQOhK', 10000, 1000000, 14, TRUE),
+ ('BUSINESS', 'Business', TRUE, 'price_1RgUZ3FV6ecOa0XvQFLFQsX4', 10000, 1000000, 14, TRUE),
+ ('PARTNER', 'Design Partner', FALSE, 'price_1RgXMSFV6ecOa0XvLQtlhQr0', 10000, 1000000, 14, FALSE);
+
+CREATE TABLE "companyPlan" (
+ "id" TEXT NOT NULL DEFAULT xid(),
+ "planId" TEXT NOT NULL,
+ "tasksLimit" INTEGER NOT NULL DEFAULT 10000,
+ "aiTokensLimit" INTEGER NOT NULL DEFAULT 1000000,
+ "usersLimit" INTEGER NOT NULL DEFAULT 10,
+ "subscriptionStartDate" TIMESTAMP WITH TIME ZONE NOT NULL,
+ "stripeCustomerId" TEXT,
+ "stripeSubscriptionId" TEXT NOT NULL,
+ "stripeSubscriptionStatus" TEXT NOT NULL DEFAULT 'ACTIVE',
+ "trialPeriodEndsAt" TIMESTAMP WITH TIME ZONE,
+ "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
+ "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
+ CONSTRAINT "pk_companyPlan" PRIMARY KEY ("id"),
+ CONSTRAINT "fk_companyPlan_plan" FOREIGN KEY ("planId") REFERENCES "plan"("id") ON DELETE CASCADE,
+ CONSTRAINT "fk_companyPlan_company" FOREIGN KEY ("id") REFERENCES "company"("id") ON DELETE CASCADE
+);
+
+ALTER TABLE "companyPlan" ENABLE ROW LEVEL SECURITY;
+
+CREATE POLICY "SELECT" ON "companyPlan"
+ FOR SELECT
+ USING (
+ auth.role() = 'authenticated' AND "id" IN (
+ SELECT "companyId" FROM "userToCompany" WHERE "userId" = auth.uid()::text
+ )
+ );
+
+CREATE TABLE "companyUsage" (
+ "id" TEXT NOT NULL DEFAULT xid(),
+ "users" INTEGER NOT NULL DEFAULT 0,
+ "tasks" INTEGER NOT NULL DEFAULT 0,
+ "aiTokens" INTEGER NOT NULL DEFAULT 0,
+ "nextResetDatetime" TIMESTAMP WITH TIME ZONE NOT NULL,
+ "companyId" TEXT NOT NULL,
+ "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
+ "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
+ CONSTRAINT "pk_companyUsage" PRIMARY KEY ("id"),
+ CONSTRAINT "fk_companyUsage_company" FOREIGN KEY ("companyId") REFERENCES "company"("id") ON DELETE CASCADE
+);
+
+CREATE INDEX "idx_companyUsage_companyId" ON "companyUsage" ("companyId");
+
+CREATE POLICY "SELECT" ON "companyUsage"
+ FOR SELECT
+ USING (
+ auth.role() = 'authenticated' AND "id" IN (
+ SELECT "companyId" FROM "userToCompany" WHERE "userId" = auth.uid()::text
+ )
+ );
\ No newline at end of file
diff --git a/packages/database/supabase/migrations/20250702170717_self-signup.sql b/packages/database/supabase/migrations/20250702170717_self-signup.sql
deleted file mode 100644
index ed4d0c07e7..0000000000
--- a/packages/database/supabase/migrations/20250702170717_self-signup.sql
+++ /dev/null
@@ -1 +0,0 @@
-ALTER TABLE "company" ADD COLUMN "ownerId" TEXT REFERENCES "user"("id") ON DELETE SET NULL;
\ No newline at end of file