@kici-dev/orchestrator 0.0.0 → 0.1.2

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.
Files changed (342) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +1 -6
  3. package/dist/__test-helpers__/mock-db.d.ts +103 -0
  4. package/dist/__test-helpers__/mock-ws.d.ts +13 -0
  5. package/dist/agent/dispatcher.d.ts +231 -0
  6. package/dist/agent/ownership-tracker.d.ts +46 -0
  7. package/dist/agent/registry.d.ts +255 -0
  8. package/dist/agent/token-store.d.ts +96 -0
  9. package/dist/app.d.ts +234 -0
  10. package/dist/audit/access-log.d.ts +92 -0
  11. package/dist/audit/sampling-rate-limiter.d.ts +41 -0
  12. package/dist/cache/build-coordinator.d.ts +42 -0
  13. package/dist/cache/dep-cache.d.ts +51 -0
  14. package/dist/cache/index.d.ts +16 -0
  15. package/dist/cache/pending-builds.d.ts +14 -0
  16. package/dist/cache/pending-dynamics.d.ts +15 -0
  17. package/dist/cache/pending-inits.d.ts +19 -0
  18. package/dist/cache/pending-tracker.d.ts +65 -0
  19. package/dist/cache/source-cache.d.ts +30 -0
  20. package/dist/cli/api-client.d.ts +411 -0
  21. package/dist/cli/commands/access-log.d.ts +30 -0
  22. package/dist/cli/commands/agent-service/index.d.ts +15 -0
  23. package/dist/cli/commands/agent-service/install.d.ts +9 -0
  24. package/dist/cli/commands/agent-service/logs.d.ts +9 -0
  25. package/dist/cli/commands/agent-service/restart.d.ts +8 -0
  26. package/dist/cli/commands/agent-service/start.d.ts +8 -0
  27. package/dist/cli/commands/agent-service/status.d.ts +10 -0
  28. package/dist/cli/commands/agent-service/stop.d.ts +8 -0
  29. package/dist/cli/commands/agent-service/uninstall.d.ts +9 -0
  30. package/dist/cli/commands/agent-service/upgrade.d.ts +11 -0
  31. package/dist/cli/commands/agent.d.ts +10 -0
  32. package/dist/cli/commands/api-key.d.ts +12 -0
  33. package/dist/cli/commands/audit.d.ts +9 -0
  34. package/dist/cli/commands/backend.d.ts +17 -0
  35. package/dist/cli/commands/cold-store-impl.d.ts +101 -0
  36. package/dist/cli/commands/cold-store.d.ts +30 -0
  37. package/dist/cli/commands/config.d.ts +16 -0
  38. package/dist/cli/commands/db.d.ts +19 -0
  39. package/dist/cli/commands/debug-bundle.d.ts +16 -0
  40. package/dist/cli/commands/diagnose.d.ts +15 -0
  41. package/dist/cli/commands/environment.d.ts +24 -0
  42. package/dist/cli/commands/event-dlq.d.ts +19 -0
  43. package/dist/cli/commands/event-log.d.ts +27 -0
  44. package/dist/cli/commands/event.d.ts +4 -0
  45. package/dist/cli/commands/execution.d.ts +17 -0
  46. package/dist/cli/commands/inspect-bundle.d.ts +16 -0
  47. package/dist/cli/commands/maintenance.d.ts +4 -0
  48. package/dist/cli/commands/orchestrator-service/index.d.ts +12 -0
  49. package/dist/cli/commands/orchestrator-service/install.d.ts +10 -0
  50. package/dist/cli/commands/orchestrator-service/logs.d.ts +10 -0
  51. package/dist/cli/commands/orchestrator-service/restart.d.ts +8 -0
  52. package/dist/cli/commands/orchestrator-service/start.d.ts +8 -0
  53. package/dist/cli/commands/orchestrator-service/status.d.ts +10 -0
  54. package/dist/cli/commands/orchestrator-service/stop.d.ts +8 -0
  55. package/dist/cli/commands/orchestrator-service/uninstall.d.ts +9 -0
  56. package/dist/cli/commands/orchestrator-service/upgrade.d.ts +12 -0
  57. package/dist/cli/commands/org-settings.d.ts +17 -0
  58. package/dist/cli/commands/peer.d.ts +13 -0
  59. package/dist/cli/commands/queue.d.ts +16 -0
  60. package/dist/cli/commands/registration.d.ts +18 -0
  61. package/dist/cli/commands/rotate.d.ts +9 -0
  62. package/dist/cli/commands/runs.d.ts +34 -0
  63. package/dist/cli/commands/secret.d.ts +12 -0
  64. package/dist/cli/commands/shared/db.d.ts +16 -0
  65. package/dist/cli/commands/shared/versioned-upgrade.d.ts +38 -0
  66. package/dist/cli/commands/source.d.ts +24 -0
  67. package/dist/cli/commands/token.d.ts +10 -0
  68. package/dist/cli/commands/workflow.d.ts +31 -0
  69. package/dist/cli/join.d.ts +14 -0
  70. package/dist/cli/kici-admin.d.ts +13 -0
  71. package/dist/cli/lazy-deps/cache.d.ts +17 -0
  72. package/dist/cli/lazy-deps/downloader.d.ts +33 -0
  73. package/dist/cli/lazy-deps/registry.d.ts +43 -0
  74. package/dist/cli/service/compose.d.ts +25 -0
  75. package/dist/cli/service/index.d.ts +24 -0
  76. package/dist/cli/service/launchd.d.ts +34 -0
  77. package/dist/cli/service/platform-detect.d.ts +59 -0
  78. package/dist/cli/service/systemd.d.ts +41 -0
  79. package/dist/cli/service/types.d.ts +91 -0
  80. package/dist/cli/service/windows.d.ts +20 -0
  81. package/dist/cli/wizard/agent-wizard.d.ts +24 -0
  82. package/dist/cli/wizard/orchestrator-wizard.d.ts +38 -0
  83. package/dist/cli/wizard/prompts.d.ts +23 -0
  84. package/dist/cli.js +11435 -0
  85. package/dist/cluster/cluster-identity.d.ts +59 -0
  86. package/dist/cluster/coordinator.d.ts +204 -0
  87. package/dist/cluster/health-api.d.ts +30 -0
  88. package/dist/cluster/index.d.ts +24 -0
  89. package/dist/cluster/join-client.d.ts +75 -0
  90. package/dist/cluster/join-handler.d.ts +58 -0
  91. package/dist/cluster/join-token.d.ts +94 -0
  92. package/dist/cluster/orphan-recovery.d.ts +67 -0
  93. package/dist/cluster/peer-client.d.ts +190 -0
  94. package/dist/cluster/peer-credentials.d.ts +108 -0
  95. package/dist/cluster/peer-crypto.d.ts +57 -0
  96. package/dist/cluster/peer-handler.d.ts +97 -0
  97. package/dist/cluster/peer-registry.d.ts +186 -0
  98. package/dist/cluster/raft-state.d.ts +36 -0
  99. package/dist/cluster/raft.d.ts +140 -0
  100. package/dist/cold-store/load-access-log-range.d.ts +73 -0
  101. package/dist/cold-store/load-event-log-range.d.ts +62 -0
  102. package/dist/cold-store/load-secret-audit-log-range.d.ts +38 -0
  103. package/dist/cold-store/orchestrator-cold-store.d.ts +58 -0
  104. package/dist/cold-store/tables/access-log.d.ts +80 -0
  105. package/dist/cold-store/tables/event-log.d.ts +70 -0
  106. package/dist/cold-store/tables/execution-jobs.d.ts +63 -0
  107. package/dist/cold-store/tables/execution-runs.d.ts +81 -0
  108. package/dist/cold-store/tables/execution-steps.d.ts +65 -0
  109. package/dist/cold-store/tables/secret-audit-log.d.ts +77 -0
  110. package/dist/concurrency/dispatch-next-queued.d.ts +63 -0
  111. package/dist/concurrency/group-tracker.d.ts +51 -0
  112. package/dist/concurrency/index.d.ts +3 -0
  113. package/dist/concurrency/queue-manager.d.ts +68 -0
  114. package/dist/concurrency/waiters.d.ts +58 -0
  115. package/dist/config/encryption.d.ts +82 -0
  116. package/dist/config/env-overlay.d.ts +45 -0
  117. package/dist/config/index.d.ts +16 -0
  118. package/dist/config/loader.d.ts +26 -0
  119. package/dist/config/reload.d.ts +113 -0
  120. package/dist/config/resolver.d.ts +47 -0
  121. package/dist/config/schema.d.ts +210 -0
  122. package/dist/config/shared-store.d.ts +142 -0
  123. package/dist/config/types.d.ts +218 -0
  124. package/dist/config.d.ts +249 -0
  125. package/dist/cron/cron-scheduler.d.ts +78 -0
  126. package/dist/cron/cron-store.d.ts +38 -0
  127. package/dist/dashboard/handler.d.ts +243 -0
  128. package/dist/db/client.d.ts +13 -0
  129. package/dist/db/migration-provider.d.ts +9 -0
  130. package/dist/db/migrations/001_initial.d.ts +8 -0
  131. package/dist/db/migrations/002_config_versions_key_version.d.ts +16 -0
  132. package/dist/db/migrations/003_access_log.d.ts +26 -0
  133. package/dist/db/migrations/004_rename_bundle_to_source.d.ts +19 -0
  134. package/dist/db/migrations/005_cold_store_chunk_counter.d.ts +19 -0
  135. package/dist/db/migrations/006_runs_jobs_steps_archived_at.d.ts +38 -0
  136. package/dist/db/migrations/007_audit_logs_archived_at.d.ts +42 -0
  137. package/dist/db/migrations/008_event_log_archived_at.d.ts +40 -0
  138. package/dist/db/migrations/009_access_log_trigram.d.ts +15 -0
  139. package/dist/db/migrations/010_cold_store_chunks.d.ts +34 -0
  140. package/dist/db/migrations/011_drop_source_secrets_notify.d.ts +21 -0
  141. package/dist/db/migrations/012_peer_credentials_active_uniq.d.ts +28 -0
  142. package/dist/db/migrations/013_execution_log_bytes.d.ts +21 -0
  143. package/dist/db/migrations/014_kici_events_lease_retry.d.ts +36 -0
  144. package/dist/db/migrations/015_org_settings_customer_scoped.d.ts +30 -0
  145. package/dist/db/migrations/016_org_settings_allow_http_npm.d.ts +15 -0
  146. package/dist/db/migrations/017_org_id_widen.d.ts +4 -0
  147. package/dist/db/migrations/018_org_id_prefix_backfill.d.ts +4 -0
  148. package/dist/db/migrator.d.ts +32 -0
  149. package/dist/db/types.d.ts +1266 -0
  150. package/dist/diagnostics/bundle-reader.d.ts +48 -0
  151. package/dist/diagnostics/bundle-writer.d.ts +57 -0
  152. package/dist/diagnostics/checks/agents.d.ts +10 -0
  153. package/dist/diagnostics/checks/certs.d.ts +9 -0
  154. package/dist/diagnostics/checks/config.d.ts +10 -0
  155. package/dist/diagnostics/checks/db.d.ts +9 -0
  156. package/dist/diagnostics/checks/disk.d.ts +9 -0
  157. package/dist/diagnostics/checks/index.d.ts +17 -0
  158. package/dist/diagnostics/checks/ws.d.ts +9 -0
  159. package/dist/diagnostics/index.d.ts +13 -0
  160. package/dist/diagnostics/runner.d.ts +23 -0
  161. package/dist/diagnostics/types.d.ts +38 -0
  162. package/dist/entry-helpers.d.ts +93 -0
  163. package/dist/environments/binding-store.d.ts +27 -0
  164. package/dist/environments/environment-store.d.ts +74 -0
  165. package/dist/environments/held-runs.d.ts +64 -0
  166. package/dist/environments/index.d.ts +10 -0
  167. package/dist/environments/protection/branch-gate.d.ts +5 -0
  168. package/dist/environments/protection/concurrency-gate.d.ts +7 -0
  169. package/dist/environments/protection/pipeline.d.ts +18 -0
  170. package/dist/environments/protection/reviewer-gate.d.ts +7 -0
  171. package/dist/environments/protection/trust-gate.d.ts +7 -0
  172. package/dist/environments/protection/wait-timer-gate.d.ts +7 -0
  173. package/dist/environments/variable-store.d.ts +39 -0
  174. package/dist/events/circuit-breaker.d.ts +33 -0
  175. package/dist/events/event-emitter.d.ts +55 -0
  176. package/dist/events/event-retry-scanner.d.ts +52 -0
  177. package/dist/events/event-router.d.ts +183 -0
  178. package/dist/events/event-store.d.ts +157 -0
  179. package/dist/events/trust-store.d.ts +54 -0
  180. package/dist/events/types.d.ts +61 -0
  181. package/dist/helpers/ip-extraction.d.ts +29 -0
  182. package/dist/helpers/rate-limiter.d.ts +23 -0
  183. package/dist/index.d.ts +7 -0
  184. package/dist/index.js +772 -0
  185. package/dist/lockfile-cache.d.ts +39 -0
  186. package/dist/metrics/agent-metrics-aggregator.d.ts +116 -0
  187. package/dist/metrics/metrics-reporter.d.ts +40 -0
  188. package/dist/metrics/prometheus.d.ts +261 -0
  189. package/dist/metrics/scheduled-jobs.d.ts +20 -0
  190. package/dist/orchestrator-core.d.ts +193 -0
  191. package/dist/pipeline/dispatch-matched-workflow.d.ts +102 -0
  192. package/dist/pipeline/inline-eval.d.ts +28 -0
  193. package/dist/pipeline/install-secrets-resolver.d.ts +73 -0
  194. package/dist/pipeline/manual-schedule.d.ts +21 -0
  195. package/dist/pipeline/needs-scheduler.d.ts +85 -0
  196. package/dist/pipeline/process-webhook.d.ts +38 -0
  197. package/dist/pipeline/processor.d.ts +326 -0
  198. package/dist/pipeline/rerun.d.ts +79 -0
  199. package/dist/pipeline/test-pipeline.d.ts +110 -0
  200. package/dist/provider-registry.d.ts +122 -0
  201. package/dist/providers/generic/index.d.ts +23 -0
  202. package/dist/providers/generic/normalizer.d.ts +112 -0
  203. package/dist/providers/generic/verification.d.ts +47 -0
  204. package/dist/providers/github/auth.d.ts +60 -0
  205. package/dist/providers/github/changed-files.d.ts +51 -0
  206. package/dist/providers/github/check-status-poster.d.ts +35 -0
  207. package/dist/providers/github/contributor-resolver.d.ts +30 -0
  208. package/dist/providers/github/index.d.ts +20 -0
  209. package/dist/providers/github/lock-file.d.ts +32 -0
  210. package/dist/providers/github/normalizer.d.ts +103 -0
  211. package/dist/providers/github/repo-url.d.ts +35 -0
  212. package/dist/providers/internal/index.d.ts +32 -0
  213. package/dist/providers/internal/lock-file-fetcher.d.ts +34 -0
  214. package/dist/providers/internal/normalizer.d.ts +89 -0
  215. package/dist/providers/internal/repo-url-builder.d.ts +42 -0
  216. package/dist/providers/universal-git/changed-files.d.ts +42 -0
  217. package/dist/providers/universal-git/clone-token.d.ts +83 -0
  218. package/dist/providers/universal-git/config.d.ts +192 -0
  219. package/dist/providers/universal-git/index.d.ts +55 -0
  220. package/dist/providers/universal-git/lock-file.d.ts +71 -0
  221. package/dist/providers/universal-git/normalizer.d.ts +90 -0
  222. package/dist/providers/universal-git/repo-url.d.ts +50 -0
  223. package/dist/providers/universal-git/ssh-auth.d.ts +94 -0
  224. package/dist/queue/bootstrap.d.ts +50 -0
  225. package/dist/queue/cleanup.d.ts +41 -0
  226. package/dist/queue/depth-refresher.d.ts +65 -0
  227. package/dist/queue/job-queue.d.ts +343 -0
  228. package/dist/queue/scheduled-job.d.ts +91 -0
  229. package/dist/registration/extractor.d.ts +44 -0
  230. package/dist/registration/registration-index.d.ts +162 -0
  231. package/dist/registration/registration-store.d.ts +111 -0
  232. package/dist/reporting/check-run-summary.d.ts +102 -0
  233. package/dist/reporting/commit-status.d.ts +382 -0
  234. package/dist/reporting/execution-tracker.d.ts +538 -0
  235. package/dist/reporting/fs-log-storage.d.ts +41 -0
  236. package/dist/reporting/log-pull-handler.d.ts +35 -0
  237. package/dist/reporting/log-storage.d.ts +70 -0
  238. package/dist/reporting/log-writer.d.ts +45 -0
  239. package/dist/reporting/s3-log-storage.d.ts +42 -0
  240. package/dist/reporting/step-log-buffer.d.ts +57 -0
  241. package/dist/routes/admin-access-log.d.ts +34 -0
  242. package/dist/routes/admin-backends.d.ts +28 -0
  243. package/dist/routes/admin-config.d.ts +57 -0
  244. package/dist/routes/admin-db.d.ts +20 -0
  245. package/dist/routes/admin-environments.d.ts +42 -0
  246. package/dist/routes/admin-errors.d.ts +4 -0
  247. package/dist/routes/admin-event-dlq.d.ts +39 -0
  248. package/dist/routes/admin-event-log.d.ts +42 -0
  249. package/dist/routes/admin-events.d.ts +46 -0
  250. package/dist/routes/admin-maintenance.d.ts +22 -0
  251. package/dist/routes/admin-org-settings.d.ts +29 -0
  252. package/dist/routes/admin-queue-execution.d.ts +27 -0
  253. package/dist/routes/admin-registrations.d.ts +37 -0
  254. package/dist/routes/admin-runs.d.ts +57 -0
  255. package/dist/routes/admin-scheduled-jobs.d.ts +36 -0
  256. package/dist/routes/admin-sources.d.ts +18 -0
  257. package/dist/routes/admin.d.ts +103 -0
  258. package/dist/routes/capabilities.d.ts +24 -0
  259. package/dist/routes/diagnostics.d.ts +16 -0
  260. package/dist/routes/health.d.ts +20 -0
  261. package/dist/routes/test-trigger.d.ts +41 -0
  262. package/dist/routes/uploads.d.ts +38 -0
  263. package/dist/routes/webhooks.d.ts +36 -0
  264. package/dist/scaler/bare-metal-backend.d.ts +107 -0
  265. package/dist/scaler/config.d.ts +303 -0
  266. package/dist/scaler/container-backend.d.ts +125 -0
  267. package/dist/scaler/file-tail.d.ts +23 -0
  268. package/dist/scaler/firecracker-api.d.ts +100 -0
  269. package/dist/scaler/firecracker-backend.d.ts +263 -0
  270. package/dist/scaler/index.d.ts +24 -0
  271. package/dist/scaler/ip-allocator.d.ts +177 -0
  272. package/dist/scaler/label-matcher.d.ts +73 -0
  273. package/dist/scaler/log-forwarder.d.ts +54 -0
  274. package/dist/scaler/machine-ledger.d.ts +160 -0
  275. package/dist/scaler/manager.d.ts +338 -0
  276. package/dist/scaler/nftables.d.ts +85 -0
  277. package/dist/scaler/types.d.ts +388 -0
  278. package/dist/scaler/warm-pool.d.ts +81 -0
  279. package/dist/secrets/audit-logger.d.ts +65 -0
  280. package/dist/secrets/backend-health.d.ts +60 -0
  281. package/dist/secrets/backend-registry.d.ts +68 -0
  282. package/dist/secrets/backend-sync.d.ts +40 -0
  283. package/dist/secrets/cleanup.d.ts +40 -0
  284. package/dist/secrets/config.d.ts +51 -0
  285. package/dist/secrets/crypto.d.ts +49 -0
  286. package/dist/secrets/ephemeral-keys.d.ts +49 -0
  287. package/dist/secrets/index.d.ts +17 -0
  288. package/dist/secrets/pg-secret-store.d.ts +105 -0
  289. package/dist/secrets/rbac.d.ts +47 -0
  290. package/dist/secrets/secret-output-store.d.ts +46 -0
  291. package/dist/secrets/secret-resolver.d.ts +137 -0
  292. package/dist/secrets/source-credentials.d.ts +61 -0
  293. package/dist/secrets/token-manager.d.ts +63 -0
  294. package/dist/secrets/vault-secret-store.d.ts +85 -0
  295. package/dist/security/comment-handler.d.ts +67 -0
  296. package/dist/security/contributor-cache.d.ts +75 -0
  297. package/dist/security/global-workflow-policy.d.ts +72 -0
  298. package/dist/security/lock-source.d.ts +34 -0
  299. package/dist/security/trust-resolver.d.ts +108 -0
  300. package/dist/security/workflow-diff.d.ts +26 -0
  301. package/dist/server.d.ts +17 -0
  302. package/dist/server.js +48055 -0
  303. package/dist/sources/index.d.ts +10 -0
  304. package/dist/sources/source-manager.d.ts +63 -0
  305. package/dist/sources/source-store.d.ts +79 -0
  306. package/dist/sources/source-validator.d.ts +16 -0
  307. package/dist/stale-detector/stale-run-detector.d.ts +109 -0
  308. package/dist/standalone.d.ts +20 -0
  309. package/dist/standalone.js +41546 -0
  310. package/dist/storage/blob-routes.d.ts +20 -0
  311. package/dist/storage/filesystem.d.ts +60 -0
  312. package/dist/storage/index.d.ts +20 -0
  313. package/dist/storage/s3.d.ts +68 -0
  314. package/dist/storage/sign-url.d.ts +45 -0
  315. package/dist/storage/types.d.ts +98 -0
  316. package/dist/webhook/dedup.d.ts +44 -0
  317. package/dist/webhook/event-log.d.ts +83 -0
  318. package/dist/webhook/generic-sources.d.ts +169 -0
  319. package/dist/webhook/handler.d.ts +23 -0
  320. package/dist/webhook/relay-buffer.d.ts +96 -0
  321. package/dist/webhook/verify-inbound.d.ts +78 -0
  322. package/dist/worker/in-memory-execution-tracker.d.ts +94 -0
  323. package/dist/worker/in-memory-job-queue.d.ts +74 -0
  324. package/dist/worker/static-agent-token-store.d.ts +58 -0
  325. package/dist/worker/worker-status.d.ts +36 -0
  326. package/dist/worker-core.d.ts +74 -0
  327. package/dist/ws/agent-api-registry.d.ts +49 -0
  328. package/dist/ws/agent-handler.d.ts +176 -0
  329. package/dist/ws/agent-heartbeat.d.ts +45 -0
  330. package/dist/ws/dashboard-backends-handler.d.ts +51 -0
  331. package/dist/ws/dashboard-diagnostics-handler.d.ts +56 -0
  332. package/dist/ws/dashboard-env-handler.d.ts +107 -0
  333. package/dist/ws/dashboard-global-workflows-handler.d.ts +72 -0
  334. package/dist/ws/dashboard-registrations-handler.d.ts +84 -0
  335. package/dist/ws/event-buffer.d.ts +16 -0
  336. package/dist/ws/observer-handler.d.ts +42 -0
  337. package/dist/ws/observer-registry.d.ts +88 -0
  338. package/dist/ws/platform-client.d.ts +270 -0
  339. package/dist/ws/server-options.d.ts +15 -0
  340. package/package.json +87 -7
  341. package/sbom.spdx.json +14370 -0
  342. package/index.js +0 -3
