@dawntech/dispatcher 0.2.6 → 0.2.8

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 (89) hide show
  1. package/dist/index.d.mts +583 -11
  2. package/dist/index.js +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +1 -1
  5. package/dist/index.mjs.map +1 -1
  6. package/eslint.config.mjs +33 -0
  7. package/package.json +17 -2
  8. package/dist/chunk-4LYB64T2.mjs +0 -2
  9. package/dist/chunk-4LYB64T2.mjs.map +0 -1
  10. package/dist/chunk-64334IMD.mjs +0 -2
  11. package/dist/chunk-64334IMD.mjs.map +0 -1
  12. package/dist/chunk-B7IDVU6T.mjs +0 -2
  13. package/dist/chunk-B7IDVU6T.mjs.map +0 -1
  14. package/dist/chunk-CVPGUSFU.mjs +0 -2
  15. package/dist/chunk-CVPGUSFU.mjs.map +0 -1
  16. package/dist/chunk-HYW2O7ZX.mjs +0 -2
  17. package/dist/chunk-HYW2O7ZX.mjs.map +0 -1
  18. package/dist/chunk-JD53PFR4.mjs +0 -2
  19. package/dist/chunk-JD53PFR4.mjs.map +0 -1
  20. package/dist/chunk-OXXLVJVC.mjs +0 -2
  21. package/dist/chunk-OXXLVJVC.mjs.map +0 -1
  22. package/dist/chunk-PAKGTHKD.mjs +0 -2
  23. package/dist/chunk-PAKGTHKD.mjs.map +0 -1
  24. package/dist/chunk-QA6PFVGP.mjs +0 -2
  25. package/dist/chunk-QA6PFVGP.mjs.map +0 -1
  26. package/dist/chunk-UFUGEIFL.mjs +0 -2
  27. package/dist/chunk-UFUGEIFL.mjs.map +0 -1
  28. package/dist/chunk-VTJMLZE3.mjs +0 -2
  29. package/dist/chunk-VTJMLZE3.mjs.map +0 -1
  30. package/dist/core/Blip.d.mts +0 -84
  31. package/dist/core/Blip.js +0 -2
  32. package/dist/core/Blip.js.map +0 -1
  33. package/dist/core/Blip.mjs +0 -2
  34. package/dist/core/Blip.mjs.map +0 -1
  35. package/dist/core/Dispatcher.d.mts +0 -52
  36. package/dist/core/Dispatcher.js +0 -2
  37. package/dist/core/Dispatcher.js.map +0 -1
  38. package/dist/core/Dispatcher.mjs +0 -2
  39. package/dist/core/Dispatcher.mjs.map +0 -1
  40. package/dist/core/DispatcherDescriptor.d.mts +0 -23
  41. package/dist/core/DispatcherDescriptor.js +0 -2
  42. package/dist/core/DispatcherDescriptor.js.map +0 -1
  43. package/dist/core/DispatcherDescriptor.mjs +0 -2
  44. package/dist/core/DispatcherDescriptor.mjs.map +0 -1
  45. package/dist/core/DispatcherMonitor.d.mts +0 -52
  46. package/dist/core/DispatcherMonitor.js +0 -2
  47. package/dist/core/DispatcherMonitor.js.map +0 -1
  48. package/dist/core/DispatcherMonitor.mjs +0 -2
  49. package/dist/core/DispatcherMonitor.mjs.map +0 -1
  50. package/dist/core/DispatcherQuery.d.mts +0 -14
  51. package/dist/core/DispatcherQuery.js +0 -2
  52. package/dist/core/DispatcherQuery.js.map +0 -1
  53. package/dist/core/DispatcherQuery.mjs +0 -2
  54. package/dist/core/DispatcherQuery.mjs.map +0 -1
  55. package/dist/core/DispatcherRepository.d.mts +0 -50
  56. package/dist/core/DispatcherRepository.js +0 -2
  57. package/dist/core/DispatcherRepository.js.map +0 -1
  58. package/dist/core/DispatcherRepository.mjs +0 -2
  59. package/dist/core/DispatcherRepository.mjs.map +0 -1
  60. package/dist/core/DispatcherStateMachine.d.mts +0 -20
  61. package/dist/core/DispatcherStateMachine.js +0 -2
  62. package/dist/core/DispatcherStateMachine.js.map +0 -1
  63. package/dist/core/DispatcherStateMachine.mjs +0 -2
  64. package/dist/core/DispatcherStateMachine.mjs.map +0 -1
  65. package/dist/errors/index.d.mts +0 -54
  66. package/dist/errors/index.js +0 -2
  67. package/dist/errors/index.js.map +0 -1
  68. package/dist/errors/index.mjs +0 -2
  69. package/dist/errors/index.mjs.map +0 -1
  70. package/dist/server.d.mts +0 -2
  71. package/dist/server.js +0 -2
  72. package/dist/server.js.map +0 -1
  73. package/dist/server.mjs +0 -2
  74. package/dist/server.mjs.map +0 -1
  75. package/dist/types/blip.d.mts +0 -127
  76. package/dist/types/blip.js +0 -2
  77. package/dist/types/blip.js.map +0 -1
  78. package/dist/types/blip.mjs +0 -2
  79. package/dist/types/blip.mjs.map +0 -1
  80. package/dist/types/index.d.mts +0 -160
  81. package/dist/types/index.js +0 -2
  82. package/dist/types/index.js.map +0 -1
  83. package/dist/types/index.mjs +0 -2
  84. package/dist/types/index.mjs.map +0 -1
  85. package/dist/utils/logger.d.mts +0 -73
  86. package/dist/utils/logger.js +0 -2
  87. package/dist/utils/logger.js.map +0 -1
  88. package/dist/utils/logger.mjs +0 -2
  89. package/dist/utils/logger.mjs.map +0 -1
