@nathapp/nestjs-queue 2.1.0-rc.1

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 (153) hide show
  1. package/CLAUDE.md +106 -0
  2. package/TODO.md +44 -0
  3. package/dist/constant/index.d.ts +1 -0
  4. package/dist/constant/index.js +18 -0
  5. package/dist/constant/index.js.map +1 -0
  6. package/dist/constant/queue.constant.d.ts +6 -0
  7. package/dist/constant/queue.constant.js +10 -0
  8. package/dist/constant/queue.constant.js.map +1 -0
  9. package/dist/decorator/index.d.ts +3 -0
  10. package/dist/decorator/index.js +20 -0
  11. package/dist/decorator/index.js.map +1 -0
  12. package/dist/decorator/on-queue-event.decorator.d.ts +6 -0
  13. package/dist/decorator/on-queue-event.decorator.js +18 -0
  14. package/dist/decorator/on-queue-event.decorator.js.map +1 -0
  15. package/dist/decorator/process.decorator.d.ts +5 -0
  16. package/dist/decorator/process.decorator.js +18 -0
  17. package/dist/decorator/process.decorator.js.map +1 -0
  18. package/dist/decorator/processor.decorator.d.ts +5 -0
  19. package/dist/decorator/processor.decorator.js +12 -0
  20. package/dist/decorator/processor.decorator.js.map +1 -0
  21. package/dist/enum/index.d.ts +3 -0
  22. package/dist/enum/index.js +20 -0
  23. package/dist/enum/index.js.map +1 -0
  24. package/dist/enum/job-status.enum.d.ts +8 -0
  25. package/dist/enum/job-status.enum.js +13 -0
  26. package/dist/enum/job-status.enum.js.map +1 -0
  27. package/dist/enum/provider.enum.d.ts +7 -0
  28. package/dist/enum/provider.enum.js +12 -0
  29. package/dist/enum/provider.enum.js.map +1 -0
  30. package/dist/enum/queue-event.enum.d.ts +11 -0
  31. package/dist/enum/queue-event.enum.js +16 -0
  32. package/dist/enum/queue-event.enum.js.map +1 -0
  33. package/dist/explorer/index.d.ts +1 -0
  34. package/dist/explorer/index.js +18 -0
  35. package/dist/explorer/index.js.map +1 -0
  36. package/dist/explorer/processor.explorer.d.ts +25 -0
  37. package/dist/explorer/processor.explorer.js +241 -0
  38. package/dist/explorer/processor.explorer.js.map +1 -0
  39. package/dist/index.d.ts +10 -0
  40. package/dist/index.js +27 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/interface/circuit-breaker.interface.d.ts +21 -0
  43. package/dist/interface/circuit-breaker.interface.js +10 -0
  44. package/dist/interface/circuit-breaker.interface.js.map +1 -0
  45. package/dist/interface/health.interface.d.ts +12 -0
  46. package/dist/interface/health.interface.js +3 -0
  47. package/dist/interface/health.interface.js.map +1 -0
  48. package/dist/interface/idempotency-store.interface.d.ts +14 -0
  49. package/dist/interface/idempotency-store.interface.js +3 -0
  50. package/dist/interface/idempotency-store.interface.js.map +1 -0
  51. package/dist/interface/index.d.ts +5 -0
  52. package/dist/interface/index.js +22 -0
  53. package/dist/interface/index.js.map +1 -0
  54. package/dist/interface/job.interface.d.ts +56 -0
  55. package/dist/interface/job.interface.js +3 -0
  56. package/dist/interface/job.interface.js.map +1 -0
  57. package/dist/interface/metrics.interface.d.ts +12 -0
  58. package/dist/interface/metrics.interface.js +3 -0
  59. package/dist/interface/metrics.interface.js.map +1 -0
  60. package/dist/interface/queue-options.interface.d.ts +84 -0
  61. package/dist/interface/queue-options.interface.js +3 -0
  62. package/dist/interface/queue-options.interface.js.map +1 -0
  63. package/dist/interface/queue-provider.interface.d.ts +55 -0
  64. package/dist/interface/queue-provider.interface.js +7 -0
  65. package/dist/interface/queue-provider.interface.js.map +1 -0
  66. package/dist/module/index.d.ts +3 -0
  67. package/dist/module/index.js +20 -0
  68. package/dist/module/index.js.map +1 -0
  69. package/dist/module/queue.module-definition.d.ts +2 -0
  70. package/dist/module/queue.module-definition.js +11 -0
  71. package/dist/module/queue.module-definition.js.map +1 -0
  72. package/dist/module/queue.module.d.ts +3 -0
  73. package/dist/module/queue.module.js +26 -0
  74. package/dist/module/queue.module.js.map +1 -0
  75. package/dist/module/queue.provider.d.ts +2 -0
  76. package/dist/module/queue.provider.js +57 -0
  77. package/dist/module/queue.provider.js.map +1 -0
  78. package/dist/provider/bullmq/bullmq.options.d.ts +12 -0
  79. package/dist/provider/bullmq/bullmq.options.js +3 -0
  80. package/dist/provider/bullmq/bullmq.options.js.map +1 -0
  81. package/dist/provider/bullmq/bullmq.provider.d.ts +52 -0
  82. package/dist/provider/bullmq/bullmq.provider.js +476 -0
  83. package/dist/provider/bullmq/bullmq.provider.js.map +1 -0
  84. package/dist/provider/bullmq/index.d.ts +1 -0
  85. package/dist/provider/bullmq/index.js +18 -0
  86. package/dist/provider/bullmq/index.js.map +1 -0
  87. package/dist/provider/index.d.ts +4 -0
  88. package/dist/provider/index.js +21 -0
  89. package/dist/provider/index.js.map +1 -0
  90. package/dist/provider/kafka/index.d.ts +1 -0
  91. package/dist/provider/kafka/index.js +18 -0
  92. package/dist/provider/kafka/index.js.map +1 -0
  93. package/dist/provider/kafka/kafka.provider.d.ts +59 -0
  94. package/dist/provider/kafka/kafka.provider.js +598 -0
  95. package/dist/provider/kafka/kafka.provider.js.map +1 -0
  96. package/dist/provider/rabbitmq/index.d.ts +1 -0
  97. package/dist/provider/rabbitmq/index.js +18 -0
  98. package/dist/provider/rabbitmq/index.js.map +1 -0
  99. package/dist/provider/rabbitmq/rabbitmq.provider.d.ts +48 -0
  100. package/dist/provider/rabbitmq/rabbitmq.provider.js +498 -0
  101. package/dist/provider/rabbitmq/rabbitmq.provider.js.map +1 -0
  102. package/dist/provider/redis-pubsub/index.d.ts +1 -0
  103. package/dist/provider/redis-pubsub/index.js +18 -0
  104. package/dist/provider/redis-pubsub/index.js.map +1 -0
  105. package/dist/provider/redis-pubsub/redis-pubsub.provider.d.ts +40 -0
  106. package/dist/provider/redis-pubsub/redis-pubsub.provider.js +226 -0
  107. package/dist/provider/redis-pubsub/redis-pubsub.provider.js.map +1 -0
  108. package/dist/service/index.d.ts +1 -0
  109. package/dist/service/index.js +18 -0
  110. package/dist/service/index.js.map +1 -0
  111. package/dist/service/queue.service.d.ts +36 -0
  112. package/dist/service/queue.service.js +89 -0
  113. package/dist/service/queue.service.js.map +1 -0
  114. package/dist/store/in-memory-idempotency.store.d.ts +15 -0
  115. package/dist/store/in-memory-idempotency.store.js +84 -0
  116. package/dist/store/in-memory-idempotency.store.js.map +1 -0
  117. package/dist/store/index.d.ts +1 -0
  118. package/dist/store/index.js +6 -0
  119. package/dist/store/index.js.map +1 -0
  120. package/dist/utils/circuit-breaker.d.ts +30 -0
  121. package/dist/utils/circuit-breaker.js +133 -0
  122. package/dist/utils/circuit-breaker.js.map +1 -0
  123. package/dist/utils/delayed-scheduler.d.ts +16 -0
  124. package/dist/utils/delayed-scheduler.js +100 -0
  125. package/dist/utils/delayed-scheduler.js.map +1 -0
  126. package/dist/utils/errors.d.ts +23 -0
  127. package/dist/utils/errors.js +85 -0
  128. package/dist/utils/errors.js.map +1 -0
  129. package/dist/utils/index.d.ts +5 -0
  130. package/dist/utils/index.js +22 -0
  131. package/dist/utils/index.js.map +1 -0
  132. package/dist/utils/lock-renewal.d.ts +14 -0
  133. package/dist/utils/lock-renewal.js +61 -0
  134. package/dist/utils/lock-renewal.js.map +1 -0
  135. package/dist/utils/redis-idempotency-store.d.ts +21 -0
  136. package/dist/utils/redis-idempotency-store.js +88 -0
  137. package/dist/utils/redis-idempotency-store.js.map +1 -0
  138. package/dist/utils/sanitize.d.ts +3 -0
  139. package/dist/utils/sanitize.js +55 -0
  140. package/dist/utils/sanitize.js.map +1 -0
  141. package/dist/utils/validation.d.ts +8 -0
  142. package/dist/utils/validation.js +60 -0
  143. package/dist/utils/validation.js.map +1 -0
  144. package/docker-compose.e2e.yml +69 -0
  145. package/docs/FINAL_CODE_REVIEW.md +328 -0
  146. package/docs/IMPLEMENTATION_PLAN.md +748 -0
  147. package/docs/archive/CIRCUIT_BREAKER_PLAN.md +35 -0
  148. package/docs/archive/CODE_REVIEW.md +596 -0
  149. package/docs/archive/CODE_REVIEW_V2.md +1081 -0
  150. package/docs/archive/CODE_REVIEW_V3.md +402 -0
  151. package/docs/archive/IMPLEMENTATION_PLAN.md +505 -0
  152. package/docs/archive/IMPLEMENTATION_PLAN_BUGFIX.md +428 -0
  153. package/package.json +70 -0
