@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,40 @@
1
+ import type { Logger } from '@kici-dev/shared';
2
+ import type { BackendRegistry } from './backend-registry.js';
3
+ /**
4
+ * Manages scope discovery and sync for all registered secret backends.
5
+ *
6
+ * On each sync cycle, lists scopes from each backend's store, applies
7
+ * the scope filter, and updates the registry with the discovered count.
8
+ */
9
+ export declare class BackendSyncManager {
10
+ private readonly registry;
11
+ private readonly logger;
12
+ private readonly intervalHandles;
13
+ constructor(registry: BackendRegistry, logger: Logger);
14
+ /**
15
+ * Sync a single backend by name. Discovers scopes via listing,
16
+ * applies the scope filter, and updates the registry.
17
+ */
18
+ syncBackend(name: string): Promise<{
19
+ scopeCount: number;
20
+ error?: string;
21
+ }>;
22
+ /**
23
+ * Sync all enabled backends in parallel via Promise.allSettled.
24
+ */
25
+ syncAllBackends(): Promise<Array<{
26
+ name: string;
27
+ scopeCount: number;
28
+ error?: string;
29
+ }>>;
30
+ /**
31
+ * Start periodic sync for each enabled backend at its configured interval.
32
+ */
33
+ startPeriodicSync(): void;
34
+ private startPeriodicSyncAsync;
35
+ /**
36
+ * Stop all periodic sync intervals.
37
+ */
38
+ stopPeriodicSync(): void;
39
+ }
40
+ //# sourceMappingURL=backend-sync.d.ts.map
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Periodic cleanup of orphaned ephemeral keys and secret outputs.
3
+ *
4
+ * Runs on a configurable interval (default: 1 hour) and deletes rows
5
+ * from run_ephemeral_keys and run_secret_outputs older than a configurable
6
+ * threshold (default: 24 hours). This catches data from crashed or
7
+ * abandoned runs whose normal cleanup never fired.
8
+ */
9
+ import type { Kysely } from 'kysely';
10
+ import type { Database } from '../db/types.js';
11
+ export interface SecretCleanupDeps {
12
+ db: Kysely<Database>;
13
+ /** Max age in hours before rows are considered orphaned. Default: 24 */
14
+ maxAgeHours?: number;
15
+ /** Optional logger for cleanup messages */
16
+ logger?: {
17
+ info(msg: string, meta?: Record<string, unknown>): void;
18
+ warn(msg: string, meta?: Record<string, unknown>): void;
19
+ };
20
+ }
21
+ /**
22
+ * Delete orphaned ephemeral keys and secret outputs older than maxAgeHours.
23
+ *
24
+ * @returns Count of deleted rows from each table
25
+ */
26
+ export declare function cleanupOrphanedSecrets(db: Kysely<Database>, maxAgeHours?: number): Promise<{
27
+ keysDeleted: number;
28
+ outputsDeleted: number;
29
+ }>;
30
+ /**
31
+ * Build a per-tick handler for the orphan-secret-cleanup scheduled job.
32
+ *
33
+ * The cadence and the periodic wrapper itself live in
34
+ * `packages/orchestrator/src/queue/scheduled-job.ts` — this factory
35
+ * just produces the tick function. Success is logged only when rows
36
+ * were actually deleted to keep the hourly log line noise-free on an
37
+ * idle orchestrator.
38
+ */
39
+ export declare function createOrphanSecretCleanupHandler(deps: SecretCleanupDeps): () => Promise<void>;
40
+ //# sourceMappingURL=cleanup.d.ts.map
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Secret store configuration.
3
+ */
4
+ export interface SecretStoreConfig {
5
+ /** 32-byte AES-256 encryption key. */
6
+ masterKey: Buffer;
7
+ /** Key version for rotation tracking. Default 1. */
8
+ keyVersion: number;
9
+ /** Path to key file, if used. */
10
+ keyFilePath: string | undefined;
11
+ /** Previous master key for dual-key rotation. */
12
+ oldMasterKey?: Buffer;
13
+ }
14
+ /**
15
+ * Load the master encryption key from environment or file.
16
+ *
17
+ * Priority:
18
+ * 1. Environment variable (envKey, defaults to KICI_SECRET_KEY)
19
+ * 2. Key file (keyFilePath)
20
+ *
21
+ * @param envKey - Environment variable name to read. Defaults to KICI_SECRET_KEY.
22
+ * @param keyFilePath - Optional path to a file containing the key material.
23
+ * @returns 32-byte Buffer suitable for AES-256-GCM.
24
+ * @throws If neither env var nor key file provides a valid key.
25
+ */
26
+ export declare function loadMasterKey(envKey?: string, keyFilePath?: string): Buffer;
27
+ /**
28
+ * Load the old (previous) master encryption key for key rotation.
29
+ *
30
+ * Returns undefined when no old key is configured (normal operation).
31
+ * Returns a 32-byte Buffer when KICI_SECRET_KEY_OLD or a key file is set.
32
+ *
33
+ * @param envKey - Environment variable name to read. Defaults to KICI_SECRET_KEY_OLD.
34
+ * @param keyFilePath - Optional path to a file containing the old key material.
35
+ * @returns 32-byte Buffer or undefined if no old key is configured.
36
+ */
37
+ export declare function loadOldMasterKey(envKey?: string, keyFilePath?: string): Buffer | undefined;
38
+ /**
39
+ * Load the full secret store configuration.
40
+ *
41
+ * @param opts - Optional overrides for env var name, key file path, and key version.
42
+ * @returns Complete SecretStoreConfig ready for PgSecretStore.
43
+ */
44
+ export declare function loadSecretStoreConfig(opts?: {
45
+ envKey?: string;
46
+ keyFilePath?: string;
47
+ keyVersion?: number;
48
+ oldEnvKey?: string;
49
+ oldKeyFilePath?: string;
50
+ }): SecretStoreConfig;
51
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Encrypted value with key version tracking.
3
+ * The data field contains base64-encoded IV || AuthTag || Ciphertext.
4
+ */
5
+ export interface EncryptedValue {
6
+ /** Base64-encoded IV + auth tag + ciphertext. */
7
+ data: string;
8
+ /** Version of the encryption key used. */
9
+ keyVersion: number;
10
+ }
11
+ /**
12
+ * Encrypt a plaintext string using AES-256-GCM with AAD.
13
+ *
14
+ * @param plaintext - The string to encrypt
15
+ * @param key - 32-byte encryption key
16
+ * @param keyVersion - Version number for key rotation tracking
17
+ * @param aad - Additional authenticated data (e.g., "contextId:keyName")
18
+ * @returns Encrypted value with key version
19
+ */
20
+ export declare function encrypt(plaintext: string, key: Buffer, keyVersion: number, aad: string): EncryptedValue;
21
+ /**
22
+ * Decrypt an encrypted value using AES-256-GCM with AAD verification.
23
+ *
24
+ * @param encrypted - The encrypted value to decrypt
25
+ * @param key - 32-byte encryption key (must match the key used for encryption)
26
+ * @param aad - Additional authenticated data (must match the AAD used for encryption)
27
+ * @returns Decrypted plaintext string
28
+ * @throws If decryption fails (wrong key, wrong AAD, tampered data)
29
+ */
30
+ export declare function decrypt(encrypted: EncryptedValue, key: Buffer, aad: string): string;
31
+ /**
32
+ * Derive a 32-byte encryption key from a string input.
33
+ *
34
+ * Accepts two formats:
35
+ * - 64-character hex string (e.g., from generateMasterKey())
36
+ * - Base64-encoded 32-byte key
37
+ *
38
+ * @param input - Hex or base64 encoded key material
39
+ * @returns 32-byte Buffer suitable for use with encrypt/decrypt
40
+ * @throws If the derived key is not exactly 32 bytes
41
+ */
42
+ export declare function deriveKey(input: string): Buffer;
43
+ /**
44
+ * Generate a new random 32-byte master key as a hex string.
45
+ *
46
+ * @returns 64-character hex string suitable for KICI_SECRET_KEY env var
47
+ */
48
+ export declare function generateMasterKey(): string;
49
+ //# sourceMappingURL=crypto.d.ts.map
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Generate an X25519 key pair for a run.
3
+ *
4
+ * @returns publicKey and privateKey as DER-encoded Buffers
5
+ */
6
+ export declare function generateRunKeyPair(): {
7
+ publicKey: Buffer;
8
+ privateKey: Buffer;
9
+ };
10
+ /**
11
+ * Encrypt a run's private key using the orchestrator secret key (KICI_SECRET_KEY).
12
+ *
13
+ * @param privateKey - DER-encoded private key Buffer
14
+ * @param secretKey - Orchestrator secret key (hex or base64 string)
15
+ * @returns Base64-encoded encrypted data (IV || AuthTag || Ciphertext)
16
+ */
17
+ export declare function encryptPrivateKey(privateKey: Buffer, secretKey: string): string;
18
+ /**
19
+ * Decrypt a run's private key using the orchestrator secret key (KICI_SECRET_KEY).
20
+ *
21
+ * @param encryptedData - Base64-encoded encrypted private key
22
+ * @param secretKey - Orchestrator secret key (hex or base64 string)
23
+ * @returns DER-encoded private key Buffer
24
+ * @throws If decryption fails
25
+ */
26
+ export declare function decryptPrivateKey(encryptedData: string, secretKey: string): Buffer;
27
+ /**
28
+ * Decrypt a secret output envelope produced by an agent.
29
+ *
30
+ * The agent encrypts with:
31
+ * 1. Generate ephemeral X25519 key pair
32
+ * 2. ECDH: shared secret = agentPrivateKey x runPublicKey
33
+ * 3. HKDF(sha256, sharedSecret, salt='', info='kici-run-secret-outputs', 32)
34
+ * 4. AES-256-GCM encrypt with derived key
35
+ *
36
+ * We decrypt with:
37
+ * 1. ECDH: shared secret = runPrivateKey x agentPublicKey
38
+ * 2. Same HKDF derivation
39
+ * 3. AES-256-GCM decrypt
40
+ *
41
+ * @param envelope - { agentPublicKey: base64, encrypted: base64 (IV||AuthTag||Ciphertext) }
42
+ * @param runPrivateKeyDer - DER-encoded run private key Buffer
43
+ * @returns Decrypted plaintext string
44
+ */
45
+ export declare function decryptSecretOutput(envelope: {
46
+ agentPublicKey: string;
47
+ encrypted: string;
48
+ }, runPrivateKeyDer: Buffer): string;
49
+ //# sourceMappingURL=ephemeral-keys.d.ts.map
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Secrets management module.
3
+ *
4
+ * Re-exports the PG secret store, audit logger, crypto utilities,
5
+ * and configuration helpers.
6
+ */
7
+ export { PgSecretStore } from './pg-secret-store.js';
8
+ export { AuditLogger } from './audit-logger.js';
9
+ export { loadMasterKey, loadOldMasterKey, loadSecretStoreConfig, type SecretStoreConfig, } from './config.js';
10
+ export { encrypt, decrypt, deriveKey, generateMasterKey, type EncryptedValue } from './crypto.js';
11
+ export { VaultSecretStore, type VaultConfig } from './vault-secret-store.js';
12
+ export { SecretResolver, type SecretResolverDeps, type ResolvedSecretMeta, type EnvironmentStoreLike, type BindingStoreLike, type SecretStoreLike, } from './secret-resolver.js';
13
+ export { BackendSyncManager } from './backend-sync.js';
14
+ export { RbacEnforcer, PermissionDeniedError, type Role, type Permission } from './rbac.js';
15
+ export { TokenManager } from './token-manager.js';
16
+ export { cleanupOrphanedSecrets, createOrphanSecretCleanupHandler, type SecretCleanupDeps, } from './cleanup.js';
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,105 @@
1
+ /**
2
+ * PostgreSQL-backed secret store implementing SecretStore.
3
+ *
4
+ * Encrypts secret values at rest using AES-256-GCM with AAD binding
5
+ * (orgId:scope:keyName) to prevent cross-scope secret swaps.
6
+ *
7
+ * Operates on the scoped_secrets table with (org_id, scope, key) composite key.
8
+ */
9
+ import { type Kysely } from 'kysely';
10
+ import type { Database } from '../db/types.js';
11
+ import type { SecretStore } from '@kici-dev/engine';
12
+ import type { AuditLogger } from './audit-logger.js';
13
+ /**
14
+ * PostgreSQL secret store with AES-256-GCM encryption.
15
+ * Uses scoped_secrets table keyed by (org_id, scope, key).
16
+ */
17
+ export declare class PgSecretStore implements SecretStore {
18
+ private readonly db;
19
+ private readonly masterKey;
20
+ private keyVersion;
21
+ private readonly auditLogger;
22
+ private readonly oldMasterKey?;
23
+ /**
24
+ * When false, setSecret() rejects for non-internal scopes (customer secrets disabled).
25
+ * Internal scopes (__source__/* and __webhook__/*) are always allowed.
26
+ */
27
+ customerSecretsEnabled: boolean;
28
+ constructor(db: Kysely<Database>, masterKey: Buffer, keyVersion: number, auditLogger: AuditLogger, oldMasterKey?: Buffer | undefined);
29
+ /**
30
+ * Create a PgSecretStore with keyVersion initialized from the database.
31
+ * Reads MAX(key_version) from scoped_secrets to avoid version conflicts
32
+ * after orchestrator restarts.
33
+ */
34
+ static create(db: Kysely<Database>, masterKey: Buffer, auditLogger: AuditLogger, oldMasterKey?: Buffer): Promise<PgSecretStore>;
35
+ /**
36
+ * Decrypt with current key, falling back to old key if available.
37
+ * Follows the same dual-key pattern as decryptPrivateKey() in ephemeral-keys.ts.
38
+ */
39
+ private decryptWithFallback;
40
+ /**
41
+ * Get all secrets for a scope as decrypted key-value pairs.
42
+ */
43
+ getSecrets(orgId: string, scope: string): Promise<Record<string, string>>;
44
+ /**
45
+ * Set (create or update) a secret in a scope.
46
+ * Encrypts the value with AAD = "orgId:scope:key".
47
+ */
48
+ /** Check if a scope is internal/operational (always allowed regardless of toggle). */
49
+ private isInternalScope;
50
+ setSecret(orgId: string, scope: string, key: string, value: string): Promise<void>;
51
+ /**
52
+ * Delete a secret from a scope.
53
+ */
54
+ deleteSecret(orgId: string, scope: string, key: string): Promise<void>;
55
+ /**
56
+ * List all secret key names in a scope (no values returned).
57
+ */
58
+ listKeys(orgId: string, scope: string): Promise<string[]>;
59
+ /**
60
+ * List all distinct scopes for an org.
61
+ *
62
+ * When orgId is empty, returns all distinct org_ids (with trailing slash)
63
+ * to support backend-sync scope discovery. This matches the Vault convention
64
+ * where listScopes('') returns top-level directory entries.
65
+ */
66
+ listScopes(orgId: string): Promise<string[]>;
67
+ /**
68
+ * Get all secrets for an org (for resolver).
69
+ * Returns scope, key, encrypted value, and key version without decrypting.
70
+ */
71
+ getAllSecrets(orgId: string): Promise<Array<{
72
+ scope: string;
73
+ key: string;
74
+ encryptedValue: string;
75
+ keyVersion: number;
76
+ }>>;
77
+ /**
78
+ * Decrypt a single secret value given its encrypted data, key version, and AAD components.
79
+ */
80
+ decryptValue(orgId: string, scope: string, key: string, encryptedValue: string, keyVersion: number): string;
81
+ /**
82
+ * Create an empty scope using a sentinel row (__empty__ key).
83
+ * If the scope already has keys, this is a no-op (idempotent).
84
+ */
85
+ createScope(orgId: string, scope: string): Promise<void>;
86
+ /**
87
+ * Rename a scope -- atomically update scoped_secrets and environment_bindings.
88
+ */
89
+ renameScope(orgId: string, oldScope: string, newScope: string): Promise<void>;
90
+ /**
91
+ * Delete a scope and all its secrets, plus any environment bindings referencing it.
92
+ */
93
+ deleteScope(orgId: string, scope: string): Promise<void>;
94
+ /**
95
+ * Rotate the encryption key version.
96
+ * Re-encrypts all secrets with the same master key but a new key version.
97
+ * Runs in a transaction for atomicity.
98
+ *
99
+ * @returns Number of re-encrypted secret values.
100
+ */
101
+ rotateKey(): Promise<{
102
+ reEncrypted: number;
103
+ }>;
104
+ }
105
+ //# sourceMappingURL=pg-secret-store.d.ts.map
@@ -0,0 +1,47 @@
1
+ /**
2
+ * RBAC (Role-Based Access Control) enforcer for secrets management admin API.
3
+ *
4
+ * Provides a fixed 3-role permission model:
5
+ * - owner: all permissions (manages tokens, rotates keys)
6
+ * - admin: context + secret + audit management
7
+ * - auditor: read-only access to contexts and audit logs (no secret values)
8
+ */
9
+ /**
10
+ * Fixed roles for the secrets management admin API.
11
+ */
12
+ export type Role = 'owner' | 'admin' | 'auditor';
13
+ /**
14
+ * Permissions for the secrets management admin API.
15
+ */
16
+ export type Permission = 'context.create' | 'context.read' | 'context.update' | 'context.delete' | 'secret.read' | 'secret.write' | 'secret.delete' | 'secret.reveal' | 'audit.read' | 'token.manage' | 'key.rotate' | 'run.read' | 'run.cancel' | 'event_log.read' | 'event_log.read_payload' | 'access_log.read' | 'scheduled_job.trigger' | 'event_dlq.read' | 'event_dlq.manage';
17
+ /**
18
+ * Error thrown when a role lacks the required permission.
19
+ */
20
+ export declare class PermissionDeniedError extends Error {
21
+ readonly role: Role;
22
+ readonly permission: Permission;
23
+ constructor(role: Role, permission: Permission);
24
+ }
25
+ /**
26
+ * RBAC enforcer for the secrets management admin API.
27
+ *
28
+ * Checks role-based permissions using a static permission mapping.
29
+ * No database or external state -- purely in-memory evaluation.
30
+ */
31
+ export declare class RbacEnforcer {
32
+ /**
33
+ * Check whether a role has a specific permission.
34
+ */
35
+ hasPermission(role: Role, permission: Permission): boolean;
36
+ /**
37
+ * Require a permission, throwing PermissionDeniedError if not authorized.
38
+ */
39
+ requirePermission(role: Role, permission: Permission): void;
40
+ /**
41
+ * Check whether a role can access secret values (not just metadata).
42
+ * Only owner and admin can see actual secret values.
43
+ * Auditor can see context metadata and audit logs but NOT secret values.
44
+ */
45
+ canAccessSecretValues(role: Role): boolean;
46
+ }
47
+ //# sourceMappingURL=rbac.d.ts.map
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Secret output store for cross-job secret output CRUD.
3
+ *
4
+ * Provides typed operations against the run_secret_outputs table:
5
+ * - Upsert encrypted secret outputs (per run/job/key)
6
+ * - Retrieve outputs for a specific job or multiple upstream jobs
7
+ * - Delete all outputs for a run (cleanup)
8
+ * - Delete orphaned outputs older than a threshold (maintenance)
9
+ */
10
+ import type { Kysely } from 'kysely';
11
+ import type { Database } from '../db/types.js';
12
+ export declare class SecretOutputStore {
13
+ private readonly db;
14
+ constructor(db: Kysely<Database>);
15
+ /**
16
+ * Store an encrypted secret output (upsert).
17
+ * If (run_id, job_id, output_key) already exists, the value is updated.
18
+ */
19
+ storeSecretOutput(runId: string, jobId: string, outputKey: string, encryptedValue: string): Promise<void>;
20
+ /**
21
+ * Get all secret outputs for a specific job in a run.
22
+ *
23
+ * @returns Record mapping output_key -> encrypted_value
24
+ */
25
+ getSecretOutputs(runId: string, jobId: string): Promise<Record<string, string>>;
26
+ /**
27
+ * Get secret outputs from multiple upstream jobs.
28
+ *
29
+ * @returns Record mapping jobId -> Record<output_key, encrypted_value>
30
+ */
31
+ getUpstreamSecretOutputs(runId: string, jobIds: string[]): Promise<Record<string, Record<string, string>>>;
32
+ /**
33
+ * Delete all secret outputs for a run.
34
+ *
35
+ * @returns Number of rows deleted
36
+ */
37
+ deleteByRunId(runId: string): Promise<number>;
38
+ /**
39
+ * Delete orphaned secret outputs older than maxAgeHours.
40
+ * Used for periodic cleanup of outputs from completed/abandoned runs.
41
+ *
42
+ * @returns Number of rows deleted
43
+ */
44
+ cleanupOrphaned(maxAgeHours: number): Promise<number>;
45
+ }
46
+ //# sourceMappingURL=secret-output-store.d.ts.map
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Secret resolver for dispatch-time secret resolution.
3
+ *
4
+ * Uses environment bindings + scope resolver to match secrets from multiple backends.
5
+ * When a job dispatches with an environment name, the resolver:
6
+ * 1. Looks up the environment by name
7
+ * 2. Gets bindings for that environment
8
+ * 3. Queries ALL registered backend stores for secrets
9
+ * 4. Prefixes each secret's scope with the backend name (e.g., pg:aws/prod)
10
+ * 5. Uses resolveSecretsForEnvironment to match bindings against prefixed secrets
11
+ * 6. Returns a flat decrypted key-value map
12
+ *
13
+ * unreachable backends cause job failure (not silent skip).
14
+ * external (Vault) secrets are fetched real-time (no cache).
15
+ * longest-path-wins uses scope path after stripping backend prefix.
16
+ * audit log includes backend name.
17
+ */
18
+ import { type EnvironmentBinding, type ScopedSecret } from '@kici-dev/engine';
19
+ import type { Logger } from '@kici-dev/shared';
20
+ import type { AuditLogger } from './audit-logger.js';
21
+ /**
22
+ * Minimal environment store interface (subset needed by resolver).
23
+ */
24
+ export interface EnvironmentStoreLike {
25
+ getByName(orgId: string, name: string): Promise<{
26
+ id: string;
27
+ name: string;
28
+ orgId: string;
29
+ } | null>;
30
+ }
31
+ /**
32
+ * Minimal binding store interface (subset needed by resolver).
33
+ */
34
+ export interface BindingStoreLike {
35
+ getByEnvironmentId(environmentId: string): Promise<EnvironmentBinding[]>;
36
+ }
37
+ /**
38
+ * Minimal secret store interface (subset needed by resolver).
39
+ * getAllSecrets returns raw encrypted secrets; decrypt decrypts a single secret.
40
+ * getSecrets returns a decrypted key-value map for a single scope (used by
41
+ * resolveNamed for source-scoped credential lookup).
42
+ */
43
+ export interface SecretStoreLike {
44
+ getAllSecrets(orgId: string): Promise<ScopedSecret[]>;
45
+ decrypt(secret: ScopedSecret): string;
46
+ getSecrets(orgId: string, scope: string): Promise<Record<string, string>>;
47
+ }
48
+ /**
49
+ * Dependencies for the SecretResolver.
50
+ */
51
+ export interface SecretResolverDeps {
52
+ environmentStore: EnvironmentStoreLike;
53
+ bindingStore: BindingStoreLike;
54
+ /** Map of backend name to store. Replaces single secretStore. */
55
+ backendStores: Map<string, SecretStoreLike>;
56
+ auditLogger: AuditLogger;
57
+ logger: Logger;
58
+ }
59
+ /** Metadata about a resolved secret. */
60
+ export interface ResolvedSecretMeta {
61
+ value: string;
62
+ backend: string;
63
+ scope: string;
64
+ }
65
+ /**
66
+ * Resolves secrets for a job by matching environment bindings against scoped secrets
67
+ * from multiple backends.
68
+ *
69
+ * All backend stores are queried. Each secret's scope is prefixed with the backend
70
+ * name (e.g., 'pg:aws/prod', 'vault-prod:databases/staging'). The prefixed scopes
71
+ * are matched against binding patterns, and longest-path-wins uses the path AFTER
72
+ * stripping the backend prefix.
73
+ */
74
+ export declare class SecretResolver {
75
+ private readonly environmentStore;
76
+ private readonly bindingStore;
77
+ private readonly backendStores;
78
+ private readonly auditLogger;
79
+ private readonly logger;
80
+ constructor(deps: SecretResolverDeps);
81
+ /**
82
+ * Resolve secrets for a job dispatch.
83
+ *
84
+ * @param orgId - Organization ID
85
+ * @param environmentName - Environment name to resolve secrets for
86
+ * @returns Flat map of decrypted secret key-value pairs
87
+ */
88
+ resolveForJob(orgId: string, environmentName: string): Promise<Record<string, string>>;
89
+ /**
90
+ * Resolve a single named secret by (orgId, scope, key), optionally scoped to
91
+ * a specific backend. Bypasses environment bindings — this is a direct
92
+ * lookup used for source-scoped credentials (e.g. universal-git PAT/SSH
93
+ * keys stored under `__source__/<sourceId>`).
94
+ *
95
+ * When `store` is omitted, backends are tried in Map iteration order (the
96
+ * order they were registered) and the first hit wins. An explicit `store`
97
+ * restricts the lookup to that one backend and returns null on miss.
98
+ *
99
+ * Audit-log: writes one `resolve_named` entry on success. Throws when the
100
+ * named store is requested but doesn't exist, mirroring `resolveForJob`'s
101
+ * fail-fast policy — the caller asked for a specific backend and
102
+ * it's gone.
103
+ */
104
+ resolveNamed(orgId: string, scope: string, key: string, opts?: {
105
+ store?: string;
106
+ runId?: string;
107
+ jobId?: string;
108
+ }): Promise<string | null>;
109
+ /**
110
+ * Resolve secrets with metadata (per, for secrets.getMeta).
111
+ *
112
+ * Returns the secret value along with which backend and scope provided it.
113
+ */
114
+ resolveForJobWithMeta(orgId: string, environmentName: string): Promise<Record<string, ResolvedSecretMeta>>;
115
+ /**
116
+ * Collect all secrets from all backend stores, prefixing scopes.
117
+ * Per /: unreachable backends are tracked but not fatal here.
118
+ * Callers apply scoped failure policy based on job bindings.
119
+ */
120
+ private collectAllSecrets;
121
+ /**
122
+ * Build a decrypt function that dispatches to the correct backend store.
123
+ */
124
+ private buildDecryptFn;
125
+ /**
126
+ * Check if any failed backend could affect the job's environment bindings.
127
+ * throw when a failed backend's scopes could match a binding and
128
+ * no healthy backend already satisfies that binding.
129
+ * jobs referencing only healthy backends succeed normally.
130
+ */
131
+ private checkScopedFailure;
132
+ /**
133
+ * Find the winning secret for a given key (highest scope depth after prefix strip).
134
+ */
135
+ private findWinningSecret;
136
+ }
137
+ //# sourceMappingURL=secret-resolver.d.ts.map
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Source-scoped credential resolution.
3
+ *
4
+ * Generic/universal-git webhook sources store a `credentialRef` (see
5
+ * `providers/universal-git/config.ts`) that points to a secret the agent
6
+ * will use to clone the source's repo. The secret itself is stored under
7
+ * the reserved scope `__source__/<sourceId>` — the same convention already
8
+ * used by `PgSecretStore.isInternalScope()` — with `credentialRef.key` as
9
+ * the key name.
10
+ *
11
+ * This module is a thin, opinionated wrapper around
12
+ * `SecretResolver.resolveNamed()` that:
13
+ * 1. Builds the canonical scope string for a given source ID.
14
+ * 2. Delegates to the resolver's direct-lookup method.
15
+ * 3. Returns a structured failure (null + reason) so callers can emit
16
+ * metrics without throwing across the clone-token boundary.
17
+ *
18
+ * The universal-git provider bundle's `CloneTokenProvider` is the primary
19
+ * consumer; an agent-side secret store lookup is **not** implemented here
20
+ * because the agent never talks to the orchestrator's secret backend
21
+ * directly — the orchestrator resolves and passes the material in the
22
+ * dispatch message (`gitAuth` / `sourceAuth` / `workflowAuth`).
23
+ */
24
+ import type { SecretResolver } from './secret-resolver.js';
25
+ import type { CredentialRef } from '../providers/universal-git/config.js';
26
+ /**
27
+ * Canonical scope for a source-owned secret. Uses the `__source__/` prefix
28
+ * which is whitelisted by `PgSecretStore.isInternalScope()` so setting
29
+ * these secrets is allowed even when customer secrets are globally
30
+ * disabled.
31
+ */
32
+ export declare function sourceCredentialScope(sourceId: string): string;
33
+ /**
34
+ * Result of a source credential lookup. `ok: false` is a recoverable
35
+ * miss (secret not present in any backend, or explicit backend empty) —
36
+ * callers can emit metrics or fall through. Throws are reserved for
37
+ * genuine errors (missing backend when one was explicitly requested).
38
+ */
39
+ export type SourceCredentialResult = {
40
+ ok: true;
41
+ value: string;
42
+ backend: string;
43
+ } | {
44
+ ok: false;
45
+ reason: 'not_found' | 'store_missing';
46
+ message: string;
47
+ };
48
+ /**
49
+ * Resolve a source-scoped credential via the shared SecretResolver.
50
+ *
51
+ * @param resolver The orchestrator's SecretResolver instance.
52
+ * @param orgId Organisation/customer ID that owns the source.
53
+ * @param sourceId Source row ID (`generic_webhook_sources.id`).
54
+ * @param credentialRef The `{ key, store? }` ref validated by Zod.
55
+ * @param opts Optional correlation IDs for audit entries.
56
+ */
57
+ export declare function resolveSourceCredential(resolver: SecretResolver, orgId: string, sourceId: string, credentialRef: CredentialRef, opts?: {
58
+ runId?: string;
59
+ jobId?: string;
60
+ }): Promise<SourceCredentialResult>;
61
+ //# sourceMappingURL=source-credentials.d.ts.map