@n8n/n8n-nodes-langchain
Version:
43 lines • 1.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createCustomModelEndpointAuthFetch = createCustomModelEndpointAuthFetch;
const ai_utilities_1 = require("@n8n/ai-utilities");
const n8n_workflow_1 = require("n8n-workflow");
const headers_1 = require("./headers");
function withoutInheritedAuthorization(input, init) {
const source = init?.headers ?? (input instanceof Request ? input.headers : undefined);
if (source === undefined)
return { input, init };
const headers = new Headers(source);
if (!headers.has('authorization'))
return { input, init };
headers.delete('authorization');
return { input, init: { ...init, headers } };
}
function createCustomModelEndpointAuthFetch(ctx, credential, options) {
const { endpoint, egressFilter, baseFetch, requestHeaders } = options;
const node = ctx.getNode();
const allowedDomains = (0, n8n_workflow_1.getCredentialAllowedDomains)({
node,
credentialData: credential,
credentialOwnedSurface: true,
nodeEndpointUrl: endpoint.baseUrl,
});
const authFetch = (0, ai_utilities_1.createRefreshingAuthFetch)({
baseFetch,
resolveHeaders: async () => (0, headers_1.buildRequestHeaders)({ endpoint, requestHeaders }),
assertAllowedUrl: async (hopUrl) => {
(0, n8n_workflow_1.assertUrlAllowed)({ url: hopUrl, allowedDomains, node });
if (!egressFilter)
return;
const result = await egressFilter.validateUrl(hopUrl);
if (!result.ok)
throw result.error;
},
});
return async (input, init) => {
const stripped = withoutInheritedAuthorization(input, init);
return await authFetch(stripped.input, stripped.init);
};
}
//# sourceMappingURL=auth-fetch.js.map