@@ -0,0 +1,428 @@
1
+ # nestjs-queue Bug Fix Implementation Plan
2
+
3
+ **Date:** 2026-02-08
4
+ **Priority:** P0/P1 Bug Fixes
5
+ **Estimated Time:** 2-3 hours
6
+
7
+ ---
8
+
9
+ ## Phase 1: P0 Critical Bug Fixes
10
+
11
+ ### 1.1 BullMQ Lua Script Error Fix
12
+
13
+ **File:** `lib/provider/bullmq/bullmq.provider.ts`
14
+
15
+ **Problem:** `mapJobOptions()` returns object with undefined values, which BullMQ passes to Redis Lua scripts causing errors.
16
+
17
+ **Implementation Steps:**
18
+
19
+ 1. Refactor `mapJobOptions()` method (lines 65-80):
20
+
21
+ ```typescript
22
+ /**
23
+ * Map internal job options to BullMQ format
24
+ * Filters out undefined values to prevent Redis Lua script errors
25
+ */
26
+ private mapJobOptions(opts?: JobOptions): Record<string, any> {
27
+ if (!opts) return {};
28
+
29
+ const result: Record<string, any> = {};
30
+
31
+ // Only include defined values
32
+ if (opts.delay !== undefined) result.delay = opts.delay;
33
+ if (opts.attempts !== undefined) result.attempts = opts.attempts;
34
+ if (opts.priority !== undefined) result.priority = opts.priority;
35
+ if (opts.removeOnComplete !== undefined) result.removeOnComplete = opts.removeOnComplete;
36
+ if (opts.removeOnFail !== undefined) result.removeOnFail = opts.removeOnFail;
37
+ if (opts.jobId !== undefined) result.jobId = opts.jobId;
38
+
39
+ // Handle backoff - ensure proper structure
40
+ if (opts.backoff !== undefined) {
41
+ if (typeof opts.backoff === 'number') {
42
+ result.backoff = { type: 'fixed', delay: opts.backoff };
43
+ } else {
44
+ result.backoff = {
45
+ type: opts.backoff.type,
46
+ delay: opts.backoff.delay,
47
+ };
48
+ }
49
+ }
50
+
51
+ // Handle repeat options - only include if defined
52
+ if (opts.repeat) {
53
+ const repeat: Record<string, any> = {};
54
+ if (opts.repeat.pattern !== undefined) repeat.pattern = opts.repeat.pattern;
55
+ if (opts.repeat.every !== undefined) repeat.every = opts.repeat.every;
56
+ if (opts.repeat.limit !== undefined) repeat.limit = opts.repeat.limit;
57
+ if (opts.repeat.startDate !== undefined) repeat.startDate = opts.repeat.startDate;
58
+ if (opts.repeat.endDate !== undefined) repeat.endDate = opts.repeat.endDate;
59
+ if (opts.repeat.tz !== undefined) repeat.tz = opts.repeat.tz;
60
+
61
+ if (Object.keys(repeat).length > 0) {
62
+ result.repeat = repeat;
63
+ }
64
+ }
65
+
66
+ return result;
67
+ }
68
+ ```
69
+
70
+ 2. Add unit test for `mapJobOptions`:
71
+
72
+ ```typescript
73
+ // In test file
74
+ describe('mapJobOptions', () => {
75
+ it('should filter out undefined values', () => {
76
+ const opts: JobOptions = { delay: 1000 };
77
+ const result = provider['mapJobOptions'](opts);
78
+
79
+ expect(result).toEqual({ delay: 1000 });
80
+ expect(result.attempts).toBeUndefined();
81
+ expect('attempts' in result).toBe(false);
82
+ });
83
+
84
+ it('should handle backoff as number', () => {
85
+ const opts: JobOptions = { backoff: 5000 };
86
+ const result = provider['mapJobOptions'](opts);
87
+
88
+ expect(result.backoff).toEqual({ type: 'fixed', delay: 5000 });
89
+ });
90
+
91
+ it('should return empty object for undefined opts', () => {
92
+ expect(provider['mapJobOptions'](undefined)).toEqual({});
93
+ });
94
+ });
95
+ ```
96
+
97
+ ---
98
+
99
+ ### 1.2 RabbitMQ Retry Race Condition Fix
100
+
101
+ **File:** `lib/provider/rabbitmq/rabbitmq.provider.ts`
102
+
103
+ **Problem:** `nack()` is called before re-adding the job. If connection drops between nack and re-add, job is lost.
104
+
105
+ **Implementation Steps:**
106
+
107
+ 1. Refactor the retry logic in `process()` method (lines 170-195):
108
+
109
+ ```typescript
110
+ } catch (error: any) {
111
+ job.attemptsMade = attempts + 1;
112
+ job.failedReason = error.message;
113
+
114
+ if (job.attemptsMade < maxAttempts) {
115
+ const delay = this.calculateBackoff(job);
116
+
117
+ try {
118
+ // IMPORTANT: Re-add job BEFORE acknowledging the original
119
+ // This ensures job is not lost if connection drops
120
+ const retryJobOpts: JobOptions = {
121
+ ...job.opts,
122
+ jobId: `${job.id}-retry-${job.attemptsMade}`, // New ID to avoid conflicts
123
+ delay,
124
+ };
125
+
126
+ // Store retry metadata in job
127
+ const retryJob = {
128
+ ...job,
129
+ opts: retryJobOpts,
130
+ };
131
+
132
+ await this.add(queueName, job.name, job.data, retryJobOpts);
133
+
134
+ // Only acknowledge original after successful re-add
135
+ channel.ack(msg);
136
+
137
+ this.logger.debug(
138
+ `Job retry scheduled: ${job.name} (${job.id}), attempt ${job.attemptsMade + 1}/${maxAttempts}, delay ${delay}ms`,
139
+ );
140
+ } catch (retryError: any) {
141
+ // If re-add fails, nack with requeue to preserve the message
142
+ this.logger.error(`Failed to schedule retry for job ${job.id}: ${retryError.message}`);
143
+ channel.nack(msg, false, true); // Requeue the original message
144
+ }
145
+ } else {
146
+ // Max attempts reached - move to DLQ
147
+ channel.nack(msg, false, false);
148
+ this.emitEvent(queueName, QueueEvent.FAILED, job, error);
149
+ this.logger.error(`Job failed permanently: ${job.name} (${job.id}): ${error.message}`);
150
+ }
151
+ }
152
+ ```
153
+
154
+ 2. Update the job header to track retry attempts properly:
155
+
156
+ ```typescript
157
+ // In add() method, update headers
158
+ const messageOptions: amqp.Options.Publish = {
159
+ persistent: true,
160
+ messageId: job.id,
161
+ contentType: 'application/json',
162
+ headers: {
163
+ 'x-job-name': jobName,
164
+ 'x-job-id': job.id,
165
+ 'x-original-job-id': opts?.originalJobId || job.id, // Track original job
166
+ 'x-attempts': job.attemptsMade || 0,
167
+ 'x-max-attempts': opts?.attempts || 1,
168
+ 'x-timestamp': job.timestamp,
169
+ },
170
+ };
171
+ ```
172
+
173
+ ---
174
+
175
+ ## Phase 2: P1 Bug Fixes
176
+
177
+ ### 2.1 RabbitMQ Event Listener Isolation
178
+
179
+ **File:** `lib/provider/rabbitmq/rabbitmq.provider.ts`
180
+
181
+ **Problem:** Event listeners receive events from ALL jobs, causing cross-contamination.
182
+
183
+ **Implementation Steps:**
184
+
185
+ 1. Add job filtering to event registration:
186
+
187
+ ```typescript
188
+ /**
189
+ * Event listener registration with optional job filtering
190
+ */
191
+ on(
192
+ queueName: string,
193
+ event: QueueEvent,
194
+ callback: (job: IJob, result?: any) => void,
195
+ filter?: { jobName?: string; jobId?: string },
196
+ ): void {
197
+ if (!this.eventListeners.has(queueName)) {
198
+ this.eventListeners.set(queueName, new Map());
199
+ }
200
+
201
+ const queueListeners = this.eventListeners.get(queueName)!;
202
+ if (!queueListeners.has(event)) {
203
+ queueListeners.set(event, []);
204
+ }
205
+
206
+ // Wrap callback with filter logic
207
+ const filteredCallback = (job: IJob, result?: any) => {
208
+ if (filter?.jobName && job.name !== filter.jobName) return;
209
+ if (filter?.jobId && job.id !== filter.jobId) return;
210
+ callback(job, result);
211
+ };
212
+
213
+ queueListeners.get(event)!.push(filteredCallback);
214
+ }
215
+ ```
216
+
217
+ 2. Update the interface:
218
+
219
+ ```typescript
220
+ // In queue-provider.interface.ts
221
+ on(
222
+ queueName: string,
223
+ event: QueueEvent,
224
+ callback: (job: IJob, result?: any) => void,
225
+ filter?: { jobName?: string; jobId?: string },
226
+ ): void;
227
+ ```
228
+
229
+ 3. Apply same pattern to Kafka and BullMQ providers for consistency.
230
+
231
+ ---
232
+
233
+ ### 2.2 Kafka Delayed Job Duplication Fix
234
+
235
+ **File:** `lib/provider/kafka/kafka.provider.ts`
236
+
237
+ **Problem:** Re-adding delayed jobs creates duplicates.
238
+
239
+ **Implementation Steps:**
240
+
241
+ 1. Track processed delayed jobs with a Set:
242
+
243
+ ```typescript
244
+ private readonly processedDelayedJobs: Set<string> = new Set();
245
+ private readonly DELAYED_JOB_TTL = 3600000; // 1 hour
246
+
247
+ // In eachMessage handler:
248
+ if (processAfter && parseInt(processAfter) > Date.now()) {
249
+ const delayKey = `${job.id}-${processAfter}`;
250
+
251
+ // Skip if already re-queued
252
+ if (this.processedDelayedJobs.has(delayKey)) {
253
+ return;
254
+ }
255
+
256
+ this.processedDelayedJobs.add(delayKey);
257
+
258
+ // Clean up old entries periodically
259
+ setTimeout(() => this.processedDelayedJobs.delete(delayKey), this.DELAYED_JOB_TTL);
260
+
261
+ const delay = parseInt(processAfter) - Date.now();
262
+ await this.add(queueName, job.name, job.data, {
263
+ ...job.opts,
264
+ delay,
265
+ jobId: job.id, // Keep same ID
266
+ });
267
+ return;
268
+ }
269
+ ```
270
+
271
+ 2. Better approach - use a scheduled executor:
272
+
273
+ ```typescript
274
+ private readonly delayedJobScheduler: Map<string, NodeJS.Timeout> = new Map();
275
+
276
+ // Instead of re-adding, schedule local execution
277
+ if (processAfter && parseInt(processAfter) > Date.now()) {
278
+ const delay = parseInt(processAfter) - Date.now();
279
+ const scheduleKey = `${queueName}:${job.id}`;
280
+
281
+ if (!this.delayedJobScheduler.has(scheduleKey)) {
282
+ const timeout = setTimeout(async () => {
283
+ this.delayedJobScheduler.delete(scheduleKey);
284
+ try {
285
+ this.emitEvent(queueName, QueueEvent.ACTIVE, job);
286
+ const result = await processor(job);
287
+ job.returnvalue = result;
288
+ this.emitEvent(queueName, QueueEvent.COMPLETED, job, result);
289
+ } catch (err: any) {
290
+ job.failedReason = err.message;
291
+ this.emitEvent(queueName, QueueEvent.FAILED, job, err);
292
+ }
293
+ }, delay);
294
+
295
+ this.delayedJobScheduler.set(scheduleKey, timeout);
296
+ }
297
+ return;
298
+ }
299
+ ```
300
+
301
+ ---
302
+
303
+ ## Phase 3: Security Fixes
304
+
305
+ ### 3.1 Input Validation
306
+
307
+ **New File:** `lib/utils/validation.ts`
308
+
309
+ ```typescript
310
+ import { Logger } from '@nestjs/common';
311
+
312
+ const logger = new Logger('QueueValidation');
313
+
314
+ export interface ValidationOptions {
315
+ maxPayloadSize?: number; // bytes, default 1MB
316
+ maxJobIdLength?: number; // default 256
317
+ allowedJobIdPattern?: RegExp;
318
+ }
319
+
320
+ const DEFAULT_OPTIONS: ValidationOptions = {
321
+ maxPayloadSize: 1024 * 1024, // 1MB
322
+ maxJobIdLength: 256,
323
+ allowedJobIdPattern: /^[a-zA-Z0-9_-]+$/,
324
+ };
325
+
326
+ export function validateJobId(id: string, options = DEFAULT_OPTIONS): void {
327
+ if (!id || typeof id !== 'string') {
328
+ throw new Error('Job ID must be a non-empty string');
329
+ }
330
+
331
+ if (id.length > (options.maxJobIdLength || 256)) {
332
+ throw new Error(`Job ID exceeds maximum length of ${options.maxJobIdLength}`);
333
+ }
334
+
335
+ if (options.allowedJobIdPattern && !options.allowedJobIdPattern.test(id)) {
336
+ throw new Error('Job ID contains invalid characters');
337
+ }
338
+ }
339
+
340
+ export function validateJobData<T>(data: T, options = DEFAULT_OPTIONS): void {
341
+ const serialized = JSON.stringify(data);
342
+
343
+ if (serialized.length > (options.maxPayloadSize || 1024 * 1024)) {
344
+ throw new Error(`Job payload exceeds maximum size of ${options.maxPayloadSize} bytes`);
345
+ }
346
+
347
+ // Check for prototype pollution attempts
348
+ const dangerous = ['__proto__', 'constructor', 'prototype'];
349
+ const checkForDangerous = (obj: any, path = ''): void => {
350
+ if (obj && typeof obj === 'object') {
351
+ for (const key of Object.keys(obj)) {
352
+ if (dangerous.includes(key)) {
353
+ throw new Error(`Dangerous key "${key}" found in job data at ${path}`);
354
+ }
355
+ checkForDangerous(obj[key], `${path}.${key}`);
356
+ }
357
+ }
358
+ };
359
+
360
+ checkForDangerous(data);
361
+ }
362
+ ```
363
+
364
+ ### 3.2 Sanitize Error Logging
365
+
366
+ **File:** `lib/utils/sanitize.ts`
367
+
368
+ ```typescript
369
+ const SENSITIVE_PATTERNS = [
370
+ /password[=:]\s*\S+/gi,
371
+ /secret[=:]\s*\S+/gi,
372
+ /token[=:]\s*\S+/gi,
373
+ /key[=:]\s*\S+/gi,
374
+ /auth[=:]\s*\S+/gi,
375
+ ];
376
+
377
+ export function sanitizeErrorMessage(message: string): string {
378
+ let sanitized = message;
379
+ for (const pattern of SENSITIVE_PATTERNS) {
380
+ sanitized = sanitized.replace(pattern, (match) => {
381
+ const [key] = match.split(/[=:]/);
382
+ return `${key}=***REDACTED***`;
383
+ });
384
+ }
385
+ return sanitized;
386
+ }
387
+ ```
388
+
389
+ ---
390
+
391
+ ## Testing Plan
392
+
393
+ 1. **Unit Tests:**
394
+ - `mapJobOptions` filtering undefined values
395
+ - `validateJobId` edge cases
396
+ - `validateJobData` payload size and prototype pollution
397
+ - `sanitizeErrorMessage` patterns
398
+
399
+ 2. **Integration Tests:**
400
+ - BullMQ job processing with various option combinations
401
+ - RabbitMQ retry scenarios with simulated connection drops
402
+ - Kafka delayed job deduplication
403
+
404
+ 3. **E2E Tests:**
405
+ - Re-run existing e2e tests after fixes
406
+ - Add new tests for edge cases
407
+
408
+ ---
409
+
410
+ ## Files to Modify
411
+
412
+ 1. `lib/provider/bullmq/bullmq.provider.ts` - mapJobOptions fix
413
+ 2. `lib/provider/rabbitmq/rabbitmq.provider.ts` - retry race condition + event isolation
414
+ 3. `lib/provider/kafka/kafka.provider.ts` - delayed job deduplication
415
+ 4. `lib/interface/queue-provider.interface.ts` - update on() signature
416
+ 5. `lib/utils/validation.ts` - NEW FILE
417
+ 6. `lib/utils/sanitize.ts` - NEW FILE
418
+ 7. `lib/utils/index.ts` - export new utils
419
+ 8. `test/bullmq.provider.spec.ts` - add mapJobOptions tests
420
+ 9. `test/validation.spec.ts` - NEW FILE
421
+
422
+ ---
423
+
424
+ ## Rollback Plan
425
+
426
+ All changes are isolated to specific methods. If issues arise:
427
+ 1. Revert specific provider file to previous commit
428
+ 2. Each fix can be rolled back independently
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@nathapp/nestjs-queue",
3
+ "version": "2.1.0-rc.1",
4
+ "description": "NestJS Queue Module with multi-provider support (BullMQ, Kafka, RabbitMQ, Redis Pub/Sub)",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "scripts": {
8
+ "clean": "rimraf dist/ .turbo/",
9
+ "build": "rimraf dist && tsc -p tsconfig.json",
10
+ "precommit": "lint-staged",
11
+ "test": "jest --config ./test/jest-test.json",
12
+ "test:cov": "jest --config ./test/jest-test.json --coverage",
13
+ "test:watch": "jest --config ./test/jest-test.json --watch",
14
+ "test:e2e": "npm run test:e2e:up && npm run test:e2e:run; TEST_EXIT_CODE=$?; npm run test:e2e:down; exit $TEST_EXIT_CODE",
15
+ "test:e2e:up": "sudo docker compose -f docker-compose.e2e.yml up -d --wait && sleep 5",
16
+ "test:e2e:run": "jest --config ./test/jest-e2e.json --runInBand --forceExit",
17
+ "test:e2e:down": "sudo docker compose -f docker-compose.e2e.yml down -v",
18
+ "lint": "eslint -c .eslintrc.js"
19
+ },
20
+ "author": "William Khoo",
21
+ "license": "ISC",
22
+ "dependencies": {
23
+ "@nathapp/nestjs-common": "2.0.4",
24
+ "uuid": "^9.0.0"
25
+ },
26
+ "peerDependencies": {
27
+ "@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0",
28
+ "@nestjs/core": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0",
29
+ "bullmq": "^5.0.0",
30
+ "ioredis": "^5.0.0",
31
+ "kafkajs": "^2.0.0",
32
+ "amqplib": "^0.10.0",
33
+ "amqp-connection-manager": "^4.0.0"
34
+ },
35
+ "peerDependenciesMeta": {
36
+ "bullmq": {
37
+ "optional": true
38
+ },
39
+ "ioredis": {
40
+ "optional": true
41
+ },
42
+ "kafkajs": {
43
+ "optional": true
44
+ },
45
+ "amqplib": {
46
+ "optional": true
47
+ },
48
+ "amqp-connection-manager": {
49
+ "optional": true
50
+ }
51
+ },
52
+ "devDependencies": {
53
+ "@nestjs/testing": "^11.0.0",
54
+ "@types/amqplib": "^0.10.0",
55
+ "@types/jest": "^29.5.2",
56
+ "@types/uuid": "^9.0.0",
57
+ "bullmq": "^5.34.8",
58
+ "ioredis": "^5.4.1",
59
+ "kafkajs": "^2.2.4",
60
+ "amqplib": "^0.10.4",
61
+ "amqp-connection-manager": "^4.1.14",
62
+ "eslint": "^8.57.0",
63
+ "jest": "^29.5.0",
64
+ "ts-jest": "^29.1.0",
65
+ "typescript": "^5"
66
+ },
67
+ "directories": {
68
+ "lib": "lib"
69
+ }
70
+ }