clinkx 1.1.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +67 -14
  3. package/clinkx-workflows/dist/allowed-roots.js +2 -0
  4. package/clinkx-workflows/dist/allowed-roots.js.map +1 -1
  5. package/clinkx-workflows/dist/architecture-arena/admission.d.ts +16 -0
  6. package/clinkx-workflows/dist/architecture-arena/admission.js +107 -0
  7. package/clinkx-workflows/dist/architecture-arena/admission.js.map +1 -0
  8. package/clinkx-workflows/dist/architecture-arena/contract.d.ts +1368 -0
  9. package/clinkx-workflows/dist/architecture-arena/contract.js +254 -0
  10. package/clinkx-workflows/dist/architecture-arena/contract.js.map +1 -0
  11. package/clinkx-workflows/dist/architecture-arena/runtime.d.ts +53 -0
  12. package/clinkx-workflows/dist/architecture-arena/runtime.js +511 -0
  13. package/clinkx-workflows/dist/architecture-arena/runtime.js.map +1 -0
  14. package/clinkx-workflows/dist/architecture-comparison/admission.d.ts +17 -1
  15. package/clinkx-workflows/dist/architecture-comparison/admission.js +27 -4
  16. package/clinkx-workflows/dist/architecture-comparison/admission.js.map +1 -1
  17. package/clinkx-workflows/dist/architecture-comparison/contract.d.ts +59 -62
  18. package/clinkx-workflows/dist/architecture-comparison/contract.js +4 -21
  19. package/clinkx-workflows/dist/architecture-comparison/contract.js.map +1 -1
  20. package/clinkx-workflows/dist/architecture-comparison/runtime.d.ts +4 -3
  21. package/clinkx-workflows/dist/architecture-comparison/runtime.js +22 -67
  22. package/clinkx-workflows/dist/architecture-comparison/runtime.js.map +1 -1
  23. package/clinkx-workflows/dist/artifacts.d.ts +19 -4
  24. package/clinkx-workflows/dist/artifacts.js +16 -7
  25. package/clinkx-workflows/dist/artifacts.js.map +1 -1
  26. package/clinkx-workflows/dist/backend.d.ts +30 -0
  27. package/clinkx-workflows/dist/child-env.d.ts +3 -1
  28. package/clinkx-workflows/dist/child-env.js +6 -2
  29. package/clinkx-workflows/dist/child-env.js.map +1 -1
  30. package/clinkx-workflows/dist/clink-client.d.ts +8 -2
  31. package/clinkx-workflows/dist/clink-client.js +4 -2
  32. package/clinkx-workflows/dist/clink-client.js.map +1 -1
  33. package/clinkx-workflows/dist/config.d.ts +28 -5
  34. package/clinkx-workflows/dist/config.js +137 -20
  35. package/clinkx-workflows/dist/config.js.map +1 -1
  36. package/clinkx-workflows/dist/contained-file.js +9 -0
  37. package/clinkx-workflows/dist/contained-file.js.map +1 -1
  38. package/clinkx-workflows/dist/context-preflight.d.ts +6 -0
  39. package/clinkx-workflows/dist/context-preflight.js.map +1 -1
  40. package/clinkx-workflows/dist/council-execution-policy.d.ts +3 -1
  41. package/clinkx-workflows/dist/council-execution-policy.js +4 -0
  42. package/clinkx-workflows/dist/council-execution-policy.js.map +1 -1
  43. package/clinkx-workflows/dist/dashboard/contracts.d.ts +586 -586
  44. package/clinkx-workflows/dist/dashboard/progress-report-contract.d.ts +28 -28
  45. package/clinkx-workflows/dist/dashboard/session-log-contract.d.ts +32 -32
  46. package/clinkx-workflows/dist/dashboard/session-log-identity.js +2 -1
  47. package/clinkx-workflows/dist/dashboard/session-log-identity.js.map +1 -1
  48. package/clinkx-workflows/dist/dashboard-ui/assets/index-DRId2DVA.js +119 -0
  49. package/clinkx-workflows/dist/dashboard-ui/assets/style-CHAw57y5.css +1 -0
  50. package/clinkx-workflows/dist/dashboard-ui/index.html +2 -2
  51. package/clinkx-workflows/dist/delegate-signature.d.ts +4 -3
  52. package/clinkx-workflows/dist/delegate-signature.js +4 -3
  53. package/clinkx-workflows/dist/delegate-signature.js.map +1 -1
  54. package/clinkx-workflows/dist/durable-file.d.ts +69 -0
  55. package/clinkx-workflows/dist/durable-file.js +145 -0
  56. package/clinkx-workflows/dist/durable-file.js.map +1 -0
  57. package/clinkx-workflows/dist/engine.d.ts +42 -7
  58. package/clinkx-workflows/dist/engine.js +196 -24
  59. package/clinkx-workflows/dist/engine.js.map +1 -1
  60. package/clinkx-workflows/dist/ping-pong/admission.d.ts +127 -0
  61. package/clinkx-workflows/dist/ping-pong/admission.js +522 -0
  62. package/clinkx-workflows/dist/ping-pong/admission.js.map +1 -0
  63. package/clinkx-workflows/dist/ping-pong/contract.d.ts +2539 -0
  64. package/clinkx-workflows/dist/ping-pong/contract.js +819 -0
  65. package/clinkx-workflows/dist/ping-pong/contract.js.map +1 -0
  66. package/clinkx-workflows/dist/ping-pong/control.d.ts +67 -0
  67. package/clinkx-workflows/dist/ping-pong/control.js +12 -0
  68. package/clinkx-workflows/dist/ping-pong/control.js.map +1 -0
  69. package/clinkx-workflows/dist/ping-pong/runtime-handle.d.ts +24 -0
  70. package/clinkx-workflows/dist/ping-pong/runtime-handle.js +55 -0
  71. package/clinkx-workflows/dist/ping-pong/runtime-handle.js.map +1 -0
  72. package/clinkx-workflows/dist/ping-pong/runtime.d.ts +235 -0
  73. package/clinkx-workflows/dist/ping-pong/runtime.js +1183 -0
  74. package/clinkx-workflows/dist/ping-pong/runtime.js.map +1 -0
  75. package/clinkx-workflows/dist/ping-pong/settle.d.ts +57 -0
  76. package/clinkx-workflows/dist/ping-pong/settle.js +58 -0
  77. package/clinkx-workflows/dist/ping-pong/settle.js.map +1 -0
  78. package/clinkx-workflows/dist/ping-pong/sidecar.d.ts +65 -0
  79. package/clinkx-workflows/dist/ping-pong/sidecar.js +138 -0
  80. package/clinkx-workflows/dist/ping-pong/sidecar.js.map +1 -0
  81. package/clinkx-workflows/dist/plan-review/publication.d.ts +2 -1
  82. package/clinkx-workflows/dist/plan-review/publication.js +5 -6
  83. package/clinkx-workflows/dist/plan-review/publication.js.map +1 -1
  84. package/clinkx-workflows/dist/plan-review/snapshot.d.ts +3 -2
  85. package/clinkx-workflows/dist/plan-review/snapshot.js +8 -8
  86. package/clinkx-workflows/dist/plan-review/snapshot.js.map +1 -1
  87. package/clinkx-workflows/dist/recipe-host.d.ts +315 -0
  88. package/clinkx-workflows/dist/recipe-host.js +183 -0
  89. package/clinkx-workflows/dist/recipe-host.js.map +1 -0
  90. package/clinkx-workflows/dist/recipe-seats.d.ts +96 -0
  91. package/clinkx-workflows/dist/recipe-seats.js +163 -0
  92. package/clinkx-workflows/dist/recipe-seats.js.map +1 -0
  93. package/clinkx-workflows/dist/recipe-shared/evidence.d.ts +67 -0
  94. package/clinkx-workflows/dist/recipe-shared/evidence.js +111 -0
  95. package/clinkx-workflows/dist/recipe-shared/evidence.js.map +1 -0
  96. package/clinkx-workflows/dist/reducers/index.d.ts +9 -1
  97. package/clinkx-workflows/dist/reducers/index.js +30 -0
  98. package/clinkx-workflows/dist/reducers/index.js.map +1 -1
  99. package/clinkx-workflows/dist/root-path-validation.d.ts +12 -0
  100. package/clinkx-workflows/dist/root-path-validation.js +63 -0
  101. package/clinkx-workflows/dist/root-path-validation.js.map +1 -0
  102. package/clinkx-workflows/dist/rosters.d.ts +1 -0
  103. package/clinkx-workflows/dist/rosters.js +16 -6
  104. package/clinkx-workflows/dist/rosters.js.map +1 -1
  105. package/clinkx-workflows/dist/run-lock-reclaim.d.ts +44 -0
  106. package/clinkx-workflows/dist/run-lock-reclaim.js +86 -0
  107. package/clinkx-workflows/dist/run-lock-reclaim.js.map +1 -0
  108. package/clinkx-workflows/dist/server.js +5 -2
  109. package/clinkx-workflows/dist/server.js.map +1 -1
  110. package/clinkx-workflows/dist/state-schema.d.ts +24 -0
  111. package/clinkx-workflows/dist/state-schema.js +4 -1
  112. package/clinkx-workflows/dist/state-schema.js.map +1 -1
  113. package/clinkx-workflows/dist/state.d.ts +185 -4
  114. package/clinkx-workflows/dist/state.js +684 -88
  115. package/clinkx-workflows/dist/state.js.map +1 -1
  116. package/clinkx-workflows/dist/transport.d.ts +2 -1
  117. package/clinkx-workflows/dist/transport.js +5 -0
  118. package/clinkx-workflows/dist/transport.js.map +1 -1
  119. package/clinkx-workflows/dist/validators/architecture-arena.d.ts +6 -0
  120. package/clinkx-workflows/dist/validators/architecture-arena.js +16 -0
  121. package/clinkx-workflows/dist/validators/architecture-arena.js.map +1 -0
  122. package/clinkx-workflows/dist/validators/index.js +4 -0
  123. package/clinkx-workflows/dist/validators/index.js.map +1 -1
  124. package/clinkx-workflows/dist/validators/ping-pong.d.ts +6 -0
  125. package/clinkx-workflows/dist/validators/ping-pong.js +10 -0
  126. package/clinkx-workflows/dist/validators/ping-pong.js.map +1 -0
  127. package/clinkx-workflows/dist/workflow-completion.d.ts +83 -0
  128. package/clinkx-workflows/dist/workflow-completion.js +250 -0
  129. package/clinkx-workflows/dist/workflow-completion.js.map +1 -0
  130. package/clinkx-workflows/dist/workflow-tools.d.ts +53 -6
  131. package/clinkx-workflows/dist/workflow-tools.js +1123 -65
  132. package/clinkx-workflows/dist/workflow-tools.js.map +1 -1
  133. package/clinkx-workflows/dist/workflow-verification-contract.d.ts +4 -4
  134. package/clinkx-workflows/templates/architecture-arena/candidate.txt +39 -0
  135. package/clinkx-workflows/templates/architecture-arena/judge.txt +34 -0
  136. package/clinkx-workflows/templates/ping-pong/implement.txt +14 -0
  137. package/clinkx-workflows/templates/ping-pong/remediate.txt +14 -0
  138. package/clinkx-workflows/templates/ping-pong/review.txt +27 -0
  139. package/clinkx-workflows/workflows/architecture-arena.yaml +127 -0
  140. package/clinkx-workflows/workflows/ping-pong.yaml +158 -0
  141. package/dist/allowed-roots.d.ts +1 -1
  142. package/dist/allowed-roots.js +124 -14
  143. package/dist/allowed-roots.js.map +1 -1
  144. package/dist/context-builder/bundle.js +4 -3
  145. package/dist/context-builder/bundle.js.map +1 -1
  146. package/dist/context-builder/config.d.ts +1 -0
  147. package/dist/context-builder/config.js +21 -9
  148. package/dist/context-builder/config.js.map +1 -1
  149. package/dist/context-builder/delegate-packet.d.ts +1 -0
  150. package/dist/context-builder/delegate-packet.js +66 -7
  151. package/dist/context-builder/delegate-packet.js.map +1 -1
  152. package/dist/context-builder/delegate-validation.d.ts +12 -3
  153. package/dist/context-builder/delegate-validation.js +23 -13
  154. package/dist/context-builder/delegate-validation.js.map +1 -1
  155. package/dist/context-builder/external-gaps.d.ts +14 -3
  156. package/dist/context-builder/external-gaps.js +124 -18
  157. package/dist/context-builder/external-gaps.js.map +1 -1
  158. package/dist/context-builder/handler.js +108 -191
  159. package/dist/context-builder/handler.js.map +1 -1
  160. package/dist/context-builder/mutation-lock.d.ts +4 -0
  161. package/dist/context-builder/mutation-lock.js +7 -1
  162. package/dist/context-builder/mutation-lock.js.map +1 -1
  163. package/dist/context-builder/review-coverage.js +27 -1
  164. package/dist/context-builder/review-coverage.js.map +1 -1
  165. package/dist/context-builder/secrets.js +1 -1
  166. package/dist/context-builder/secrets.js.map +1 -1
  167. package/dist/context-builder/storage.d.ts +10 -2
  168. package/dist/context-builder/storage.js +213 -16
  169. package/dist/context-builder/storage.js.map +1 -1
  170. package/dist/context-builder/versions.d.ts +10 -4
  171. package/dist/context-builder/versions.js +10 -4
  172. package/dist/context-builder/versions.js.map +1 -1
  173. package/dist/context-builder/workflow-runner.js +33 -24
  174. package/dist/context-builder/workflow-runner.js.map +1 -1
  175. package/dist/dashboard-cli.d.ts +8 -0
  176. package/dist/dashboard-cli.js +155 -86
  177. package/dist/dashboard-cli.js.map +1 -1
  178. package/dist/dashboard-companion/client.d.ts +10 -0
  179. package/dist/dashboard-companion/client.js +43 -1
  180. package/dist/dashboard-companion/client.js.map +1 -1
  181. package/dist/dashboard-companion/config.d.ts +19 -1
  182. package/dist/dashboard-companion/config.js +104 -3
  183. package/dist/dashboard-companion/config.js.map +1 -1
  184. package/dist/dashboard-companion/protocol.d.ts +16 -0
  185. package/dist/dashboard-companion/protocol.js +38 -1
  186. package/dist/dashboard-companion/protocol.js.map +1 -1
  187. package/dist/dashboard-companion/workstation-binding.d.ts +69 -0
  188. package/dist/dashboard-companion/workstation-binding.js +192 -0
  189. package/dist/dashboard-companion/workstation-binding.js.map +1 -0
  190. package/dist/dashboard-gateway/admin-cli.d.ts +10 -0
  191. package/dist/dashboard-gateway/admin-cli.js +266 -0
  192. package/dist/dashboard-gateway/admin-cli.js.map +1 -0
  193. package/dist/dashboard-gateway/config.d.ts +50 -0
  194. package/dist/dashboard-gateway/config.js +235 -1
  195. package/dist/dashboard-gateway/config.js.map +1 -1
  196. package/dist/dashboard-gateway/connection-registry.d.ts +100 -0
  197. package/dist/dashboard-gateway/connection-registry.js +228 -0
  198. package/dist/dashboard-gateway/connection-registry.js.map +1 -0
  199. package/dist/dashboard-gateway/control-plane/account-auth.d.ts +78 -0
  200. package/dist/dashboard-gateway/control-plane/account-auth.js +198 -0
  201. package/dist/dashboard-gateway/control-plane/account-auth.js.map +1 -0
  202. package/dist/dashboard-gateway/control-plane/billing.d.ts +264 -0
  203. package/dist/dashboard-gateway/control-plane/billing.js +787 -0
  204. package/dist/dashboard-gateway/control-plane/billing.js.map +1 -0
  205. package/dist/dashboard-gateway/control-plane/contracts.d.ts +1293 -0
  206. package/dist/dashboard-gateway/control-plane/contracts.js +280 -0
  207. package/dist/dashboard-gateway/control-plane/contracts.js.map +1 -0
  208. package/dist/dashboard-gateway/control-plane/cookies.d.ts +13 -0
  209. package/dist/dashboard-gateway/control-plane/cookies.js +46 -0
  210. package/dist/dashboard-gateway/control-plane/cookies.js.map +1 -0
  211. package/dist/dashboard-gateway/control-plane/credentials.d.ts +63 -0
  212. package/dist/dashboard-gateway/control-plane/credentials.js +66 -0
  213. package/dist/dashboard-gateway/control-plane/credentials.js.map +1 -0
  214. package/dist/dashboard-gateway/control-plane/entitlements.d.ts +118 -0
  215. package/dist/dashboard-gateway/control-plane/entitlements.js +329 -0
  216. package/dist/dashboard-gateway/control-plane/entitlements.js.map +1 -0
  217. package/dist/dashboard-gateway/control-plane/errors.d.ts +17 -0
  218. package/dist/dashboard-gateway/control-plane/errors.js +23 -0
  219. package/dist/dashboard-gateway/control-plane/errors.js.map +1 -0
  220. package/dist/dashboard-gateway/control-plane/hosts.d.ts +6 -0
  221. package/dist/dashboard-gateway/control-plane/hosts.js +16 -0
  222. package/dist/dashboard-gateway/control-plane/hosts.js.map +1 -0
  223. package/dist/dashboard-gateway/control-plane/http.d.ts +34 -0
  224. package/dist/dashboard-gateway/control-plane/http.js +331 -0
  225. package/dist/dashboard-gateway/control-plane/http.js.map +1 -0
  226. package/dist/dashboard-gateway/control-plane/schema.d.ts +9 -0
  227. package/dist/dashboard-gateway/control-plane/schema.js +247 -0
  228. package/dist/dashboard-gateway/control-plane/schema.js.map +1 -0
  229. package/dist/dashboard-gateway/control-plane/secrets.d.ts +20 -0
  230. package/dist/dashboard-gateway/control-plane/secrets.js +39 -0
  231. package/dist/dashboard-gateway/control-plane/secrets.js.map +1 -0
  232. package/dist/dashboard-gateway/control-plane/store.d.ts +579 -0
  233. package/dist/dashboard-gateway/control-plane/store.js +1115 -0
  234. package/dist/dashboard-gateway/control-plane/store.js.map +1 -0
  235. package/dist/dashboard-gateway/cookie-boundary.d.ts +60 -0
  236. package/dist/dashboard-gateway/cookie-boundary.js +205 -0
  237. package/dist/dashboard-gateway/cookie-boundary.js.map +1 -0
  238. package/dist/dashboard-gateway/index.js +271 -494
  239. package/dist/dashboard-gateway/index.js.map +1 -1
  240. package/dist/dashboard-gateway/main.js +7 -2
  241. package/dist/dashboard-gateway/main.js.map +1 -1
  242. package/dist/dashboard-gateway/routing.d.ts +43 -0
  243. package/dist/dashboard-gateway/routing.js +65 -0
  244. package/dist/dashboard-gateway/routing.js.map +1 -0
  245. package/dist/dashboard-gateway/tenant-gateway.d.ts +56 -0
  246. package/dist/dashboard-gateway/tenant-gateway.js +989 -0
  247. package/dist/dashboard-gateway/tenant-gateway.js.map +1 -0
  248. package/dist/dashboard-gateway/tenant-main.d.ts +41 -0
  249. package/dist/dashboard-gateway/tenant-main.js +303 -0
  250. package/dist/dashboard-gateway/tenant-main.js.map +1 -0
  251. package/dist/dashboard-gateway/tunnel-errors.d.ts +16 -0
  252. package/dist/dashboard-gateway/tunnel-errors.js +22 -0
  253. package/dist/dashboard-gateway/tunnel-errors.js.map +1 -0
  254. package/dist/dashboard-gateway/tunnel-http.d.ts +21 -0
  255. package/dist/dashboard-gateway/tunnel-http.js +175 -0
  256. package/dist/dashboard-gateway/tunnel-http.js.map +1 -0
  257. package/dist/handler.d.ts +6 -0
  258. package/dist/handler.js +17 -1
  259. package/dist/handler.js.map +1 -1
  260. package/dist/local-clink-backend.d.ts +2 -1
  261. package/dist/local-clink-backend.js +28 -4
  262. package/dist/local-clink-backend.js.map +1 -1
  263. package/dist/parsers/extract.d.ts +19 -1
  264. package/dist/parsers/extract.js +68 -3
  265. package/dist/parsers/extract.js.map +1 -1
  266. package/dist/pipeline.d.ts +17 -1
  267. package/dist/pipeline.js +34 -6
  268. package/dist/pipeline.js.map +1 -1
  269. package/dist/process-group.d.ts +65 -0
  270. package/dist/process-group.js +153 -0
  271. package/dist/process-group.js.map +1 -0
  272. package/dist/progress-report/schema.d.ts +23 -23
  273. package/dist/project-verification/files.js +1 -1
  274. package/dist/project-verification/files.js.map +1 -1
  275. package/dist/project-verification/process.js +23 -44
  276. package/dist/project-verification/process.js.map +1 -1
  277. package/dist/project-verification/service.js +9 -1
  278. package/dist/project-verification/service.js.map +1 -1
  279. package/dist/prompt.d.ts +7 -0
  280. package/dist/prompt.js +18 -1
  281. package/dist/prompt.js.map +1 -1
  282. package/dist/recipe-host/git-trust.d.ts +43 -0
  283. package/dist/recipe-host/git-trust.js +360 -0
  284. package/dist/recipe-host/git-trust.js.map +1 -0
  285. package/dist/recipe-host/git.d.ts +42 -0
  286. package/dist/recipe-host/git.js +207 -0
  287. package/dist/recipe-host/git.js.map +1 -0
  288. package/dist/recipe-host/native-recipe-host.d.ts +127 -0
  289. package/dist/recipe-host/native-recipe-host.js +880 -0
  290. package/dist/recipe-host/native-recipe-host.js.map +1 -0
  291. package/dist/recipe-host/seat-cwd.d.ts +16 -0
  292. package/dist/recipe-host/seat-cwd.js +170 -0
  293. package/dist/recipe-host/seat-cwd.js.map +1 -0
  294. package/dist/registry.d.ts +1 -1
  295. package/dist/registry.js +5 -1
  296. package/dist/registry.js.map +1 -1
  297. package/dist/runner.d.ts +43 -1
  298. package/dist/runner.js +234 -35
  299. package/dist/runner.js.map +1 -1
  300. package/dist/server.js +21 -6
  301. package/dist/server.js.map +1 -1
  302. package/docs/configuration.md +181 -15
  303. package/docs/engineering-recipes.md +291 -0
  304. package/docs/security.md +87 -0
  305. package/docs/verification/project-checks.md +24 -2
  306. package/package.json +5 -1
  307. package/scripts/provider-doctor-core.mjs +21 -5
  308. package/clinkx-workflows/dist/dashboard-ui/assets/index-BdpmbPps.js +0 -115
  309. package/clinkx-workflows/dist/dashboard-ui/assets/style-Im5i1iAs.css +0 -1
