(params: {
userId: string
amount: number
type: GrantType
description: string
expiresAt: Date | null
operationId: string
logger: Logger
})
| 290 | * Used for standalone credit grants that need retry logic and failure tracking. |
| 291 | */ |
| 292 | export 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 | |
| 329 | export async function grantSignupCredits(params: { |
| 330 | userId: string |
no test coverage detected