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,3 +1,4 @@
import { createJsonResponder, JsonBodyError, readJsonBody } from '../_shared/json-response.ts'
import { createServiceRoleClient } from '../_shared/quota.ts'
import {
createGooglePlayPurchaseApi,
@ -18,12 +19,8 @@ import {
verifyGooglePubSubIdentity,
} from '../_shared/google-pubsub.ts'
function jsonResponse(body: Record<string, unknown>, status = 200): Response {
return new Response(JSON.stringify(body), {
status,
headers: { 'Content-Type': 'application/json' },
})
}
const MAX_REQUEST_BYTES = 64 * 1024
const jsonResponse = createJsonResponder({ cors: false })
Deno.serve(async (req: Request) => {
if (req.method !== 'POST') return jsonResponse({ error: 'method_not_allowed' }, 405)
@ -33,7 +30,11 @@ Deno.serve(async (req: Request) => {
const purchaseStore = createSupabaseGooglePlayPurchaseStore(serviceClient)
try {
await verifyGooglePubSubIdentity(req)
const notification = parseGooglePlayRtdn(await req.json())
const rawBody = await readJsonBody(req, {
maxBytes: MAX_REQUEST_BYTES,
requirePlainObject: true,
})
const notification = parseGooglePlayRtdn(rawBody as Parameters<typeof parseGooglePlayRtdn>[0])
if (notification.kind === 'test') {
return jsonResponse({ success: true, test: true })
}
@ -123,6 +124,9 @@ Deno.serve(async (req: Request) => {
if (completeError) throw new Error('notification_completion_failed')
return jsonResponse({ success: true })
} catch (error) {
if (error instanceof JsonBodyError) {
return jsonResponse({ error: error.code }, error.status)
}
if (eventId) {
const errorCode = error instanceof GooglePlayVerificationError
|| error instanceof GooglePubSubError