Currently, I am working on a project where we are required to retrieve a script from an endpoint for consumption. The API designed for the web returns a self-invoking function that sets a variable. The request header specifies the content-type as application/javascript, and my goal is to extract this result from the endpoint and incorporate the variable into my application.
To illustrate this concept further, let's consider the following script:
const Script = (() => {
return {
some: "method",
another: "method",
};
})();
This script is provided by an endpoint for use in a web browser through the following script tag:
<script src="https://example.com/index.js"></script>
However, my objective is to access this script/variable for integration into my React Native application, as shown here:
fetch("https://example.com/index.js", { method: "GET" }).then((response) => {});
The issue arises when the response from the request does not align with my requirements. While I can convert it to a Blob, I am unsure about how to parse this Blob into a JavaScript function or a similar entity.