Files
sencho/backend/src/helpers/notificationDispatchRetries.ts
Anso 090a0d73ac feat: add configurable notification dispatch retries (#1655)
* feat: add configurable notification dispatch retries

Allow each node to set 0-3 extra in-process delivery attempts with a fixed
one-second delay for routes, agents, and Test dispatch.

* fix: harden notification retry settings load/save and channel tests

Guard Delivery retries against failed and out-of-order same-node settings responses, and cover Slack/webhook retry classification alongside Discord.

* fix: clear Delivery retries saving state and correct screenshot alt

Separate save-request ownership from value-generation invalidation so a successful PATCH cannot leave Save retries stuck on Saving, reset saving on node switch, and align the Channels screenshot alt with the committed image.

* fix: surface invalid notification retry settings instead of false saved clamp

Align Channels GET handling with the backend strict 0-3 parser so stored values like 9 or 1.5 show as error needing repair, matching runtime fallback to 0 instead of displaying a clamped saved policy.
2026-07-20 20:29:17 -04:00

17 lines
555 B
TypeScript

/**
* Strict parser for notification_dispatch_retries (extra attempts, 0..3).
* Accepts JSON number integers or single-digit strings "0".."3" only.
* Rejects null, booleans, empty/whitespace, decimals, and out-of-range values.
*/
export function parseNotificationDispatchRetries(raw: unknown): number | null {
if (typeof raw === 'number') {
if (!Number.isInteger(raw) || raw < 0 || raw > 3) return null;
return raw;
}
if (typeof raw === 'string') {
if (!/^[0-3]$/.test(raw)) return null;
return Number(raw);
}
return null;
}