* Add debug logging for 402 credit check failures
- Add comprehensive logging when credit check fails in supaCheckTeamCredits
- Log all ACUC fields and computed values to help diagnose incorrect credit calculations
- Add minimumSource tracking in checkCreditsMiddleware to debug how minimum credits is computed
- Remove req.body from error logs to avoid leaking sensitive user data
Co-Authored-By: Micah Stairs <micah.stairs@gmail.com>
* Revert changes in shared.ts per user request
Co-Authored-By: Micah Stairs <micah.stairs@gmail.com>
---------
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Micah Stairs <micah.stairs@gmail.com>
* fix: add Number() coercion to prevent string concatenation in credit calculations
Postgres numeric columns may be returned as strings by Supabase RPC calls.
When arithmetic operations are performed on these string values, JavaScript
does string concatenation instead of numeric addition, causing false
'Insufficient credits' errors even when users have remaining credits.
This fix adds Number() coercion to all ACUC numeric fields before arithmetic:
- credit_billing.ts: adjusted_credits_used, total_credits_sum, price_credits, remaining_credits
- batch_billing.ts: credits_used, adjusted_credits_used, remaining_credits in cache updates
- shared.ts: remaining_credits, price_credits in authMiddleware
Co-Authored-By: himanshu@sideguide.dev <himanshu@sideguide.dev>
* fix: add Number() coercion to auto_charge.ts to prevent string concatenation
Fixes the same string concatenation bug in auto_charge.ts:
- _autoChargeScale: lines 358-364 (remainingCredits calculation after auto-recharge)
- _autoChargeSelfServe: lines 615-620 (remainingCredits calculation after auto-recharge)
When chunk.remaining_credits is a string (e.g., '29986'), adding AUTO_RECHARGE_CREDITS
would produce '299861000' instead of 30986.
Co-Authored-By: himanshu@sideguide.dev <himanshu@sideguide.dev>
* fix: add Number() coercion to price.credits in auto_charge.ts
price.credits also comes from Supabase/Postgres and could be returned as a string,
causing the same string concatenation bug.
---------
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: himanshu@sideguide.dev <himanshu@sideguide.dev>
Co-authored-by: Himanshu Gupta <thinktank.himanshu@gmail.com>
* fix(api/search): saner billing logic
- search.credits_cost will only include the credits used by the search itself
- scrape.credits_cost will now include the credits used by the scrapes
- enterprise option will be stored even with zdr
* fix logic in search v1