package/dist/index.d.mts CHANGED
@@ -1,11 +1,583 @@
1
- export { CallbackMap, DispatcherDescriptor, DispatcherDescriptorOptions } from './core/DispatcherDescriptor.mjs';
2
- export { Dispatcher } from './core/Dispatcher.mjs';
3
- export { Blip, BlipError } from './core/Blip.mjs';
4
- export { DispatcherMonitor, MonitorAlert, MonitorOptions, MonitorRule } from './core/DispatcherMonitor.mjs';
5
- export { DispatcherRepository } from './core/DispatcherRepository.mjs';
6
- export { enableLogger, getLogger } from './utils/logger.mjs';
7
- export { CallbackEvent, ConnectionConfig, Contact, DispatchMessageOptions, DispatchState, DispatcherManifest, DispatcherMetrics, DispatcherOptions, Intent, Message, MessageData, MessageDispatcherOptions, MessageOptions, MessagePayload, MessageState, MessageStatus, QueryFilter, Shift, Weekdays } from './types/index.mjs';
8
- export { BlipConfig, DateInterval, PartiallyOptional, PartiallyRequiredStrict, Vnd } from './types/blip.mjs';
9
- import './core/DispatcherQuery.mjs';
10
- import 'events';
11
- import 'ioredis';
1
+ import IORedis from 'ioredis';
2
+ import { EventEmitter } from 'events';
3
+
4
+ /**
5
+ * Type definitions for Blip Platform API
6
+ * Based on the LIME protocol and Blip extensions
7
+ */
8
+ declare namespace Vnd {
9
+ namespace Lime {
10
+ enum Method {
11
+ GET = "get",
12
+ SET = "set",
13
+ DELETE = "delete",
14
+ OBSERVE = "observe",
15
+ SUBSCRIBE = "subscribe",
16
+ MERGE = "merge"
17
+ }
18
+ enum Status {
19
+ SUCCESS = "success",
20
+ FAILURE = "failure"
21
+ }
22
+ namespace Transport {
23
+ namespace Payload {
24
+ interface Request<T = unknown> {
25
+ id?: string;
26
+ to?: string;
27
+ method: Method;
28
+ uri: string;
29
+ type?: string;
30
+ resource?: T;
31
+ }
32
+ interface Response<T = unknown> {
33
+ id?: string;
34
+ from?: string;
35
+ to?: string;
36
+ method?: Method;
37
+ status: Status;
38
+ type?: string;
39
+ resource?: T;
40
+ reason?: {
41
+ code: number;
42
+ description: string;
43
+ };
44
+ }
45
+ }
46
+ }
47
+ interface Message<T = unknown> {
48
+ id?: string;
49
+ to: string;
50
+ from?: string;
51
+ type: string;
52
+ content: T;
53
+ }
54
+ namespace Command {
55
+ interface Resource<T = unknown> {
56
+ [key: string]: T;
57
+ }
58
+ }
59
+ }
60
+ namespace Iris {
61
+ interface ThreadMessage {
62
+ id: string;
63
+ direction: 'sent' | 'received';
64
+ type: string;
65
+ content: unknown;
66
+ date: string;
67
+ status?: string;
68
+ [key: string]: unknown;
69
+ }
70
+ interface Contact {
71
+ identity: string;
72
+ name?: string;
73
+ email?: string;
74
+ phoneNumber?: string;
75
+ taxDocument?: string;
76
+ gender?: string;
77
+ city?: string;
78
+ extras?: Record<string, string>;
79
+ [key: string]: unknown;
80
+ }
81
+ interface EventTrack {
82
+ category: string;
83
+ action: string;
84
+ contact?: {
85
+ identity: string;
86
+ };
87
+ extras?: unknown;
88
+ count?: number;
89
+ }
90
+ interface Ticket {
91
+ id: string;
92
+ sequentialId: number;
93
+ ownerIdentity: string;
94
+ customerIdentity: string;
95
+ providerIdentity: string;
96
+ status: string;
97
+ storageDate: string;
98
+ externalId?: string;
99
+ rating?: number;
100
+ team?: string;
101
+ agentIdentity?: string;
102
+ closedDate?: string;
103
+ transfers?: number;
104
+ [key: string]: unknown;
105
+ }
106
+ namespace ActiveCampaign {
107
+ interface AudienceSummary {
108
+ total: number;
109
+ sent: number;
110
+ failed: number;
111
+ scheduled: number;
112
+ canceled: number;
113
+ }
114
+ }
115
+ }
116
+ }
117
+ interface BlipConfig {
118
+ botUrl: string;
119
+ botKey: string;
120
+ timeout?: number;
121
+ maxRetries?: number;
122
+ }
123
+ interface DateInterval {
124
+ from?: Date;
125
+ to: Date;
126
+ }
127
+ type PartiallyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
128
+ type PartiallyRequiredStrict<T, K extends keyof T> = T & Required<Pick<T, K>>;
129
+
130
+ type Contact = Omit<Vnd.Iris.Contact, 'identity'>;
131
+ type MessageData = {
132
+ type: string;
133
+ content: Record<string, unknown> | string;
134
+ };
135
+ type MessagePayload = Record<string, unknown> | Array<unknown> | string;
136
+ declare enum MessageState {
137
+ INIT = "INIT",
138
+ DISPATCHED = "DISPATCHED",
139
+ SCHEDULED = "SCHEDULED",
140
+ QUEUED = "QUEUED",
141
+ FINAL = "FINAL"
142
+ }
143
+ declare enum MessageStatus {
144
+ INIT = "INIT",
145
+ PENDING = "PENDING",
146
+ SENDING = "SENDING",
147
+ DELIVERED = "DELIVERED",
148
+ READ = "READ",
149
+ REPLIED = "REPLIED",
150
+ FAILED = "FAILED",
151
+ CANCELED = "CANCELED"
152
+ }
153
+ declare enum DispatchState {
154
+ ACCEPTED = "accepted",
155
+ DISPATCHED = "dispatched",
156
+ RECEIVED = "received",
157
+ CONSUMED = "consumed",
158
+ FAILED = "failed"
159
+ }
160
+ interface Message {
161
+ messageId: string;
162
+ contactId: string;
163
+ descriptorId: string;
164
+ payload: MessageData;
165
+ status: MessageStatus;
166
+ state: MessageState;
167
+ attempts?: number;
168
+ retries?: number;
169
+ options?: MessageOptions;
170
+ expiresAt?: string;
171
+ scheduledTo?: string;
172
+ sentAt?: string;
173
+ acceptedAt?: string;
174
+ lastDispatchAttemptAt?: string;
175
+ createdAt: string;
176
+ deliveredAt?: string;
177
+ readAt?: string;
178
+ repliedAt?: string;
179
+ failedAt?: string;
180
+ error?: string;
181
+ }
182
+ interface Shift {
183
+ days: number;
184
+ start: string;
185
+ end: string;
186
+ gmt?: string;
187
+ }
188
+ declare enum Channel {
189
+ BLIP_CHAT = "BLIP_CHAT",
190
+ EMAIL = "EMAIL",
191
+ MESSENGER = "MESSENGER",
192
+ SKYPE = "SKYPE",
193
+ SMS_TAKE = "SMS_TAKE",
194
+ SMS_TANGRAM = "SMS_TANGRAM",
195
+ TELEGRAM = "TELEGRAM",
196
+ WHATSAPP = "WHATSAPP",
197
+ INSTAGRAM = "INSTAGRAM",
198
+ GOOGLE_RCS = "GOOGLE_RCS",
199
+ MICROSOFT_TEAMS = "MICROSOFT_TEAMS",
200
+ APPLE_BUSINESS_CHAT = "APPLE_BUSINESS_CHAT",
201
+ WORKPLACE = "WORKPLACE"
202
+ }
203
+ declare enum Weekdays {
204
+ MONDAY = 1,
205
+ TUESDAY = 2,
206
+ WEDNESDAY = 4,
207
+ THURSDAY = 8,
208
+ FRIDAY = 16,
209
+ SATURDAY = 32,
210
+ SUNDAY = 64
211
+ }
212
+ interface Intent {
213
+ intent: string;
214
+ dueDate?: string;
215
+ event?: string;
216
+ payload?: unknown;
217
+ expired?: {
218
+ event?: string;
219
+ intent?: string;
220
+ };
221
+ }
222
+ type CallbackEvent = 'dispatch' | 'sending' | 'delivered' | 'failed' | 'read' | 'replied' | 'scheduled' | 'retry' | 'evicted' | 'canceled';
223
+ type ConnectionConfig = {
224
+ contract: string;
225
+ key: string;
226
+ };
227
+ interface MessageOptions {
228
+ shifts?: Array<Shift>;
229
+ contact?: Contact;
230
+ state?: {
231
+ stateId: string;
232
+ botId: string;
233
+ botIds?: Array<string>;
234
+ };
235
+ intent?: string | Intent;
236
+ finalStatus?: 'DELIVERED' | 'READ' | 'REPLIED';
237
+ }
238
+ interface DispatchMessageOptions extends MessageOptions {
239
+ schedule?: string;
240
+ }
241
+ interface DispatcherOptions {
242
+ maxRetries?: number;
243
+ retryIntervals?: number[];
244
+ retention?: number;
245
+ timeouts?: {
246
+ pending?: number;
247
+ sending?: number;
248
+ };
249
+ batchSize?: number;
250
+ pollingIntervals?: {
251
+ scheduled?: number;
252
+ pending?: number;
253
+ sending?: number;
254
+ delivered?: number;
255
+ read?: number;
256
+ queue?: number;
257
+ };
258
+ maxQueueSize?: number;
259
+ rateLimits?: {
260
+ global?: {
261
+ points: number;
262
+ duration: number;
263
+ };
264
+ message?: {
265
+ points: number;
266
+ duration: number;
267
+ };
268
+ };
269
+ }
270
+ interface QueryFilter {
271
+ contactId?: string;
272
+ descriptorId?: string;
273
+ status?: MessageStatus | MessageStatus[];
274
+ state?: MessageState | MessageState[];
275
+ size?: number;
276
+ skip?: number;
277
+ }
278
+ interface DispatcherMetrics {
279
+ total: number;
280
+ byState: {
281
+ [key in MessageState]?: number;
282
+ };
283
+ byStatus: {
284
+ [key in MessageStatus]?: number;
285
+ };
286
+ cumulative: {
287
+ dispatched: number;
288
+ delivered: number;
289
+ failed: number;
290
+ };
291
+ }
292
+ interface DispatcherManifest {
293
+ version: string;
294
+ createdAt: string;
295
+ updatedAt: string;
296
+ }
297
+ /**
298
+ * @deprecated Use DispatcherOptions instead
299
+ */
300
+ type MessageDispatcherOptions = DispatcherOptions;
301
+
302
+ /**
303
+ * Blip - Low-level client wrapper for Blip Platform API interactions
304
+ *
305
+ * Responsibilities:
306
+ * - Send messages to contacts via Blip HTTP API
307
+ * - Merge contact metadata (custom fields)
308
+ * - Send analytics events to Blip
309
+ * - Manage bot conversation state transitions
310
+ * - Check message delivery status
311
+ */
312
+
313
+ declare class Blip {
314
+ private client;
315
+ /**
316
+ * Create a new Blip instance
317
+ * @param contract - Blip contract ID (without https:// prefix)
318
+ * @param key - Blip API key
319
+ * @param timeout - Request timeout in milliseconds (default: 30000)
320
+ */
321
+ constructor(contract: string, key: string, timeout?: number);
322
+ /**
323
+ * Send a command to the Blip API
324
+ */
325
+ private postCommand;
326
+ /**
327
+ * Send a message through the Blip API
328
+ */
329
+ private postMessage;
330
+ /**
331
+ * Merge contact metadata (custom fields)
332
+ * @param contactId - Contact identifier
333
+ * @param data - Key-value pairs to merge into contact
334
+ */
335
+ mergeContact(contactId: string, data: Omit<Vnd.Iris.Contact, 'identity'>): Promise<void>;
336
+ /**
337
+ * Send a message to a contact
338
+ * @param contactId - Contact identifier
339
+ * @param message - Message data to send
340
+ * @param id - Optional message ID (if not provided, a new one is generated)
341
+ * @returns message ID
342
+ */
343
+ sendMessage(contactId: string, message: MessageData, id?: string): Promise<string>;
344
+ /**
345
+ * Get raw dispatch state from Blip notifications
346
+ * @param messageId - Message ID to check
347
+ * @param contactId - Contact identifier to filter notifications
348
+ * @returns DispatchState or null if not found
349
+ */
350
+ getDispatchState(messageId: string, contactId: string): Promise<DispatchState | null>;
351
+ /**
352
+ * Get the first message received after a specific message ID
353
+ * @param contactId - Contact identifier
354
+ * @param messageId - Message ID to use as anchor
355
+ * @returns ThreadMessage or null if no message found
356
+ */
357
+ getMessageAfter(contactId: string, messageId: string): Promise<Vnd.Iris.ThreadMessage | null>;
358
+ /**
359
+ * Send an analytics event to Blip
360
+ * @param contactId - Contact identifier
361
+ * @param category - Event category
362
+ * @param action - Event action
363
+ * @param extras - Additional event data
364
+ */
365
+ sendEvent(contactId: string, category: string, action: string, extras: Record<string, string>): Promise<void>;
366
+ /**
367
+ * Set the bot conversation state for a contact
368
+ * @param contactId - Contact identifier
369
+ * @param botId - Bot identifier (short name)
370
+ * @param stateId - State identifier (default: "onboarding")
371
+ */
372
+ setState(contactId: string, botId: string, stateId?: string): Promise<void>;
373
+ }
374
+ /**
375
+ * Custom error class for Blip errors
376
+ */
377
+ declare class BlipError extends Error {
378
+ code: number;
379
+ constructor(message: string, code: number);
380
+ }
381
+
382
+ type CallbackMap = Partial<Record<CallbackEvent, (message: Message, api: Blip, dispatcherId: string) => void>>;
383
+ interface DispatcherDescriptorOptions extends MessageOptions {
384
+ toContactId?: (contactId: string) => string;
385
+ }
386
+ declare class DispatcherDescriptor {
387
+ readonly id: string;
388
+ private transformFn;
389
+ private callbacks;
390
+ private options?;
391
+ private contactIdTransform;
392
+ constructor(id: string, transform: (payload: MessagePayload) => MessageData, options?: DispatcherDescriptorOptions);
393
+ transform(payload: MessagePayload): MessageData;
394
+ toContactId(contactId: string): string;
395
+ get messageOptions(): MessageOptions | undefined;
396
+ on(event: CallbackEvent, callback: (message: Message, api: Blip, dispatcherId: string) => void): this;
397
+ emit(event: CallbackEvent, message: Message, api: Blip, dispatcherId: string): void;
398
+ }
399
+
400
+ declare class DispatcherRepository {
401
+ private static readonly INDEXED_STATUSES;
402
+ private static readonly INDEXED_STATES;
403
+ private client;
404
+ private keyPrefix;
405
+ constructor(dispatcherId: string, redisUrl: string);
406
+ setup(): Promise<void>;
407
+ teardown(): Promise<void>;
408
+ get redis(): IORedis;
409
+ getManifestKey(): string;
410
+ getKey(messageId: string): string;
411
+ getStateKey(state: MessageState): string;
412
+ getStatusKey(status: MessageStatus): string;
413
+ getContactKey(contactId: string): string;
414
+ getDescriptorKey(descriptorId: string): string;
415
+ getQueueKey(name: 'scheduled' | 'queued' | 'dispatched' | 'expiration' | 'retention'): string;
416
+ upsertMessage(message: Message, ttl?: number): Promise<void>;
417
+ getMessage(messageId: string): Promise<Message | null>;
418
+ getMessages(filter: {
419
+ status?: MessageStatus;
420
+ state?: MessageState;
421
+ size?: number;
422
+ skip?: number;
423
+ }): Promise<Message[]>;
424
+ getQueueSize(): Promise<number>;
425
+ evictOldest(count: number): Promise<number>;
426
+ getExpiredMessages(count?: number): Promise<string[]>;
427
+ getRetentionMessages(count?: number): Promise<string[]>;
428
+ incrementMetric(key: string, value?: number): Promise<number>;
429
+ getMetric(key: string): Promise<number>;
430
+ deleteMessage(messageId: string): Promise<void>;
431
+ private deleteMessageData;
432
+ countMessages(filter: {
433
+ status?: MessageStatus;
434
+ state?: MessageState;
435
+ }): Promise<number>;
436
+ getMetrics(descriptorId?: string): Promise<{
437
+ cumulative: {
438
+ dispatched: number;
439
+ delivered: number;
440
+ failed: number;
441
+ };
442
+ queues: {
443
+ queued: number;
444
+ scheduled: number;
445
+ dispatched: number;
446
+ };
447
+ status: Record<string, number>;
448
+ }>;
449
+ getDescriptors(): Promise<{
450
+ id: string;
451
+ count: number;
452
+ }[]>;
453
+ writeManifest(manifest: DispatcherManifest): Promise<void>;
454
+ getManifest(): Promise<DispatcherManifest | null>;
455
+ }
456
+
457
+ declare class DispatcherQuery {
458
+ private repository;
459
+ constructor(repository: DispatcherRepository);
460
+ private get client();
461
+ query(filter: QueryFilter): Promise<Message[]>;
462
+ private cleanupIndices;
463
+ }
464
+
465
+ declare class Dispatcher {
466
+ readonly id: string;
467
+ private repository;
468
+ private stateMachine;
469
+ private api;
470
+ private callbacks;
471
+ private descriptors;
472
+ private queue;
473
+ private worker;
474
+ private redis;
475
+ private queueName;
476
+ private maxRetries;
477
+ private retryIntervals;
478
+ private timeouts;
479
+ private retention;
480
+ private pollingIntervals;
481
+ private isRunning;
482
+ private setupCompleted;
483
+ private setupPromise;
484
+ private timeoutMonitorRunning;
485
+ private timeoutTimer;
486
+ readonly query: DispatcherQuery;
487
+ constructor(id: string, repository: DispatcherRepository, connection: ConnectionConfig, options?: DispatcherOptions);
488
+ setup(): Promise<void>;
489
+ private _doSetup;
490
+ teardown(): Promise<void>;
491
+ on(event: CallbackEvent, callback: (message: Message, api: Blip, dispatcherId: string) => void): this;
492
+ getMetrics(): Promise<DispatcherMetrics>;
493
+ private emit;
494
+ send(descriptor: DispatcherDescriptor, contactId: string, payload: MessagePayload, options?: DispatchMessageOptions): Promise<Message>;
495
+ cancel(messageId: string): Promise<boolean>;
496
+ private processJob;
497
+ private handleSendJob;
498
+ private handlePostSendOperations;
499
+ private handleCheckJob;
500
+ private checkAndHandleTimeout;
501
+ private handleTimeout;
502
+ private startTimeoutMonitor;
503
+ private _runTimeoutMonitorCycle;
504
+ private rescheduleCheck;
505
+ private handleDeliveredState;
506
+ private handleDispatchFailure;
507
+ private calculateScheduledTime;
508
+ private isWithinShifts;
509
+ private findNextShiftTime;
510
+ private getStatusRank;
511
+ static sanitizeContactId(id: string, source: Channel): string;
512
+ }
513
+
514
+ interface MonitorRule {
515
+ type: 'failure_rate' | 'queue_size';
516
+ threshold: number;
517
+ window?: number;
518
+ debounce?: number;
519
+ }
520
+ interface MonitorOptions {
521
+ interval?: number;
522
+ rules: MonitorRule[];
523
+ historySize?: number;
524
+ }
525
+ type MonitorAlert = {
526
+ type: string;
527
+ message: string;
528
+ level: 'warning' | 'critical';
529
+ details: Record<string, unknown>;
530
+ timestamp: string;
531
+ };
532
+ declare class DispatcherMonitor extends EventEmitter {
533
+ private id;
534
+ private repository;
535
+ private options;
536
+ private queue;
537
+ private worker;
538
+ private queueName;
539
+ private history;
540
+ private lastAlerts;
541
+ private activeAlerts;
542
+ private isRunning;
543
+ constructor(id: string, repository: DispatcherRepository, options: MonitorOptions);
544
+ start(): Promise<void>;
545
+ stop(): Promise<void>;
546
+ /**
547
+ * Independent metrics collection directly from Repository
548
+ */
549
+ private collectMetrics;
550
+ private check;
551
+ private cleanHistory;
552
+ private evaluateRule;
553
+ private isDebounced;
554
+ private emitAlert;
555
+ private resolveAlert;
556
+ private findSnapshotAt;
557
+ }
558
+
559
+ type LogFunction = (...args: unknown[]) => void;
560
+ interface Logger {
561
+ debug: LogFunction;
562
+ info: LogFunction;
563
+ warn: LogFunction;
564
+ error: LogFunction;
565
+ }
566
+ /**
567
+ * Creates a logger with a specific scope.
568
+ *
569
+ * @param scope - The scope for the logger (e.g., 'blip-api', 'dispatcher').
570
+ * @returns A logger object with methods for each log level.
571
+ */
572
+ declare function getLogger(scope: string): Logger;
573
+ /**
574
+ * Enables logging for a specific scope and level.
575
+ * This is a convenience function to programmatically enable logging,
576
+ * equivalent to setting the DEBUG environment variable.
577
+ *
578
+ * @param scope - The scope to enable (e.g., 'blip-api').
579
+ * @param level - The minimum log level to enable (e.g., 'info').
580
+ */
581
+ declare function enableLogger(namespaces: string): void;
582
+
583
+ export { Blip, type BlipConfig, BlipError, type CallbackEvent, type CallbackMap, Channel, type ConnectionConfig, type Contact, type DateInterval, type DispatchMessageOptions, DispatchState, Dispatcher, DispatcherDescriptor, type DispatcherDescriptorOptions, type DispatcherManifest, type DispatcherMetrics, DispatcherMonitor, type DispatcherOptions, DispatcherRepository, type Intent, type Message, type MessageData, type MessageDispatcherOptions, type MessageOptions, type MessagePayload, MessageState, MessageStatus, type MonitorAlert, type MonitorOptions, type MonitorRule, type PartiallyOptional, type PartiallyRequiredStrict, type QueryFilter, type Shift, Vnd, Weekdays, enableLogger, getLogger };