@classytic/notifications 1.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/CHANGELOG.md +70 -37
- package/README.md +351 -201
- package/dist/channels/index.d.mts +2 -2
- package/dist/channels/index.mjs +2 -2
- package/dist/index.d.mts +38 -18
- package/dist/index.mjs +117 -28
- package/dist/{console.channel-BoWi_5nH.d.mts → push.channel-4mRkzrEu.d.mts} +18 -2
- package/dist/{console.channel-CfA4b_Er.mjs → push.channel-D1FdTPUi.mjs} +228 -6
- package/dist/status-webhook-BDaI1BMy.d.mts +268 -0
- package/dist/status-webhook-XY42DCj_.mjs +582 -0
- package/dist/{types-BnjZ7x2U.d.mts → types-D94B3VNX.d.mts} +251 -2
- package/dist/utils/index.d.mts +3 -3
- package/dist/utils/index.mjs +3 -3
- package/package.json +11 -11
- package/dist/concurrency-CV_XyiBQ.d.mts +0 -139
- package/dist/merge-hooks-B4_uHR9x.mjs +0 -233
- /package/dist/{errors-DAIVZx_Q.mjs → errors-FYJYmfvj.mjs} +0 -0
|
@@ -1,3 +1,60 @@
|
|
|
1
|
+
//#region src/utils/rate-limiter.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Rate Limiter (Token Bucket)
|
|
4
|
+
* @module @classytic/notifications/utils
|
|
5
|
+
*
|
|
6
|
+
* Per-channel rate limiting using the token bucket algorithm.
|
|
7
|
+
* Prevents exceeding provider limits (e.g., Gmail 500/day, SendGrid 100/sec).
|
|
8
|
+
*
|
|
9
|
+
* Ships with an in-memory store; implement RateLimitStore for
|
|
10
|
+
* Redis or other distributed backends.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { EmailChannel } from '@classytic/notifications/channels';
|
|
15
|
+
*
|
|
16
|
+
* const email = new EmailChannel({
|
|
17
|
+
* from: 'noreply@app.com',
|
|
18
|
+
* transport: { service: 'gmail', auth: { user, pass } },
|
|
19
|
+
* rateLimit: {
|
|
20
|
+
* maxPerWindow: 500, // max 500 emails
|
|
21
|
+
* windowMs: 86_400_000, // per day (24h)
|
|
22
|
+
* },
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
/** Rate limit configuration for a channel */
|
|
27
|
+
interface RateLimitConfig {
|
|
28
|
+
/** Maximum sends allowed within the time window */
|
|
29
|
+
maxPerWindow: number;
|
|
30
|
+
/** Time window in milliseconds (e.g., 60_000 for 1 minute) */
|
|
31
|
+
windowMs: number;
|
|
32
|
+
}
|
|
33
|
+
/** Interface for pluggable rate limit stores (Redis, DB, etc.) */
|
|
34
|
+
interface RateLimitStore {
|
|
35
|
+
/** Record a send and return whether it was allowed */
|
|
36
|
+
consume(channelName: string, config: RateLimitConfig): boolean | Promise<boolean>;
|
|
37
|
+
/** Get remaining tokens for a channel */
|
|
38
|
+
remaining(channelName: string, config: RateLimitConfig): number | Promise<number>;
|
|
39
|
+
/** Reset rate limit state for a channel */
|
|
40
|
+
reset(channelName: string): void | Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* In-memory sliding window rate limiter.
|
|
44
|
+
*
|
|
45
|
+
* Tracks timestamps of recent sends per channel and checks
|
|
46
|
+
* against the configured window. Suitable for single-process apps.
|
|
47
|
+
* For distributed systems, implement `RateLimitStore` with Redis.
|
|
48
|
+
*/
|
|
49
|
+
declare class MemoryRateLimitStore implements RateLimitStore {
|
|
50
|
+
private windows;
|
|
51
|
+
consume(channelName: string, config: RateLimitConfig): boolean;
|
|
52
|
+
remaining(channelName: string, config: RateLimitConfig): number;
|
|
53
|
+
reset(channelName: string): void;
|
|
54
|
+
/** Get only the timestamps that fall within the current window */
|
|
55
|
+
private getActive;
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
1
58
|
//#region src/utils/idempotency.d.ts
|
|
2
59
|
/**
|
|
3
60
|
* Idempotency / deduplication utilities
|
|
@@ -45,6 +102,152 @@ declare class MemoryIdempotencyStore implements IdempotencyStore {
|
|
|
45
102
|
/** Default TTL for idempotency keys (24 hours) */
|
|
46
103
|
declare const IDEMPOTENCY_DEFAULT_TTL: number;
|
|
47
104
|
//#endregion
|
|
105
|
+
//#region src/utils/delivery-log.d.ts
|
|
106
|
+
/** A single delivery log entry */
|
|
107
|
+
interface DeliveryLogEntry {
|
|
108
|
+
/** Unique log entry ID */
|
|
109
|
+
id: string;
|
|
110
|
+
/** Timestamp of the delivery attempt */
|
|
111
|
+
timestamp: Date;
|
|
112
|
+
/** Event name */
|
|
113
|
+
event: string;
|
|
114
|
+
/** Recipient ID (if available) */
|
|
115
|
+
recipientId?: string;
|
|
116
|
+
/** Recipient email (if available) */
|
|
117
|
+
recipientEmail?: string;
|
|
118
|
+
/** Channels attempted */
|
|
119
|
+
channels: string[];
|
|
120
|
+
/** Per-channel results */
|
|
121
|
+
results: SendResult[];
|
|
122
|
+
/** Overall status */
|
|
123
|
+
status: 'delivered' | 'partial' | 'failed';
|
|
124
|
+
/** Total duration in ms */
|
|
125
|
+
duration: number;
|
|
126
|
+
/** Original payload metadata */
|
|
127
|
+
metadata?: Record<string, unknown>;
|
|
128
|
+
}
|
|
129
|
+
/** Query filter for delivery log entries */
|
|
130
|
+
interface DeliveryLogQuery {
|
|
131
|
+
recipientId?: string;
|
|
132
|
+
recipientEmail?: string;
|
|
133
|
+
event?: string;
|
|
134
|
+
channel?: string;
|
|
135
|
+
status?: 'delivered' | 'partial' | 'failed';
|
|
136
|
+
/** Only entries after this date */
|
|
137
|
+
after?: Date;
|
|
138
|
+
/** Only entries before this date */
|
|
139
|
+
before?: Date;
|
|
140
|
+
/** Max entries to return (default: 100) */
|
|
141
|
+
limit?: number;
|
|
142
|
+
}
|
|
143
|
+
/** Interface for pluggable delivery log stores (MongoDB, Postgres, etc.) */
|
|
144
|
+
interface DeliveryLog {
|
|
145
|
+
/** Record a delivery attempt */
|
|
146
|
+
record(payload: NotificationPayload, dispatch: DispatchResult): void | Promise<void>;
|
|
147
|
+
/** Query delivery history */
|
|
148
|
+
query(filter: DeliveryLogQuery): DeliveryLogEntry[] | Promise<DeliveryLogEntry[]>;
|
|
149
|
+
/** Get a specific log entry by ID */
|
|
150
|
+
get(id: string): DeliveryLogEntry | null | Promise<DeliveryLogEntry | null>;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* In-memory delivery log with query support.
|
|
154
|
+
*
|
|
155
|
+
* Keeps entries in memory with optional max size (evicts oldest).
|
|
156
|
+
* For production, implement `DeliveryLog` with your database.
|
|
157
|
+
*/
|
|
158
|
+
declare class MemoryDeliveryLog implements DeliveryLog {
|
|
159
|
+
private entries;
|
|
160
|
+
private readonly maxEntries;
|
|
161
|
+
constructor(options?: {
|
|
162
|
+
maxEntries?: number;
|
|
163
|
+
});
|
|
164
|
+
record(payload: NotificationPayload, dispatch: DispatchResult): void;
|
|
165
|
+
query(filter: DeliveryLogQuery): DeliveryLogEntry[];
|
|
166
|
+
get(id: string): DeliveryLogEntry | null;
|
|
167
|
+
/** Get total number of entries */
|
|
168
|
+
get size(): number;
|
|
169
|
+
/** Clear all entries */
|
|
170
|
+
clear(): void;
|
|
171
|
+
private resolveStatus;
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region src/utils/queue.d.ts
|
|
175
|
+
/** Status of a queued job */
|
|
176
|
+
type QueueJobStatus = 'pending' | 'processing' | 'completed' | 'failed';
|
|
177
|
+
/** A queued notification job */
|
|
178
|
+
interface QueueJob {
|
|
179
|
+
id: string;
|
|
180
|
+
payload: NotificationPayload;
|
|
181
|
+
status: QueueJobStatus;
|
|
182
|
+
attempts: number;
|
|
183
|
+
maxAttempts: number;
|
|
184
|
+
createdAt: Date;
|
|
185
|
+
updatedAt: Date;
|
|
186
|
+
error?: string;
|
|
187
|
+
}
|
|
188
|
+
/** Queue adapter interface — implement for BullMQ, Redis, DB, etc. */
|
|
189
|
+
interface QueueAdapter {
|
|
190
|
+
/**
|
|
191
|
+
* Enqueue a notification for later processing.
|
|
192
|
+
* Returns a job ID for tracking.
|
|
193
|
+
*/
|
|
194
|
+
enqueue(payload: NotificationPayload, options?: QueueEnqueueOptions): string | Promise<string>;
|
|
195
|
+
/**
|
|
196
|
+
* Process queued jobs. Called by the service when queue is attached.
|
|
197
|
+
* The processor function is the service's internal send pipeline.
|
|
198
|
+
*/
|
|
199
|
+
process(processor: QueueProcessor): void | Promise<void>;
|
|
200
|
+
/** Get job by ID */
|
|
201
|
+
getJob(id: string): QueueJob | null | Promise<QueueJob | null>;
|
|
202
|
+
/** Get queue size (pending + processing) */
|
|
203
|
+
size(): number | Promise<number>;
|
|
204
|
+
/** Pause processing */
|
|
205
|
+
pause(): void | Promise<void>;
|
|
206
|
+
/** Resume processing */
|
|
207
|
+
resume(): void | Promise<void>;
|
|
208
|
+
/** Drain the queue (remove all pending jobs) */
|
|
209
|
+
drain(): void | Promise<void>;
|
|
210
|
+
}
|
|
211
|
+
/** Options for enqueuing a notification */
|
|
212
|
+
interface QueueEnqueueOptions {
|
|
213
|
+
/** Delay before processing (ms) */
|
|
214
|
+
delay?: number;
|
|
215
|
+
/** Max processing attempts (default: 3) */
|
|
216
|
+
maxAttempts?: number;
|
|
217
|
+
}
|
|
218
|
+
/** Processor function called by the queue for each job */
|
|
219
|
+
type QueueProcessor = (payload: NotificationPayload) => Promise<void>;
|
|
220
|
+
/**
|
|
221
|
+
* In-memory queue for development and testing.
|
|
222
|
+
*
|
|
223
|
+
* Jobs are processed immediately in FIFO order with concurrency control.
|
|
224
|
+
* **Not crash-resilient** — use BullMQ or a database-backed adapter for production.
|
|
225
|
+
*/
|
|
226
|
+
declare class MemoryQueue implements QueueAdapter {
|
|
227
|
+
private jobs;
|
|
228
|
+
private pending;
|
|
229
|
+
private processor;
|
|
230
|
+
private paused;
|
|
231
|
+
private readonly concurrency;
|
|
232
|
+
private activeCount;
|
|
233
|
+
private delayTimers;
|
|
234
|
+
constructor(options?: {
|
|
235
|
+
concurrency?: number;
|
|
236
|
+
});
|
|
237
|
+
enqueue(payload: NotificationPayload, options?: QueueEnqueueOptions): string;
|
|
238
|
+
process(processor: QueueProcessor): void;
|
|
239
|
+
getJob(id: string): QueueJob | null;
|
|
240
|
+
size(): number;
|
|
241
|
+
pause(): void;
|
|
242
|
+
resume(): void;
|
|
243
|
+
drain(): void;
|
|
244
|
+
/** Get all jobs (for testing/debugging) */
|
|
245
|
+
getAllJobs(): QueueJob[];
|
|
246
|
+
/** Clear all jobs and cancel all timers */
|
|
247
|
+
clear(): void;
|
|
248
|
+
private drain_queue;
|
|
249
|
+
}
|
|
250
|
+
//#endregion
|
|
48
251
|
//#region src/types.d.ts
|
|
49
252
|
/**
|
|
50
253
|
* @classytic/notifications - Type Definitions
|
|
@@ -78,6 +281,8 @@ interface NotificationPayload {
|
|
|
78
281
|
metadata?: Record<string, unknown>;
|
|
79
282
|
/** Idempotency key — duplicate sends with the same key are skipped */
|
|
80
283
|
idempotencyKey?: string;
|
|
284
|
+
/** Delay delivery by this many milliseconds (requires queue adapter) */
|
|
285
|
+
delay?: number;
|
|
81
286
|
}
|
|
82
287
|
/** Result from a single channel send */
|
|
83
288
|
interface SendResult {
|
|
@@ -95,6 +300,8 @@ interface DispatchResult {
|
|
|
95
300
|
failed: number;
|
|
96
301
|
skipped: number;
|
|
97
302
|
duration: number;
|
|
303
|
+
/** True when the notification was enqueued (not yet processed) */
|
|
304
|
+
queued?: boolean;
|
|
98
305
|
}
|
|
99
306
|
/** Base channel configuration */
|
|
100
307
|
interface ChannelConfig {
|
|
@@ -106,6 +313,8 @@ interface ChannelConfig {
|
|
|
106
313
|
events?: string[];
|
|
107
314
|
/** Per-channel retry override */
|
|
108
315
|
retry?: RetryConfig;
|
|
316
|
+
/** Per-channel rate limiting (e.g., Gmail 500/day) */
|
|
317
|
+
rateLimit?: RateLimitConfig;
|
|
109
318
|
}
|
|
110
319
|
/** Channel interface - implement this for custom channels */
|
|
111
320
|
interface Channel {
|
|
@@ -166,6 +375,40 @@ interface WebhookChannelConfig extends ChannelConfig {
|
|
|
166
375
|
/** Request timeout in ms (default: 10000) */
|
|
167
376
|
timeout?: number;
|
|
168
377
|
}
|
|
378
|
+
/** SMS provider interface (Twilio or custom) */
|
|
379
|
+
interface SmsProvider {
|
|
380
|
+
send(message: {
|
|
381
|
+
to: string;
|
|
382
|
+
from: string;
|
|
383
|
+
body: string;
|
|
384
|
+
}): Promise<{
|
|
385
|
+
sid: string;
|
|
386
|
+
}>;
|
|
387
|
+
}
|
|
388
|
+
/** SmsChannel configuration — bring your own SMS SDK */
|
|
389
|
+
interface SmsChannelConfig extends ChannelConfig {
|
|
390
|
+
/** Sender phone number or sender ID (E.164 format: +15551234567) */
|
|
391
|
+
from: string;
|
|
392
|
+
/** SMS provider implementation (Twilio, SNS, Vonage, etc.) */
|
|
393
|
+
provider: SmsProvider;
|
|
394
|
+
}
|
|
395
|
+
/** Push notification provider interface (FCM or custom) */
|
|
396
|
+
interface PushProvider {
|
|
397
|
+
send(message: {
|
|
398
|
+
token: string;
|
|
399
|
+
title: string;
|
|
400
|
+
body: string;
|
|
401
|
+
data?: Record<string, string>;
|
|
402
|
+
imageUrl?: string;
|
|
403
|
+
}): Promise<{
|
|
404
|
+
messageId: string;
|
|
405
|
+
}>;
|
|
406
|
+
}
|
|
407
|
+
/** PushChannel configuration — bring your own push SDK */
|
|
408
|
+
interface PushChannelConfig extends ChannelConfig {
|
|
409
|
+
/** Push provider implementation (FCM, Expo, OneSignal, APNs, etc.) */
|
|
410
|
+
provider: PushProvider;
|
|
411
|
+
}
|
|
169
412
|
/** Resolved template content */
|
|
170
413
|
interface TemplateResult {
|
|
171
414
|
subject?: string;
|
|
@@ -238,9 +481,15 @@ interface NotificationServiceConfig {
|
|
|
238
481
|
/** Store implementation (default: MemoryIdempotencyStore) */store?: IdempotencyStore; /** TTL in milliseconds (default: 86400000 = 24h) */
|
|
239
482
|
ttl?: number;
|
|
240
483
|
};
|
|
484
|
+
/** Delivery log for audit trail — records every send attempt */
|
|
485
|
+
deliveryLog?: DeliveryLog;
|
|
486
|
+
/** Rate limit store (default: MemoryRateLimitStore when channels use rateLimit) */
|
|
487
|
+
rateLimitStore?: RateLimitStore;
|
|
488
|
+
/** Queue adapter for crash-resilient delivery. Service owns the queue. */
|
|
489
|
+
queue?: QueueAdapter;
|
|
241
490
|
}
|
|
242
491
|
/** Service lifecycle events */
|
|
243
|
-
type ServiceEvent = 'before:send' | 'after:send' | 'send:success' | 'send:failed' | 'send:retry';
|
|
492
|
+
type ServiceEvent = 'before:send' | 'after:send' | 'send:success' | 'send:failed' | 'send:retry' | 'send:rate_limited' | 'send:queued';
|
|
244
493
|
/** Event handler function */
|
|
245
494
|
type EventHandler<T = unknown> = (data: T) => void | Promise<void>;
|
|
246
495
|
/** Hook config for creating event-specific handlers */
|
|
@@ -294,4 +543,4 @@ interface BatchResult {
|
|
|
294
543
|
results: DispatchResult[];
|
|
295
544
|
}
|
|
296
545
|
//#endregion
|
|
297
|
-
export {
|
|
546
|
+
export { TemplateResult as A, DeliveryLogQuery as B, RetryConfig as C, SmsProvider as D, SmsChannelConfig as E, QueueJob as F, MemoryRateLimitStore as G, IDEMPOTENCY_DEFAULT_TTL as H, QueueJobStatus as I, RateLimitConfig as K, QueueProcessor as L, MemoryQueue as M, QueueAdapter as N, SmtpTransportOptions as O, QueueEnqueueOptions as P, DeliveryLog as R, ResolvedRetryConfig as S, ServiceEvent as T, IdempotencyStore as U, MemoryDeliveryLog as V, MemoryIdempotencyStore as W, NotificationServiceConfig as _, ChannelConfig as a, PushProvider as b, EmailChannelConfig as c, HookMap as d, Logger as f, NotificationPreferences as g, NotificationPayload as h, Channel as i, WebhookChannelConfig as j, TemplateResolver as k, EventHandler as l, NotificationHookConfig as m, BatchProgress as n, DispatchResult as o, NodemailerTransporter as p, RateLimitStore as q, BatchResult as r, EmailAttachment as s, BatchOptions as t, HookHandler as u, PreferenceResolver as v, SendResult as w, Recipient as x, PushChannelConfig as y, DeliveryLogEntry as z };
|
package/dist/utils/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as
|
|
3
|
-
export { ChannelError, Emitter, IDEMPOTENCY_DEFAULT_TTL, type IdempotencyStore, MemoryIdempotencyStore, NotificationError, type PMapOptions, ProviderNotInstalledError, type QuietHoursConfig, calculateDelay, isQuietHours, mergeHooks, pMap, resolveRetryConfig, withRetry };
|
|
1
|
+
import { B as DeliveryLogQuery, F as QueueJob, G as MemoryRateLimitStore, H as IDEMPOTENCY_DEFAULT_TTL, I as QueueJobStatus, K as RateLimitConfig, L as QueueProcessor, M as MemoryQueue, N as QueueAdapter, P as QueueEnqueueOptions, R as DeliveryLog, U as IdempotencyStore, V as MemoryDeliveryLog, W as MemoryIdempotencyStore, q as RateLimitStore, z as DeliveryLogEntry } from "../types-D94B3VNX.mjs";
|
|
2
|
+
import { S as mergeHooks, _ as ProviderNotInstalledError, a as createStatusHandler, b as resolveRetryConfig, c as TemplateDefinition, d as PMapOptions, f as pMap, g as NotificationError, h as ChannelError, i as StatusUpdate, l as TemplateMap, m as isQuietHours, n as StatusHandler, o as FallbackOptions, p as QuietHoursConfig, r as StatusHandlerConfig, s as withFallback, t as DeliveryStatus, u as createSimpleResolver, v as Emitter, x as withRetry, y as calculateDelay } from "../status-webhook-BDaI1BMy.mjs";
|
|
3
|
+
export { ChannelError, type DeliveryLog, type DeliveryLogEntry, type DeliveryLogQuery, type DeliveryStatus, Emitter, type FallbackOptions, IDEMPOTENCY_DEFAULT_TTL, type IdempotencyStore, MemoryDeliveryLog, MemoryIdempotencyStore, MemoryQueue, MemoryRateLimitStore, NotificationError, type PMapOptions, ProviderNotInstalledError, type QueueAdapter, type QueueEnqueueOptions, type QueueJob, type QueueJobStatus, type QueueProcessor, type QuietHoursConfig, type RateLimitConfig, type RateLimitStore, type StatusHandler, type StatusHandlerConfig, type StatusUpdate, type TemplateDefinition, type TemplateMap, calculateDelay, createSimpleResolver, createStatusHandler, isQuietHours, mergeHooks, pMap, resolveRetryConfig, withFallback, withRetry };
|
package/dist/utils/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { n as NotificationError, r as ProviderNotInstalledError, t as ChannelError } from "../errors-
|
|
1
|
+
import { a as MemoryDeliveryLog, c as MemoryRateLimitStore, d as isQuietHours, f as calculateDelay, h as Emitter, i as MemoryQueue, l as IDEMPOTENCY_DEFAULT_TTL, m as withRetry, n as withFallback, o as mergeHooks, p as resolveRetryConfig, r as createSimpleResolver, s as pMap, t as createStatusHandler, u as MemoryIdempotencyStore } from "../status-webhook-XY42DCj_.mjs";
|
|
2
|
+
import { n as NotificationError, r as ProviderNotInstalledError, t as ChannelError } from "../errors-FYJYmfvj.mjs";
|
|
3
3
|
|
|
4
|
-
export { ChannelError, Emitter, IDEMPOTENCY_DEFAULT_TTL, MemoryIdempotencyStore, NotificationError, ProviderNotInstalledError, calculateDelay, isQuietHours, mergeHooks, pMap, resolveRetryConfig, withRetry };
|
|
4
|
+
export { ChannelError, Emitter, IDEMPOTENCY_DEFAULT_TTL, MemoryDeliveryLog, MemoryIdempotencyStore, MemoryQueue, MemoryRateLimitStore, NotificationError, ProviderNotInstalledError, calculateDelay, createSimpleResolver, createStatusHandler, isQuietHours, mergeHooks, pMap, resolveRetryConfig, withFallback, withRetry };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@classytic/notifications",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Multi-channel
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Multi-channel notifications (Email, SMS, Push, Webhook) with rate limiting, delivery tracking, queue adapters, channel fallback, templates, retry — zero required dependencies",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/index.mjs",
|
|
@@ -32,20 +32,20 @@
|
|
|
32
32
|
"multi-channel",
|
|
33
33
|
"email",
|
|
34
34
|
"sms",
|
|
35
|
-
"push",
|
|
35
|
+
"push-notifications",
|
|
36
36
|
"webhook",
|
|
37
37
|
"nodemailer",
|
|
38
38
|
"smtp",
|
|
39
39
|
"ses",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
40
|
+
"rate-limiting",
|
|
41
|
+
"delivery-tracking",
|
|
42
|
+
"queue",
|
|
43
|
+
"channel-fallback",
|
|
42
44
|
"templates",
|
|
43
45
|
"retry",
|
|
46
|
+
"idempotency",
|
|
44
47
|
"pluggable",
|
|
45
48
|
"framework-agnostic",
|
|
46
|
-
"express",
|
|
47
|
-
"fastify",
|
|
48
|
-
"nestjs",
|
|
49
49
|
"typescript",
|
|
50
50
|
"zero-dependencies"
|
|
51
51
|
],
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
},
|
|
64
64
|
"homepage": "https://github.com/classytic/notifications#readme",
|
|
65
65
|
"peerDependencies": {
|
|
66
|
-
"nodemailer": "
|
|
66
|
+
"nodemailer": ">=6"
|
|
67
67
|
},
|
|
68
68
|
"peerDependenciesMeta": {
|
|
69
69
|
"nodemailer": {
|
|
@@ -93,8 +93,8 @@
|
|
|
93
93
|
"@types/nodemailer": "^6.4.17",
|
|
94
94
|
"@vitest/coverage-v8": "3.2.4",
|
|
95
95
|
"nodemailer": "^6.10.1",
|
|
96
|
-
"tsdown": "0.
|
|
96
|
+
"tsdown": "0.21.4",
|
|
97
97
|
"typescript": "^5.7.0",
|
|
98
98
|
"vitest": "^3.0.0"
|
|
99
99
|
}
|
|
100
|
-
}
|
|
100
|
+
}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { b as ResolvedRetryConfig, d as HookMap, u as HookHandler, x as RetryConfig } from "./types-BnjZ7x2U.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/utils/merge-hooks.d.ts
|
|
4
|
-
type HookInput = Record<string, HookHandler | HookHandler[]>;
|
|
5
|
-
declare function mergeHooks(...hookConfigs: (HookInput | null | undefined)[]): HookMap;
|
|
6
|
-
//#endregion
|
|
7
|
-
//#region src/utils/retry.d.ts
|
|
8
|
-
/** Resolve retry config with defaults */
|
|
9
|
-
declare function resolveRetryConfig(config?: RetryConfig): ResolvedRetryConfig;
|
|
10
|
-
/** Calculate delay for a given attempt */
|
|
11
|
-
declare function calculateDelay(attempt: number, config: ResolvedRetryConfig): number;
|
|
12
|
-
/**
|
|
13
|
-
* Execute a function with retry and backoff
|
|
14
|
-
*
|
|
15
|
-
* @param fn - Async function to retry
|
|
16
|
-
* @param config - Retry configuration
|
|
17
|
-
* @param onRetry - Called before each retry attempt
|
|
18
|
-
* @returns Result of fn
|
|
19
|
-
* @throws Last error after all attempts exhausted
|
|
20
|
-
*/
|
|
21
|
-
declare function withRetry<T>(fn: () => Promise<T>, config: ResolvedRetryConfig, onRetry?: (attempt: number, error: Error) => void): Promise<T>;
|
|
22
|
-
//#endregion
|
|
23
|
-
//#region src/utils/emitter.d.ts
|
|
24
|
-
/**
|
|
25
|
-
* Lightweight typed event emitter
|
|
26
|
-
* @module @classytic/notifications
|
|
27
|
-
*
|
|
28
|
-
* Zero-dependency alternative to Node's EventEmitter.
|
|
29
|
-
* Keeps the library portable across runtimes.
|
|
30
|
-
*/
|
|
31
|
-
type Handler = (...args: unknown[]) => void | Promise<void>;
|
|
32
|
-
declare class Emitter {
|
|
33
|
-
private handlers;
|
|
34
|
-
/** Register an event handler */
|
|
35
|
-
on(event: string, handler: Handler): this;
|
|
36
|
-
/** Remove an event handler */
|
|
37
|
-
off(event: string, handler: Handler): this;
|
|
38
|
-
/** Emit an event (runs handlers sequentially, awaits async) */
|
|
39
|
-
emit(event: string, ...args: unknown[]): Promise<void>;
|
|
40
|
-
/** Remove all handlers for an event (or all events) */
|
|
41
|
-
removeAll(event?: string): this;
|
|
42
|
-
}
|
|
43
|
-
//#endregion
|
|
44
|
-
//#region src/utils/errors.d.ts
|
|
45
|
-
/**
|
|
46
|
-
* Notification Errors
|
|
47
|
-
* @module @classytic/notifications
|
|
48
|
-
*/
|
|
49
|
-
declare class NotificationError extends Error {
|
|
50
|
-
readonly code: string;
|
|
51
|
-
readonly channel?: string;
|
|
52
|
-
readonly cause?: Error;
|
|
53
|
-
constructor(message: string, options?: {
|
|
54
|
-
code?: string;
|
|
55
|
-
channel?: string;
|
|
56
|
-
cause?: Error;
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
declare class ChannelError extends NotificationError {
|
|
60
|
-
constructor(channel: string, message: string, cause?: Error);
|
|
61
|
-
}
|
|
62
|
-
declare class ProviderNotInstalledError extends NotificationError {
|
|
63
|
-
constructor(provider: string, installCmd: string);
|
|
64
|
-
}
|
|
65
|
-
//#endregion
|
|
66
|
-
//#region src/utils/quiet-hours.d.ts
|
|
67
|
-
/**
|
|
68
|
-
* Quiet hours utility
|
|
69
|
-
* @module @classytic/notifications/utils
|
|
70
|
-
*
|
|
71
|
-
* Checks if the current time falls within a user's quiet hours window.
|
|
72
|
-
* Uses Intl.DateTimeFormat for timezone conversion (zero dependencies, Node 18+).
|
|
73
|
-
*/
|
|
74
|
-
/** Quiet hours configuration */
|
|
75
|
-
interface QuietHoursConfig {
|
|
76
|
-
/** Start time in HH:MM format (e.g. "22:00") */
|
|
77
|
-
start?: string;
|
|
78
|
-
/** End time in HH:MM format (e.g. "07:00") */
|
|
79
|
-
end?: string;
|
|
80
|
-
/** IANA timezone (e.g. "America/New_York"). Defaults to UTC */
|
|
81
|
-
timezone?: string;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Check if the current time falls within quiet hours.
|
|
85
|
-
*
|
|
86
|
-
* Supports overnight ranges (e.g. 22:00 - 07:00).
|
|
87
|
-
* Returns false if start/end are missing or malformed.
|
|
88
|
-
*
|
|
89
|
-
* @param quiet - Quiet hours config with start, end, and optional timezone
|
|
90
|
-
* @param now - Current date (defaults to new Date(), injectable for testing)
|
|
91
|
-
*/
|
|
92
|
-
declare function isQuietHours(quiet: QuietHoursConfig, now?: Date): boolean;
|
|
93
|
-
//#endregion
|
|
94
|
-
//#region src/utils/concurrency.d.ts
|
|
95
|
-
/**
|
|
96
|
-
* Concurrency pool utility
|
|
97
|
-
* @module @classytic/notifications/utils
|
|
98
|
-
*
|
|
99
|
-
* Process items in parallel with controlled concurrency.
|
|
100
|
-
* Zero dependencies — uses a worker-pool pattern where N workers
|
|
101
|
-
* pull from a shared queue, keeping the pipeline full at all times.
|
|
102
|
-
*
|
|
103
|
-
* Unlike chunk-based approaches (process N, wait, process N, wait),
|
|
104
|
-
* the pool starts the next item as soon as any worker finishes,
|
|
105
|
-
* eliminating idle time from slow outliers.
|
|
106
|
-
*
|
|
107
|
-
* @example
|
|
108
|
-
* ```typescript
|
|
109
|
-
* import { pMap } from '@classytic/notifications/utils';
|
|
110
|
-
*
|
|
111
|
-
* const results = await pMap(
|
|
112
|
-
* urls,
|
|
113
|
-
* async (url) => fetch(url).then(r => r.json()),
|
|
114
|
-
* { concurrency: 5 },
|
|
115
|
-
* );
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
/** Options for pMap */
|
|
119
|
-
interface PMapOptions {
|
|
120
|
-
/** Max parallel operations (default: 10) */
|
|
121
|
-
concurrency?: number;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Map over items with controlled concurrency.
|
|
125
|
-
*
|
|
126
|
-
* Like `Promise.all(items.map(fn))` but with a max number of
|
|
127
|
-
* parallel operations. Results are returned in input order.
|
|
128
|
-
*
|
|
129
|
-
* Uses a worker-pool pattern: N workers pull from a shared index,
|
|
130
|
-
* so the pipeline stays full even when some items are slower.
|
|
131
|
-
*
|
|
132
|
-
* @param items - Array of items to process
|
|
133
|
-
* @param fn - Async function to apply to each item
|
|
134
|
-
* @param options - Concurrency options
|
|
135
|
-
* @returns Array of results in the same order as input
|
|
136
|
-
*/
|
|
137
|
-
declare function pMap<T, R>(items: T[], fn: (item: T, index: number) => Promise<R>, options?: PMapOptions): Promise<R[]>;
|
|
138
|
-
//#endregion
|
|
139
|
-
export { ChannelError as a, Emitter as c, withRetry as d, mergeHooks as f, isQuietHours as i, calculateDelay as l, pMap as n, NotificationError as o, QuietHoursConfig as r, ProviderNotInstalledError as s, PMapOptions as t, resolveRetryConfig as u };
|