Just back to my other question, have you ever used Shopify?
It insists on a templating language to use any custom js.
Not personally as never had any need, however, I do know that it uses Liquid for JS templating. It’s written in Ruby and is used to generate dynamic content on shop fronts. There’s zero reason as to why it wouldn’t work with data supplied by 3rd party API’s, although WordPress code won’t natively work for obvious reasons, and as such, this code would need to be re-written.
The JS part will likely work with minor modification, but not the PHP file in it’s current form.