paygate-mcp 9.1.0 → 9.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -3
- package/dist/audit.d.ts +1 -1
- package/dist/audit.d.ts.map +1 -1
- package/dist/audit.js.map +1 -1
- package/dist/circuit-breaker.d.ts +64 -0
- package/dist/circuit-breaker.d.ts.map +1 -0
- package/dist/circuit-breaker.js +114 -0
- package/dist/circuit-breaker.js.map +1 -0
- package/dist/compliance.d.ts +64 -0
- package/dist/compliance.d.ts.map +1 -0
- package/dist/compliance.js +239 -0
- package/dist/compliance.js.map +1 -0
- package/dist/gate.d.ts +11 -0
- package/dist/gate.d.ts.map +1 -1
- package/dist/gate.js +53 -0
- package/dist/gate.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/openapi.js +29 -0
- package/dist/openapi.js.map +1 -1
- package/dist/response-cache.d.ts +74 -0
- package/dist/response-cache.d.ts.map +1 -0
- package/dist/response-cache.js +139 -0
- package/dist/response-cache.js.map +1 -0
- package/dist/server.d.ts +10 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +370 -2
- package/dist/server.js.map +1 -1
- package/dist/types.d.ts +20 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Monetize any MCP server with one command. Add API key auth, per-tool pricing, ra
|
|
|
11
11
|
- [Quick Start](#quick-start)
|
|
12
12
|
- [What It Does](#what-it-does)
|
|
13
13
|
- [Usage](#usage) — Local stdio, remote HTTP, multi-server, client SDK
|
|
14
|
-
- [API Reference](#api-reference) — All
|
|
14
|
+
- [API Reference](#api-reference) — All 143+ endpoints
|
|
15
15
|
- [CLI Options](#cli-options)
|
|
16
16
|
- [Deployment](#deployment) — Docker, docker-compose, systemd, PM2
|
|
17
17
|
- [Load Testing](#load-testing) — k6 benchmarking for production
|
|
@@ -23,6 +23,7 @@ Monetize any MCP server with one command. Add API key auth, per-tool pricing, ra
|
|
|
23
23
|
- [Plugins](#plugin-system) · [Groups](#key-groups-policy-templates) · [Namespaces](#multi-tenant-namespaces)
|
|
24
24
|
- [Programmatic API](#programmatic-api)
|
|
25
25
|
- [Security](#security)
|
|
26
|
+
- [Tested With](#tested-with) — Verified against popular MCP servers
|
|
26
27
|
- [Current Limitations](#current-limitations)
|
|
27
28
|
- [Roadmap](#roadmap)
|
|
28
29
|
- [Requirements](#requirements)
|
|
@@ -65,7 +66,7 @@ Agent → PayGate (auth + billing) → Your MCP Server (stdio or HTTP)
|
|
|
65
66
|
- **SSE Streaming** — Full MCP Streamable HTTP transport (POST SSE, GET notifications, DELETE sessions)
|
|
66
67
|
- **Audit Log** — Structured audit trail with retention policies, query API, CSV/JSON export
|
|
67
68
|
- **Registry/Discovery** — Agent-discoverable pricing via `/.well-known/mcp-payment`, `/pricing`, and `/.well-known/mcp.json` identity card
|
|
68
|
-
- **OpenAPI 3.1 + Interactive Docs** — Auto-generated spec at `/openapi.json`, Swagger UI at `/docs` — all
|
|
69
|
+
- **OpenAPI 3.1 + Interactive Docs** — Auto-generated spec at `/openapi.json`, Swagger UI at `/docs` — all 143+ endpoints documented
|
|
69
70
|
- **Public Endpoint Rate Limiting** — Configurable per-IP rate limit (default 300/min) on `/health`, `/info`, `/pricing`, `/docs`, `/openapi.json`, `/.well-known/*`, `/robots.txt`, `/` — 429 with Retry-After header
|
|
70
71
|
- **Robots.txt + HEAD Support** — Standard `/robots.txt` (allow public, disallow admin/keys), HEAD method on all public endpoints for uptime monitoring
|
|
71
72
|
- **Prometheus Metrics** — `/metrics` endpoint with counters, gauges, and uptime in standard text format
|
|
@@ -146,6 +147,12 @@ Agent → PayGate (auth + billing) → Your MCP Server (stdio or HTTP)
|
|
|
146
147
|
- **Quota Analysis** — `GET /admin/quotas` quota utilization analysis with per-key daily/monthly usage vs limits, per-tool denial breakdown, most constrained keys, and global/per-key quota source tracking
|
|
147
148
|
- **Denial Analysis** — `GET /admin/denials` comprehensive denial breakdown by reason type (insufficient_credits, rate_limited, quota_exceeded, key_suspended, etc.) with per-key and per-tool stats, hourly trends, and most denied keys
|
|
148
149
|
- **Traffic Analysis** — `GET /admin/traffic` request volume analysis with tool popularity, hourly volume, top consumers by call count, namespace breakdown, peak hour identification, and success rates
|
|
150
|
+
- **Response Caching** — SHA-256 keyed response cache for identical tool calls — skips backend invocation and credit deduction on cache hit, LRU eviction, per-tool or global TTL, `X-Cache: HIT/MISS` header, admin management (`GET/DELETE /admin/cache`), Prometheus gauge
|
|
151
|
+
- **Circuit Breaker** — Three-state circuit breaker (closed → open → half_open) for backend failure detection — opens after N consecutive failures, auto-recovers after cooldown, error code `-32003`, admin management (`GET/POST /admin/circuit`)
|
|
152
|
+
- **Configurable Timeouts** — Per-tool and global timeout for tool calls — returns error code `-32004` on timeout, per-tool override via `toolPricing[tool].timeoutMs`, triggers circuit breaker failure recording
|
|
153
|
+
- **Outcome-Based Pricing** — Charge extra credits based on response output size — `creditsPerKbOutput` per-tool config, post-response billing, `X-Output-Surcharge` header, complements `creditsPerKbInput` for complete size-based pricing
|
|
154
|
+
- **Compliance Audit Export** — Framework-specific compliance reports for SOC 2, GDPR, HIPAA — `GET /admin/compliance/export`, event classification into access control/data processing/config changes/security, JSON or CSV export, configurable time periods
|
|
155
|
+
- **Per-Key Webhook URLs** — Key-level webhook routing — events for a specific key sent to key's webhook URL alongside global webhook, SSRF-protected, HMAC-SHA256 signed, lazy emitter management via `POST/GET/DELETE /keys/webhook`
|
|
149
156
|
- **Security Audit** — `GET /admin/security` security posture analysis identifying keys without IP allowlists, quotas, ACL restrictions, spending limits, or expiry dates, flagging high-credit keys, and computing a composite security score
|
|
150
157
|
- **Revenue Analysis** — `GET /admin/revenue` revenue metrics with per-tool revenue breakdown, per-key spending, hourly revenue trends, credit flow summary (allocated/spent/remaining), and average revenue per call
|
|
151
158
|
- **Key Portfolio Health** — `GET /admin/key-portfolio` portfolio-wide key health with active/inactive/suspended counts, stale keys, expiring-soon keys, age distribution, credit utilization, and namespace breakdown
|
|
@@ -445,6 +452,14 @@ A real-time admin UI for managing keys, viewing usage, and monitoring tool calls
|
|
|
445
452
|
| `/stripe/webhook` | POST | Stripe Signature | Auto-top-up credits on payment |
|
|
446
453
|
| `/admin/backup` | GET | `X-Admin-Key` | Export full server state as versioned JSON snapshot |
|
|
447
454
|
| `/admin/restore` | POST | `X-Admin-Key` | Import state from backup (merge/overwrite/full modes) |
|
|
455
|
+
| `/admin/cache` | GET | `X-Admin-Key` | Response cache stats (entries, hits, misses, hit rate) |
|
|
456
|
+
| `/admin/cache` | DELETE | `X-Admin-Key` | Clear cache (all or `?tool=` filter) |
|
|
457
|
+
| `/admin/circuit` | GET | `X-Admin-Key` | Circuit breaker status (state, failures, rejections) |
|
|
458
|
+
| `/admin/circuit` | POST | `X-Admin-Key` | Reset circuit breaker to closed state |
|
|
459
|
+
| `/admin/compliance/export` | GET | `X-Admin-Key` | Compliance audit export (SOC 2/GDPR/HIPAA, JSON/CSV) |
|
|
460
|
+
| `/keys/webhook` | POST | `X-Admin-Key` | Set per-key webhook URL |
|
|
461
|
+
| `/keys/webhook` | GET | `X-Admin-Key` | Get per-key webhook status |
|
|
462
|
+
| `/keys/webhook` | DELETE | `X-Admin-Key` | Remove per-key webhook URL |
|
|
448
463
|
| `/.well-known/oauth-authorization-server` | GET | None | OAuth 2.1 server metadata |
|
|
449
464
|
| `/oauth/register` | POST | None | Dynamic Client Registration (RFC 7591) |
|
|
450
465
|
| `/oauth/authorize` | GET | None | Authorization endpoint (PKCE required) |
|
|
@@ -454,7 +469,7 @@ A real-time admin UI for managing keys, viewing usage, and monitoring tool calls
|
|
|
454
469
|
| `/.well-known/mcp-payment` | GET | None | Server payment metadata (SEP-2007) |
|
|
455
470
|
| `/.well-known/mcp.json` | GET | None | MCP Server Identity card (discovery) |
|
|
456
471
|
| `/pricing` | GET | None | Full per-tool pricing breakdown |
|
|
457
|
-
| `/openapi.json` | GET | None | OpenAPI 3.1 spec (all
|
|
472
|
+
| `/openapi.json` | GET | None | OpenAPI 3.1 spec (all 143+ endpoints) |
|
|
458
473
|
| `/docs` | GET | None | Interactive API docs (Swagger UI) |
|
|
459
474
|
| `/robots.txt` | GET | None | Crawler directives (allow public, disallow admin/keys) |
|
|
460
475
|
| `/portal` | GET | None | Self-service API key portal (browser UI, auth via X-API-Key prompt) |
|
|
@@ -5136,6 +5151,8 @@ K6_PAYGATE_URL=https://paygate.example.com K6_ADMIN_KEY=admin_xxxx k6 run load-t
|
|
|
5136
5151
|
| `-32402` | `ip_not_allowed` | Client IP not in key's allowlist |
|
|
5137
5152
|
| `-32402` | `invalid_api_key` | X-API-Key header not recognized |
|
|
5138
5153
|
| `-32402` | `maintenance_mode` | Server in maintenance mode |
|
|
5154
|
+
| `-32003` | `circuit_breaker_open` | Backend unavailable, circuit breaker is open |
|
|
5155
|
+
| `-32004` | `tool_timeout` | Tool call exceeded configured timeout |
|
|
5139
5156
|
| `-32600` | `invalid_request` | Malformed JSON-RPC request body |
|
|
5140
5157
|
| `-32601` | `method_not_found` | Unknown MCP method |
|
|
5141
5158
|
|
|
@@ -5238,6 +5255,24 @@ const result = await client.callTool('search', { query: 'hello' });
|
|
|
5238
5255
|
- Pub/sub subscriber uses a dedicated Redis connection (required by Redis protocol)
|
|
5239
5256
|
- Red-teamed with 101 adversarial security tests across 14 passes
|
|
5240
5257
|
|
|
5258
|
+
## Tested With
|
|
5259
|
+
|
|
5260
|
+
PayGate is integration-tested against popular MCP servers from the official `@modelcontextprotocol` npm scope. These tests wrap real MCP servers via `npx`, execute tool calls through the PayGate proxy, and verify that auth gating, credit billing, and rate limiting work correctly end-to-end.
|
|
5261
|
+
|
|
5262
|
+
| MCP Server | Type | Tests | What's Verified |
|
|
5263
|
+
|---|---|---|---|
|
|
5264
|
+
| `@modelcontextprotocol/server-everything` | stdio | 4 | Tool discovery, math tool execution, credit deduction, credit blocking |
|
|
5265
|
+
| `@modelcontextprotocol/server-filesystem` | stdio | 4 | File write/read through gate, credit deduction, credit blocking |
|
|
5266
|
+
| `@modelcontextprotocol/server-memory` | stdio | 4 | Entity CRUD, knowledge graph search, credit deduction, credit blocking |
|
|
5267
|
+
| `@modelcontextprotocol/server-sequential-thinking` | stdio | 4 | Sequential thinking flow, credit deduction, credit blocking |
|
|
5268
|
+
|
|
5269
|
+
**Cross-server tests** verify admin endpoints (`/health`, `/keys`, `/balance`) work identically regardless of the wrapped backend. All 16 integration tests pass.
|
|
5270
|
+
|
|
5271
|
+
```bash
|
|
5272
|
+
# Run integration tests (requires internet — downloads MCP servers via npx)
|
|
5273
|
+
npx vitest run tests/real-mcp-servers.test.ts
|
|
5274
|
+
```
|
|
5275
|
+
|
|
5241
5276
|
## Current Limitations
|
|
5242
5277
|
|
|
5243
5278
|
- **No response size limits for HTTP transport** — Large responses from remote servers are forwarded as-is.
|
package/dist/audit.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* session lifecycle, and admin operations. Ring buffer with configurable
|
|
6
6
|
* max size and age-based retention. Zero external dependencies.
|
|
7
7
|
*/
|
|
8
|
-
export type AuditEventType = 'key.created' | 'key.revoked' | 'key.suspended' | 'key.resumed' | 'key.cloned' | 'key.rotated' | 'key.topup' | 'key.acl_updated' | 'key.expiry_updated' | 'key.quota_updated' | 'key.tags_updated' | 'key.ip_updated' | 'key.limit_updated' | 'gate.allow' | 'gate.deny' | 'session.created' | 'session.destroyed' | 'oauth.client_registered' | 'oauth.token_issued' | 'oauth.token_revoked' | 'team.created' | 'team.updated' | 'team.deleted' | 'team.key_assigned' | 'team.key_removed' | 'admin.auth_failed' | 'admin.alerts_configured' | 'webhook.dead_letter_cleared' | 'webhook.replayed' | 'webhook.test' | 'webhook.pause' | 'webhook.resume' | 'key.alias_set' | 'key.expiry_warning' | 'template.created' | 'template.updated' | 'template.deleted' | 'token.created' | 'token.revoked' | 'billing.refund' | 'key.auto_topup_configured' | 'key.auto_topped_up' | 'admin_key.created' | 'admin_key.revoked' | 'admin_key.bootstrap_rotated' | 'group.created' | 'group.updated' | 'group.deleted' | 'group.key_assigned' | 'group.key_removed' | 'key.credits_transferred' | 'keys.exported' | 'keys.imported' | 'webhook_filter.created' | 'webhook_filter.updated' | 'webhook_filter.deleted' | 'config.reloaded' | 'config.export' | 'maintenance.enabled' | 'maintenance.disabled' | 'key.note_added' | 'key.note_deleted' | 'schedule.created' | 'schedule.executed' | 'schedule.cancelled' | 'credits.reserved' | 'credits.committed' | 'credits.released' | 'stripe.checkout_created' | 'admin.backup_created' | 'admin.backup_restored';
|
|
8
|
+
export type AuditEventType = 'key.created' | 'key.revoked' | 'key.suspended' | 'key.resumed' | 'key.cloned' | 'key.rotated' | 'key.topup' | 'key.acl_updated' | 'key.expiry_updated' | 'key.quota_updated' | 'key.tags_updated' | 'key.ip_updated' | 'key.limit_updated' | 'gate.allow' | 'gate.deny' | 'session.created' | 'session.destroyed' | 'oauth.client_registered' | 'oauth.token_issued' | 'oauth.token_revoked' | 'team.created' | 'team.updated' | 'team.deleted' | 'team.key_assigned' | 'team.key_removed' | 'admin.auth_failed' | 'admin.alerts_configured' | 'webhook.dead_letter_cleared' | 'webhook.replayed' | 'webhook.test' | 'webhook.pause' | 'webhook.resume' | 'key.alias_set' | 'key.expiry_warning' | 'template.created' | 'template.updated' | 'template.deleted' | 'token.created' | 'token.revoked' | 'billing.refund' | 'key.auto_topup_configured' | 'key.auto_topped_up' | 'admin_key.created' | 'admin_key.revoked' | 'admin_key.bootstrap_rotated' | 'group.created' | 'group.updated' | 'group.deleted' | 'group.key_assigned' | 'group.key_removed' | 'key.credits_transferred' | 'keys.exported' | 'keys.imported' | 'webhook_filter.created' | 'webhook_filter.updated' | 'webhook_filter.deleted' | 'config.reloaded' | 'config.export' | 'maintenance.enabled' | 'maintenance.disabled' | 'key.note_added' | 'key.note_deleted' | 'schedule.created' | 'schedule.executed' | 'schedule.cancelled' | 'credits.reserved' | 'credits.committed' | 'credits.released' | 'stripe.checkout_created' | 'admin.backup_created' | 'admin.backup_restored' | 'admin.cache_cleared' | 'admin.circuit_reset';
|
|
9
9
|
export interface AuditEvent {
|
|
10
10
|
/** Monotonically increasing ID */
|
|
11
11
|
id: number;
|
package/dist/audit.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,MAAM,cAAc,GAEtB,aAAa,GACb,aAAa,GACb,eAAe,GACf,aAAa,GACb,YAAY,GACZ,aAAa,GACb,WAAW,GACX,iBAAiB,GACjB,oBAAoB,GACpB,mBAAmB,GACnB,kBAAkB,GAClB,gBAAgB,GAChB,mBAAmB,GAEnB,YAAY,GACZ,WAAW,GAEX,iBAAiB,GACjB,mBAAmB,GAEnB,yBAAyB,GACzB,oBAAoB,GACpB,qBAAqB,GAErB,cAAc,GACd,cAAc,GACd,cAAc,GACd,mBAAmB,GACnB,kBAAkB,GAElB,mBAAmB,GACnB,yBAAyB,GAEzB,6BAA6B,GAC7B,kBAAkB,GAClB,cAAc,GACd,eAAe,GACf,gBAAgB,GAEhB,eAAe,GAEf,oBAAoB,GAEpB,kBAAkB,GAClB,kBAAkB,GAClB,kBAAkB,GAElB,eAAe,GACf,eAAe,GAEf,gBAAgB,GAEhB,2BAA2B,GAC3B,oBAAoB,GAEpB,mBAAmB,GACnB,mBAAmB,GACnB,6BAA6B,GAE7B,eAAe,GACf,eAAe,GACf,eAAe,GACf,oBAAoB,GACpB,mBAAmB,GAEnB,yBAAyB,GAEzB,eAAe,GACf,eAAe,GAEf,wBAAwB,GACxB,wBAAwB,GACxB,wBAAwB,GAExB,iBAAiB,GACjB,eAAe,GAEf,qBAAqB,GACrB,sBAAsB,GAEtB,gBAAgB,GAChB,kBAAkB,GAElB,kBAAkB,GAClB,mBAAmB,GACnB,oBAAoB,GAEpB,kBAAkB,GAClB,mBAAmB,GACnB,kBAAkB,GAElB,yBAAyB,GAEzB,sBAAsB,GACtB,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,MAAM,cAAc,GAEtB,aAAa,GACb,aAAa,GACb,eAAe,GACf,aAAa,GACb,YAAY,GACZ,aAAa,GACb,WAAW,GACX,iBAAiB,GACjB,oBAAoB,GACpB,mBAAmB,GACnB,kBAAkB,GAClB,gBAAgB,GAChB,mBAAmB,GAEnB,YAAY,GACZ,WAAW,GAEX,iBAAiB,GACjB,mBAAmB,GAEnB,yBAAyB,GACzB,oBAAoB,GACpB,qBAAqB,GAErB,cAAc,GACd,cAAc,GACd,cAAc,GACd,mBAAmB,GACnB,kBAAkB,GAElB,mBAAmB,GACnB,yBAAyB,GAEzB,6BAA6B,GAC7B,kBAAkB,GAClB,cAAc,GACd,eAAe,GACf,gBAAgB,GAEhB,eAAe,GAEf,oBAAoB,GAEpB,kBAAkB,GAClB,kBAAkB,GAClB,kBAAkB,GAElB,eAAe,GACf,eAAe,GAEf,gBAAgB,GAEhB,2BAA2B,GAC3B,oBAAoB,GAEpB,mBAAmB,GACnB,mBAAmB,GACnB,6BAA6B,GAE7B,eAAe,GACf,eAAe,GACf,eAAe,GACf,oBAAoB,GACpB,mBAAmB,GAEnB,yBAAyB,GAEzB,eAAe,GACf,eAAe,GAEf,wBAAwB,GACxB,wBAAwB,GACxB,wBAAwB,GAExB,iBAAiB,GACjB,eAAe,GAEf,qBAAqB,GACrB,sBAAsB,GAEtB,gBAAgB,GAChB,kBAAkB,GAElB,kBAAkB,GAClB,mBAAmB,GACnB,oBAAoB,GAEpB,kBAAkB,GAClB,mBAAmB,GACnB,kBAAkB,GAElB,yBAAyB,GAEzB,sBAAsB,GACtB,uBAAuB,GACvB,qBAAqB,GACrB,qBAAqB,CAAC;AAE1B,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AQ;gBAEzC,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC;IAU5C;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,UAAU;IAqC7G;;OAEG;IACH,KAAK,CAAC,CAAC,GAAE,UAAe,GAAG,gBAAgB;IAoC3C;;OAEG;IACH,KAAK,IAAI;QACP,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;QAC3B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;QAC3B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACrC,cAAc,EAAE,MAAM,CAAC;QACvB,aAAa,EAAE,MAAM,CAAC;KACvB;IA0BD;;OAEG;IACH,SAAS,IAAI,UAAU,EAAE;IAIzB;;OAEG;IACH,SAAS,CAAC,CAAC,GAAE,UAAe,GAAG,MAAM;IASrC;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,gBAAgB,IAAI,MAAM;IAS1B;;OAEG;IACH,KAAK,IAAI,IAAI;IAKb;;OAEG;IACH,OAAO,IAAI,IAAI;CAMhB;AAID,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGnD"}
|
package/dist/audit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit.js","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;
|
|
1
|
+
{"version":3,"file":"audit.js","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AA+VH,0CAGC;AA5MD,MAAM,oBAAoB,GAAmB;IAC3C,SAAS,EAAE,MAAM;IACjB,WAAW,EAAE,GAAG,EAAE,UAAU;IAC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AE,IAAI,MAAM,CAAC,CAAC;QACjF,OAAO,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAClB,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YACjC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QAC3B,CAAC;IACH,CAAC;CACF;AA7LD,kCA6LC;AAED,gFAAgF;AAEhF,SAAgB,eAAe,CAAC,GAAW;IACzC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,EAAE;QAAE,OAAO,KAAK,CAAC;IAC1C,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CircuitBreaker — Detects failing backends and fails fast.
|
|
3
|
+
*
|
|
4
|
+
* States:
|
|
5
|
+
* CLOSED — Normal operation. Requests pass through.
|
|
6
|
+
* OPEN — Backend is failing. Requests rejected immediately (503).
|
|
7
|
+
* HALF_OPEN — After cooldown, one probe request allowed through.
|
|
8
|
+
*
|
|
9
|
+
* Transitions:
|
|
10
|
+
* CLOSED → OPEN: After N consecutive failures (threshold).
|
|
11
|
+
* OPEN → HALF_OPEN: After cooldown period expires.
|
|
12
|
+
* HALF_OPEN → CLOSED: If probe succeeds.
|
|
13
|
+
* HALF_OPEN → OPEN: If probe fails (reset cooldown timer).
|
|
14
|
+
*/
|
|
15
|
+
export type CircuitState = 'closed' | 'open' | 'half_open';
|
|
16
|
+
export interface CircuitBreakerConfig {
|
|
17
|
+
/** Consecutive failures before opening circuit. */
|
|
18
|
+
threshold: number;
|
|
19
|
+
/** Cooldown period in seconds before attempting recovery. */
|
|
20
|
+
cooldownSeconds: number;
|
|
21
|
+
}
|
|
22
|
+
export interface CircuitStatus {
|
|
23
|
+
state: CircuitState;
|
|
24
|
+
consecutiveFailures: number;
|
|
25
|
+
lastFailureAt: string | null;
|
|
26
|
+
openedAt: string | null;
|
|
27
|
+
totalFailures: number;
|
|
28
|
+
totalSuccesses: number;
|
|
29
|
+
totalRejections: number;
|
|
30
|
+
}
|
|
31
|
+
export declare class CircuitBreaker {
|
|
32
|
+
private state;
|
|
33
|
+
private consecutiveFailures;
|
|
34
|
+
private lastFailureAt;
|
|
35
|
+
private openedAt;
|
|
36
|
+
private totalFailures;
|
|
37
|
+
private totalSuccesses;
|
|
38
|
+
private totalRejections;
|
|
39
|
+
private readonly threshold;
|
|
40
|
+
private readonly cooldownMs;
|
|
41
|
+
constructor(config: CircuitBreakerConfig);
|
|
42
|
+
/**
|
|
43
|
+
* Check if a request should be allowed through.
|
|
44
|
+
* Returns true if allowed, false if circuit is open.
|
|
45
|
+
*/
|
|
46
|
+
allowRequest(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Record a successful response from the backend.
|
|
49
|
+
*/
|
|
50
|
+
recordSuccess(): void;
|
|
51
|
+
/**
|
|
52
|
+
* Record a failed response from the backend.
|
|
53
|
+
*/
|
|
54
|
+
recordFailure(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Get current circuit status.
|
|
57
|
+
*/
|
|
58
|
+
status(): CircuitStatus;
|
|
59
|
+
/**
|
|
60
|
+
* Reset the circuit breaker to closed state.
|
|
61
|
+
*/
|
|
62
|
+
reset(): void;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=circuit-breaker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circuit-breaker.d.ts","sourceRoot":"","sources":["../src/circuit-breaker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;AAE3D,MAAM,WAAW,oBAAoB;IACnC,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,YAAY,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,mBAAmB,CAAK;IAChC,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,eAAe,CAAK;IAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAExB,MAAM,EAAE,oBAAoB;IAKxC;;;OAGG;IACH,YAAY,IAAI,OAAO;IAoBvB;;OAEG;IACH,aAAa,IAAI,IAAI;IAYrB;;OAEG;IACH,aAAa,IAAI,IAAI;IAerB;;OAEG;IACH,MAAM,IAAI,aAAa;IAgBvB;;OAEG;IACH,KAAK,IAAI,IAAI;CAKd"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* CircuitBreaker — Detects failing backends and fails fast.
|
|
4
|
+
*
|
|
5
|
+
* States:
|
|
6
|
+
* CLOSED — Normal operation. Requests pass through.
|
|
7
|
+
* OPEN — Backend is failing. Requests rejected immediately (503).
|
|
8
|
+
* HALF_OPEN — After cooldown, one probe request allowed through.
|
|
9
|
+
*
|
|
10
|
+
* Transitions:
|
|
11
|
+
* CLOSED → OPEN: After N consecutive failures (threshold).
|
|
12
|
+
* OPEN → HALF_OPEN: After cooldown period expires.
|
|
13
|
+
* HALF_OPEN → CLOSED: If probe succeeds.
|
|
14
|
+
* HALF_OPEN → OPEN: If probe fails (reset cooldown timer).
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.CircuitBreaker = void 0;
|
|
18
|
+
class CircuitBreaker {
|
|
19
|
+
state = 'closed';
|
|
20
|
+
consecutiveFailures = 0;
|
|
21
|
+
lastFailureAt = null;
|
|
22
|
+
openedAt = null;
|
|
23
|
+
totalFailures = 0;
|
|
24
|
+
totalSuccesses = 0;
|
|
25
|
+
totalRejections = 0;
|
|
26
|
+
threshold;
|
|
27
|
+
cooldownMs;
|
|
28
|
+
constructor(config) {
|
|
29
|
+
this.threshold = Math.max(1, config.threshold);
|
|
30
|
+
this.cooldownMs = Math.max(1000, config.cooldownSeconds * 1000);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Check if a request should be allowed through.
|
|
34
|
+
* Returns true if allowed, false if circuit is open.
|
|
35
|
+
*/
|
|
36
|
+
allowRequest() {
|
|
37
|
+
if (this.state === 'closed')
|
|
38
|
+
return true;
|
|
39
|
+
if (this.state === 'open') {
|
|
40
|
+
// Check if cooldown has expired → transition to half_open
|
|
41
|
+
const now = Date.now();
|
|
42
|
+
if (this.openedAt && now - this.openedAt >= this.cooldownMs) {
|
|
43
|
+
this.state = 'half_open';
|
|
44
|
+
return true; // Allow one probe request
|
|
45
|
+
}
|
|
46
|
+
this.totalRejections++;
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
// half_open — allow the probe request (only one at a time)
|
|
50
|
+
// In a simple implementation, we allow all requests in half_open
|
|
51
|
+
// The first success/failure determines the next state.
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Record a successful response from the backend.
|
|
56
|
+
*/
|
|
57
|
+
recordSuccess() {
|
|
58
|
+
this.totalSuccesses++;
|
|
59
|
+
if (this.state === 'half_open') {
|
|
60
|
+
// Probe succeeded → close circuit
|
|
61
|
+
this.state = 'closed';
|
|
62
|
+
this.consecutiveFailures = 0;
|
|
63
|
+
this.openedAt = null;
|
|
64
|
+
}
|
|
65
|
+
else if (this.state === 'closed') {
|
|
66
|
+
this.consecutiveFailures = 0;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Record a failed response from the backend.
|
|
71
|
+
*/
|
|
72
|
+
recordFailure() {
|
|
73
|
+
this.totalFailures++;
|
|
74
|
+
this.consecutiveFailures++;
|
|
75
|
+
this.lastFailureAt = Date.now();
|
|
76
|
+
if (this.state === 'half_open') {
|
|
77
|
+
// Probe failed → re-open circuit
|
|
78
|
+
this.state = 'open';
|
|
79
|
+
this.openedAt = Date.now();
|
|
80
|
+
}
|
|
81
|
+
else if (this.state === 'closed' && this.consecutiveFailures >= this.threshold) {
|
|
82
|
+
this.state = 'open';
|
|
83
|
+
this.openedAt = Date.now();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get current circuit status.
|
|
88
|
+
*/
|
|
89
|
+
status() {
|
|
90
|
+
// Re-check if cooldown has expired (for accurate state reporting)
|
|
91
|
+
if (this.state === 'open' && this.openedAt && Date.now() - this.openedAt >= this.cooldownMs) {
|
|
92
|
+
this.state = 'half_open';
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
state: this.state,
|
|
96
|
+
consecutiveFailures: this.consecutiveFailures,
|
|
97
|
+
lastFailureAt: this.lastFailureAt ? new Date(this.lastFailureAt).toISOString() : null,
|
|
98
|
+
openedAt: this.openedAt ? new Date(this.openedAt).toISOString() : null,
|
|
99
|
+
totalFailures: this.totalFailures,
|
|
100
|
+
totalSuccesses: this.totalSuccesses,
|
|
101
|
+
totalRejections: this.totalRejections,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Reset the circuit breaker to closed state.
|
|
106
|
+
*/
|
|
107
|
+
reset() {
|
|
108
|
+
this.state = 'closed';
|
|
109
|
+
this.consecutiveFailures = 0;
|
|
110
|
+
this.openedAt = null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.CircuitBreaker = CircuitBreaker;
|
|
114
|
+
//# sourceMappingURL=circuit-breaker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circuit-breaker.js","sourceRoot":"","sources":["../src/circuit-breaker.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAqBH,MAAa,cAAc;IACjB,KAAK,GAAiB,QAAQ,CAAC;IAC/B,mBAAmB,GAAG,CAAC,CAAC;IACxB,aAAa,GAAkB,IAAI,CAAC;IACpC,QAAQ,GAAkB,IAAI,CAAC;IAC/B,aAAa,GAAG,CAAC,CAAC;IAClB,cAAc,GAAG,CAAC,CAAC;IACnB,eAAe,GAAG,CAAC,CAAC;IACX,SAAS,CAAS;IAClB,UAAU,CAAS;IAEpC,YAAY,MAA4B;QACtC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;QAC/C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IAClE,CAAC;IAED;;;OAGG;IACH,YAAY;QACV,IAAI,IAAI,CAAC,KAAK,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;QAEzC,IAAI,IAAI,CAAC,KAAK,KAAK,MAAM,EAAE,CAAC;YAC1B,0DAA0D;YAC1D,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAA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M,CAAC;YACpB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,kEAAkE;QAClE,IAAI,IAAI,CAAC,KAAK,KAAK,MAAM,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAC5F,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC;QAC3B,CAAC;QACD,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;YAC7C,aAAa,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI;YACrF,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI;YACtE,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,eAAe,EAAE,IAAI,CAAC,eAAe;SACtC,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC;QACtB,IAAI,CAAC,mBAAmB,GAAG,CAAC,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACvB,CAAC;CACF;AApGD,wCAoGC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compliance Export — Generate audit reports for SOC 2, GDPR, and HIPAA compliance.
|
|
3
|
+
*
|
|
4
|
+
* Formats audit events into structured compliance reports with:
|
|
5
|
+
* - Report metadata (period, generation time, framework, version)
|
|
6
|
+
* - Access control events (key management, auth failures)
|
|
7
|
+
* - Data processing events (tool calls, credit operations)
|
|
8
|
+
* - Configuration changes (config reload, webhook updates)
|
|
9
|
+
* - Summary statistics
|
|
10
|
+
*/
|
|
11
|
+
import { AuditLogger } from './audit';
|
|
12
|
+
export type ComplianceFramework = 'soc2' | 'gdpr' | 'hipaa';
|
|
13
|
+
export interface ComplianceReportMeta {
|
|
14
|
+
framework: ComplianceFramework;
|
|
15
|
+
generatedAt: string;
|
|
16
|
+
periodStart: string;
|
|
17
|
+
periodEnd: string;
|
|
18
|
+
serverVersion: string;
|
|
19
|
+
totalEvents: number;
|
|
20
|
+
}
|
|
21
|
+
export interface ComplianceSection {
|
|
22
|
+
title: string;
|
|
23
|
+
description: string;
|
|
24
|
+
events: ComplianceEvent[];
|
|
25
|
+
count: number;
|
|
26
|
+
}
|
|
27
|
+
export interface ComplianceEvent {
|
|
28
|
+
timestamp: string;
|
|
29
|
+
category: string;
|
|
30
|
+
action: string;
|
|
31
|
+
actor: string;
|
|
32
|
+
detail: string;
|
|
33
|
+
severity: 'info' | 'warning' | 'critical';
|
|
34
|
+
metadata?: Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
export interface ComplianceReport {
|
|
37
|
+
meta: ComplianceReportMeta;
|
|
38
|
+
sections: ComplianceSection[];
|
|
39
|
+
summary: ComplianceSummary;
|
|
40
|
+
}
|
|
41
|
+
export interface ComplianceSummary {
|
|
42
|
+
totalAccessControlEvents: number;
|
|
43
|
+
totalDataProcessingEvents: number;
|
|
44
|
+
totalConfigChangeEvents: number;
|
|
45
|
+
totalSecurityEvents: number;
|
|
46
|
+
authFailures: number;
|
|
47
|
+
keysCreated: number;
|
|
48
|
+
keysRevoked: number;
|
|
49
|
+
keysSuspended: number;
|
|
50
|
+
uniqueActors: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Generate a compliance report from audit log events.
|
|
54
|
+
*/
|
|
55
|
+
export declare function generateComplianceReport(auditLogger: AuditLogger, framework: ComplianceFramework, options: {
|
|
56
|
+
since?: string;
|
|
57
|
+
until?: string;
|
|
58
|
+
serverVersion: string;
|
|
59
|
+
}): ComplianceReport;
|
|
60
|
+
/**
|
|
61
|
+
* Convert a compliance report to CSV format.
|
|
62
|
+
*/
|
|
63
|
+
export declare function complianceReportToCsv(report: ComplianceReport): string;
|
|
64
|
+
//# sourceMappingURL=compliance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compliance.d.ts","sourceRoot":"","sources":["../src/compliance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAc,WAAW,EAAc,MAAM,SAAS,CAAC;AAI9D,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE5D,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,mBAAmB,CAAC;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,CAAC;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,oBAAoB,CAAC;IAC3B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