@corva/python-alerts-core
v0.7.0
Published
Store-free rules for Corva Python alerts: drafts, review, replay and Corva review.
Maintainers
Keywords
Readme
@corva/python-alerts-core
Store-free rules for Corva Python alerts: saving a draft, its review, its replay and sending it for Corva review.
yarn add @corva/python-alerts-coreUse
The package imports no store, toast or UI kit. The host passes its own clients in a
PythonAlertsContext (dataApi, coreApi, assets, now, currentUser, delay), and every
command returns a Result instead of throwing:
import { saveDraft, saveDraftPorts } from '@corva/python-alerts-core';
const saved = await saveDraft(saveDraftPorts(context), { companyId, content, coreAlerts });
if (saved.outcome === 'refused') {
// `code` is what code branches on; `message` is a sentence a person can read.
report(saved.refusal.code, saved.refusal.message);
}Readers named ...OrThrow throw instead, for a caller that must tell "nothing there" from
"could not read it".
Before creating an alert, listCompanyAlertsOrThrow(dataApi, companyId, limit) lists the
company's drafts and live alerts (name, description, segment, datasets, threshold keys, whether it
is live, its draft's request state; not the code), so a client can offer an existing alert instead
of a duplicate. isTruncated says the list stopped at limit.
After a replay that fired, buildReplayPresentation(digest, series) gives a Plotly chart and a
markdown table to paste into an answer unchanged. readReplaySeriesOrThrow(dataApi, replay) reads
the fields the alert used over the span it replayed, a few lines of at most sixty points each;
passed in, they are drawn as lines, each fired alert shading the plot over them and marked in a
lane along the bottom. A line whose read stopped short of the span
(isTruncated) is named partial. Without them the chart shows the fired alerts alone. The chart is titled with the digest's alertName when buildReplayDigest is given one.
The rules themselves, and why each exists, are in docs/rules.md, which ships with the package: the documents, the write contract, the workflow, the send gate and the task apps.
@corva/python-alerts-core/testing exports createInMemoryContext, in-memory fakes of the
clients for tests.
Versioning
Until 1.0, a minor release (0.x.0) may change an export, a Result code or a rule; a patch
release does not. Depend on ^0.x.y and take a minor release on purpose.