@@ -0,0 +1,100 @@
1
+ export declare const LEGACY_CONNECTION_SLOT = "legacy";
2
+ export type RequestPhase = "admitted" | "forwarded";
3
+ export interface OwnedRequest<TValue> {
4
+ readonly id: string;
5
+ readonly phase: RequestPhase;
6
+ readonly value: TValue;
7
+ }
8
+ export interface GatewayConnection<TSocket> {
9
+ readonly slot: string;
10
+ readonly generation: number;
11
+ readonly socket: TSocket;
12
+ readonly version: 1 | 2;
13
+ }
14
+ export interface UpgradeClaim {
15
+ readonly slot: string;
16
+ }
17
+ export interface ConnectionCounters {
18
+ admitted: number;
19
+ rejectedOverCapacity: number;
20
+ forwarded: number;
21
+ completed: number;
22
+ failed: number;
23
+ lostOnDisconnect: number;
24
+ }
25
+ export interface ConnectionSnapshot {
26
+ readonly slot: string;
27
+ readonly generation: number;
28
+ readonly version: 1 | 2;
29
+ readonly attached: boolean;
30
+ readonly pending: number;
31
+ readonly counters: Readonly<ConnectionCounters>;
32
+ }
33
+ export type AdmitResult = "admitted" | "not_current" | "over_capacity" | "duplicate_id";
34
+ /**
35
+ * `abandoned` is a failure whose companion response may still arrive later
36
+ * (timeout, browser cancel, send error); its id is remembered so that late
37
+ * reply is dropped instead of being treated as a protocol violation.
38
+ */
39
+ export type SettleOutcome = "completed" | "failed" | "abandoned";
40
+ export type ResponseLookup<TValue> = {
41
+ readonly kind: "owned";
42
+ readonly request: OwnedRequest<TValue>;
43
+ } | {
44
+ readonly kind: "late";
45
+ } | {
46
+ readonly kind: "unknown";
47
+ } | {
48
+ readonly kind: "stale_connection";
49
+ };
50
+ export interface AttachResult<TSocket, TValue> {
51
+ readonly connection: GatewayConnection<TSocket>;
52
+ readonly displaced?: GatewayConnection<TSocket>;
53
+ readonly displacedRequests: readonly OwnedRequest<TValue>[];
54
+ }
55
+ /**
56
+ * At most one live companion connection per slot. Legacy mode uses
57
+ * LEGACY_CONNECTION_SLOT; tenant mode keys slots by the companion id taken from
58
+ * the authenticated device credential, so each workstation holds its own slot.
59
+ *
60
+ * Second-connection policy: the live holder always wins. A claim is refused
61
+ * while the slot's current socket is open or another upgrade holds the claim.
62
+ * A current connection whose socket is no longer open is displaced by the next
63
+ * attach, and its owned requests are handed back for failure.
64
+ *
65
+ * Requests are owned by exactly one connection handle. Every lookup is scoped
66
+ * to the handle that asks, so a socket can never observe, complete, or remove
67
+ * another connection's request, and a retired handle owns nothing.
68
+ */
69
+ export declare class ConnectionRegistry<TSocket, TValue> {
70
+ private readonly isOpen;
71
+ private readonly slots;
72
+ private readonly records;
73
+ private readonly lastGenerations;
74
+ private readonly nextGeneration;
75
+ constructor(isOpen: (socket: TSocket) => boolean, nextGeneration?: () => number);
76
+ claim(slot: string): UpgradeClaim | undefined;
77
+ isClaimValid(claim: UpgradeClaim): boolean;
78
+ release(claim: UpgradeClaim): void;
79
+ attach(claim: UpgradeClaim, socket: TSocket, version: 1 | 2): AttachResult<TSocket, TValue> | undefined;
80
+ current(slot: string): GatewayConnection<TSocket> | undefined;
81
+ isAttached(connection: GatewayConnection<TSocket>): boolean;
82
+ isCurrent(connection: GatewayConnection<TSocket>): boolean;
83
+ /** Close-callback entry point. A stale handle (already displaced) is a no-op. */
84
+ detach(connection: GatewayConnection<TSocket>): OwnedRequest<TValue>[];
85
+ admit(connection: GatewayConnection<TSocket>, id: string, value: TValue, limit: number): AdmitResult;
86
+ /** Marks an admitted request as handed to the socket. Fails unless the owner is still current. */
87
+ markForwarded(connection: GatewayConnection<TSocket>, id: string): boolean;
88
+ owned(connection: GatewayConnection<TSocket>, id: string): OwnedRequest<TValue> | undefined;
89
+ settle(connection: GatewayConnection<TSocket>, id: string, outcome: SettleOutcome): OwnedRequest<TValue> | undefined;
90
+ /**
91
+ * Resolves a response id against the responding connection only. It never
92
+ * changes pending state; the caller settles after validating the payload.
93
+ */
94
+ lookupResponse(connection: GatewayConnection<TSocket>, id: string): ResponseLookup<TValue>;
95
+ snapshot(connection: GatewayConnection<TSocket>): ConnectionSnapshot | undefined;
96
+ /** Invalidates every outstanding claim and returns the attached connections for termination. */
97
+ shutdown(): GatewayConnection<TSocket>[];
98
+ private retire;
99
+ private pruneSlot;
100
+ }
@@ -0,0 +1,228 @@
1
+ export const LEGACY_CONNECTION_SLOT = "legacy";
2
+ const MAX_RETIRED_REQUEST_IDS = 1_024;
3
+ /**
4
+ * At most one live companion connection per slot. Legacy mode uses
5
+ * LEGACY_CONNECTION_SLOT; tenant mode keys slots by the companion id taken from
6
+ * the authenticated device credential, so each workstation holds its own slot.
7
+ *
8
+ * Second-connection policy: the live holder always wins. A claim is refused
9
+ * while the slot's current socket is open or another upgrade holds the claim.
10
+ * A current connection whose socket is no longer open is displaced by the next
11
+ * attach, and its owned requests are handed back for failure.
12
+ *
13
+ * Requests are owned by exactly one connection handle. Every lookup is scoped
14
+ * to the handle that asks, so a socket can never observe, complete, or remove
15
+ * another connection's request, and a retired handle owns nothing.
16
+ */
17
+ export class ConnectionRegistry {
18
+ isOpen;
19
+ slots = new Map();
20
+ records = new WeakMap();
21
+ lastGenerations = new Map();
22
+ nextGeneration;
23
+ constructor(isOpen, nextGeneration) {
24
+ this.isOpen = isOpen;
25
+ let counter = 0;
26
+ this.nextGeneration = nextGeneration ?? (() => ++counter);
27
+ }
28
+ claim(slot) {
29
+ const state = this.slots.get(slot) ?? { current: undefined, claim: undefined };
30
+ if (state.claim !== undefined)
31
+ return undefined;
32
+ if (state.current !== undefined && this.isOpen(state.current.socket))
33
+ return undefined;
34
+ const claim = Object.freeze({ slot });
35
+ state.claim = claim;
36
+ this.slots.set(slot, state);
37
+ return claim;
38
+ }
39
+ isClaimValid(claim) {
40
+ return this.slots.get(claim.slot)?.claim === claim;
41
+ }
42
+ release(claim) {
43
+ const state = this.slots.get(claim.slot);
44
+ if (state?.claim !== claim)
45
+ return;
46
+ state.claim = undefined;
47
+ this.pruneSlot(claim.slot);
48
+ }
49
+ attach(claim, socket, version) {
50
+ const state = this.slots.get(claim.slot);
51
+ if (state?.claim !== claim)
52
+ return undefined;
53
+ state.claim = undefined;
54
+ const previous = state.current;
55
+ if (previous !== undefined && this.isOpen(previous.socket)) {
56
+ this.pruneSlot(claim.slot);
57
+ return undefined;
58
+ }
59
+ const displacedRequests = previous === undefined ? [] : this.retire(previous);
60
+ const lastGeneration = this.lastGenerations.get(claim.slot);
61
+ let generation = this.nextGeneration();
62
+ while (generation === lastGeneration)
63
+ generation = this.nextGeneration();
64
+ this.lastGenerations.set(claim.slot, generation);
65
+ const connection = Object.freeze({
66
+ slot: claim.slot,
67
+ generation,
68
+ socket,
69
+ version,
70
+ });
71
+ state.current = connection;
72
+ this.records.set(connection, {
73
+ attached: true,
74
+ requests: new Map(),
75
+ retiredRequestIds: new Set(),
76
+ counters: {
77
+ admitted: 0,
78
+ rejectedOverCapacity: 0,
79
+ forwarded: 0,
80
+ completed: 0,
81
+ failed: 0,
82
+ lostOnDisconnect: 0,
83
+ },
84
+ });
85
+ return previous === undefined
86
+ ? { connection, displacedRequests }
87
+ : { connection, displaced: previous, displacedRequests };
88
+ }
89
+ current(slot) {
90
+ const connection = this.slots.get(slot)?.current;
91
+ return connection !== undefined && this.isOpen(connection.socket) ? connection : undefined;
92
+ }
93
+ isAttached(connection) {
94
+ return this.records.get(connection)?.attached === true;
95
+ }
96
+ isCurrent(connection) {
97
+ return this.slots.get(connection.slot)?.current === connection
98
+ && this.isAttached(connection)
99
+ && this.isOpen(connection.socket);
100
+ }
101
+ /** Close-callback entry point. A stale handle (already displaced) is a no-op. */
102
+ detach(connection) {
103
+ if (this.slots.get(connection.slot)?.current !== connection)
104
+ return [];
105
+ const lost = this.retire(connection);
106
+ this.pruneSlot(connection.slot);
107
+ return lost;
108
+ }
109
+ admit(connection, id, value, limit) {
110
+ const record = this.records.get(connection);
111
+ if (record === undefined || !this.isCurrent(connection))
112
+ return "not_current";
113
+ if (record.requests.has(id) || record.retiredRequestIds.has(id))
114
+ return "duplicate_id";
115
+ if (record.requests.size >= limit) {
116
+ record.counters.rejectedOverCapacity += 1;
117
+ return "over_capacity";
118
+ }
119
+ record.requests.set(id, { phase: "admitted", value });
120
+ record.counters.admitted += 1;
121
+ return "admitted";
122
+ }
123
+ /** Marks an admitted request as handed to the socket. Fails unless the owner is still current. */
124
+ markForwarded(connection, id) {
125
+ const record = this.records.get(connection);
126
+ const entry = record?.requests.get(id);
127
+ if (record === undefined || entry === undefined || entry.phase !== "admitted")
128
+ return false;
129
+ if (!this.isCurrent(connection))
130
+ return false;
131
+ entry.phase = "forwarded";
132
+ record.counters.forwarded += 1;
133
+ return true;
134
+ }
135
+ owned(connection, id) {
136
+ const entry = this.records.get(connection)?.requests.get(id);
137
+ return entry === undefined ? undefined : { id, phase: entry.phase, value: entry.value };
138
+ }
139
+ settle(connection, id, outcome) {
140
+ const record = this.records.get(connection);
141
+ const entry = record?.requests.get(id);
142
+ if (record === undefined || entry === undefined)
143
+ return undefined;
144
+ record.requests.delete(id);
145
+ if (outcome === "completed") {
146
+ record.counters.completed += 1;
147
+ }
148
+ else {
149
+ record.counters.failed += 1;
150
+ if (outcome === "abandoned" && entry.phase === "forwarded") {
151
+ record.retiredRequestIds.add(id);
152
+ while (record.retiredRequestIds.size > MAX_RETIRED_REQUEST_IDS) {
153
+ const oldest = record.retiredRequestIds.values().next().value;
154
+ if (oldest === undefined)
155
+ break;
156
+ record.retiredRequestIds.delete(oldest);
157
+ }
158
+ }
159
+ }
160
+ return { id, phase: entry.phase, value: entry.value };
161
+ }
162
+ /**
163
+ * Resolves a response id against the responding connection only. It never
164
+ * changes pending state; the caller settles after validating the payload.
165
+ */
166
+ lookupResponse(connection, id) {
167
+ const record = this.records.get(connection);
168
+ if (record === undefined || !record.attached)
169
+ return { kind: "stale_connection" };
170
+ const entry = record.requests.get(id);
171
+ if (entry !== undefined) {
172
+ return entry.phase === "forwarded"
173
+ ? { kind: "owned", request: { id, phase: entry.phase, value: entry.value } }
174
+ : { kind: "unknown" };
175
+ }
176
+ if (record.retiredRequestIds.delete(id))
177
+ return { kind: "late" };
178
+ return { kind: "unknown" };
179
+ }
180
+ snapshot(connection) {
181
+ const record = this.records.get(connection);
182
+ if (record === undefined)
183
+ return undefined;
184
+ return {
185
+ slot: connection.slot,
186
+ generation: connection.generation,
187
+ version: connection.version,
188
+ attached: record.attached,
189
+ pending: record.requests.size,
190
+ counters: { ...record.counters },
191
+ };
192
+ }
193
+ /** Invalidates every outstanding claim and returns the attached connections for termination. */
194
+ shutdown() {
195
+ const attached = [];
196
+ for (const [slot, state] of this.slots) {
197
+ state.claim = undefined;
198
+ if (state.current !== undefined)
199
+ attached.push(state.current);
200
+ this.pruneSlot(slot);
201
+ }
202
+ return attached;
203
+ }
204
+ retire(connection) {
205
+ const state = this.slots.get(connection.slot);
206
+ if (state?.current === connection)
207
+ state.current = undefined;
208
+ const record = this.records.get(connection);
209
+ if (record === undefined || !record.attached)
210
+ return [];
211
+ record.attached = false;
212
+ const lost = [...record.requests].map(([id, entry]) => ({
213
+ id,
214
+ phase: entry.phase,
215
+ value: entry.value,
216
+ }));
217
+ record.counters.lostOnDisconnect += lost.length;
218
+ record.requests.clear();
219
+ return lost;
220
+ }
221
+ pruneSlot(slot) {
222
+ const state = this.slots.get(slot);
223
+ if (state !== undefined && state.current === undefined && state.claim === undefined) {
224
+ this.slots.delete(slot);
225
+ }
226
+ }
227
+ }
228
+ //# sourceMappingURL=connection-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-registry.js","source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AAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAI,KAAK,EAAE,OAAO,KAAK,UAAU;YAAE,KAAK,CAAC,OAAO,GAAG,SAAS,CAAC;QAC7D,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC5C,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,QAAQ;YAAE,OAAO,EAAE,CAAC;QACxD,MAAM,CAAC,QAAQ,GAAG,KAAK,CAAC;QACxB,MAAM,IAAI,GAAG,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YACtD,EAAE;YACF,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB,CAAC,CAAC,CAAC;QACJ,MAAM,CAAC,QAAQ,CAAC,gBAAgB,IAAI,IAAI,CAAC,MAAM,CAAC;QAChD,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,SAAS,CAAC,IAAY;QAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACnC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YACpF,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,78 @@
1
+ import type { AuthCallbackQuery } from "./contracts.js";
2
+ import type { AccountRecord, AccountSessionContext, ControlPlaneStore, TenantMemberContext, TenantRecord } from "./store.js";
3
+ export declare const AUTH_CALLBACK_PATH = "/api/control/auth/callback";
4
+ export interface AccountAuthTtls {
5
+ readonly pendingLoginMs: number;
6
+ readonly accountSessionMs: number;
7
+ }
8
+ export declare const DEFAULT_ACCOUNT_AUTH_TTLS: AccountAuthTtls;
9
+ export interface OidcClientConfig {
10
+ readonly issuer: string;
11
+ readonly clientId: string;
12
+ /** Name of the environment variable holding the client secret; read on every token request. */
13
+ readonly clientSecretEnv: string;
14
+ }
15
+ export interface AccountAuthOptions {
16
+ readonly store: ControlPlaneStore;
17
+ /** The single public origin: canonical `https://host` with no port. */
18
+ readonly publicOrigin: string;
19
+ readonly oidc: OidcClientConfig;
20
+ readonly env?: Readonly<Record<string, string | undefined>>;
21
+ readonly ttls?: Partial<AccountAuthTtls>;
22
+ /**
23
+ * Test fixtures only: permits a loopback `http://` issuer through
24
+ * openid-client's explicit `allowInsecureRequests`. Production wiring never sets it.
25
+ */
26
+ readonly allowInsecureRequests?: boolean;
27
+ }
28
+ export interface IssuedSession {
29
+ readonly secret: string;
30
+ readonly expiresAt: number;
31
+ readonly maxAgeSeconds: number;
32
+ }
33
+ export interface LoginStart {
34
+ readonly authorizationUrl: string;
35
+ readonly loginBinding: string;
36
+ readonly bindingMaxAgeSeconds: number;
37
+ }
38
+ export interface LoginCompletion {
39
+ readonly session: IssuedSession;
40
+ readonly account: AccountRecord;
41
+ readonly workspace: TenantRecord;
42
+ }
43
+ /**
44
+ * Account authority: generic OIDC sign-in and account sessions on the single
45
+ * public origin. The account session is the only browser authority; it
46
+ * resolves to the workspace its account owns. Identity is the provider
47
+ * (issuer, subject) pair; email is never read.
48
+ */
49
+ export declare class AccountAuthority {
50
+ private readonly store;
51
+ private readonly publicOrigin;
52
+ private readonly oidcConfig;
53
+ private readonly env;
54
+ private readonly ttls;
55
+ private readonly allowInsecureRequests;
56
+ private discovered;
57
+ constructor(options: AccountAuthOptions);
58
+ get redirectUri(): string;
59
+ private readonly clientAuthentication;
60
+ private configuration;
61
+ startLogin(): Promise<LoginStart>;
62
+ /**
63
+ * Finish sign-in and ensure the account's workspace exists. The pending login
64
+ * is consumed before any check runs, so a failed or replayed callback can
65
+ * never be completed later.
66
+ */
67
+ completeLogin(input: {
68
+ callbackUrl: URL;
69
+ query: AuthCallbackQuery;
70
+ loginBinding: string | null;
71
+ }): Promise<LoginCompletion>;
72
+ resolveAccountSession(secret: string | null): AccountSessionContext | null;
73
+ logoutAccount(secret: string | null): void;
74
+ /** The session's account together with the workspace it owns, or `null`. */
75
+ resolveTenantMember(secret: string | null): TenantMemberContext | null;
76
+ /** Workspace authority for a browser request, from its Cookie header. */
77
+ resolveTenantMemberFromCookies(cookieHeader: string | undefined): TenantMemberContext | null;
78
+ }
@@ -0,0 +1,198 @@
1
+ import * as oidc from "openid-client";
2
+ import { ACCOUNT_SESSION_COOKIE, readSingleCookie } from "./cookies.js";
3
+ import { ControlError } from "./errors.js";
4
+ import { SECRET_PREFIX, constantTimeEqual, deriveVerifier, generateControlId, generateOpaqueSecret, isOpaqueSecret, } from "./secrets.js";
5
+ export const AUTH_CALLBACK_PATH = "/api/control/auth/callback";
6
+ export const DEFAULT_ACCOUNT_AUTH_TTLS = {
7
+ pendingLoginMs: 10 * 60_000,
8
+ accountSessionMs: 12 * 60 * 60_000,
9
+ };
10
+ const PROVIDER_FAILURE_CODES = new Set([
11
+ "OAUTH_TIMEOUT",
12
+ "OAUTH_ABORT",
13
+ "OAUTH_RESPONSE_IS_NOT_CONFORM",
14
+ "OAUTH_RESPONSE_IS_NOT_JSON",
15
+ ]);
16
+ function classifyProviderError(error) {
17
+ if (error instanceof ControlError)
18
+ return error;
19
+ if (error instanceof TypeError)
20
+ return new ControlError("provider_unavailable", undefined, { cause: error });
21
+ if (error instanceof oidc.ClientError && error.code !== undefined && PROVIDER_FAILURE_CODES.has(error.code)) {
22
+ return new ControlError("provider_unavailable", undefined, { cause: error });
23
+ }
24
+ if (error instanceof oidc.ClientError && error.cause instanceof ControlError)
25
+ return error.cause;
26
+ if (error instanceof oidc.ResponseBodyError && (error.status === 429 || error.status >= 500)) {
27
+ return new ControlError("provider_unavailable", undefined, { cause: error });
28
+ }
29
+ return new ControlError("auth_failed", undefined, { cause: error });
30
+ }
31
+ function issuedSession(secret, expiresAt, ttlMs) {
32
+ return { secret, expiresAt, maxAgeSeconds: Math.floor(ttlMs / 1000) };
33
+ }
34
+ function displayNameFrom(claims) {
35
+ const name = claims.name;
36
+ if (typeof name !== "string")
37
+ return null;
38
+ const trimmed = name.trim();
39
+ return trimmed.length >= 1 && trimmed.length <= 200 ? trimmed : null;
40
+ }
41
+ /**
42
+ * Account authority: generic OIDC sign-in and account sessions on the single
43
+ * public origin. The account session is the only browser authority; it
44
+ * resolves to the workspace its account owns. Identity is the provider
45
+ * (issuer, subject) pair; email is never read.
46
+ */
47
+ export class AccountAuthority {
48
+ store;
49
+ publicOrigin;
50
+ oidcConfig;
51
+ env;
52
+ ttls;
53
+ allowInsecureRequests;
54
+ discovered = null;
55
+ constructor(options) {
56
+ this.store = options.store;
57
+ this.publicOrigin = options.publicOrigin;
58
+ this.oidcConfig = options.oidc;
59
+ this.env = options.env ?? process.env;
60
+ this.ttls = { ...DEFAULT_ACCOUNT_AUTH_TTLS, ...options.ttls };
61
+ this.allowInsecureRequests = options.allowInsecureRequests === true;
62
+ }
63
+ get redirectUri() {
64
+ return `${this.publicOrigin}${AUTH_CALLBACK_PATH}`;
65
+ }
66
+ clientAuthentication = (as, client, body, headers) => {
67
+ const secret = this.env[this.oidcConfig.clientSecretEnv];
68
+ if (secret === undefined || secret === "") {
69
+ throw new ControlError("provider_unavailable", "OIDC client secret is not configured");
70
+ }
71
+ oidc.ClientSecretBasic(secret)(as, client, body, headers);
72
+ };
73
+ configuration() {
74
+ if (this.discovered === null) {
75
+ const options = this.allowInsecureRequests
76
+ ? { execute: [oidc.allowInsecureRequests] }
77
+ : {};
78
+ const pending = oidc
79
+ .discovery(new URL(this.oidcConfig.issuer), this.oidcConfig.clientId, undefined, this.clientAuthentication, options)
80
+ .catch((error) => {
81
+ if (this.discovered === pending)
82
+ this.discovered = null;
83
+ throw new ControlError("provider_unavailable", "OIDC discovery failed", { cause: error });
84
+ });
85
+ this.discovered = pending;
86
+ }
87
+ return this.discovered;
88
+ }
89
+ async startLogin() {
90
+ const config = await this.configuration();
91
+ const state = oidc.randomState();
92
+ const nonce = oidc.randomNonce();
93
+ const codeVerifier = oidc.randomPKCECodeVerifier();
94
+ const codeChallenge = await oidc.calculatePKCECodeChallenge(codeVerifier);
95
+ const loginBinding = generateOpaqueSecret(SECRET_PREFIX.loginBinding);
96
+ const pending = this.store.insertPendingLogin({
97
+ stateVerifier: deriveVerifier("login_state", state),
98
+ bindingVerifier: deriveVerifier("login_binding", loginBinding),
99
+ codeVerifier,
100
+ nonce,
101
+ ttlMs: this.ttls.pendingLoginMs,
102
+ });
103
+ if (pending.status === "rate_limited")
104
+ throw new ControlError("rate_limited", "too many sign-ins are in progress");
105
+ const url = oidc.buildAuthorizationUrl(config, {
106
+ redirect_uri: this.redirectUri,
107
+ response_type: "code",
108
+ scope: "openid profile",
109
+ state,
110
+ nonce,
111
+ code_challenge: codeChallenge,
112
+ code_challenge_method: "S256",
113
+ });
114
+ return {
115
+ authorizationUrl: url.href,
116
+ loginBinding,
117
+ bindingMaxAgeSeconds: Math.floor(this.ttls.pendingLoginMs / 1000),
118
+ };
119
+ }
120
+ /**
121
+ * Finish sign-in and ensure the account's workspace exists. The pending login
122
+ * is consumed before any check runs, so a failed or replayed callback can
123
+ * never be completed later.
124
+ */
125
+ async completeLogin(input) {
126
+ const consumed = this.store.consumePendingLogin(deriveVerifier("login_state", input.query.state));
127
+ if (consumed.status !== "ok")
128
+ throw new ControlError("auth_failed", "login is unknown, expired, or already used");
129
+ const login = consumed.login;
130
+ if (input.loginBinding === null ||
131
+ !isOpaqueSecret(SECRET_PREFIX.loginBinding, input.loginBinding) ||
132
+ !constantTimeEqual(login.bindingVerifier, deriveVerifier("login_binding", input.loginBinding))) {
133
+ throw new ControlError("auth_failed", "login was started by a different browser");
134
+ }
135
+ if (input.query.error !== undefined)
136
+ throw new ControlError("auth_failed", "provider returned an error");
137
+ let claims;
138
+ try {
139
+ const config = await this.configuration();
140
+ const tokens = await oidc.authorizationCodeGrant(config, input.callbackUrl, {
141
+ pkceCodeVerifier: login.codeVerifier,
142
+ expectedState: input.query.state,
143
+ expectedNonce: login.nonce,
144
+ idTokenExpected: true,
145
+ });
146
+ claims = tokens.claims();
147
+ }
148
+ catch (error) {
149
+ throw classifyProviderError(error);
150
+ }
151
+ if (claims === undefined ||
152
+ typeof claims.iss !== "string" ||
153
+ claims.iss.length === 0 ||
154
+ claims.iss.length > 2048 ||
155
+ typeof claims.sub !== "string" ||
156
+ claims.sub.length === 0 ||
157
+ claims.sub.length > 255) {
158
+ throw new ControlError("auth_failed", "ID token lacks a usable issuer and subject");
159
+ }
160
+ const account = this.store.upsertAccount({
161
+ issuer: claims.iss,
162
+ subject: claims.sub,
163
+ displayName: displayNameFrom(claims),
164
+ });
165
+ const workspace = this.store.ensureWorkspace(account.id);
166
+ if (workspace.status !== "ok")
167
+ throw new ControlError("auth_failed", "account vanished during sign-in");
168
+ const secret = generateOpaqueSecret(SECRET_PREFIX.session);
169
+ const expiresAt = this.store.insertAccountSession({
170
+ id: generateControlId("ases"),
171
+ verifier: deriveVerifier("account_session", secret),
172
+ accountId: account.id,
173
+ ttlMs: this.ttls.accountSessionMs,
174
+ });
175
+ return { session: issuedSession(secret, expiresAt, this.ttls.accountSessionMs), account, workspace: workspace.tenant };
176
+ }
177
+ resolveAccountSession(secret) {
178
+ if (secret === null || !isOpaqueSecret(SECRET_PREFIX.session, secret))
179
+ return null;
180
+ return this.store.resolveAccountSession(deriveVerifier("account_session", secret));
181
+ }
182
+ logoutAccount(secret) {
183
+ if (secret === null || !isOpaqueSecret(SECRET_PREFIX.session, secret))
184
+ return;
185
+ this.store.revokeAccountSession(deriveVerifier("account_session", secret));
186
+ }
187
+ /** The session's account together with the workspace it owns, or `null`. */
188
+ resolveTenantMember(secret) {
189
+ if (secret === null || !isOpaqueSecret(SECRET_PREFIX.session, secret))
190
+ return null;
191
+ return this.store.resolveTenantMember(deriveVerifier("account_session", secret));
192
+ }
193
+ /** Workspace authority for a browser request, from its Cookie header. */
194
+ resolveTenantMemberFromCookies(cookieHeader) {
195
+ return this.resolveTenantMember(readSingleCookie(cookieHeader, ACCOUNT_SESSION_COOKIE));
196
+ }
197
+ }
198
+ //# sourceMappingURL=account-auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-auth.js","sourceRoot":"","sources":["../../../src/dashboard-gateway/control-plane/account-auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AAGtC,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,GACf,MAAM,cAAc,CAAC;AAStB,MAAM,CAAC,MAAM,kBAAkB,GAAG,4BAA4B,CAAC;AAO/D,MAAM,CAAC,MAAM,yBAAyB,GAAoB;IACxD,cAAc,EAAE,EAAE,GAAG,MAAM;IAC3B,gBAAgB,EAAE,EAAE,GAAG,EAAE,GAAG,MAAM;CACnC,CAAC;AAyCF,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC;IACrC,eAAe;IACf,aAAa;IACb,+BAA+B;IAC/B,4BAA4B;CAC7B,CAAC,CAAC;AAEH,SAAS,qBAAqB,CAAC,KAAc;IAC3C,IAAI,KAAK,YAAY,YAAY;QAAE,OAAO,KAAK,CAAC;IAChD,IAAI,KAAK,YAAY,SAAS;QAAE,OAAO,IAAI,YAAY,CAAC,sBAAsB,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7G,IAAI,KAAK,YAAY,IAAI,CAAC,WAAW,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,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