tiryaq-shared 1.2.30 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/kafka/broker-parser.d.ts +54 -0
  6. package/dist/kafka/broker-parser.d.ts.map +1 -0
  7. package/dist/kafka/broker-parser.js +191 -0
  8. package/dist/kafka/broker-parser.js.map +1 -0
  9. package/dist/kafka/circuit-breaker.provider.d.ts +113 -0
  10. package/dist/kafka/circuit-breaker.provider.d.ts.map +1 -0
  11. package/dist/kafka/circuit-breaker.provider.js +230 -0
  12. package/dist/kafka/circuit-breaker.provider.js.map +1 -0
  13. package/dist/kafka/dlq-handler.d.ts +102 -0
  14. package/dist/kafka/dlq-handler.d.ts.map +1 -0
  15. package/dist/kafka/dlq-handler.js +220 -0
  16. package/dist/kafka/dlq-handler.js.map +1 -0
  17. package/dist/kafka/health-check.provider.d.ts +78 -0
  18. package/dist/kafka/health-check.provider.d.ts.map +1 -0
  19. package/dist/kafka/health-check.provider.js +170 -0
  20. package/dist/kafka/health-check.provider.js.map +1 -0
  21. package/dist/kafka/index.d.ts +15 -0
  22. package/dist/kafka/index.d.ts.map +1 -0
  23. package/dist/kafka/index.js +41 -0
  24. package/dist/kafka/index.js.map +1 -0
  25. package/dist/kafka/kafka-config.manager.d.ts +92 -0
  26. package/dist/kafka/kafka-config.manager.d.ts.map +1 -0
  27. package/dist/kafka/kafka-config.manager.js +306 -0
  28. package/dist/kafka/kafka-config.manager.js.map +1 -0
  29. package/dist/kafka/kafka-logger.d.ts +125 -0
  30. package/dist/kafka/kafka-logger.d.ts.map +1 -0
  31. package/dist/kafka/kafka-logger.js +204 -0
  32. package/dist/kafka/kafka-logger.js.map +1 -0
  33. package/dist/kafka/subscription-registry.d.ts +141 -0
  34. package/dist/kafka/subscription-registry.d.ts.map +1 -0
  35. package/dist/kafka/subscription-registry.js +219 -0
  36. package/dist/kafka/subscription-registry.js.map +1 -0
  37. package/dist/kafka/types.d.ts +163 -0
  38. package/dist/kafka/types.d.ts.map +1 -0
  39. package/dist/kafka/types.js +19 -0
  40. package/dist/kafka/types.js.map +1 -0
  41. package/dist/message-patterns.d.ts +2 -0
  42. package/dist/message-patterns.d.ts.map +1 -1
  43. package/dist/message-patterns.js +3 -0
  44. package/dist/message-patterns.js.map +1 -1
  45. package/package.json +1 -1
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Kafka Configuration Manager
3
+ *
4
+ * Central configuration manager providing standardized Kafka client, consumer,
5
+ * and producer configurations for all microservices in the Tiryaq platform.
6
+ *
7
+ * Supports both local development (localhost:9092) and AWS MSK (with SASL/SSL).
8
+ */
9
+ import { Logger } from '@nestjs/common';
10
+ import { KafkaClientConfig, KafkaConsumerConfig, KafkaMode } from './types';
11
+ /**
12
+ * KafkaConfigManager class for centralized Kafka configuration management
13
+ */
14
+ export declare class KafkaConfigManager {
15
+ private logger;
16
+ private mode;
17
+ private brokerParser;
18
+ constructor(logger?: Logger);
19
+ /**
20
+ * Detect and parse Kafka mode from environment
21
+ *
22
+ * Reads KAFKA_MODE environment variable and parses broker configuration.
23
+ * Validates the configuration and returns complete mode information.
24
+ *
25
+ * @returns KafkaMode object with mode, brokers, SASL config, and SSL flag
26
+ * @throws Error if configuration is invalid
27
+ */
28
+ detectKafkaMode(): KafkaMode;
29
+ /**
30
+ * Parse broker addresses from environment
31
+ *
32
+ * Uses BrokerParser to parse KAFKA_BROKER environment variable.
33
+ * Supports both JSON format (MSK) and comma-separated format (local).
34
+ *
35
+ * @returns Array of broker addresses in host:port format
36
+ * @throws Error if broker parsing fails
37
+ */
38
+ parseBrokers(): string[];
39
+ /**
40
+ * Build SASL configuration for MSK mode
41
+ *
42
+ * Extracts SASL credentials from KAFKA_BROKER JSON in MSK mode.
43
+ * Returns undefined for local mode.
44
+ *
45
+ * @returns SASL configuration object or undefined
46
+ */
47
+ buildSaslConfig(): KafkaClientConfig['sasl'] | undefined;
48
+ /**
49
+ * Build SSL configuration based on mode
50
+ *
51
+ * Returns true for MSK mode (requires SSL), false for local mode.
52
+ *
53
+ * @returns Boolean indicating whether SSL should be enabled
54
+ */
55
+ buildSslConfig(): boolean;
56
+ /**
57
+ * Get complete client configuration
58
+ *
59
+ * Builds a complete Kafka client configuration with brokers, SASL, SSL,
60
+ * timeouts, and retry settings. Merges provided options with defaults.
61
+ *
62
+ * @param clientId - Unique identifier for this Kafka client
63
+ * @param options - Optional configuration overrides
64
+ * @returns Complete KafkaClientConfig object
65
+ */
66
+ getClientConfig(clientId: string, options?: Partial<KafkaClientConfig>): KafkaClientConfig;
67
+ /**
68
+ * Get consumer configuration with defaults
69
+ *
70
+ * Builds a complete Kafka consumer configuration with session timeouts,
71
+ * heartbeat intervals, rebalance settings, and retry configuration.
72
+ * Merges custom configuration with defaults.
73
+ *
74
+ * @param groupId - Consumer group identifier
75
+ * @param customConfig - Optional custom consumer configuration
76
+ * @returns Complete KafkaConsumerConfig object
77
+ */
78
+ getConsumerConfig(groupId: string, customConfig?: Partial<KafkaConsumerConfig>): KafkaConsumerConfig;
79
+ /**
80
+ * Validate configuration at startup
81
+ *
82
+ * Performs comprehensive validation of Kafka configuration including:
83
+ * - KAFKA_MODE validation
84
+ * - Broker address validation
85
+ * - SASL configuration validation (MSK mode)
86
+ * - Consumer group ID format validation
87
+ *
88
+ * @throws Error if any validation fails with descriptive message
89
+ */
90
+ validateConfig(): void;
91
+ }
92
+ //# sourceMappingURL=kafka-config.manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kafka-config.manager.d.ts","sourceRoot":"","sources":["../../src/kafka/kafka-config.manager.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,EACV,MAAM,SAAS,CAAC;AA6BjB;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,IAAI,CAAkB;IAC9B,OAAO,CAAC,YAAY,CAAe;gBAEvB,MAAM,CAAC,EAAE,MAAM;IAM3B;;;;;;;;OAQG;IACH,eAAe,IAAI,SAAS;IAiC5B;;;;;;;;OAQG;IACH,YAAY,IAAI,MAAM,EAAE;IAcxB;;;;;;;OAOG;IACH,eAAe,IAAI,iBAAiB,CAAC,MAAM,CAAC,GAAG,SAAS;IA4CxD;;;;;;OAMG;IACH,cAAc,IAAI,OAAO;IAMzB;;;;;;;;;OASG;IACH,eAAe,CACb,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GACnC,iBAAiB;IAqCpB;;;;;;;;;;OAUG;IACH,iBAAiB,CACf,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAC1C,mBAAmB;IA6BtB;;;;;;;;;;OAUG;IACH,cAAc,IAAI,IAAI;CA6EvB"}
@@ -0,0 +1,306 @@
1
+ "use strict";
2
+ /**
3
+ * Kafka Configuration Manager
4
+ *
5
+ * Central configuration manager providing standardized Kafka client, consumer,
6
+ * and producer configurations for all microservices in the Tiryaq platform.
7
+ *
8
+ * Supports both local development (localhost:9092) and AWS MSK (with SASL/SSL).
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.KafkaConfigManager = void 0;
12
+ const common_1 = require("@nestjs/common");
13
+ const broker_parser_1 = require("./broker-parser");
14
+ /**
15
+ * Default retry configuration for Kafka operations
16
+ */
17
+ const DEFAULT_RETRY_CONFIG = {
18
+ retries: 8,
19
+ initialRetryTime: 300,
20
+ multiplier: 2,
21
+ maxRetryTime: 30000
22
+ };
23
+ /**
24
+ * Default consumer configuration values
25
+ */
26
+ const DEFAULT_CONSUMER_CONFIG = {
27
+ sessionTimeout: 300000, // 5 minutes
28
+ heartbeatInterval: 3000, // 3 seconds
29
+ rebalanceTimeout: 60000, // 1 minute
30
+ allowAutoTopicCreation: true,
31
+ retry: DEFAULT_RETRY_CONFIG
32
+ };
33
+ /**
34
+ * Default connection timeouts
35
+ */
36
+ const DEFAULT_CONNECTION_TIMEOUT = 10000; // 10 seconds
37
+ const DEFAULT_REQUEST_TIMEOUT = 30000; // 30 seconds
38
+ /**
39
+ * KafkaConfigManager class for centralized Kafka configuration management
40
+ */
41
+ class KafkaConfigManager {
42
+ constructor(logger) {
43
+ this.logger = logger || new common_1.Logger('KafkaConfigManager');
44
+ this.brokerParser = new broker_parser_1.BrokerParser(this.logger);
45
+ this.mode = 'local'; // Default mode, will be set by detectKafkaMode
46
+ }
47
+ /**
48
+ * Detect and parse Kafka mode from environment
49
+ *
50
+ * Reads KAFKA_MODE environment variable and parses broker configuration.
51
+ * Validates the configuration and returns complete mode information.
52
+ *
53
+ * @returns KafkaMode object with mode, brokers, SASL config, and SSL flag
54
+ * @throws Error if configuration is invalid
55
+ */
56
+ detectKafkaMode() {
57
+ const kafkaMode = process.env.KAFKA_MODE?.toLowerCase();
58
+ // Validate KAFKA_MODE
59
+ if (!kafkaMode || (kafkaMode !== 'local' && kafkaMode !== 'msk')) {
60
+ this.logger.warn(`Invalid or missing KAFKA_MODE: "${kafkaMode}". Defaulting to "local". ` +
61
+ `Valid values are "local" or "msk".`);
62
+ this.mode = 'local';
63
+ }
64
+ else {
65
+ this.mode = kafkaMode;
66
+ }
67
+ this.logger.log(`Kafka mode detected: ${this.mode.toUpperCase()}`);
68
+ // Parse brokers
69
+ const brokers = this.parseBrokers();
70
+ // Build SASL config for MSK mode
71
+ const sasl = this.buildSaslConfig();
72
+ // Determine SSL setting
73
+ const ssl = this.buildSslConfig();
74
+ return {
75
+ mode: this.mode,
76
+ brokers,
77
+ sasl,
78
+ ssl
79
+ };
80
+ }
81
+ /**
82
+ * Parse broker addresses from environment
83
+ *
84
+ * Uses BrokerParser to parse KAFKA_BROKER environment variable.
85
+ * Supports both JSON format (MSK) and comma-separated format (local).
86
+ *
87
+ * @returns Array of broker addresses in host:port format
88
+ * @throws Error if broker parsing fails
89
+ */
90
+ parseBrokers() {
91
+ const kafkaBroker = process.env.KAFKA_BROKER || '';
92
+ try {
93
+ const brokers = this.brokerParser.parse(kafkaBroker, this.mode);
94
+ this.logger.log(`Parsed ${brokers.length} broker(s): ${brokers.join(', ')}`);
95
+ return brokers;
96
+ }
97
+ catch (error) {
98
+ const errorMessage = error instanceof Error ? error.message : String(error);
99
+ this.logger.error(`Failed to parse brokers: ${errorMessage}`);
100
+ throw error;
101
+ }
102
+ }
103
+ /**
104
+ * Build SASL configuration for MSK mode
105
+ *
106
+ * Extracts SASL credentials from KAFKA_BROKER JSON in MSK mode.
107
+ * Returns undefined for local mode.
108
+ *
109
+ * @returns SASL configuration object or undefined
110
+ */
111
+ buildSaslConfig() {
112
+ if (this.mode !== 'msk') {
113
+ return undefined;
114
+ }
115
+ const kafkaBroker = process.env.KAFKA_BROKER || '';
116
+ if (!kafkaBroker) {
117
+ throw new Error('KAFKA_BROKER environment variable is required for MSK mode');
118
+ }
119
+ try {
120
+ const config = this.brokerParser.parseJsonConfig(kafkaBroker);
121
+ if (!config.sasl) {
122
+ this.logger.warn('No SASL configuration found in MSK mode. This may cause authentication failures.');
123
+ return undefined;
124
+ }
125
+ // Validate SASL mechanism
126
+ const validMechanisms = ['plain', 'scram-sha-256', 'scram-sha-512'];
127
+ const mechanism = config.sasl.mechanism.toLowerCase();
128
+ if (!validMechanisms.includes(mechanism)) {
129
+ throw new Error(`Invalid SASL mechanism: "${config.sasl.mechanism}". ` +
130
+ `Valid values are: ${validMechanisms.join(', ')}`);
131
+ }
132
+ this.logger.log(`SASL configuration built with mechanism: ${mechanism}`);
133
+ return {
134
+ mechanism: mechanism,
135
+ username: config.sasl.username,
136
+ password: config.sasl.password
137
+ };
138
+ }
139
+ catch (error) {
140
+ const errorMessage = error instanceof Error ? error.message : String(error);
141
+ this.logger.error(`Failed to build SASL config: ${errorMessage}`);
142
+ throw error;
143
+ }
144
+ }
145
+ /**
146
+ * Build SSL configuration based on mode
147
+ *
148
+ * Returns true for MSK mode (requires SSL), false for local mode.
149
+ *
150
+ * @returns Boolean indicating whether SSL should be enabled
151
+ */
152
+ buildSslConfig() {
153
+ const ssl = this.mode === 'msk';
154
+ this.logger.log(`SSL ${ssl ? 'enabled' : 'disabled'} for ${this.mode} mode`);
155
+ return ssl;
156
+ }
157
+ /**
158
+ * Get complete client configuration
159
+ *
160
+ * Builds a complete Kafka client configuration with brokers, SASL, SSL,
161
+ * timeouts, and retry settings. Merges provided options with defaults.
162
+ *
163
+ * @param clientId - Unique identifier for this Kafka client
164
+ * @param options - Optional configuration overrides
165
+ * @returns Complete KafkaClientConfig object
166
+ */
167
+ getClientConfig(clientId, options) {
168
+ if (!clientId || clientId.trim() === '') {
169
+ throw new Error('clientId is required and cannot be empty');
170
+ }
171
+ // Detect mode and get configuration
172
+ const modeConfig = this.detectKafkaMode();
173
+ // Build base configuration
174
+ const config = {
175
+ clientId: clientId.trim(),
176
+ brokers: modeConfig.brokers,
177
+ sasl: modeConfig.sasl,
178
+ ssl: modeConfig.ssl,
179
+ requestTimeout: DEFAULT_REQUEST_TIMEOUT,
180
+ connectionTimeout: DEFAULT_CONNECTION_TIMEOUT,
181
+ retry: DEFAULT_RETRY_CONFIG
182
+ };
183
+ // Merge with provided options
184
+ if (options) {
185
+ Object.assign(config, options);
186
+ // Deep merge retry config if provided
187
+ if (options.retry) {
188
+ config.retry = {
189
+ ...DEFAULT_RETRY_CONFIG,
190
+ ...options.retry
191
+ };
192
+ }
193
+ }
194
+ this.logger.log(`Client configuration built for: ${clientId}`);
195
+ return config;
196
+ }
197
+ /**
198
+ * Get consumer configuration with defaults
199
+ *
200
+ * Builds a complete Kafka consumer configuration with session timeouts,
201
+ * heartbeat intervals, rebalance settings, and retry configuration.
202
+ * Merges custom configuration with defaults.
203
+ *
204
+ * @param groupId - Consumer group identifier
205
+ * @param customConfig - Optional custom consumer configuration
206
+ * @returns Complete KafkaConsumerConfig object
207
+ */
208
+ getConsumerConfig(groupId, customConfig) {
209
+ if (!groupId || groupId.trim() === '') {
210
+ throw new Error('groupId is required and cannot be empty');
211
+ }
212
+ // Build base configuration with defaults
213
+ const config = {
214
+ groupId: groupId.trim(),
215
+ ...DEFAULT_CONSUMER_CONFIG
216
+ };
217
+ // Merge with custom configuration
218
+ if (customConfig) {
219
+ Object.assign(config, customConfig);
220
+ // Deep merge retry config if provided
221
+ if (customConfig.retry) {
222
+ config.retry = {
223
+ ...DEFAULT_CONSUMER_CONFIG.retry,
224
+ ...customConfig.retry
225
+ };
226
+ }
227
+ }
228
+ this.logger.log(`Consumer configuration built for group: ${groupId}`);
229
+ return config;
230
+ }
231
+ /**
232
+ * Validate configuration at startup
233
+ *
234
+ * Performs comprehensive validation of Kafka configuration including:
235
+ * - KAFKA_MODE validation
236
+ * - Broker address validation
237
+ * - SASL configuration validation (MSK mode)
238
+ * - Consumer group ID format validation
239
+ *
240
+ * @throws Error if any validation fails with descriptive message
241
+ */
242
+ validateConfig() {
243
+ this.logger.log('Starting Kafka configuration validation...');
244
+ // Validate KAFKA_MODE
245
+ const kafkaMode = process.env.KAFKA_MODE?.toLowerCase();
246
+ if (!kafkaMode) {
247
+ throw new Error('KAFKA_MODE environment variable is required. Valid values: "local" or "msk"');
248
+ }
249
+ if (kafkaMode !== 'local' && kafkaMode !== 'msk') {
250
+ throw new Error(`Invalid KAFKA_MODE: "${kafkaMode}". Valid values are "local" or "msk"`);
251
+ }
252
+ this.mode = kafkaMode;
253
+ // Validate MSK-specific requirements
254
+ if (this.mode === 'msk') {
255
+ const kafkaBroker = process.env.KAFKA_BROKER;
256
+ if (!kafkaBroker) {
257
+ throw new Error('KAFKA_BROKER environment variable is required for MSK mode. ' +
258
+ 'Expected JSON format with kafka_broker, kafka_sasl_mechanism, ' +
259
+ 'kafka_sasl_username, and kafka_sasl_password fields.');
260
+ }
261
+ // Validate JSON format
262
+ try {
263
+ const config = this.brokerParser.parseJsonConfig(kafkaBroker);
264
+ // Validate SASL configuration presence
265
+ if (!config.sasl) {
266
+ this.logger.warn('MSK mode configured without SASL credentials. ' +
267
+ 'This may cause authentication failures.');
268
+ }
269
+ else {
270
+ // Validate SASL fields are non-empty
271
+ if (!config.sasl.mechanism || config.sasl.mechanism.trim() === '') {
272
+ throw new Error('kafka_sasl_mechanism cannot be empty');
273
+ }
274
+ if (!config.sasl.username || config.sasl.username.trim() === '') {
275
+ throw new Error('kafka_sasl_username cannot be empty');
276
+ }
277
+ if (!config.sasl.password || config.sasl.password.trim() === '') {
278
+ throw new Error('kafka_sasl_password cannot be empty');
279
+ }
280
+ }
281
+ // Validate brokers
282
+ if (config.brokers.length === 0) {
283
+ throw new Error('At least one broker address is required');
284
+ }
285
+ }
286
+ catch (error) {
287
+ const errorMessage = error instanceof Error ? error.message : String(error);
288
+ throw new Error(`MSK configuration validation failed: ${errorMessage}`);
289
+ }
290
+ }
291
+ // Validate broker addresses
292
+ try {
293
+ const brokers = this.parseBrokers();
294
+ if (brokers.length === 0) {
295
+ throw new Error('At least one valid broker address is required');
296
+ }
297
+ }
298
+ catch (error) {
299
+ const errorMessage = error instanceof Error ? error.message : String(error);
300
+ throw new Error(`Broker validation failed: ${errorMessage}`);
301
+ }
302
+ this.logger.log('Kafka configuration validation completed successfully');
303
+ }
304
+ }
305
+ exports.KafkaConfigManager = KafkaConfigManager;
306
+ //# sourceMappingURL=kafka-config.manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kafka-config.manager.js","sourceRoot":"","sources":["../../src/kafka/kafka-config.manager.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,2CAAwC;AACxC,mDAA+C;AAO/C;;GAEG;AACH,MAAM,oBAAoB,GAAG;IAC3B,OAAO,EAAE,CAAC;IACV,gBAAgB,EAAE,GAAG;IACrB,UAAU,EAAE,CAAC;IACb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,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBAC5E,MAAM,IAAI,KAAK,CAAC,wCAAwC,YAAY,EAAE,CAAC,CAAC;YAC1E,CAAC;QACH,CAAC;QAED,4BAA4B;QAC5B,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;YACpC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACzB,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;YACnE,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC5E,MAAM,IAAI,KAAK,CAAC,6BAA6B,YAAY,EAAE,CAAC,CAAC;QAC/D,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;IAC3E,CAAC;CACF;AAlUD,gDAkUC"}
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Kafka Logger
3
+ *
4
+ * Provides structured logging for Kafka operations using NestJS Logger.
5
+ * Ensures consistent log formatting and credential filtering across all services.
6
+ */
7
+ import { Logger } from '@nestjs/common';
8
+ import { KafkaLogContext, DLQMessage, CircuitState, CircuitBreakerStats } from './types';
9
+ /**
10
+ * KafkaLogger class provides structured logging for all Kafka-related operations
11
+ *
12
+ * Features:
13
+ * - Uses NestJS Logger for consistent formatting
14
+ * - Filters credentials from logs for security
15
+ * - Provides context-rich log messages
16
+ * - Supports all Kafka lifecycle events
17
+ */
18
+ export declare class KafkaLogger {
19
+ private logger;
20
+ private serviceName;
21
+ /**
22
+ * Create a new KafkaLogger instance
23
+ *
24
+ * @param serviceName - Name of the service using this logger
25
+ * @param logger - Optional NestJS Logger instance (creates new one if not provided)
26
+ */
27
+ constructor(serviceName: string, logger?: Logger);
28
+ /**
29
+ * Log Kafka mode detection
30
+ *
31
+ * @param mode - Detected Kafka mode (local or msk)
32
+ */
33
+ logModeDetection(mode: 'local' | 'msk'): void;
34
+ /**
35
+ * Log broker parsing result
36
+ *
37
+ * @param brokers - Array of parsed broker addresses
38
+ */
39
+ logBrokersParsed(brokers: string[]): void;
40
+ /**
41
+ * Log SASL configuration (without credentials)
42
+ *
43
+ * @param mechanism - SASL mechanism being used
44
+ */
45
+ logSaslConfig(mechanism: string): void;
46
+ /**
47
+ * Log connection attempt
48
+ *
49
+ * @param clientId - Kafka client identifier
50
+ */
51
+ logConnectionAttempt(clientId: string): void;
52
+ /**
53
+ * Log successful connection
54
+ *
55
+ * @param clientId - Kafka client identifier
56
+ * @param brokers - Connected broker addresses
57
+ */
58
+ logConnectionSuccess(clientId: string, brokers: string[]): void;
59
+ /**
60
+ * Log connection failure
61
+ *
62
+ * @param clientId - Kafka client identifier
63
+ * @param error - Error that occurred during connection
64
+ */
65
+ logConnectionFailure(clientId: string, error: Error): void;
66
+ /**
67
+ * Log subscription registration
68
+ *
69
+ * @param pattern - Message pattern being subscribed to
70
+ * @param clientName - Name of the client subscribing
71
+ */
72
+ logSubscription(pattern: string, clientName: string): void;
73
+ /**
74
+ * Log message send operation
75
+ *
76
+ * @param pattern - Message pattern being sent
77
+ * @param context - Optional additional context
78
+ */
79
+ logMessageSend(pattern: string, context?: KafkaLogContext): void;
80
+ /**
81
+ * Log message receive operation
82
+ *
83
+ * @param pattern - Message pattern received
84
+ * @param context - Optional additional context
85
+ */
86
+ logMessageReceive(pattern: string, context?: KafkaLogContext): void;
87
+ /**
88
+ * Log message processing error
89
+ *
90
+ * @param pattern - Message pattern that failed processing
91
+ * @param error - Error that occurred
92
+ * @param context - Optional additional context
93
+ */
94
+ logProcessingError(pattern: string, error: Error, context?: KafkaLogContext): void;
95
+ /**
96
+ * Log dead letter queue event
97
+ *
98
+ * @param message - DLQ message being logged
99
+ */
100
+ logDLQEvent(message: DLQMessage): void;
101
+ /**
102
+ * Log circuit breaker state change
103
+ *
104
+ * @param serviceName - Target service name
105
+ * @param oldState - Previous circuit state
106
+ * @param newState - New circuit state
107
+ * @param stats - Circuit breaker statistics
108
+ */
109
+ logCircuitBreakerStateChange(serviceName: string, oldState: CircuitState, newState: CircuitState, stats: CircuitBreakerStats): void;
110
+ /**
111
+ * Build log context with service name and additional metadata
112
+ *
113
+ * @param metadata - Additional metadata to include in context
114
+ * @returns Formatted context string
115
+ */
116
+ private buildContext;
117
+ /**
118
+ * Filter credentials from metadata to prevent logging sensitive information
119
+ *
120
+ * @param metadata - Metadata object that may contain credentials
121
+ * @returns Filtered metadata with credentials removed
122
+ */
123
+ private filterCredentials;
124
+ }
125
+ //# sourceMappingURL=kafka-logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kafka-logger.d.ts","sourceRoot":"","sources":["../../src/kafka/kafka-logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EACL,eAAe,EACf,UAAU,EACV,YAAY,EACZ,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;GAQG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,WAAW,CAAS;IAE5B;;;;;OAKG;gBACS,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAKhD;;;;OAIG;IACH,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,KAAK,GAAG,IAAI;IAO7C;;;;OAIG;IACH,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAOzC;;;;OAIG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAOtC;;;;OAIG;IACH,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAO5C;;;;;O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