2026-01-15 01:13:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
2026-01-17 02:46:30 +00:00
|
|
|
use App\Listeners\StripeEventListener;
|
2026-01-18 19:46:27 +00:00
|
|
|
use App\Models\Language;
|
|
|
|
|
use App\Models\Media;
|
|
|
|
|
use App\Models\Post;
|
|
|
|
|
use App\Models\PostPlatform;
|
|
|
|
|
use App\Models\SocialAccount;
|
2026-01-17 17:44:37 +00:00
|
|
|
use App\Models\Subscription;
|
|
|
|
|
use App\Models\SubscriptionItem;
|
2026-01-18 19:46:27 +00:00
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Workspace;
|
|
|
|
|
use App\Models\WorkspaceHashtag;
|
|
|
|
|
use App\Models\WorkspaceInvite;
|
|
|
|
|
use App\Models\WorkspaceLabel;
|
2026-01-17 02:46:30 +00:00
|
|
|
use App\Socialite\InstagramProvider;
|
2026-01-15 17:24:39 +00:00
|
|
|
use App\Socialite\LinkedInPageExtendSocialite;
|
2026-01-15 01:13:44 +00:00
|
|
|
use Carbon\CarbonImmutable;
|
2026-01-18 19:46:27 +00:00
|
|
|
use Illuminate\Auth\Notifications\ResetPassword;
|
|
|
|
|
use Illuminate\Auth\Notifications\VerifyEmail;
|
2026-03-29 23:14:23 +00:00
|
|
|
use Illuminate\Cache\RateLimiting\Limit;
|
feat: implement MCP server with tools, Post API tests, auth middleware
- Create TryPostServer MCP server with 17 tools:
Post (List, Get, Create, Delete), Hashtag (List, Create, Update, Delete),
Label (List, Create, Update, Delete), Workspace (Get),
ApiKey (List, Create, Delete)
- Create AuthenticateMcpToken middleware (logs in workspace owner)
- Register mcp.auth middleware alias in bootstrap/app.php
- Create routes/ai.php with mcp.trypost.test subdomain
- Add PostApiTest with 6 tests (list, show, create, delete, isolation)
- Fix PostApiTest assertions for pagination/resource wrapping
- 704 tests passing, frontend build passing
2026-03-29 23:30:36 +00:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2026-01-18 19:46:27 +00:00
|
|
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
2026-03-29 23:14:23 +00:00
|
|
|
use Illuminate\Http\Request;
|
2026-01-18 19:46:27 +00:00
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
2026-01-15 01:13:44 +00:00
|
|
|
use Illuminate\Support\Facades\Date;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
use Illuminate\Support\Facades\Event;
|
2026-03-29 23:14:23 +00:00
|
|
|
use Illuminate\Support\Facades\RateLimiter;
|
2026-01-15 01:13:44 +00:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
|
use Illuminate\Validation\Rules\Password;
|
2026-01-17 17:44:37 +00:00
|
|
|
use Laravel\Cashier\Cashier;
|
2026-01-17 02:46:30 +00:00
|
|
|
use Laravel\Cashier\Events\WebhookReceived;
|
2026-01-18 19:46:27 +00:00
|
|
|
use Laravel\Nightwatch\Facades\Nightwatch;
|
|
|
|
|
use Laravel\Nightwatch\Records\CacheEvent;
|
2026-01-17 02:46:30 +00:00
|
|
|
use Laravel\Socialite\Facades\Socialite;
|
|
|
|
|
use SocialiteProviders\Facebook\FacebookExtendSocialite;
|
2026-01-15 01:13:44 +00:00
|
|
|
use SocialiteProviders\LinkedIn\LinkedInExtendSocialite;
|
|
|
|
|
use SocialiteProviders\Manager\SocialiteWasCalled;
|
2026-01-18 16:10:01 +00:00
|
|
|
use SocialiteProviders\Pinterest\PinterestExtendSocialite;
|
2026-01-15 01:13:44 +00:00
|
|
|
use SocialiteProviders\TikTok\TikTokExtendSocialite;
|
|
|
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Register any application services.
|
|
|
|
|
*/
|
|
|
|
|
public function register(): void
|
|
|
|
|
{
|
feat: implement MCP server with tools, Post API tests, auth middleware
- Create TryPostServer MCP server with 17 tools:
Post (List, Get, Create, Delete), Hashtag (List, Create, Update, Delete),
Label (List, Create, Update, Delete), Workspace (Get),
ApiKey (List, Create, Delete)
- Create AuthenticateMcpToken middleware (logs in workspace owner)
- Register mcp.auth middleware alias in bootstrap/app.php
- Create routes/ai.php with mcp.trypost.test subdomain
- Add PostApiTest with 6 tests (list, show, create, delete, isolation)
- Fix PostApiTest assertions for pagination/resource wrapping
- 704 tests passing, frontend build passing
2026-03-29 23:30:36 +00:00
|
|
|
if ($this->app->environment('local') && class_exists(\Laravel\Telescope\TelescopeServiceProvider::class)) {
|
|
|
|
|
$this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
|
|
|
|
|
$this->app->register(TelescopeServiceProvider::class);
|
|
|
|
|
}
|
2026-01-15 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Bootstrap any application services.
|
|
|
|
|
*/
|
|
|
|
|
public function boot(): void
|
|
|
|
|
{
|
|
|
|
|
$this->configureDefaults();
|
2026-01-18 19:46:27 +00:00
|
|
|
$this->configureMorphMap();
|
2026-03-29 23:14:23 +00:00
|
|
|
$this->configureRateLimiting();
|
2026-01-15 01:13:44 +00:00
|
|
|
$this->configureSocialite();
|
2026-01-17 02:46:30 +00:00
|
|
|
$this->configureStripeWebhooks();
|
2026-01-17 17:44:37 +00:00
|
|
|
|
|
|
|
|
Cashier::useSubscriptionModel(Subscription::class);
|
|
|
|
|
Cashier::useSubscriptionItemModel(SubscriptionItem::class);
|
2026-01-17 02:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-18 19:46:27 +00:00
|
|
|
protected function configureMorphMap(): void
|
|
|
|
|
{
|
|
|
|
|
Relation::enforceMorphMap([
|
|
|
|
|
'language' => Language::class,
|
|
|
|
|
'media' => Media::class,
|
|
|
|
|
'post' => Post::class,
|
|
|
|
|
'postPlatform' => PostPlatform::class,
|
|
|
|
|
'socialAccount' => SocialAccount::class,
|
|
|
|
|
'subscription' => Subscription::class,
|
|
|
|
|
'subscriptionItem' => SubscriptionItem::class,
|
|
|
|
|
'user' => User::class,
|
|
|
|
|
'workspace' => Workspace::class,
|
|
|
|
|
'workspaceHashtag' => WorkspaceHashtag::class,
|
|
|
|
|
'workspaceInvite' => WorkspaceInvite::class,
|
|
|
|
|
'workspaceLabel' => WorkspaceLabel::class,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-29 23:14:23 +00:00
|
|
|
protected function configureRateLimiting(): void
|
|
|
|
|
{
|
|
|
|
|
RateLimiter::for('api', function (Request $request) {
|
|
|
|
|
if ($this->app->environment('local')) {
|
|
|
|
|
return Limit::none();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Limit::perMinute(60)->by($request->workspace?->id ?: $request->ip());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-17 02:46:30 +00:00
|
|
|
protected function configureStripeWebhooks(): void
|
|
|
|
|
{
|
|
|
|
|
Event::listen(WebhookReceived::class, StripeEventListener::class);
|
2026-01-15 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function configureSocialite(): void
|
|
|
|
|
{
|
2026-01-17 02:46:30 +00:00
|
|
|
// Instagram Business Login
|
|
|
|
|
Socialite::extend('instagram', function ($app) {
|
|
|
|
|
$config = $app['config']['services.instagram'];
|
|
|
|
|
|
|
|
|
|
return Socialite::buildProvider(InstagramProvider::class, $config);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Event::listen(SocialiteWasCalled::class, FacebookExtendSocialite::class);
|
2026-01-15 01:13:44 +00:00
|
|
|
Event::listen(SocialiteWasCalled::class, LinkedInExtendSocialite::class);
|
|
|
|
|
Event::listen(SocialiteWasCalled::class, LinkedInPageExtendSocialite::class);
|
2026-01-18 16:10:01 +00:00
|
|
|
Event::listen(SocialiteWasCalled::class, PinterestExtendSocialite::class);
|
2026-01-15 01:13:44 +00:00
|
|
|
Event::listen(SocialiteWasCalled::class, TikTokExtendSocialite::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function configureDefaults(): void
|
|
|
|
|
{
|
|
|
|
|
Date::use(CarbonImmutable::class);
|
|
|
|
|
|
2026-01-18 19:46:27 +00:00
|
|
|
// Disable wrapping of JSON resources
|
|
|
|
|
JsonResource::withoutWrapping();
|
feat: implement MCP server with tools, Post API tests, auth middleware
- Create TryPostServer MCP server with 17 tools:
Post (List, Get, Create, Delete), Hashtag (List, Create, Update, Delete),
Label (List, Create, Update, Delete), Workspace (Get),
ApiKey (List, Create, Delete)
- Create AuthenticateMcpToken middleware (logs in workspace owner)
- Register mcp.auth middleware alias in bootstrap/app.php
- Create routes/ai.php with mcp.trypost.test subdomain
- Add PostApiTest with 6 tests (list, show, create, delete, isolation)
- Fix PostApiTest assertions for pagination/resource wrapping
- 704 tests passing, frontend build passing
2026-03-29 23:30:36 +00:00
|
|
|
Model::shouldBeStrict(! $this->app->isProduction());
|
2026-01-18 19:46:27 +00:00
|
|
|
|
2026-01-15 01:13:44 +00:00
|
|
|
DB::prohibitDestructiveCommands(
|
|
|
|
|
app()->isProduction(),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Password::defaults(fn (): ?Password => app()->isProduction()
|
|
|
|
|
? Password::min(12)
|
|
|
|
|
->mixedCase()
|
|
|
|
|
->letters()
|
|
|
|
|
->numbers()
|
|
|
|
|
->symbols()
|
|
|
|
|
->uncompromised()
|
|
|
|
|
: null
|
|
|
|
|
);
|
2026-01-18 19:46:27 +00:00
|
|
|
|
|
|
|
|
Nightwatch::rejectCacheEvents(function (CacheEvent $cacheEvent) {
|
|
|
|
|
return in_array($cacheEvent->key, [
|
|
|
|
|
'illuminate:foundation:down',
|
|
|
|
|
'illuminate:queue:restart',
|
|
|
|
|
'illuminate:schedule:interrupt',
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Custom email verification template
|
|
|
|
|
VerifyEmail::toMailUsing(function (User $user, string $url) {
|
|
|
|
|
return (new MailMessage)
|
|
|
|
|
->from(config('mail.from.address'), config('mail.from.name'))
|
2026-01-18 20:48:12 +00:00
|
|
|
->subject('Verify your email address')
|
2026-01-18 19:46:27 +00:00
|
|
|
->view('mail.email-verification', [
|
2026-01-18 20:48:12 +00:00
|
|
|
'title' => 'Verify your email address',
|
|
|
|
|
'previewText' => 'Please verify your email address.',
|
2026-01-18 19:46:27 +00:00
|
|
|
'user' => $user,
|
|
|
|
|
'url' => $url,
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Custom password reset template
|
|
|
|
|
ResetPassword::toMailUsing(function (User $user, string $token) {
|
|
|
|
|
$url = url(route('password.reset', [
|
|
|
|
|
'token' => $token,
|
|
|
|
|
'email' => $user->getEmailForPasswordReset(),
|
|
|
|
|
], false));
|
|
|
|
|
|
|
|
|
|
return (new MailMessage)
|
|
|
|
|
->from(config('mail.from.address'), config('mail.from.name'))
|
2026-01-18 20:48:12 +00:00
|
|
|
->subject('Reset your password')
|
2026-01-18 19:46:27 +00:00
|
|
|
->view('mail.password-reset', [
|
2026-01-18 20:48:12 +00:00
|
|
|
'title' => 'Reset your password',
|
|
|
|
|
'previewText' => 'Reset your password.',
|
2026-01-18 19:46:27 +00:00
|
|
|
'user' => $user,
|
|
|
|
|
'url' => $url,
|
|
|
|
|
]);
|
|
|
|
|
});
|
2026-01-15 01:13:44 +00:00
|
|
|
}
|
|
|
|
|
}
|