Query data source from JavaScript (text/html panel)

Which is the correct way to ask Grafana to run a DB query from a Text/HTML panel? I’d like to retrieve InfluxDB results from a custom JavaScript without passing through variables. I could maybe run the query from JavaScript but I guess this is not CORS-friendly. On the other hand, asking the server to query one of its data sources should be OK in terms of security.

Thanks in advance.