@classytic/notifications 2.3.0 → 2.5.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 CHANGED
@@ -2,6 +2,83 @@
2
2
 
3
3
  All notable changes to `@classytic/notifications` will be documented in this file.
4
4
 
5
+ ## [2.5.0] — 2026-08-26
6
+
7
+ ### Fixed — send-failure log now walks the `cause` chain
8
+
9
+ A real incident — `"Unsupported state or unable to authenticate data"` logged six
10
+ times per order with no frame, no layer — took an afternoon to trace because the
11
+ delivery log and the logger both recorded only `err.message`. Several components in
12
+ the path decrypt something, so the message fit all of them equally.
13
+
14
+ The fix splits the two concerns:
15
+
16
+ - **`result.error`** (persisted, operator-facing) — still the bare message. A stack
17
+ in an audit record is noise; raw vendor text in a persisted field violates the
18
+ house rule on normalised stored errors.
19
+ - **`logger.error`** — now walks the `cause` chain (up to depth 4) and appends the
20
+ first four stack frames of each `Error` node. An adapter that wraps a provider
21
+ error puts the real origin in `cause`; printing only the outer message hid the
22
+ layer you actually needed.
23
+
24
+ The split is covered by `tests/send-failure-diagnostics.test.ts`.
25
+
26
+ ## [2.4.0] - 2026-08-17
27
+
28
+ ### Fixed — `providerMessageId` now works the way 2.3.0 claimed
29
+
30
+ 2.3.0 introduced `SendResult.providerMessageId` as the cross-channel correlation
31
+ key but populated it on **email only**, so the property it exists to provide did not
32
+ hold: a consumer reading `providerMessageId` got a value for email and `undefined`
33
+ for push and sms, and still had to know which channel produced the result before it
34
+ could find the id in the untyped `metadata` bag. A half-migrated contract is worse
35
+ than none — it reads as available and silently isn't.
36
+
37
+ - **`PushChannel` sets `providerMessageId`** (from the provider's `messageId`).
38
+ - **`SmsChannel` sets `providerMessageId`** (from the provider's `sid`). This is the
39
+ case that motivates the field: three vendors, three spellings (`messageId`, `id`,
40
+ `sid`), one concept.
41
+ - `WebhookChannel` and `ConsoleChannel` deliberately leave it **unset** — a 2xx from
42
+ an HTTP POST is not a message identifier, and synthesising one would make an
43
+ unjoinable send look joinable. Absent means "no correlation is possible", never
44
+ "delivery unknown".
45
+
46
+ ### Fixed — restores `metadata.messageId` on `EmailChannel`
47
+
48
+ 2.3.0 deleted it in the same MINOR that added `providerMessageId`, so anyone reading
49
+ `metadata.messageId` lost it on a range-satisfying `^2.2.0` upgrade with nothing to
50
+ signal the change. The removal was right in direction and wrong in timing. It is
51
+ back for a deprecation window.
52
+
53
+ **All three id-bearing channels now mirror their provider id under both names** —
54
+ `providerMessageId` (read this) and the legacy `metadata` key (`messageId` for
55
+ email/push, `sid` for sms). **3.0.0 removes the legacy keys from every channel at
56
+ once**, as one deliberate break rather than three accidental ones.
57
+
58
+ Pinned by `tests/channels.test.ts` → `providerMessageId across channels`, including
59
+ a case that asserts a consumer can read the id **without branching on channel** —
60
+ the actual contract, so a channel regressing to metadata-only fails there.
61
+
62
+ ## [2.3.0] - 2026-08-16
63
+
64
+ Recorded retroactively; this release shipped without a changelog entry.
65
+
66
+ ### Added
67
+
68
+ - **`SendResult.providerMessageId`** — the typed cross-channel correlation key, so a
69
+ delivery receipt (SES bounce, SMS DLR, push feedback) can be joined back to the
70
+ send that produced it.
71
+ - **`SendResult.subject`** + `NotificationSubject` (`{ sourceModel, sourceId }`) —
72
+ the business document a notification concerns, so "show me every message we sent
73
+ about invoice X" stops being a scan over an unindexed `metadata` blob.
74
+
75
+ ### Changed — BREAKING, shipped as a minor
76
+
77
+ - `EmailChannel` stopped emitting `metadata.messageId`. Readers of that key broke on
78
+ upgrade with no signal. **Restored in 2.4.0**; upgrade straight to 2.4.0.
79
+ - Only `EmailChannel` populated `providerMessageId`; push and sms did not. **Fixed
80
+ in 2.4.0.**
81
+
5
82
  ## [2.2.0] - 2026-06-03
6
83
 
7
84
  - `SendResult.retryable?: boolean` — when `false`, service short-circuits `withRetry` immediately (permanent failures: bad credentials, invalid address, hard bounce, 4xx)
@@ -1,2 +1,2 @@
1
- import { a as EmailChannel, i as WebhookChannel, n as SmsChannel, o as BaseChannel, r as ConsoleChannel, t as PushChannel } from "../push.channel-CfPaV8z5.mjs";
1
+ import { a as EmailChannel, i as WebhookChannel, n as SmsChannel, o as BaseChannel, r as ConsoleChannel, t as PushChannel } from "../push.channel-1tNMyaXl.mjs";
2
2
  export { BaseChannel, ConsoleChannel, EmailChannel, PushChannel, SmsChannel, WebhookChannel };
@@ -1,3 +1,3 @@
1
- import { a as EmailChannel, i as WebhookChannel, n as SmsChannel, o as BaseChannel, r as ConsoleChannel, t as PushChannel } from "../push.channel-BhktEp30.mjs";
1
+ import { a as EmailChannel, i as WebhookChannel, n as SmsChannel, o as BaseChannel, r as ConsoleChannel, t as PushChannel } from "../push.channel-BkgxUc82.mjs";
2
2
 
3
3
  export { BaseChannel, ConsoleChannel, EmailChannel, PushChannel, SmsChannel, WebhookChannel };
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { A as TemplateResult, B as DeliveryLogQuery, C as RetryConfig, D as SmsProvider, E as SmsChannelConfig, 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, O as SmtpTransportOptions, P as QueueEnqueueOptions, R as DeliveryLog, S as ResolvedRetryConfig, T as ServiceEvent, U as IdempotencyStore, V as MemoryDeliveryLog, W as MemoryIdempotencyStore, _ as NotificationServiceConfig, a as ChannelConfig, b as PushProvider, c as EmailChannelConfig, d as HookMap, f as Logger, g as NotificationPreferences, h as NotificationPayload, i as Channel, j as WebhookChannelConfig, k as TemplateResolver, l as EventHandler, m as NotificationHookConfig, n as BatchProgress, o as DispatchResult, p as NodemailerTransporter, q as RateLimitStore, r as BatchResult, s as EmailAttachment, t as BatchOptions, u as HookHandler, v as PreferenceResolver, w as SendResult, x as Recipient, y as PushChannelConfig, z as DeliveryLogEntry } from "./types-B5InMRIc.mjs";
2
- import { a as EmailChannel, i as WebhookChannel, n as SmsChannel, o as BaseChannel, r as ConsoleChannel, t as PushChannel } from "./push.channel-CfPaV8z5.mjs";
3
- import { C as resolveRetryConfig, S as calculateDelay, T as mergeHooks, _ as isQuietHours, a as createStatusHandler, b as ProviderNotInstalledError, c as InterpolateOptions, d as TemplateMap, f as createSimpleResolver, g as QuietHoursConfig, h as pMap, i as StatusUpdate, l as SimpleResolverOptions, m as PMapOptions, n as StatusHandler, o as FallbackOptions, p as interpolateHtml, r as StatusHandlerConfig, s as withFallback, t as DeliveryStatus, u as TemplateDefinition, v as ChannelError, w as withRetry, x as Emitter, y as NotificationError } from "./status-webhook-NDUgykHA.mjs";
1
+ import { A as TemplateResult, B as DeliveryLogQuery, C as RetryConfig, D as SmsProvider, E as SmsChannelConfig, 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, O as SmtpTransportOptions, P as QueueEnqueueOptions, R as DeliveryLog, S as ResolvedRetryConfig, T as ServiceEvent, U as IdempotencyStore, V as MemoryDeliveryLog, W as MemoryIdempotencyStore, _ as NotificationServiceConfig, a as ChannelConfig, b as PushProvider, c as EmailChannelConfig, d as HookMap, f as Logger, g as NotificationPreferences, h as NotificationPayload, i as Channel, j as WebhookChannelConfig, k as TemplateResolver, l as EventHandler, m as NotificationHookConfig, n as BatchProgress, o as DispatchResult, p as NodemailerTransporter, q as RateLimitStore, r as BatchResult, s as EmailAttachment, t as BatchOptions, u as HookHandler, v as PreferenceResolver, w as SendResult, x as Recipient, y as PushChannelConfig, z as DeliveryLogEntry } from "./types-DkFudalo.mjs";
2
+ import { a as EmailChannel, i as WebhookChannel, n as SmsChannel, o as BaseChannel, r as ConsoleChannel, t as PushChannel } from "./push.channel-1tNMyaXl.mjs";
3
+ import { C as resolveRetryConfig, S as calculateDelay, T as mergeHooks, _ as isQuietHours, a as createStatusHandler, b as ProviderNotInstalledError, c as InterpolateOptions, d as TemplateMap, f as createSimpleResolver, g as QuietHoursConfig, h as pMap, i as StatusUpdate, l as SimpleResolverOptions, m as PMapOptions, n as StatusHandler, o as FallbackOptions, p as interpolateHtml, r as StatusHandlerConfig, s as withFallback, t as DeliveryStatus, u as TemplateDefinition, v as ChannelError, w as withRetry, x as Emitter, y as NotificationError } from "./status-webhook-CuCdFeVN.mjs";
4
4
  //#region src/NotificationService.d.ts
5
5
  declare class NotificationService {
6
6
  private channels;
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { a as MemoryQueue, c as pMap, d as MemoryIdempotencyStore, f as isQuietHours, g as Emitter, h as withRetry, i as interpolateHtml, l as MemoryRateLimitStore, m as resolveRetryConfig, n as withFallback, o as MemoryDeliveryLog, p as calculateDelay, r as createSimpleResolver, s as mergeHooks, t as createStatusHandler, u as IDEMPOTENCY_DEFAULT_TTL } from "./status-webhook-B4Sv8X_G.mjs";
2
2
  import { n as NotificationError, r as ProviderNotInstalledError, t as ChannelError } from "./errors-BxRjct-E.mjs";
3
- import { a as EmailChannel, i as WebhookChannel, n as SmsChannel, o as BaseChannel, r as ConsoleChannel, t as PushChannel } from "./push.channel-BhktEp30.mjs";
3
+ import { a as EmailChannel, i as WebhookChannel, n as SmsChannel, o as BaseChannel, r as ConsoleChannel, t as PushChannel } from "./push.channel-BkgxUc82.mjs";
4
4
 
5
5
  //#region src/NotificationService.ts
6
6
  /**
@@ -324,7 +324,31 @@ var NotificationService = class {
324
324
  duration: Date.now() - start
325
325
  };
326
326
  const message = err instanceof Error ? err.message : String(err);
327
- this.logger.error(`[${channel.name}] Failed: ${message}`);
327
+ /**
328
+ * Log the ORIGIN, persist only the message.
329
+ *
330
+ * The returned `error` string is what ends up in the delivery log, which
331
+ * is an operator-facing audit record — a raw stack there would be noise
332
+ * at best and leak vendor internals at worst. But a bare message is not
333
+ * diagnosable either: `"Unsupported state or unable to authenticate
334
+ * data"` (Node's AES-GCM failure) took an afternoon to trace precisely
335
+ * because the delivery row recorded that string and nothing else — no
336
+ * frame, no cause, no indication of which of several decrypting layers
337
+ * produced it, and the message never reached a log at all beyond this
338
+ * one line.
339
+ *
340
+ * So the split follows the house rule: normalise what is stored, and log
341
+ * the detail separately. `cause` is walked because an adapter that wraps
342
+ * a provider error puts the real origin there, and printing only the
343
+ * outer message hides exactly the layer you need.
344
+ */
345
+ const detail = [];
346
+ let cursor = err;
347
+ for (let depth = 0; cursor instanceof Error && depth < 4; depth++) {
348
+ detail.push(`${depth === 0 ? "error" : `cause[${depth}]`}: ${cursor.name}: ${cursor.message}` + (cursor.stack ? `\n${cursor.stack.split("\n").slice(1, 5).join("\n")}` : ""));
349
+ cursor = cursor.cause;
350
+ }
351
+ this.logger.error(`[${channel.name}] Failed: ${message}\n${detail.join("\n")}`);
328
352
  return {
329
353
  status: "failed",
330
354
  channel: channel.name,
@@ -1,4 +1,4 @@
1
- import { C as RetryConfig, E as SmsChannelConfig, K as RateLimitConfig, a as ChannelConfig, c as EmailChannelConfig, h as NotificationPayload, i as Channel, j as WebhookChannelConfig, w as SendResult, y as PushChannelConfig } from "./types-B5InMRIc.mjs";
1
+ import { C as RetryConfig, E as SmsChannelConfig, K as RateLimitConfig, a as ChannelConfig, c as EmailChannelConfig, h as NotificationPayload, i as Channel, j as WebhookChannelConfig, w as SendResult, y as PushChannelConfig } from "./types-DkFudalo.mjs";
2
2
  //#region src/channels/BaseChannel.d.ts
3
3
  declare abstract class BaseChannel<TConfig extends ChannelConfig = ChannelConfig> implements Channel {
4
4
  readonly name: string;
@@ -175,7 +175,18 @@ var EmailChannel = class EmailChannel extends BaseChannel {
175
175
  * and a consumer has to know which channel produced the result before it can
176
176
  * find the id — which is why `SendResult.providerMessageId` exists.
177
177
  */
178
- providerMessageId: result.messageId
178
+ providerMessageId: result.messageId,
179
+ /**
180
+ * RESTORED in 2.4.0. 2.3.0 introduced `providerMessageId` and deleted this
181
+ * in the same MINOR, so a consumer reading `metadata.messageId` lost it on
182
+ * a range-satisfying upgrade with nothing to tell them — the removal was
183
+ * correct in direction and wrong in timing. It is back for the deprecation
184
+ * window, so all three id-bearing channels behave identically, and 3.0.0
185
+ * removes it from every channel at once as one deliberate break.
186
+ *
187
+ * @deprecated read `providerMessageId`; removed in 3.0.0
188
+ */
189
+ metadata: { messageId: result.messageId }
179
190
  };
180
191
  } catch (err) {
181
192
  const message = err instanceof Error ? err.message : String(err);
@@ -413,6 +424,23 @@ var SmsChannel = class extends BaseChannel {
413
424
  return {
414
425
  status: "sent",
415
426
  channel: this.name,
427
+ /**
428
+ * The TYPED correlation key. SMS is the case that makes the argument:
429
+ * the provider calls it `sid`, email calls it `messageId`, push calls
430
+ * it `messageId` — three spellings for one concept, so a delivery
431
+ * receipt (a DLR) could only be joined back to its send by code that
432
+ * already knew which channel had produced the result. That is the
433
+ * exact coupling `SendResult.providerMessageId` removes.
434
+ */
435
+ providerMessageId: result.sid,
436
+ /**
437
+ * Kept for one release alongside the typed field. Dropping it here
438
+ * would be a silent removal in a MINOR — exactly what 2.3.0 did to
439
+ * email's `metadata.messageId`, breaking readers with no signal.
440
+ * Removed in 3.0.0, from every channel at once.
441
+ *
442
+ * @deprecated read `providerMessageId`; removed in 3.0.0
443
+ */
416
444
  metadata: { sid: result.sid }
417
445
  };
418
446
  } catch (err) {
@@ -537,6 +565,22 @@ var PushChannel = class extends BaseChannel {
537
565
  return {
538
566
  status: "sent",
539
567
  channel: this.name,
568
+ /**
569
+ * The TYPED correlation key — same contract email publishes. A push
570
+ * receipt (FCM/APNs feedback, an Expo receipt lookup) arrives naming
571
+ * this id, and until it was here a consumer had to know the result
572
+ * came from THIS channel before it could find it under the untyped
573
+ * key `metadata.messageId`.
574
+ */
575
+ providerMessageId: result.messageId,
576
+ /**
577
+ * Kept for one release alongside the typed field. Dropping it here
578
+ * would be a silent removal in a MINOR — exactly what 2.3.0 did to
579
+ * email's `metadata.messageId`, breaking readers with no signal.
580
+ * Removed in 3.0.0, from every channel at once.
581
+ *
582
+ * @deprecated read `providerMessageId`; removed in 3.0.0
583
+ */
540
584
  metadata: { messageId: result.messageId }
541
585
  };
542
586
  } catch (err) {
@@ -1,4 +1,4 @@
1
- import { C as RetryConfig, S as ResolvedRetryConfig, d as HookMap, h as NotificationPayload, k as TemplateResolver, o as DispatchResult, u as HookHandler } from "./types-B5InMRIc.mjs";
1
+ import { C as RetryConfig, S as ResolvedRetryConfig, d as HookMap, h as NotificationPayload, k as TemplateResolver, o as DispatchResult, u as HookHandler } from "./types-DkFudalo.mjs";
2
2
  //#region src/utils/merge-hooks.d.ts
3
3
  type HookInput = Record<string, HookHandler | HookHandler[]>;
4
4
  declare function mergeHooks(...hookConfigs: (HookInput | null | undefined)[]): HookMap;
@@ -418,8 +418,21 @@ interface SendResult {
418
418
  * Optional because it is genuinely absent for synchronous channels (in-app feed) and
419
419
  * for providers that acknowledge without issuing an id. Absent means "no correlation
420
420
  * is possible", NOT "delivery unknown" — a consumer must not infer failure from it.
421
+ *
422
+ * Populated by every channel whose provider issues one: `email` (`messageId`),
423
+ * `push` (`messageId`), `sms` (`sid`). `webhook` and `console` leave it unset
424
+ * because there is no id to report — a 2xx from an HTTP POST is not a message
425
+ * identifier, and inventing one would make an unjoinable send look joinable.
421
426
  */
422
427
  providerMessageId?: string;
428
+ /**
429
+ * Free-form per-channel extras.
430
+ *
431
+ * Until 3.0.0 the id-bearing channels ALSO mirror their provider id here under
432
+ * the legacy key (`messageId` for email/push, `sid` for sms). That duplication
433
+ * is the deprecation window, not the contract: read {@link providerMessageId},
434
+ * which is the same value under one name on every channel.
435
+ */
423
436
  metadata?: Record<string, unknown>;
424
437
  }
425
438
  /** Result from dispatching to all channels */
@@ -1,3 +1,3 @@
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-B5InMRIc.mjs";
2
- import { C as resolveRetryConfig, S as calculateDelay, T as mergeHooks, _ as isQuietHours, a as createStatusHandler, b as ProviderNotInstalledError, c as InterpolateOptions, d as TemplateMap, f as createSimpleResolver, g as QuietHoursConfig, h as pMap, i as StatusUpdate, m as PMapOptions, n as StatusHandler, o as FallbackOptions, p as interpolateHtml, r as StatusHandlerConfig, s as withFallback, t as DeliveryStatus, u as TemplateDefinition, v as ChannelError, w as withRetry, x as Emitter, y as NotificationError } from "../status-webhook-NDUgykHA.mjs";
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-DkFudalo.mjs";
2
+ import { C as resolveRetryConfig, S as calculateDelay, T as mergeHooks, _ as isQuietHours, a as createStatusHandler, b as ProviderNotInstalledError, c as InterpolateOptions, d as TemplateMap, f as createSimpleResolver, g as QuietHoursConfig, h as pMap, i as StatusUpdate, m as PMapOptions, n as StatusHandler, o as FallbackOptions, p as interpolateHtml, r as StatusHandlerConfig, s as withFallback, t as DeliveryStatus, u as TemplateDefinition, v as ChannelError, w as withRetry, x as Emitter, y as NotificationError } from "../status-webhook-CuCdFeVN.mjs";
3
3
  export { ChannelError, type DeliveryLog, type DeliveryLogEntry, type DeliveryLogQuery, type DeliveryStatus, Emitter, type FallbackOptions, IDEMPOTENCY_DEFAULT_TTL, type IdempotencyStore, type InterpolateOptions, 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, interpolateHtml, isQuietHours, mergeHooks, pMap, resolveRetryConfig, withFallback, withRetry };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classytic/notifications",
3
- "version": "2.3.0",
3
+ "version": "2.5.0",
4
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,