Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
RouteServiceProvider
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 boot
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 configureRateLimiting
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace App\Providers;
4
5use Illuminate\Cache\RateLimiting\Limit;
6use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
7use Illuminate\Http\Request;
8use Illuminate\Support\Facades\RateLimiter;
9use Illuminate\Support\Facades\Route;
10
11class RouteServiceProvider extends ServiceProvider
12{
13    /**
14     * The path to the "home" route for your application.
15     *
16     * This is used by Laravel authentication to redirect users after login.
17     *
18     * @var string
19     */
20    public const HOME = '/home';
21
22    // protected $namespace = 'App\\Http\\Controllers';
23
24    /**
25     * Define your route model bindings, pattern filters, etc.
26     *
27     * @return void
28     */
29    public function boot()
30    {
31        $this->configureRateLimiting();
32
33        $this->routes(function () {
34            Route::prefix('api')
35                ->middleware('api')
36                ->namespace($this->namespace)
37                ->group(base_path('routes/api.php'));
38
39            Route::middleware('web')
40                ->namespace($this->namespace)
41                ->group(base_path('routes/web.php'));
42        });
43    }
44
45    /**
46     * Configure the rate limiters for the application.
47     *
48     * @return void
49     */
50    protected function configureRateLimiting()
51    {
52        RateLimiter::for('api', function (Request $request) {
53            return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
54        });
55
56        // FIRE-1147 / FIRE-1151: rate-limit G3W API calls across all parallel
57        // queue jobs. Sized conservatively at 60/min until the actual G3W rate
58        // limit is confirmed — easy to raise once measured. Used by jobs that
59        // wrap themselves with (new RateLimited('g3w')) middleware.
60        RateLimiter::for('g3w', fn () => Limit::perMinute(60)->by('g3w-global'));
61
62        // FIRE-1077 follow-up: Cofrai parallel to 'g3w'. Separate bucket so the
63        // two integrations don't share an external-API budget. Consumed by
64        // App\Jobs\SyncCofraiRegion + App\Jobs\SyncCofraiClientsForRegion via
65        // (new RateLimited('cofrai')) middleware.
66        //
67        // NOTE: this only protects QUEUED-job paths. Synchronous direct calls
68        // through CofraiService::request (invoked from controllers) bypass the
69        // limiter — intentional for now to keep the change small. Revisit if
70        // we see Cofrai 429s coming from request-time traffic.
71        RateLimiter::for('cofrai', fn () => Limit::perMinute(60)->by('cofrai-global'));
72
73        // Google Drive API quota — Drive Files: ~1000 reads/100s/user, plenty
74        // of headroom at 60/min. Used by ImportFinanceDriveFile (FIRE-1151).
75        RateLimiter::for('drive', fn () => Limit::perMinute(60)->by('drive-global'));
76
77        // FIRE-1147: SendGrid bucket shared by all App\Jobs\Email\* jobs.
78        // 100/min is conservative for our typical SendGrid plan; raise once
79        // the actual rate-limit ceiling is confirmed with the email provider.
80        RateLimiter::for('sendgrid', fn () => Limit::perMinute(100)->by('sendgrid-global'));
81    }
82}