Server API ​
All exports below are server-side. Mutating APIs take the acting server ID as the first argument and re-check the
feature on the server. Return shape is generally ok, result or false, reason. Provider calls are trusted
resource-to-resource calls; never forward an arbitrary client value as an actor ID.
Cases and court ​
| Export | Signature | Notes |
|---|---|---|
CreateCase |
(src, spec) -> case | nil, reason |
Kinds: criminal, civil, traffic, warrant, bail, probate, records, notary, licence. src=nil is for a trusted integration. |
GetCase |
(idOrNumber) -> case | nil |
Trusted server lookup. |
ListCases |
(src, opts?) -> case[] | nil, reason |
Requires legal.records; supports kind, status, limit. |
GetCaseTimeline |
(src, id, limit?) -> event[] | nil, reason |
Case party or legal.records. |
TransitionCase |
(src, id, status, payload?) -> ok, caseOrReason |
Judge transition; sealing additionally allows legal.records. State machine rejects invalid transitions. |
AddCaseParty |
(src, id, party) -> ok, reason |
legal.records; party { identifier, name, role }. |
AttachExhibit |
(src, id, exhibit) -> ok, reason |
legal.records; exhibit is a reference and metadata snapshot, never a client-authored evidence truth. |
StartCourtSession |
(src, caseId, placeId?) -> ok, sessionOrReason |
Requires legal.judge; place scope is passed to np_jobs. |
GetCourtSession |
(id) -> session | nil |
Trusted server lookup. |
CourtSessionAction |
(src, sessionId, action, payload) -> ok, result |
Judge assigned to the session only. Actions: phase, gavel, recording, testimony. |
IssueRuling |
(src, caseId, { verdict, effects }) -> ok, result |
Effects are recorded independently and failed effects can be retried. |
RetryRulingEffect |
(src, rulingId, index, confirmRecovery?) -> ok, result |
Requires np_legal.admin. Confirm recovery only after reviewing an applying effect; the external side effect may have completed before a crash. |
Session phase values: call_case, roll_call, opening, evidence, testimony, closing, verdict,
sentencing. Gavel commands: order, recess, resume, adjourn, verdict. Each phase, testimony line, gavel
action, exhibit, and ruling is appended to the case timeline.
Documents, retainers, warrants and records ​
| Export | Signature | Notes |
|---|---|---|
IssueDocument |
(src, spec) -> document | nil, reason |
Registers a row and delivers the np_inventory item to the issuer and online document parties when available. Item failure returns the registered document and item_delivery:*; np_phone parties can also read/sign from the Legal app. |
GetDocument |
(idOrNumber) -> document | nil |
Trusted server lookup. |
SignDocument |
(src, id, role) -> ok, documentOrReason |
One signature per identifier/role; only a party listed on the document can sign. |
VerifyDocument |
(id, itemHash?) -> verification |
Result status: valid, revoked, hash_mismatch, or not_on_file. |
CreateRetainer |
(src, caseId, clientIdentifier, terms) -> ok, retainer |
legal.represent; client must already be a case party. Defence access is granted only after client and counsel both sign. |
RequestLawyerVisit |
(src, inmateIdentifier, at?) -> ok, visitOrReason |
legal.represent; calls np_prison:BookLawyerVisit; an omitted time selects the next available lawyer slot. |
SetBail / PostBail / ResolveBail / RetryBailRefund / RecoverInterruptedBailRefund |
(src, caseId, identifier, amount, conditions) / (src, bailId, method) / `(src, bailId, refund |
forfeit, note)/(src, bailId)/(src, bailId)` |
| Civil filing fee / notary service fee | fileCivil event / requestTransfer(src, spec) |
Before charging, np_legal persists a correlation on the docket case and passes it as np_payments metadata. An interrupted export is recovered through caller-scoped FindPaymentByCorrelation; lookup errors are quarantined as reconciliation-required, and unresolved filings stay in filing_pending and notary cases in payment_pending, so neither can enter normal case actions before settlement. Notary cases persist the configured fee and transfer terms; concurrent retries for the same case/terms are serialized per server process. A retry must use the same caseId, respondent identifier (civil), seller, buyer, asset, kind, title, and fee. Notary providers receive the stable case ID as spec.operationId and should make prepare idempotent. Recoverable notary errors include case=<caseId>. A completed or existing transfer is returned instead of creating another. |
ProsecutorAction |
(src, caseId, action, payload) -> ok, result |
legal.prosecute; drop, plea, or review_warrant. |
AppealCase |
(src, caseId, grounds) -> ok, appealCase |
legal.records; opens a records case and atomically links it to the parent appeal status/event. An applied ruling on the current appeal closes the original with a linked timeline event; startup reconciliation repairs an interrupted resolution and ignores stale appeals. Fine and restitution invoices use the ruling/effect identity as np_payments' idempotency key, so recovery reuses the same invoice. |
RequestTransfer |
(src, spec) -> ok, transfer |
legal.notary; vehicle uses the included provider. property returns provider_unavailable until a deployment registers a provider against a verified np_housing API. |
SignTransfer |
(src, transferId, role) -> ok, result |
Seller, buyer, and assigned notary signatures required before the provider commits. |
IssueLicence |
(src, target, type, action, data) -> ok, serialOrReason |
legal.licence_issue; delegates to np_identification. |
RecordsAction |
(src, provider, action, payload) -> ok, result |
legal.records; delegates to an explicitly registered records provider. |
Warrant providers call CreateWarrantRequest(src, spec) with provider (for example np_police), providerRef, kind, subject, summary,
evidence, optional caseId, and expiresAt. The signing APIs are GetWarrant(id), ReviewWarrant(src, id, note), ListWarrants(src, status?), and DecideWarrant(src, id, approve|deny|revoke, note). The queue only
returns provider/kind combinations allowed by the caller's feature config. Effects are delivered to an explicitly
registered RegisterWarrantProvider(provider, fn) callback as fn(decision, warrant, actorSrc). A provider must return true to acknowledge a decision. Provider failures are retained in execution_status; an authorized signer can retry a confirmed failure. Unknown outcomes are quarantined; staff with np_legal.override must inspect provider state by warrant ID and explicitly resolve reconcile_<action>_applied or reconcile_<action>_not_applied through DecideWarrant. The queue UI offers this recovery action, and confirmed applied state is recorded without calling the provider again. Providers should implement idempotency and an explicit reconciliation path for safe recovery. The queue includes quarantined requests and only exposes retries for retryable states. np_police mirrors approve, deny, expiry and revoke.
After manual resolution, np_legal emits np_legal:warrant:execution_reconciled with the durable warrant row so integrations can repair their mirrored state. Providers should also retry reconciliation at startup to recover from missed events or temporary export failures.
Capability pack and providers ​
IsReady() -> booleanis false until the warrant schema has passed the startup gate; integrations should check it before creating or signing provider warrants.Can(src, featureId, opts?) -> ok, reason, infoGetFeatureConfig(src, featureId, opts?) -> table|nilGetPlayersWithFeature(featureId, opts?) -> number[]GetVersion() -> stringRegisterRulingEffect(effectId, fn(src, case, effect, rulingId))RegisterWarrantProvider(providerId, fn(decision, warrant, actorSrc))RecoverInterruptedBailRefund(src, bailId)— reconciles an interrupted bail charge/refund against the np_payments ledger before finalizing it; committed charges can be found by the stable bail correlation key.RegisterTransferProvider(kind, fn(stage, src, spec, case, transfer))RegisterRecordProvider(providerId, fn(action, src, payload))
The registered features are legal.judge, legal.represent, legal.prosecute, legal.warrant_sign, legal.bail,
legal.notary, legal.licence_issue, and legal.records. Their schemas and permission nodes are in
shared/features.lua and mirrored in IDEAS.md.
The standalone UI's Services tab calls the same server APIs for sessions, rulings, retainers, prosecution, bail (including failed-refund retry), transfers, licences, appeals, and expungement. The np_phone Legal app lists and signs party documents. Server checks remain authoritative. Lawyer visit booking, probation/community service/seizure effects, and bondsman recovery rewards require external providers.
Events ​
Server events: np_legal:server:ready (startup complete), np_legal:case:event(caseId, eventType, payload, actor),
np_legal:warrant:requested(id, provider, kind), np_legal:warrant:decided(warrant, actorSrc),
np_legal:document:signed(document, signature, signerSrc), np_legal:session:opened(id, case, place, judgeSrc),
np_legal:transfer:completed(transfer, result), and np_legal:audit(entry). Cross-resource request events are
server-local and are documented in the installation guide; do not register them as client network events.