@grantex/destinations package, you can forward events to SIEMs, data warehouses, and message brokers without writing custom plumbing.
Architecture
EventSource class connects to the SSE stream and dispatches each event to one or more destinations you configure. Destinations buffer events and flush them in batches for efficiency.
Event Types
| Event | When it fires |
|---|---|
grant.created | A new grant is issued after the user completes the consent flow |
grant.revoked | A grant is revoked (root or cascade revocation) |
token.issued | A grant token is issued (initial exchange or refresh) |
budget.threshold | A budget usage threshold is crossed (e.g., 80%) |
budget.exhausted | A budget is fully consumed |
SSE Endpoint
GET /v1/events/stream returns a Server-Sent Events stream. Authenticate with your API key as a Bearer token.
curl
types query parameter (comma-separated):
TypeScript
Python
WebSocket Endpoint
GET /v1/events/ws upgrades to a WebSocket connection. Each message is a JSON-encoded event.
TypeScript
Python
@grantex/destinations Package
The@grantex/destinations package provides a high-level EventSource class that connects to the SSE stream and dispatches events to one or more destinations. Install it with:
Basic Usage
Available Destinations
| Destination | Class | Target |
|---|---|---|
| Datadog | DatadogDestination | Datadog Logs API |
| Splunk | SplunkDestination | Splunk HTTP Event Collector |
| Amazon S3 | S3Destination | S3 bucket (NDJSON files) |
| BigQuery | BigQueryDestination | Google BigQuery table |
| Kafka | KafkaDestination | Apache Kafka topic |
Shared Configuration
All destinations accept these base options:| Option | Type | Default | Description |
|---|---|---|---|
batchSize | number | Varies | Number of events to buffer before flushing |
flushIntervalMs | number | — | Flush on a timer (milliseconds) even if batch is not full |
Graceful Shutdown
Always callstop() to flush pending events and close connections:
Custom Destinations
Implement theEventDestination interface to build your own:
Next Steps
- Datadog Integration — monitors and alerting
- Splunk Integration — saved searches and dashboards
- S3 & BigQuery Archival — compliance archival
- Webhooks — push-based event delivery to your own endpoints
- Metrics & Observability — Prometheus metrics and Grafana dashboards