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

Function resolvePlanTypesByWorkspaceId

apps/sim/lib/billing/cleanup-dispatcher.ts:136–186  ·  view source on GitHub ↗
(
  rows: WorkspaceCleanupScopeRow[]
)

Source from the content-addressed store, hash-verified

134}
135
136async function resolvePlanTypesByWorkspaceId(
137 rows: WorkspaceCleanupScopeRow[]
138): Promise<Map<string, PlanCategory>> {
139 const userScopedRows = rows.filter((row) => row.workspaceMode !== WORKSPACE_MODE.ORGANIZATION)
140 const userPlanByBilledUserId = await resolvePersonalPlanTypesByBilledUserId(userScopedRows)
141 const entries = await Promise.all(
142 rows.map(async (row) => {
143 if (row.workspaceMode === WORKSPACE_MODE.ORGANIZATION) {
144 const organizationId = isOrganizationWorkspace(row) ? row.organizationId : null
145 if (!organizationId) {
146 logger.error('Skipping cleanup for malformed organization workspace', {
147 workspaceId: row.id,
148 organizationId: row.organizationId,
149 })
150 return null
151 }
152
153 try {
154 const subscription = await getOrganizationSubscription(organizationId, {
155 onError: 'throw',
156 })
157 if (!subscription) {
158 logger.warn('Skipping cleanup for organization workspace without an org subscription', {
159 workspaceId: row.id,
160 organizationId,
161 })
162 return null
163 }
164
165 return [row.id, getPlanType(subscription?.plan)] as const
166 } catch (error) {
167 logger.error('Skipping cleanup for organization workspace after plan lookup failed', {
168 workspaceId: row.id,
169 organizationId,
170 error,
171 })
172 return null
173 }
174 }
175
176 const plan = userPlanByBilledUserId.get(row.billedAccountUserId)
177 if (plan === undefined) {
178 return null
179 }
180
181 return [row.id, plan] as const
182 })
183 )
184
185 return new Map(entries.filter((entry): entry is PlanResolutionEntry => entry !== null))
186}
187
188async function buildCleanupRunner(jobType: CleanupJobType): Promise<EnqueueOptions['runner']> {
189 const cleanupRunner = await (async () => {

Callers 1

forEachCleanupChunkFunction · 0.85

Calls 7

isOrganizationWorkspaceFunction · 0.90
getPlanTypeFunction · 0.90
errorMethod · 0.80
warnMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected