1
0
Fork 0
mirror of https://github.com/n8n-io/n8n.git synced 2025-03-05 20:50:17 -08:00
n8n/packages/nodes-base/nodes/Kafka/GenericFunctions.ts
कारतोफ्फेलस्क्रिप्ट™ e044b78049
feat(Kafka Node): Overhaul Kafka and KafkaTrigger nodes
2024-12-10 13:49:21 +01:00

38 lines
991 B
TypeScript

import { logLevel, SASLOptions, type KafkaConfig } from 'kafkajs';
import type { KafkaCredential } from './types';
import {
type ICredentialTestFunctions,
NodeOperationError,
type ITriggerFunctions,
} from 'n8n-workflow';
export const getConnectionConfig = (
context: ITriggerFunctions | ICredentialTestFunctions,
credentials: KafkaCredential,
): KafkaConfig => {
const brokers = ((credentials.brokers as string) || '').split(',').map((item) => item.trim());
const config: KafkaConfig = {
brokers,
clientId: credentials.clientId,
ssl: credentials.ssl,
logLevel: logLevel.ERROR,
};
if (credentials.authentication) {
if (!(credentials.username && credentials.password)) {
throw new NodeOperationError(
context.getNode(),
'Username and password are required for authentication',
);
}
config.sasl = {
username: credentials.username,
password: credentials.password,
mechanism: credentials.saslMechanism,
} as SASLOptions;
}
return config;
};