Skip to content

Core hooks for regional compliance integrations: invoice.* events, delivery-failure alerting, webhook docs#162

Merged
telivity-otaip merged 5 commits into
mainfrom
cursor/regional-hooks-ci-fix-5cff
Jul 17, 2026
Merged

Core hooks for regional compliance integrations: invoice.* events, delivery-failure alerting, webhook docs#162
telivity-otaip merged 5 commits into
mainfrom
cursor/regional-hooks-ci-fix-5cff

Conversation

@telivity-otaip

@telivity-otaip telivity-otaip commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

Supports #159 (Brazilian government guest registration + tax invoice integrations). The existing webhook subscription system already covers the event-driven side; this PR adds the three core pieces that make external regional integrations clean to build, without putting any regional tax logic in core.

Supersedes #161 (same changes + README test-count sync that CI rejected on the previous branch).

1. Fiscal document references + invoice.* events

Jurisdictions like Brazil require official tax documents (NFS-e tax notes) per folio. Core now stores a reference to such documents and emits lifecycle events, while issuance stays in an external integration:

  • New fiscal_documents table (property-scoped, folio-linked, metadata jsonb for regional fields — series, verification codes, etc. Core never interprets them).
  • New events: invoice.requested, invoice.issued, invoice.voided.
  • New endpoints on folios:
    • POST /folios/:id/fiscal-documents — request a document → emits invoice.requested
    • POST /folios/:id/fiscal-documents/:documentId/issue — integration reports the issued document number → emits invoice.issued
    • POST /folios/:id/fiscal-documents/:documentId/void — void/cancel → emits invoice.voided
    • GET /folios/:id/fiscal-documents — list
  • All queries scoped by propertyId per the multi-tenancy rules; migration added to both push-schema.ts and src/migrations/0007_fiscal_documents.sql.

2. Staff alerting on permanent webhook delivery failure

A delivery that exhausted all 5 retries (~7h) previously went silent — unacceptable when the subscriber is a mandatory government-reporting integration. WebhookDeliveryService now emits an in-process webhook.delivery_failed event on permanent failure, and StaffNotificationListener creates a critical staff notification. The internal event is deliberately not fanned out to external subscribers (their endpoint is the thing failing), and failures of staff.notification_created deliveries are skipped to prevent an alert-on-alert loop.

3. Webhook integration guide (docs/webhooks.md)

Documents subscribing via the Connect API, HMAC signature verification (with code sample), the lean-payload / fetch-by-entityId convention (keeps guest PII out of webhook bodies), retry + at-least-once semantics, the polling reconciliation fallback, the fiscal document flow, and a worked government guest-registration example. Linked from the README. README test counts synced to 1129 / 136.

Testing

  • 18 new tests (fiscal document lifecycle + multi-tenancy scoping, delivery-failure event emission, listener behavior incl. loop guard).
  • Full suite: 1129 tests across 136 files. Typecheck clean, lint 0 errors.

Notes for reviewers

  • The fiscal document concept is not in the KB; it is deliberately modeled as pure integration plumbing (a reference + lifecycle + events), not hotel/tax domain logic. documentType and metadata are opaque to core.
  • EventEmitter2 is injected @Optional() into WebhookDeliveryService so existing direct-construction tests remain valid.

cursoragent and others added 5 commits July 17, 2026 02:14
Regional tax integrations (e.g. NFS-e tax notes in Brazil) can now be built
on core hooks: staff request a fiscal document on a folio (emits
invoice.requested), an external integration performs the issuance against
the government API and reports the official document number back (emits
invoice.issued), with voiding supported (invoice.voided). Core stores only
the reference and lifecycle; regional fields live in metadata jsonb.

Requested in #159.

Co-authored-by: telivity-otaip <telivity-otaip@users.noreply.github.com>
A delivery that exhausts all 5 retry attempts (~7h) previously just marked
the row failed — silent for operators. For mandatory-delivery subscribers
(e.g. government reporting integrations, #159) that is not acceptable.

WebhookDeliveryService now emits an in-process webhook.delivery_failed
event on permanent failure (deliberately not fanned out to external
subscribers — their endpoint is the thing failing), and
StaffNotificationListener turns it into a critical staff notification.
Failures of staff.notification_created deliveries are skipped to prevent
an alert-on-alert loop.

Co-authored-by: telivity-otaip <telivity-otaip@users.noreply.github.com>
…ion patterns

New docs/webhooks.md covers subscribing via the Connect API, HMAC signature
verification, the lean-payload / fetch-by-entityId convention, retry and
at-least-once semantics, the polling reconciliation fallback, the fiscal
document (invoice.*) flow, and a worked government guest-registration
example. Linked from the README webhook engine section.

Co-authored-by: telivity-otaip <telivity-otaip@users.noreply.github.com>
CI requires the badge and docs counts to match the suite (1129 tests /
136 files after the 18 new tests in this PR).

Co-authored-by: telivity-otaip <telivity-otaip@users.noreply.github.com>
@telivity-otaip
telivity-otaip marked this pull request as ready for review July 17, 2026 02:26
@telivity-otaip telivity-otaip self-assigned this Jul 17, 2026
@telivity-otaip
telivity-otaip merged commit 575ff4d into main Jul 17, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants