Skip to content

refactor(billing): extract BillingQuotaService from requireQuota middleware #3748

@PierreBrisorgueil

Description

@PierreBrisorgueil

Summary

Promote Trawl's BillingQuotaService extraction up to Devkit so every downstream benefits.

Trawl extracted the quota/meter enforcement logic from billing.requireQuota.js into a dedicated BillingQuotaService.assertCanExecute(...) for testability and reuse (sharing the enforcement path with MCP tool callers). This promote-up task ports that extraction to Devkit.

Changes

  • New: modules/billing/services/billing.quota.service.jsassertCanExecute({ orgId, organization, user, resource, action }) — single source of truth for both legacy quota + meter mode enforcement
  • Refactor: modules/billing/middlewares/billing.requireQuota.js — now a thin wrapper around BillingQuotaService, behavior unchanged
  • New tests: modules/billing/tests/billing.quota.service.unit.tests.js — direct service-layer unit tests
  • Updated tests: modules/billing/tests/billing.quota.unit.tests.js — adapted to mock at the service boundary

Why

  • Pure refactor — behavior is identical, Trawl has been running this in prod for weeks
  • After merge + /update-stack, Trawl's billing.requireQuota.js becomes byte-compatible with Devkit's
  • All other downstreams (comes, montaine, pierreb, ism) inherit the service-layer extraction on their next /update-stack

Plan reference

Infra plan Task D.1: docs/superpowers/plans/2026-05-30-trawl-devkit-perfect-alignment.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    RefactorNeither fixes a bug nor adds a feat

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions