-
Notifications
You must be signed in to change notification settings - Fork 0
Ship production AI crypto workspace #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8b4bac7
feat: ship production AI crypto workspace
svg8bit cf3b35c
test: align visual baselines across chromium runtimes
svg8bit 230d4ca
fix: close production review boundaries
svg8bit 20b606d
fix: apply final review and browser baselines
svg8bit 4bf00e3
fix: keep release boundary green
svg8bit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import { NextRequest, NextResponse } from "next/server.js"; | ||
|
|
||
| import { | ||
| BillingUnavailableError, | ||
| BillingValidationError, | ||
| createProCheckout, | ||
| stripeBillingProvider, | ||
| stripeCheckoutConfiguration, | ||
| } from "@/lib/billing"; | ||
| import { | ||
| billingRepository, | ||
| billingStorageConfigured, | ||
| BillingStorageUnavailableError, | ||
| } from "@/db/billing"; | ||
| import { | ||
| resolveStudioAccount, | ||
| STUDIO_ACCOUNT_COOKIE, | ||
| } from "@/lib/access-tier"; | ||
| import { consumeRequestLimit } from "@/lib/request-rate-limit"; | ||
| import { | ||
| decodeUtf8Body, | ||
| hasJsonMediaType, | ||
| readBoundedRequestBody, | ||
| RequestBodyBoundaryError, | ||
| } from "@/lib/http-request-boundary"; | ||
|
|
||
| export const runtime = "nodejs"; | ||
| export const dynamic = "force-dynamic"; | ||
|
|
||
| const HEADERS = { "cache-control": "private, no-store, max-age=0", vary: "Cookie" }; | ||
|
|
||
| function json(error: string, status: number) { | ||
| return NextResponse.json({ error }, { status, headers: HEADERS }); | ||
| } | ||
|
|
||
| function sameOrigin(request: NextRequest): boolean { | ||
| const origin = request.headers.get("origin"); | ||
| if (!origin || request.headers.get("sec-fetch-site")?.toLowerCase() === "cross-site") return false; | ||
| try { | ||
| return new URL(origin).origin === request.nextUrl.origin; | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| export async function POST(request: NextRequest) { | ||
| const config = stripeCheckoutConfiguration(); | ||
| if (!config || !billingStorageConfigured()) { | ||
| return json("Billing is not configured or unavailable.", 503); | ||
| } | ||
| const account = resolveStudioAccount( | ||
| request.cookies.get(STUDIO_ACCOUNT_COOKIE)?.value, | ||
| ); | ||
| if (!account) return json("A signed Studio member account is required.", 401); | ||
| if (!sameOrigin(request)) return json("Cross-origin billing request rejected.", 403); | ||
| if (!hasJsonMediaType(request)) { | ||
| return json("Billing checkout requires application/json.", 415); | ||
| } | ||
| let raw: string; | ||
| try { | ||
| raw = decodeUtf8Body(await readBoundedRequestBody(request, 2_048)); | ||
| } catch (error) { | ||
| if (error instanceof RequestBodyBoundaryError && error.reason === "too-large") { | ||
| return json("Billing checkout request is too large.", 413); | ||
| } | ||
| return json("Billing checkout request is invalid.", 400); | ||
| } | ||
| let consent = false; | ||
| try { | ||
| consent = (JSON.parse(raw) as { consent?: unknown }).consent === true; | ||
| } catch { | ||
| return json("Billing checkout request is invalid.", 400); | ||
| } | ||
| const limit = await consumeRequestLimit({ | ||
| identity: account.identity, | ||
| namespace: "billing-checkout", | ||
| max: 8, | ||
| windowMs: 60 * 60 * 1_000, | ||
| }); | ||
| if (limit === "limited") return json("Too many checkout requests. Try again later.", 429); | ||
| if (limit === "unavailable") return json("Billing request protection is unavailable.", 503); | ||
| try { | ||
| const receipt = await createProCheckout( | ||
| { accountIdentity: account.identity, origin: request.nextUrl.origin, consent }, | ||
| { | ||
| config, | ||
| repository: billingRepository, | ||
| provider: stripeBillingProvider(config.secretKey), | ||
| }, | ||
| ); | ||
| return NextResponse.json(receipt, { status: 201, headers: HEADERS }); | ||
| } catch (error) { | ||
| if (error instanceof BillingValidationError) return json(error.message, 400); | ||
| if ( | ||
| error instanceof BillingUnavailableError | ||
| || error instanceof BillingStorageUnavailableError | ||
| ) { | ||
| return json("Billing is not configured or unavailable.", 503); | ||
| } | ||
| return json("Stripe checkout could not be created.", 502); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: svg8bit/drops-studio
Length of output: 1778
🏁 Script executed:
Repository: svg8bit/drops-studio
Length of output: 6246
Document
project-studio.chrome.cssandproject-studio.workspace.cssin the CSS policy.DESIGN.mdonly grants an exception toproject-studio.runtime.css, butapp/studio/project-studio.cssalso importsproject-studio.chrome.cssandproject-studio.workspace.css. Add those files here with their intended bounds, or update the guardrail so the policy matches the shipped CSS surface.🧰 Tools
🪛 LanguageTool
[style] ~107-~107: This is not the usual sequence for adjectives that have no special emphasis.
Context: ...ual manual stylesheet above 48 KiB so a new monolithic CSS surface cannot silently return. `a...
(EN_ADJ_ORDER)
🤖 Prompt for AI Agents