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

Function processAndGrantCredit

packages/billing/src/grant-credits.ts:292–327  ·  view source on GitHub ↗
(params: {
  userId: string
  amount: number
  type: GrantType
  description: string
  expiresAt: Date | null
  operationId: string
  logger: Logger
})

Source from the content-addressed store, hash-verified

290 * Used for standalone credit grants that need retry logic and failure tracking.
291 */
292export async function processAndGrantCredit(params: {
293 userId: string
294 amount: number
295 type: GrantType
296 description: string
297 expiresAt: Date | null
298 operationId: string
299 logger: Logger
300}): Promise<void> {
301 const { operationId, logger } = params
302
303 try {
304 await withRetry(() => grantCreditOperation(params), {
305 maxRetries: 3,
306 retryIf: () => true,
307 onRetry: (error, attempt) => {
308 logger.warn(
309 { operationId, attempt, error },
310 `processAndGrantCredit retry ${attempt}`,
311 )
312 },
313 })
314 } catch (error: any) {
315 await logSyncFailure({
316 id: operationId,
317 errorMessage: error.message,
318 provider: 'internal',
319 logger,
320 })
321 logger.error(
322 { operationId, error },
323 'processAndGrantCredit failed after retries, logged to sync_failure',
324 )
325 throw error
326 }
327}
328
329export async function grantSignupCredits(params: {
330 userId: string

Callers 4

processAutoTopupPaymentFunction · 0.90
POSTFunction · 0.90
grantSignupCreditsFunction · 0.85

Calls 3

withRetryFunction · 0.90
logSyncFailureFunction · 0.90
grantCreditOperationFunction · 0.85

Tested by

no test coverage detected