feat: ship Wave 5-6 multi-surface hygiene, optimization, and bug fixes

This commit is contained in:
Yun Chan 2026-11-14 11:51:41 +09:00
parent 01ef3293cf
commit 66b6b45ba9
399 changed files with 17828 additions and 11330 deletions

View file

@ -1,5 +1,6 @@
import { corsHeaders, handleCorsPreflightRequest } from '../_shared/cors.ts'
import { authErrorResponse, requireUser, type AuthError } from '../_shared/auth.ts'
import { createJsonResponder, JsonBodyError, readJsonBody } from '../_shared/json-response.ts'
import { createServiceRoleClient } from '../_shared/quota.ts'
import {
createGooglePlayPurchaseApi,
@ -17,12 +18,8 @@ interface VerifyPurchaseRequest {
purchaseToken?: unknown
}
function jsonResponse(body: Record<string, unknown>, status = 200): Response {
return new Response(JSON.stringify(body), {
status,
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
})
}
const MAX_REQUEST_BYTES = 16 * 1024
const jsonResponse = createJsonResponder()
Deno.serve(async (req: Request) => {
const preflight = handleCorsPreflightRequest(req)
@ -34,7 +31,10 @@ Deno.serve(async (req: Request) => {
try {
const user = await requireUser(req)
const body = await req.json() as VerifyPurchaseRequest
const body = await readJsonBody(req, {
maxBytes: MAX_REQUEST_BYTES,
requirePlainObject: true,
}) as VerifyPurchaseRequest
if (
body.platform !== 'google_play'
|| typeof body.productId !== 'string'
@ -67,6 +67,9 @@ Deno.serve(async (req: Request) => {
server_acknowledged: purchase.acknowledged,
})
} catch (error) {
if (error instanceof JsonBodyError) {
return jsonResponse({ error: error.status === 413 ? 'request_too_large' : 'invalid_request' }, error.status)
}
if (error && typeof error === 'object' && 'status' in error && 'message' in error) {
const candidate = error as { status: unknown; message: unknown }
if (