teddi-x
Version:
Teddi (teddi-x) is a Node package that extends security to vertical agents., applications, and tooling built on, for, or with AI.
45 lines (38 loc) • 1.39 kB
JavaScript
const secureFetch = (teddiHash, integrationId) => {
return async(input, init = {}) => {
console.log("init", init);
// Convert Headers object to plain object
const headersObj = {};
if (init.headers instanceof Headers) {
init.headers.forEach((value, key) => {
headersObj[key] = value;
});
console.log("Headers keys:", [...init.headers.keys()]);
} else if (init.headers) {
// Handle if it's already a plain object
Object.assign(headersObj, init.headers);
console.log("Headers object:", headersObj);
}
const originalUrl = typeof input === "string" ? input : input.url;
const method = init.method || "GET";
const body = init.body || null;
const proxyUrl = "http://localhost:6999/proxy-api";
const payload = {
originalUrl,
method,
body,
headers: headersObj, // Use the converted headers
};
const requestHeaders = {
"Content-Type": "application/json",
"X-Teddi-Hash": teddiHash,
integrationid: integrationId,
};
return fetch(proxyUrl, {
method: "POST",
headers: requestHeaders,
body: JSON.stringify(payload),
});
};
};
export { secureFetch };