Circling back around to give thanks to @merefield I looked more into serializing and was able to accomplish the task by making the API call in the serializer instead of requesting it from JS as I was doing.
I’m sure there are a plethora of reasons why this isn’t suggested but it works for me so I’m running with it, for those finding this in the future, you can slide data into a serializer with the following code:
add_to_serializer(:topic_view, :data_name) do
JSON.parse(Net::HTTP.get(URI('https://yourwebsite.com?topic_id=' + object.topic.id.to_s)))
end
Which then allows you to access the data within a call to reopenWidget. In my case I’m tacking the data pertinent to the topic onto the topic_view serializer and accessing it while modifying the post like so:
api.reopenWidget("post", {
html(attrs) {
let data_name = this.model.topic.data_name;
// Do stuff with data
return this.attach("post-article", attrs);
},
});
As I said before there’s probably a ton of reasons this isn’t the right way to go about it but it is working for my use case with minimal impact on load times.
For those looking to accomplish the task within JS for whatever reason, pertinent code seems to exist in the discourse-encrypt plugin where they decrypt posts, but I found this method far easier to implement: discourse-encrypt/assets/javascripts/discourse/initializers/decrypt-posts.js at 255724ebc5fc3956f26beca09c1f7cb273d76eb2 · discourse/discourse-encrypt · GitHub