feat: ship Wave 5-6 multi-surface hygiene, optimization, and bug fixes
This commit is contained in:
parent
01ef3293cf
commit
66b6b45ba9
399 changed files with 17828 additions and 11330 deletions
|
|
@ -1,18 +1,13 @@
|
|||
import { createClient } from '@supabase/supabase-js'
|
||||
import { requireUser } from '../_shared/auth.ts'
|
||||
import { corsHeaders, handleCorsPreflightRequest } from '../_shared/cors.ts'
|
||||
import { handleCorsPreflightRequest } from '../_shared/cors.ts'
|
||||
import { createJsonResponder, JsonBodyError, readJsonBody } from '../_shared/json-response.ts'
|
||||
import {
|
||||
mapTeamRpcError,
|
||||
parseTeamAcceptInput,
|
||||
TeamContractError,
|
||||
} from '../_shared/team-contract.ts'
|
||||
|
||||
const JSON_HEADERS = {
|
||||
...corsHeaders,
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'no-store',
|
||||
Pragma: 'no-cache',
|
||||
}
|
||||
const REQUEST_LIMIT_BYTES = 4 * 1024
|
||||
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
|
||||
|
||||
|
|
@ -23,26 +18,16 @@ interface AcceptRpcResult {
|
|||
already_member: boolean
|
||||
}
|
||||
|
||||
function jsonResponse(body: Record<string, unknown>, status = 200): Response {
|
||||
return new Response(JSON.stringify(body), { status, headers: JSON_HEADERS })
|
||||
}
|
||||
const jsonResponse = createJsonResponder({ noStore: true, pragmaNoCache: true })
|
||||
|
||||
async function readJson(req: Request): Promise<unknown> {
|
||||
if (req.headers.get('Content-Type')?.split(';', 1)[0].trim().toLowerCase() !== 'application/json') {
|
||||
throw new TeamContractError('unsupported_media_type', 415)
|
||||
}
|
||||
const declaredLength = Number(req.headers.get('Content-Length') ?? '0')
|
||||
if (Number.isFinite(declaredLength) && declaredLength > REQUEST_LIMIT_BYTES) {
|
||||
throw new TeamContractError('request_too_large', 413)
|
||||
}
|
||||
const text = await req.text()
|
||||
if (new TextEncoder().encode(text).byteLength > REQUEST_LIMIT_BYTES) {
|
||||
throw new TeamContractError('request_too_large', 413)
|
||||
}
|
||||
try {
|
||||
return JSON.parse(text)
|
||||
} catch {
|
||||
throw new TeamContractError('invalid_json', 400)
|
||||
return await readJsonBody(req, { maxBytes: REQUEST_LIMIT_BYTES, requireContentType: true })
|
||||
} catch (error) {
|
||||
if (error instanceof JsonBodyError) {
|
||||
throw new TeamContractError(error.code, error.status)
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue