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.
38 lines (30 loc) • 1.15 kB
JavaScript
import { secureFetch } from "./secureFetch.js";
function withSecureFetch(sdkFactory, teddiUrl, teddiHash, integrationId) {
const proxyFetch = (input, init = {}) => {
return secureFetch(input, {...init, teddiHash, integrationId });
};
// Detect if the SDK factory is Supabase based on function name or signature
const isSupabase = sdkFactory.name === "createClient";
let instance;
if (isSupabase) {
// Supabase supports fetch override during creation
instance = sdkFactory(teddiUrl, teddiHash, {
global: { fetch: proxyFetch },
});
} else {
// Generic SDK creation (non-Supabase)
instance = sdkFactory(teddiUrl, teddiHash);
}
// Fallback patching for any SDK that exposes a `.fetch` method
const wrap = (obj) => {
if (obj && typeof obj.fetch === "function") {
obj.fetch = (input, init = {}) =>
secureFetch(input, {...init, teddiHash, integrationId });
}
};
wrap(instance.auth);
wrap(instance.rest);
wrap(instance); // default obj
return instance;
}
export { withSecureFetch };