import { User } from 'lua-cli';
async function checkRefunds() {
const spike = await detectRefundSpike(); // your own logic
if (!spike) return { status: 'all clear' };
// ── 1. The notice — keyed, so re-runs REVISE instead of re-knocking ──
const receipt = await User.Inbox.push({
title: `${spike.count} refunds on ${spike.sku} within the hour`,
body: 'All from the same checkout flow — want a summary before it spreads?',
deeplink: `https://yourdashboard.example.com/refunds?sku=${spike.sku}`,
priority: spike.count > 5 ? 'urgent' : 'high',
key: `refund-spike-${spike.sku}`, // stable per incident
});
// ── 2. Handle the receipt — capped is a NORMAL outcome ──
if (receipt.outcome === 'capped') {
// Budget spent or the org has disabled pushes. Don't retry, don't
// throw — carry the finding in your run summary instead.
return {
status: 'anomaly found',
note: `Refund spike on ${spike.sku} (${spike.count} in the last hour). ` +
`Inbox push unavailable: ${receipt.reason}`,
};
}
return { status: 'user notified', outcome: receipt.outcome };
}