MCPcopy Index your code
hub / github.com/simstudioai/sim / createWorkspace

Function createWorkspace

apps/sim/app/api/workspaces/route.ts:277–408  ·  view source on GitHub ↗
({
  userId,
  name,
  skipDefaultWorkflow = false,
  explicitColor,
  organizationId,
  workspaceMode,
  billedAccountUserId,
}: CreateWorkspaceParams)

Source from the content-addressed store, hash-verified

275}
276
277async function createWorkspace({
278 userId,
279 name,
280 skipDefaultWorkflow = false,
281 explicitColor,
282 organizationId,
283 workspaceMode,
284 billedAccountUserId,
285}: CreateWorkspaceParams) {
286 const workspaceId = generateId()
287 const workflowId = generateId()
288 const now = new Date()
289 const color = explicitColor || getRandomWorkspaceColor()
290
291 try {
292 await db.transaction(async (tx) => {
293 await tx.insert(workspace).values({
294 id: workspaceId,
295 name,
296 color,
297 ownerId: userId,
298 organizationId,
299 workspaceMode,
300 billedAccountUserId,
301 allowPersonalApiKeys: true,
302 createdAt: now,
303 updatedAt: now,
304 })
305
306 const permissionRows = [
307 {
308 id: generateId(),
309 entityType: 'workspace' as const,
310 entityId: workspaceId,
311 userId,
312 permissionType: 'admin' as const,
313 createdAt: now,
314 updatedAt: now,
315 },
316 ]
317
318 if (
319 workspaceMode === WORKSPACE_MODE.ORGANIZATION &&
320 billedAccountUserId &&
321 billedAccountUserId !== userId
322 ) {
323 permissionRows.push({
324 id: generateId(),
325 entityType: 'workspace' as const,
326 entityId: workspaceId,
327 userId: billedAccountUserId,
328 permissionType: 'admin' as const,
329 createdAt: now,
330 updatedAt: now,
331 })
332 }
333
334 await tx.insert(permissions).values(permissionRows)

Callers 2

route.tsFile · 0.70
createDefaultWorkspaceFunction · 0.70

Calls 8

generateIdFunction · 0.90
getRandomWorkspaceColorFunction · 0.90
getWorkspaceInvitePolicyFunction · 0.90
infoMethod · 0.80
errorMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected