@queuedash/sdk 0.2.0 → 2.0.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Alex Budure
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @queuedash/sdk
2
2
 
3
- Official SDK for QueueDash - Real-time monitoring for Bull, BullMQ, and Bee-Queue.
3
+ Official SDK for Queuedash - Real-time monitoring for BullMQ, Bull, Bee-Queue, and GroupMQ.
4
4
 
5
5
  ## Installation
6
6
 
@@ -14,69 +14,75 @@ yarn add @queuedash/sdk
14
14
 
15
15
  ## Quick Start
16
16
 
17
+ The SDK auto-detects your queue library (BullMQ, Bull, Bee-Queue, or GroupMQ) - just use `attach()`:
18
+
17
19
  ### BullMQ
18
20
 
19
21
  ```typescript
20
22
  import { Queue } from "bullmq";
21
- import { QueueDashClient, attachToBullMQ } from "@queuedash/sdk";
23
+ import { Queuedash } from "@queuedash/sdk";
24
+
25
+ const qd = new Queuedash({ apiKey: process.env.QUEUEDASH_API_KEY });
22
26
 
23
- // Create your queue
24
27
  const myQueue = new Queue("my-queue", {
25
28
  connection: { host: "localhost", port: 6379 },
26
29
  });
27
30
 
28
- // Initialize QueueDash client
29
- const queueDash = new QueueDashClient({
30
- apiKey: process.env.QUEUEDASH_API_KEY,
31
- });
32
-
33
- // Attach to your queue - that's it!
34
- attachToBullMQ(myQueue, queueDash);
31
+ qd.attach(myQueue);
35
32
 
36
- // Jobs are now automatically synced to QueueDash
33
+ // Jobs are now automatically synced to Queuedash
37
34
  ```
38
35
 
39
36
  ### Bull
40
37
 
41
38
  ```typescript
42
39
  import Queue from "bull";
43
- import { QueueDashClient, attachToBull } from "@queuedash/sdk";
40
+ import { Queuedash } from "@queuedash/sdk";
44
41
 
45
- const myQueue = new Queue("my-queue", {
46
- redis: { host: "localhost", port: 6379 },
47
- });
42
+ const qd = new Queuedash({ apiKey: process.env.QUEUEDASH_API_KEY });
48
43
 
49
- const queueDash = new QueueDashClient({
50
- apiKey: process.env.QUEUEDASH_API_KEY,
51
- });
44
+ const myQueue = new Queue("my-queue", "redis://localhost:6379");
52
45
 
53
- attachToBull(myQueue, queueDash);
46
+ qd.attach(myQueue);
54
47
  ```
55
48
 
56
49
  ### Bee-Queue
57
50
 
58
51
  ```typescript
59
52
  import Queue from "bee-queue";
60
- import { QueueDashClient, attachToBeeQueue } from "@queuedash/sdk";
53
+ import { Queuedash } from "@queuedash/sdk";
54
+
55
+ const qd = new Queuedash({ apiKey: process.env.QUEUEDASH_API_KEY });
61
56
 
62
57
  const myQueue = new Queue("my-queue", {
63
58
  redis: { host: "localhost", port: 6379 },
64
59
  });
65
60
 
66
- const queueDash = new QueueDashClient({
67
- apiKey: process.env.QUEUEDASH_API_KEY,
68
- });
61
+ qd.attach(myQueue);
62
+ ```
63
+
64
+ ### Multiple Queues
69
65
 
70
- attachToBeeQueue(myQueue, queueDash);
66
+ ```typescript
67
+ import { Queue } from "bullmq";
68
+ import { Queuedash } from "@queuedash/sdk";
69
+
70
+ const qd = new Queuedash({ apiKey: process.env.QUEUEDASH_API_KEY });
71
+
72
+ const connection = { host: "localhost", port: 6379 };
73
+
74
+ qd.attach(new Queue("emails", { connection }));
75
+ qd.attach(new Queue("reports", { connection }));
76
+ qd.attach(new Queue("notifications", { connection }));
71
77
  ```
72
78
 
73
79
  ## Configuration
74
80
 
75
81
  ### API Key
76
82
 
77
- Get your API key from [QueueDash](https://queuedash.com):
83
+ Get your API key from [Queuedash](https://queuedash.com):
78
84
 
79
- 1. Navigate to your environment settings
85
+ 1. Navigate to your project
80
86
  2. Click "API Keys"
81
87
  3. Generate a new API key
82
88
 
@@ -85,34 +91,37 @@ Get your API key from [QueueDash](https://queuedash.com):
85
91
  QUEUEDASH_API_KEY=sk_live_...
86
92
  ```
87
93
 
88
- ### Advanced Options
94
+ ### Options
89
95
 
90
96
  ```typescript
91
- interface QueueDashClientOptions {
92
- // Required: Your API key from QueueDash
93
- apiKey: string;
97
+ const qd = new Queuedash({
98
+ // Required: Your API key from Queuedash
99
+ apiKey: string,
100
+
101
+ // Optional: Custom API URL (default: https://api.queuedash.com)
102
+ baseUrl?: string,
94
103
 
95
- // Optional: Batch size for syncing jobs (defaults to 50)
96
- batchSize?: number;
104
+ // Optional: Batch size for syncing jobs (default: 50)
105
+ batchSize?: number,
97
106
 
98
- // Optional: Flush interval in milliseconds (defaults to 100)
99
- flushInterval?: number;
107
+ // Optional: Flush interval in milliseconds (default: 100)
108
+ flushInterval?: number,
100
109
 
101
- // Optional: Max retry attempts with exponential backoff (defaults to 5)
102
- maxRetries?: number;
110
+ // Optional: Max retry attempts with exponential backoff (default: 5)
111
+ maxRetries?: number,
103
112
 
104
- // Optional: Request timeout in milliseconds (defaults to 30000)
105
- requestTimeout?: number;
113
+ // Optional: Request timeout in milliseconds (default: 30000)
114
+ requestTimeout?: number,
106
115
 
107
- // Optional: Max jobs to queue in memory (defaults to 10000)
108
- maxQueueSize?: number;
116
+ // Optional: Max jobs to queue in memory (default: 10000)
117
+ maxQueueSize?: number,
109
118
 
110
119
  // Optional: Error handler called on critical failures
111
- onError?: (error: Error) => void;
112
- }
120
+ onError?: (error: Error) => void,
121
+ });
113
122
  ```
114
123
 
115
- ### Reliability & Robustness
124
+ ## Reliability & Robustness
116
125
 
117
126
  The SDK is production-ready with multiple layers of protection:
118
127
 
@@ -137,7 +146,7 @@ The SDK is production-ready with multiple layers of protection:
137
146
  **Graceful Shutdown**
138
147
 
139
148
  - SIGTERM/SIGINT handlers flush pending jobs before exit
140
- - Warns if jobs remain unsynced on crash
149
+ - Call `await qd.stop()` to manually stop
141
150
  - No jobs lost during normal shutdown
142
151
 
143
152
  **Request Safety**
@@ -148,16 +157,9 @@ The SDK is production-ready with multiple layers of protection:
148
157
 
149
158
  ## Features
150
159
 
160
+ - **Auto-detection**: Works with BullMQ, Bull, Bee-Queue, and GroupMQ automatically
151
161
  - **Real-time sync**: Jobs are synced as events happen
152
162
  - **Smart batching**: Events are automatically batched for performance
153
163
  - **Auto-retry**: Failed syncs are automatically retried
154
164
  - **Zero config**: Works out of the box with sensible defaults
155
165
  - **TypeScript**: Full TypeScript support
156
-
157
- ## How It Works
158
-
159
- The SDK automatically syncs your queue jobs to QueueDash's SaaS platform at `api.queuedash.com`. Just provide your API key and you're done - no additional configuration needed!
160
-
161
- ## License
162
-
163
- MIT
package/dist/client.d.ts CHANGED
@@ -1,5 +1,9 @@
1
- import { JobData, QueueDashClientOptions } from "./types";
2
- export declare class QueueDashClient {
1
+ import { JobData, QueuedashOptions } from "./types";
2
+ type BullMQQueueEvents = {
3
+ on: (event: string, handler: (...args: any[]) => void) => any;
4
+ close: () => Promise<void>;
5
+ };
6
+ export declare class Queuedash {
3
7
  private apiKey;
4
8
  private apiUrl;
5
9
  private batchSize;
@@ -16,26 +20,60 @@ export declare class QueueDashClient {
16
20
  private circuitBreakerOpen;
17
21
  private circuitBreakerResetTimer?;
18
22
  private syncingJobIds;
19
- constructor(options: QueueDashClientOptions);
23
+ private managedQueueEvents;
24
+ private attachedQueues;
25
+ constructor(options: QueuedashOptions);
20
26
  /**
21
- * Delete a job (soft delete in QueueDash)
27
+ * Attach a queue or worker for monitoring.
28
+ * Auto-detects the queue library (BullMQ, Bull, Bee-Queue, GroupMQ).
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const qd = new Queuedash({ apiKey: 'qd_...' });
33
+ *
34
+ * // BullMQ - we create QueueEvents internally
35
+ * qd.attach(myBullMQQueue);
36
+ *
37
+ * // Bull
38
+ * qd.attach(myBullQueue);
39
+ *
40
+ * // Bee-Queue
41
+ * qd.attach(myBeeQueue);
42
+ * ```
43
+ */
44
+ attach(resource: unknown, options?: {
45
+ events?: BullMQQueueEvents;
46
+ }): this;
47
+ private detectType;
48
+ private attachBullMQ;
49
+ private attachBullMQWorker;
50
+ private attachBull;
51
+ private attachBee;
52
+ private extractBullMQJobData;
53
+ private extractBullJobData;
54
+ private extractBeeJobData;
55
+ /**
56
+ * Delete a job (soft delete in Queuedash)
22
57
  */
23
58
  deleteJob(jobId: string, queueName: string): Promise<void>;
24
59
  /**
25
- * Queue a job for syncing
60
+ * Queue a job for syncing (internal use)
26
61
  */
27
62
  syncJob(job: JobData): void;
28
63
  /**
29
64
  * Manually flush all pending jobs
30
65
  */
31
66
  flush(): Promise<void>;
67
+ private splitIntoChunks;
68
+ private sendBatch;
32
69
  private openCircuitBreaker;
33
- private logger;
70
+ private log;
34
71
  /**
35
- * Stop the client and flush remaining jobs
72
+ * Stop the client, close managed resources, and flush remaining jobs
36
73
  */
37
74
  stop(): Promise<void>;
38
75
  private startFlushTimer;
39
76
  private setupShutdownHandlers;
40
77
  }
78
+ export {};
41
79
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../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