@@ -0,0 +1,33 @@
1
+ import type { EventRouterConfig } from './types.js';
2
+ /**
3
+ * Circuit breaker for event loop detection and per-workflow rate limiting.
4
+ *
5
+ * Two-layer protection:
6
+ * 1. Chain depth: Rejects events exceeding configurable max chain depth.
7
+ * 2. Rate limiting: Sliding-window per-workflow rate limiter.
8
+ */
9
+ export declare class EventCircuitBreaker {
10
+ private readonly config;
11
+ private rateLimiter;
12
+ constructor(config: EventRouterConfig);
13
+ /**
14
+ * Check if the current chain depth is within limits.
15
+ */
16
+ checkChainDepth(currentDepth: number): {
17
+ allowed: boolean;
18
+ reason?: string;
19
+ };
20
+ /**
21
+ * Check if a workflow is within its per-minute rate limit.
22
+ * Uses a sliding window of 60 seconds.
23
+ */
24
+ checkRateLimit(workflowKey: string): {
25
+ allowed: boolean;
26
+ retryAfterMs?: number;
27
+ };
28
+ /**
29
+ * Clear all rate limit state (for testing).
30
+ */
31
+ reset(): void;
32
+ }
33
+ //# sourceMappingURL=circuit-breaker.d.ts.map
@@ -0,0 +1,55 @@
1
+ import type { EventRouter } from './event-router.js';
2
+ /**
3
+ * Input data for emitting a workflow_complete system event.
4
+ */
5
+ export interface WorkflowCompleteData {
6
+ routingKey: string;
7
+ repo: string;
8
+ workflowName: string;
9
+ runId: string;
10
+ status: string;
11
+ conclusion: string;
12
+ duration: number;
13
+ jobResults: Array<{
14
+ name: string;
15
+ status: string;
16
+ }>;
17
+ }
18
+ /**
19
+ * Input data for emitting a job_complete system event.
20
+ */
21
+ export interface JobCompleteData {
22
+ routingKey: string;
23
+ repo: string;
24
+ workflowName: string;
25
+ jobName: string;
26
+ runId: string;
27
+ jobId: string;
28
+ status: string;
29
+ duration: number;
30
+ stepResults: Array<{
31
+ name: string;
32
+ status: string;
33
+ }>;
34
+ }
35
+ /**
36
+ * EventEmitter automatically generates system events when workflows and jobs complete.
37
+ *
38
+ * System events are root-level (chainDepth: 0) since they originate from the
39
+ * orchestrator, not from a chain of events.
40
+ */
41
+ export declare class EventEmitter {
42
+ private readonly router;
43
+ constructor(router: EventRouter);
44
+ /**
45
+ * Emit a __workflow_complete system event with rich metadata.
46
+ * Returns the event ID as delivery receipt.
47
+ */
48
+ emitWorkflowComplete(data: WorkflowCompleteData): Promise<string>;
49
+ /**
50
+ * Emit a __job_complete system event with rich metadata.
51
+ * Returns the event ID as delivery receipt.
52
+ */
53
+ emitJobComplete(data: JobCompleteData): Promise<string>;
54
+ }
55
+ //# sourceMappingURL=event-emitter.d.ts.map
@@ -0,0 +1,52 @@
1
+ import { type Kysely } from 'kysely';
2
+ import type { Database } from '../db/types.js';
3
+ import type { EventStore } from './event-store.js';
4
+ import type { EventRouterConfig } from './types.js';
5
+ interface EventRetryScannerOptions {
6
+ db: Kysely<Database>;
7
+ eventStore: EventStore;
8
+ config: EventRouterConfig;
9
+ }
10
+ /**
11
+ * Leader-only periodic scanner that closes two gaps in event delivery:
12
+ *
13
+ * 1. Retries: events whose `next_retry_at <= NOW()` are re-published via
14
+ * `pg_notify('kici_event_channel', id)` so any healthy orchestrator
15
+ * picks them up via the normal `LISTEN/NOTIFY` path. The receiver's
16
+ * `tryLeaseForProcessing` ensures only one node actually dispatches.
17
+ *
18
+ * 2. Lease expiry: events whose `claimed_at` is older than
19
+ * `leaseDurationMs` belong to a node that crashed (or hung) before
20
+ * finalising the dispatch. The scanner releases the lease (clears
21
+ * `claimed_at`, sets `next_retry_at = NOW()`) and re-publishes
22
+ * `pg_notify`. This is the visible signal — via
23
+ * `kici_orch_event_lease_expirations_total` — that a node died
24
+ * mid-dispatch.
25
+ *
26
+ * The scanner also refreshes the `kici_orch_event_dlq_depth` gauge so
27
+ * operators can alert on DLQ growth.
28
+ *
29
+ * Modeled on `CronScheduler`: leader-only, started/stopped via Raft
30
+ * leadership callbacks, single timer cleared on `stop()`.
31
+ */
32
+ export declare class EventRetryScanner {
33
+ private readonly db;
34
+ private readonly eventStore;
35
+ private readonly config;
36
+ private timer;
37
+ private isLeader;
38
+ constructor(options: EventRetryScannerOptions);
39
+ onBecomeLeader(): void;
40
+ onLoseLeadership(): void;
41
+ stop(): void;
42
+ /**
43
+ * One scanner tick. Public for tests; not on the hot path otherwise.
44
+ */
45
+ tick(): Promise<void>;
46
+ private processExpiredLeases;
47
+ private processDueRetries;
48
+ private refreshDlqDepth;
49
+ private publishNotify;
50
+ }
51
+ export {};
52
+ //# sourceMappingURL=event-retry-scanner.d.ts.map
@@ -0,0 +1,183 @@
1
+ import type pg from 'pg';
2
+ import { type Kysely, type Transaction } from 'kysely';
3
+ import type { Database } from '../db/types.js';
4
+ import type { LockFile, WorkflowDecision } from '@kici-dev/engine';
5
+ import type { EventStore } from './event-store.js';
6
+ import type { EventCircuitBreaker } from './circuit-breaker.js';
7
+ import type { TrustStore } from './trust-store.js';
8
+ import type { RegistrationIndex } from '../registration/registration-index.js';
9
+ import type { EventRouterConfig, StoredEvent } from './types.js';
10
+ /**
11
+ * Input for emitting an internal event.
12
+ */
13
+ export interface EmitEventInput {
14
+ eventName: string;
15
+ payload: Record<string, unknown>;
16
+ sourceRepo?: string;
17
+ sourceRoutingKey?: string;
18
+ sourceRunId?: string;
19
+ sourceJobId?: string;
20
+ /** Optional cross-repo targeting: deliver only to registrations matching these repos */
21
+ target?: {
22
+ repos?: string[];
23
+ };
24
+ chainDepth?: number;
25
+ }
26
+ /**
27
+ * Context about the registration that matched an event.
28
+ */
29
+ export interface EventMatchContext {
30
+ /** Routing key (e.g., "github:42") for provider resolution */
31
+ routingKey: string;
32
+ /** Repository identifier (e.g., "owner/repo") */
33
+ repoIdentifier: string;
34
+ /** Provider-specific credentials captured at registration time */
35
+ providerContext: Record<string, unknown>;
36
+ }
37
+ export interface EventRouterOptions {
38
+ db: Kysely<Database>;
39
+ pool: pg.Pool;
40
+ eventStore: EventStore;
41
+ circuitBreaker: EventCircuitBreaker;
42
+ trustStore: TrustStore;
43
+ config: EventRouterConfig;
44
+ onEventMatched: (event: StoredEvent, lockFile: LockFile, matchedWorkflows: WorkflowDecision[], context?: EventMatchContext) => Promise<void>;
45
+ /** Registration index for DB-backed subscription matching. Events match against persistent registrations. */
46
+ registrationIndex: RegistrationIndex;
47
+ /** Stable identifier for this orchestrator process — written into `kici_events.claimed_by` for diagnostics. */
48
+ nodeId: string;
49
+ }
50
+ /**
51
+ * EventRouter delivers internal events to matching workflows via PostgreSQL LISTEN/NOTIFY.
52
+ *
53
+ * Follows the WebhookSecretManager pattern: raw pg.PoolClient for LISTEN,
54
+ * Kysely for queries.
55
+ *
56
+ * On start, performs a catch-up scan for events missed during downtime.
57
+ * On notification, leases the event from DB, matches against registered
58
+ * workflows via the RegistrationIndex, and calls onEventMatched for each
59
+ * match. Failures schedule a retry via `recordDispatchFailure`; events that
60
+ * exhaust `maxDispatchAttempts` are moved to the DLQ via `markDlq`.
61
+ */
62
+ export declare class EventRouter {
63
+ private readonly db;
64
+ private readonly pool;
65
+ private readonly eventStore;
66
+ private readonly circuitBreaker;
67
+ private readonly trustStore;
68
+ private readonly config;
69
+ private readonly onEventMatched;
70
+ private readonly registrationIndex;
71
+ private readonly nodeId;
72
+ private client;
73
+ private lastProcessedEventId;
74
+ constructor(options: EventRouterOptions);
75
+ /**
76
+ * Start listening for events via PostgreSQL LISTEN/NOTIFY.
77
+ * Runs catch-up on start to process events missed during downtime.
78
+ */
79
+ start(): Promise<void>;
80
+ /**
81
+ * Stop listening and release the dedicated pg client.
82
+ */
83
+ stop(): Promise<void>;
84
+ /**
85
+ * Emit an internal event using the default DB handle.
86
+ *
87
+ * Wraps `emitInTx` in its own transaction. Callers that need to combine
88
+ * the emit with other transactional work (cron-fire being the canonical
89
+ * case) should call `emitInTx` directly with their own tx so all writes
90
+ * commit or roll back together.
91
+ */
92
+ emit(event: EmitEventInput): Promise<string>;
93
+ /**
94
+ * Emit an internal event inside a caller-provided transaction.
95
+ *
96
+ * Circuit-breaker checks (chain depth + rate limit) run BEFORE the
97
+ * transaction so they fail fast without burning DB roundtrips. The
98
+ * `kici_events` insert and the `pg_notify` are issued on the supplied
99
+ * `tx` so they only become visible (and the notification is only
100
+ * delivered) on commit. Postgres queues NOTIFYs issued inside a
101
+ * transaction and releases them at COMMIT; if the tx rolls back, no
102
+ * listener is woken — exactly what we need to make cron-fire atomic.
103
+ */
104
+ emitInTx(event: EmitEventInput, tx: Transaction<Database>): Promise<string>;
105
+ /**
106
+ * Handle a LISTEN/NOTIFY notification for a new event.
107
+ *
108
+ * Lease-based dispatch (replaces the previous "flip processed=true upfront"
109
+ * pattern that silently lost events when dispatch threw):
110
+ *
111
+ * 1. Take a dispatch lease (claimed_at + claimed_by, attempts++).
112
+ * Fails fast if the event is already processed, in DLQ, or held by a
113
+ * fresh lease on another node.
114
+ * 2. Run dispatch. On success: markProcessed (clears lease, processed=true).
115
+ * 3. On failure: either schedule a retry (recordDispatchFailure → leader
116
+ * scanner re-publishes pg_notify when next_retry_at elapses) or move
117
+ * to the DLQ (markDlq) when attempts exceed maxDispatchAttempts.
118
+ *
119
+ * If the dispatching node crashes between lease and finalisation, the
120
+ * leader-only retry scanner releases the lease after leaseDurationMs and
121
+ * re-publishes pg_notify so a healthy node can re-dispatch.
122
+ */
123
+ private onNotification;
124
+ /**
125
+ * Run dispatch for a leased event and record the outcome (processed,
126
+ * retry, or DLQ). Used by both the live notification handler and the
127
+ * catch-up loop so the failure semantics stay identical.
128
+ */
129
+ private dispatchAndRecord;
130
+ /**
131
+ * Match an event against all registered workflows and dispatch matches.
132
+ *
133
+ * Looks up registrations by trigger type via the RegistrationIndex,
134
+ * builds per-registration lock files, and runs trigger matching against them.
135
+ *
136
+ * Errors propagate so the lease wrapper (`dispatchAndRecord`) can either
137
+ * schedule a retry or move the event to the DLQ. Swallowing the error
138
+ * here would silently lose the event — exactly the failure mode the
139
+ * lease pattern fixes.
140
+ */
141
+ private processSubscriptions;
142
+ /**
143
+ * Map a stored event to a trigger type string for RegistrationIndex lookup.
144
+ *
145
+ * System events (__workflow_complete, __job_complete) map to their type without __ prefix.
146
+ * Custom events map to 'kici_event'.
147
+ */
148
+ private eventToTriggerType;
149
+ /**
150
+ * Build a SimulatedEvent from a StoredEvent for trigger matching.
151
+ *
152
+ * System events (__workflow_complete, __job_complete) map their type by
153
+ * stripping the __ prefix and pass the payload through directly (the
154
+ * matcher checks payload.workflowName, payload.status, etc.).
155
+ *
156
+ * Custom events use type 'kici_event'. The matcher reads eventName and
157
+ * the user payload from event.payload.eventName / event.payload.payload,
158
+ * so we wrap the stored event's metadata into the expected structure.
159
+ */
160
+ private buildSimulatedEvent;
161
+ /**
162
+ * Catch-up: process unprocessed events missed during downtime.
163
+ *
164
+ * Uses lease-based dispatch identical to the live path, so a catch-up
165
+ * dispatch failure schedules a retry via the leader-only scanner instead
166
+ * of being silently dropped.
167
+ */
168
+ private catchUp;
169
+ }
170
+ /**
171
+ * Compute the next retry timestamp using exponential backoff with full
172
+ * jitter. `attempts` is the count AFTER the most recent failed attempt.
173
+ *
174
+ * target = min(maxBackoffMs, baseBackoffMs * 2^(attempts - 1))
175
+ * actual = random in [0, target]
176
+ *
177
+ * Full jitter (vs. equal jitter or no jitter) gives the best balance
178
+ * between worst-case retry concentration and average latency, per the AWS
179
+ * "Exponential backoff and jitter" article. baseBackoffMs and
180
+ * maxBackoffMs come from EventRouterConfig so tests can shrink them.
181
+ */
182
+ export declare function computeNextRetryAt(attempts: number, baseBackoffMs: number, maxBackoffMs: number, now?: () => number): Date;
183
+ //# sourceMappingURL=event-router.d.ts.map
@@ -0,0 +1,157 @@
1
+ import { type Kysely, type Transaction } from 'kysely';
2
+ import type { Database } from '../db/types.js';
3
+ import type { DlqReason, EventRouterConfig, StoredEvent } from './types.js';
4
+ /** Either a Kysely DB handle or an active transaction. */
5
+ export type DbExecutor = Kysely<Database> | Transaction<Database>;
6
+ /**
7
+ * Input shape for writing a new event. Excludes columns the DB fills in
8
+ * itself (id, processed, created_at, attempts, claimed_*, last_error,
9
+ * next_retry_at, dlq_*).
10
+ */
11
+ export interface NewEventInput {
12
+ eventName: string;
13
+ payload: Record<string, unknown>;
14
+ sourceRepo?: string;
15
+ sourceRoutingKey?: string;
16
+ sourceRunId?: string;
17
+ sourceJobId?: string;
18
+ targetRepos?: string[];
19
+ chainDepth: number;
20
+ expiresAt: Date;
21
+ }
22
+ /**
23
+ * Persists and queries internal events (system + custom).
24
+ *
25
+ * Provides:
26
+ * - TTL-based cleanup for expired non-DLQ events.
27
+ * - Lease-based dispatch claim with bounded retries (replaces the prior
28
+ * "flip processed=true upfront" pattern that silently lost events when
29
+ * dispatch threw).
30
+ * - DLQ helpers for surfacing events that exhausted retries.
31
+ */
32
+ export declare class EventStore {
33
+ private readonly db;
34
+ private readonly config;
35
+ private cleanupTimer;
36
+ constructor(db: Kysely<Database>, config: EventRouterConfig);
37
+ /**
38
+ * Expose the underlying Kysely handle for callers that need to issue
39
+ * `pg_notify` outside of EventStore (e.g. the admin DLQ retry route, which
40
+ * re-publishes after `resetFromDlq` so a healthy node picks the event up
41
+ * before the next retry-scanner tick).
42
+ */
43
+ getDb(): Kysely<Database>;
44
+ /**
45
+ * Write a new event to the store using the default DB handle.
46
+ * Computes expires_at from the configured TTL.
47
+ * Returns the generated event ID.
48
+ */
49
+ write(event: NewEventInput): Promise<string>;
50
+ /**
51
+ * Write a new event using a caller-provided executor (typically a Kysely
52
+ * Transaction). Used by `EventRouter.emitInTx` to atomically combine the
53
+ * insert with other transactional work (e.g. cron `tryClaimFire`).
54
+ */
55
+ writeWith(event: NewEventInput, executor: DbExecutor): Promise<string>;
56
+ /**
57
+ * Retrieve a single event by ID.
58
+ */
59
+ getById(id: string): Promise<StoredEvent | null>;
60
+ /**
61
+ * Get unprocessed events for catch-up on reconnect.
62
+ * If sinceId is null, returns all unprocessed events.
63
+ * Ordered by created_at ASC. Excludes DLQ rows.
64
+ */
65
+ getUnprocessedSince(sinceId: string | null, limit?: number): Promise<StoredEvent[]>;
66
+ /**
67
+ * Mark an event as fully processed. Called after a successful dispatch.
68
+ * Clears any prior lease so the row is unambiguously terminal.
69
+ */
70
+ markProcessed(id: string): Promise<void>;
71
+ /**
72
+ * Atomically take a dispatch lease on an event. Replaces the previous
73
+ * "flip processed=true upfront" pattern that silently lost events when
74
+ * dispatch threw after the flip.
75
+ *
76
+ * The UPDATE succeeds when:
77
+ * - the event is not yet processed and not in DLQ, AND
78
+ * - either no lease is held, OR the existing lease has expired.
79
+ *
80
+ * On success: sets `claimed_at = NOW()`, `claimed_by = $leaseHolder`,
81
+ * increments `attempts`. The caller must subsequently call `markProcessed`
82
+ * (success), `recordDispatchFailure` (failure with retry), or `markDlq`
83
+ * (terminal failure) — otherwise the lease times out after
84
+ * `leaseDurationMs` and the leader-only retry scanner releases it.
85
+ *
86
+ * Returns the leased event row, or null if the event was already
87
+ * processed/leased/DLQ'd.
88
+ */
89
+ tryLeaseForProcessing(id: string, leaseHolder: string): Promise<StoredEvent | null>;
90
+ /**
91
+ * Record a failed dispatch attempt. Releases the lease, stores the
92
+ * (truncated) error, and schedules the next retry. The leader-only
93
+ * retry scanner will re-publish `pg_notify` for this event when
94
+ * `next_retry_at <= NOW()`.
95
+ */
96
+ recordDispatchFailure(id: string, errorMessage: string, nextRetryAt: Date): Promise<void>;
97
+ /**
98
+ * Mark an event as DLQ. Sets `processed=true` so it stops being eligible
99
+ * for retry, records `dlq_at` + `dlq_reason`, and preserves `last_error`
100
+ * (overwritten if a fresh error message is provided).
101
+ */
102
+ markDlq(id: string, reason: DlqReason, errorMessage?: string): Promise<void>;
103
+ /**
104
+ * Find events whose `next_retry_at` is due. The leader-only retry scanner
105
+ * uses this to know which events to re-publish via `pg_notify`.
106
+ */
107
+ findEventsDueForRetry(limit: number): Promise<StoredEvent[]>;
108
+ /**
109
+ * Find events whose lease has expired. The leader-only scanner releases
110
+ * these (clears `claimed_at` + sets `next_retry_at = NOW()`) and then
111
+ * re-publishes `pg_notify` so a healthy node picks them up.
112
+ */
113
+ findExpiredLeases(limit: number): Promise<StoredEvent[]>;
114
+ /**
115
+ * Release an expired lease so the event is once again eligible for
116
+ * `tryLeaseForProcessing`. Used by the retry scanner together with a
117
+ * `pg_notify` re-publication.
118
+ */
119
+ releaseExpiredLease(id: string): Promise<void>;
120
+ /**
121
+ * List events currently in the DLQ. Most recent first. Used by the
122
+ * dashboard admin DLQ page.
123
+ */
124
+ listDlq(limit: number, beforeDlqAt?: Date): Promise<StoredEvent[]>;
125
+ /**
126
+ * Count events currently in the DLQ. Used by the dashboard summary row
127
+ * and the `kici_orch_event_dlq_depth` gauge.
128
+ */
129
+ countDlq(): Promise<number>;
130
+ /**
131
+ * Reset a DLQ event so it gets retried on the next scanner tick. Used by
132
+ * the dashboard "Retry" action.
133
+ */
134
+ resetFromDlq(id: string): Promise<boolean>;
135
+ /**
136
+ * Permanently delete a DLQ event. Used by the dashboard "Discard" action.
137
+ */
138
+ deleteDlq(id: string): Promise<boolean>;
139
+ /**
140
+ * Delete expired events. Returns the count of deleted rows. DLQ rows are
141
+ * preserved so operators have time to triage them.
142
+ */
143
+ cleanup(): Promise<number>;
144
+ /**
145
+ * Start periodic cleanup using setInterval.
146
+ */
147
+ startCleanupTimer(): void;
148
+ /**
149
+ * Stop periodic cleanup.
150
+ */
151
+ stopCleanupTimer(): void;
152
+ /**
153
+ * Convert a DB row to a StoredEvent.
154
+ */
155
+ private rowToStoredEvent;
156
+ }
157
+ //# sourceMappingURL=event-store.d.ts.map
@@ -0,0 +1,54 @@
1
+ import { type Kysely } from 'kysely';
2
+ import type { Database } from '../db/types.js';
3
+ /**
4
+ * Trust entry representing a cross-repo trust relationship.
5
+ */
6
+ interface TrustEntry {
7
+ id: string;
8
+ sourceRepo: string;
9
+ sourceRoutingKey: string;
10
+ targetRepo: string;
11
+ targetRoutingKey: string;
12
+ allowedEvents: string[] | null;
13
+ enabled: boolean;
14
+ }
15
+ /**
16
+ * TrustStore enforces bidirectional trust for cross-repo event delivery.
17
+ *
18
+ * Same-repo events (same routing key) are always trusted without a DB lookup.
19
+ * Cross-repo events require an explicit enabled row in the cross_repo_trust table.
20
+ * Glob-based event filtering is supported via the allowed_events column.
21
+ */
22
+ export declare class TrustStore {
23
+ private readonly db;
24
+ constructor(db: Kysely<Database>);
25
+ /**
26
+ * Check whether event delivery from source to target is trusted.
27
+ *
28
+ * Same-routing-key events bypass the DB lookup entirely.
29
+ * Cross-repo events require an enabled row with matching event name.
30
+ */
31
+ isTrusted(sourceRepo: string, sourceRoutingKey: string, targetRepo: string, targetRoutingKey: string, eventName: string): Promise<boolean>;
32
+ /**
33
+ * Add a trust relationship between source and target.
34
+ * Uses ON CONFLICT DO NOTHING for idempotent inserts.
35
+ * Returns the trust entry ID.
36
+ */
37
+ addTrust(source: {
38
+ repo: string;
39
+ routingKey: string;
40
+ }, target: {
41
+ repo: string;
42
+ routingKey: string;
43
+ }, allowedEvents?: string[]): Promise<string>;
44
+ /**
45
+ * Remove a trust relationship by ID.
46
+ */
47
+ removeTrust(id: string): Promise<void>;
48
+ /**
49
+ * List all trust relationships for a routing key (as source or target).
50
+ */
51
+ listTrust(routingKey: string): Promise<TrustEntry[]>;
52
+ }
53
+ export {};
54
+ //# sourceMappingURL=trust-store.d.ts.map
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Event routing configuration and types.
3
+ */
4
+ /**
5
+ * Configuration for the event routing system.
6
+ */
7
+ export interface EventRouterConfig {
8
+ /** Maximum allowed chain depth before circuit breaker trips (default: 10) */
9
+ maxChainDepth: number;
10
+ /** Maximum event emissions per workflow per minute (default: 100) */
11
+ rateLimitPerWorkflowPerMinute: number;
12
+ /** TTL for persisted events in seconds (default: 604800 = 7 days) */
13
+ eventTtlSeconds: number;
14
+ /** Interval between cleanup runs in milliseconds (default: 3600000 = 1 hour) */
15
+ cleanupIntervalMs: number;
16
+ /** Max dispatch attempts before an event is moved to the DLQ (default: 5) */
17
+ maxDispatchAttempts: number;
18
+ /** How long a dispatch lease is valid before another node may steal it (default: 60_000) */
19
+ leaseDurationMs: number;
20
+ /** Base backoff for exponential retry, with full jitter (default: 5_000) */
21
+ retryBaseBackoffMs: number;
22
+ /** Maximum backoff cap (default: 300_000 = 5 min) */
23
+ retryMaxBackoffMs: number;
24
+ /** Interval at which the leader-only retry scanner ticks (default: 10_000) */
25
+ retryScanIntervalMs: number;
26
+ }
27
+ /**
28
+ * Reason an event landed in the DLQ.
29
+ */
30
+ export type DlqReason = 'exhausted_retries' | 'non_retryable';
31
+ /**
32
+ * A stored internal event (matches DB row shape but with JS types).
33
+ */
34
+ export interface StoredEvent {
35
+ id: string;
36
+ eventName: string;
37
+ payload: Record<string, unknown>;
38
+ sourceRepo?: string;
39
+ sourceRoutingKey?: string;
40
+ sourceRunId?: string;
41
+ sourceJobId?: string;
42
+ /** Optional target repos for cross-repo event targeting */
43
+ targetRepos?: string[];
44
+ chainDepth: number;
45
+ processed: boolean;
46
+ createdAt: Date;
47
+ expiresAt: Date;
48
+ /** Lease + retry + DLQ fields (added by migration 014) */
49
+ claimedAt: Date | null;
50
+ claimedBy: string | null;
51
+ attempts: number;
52
+ lastError: string | null;
53
+ nextRetryAt: Date | null;
54
+ dlqAt: Date | null;
55
+ dlqReason: DlqReason | null;
56
+ }
57
+ /**
58
+ * Default event router configuration.
59
+ */
60
+ export declare const DEFAULT_EVENT_ROUTER_CONFIG: EventRouterConfig;
61
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Shared IP extraction helper with trusted proxy + CIDR support.
3
+ *
4
+ * Used by app.ts to extract the real client IP from Hono context,
5
+ * respecting proxy headers only when the direct connection comes
6
+ * from a configured trusted proxy.
7
+ */
8
+ import type { Context } from 'hono';
9
+ import type { ConnInfo } from 'hono/conninfo';
10
+ /**
11
+ * Normalize an IP address by stripping the IPv6-mapped IPv4 prefix.
12
+ * E.g., '::ffff:127.0.0.1' -> '127.0.0.1'
13
+ */
14
+ export declare function normalizeIp(ip: string): string;
15
+ /**
16
+ * Check if a socket IP is a trusted proxy.
17
+ * Supports exact IP matches and CIDR ranges.
18
+ * IPv6-mapped IPv4 addresses are normalized before comparison.
19
+ */
20
+ export declare function isTrustedProxy(socketIp: string, trustedProxies: string[]): boolean;
21
+ /**
22
+ * Extract the real remote IP from a Hono request context.
23
+ *
24
+ * - If the direct socket is a trusted proxy, reads X-Real-IP or X-Forwarded-For
25
+ * - Otherwise, returns the socket IP directly (ignoring proxy headers)
26
+ * - Returns 'unknown' if socket address is not available
27
+ */
28
+ export declare function extractRemoteIp(c: Context, connInfo: ConnInfo, trustedProxies: string[]): string;
29
+ //# sourceMappingURL=ip-extraction.d.ts.map
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Sliding-window rate limiter.
3
+ *
4
+ * Tracks timestamps of recent events per key and rejects new events
5
+ * once the count within the window exceeds the configured maximum.
6
+ */
7
+ export declare class SlidingWindowRateLimiter {
8
+ private readonly maxPerWindow;
9
+ private readonly windowMs;
10
+ private state;
11
+ constructor(maxPerWindow: number, windowMs?: number);
12
+ /**
13
+ * Check if a new event is allowed for the given key.
14
+ * @param key - The rate limit bucket key.
15
+ * @param maxOverride - Per-call limit override (uses constructor default if omitted).
16
+ */
17
+ check(key: string, maxOverride?: number): {
18
+ allowed: boolean;
19
+ retryAfterMs?: number;
20
+ };
21
+ reset(): void;
22
+ }
23
+ //# sourceMappingURL=rate-limiter.d.ts.map
@@ -0,0 +1,7 @@
1
+ export type { CacheStorage, CacheStorageConfig, CacheMetadata } from './storage/types.js';
2
+ export { S3CacheStorage, type S3CacheStorageOptions } from './storage/s3.js';
3
+ export { createCacheStorage } from './storage/index.js';
4
+ export { SourceCache } from './cache/source-cache.js';
5
+ export { DepCache } from './cache/dep-cache.js';
6
+ export { PeerCredentialStore, createPeerCredentialStoreFromUrl, type PeerCredential, } from './cluster/peer-credentials.js';
7
+ //# sourceMappingURL=index.d.ts.map