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

Function createOrganizationForTeamPlan

apps/sim/lib/billing/organization.ts:54–98  ·  view source on GitHub ↗
(
  userId: string,
  userName?: string,
  userEmail?: string,
  organizationSlug?: string
)

Source from the content-addressed store, hash-verified

52}
53
54export async function createOrganizationForTeamPlan(
55 userId: string,
56 userName?: string,
57 userEmail?: string,
58 organizationSlug?: string
59): Promise<string> {
60 try {
61 const existingOrgId = await getUserOwnedOrganization(userId)
62 if (existingOrgId) {
63 return existingOrgId
64 }
65
66 const organizationName = userName || `${userEmail || 'User'}'s Team`
67 const slug =
68 organizationSlug ||
69 `${userId}-team-${Date.now()}`
70 .toLowerCase()
71 .replace(/[^a-z0-9-_]+/g, '-')
72 .replace(/^-|-$/g, '')
73
74 const { organizationId: orgId } = await createOrganizationWithOwner({
75 ownerUserId: userId,
76 name: organizationName,
77 slug,
78 metadata: {
79 createdForTeamPlan: true,
80 originalUserId: userId,
81 },
82 })
83
84 logger.info('Created organization for team/enterprise plan', {
85 userId,
86 organizationId: orgId,
87 organizationName,
88 })
89
90 return orgId
91 } catch (error) {
92 logger.error('Failed to create organization for team/enterprise plan', {
93 userId,
94 error,
95 })
96 throw error
97 }
98}
99
100export async function ensureOrganizationForTeamSubscription(
101 subscription: SubscriptionData

Callers 2

route.tsFile · 0.90

Calls 5

getUserOwnedOrganizationFunction · 0.85
infoMethod · 0.80
errorMethod · 0.80
replaceMethod · 0.65

Tested by

no test coverage detected