"""``POST /events/batch`` — 客户端埋点批量上报(FR-SYS-06 服务端入口)。 埋点链路对客户端静默降级:非法批返回 40020(无 hint),客户端丢弃本地 缓存即可,不打扰用户。校验规则见 packages/analytics/service.py。 """ from __future__ import annotations from fastapi import APIRouter from apps.api.deps import AnalyticsServiceDep, CurrentUserId from packages.analytics.schemas import EventBatchRequest, EventBatchResponse from packages.shared.response import ok router = APIRouter(prefix="/events", tags=["events"]) @router.post("/batch", summary="批量上报埋点事件(整批校验,任一非法整批拒绝)") async def post_event_batch( user_id: CurrentUserId, analytics: AnalyticsServiceDep, payload: EventBatchRequest, ) -> dict[str, object]: accepted = await analytics.record(user_id=user_id, batch=payload.events) return ok(EventBatchResponse(accepted=accepted).model_dump())