Skip to content

Commit ab32bcd

Browse files
authored
Merge pull request #637 from trycompai/claudio/comp-121-enable-database-synced-frameworks
[dev] [claudfuen] claudio/comp-121-enable-database-synced-frameworks
2 parents 6d455c4 + 912e87d commit ab32bcd

File tree

233 files changed

+13194
-27591
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

233 files changed

+13194
-27591
lines changed

apps/app/next.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const config: NextConfig = {
1717
},
1818
],
1919
},
20-
transpilePackages: ["@comp/ui", "@comp/data"],
20+
transpilePackages: ["@comp/ui"],
2121
logging: {
2222
fetches: {
2323
fullUrl: process.env.LOG_FETCHES === "true",

apps/app/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"@browserbasehq/sdk": "^2.5.0",
2626
"@calcom/atoms": "^1.0.102-framer",
2727
"@calcom/embed-react": "^1.5.3",
28-
"@comp/data": "workspace:*",
2928
"@comp/db": "workspace:*",
3029
"@comp/notifications": "workspace:*",
3130
"@date-fns/tz": "^1.2.0",
@@ -58,6 +57,7 @@
5857
"@vercel/sdk": "^1.7.1",
5958
"ai": "^4.3.10",
6059
"argon2": "^0.43.0",
60+
"axios": "^1.9.0",
6161
"better-auth": "^1.2.7",
6262
"bun": "^1.2.10",
6363
"crypto": "^1.0.1",
@@ -67,7 +67,6 @@
6767
"geist": "^1.3.1",
6868
"highlight.js": "^11.11.1",
6969
"immer": "^10.1.1",
70-
"ky": "^1.8.1",
7170
"languine": "^3.1.4",
7271
"marked": "^15.0.11",
7372
"motion": "^12.9.2",

apps/app/src/actions/organization/create-organization-action.ts

Lines changed: 11 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
"use server";
22

3-
import { performance } from "node:perf_hooks";
3+
import type { newOrgSequence } from "@/jobs/tasks/marketing/new-org-sequence";
44
import { auth } from "@/utils/auth";
55
import { db } from "@comp/db";
6+
import { tasks } from "@trigger.dev/sdk/v3";
67
import { revalidatePath } from "next/cache";
78
import { headers } from "next/headers";
9+
import { performance } from "node:perf_hooks";
810
import { Resend } from "resend";
911
import { authActionClient } from "../safe-action";
1012
import { organizationSchema } from "../schema";
1113
import { createStripeCustomer } from "./lib/create-stripe-customer";
12-
import {
13-
createControlArtifacts,
14-
createFrameworkInstance,
15-
createOrganizationPolicies,
16-
createOrganizationTasks,
17-
getRelevantControls,
18-
} from "./lib/utils";
19-
import { env } from "@/env.mjs";
20-
import ky from "ky";
21-
import { tasks } from "@trigger.dev/sdk/v3";
22-
import type { newOrgSequence } from "@/jobs/tasks/marketing/new-org-sequence";
14+
import { initializeOrganization } from "./lib/initialize-organization";
2315

2416
export const createOrganizationAction = authActionClient
2517
.schema(organizationSchema)
@@ -31,7 +23,7 @@ export const createOrganizationAction = authActionClient
3123
},
3224
})
3325
.action(async ({ parsedInput, ctx }) => {
34-
const { name, frameworks, website } = parsedInput;
26+
const { name, frameworkIds, website } = parsedInput;
3527
const { id: userId } = ctx.user;
3628

3729
if (!name) {
@@ -109,109 +101,25 @@ export const createOrganizationAction = authActionClient
109101
}
110102

111103
start = performance.now();
104+
105+
// Update stripe ID and website
112106
await db.organization.update({
113107
where: { id: organizationId },
114108
data: { stripeCustomerId, website },
115109
});
110+
111+
116112
timings.updateOrganizationWithStripeId =
117113
(performance.now() - start) / 1000;
118114

119115
// --- Main Creation Logic (Inside Transaction) ---
120116
const transactionStart = performance.now();
121-
const result = await db.$transaction(
122-
async (tx) => {
123-
// REVISIT: Consider if more granular error handling/logging is needed within the transaction
124117

125-
start = performance.now();
126-
const relevantControls = getRelevantControls(frameworks);
127-
const getRelevantControlsTime =
128-
(performance.now() - start) / 1000;
129118

130-
start = performance.now();
131-
// Pass the transaction client `tx` to the helper
132-
const organizationFrameworks = await Promise.all(
133-
frameworks.map(
134-
(frameworkId) =>
135-
createFrameworkInstance(
136-
organizationId,
137-
frameworkId,
138-
tx,
139-
), // Pass tx
140-
),
141-
);
142-
const createFrameworkInstancesTime =
143-
(performance.now() - start) / 1000;
119+
// Initialize Organization
120+
await initializeOrganization({frameworkIds, organizationId});
144121

145-
// Fetch DB controls needed for Task creation
146-
const dbControlsList = await tx.control.findMany({
147-
where: {
148-
organizationId,
149-
name: { in: relevantControls.map((c) => c.name) },
150-
},
151-
select: { id: true, name: true },
152-
});
153-
const dbControlsMap = new Map<string, { id: string }>();
154-
for (const control of dbControlsList) {
155-
dbControlsMap.set(control.name, control);
156-
}
157-
158-
// Run policy and task creation in parallel
159-
start = performance.now();
160-
const [policiesForFrameworks, tasksCreationResult] =
161-
await Promise.all([
162-
createOrganizationPolicies(
163-
organizationId,
164-
relevantControls,
165-
userId,
166-
tx,
167-
), // Pass tx
168-
createOrganizationTasks(
169-
organizationId,
170-
relevantControls,
171-
dbControlsMap, // Pass the map
172-
userId,
173-
tx,
174-
),
175-
]);
176-
const createPoliciesAndTasksParallelTime =
177-
(performance.now() - start) / 1000;
178-
179-
start = performance.now();
180-
// Pass the transaction client `tx` to the helper
181-
await createControlArtifacts(
182-
organizationId,
183-
organizationFrameworks.map((framework) => framework.id),
184-
relevantControls,
185-
policiesForFrameworks,
186-
tx, // Pass tx
187-
);
188-
const createControlArtifactsTime =
189-
(performance.now() - start) / 1000;
190-
191-
// Return timings calculated inside the transaction scope
192-
return {
193-
getRelevantControlsTime,
194-
createFrameworkInstancesTime,
195-
createPoliciesAndTasksParallelTime,
196-
createControlArtifactsTime,
197-
organizationFrameworks, // Need this for the final return value potentially
198-
};
199-
},
200-
{
201-
maxWait: 15000,
202-
timeout: 40000,
203-
},
204-
);
205122
timings.transaction = (performance.now() - transactionStart) / 1000;
206-
207-
// Assign timings from the transaction result
208-
timings.getRelevantControls = result.getRelevantControlsTime;
209-
timings.createFrameworkInstances =
210-
result.createFrameworkInstancesTime;
211-
timings.createPoliciesAndTasksParallel =
212-
result.createPoliciesAndTasksParallelTime;
213-
timings.createControlArtifacts = result.createControlArtifactsTime;
214-
215123
timings.total = (performance.now() - totalStart) / 1000;
216124
console.log("createOrganizationAction timings (s):", timings);
217125
console.warn(

0 commit comments

Comments
 (0)