238 ai agent readiness#239
Conversation
…r lage billing file
… 238-ai-agent-readiness
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
corates | 9ef70a4 | Commit Preview URL | Jan 07 2026, 01:25 AM |
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughThis PR introduces comprehensive documentation updates, adds a new offline-capable authentication store with Better Auth integration, refactors billing infrastructure into modular routes, adds centralized error handling middleware, migrates all workers package imports to path aliases, and introduces new configuration constants for time durations, quotas, and caching. Changes
Sequence DiagramssequenceDiagram
participant Client
participant AuthStore as Better Auth Store
participant BetterAuth as Better Auth Service
participant LocalStorage
participant IndexedDB
participant BroadcastChannel
Client->>AuthStore: useBetterAuth()
AuthStore->>LocalStorage: Load cached session (7-day TTL)
alt Cache Valid
AuthStore->>AuthStore: Use cached session
else Cache Expired/Invalid
AuthStore->>BetterAuth: Fetch fresh session
BetterAuth-->>AuthStore: Session data
AuthStore->>LocalStorage: Update cache with timestamp
end
AuthStore->>IndexedDB: Load cached avatar URLs
alt User Goes Offline
AuthStore->>AuthStore: Set isOnline = false
AuthStore->>Client: Return cached session/user
else User Online
AuthStore->>BetterAuth: Sync auth state
end
rect rgb(200, 220, 255)
Note over BroadcastChannel: Cross-Tab Sync
AuthStore->>BroadcastChannel: Post auth-changed message
BroadcastChannel-->>AuthStore: Receive from other tabs
AuthStore->>AuthStore: Refetch session on changes
end
sequenceDiagram
participant Client
participant CheckoutHandler as POST /checkout
participant DB
participant Stripe
participant BetterAuthPlugin as Better Auth<br/>Stripe Plugin
Client->>CheckoutHandler: POST with targetTier
CheckoutHandler->>CheckoutHandler: Validate auth + org ownership
CheckoutHandler->>DB: Resolve org context + role
CheckoutHandler->>CheckoutHandler: requireOrgOwner(orgId, role)
alt Validation Failed
CheckoutHandler-->>Client: Domain FORBIDDEN error
else Validation Passed
CheckoutHandler->>BetterAuthPlugin: Call upgradePlan
BetterAuthPlugin->>Stripe: Create checkout session
Stripe-->>BetterAuthPlugin: Session data
BetterAuthPlugin-->>CheckoutHandler: Result with sessionId
CheckoutHandler-->>Client: JSON { sessionId, url }
end
sequenceDiagram
participant Stripe
participant WebhookHandler as POST /purchases/webhook
participant DB
participant Ledger
participant GrantsDB
Stripe->>WebhookHandler: Send event (checkout.session.completed)
WebhookHandler->>WebhookHandler: Read raw body
rect rgb(200, 220, 255)
Note over WebhookHandler: Phase 1: Trust-Minimal
WebhookHandler->>WebhookHandler: Compute payload hash
WebhookHandler->>Ledger: Check for duplicate
alt Duplicate Found
WebhookHandler-->>Stripe: 200 OK (skipped)
end
WebhookHandler->>Ledger: Create ledger entry
end
rect rgb(220, 200, 220)
Note over WebhookHandler: Phase 2: Verification
WebhookHandler->>WebhookHandler: Verify Stripe signature
alt Signature Invalid
WebhookHandler->>Ledger: Update failed
WebhookHandler-->>Stripe: 403 Forbidden
end
end
WebhookHandler->>DB: Validate metadata (orgId, grantType)
alt Valid Payment (paid, mode=payment)
WebhookHandler->>GrantsDB: Check existing grant by session
alt Grant Exists
GrantsDB->>GrantsDB: Extend expiresAt by 6 months
WebhookHandler->>Ledger: Mark processed
else No Existing Grant
WebhookHandler->>GrantsDB: Create new grant (6-month expiry)
WebhookHandler->>Ledger: Record grantId
end
WebhookHandler-->>Stripe: 200 OK { grantId }
else Invalid
WebhookHandler->>Ledger: Mark as skipped
WebhookHandler-->>Stripe: 200 OK
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes Possibly related PRs
✨ Finishing touches
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (83)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.