MCPcopy
hub / github.com/CodebuffAI/codebuff / getSubscriptionLimits

Function getSubscriptionLimits

packages/billing/src/subscription.ts:152–189  ·  view source on GitHub ↗
(params: {
  userId: string
  logger: Logger
  conn?: DbConn
  tier?: number | null
})

Source from the content-addressed store, hash-verified

150 * Checks `limit_override` first, then falls back to the default tier constants.
151 */
152export async function getSubscriptionLimits(params: {
153 userId: string
154 logger: Logger
155 conn?: DbConn
156 tier?: number | null
157}): Promise<SubscriptionLimits> {
158 const { userId, logger, conn = db, tier } = params
159
160 const overrides = await conn
161 .select()
162 .from(schema.limitOverride)
163 .where(eq(schema.limitOverride.user_id, userId))
164 .limit(1)
165
166 if (overrides.length > 0) {
167 const o = overrides[0]
168 logger.debug(
169 { userId, creditsPerBlock: o.credits_per_block },
170 'Using limit override for user',
171 )
172 return {
173 creditsPerBlock: o.credits_per_block,
174 blockDurationHours: o.block_duration_hours,
175 weeklyCreditsLimit: o.weekly_credit_limit,
176 }
177 }
178
179 const tierConfig =
180 tier != null && tier in SUBSCRIPTION_TIERS
181 ? SUBSCRIPTION_TIERS[tier as SubscriptionTierPrice]
182 : DEFAULT_TIER
183
184 return {
185 creditsPerBlock: tierConfig.creditsPerBlock,
186 blockDurationHours: tierConfig.blockDurationHours,
187 weeklyCreditsLimit: tierConfig.weeklyCreditsLimit,
188 }
189}
190
191// ---------------------------------------------------------------------------
192// Weekly usage tracking

Callers 4

GETFunction · 0.90
checkRateLimitFunction · 0.85

Calls 1

fromMethod · 0.80

Tested by

no test coverage detected