"""Account app fragment endpoints. Exposes sx fragments at ``/internal/fragments/`` for consumption by other coop apps via the fragment client. Fragments: auth-menu Desktop + mobile auth menu (sign-in or user link) """ from __future__ import annotations from quart import Blueprint, Response, request from shared.infrastructure.fragments import FRAGMENT_HEADER def register(): bp = Blueprint("fragments", __name__, url_prefix="/internal/fragments") # --------------------------------------------------------------- # Fragment handlers — return sx source text # --------------------------------------------------------------- async def _auth_menu(): from shared.infrastructure.urls import account_url from shared.sx.helpers import sx_call user_email = request.args.get("email", "") return sx_call("auth-menu", user_email=user_email or None, account_url=account_url("")) _handlers = { "auth-menu": _auth_menu, } # --------------------------------------------------------------- # Routing # --------------------------------------------------------------- @bp.before_request async def _require_fragment_header(): if not request.headers.get(FRAGMENT_HEADER): return Response("", status=403) @bp.get("/") async def get_fragment(fragment_type: str): handler = _handlers.get(fragment_type) if handler is None: return Response("", status=200, content_type="text/sx") src = await handler() return Response(src, status=200, content_type="text/sx") return bp