MCPcopy
hub / github.com/simstudioai/sim / hasWorkspaceInboxAccess

Function hasWorkspaceInboxAccess

apps/sim/lib/billing/core/subscription.ts:547–573  ·  view source on GitHub ↗
(workspaceId: string)

Source from the content-addressed store, hash-verified

545 * - the billed user has an individual Max/enterprise subscription (personal workspace).
546 */
547export async function hasWorkspaceInboxAccess(workspaceId: string): Promise<boolean> {
548 try {
549 if (isInboxEnabled) return true
550 if (!isBillingEnabled) return true
551
552 const { getWorkspaceWithOwner } = await import('@/lib/workspaces/permissions/utils')
553 const ws = await getWorkspaceWithOwner(workspaceId, { includeArchived: true })
554 if (!ws) return false
555
556 if (ws.organizationId) {
557 if (await isOrganizationBillingBlocked(ws.organizationId)) return false
558 const orgSub = await getOrganizationSubscriptionUsable(ws.organizationId)
559 return !!orgSub && isInboxEntitledPlan(orgSub.plan)
560 }
561
562 const [billedSub, billingStatus] = await Promise.all([
563 getHighestPrioritySubscription(ws.billedAccountUserId),
564 getEffectiveBillingStatus(ws.billedAccountUserId),
565 ])
566 if (!billedSub) return false
567 if (!hasUsableSubscriptionAccess(billedSub.status, billingStatus.billingBlocked)) return false
568 return isInboxEntitledPlan(billedSub.plan)
569 } catch (error) {
570 logger.error('Error checking workspace inbox access', { error, workspaceId })
571 return false
572 }
573}
574
575/**
576 * Whether a workspace should RETAIN its provisioned inbox (Sim Mailer)

Callers 4

route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90

Calls 8

getWorkspaceWithOwnerFunction · 0.85
isInboxEntitledPlanFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected