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

Function initializeUserUsageLimit

apps/sim/lib/billing/core/usage.ts:398–425  ·  view source on GitHub ↗

* Initialize usage limits for a new user

(userId: string)

Source from the content-addressed store, hash-verified

396 * Initialize usage limits for a new user
397 */
398async function initializeUserUsageLimit(userId: string): Promise<void> {
399 // Check if user already has usage stats
400 const existingStats = await db
401 .select()
402 .from(userStats)
403 .where(eq(userStats.userId, userId))
404 .limit(1)
405
406 if (existingStats.length > 0) {
407 return
408 }
409
410 const subscription = await getHighestPrioritySubscription(userId)
411 const orgScoped = isOrgScopedSubscription(subscription, userId)
412
413 await db.insert(userStats).values({
414 id: generateId(),
415 userId,
416 currentUsageLimit: orgScoped ? null : getFreeTierLimit().toString(),
417 usageLimitUpdatedAt: new Date(),
418 })
419
420 logger.info('Initialized user stats', {
421 userId,
422 plan: subscription?.plan || 'free',
423 hasIndividualLimit: !orgScoped,
424 })
425}
426
427/**
428 * Update a user's custom usage limit

Callers

nothing calls this directly

Calls 7

isOrgScopedSubscriptionFunction · 0.90
generateIdFunction · 0.90
getFreeTierLimitFunction · 0.90
infoMethod · 0.80
eqFunction · 0.50
toStringMethod · 0.45

Tested by

no test coverage detected