clinkx 1.2.0 → 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 (270) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +4 -2
  3. package/clinkx-workflows/dist/architecture-arena/admission.d.ts +16 -0
  4. package/clinkx-workflows/dist/architecture-arena/admission.js +107 -0
  5. package/clinkx-workflows/dist/architecture-arena/admission.js.map +1 -0
  6. package/clinkx-workflows/dist/architecture-arena/contract.d.ts +1368 -0
  7. package/clinkx-workflows/dist/architecture-arena/contract.js +254 -0
  8. package/clinkx-workflows/dist/architecture-arena/contract.js.map +1 -0
  9. package/clinkx-workflows/dist/architecture-arena/runtime.d.ts +53 -0
  10. package/clinkx-workflows/dist/architecture-arena/runtime.js +511 -0
  11. package/clinkx-workflows/dist/architecture-arena/runtime.js.map +1 -0
  12. package/clinkx-workflows/dist/architecture-comparison/admission.d.ts +17 -1
  13. package/clinkx-workflows/dist/architecture-comparison/admission.js +27 -4
  14. package/clinkx-workflows/dist/architecture-comparison/admission.js.map +1 -1
  15. package/clinkx-workflows/dist/architecture-comparison/contract.d.ts +59 -62
  16. package/clinkx-workflows/dist/architecture-comparison/contract.js +4 -21
  17. package/clinkx-workflows/dist/architecture-comparison/contract.js.map +1 -1
  18. package/clinkx-workflows/dist/architecture-comparison/runtime.d.ts +4 -3
  19. package/clinkx-workflows/dist/architecture-comparison/runtime.js +22 -67
  20. package/clinkx-workflows/dist/architecture-comparison/runtime.js.map +1 -1
  21. package/clinkx-workflows/dist/artifacts.d.ts +19 -4
  22. package/clinkx-workflows/dist/artifacts.js +16 -7
  23. package/clinkx-workflows/dist/artifacts.js.map +1 -1
  24. package/clinkx-workflows/dist/backend.d.ts +30 -0
  25. package/clinkx-workflows/dist/clink-client.d.ts +8 -2
  26. package/clinkx-workflows/dist/clink-client.js +4 -2
  27. package/clinkx-workflows/dist/clink-client.js.map +1 -1
  28. package/clinkx-workflows/dist/context-preflight.d.ts +6 -0
  29. package/clinkx-workflows/dist/context-preflight.js.map +1 -1
  30. package/clinkx-workflows/dist/council-execution-policy.d.ts +3 -1
  31. package/clinkx-workflows/dist/council-execution-policy.js +4 -0
  32. package/clinkx-workflows/dist/council-execution-policy.js.map +1 -1
  33. package/clinkx-workflows/dist/dashboard/contracts.d.ts +586 -586
  34. package/clinkx-workflows/dist/dashboard/progress-report-contract.d.ts +28 -28
  35. package/clinkx-workflows/dist/dashboard/session-log-contract.d.ts +32 -32
  36. package/clinkx-workflows/dist/dashboard-ui/assets/index-DRId2DVA.js +119 -0
  37. package/clinkx-workflows/dist/dashboard-ui/assets/style-CHAw57y5.css +1 -0
  38. package/clinkx-workflows/dist/dashboard-ui/index.html +2 -2
  39. package/clinkx-workflows/dist/delegate-signature.d.ts +4 -3
  40. package/clinkx-workflows/dist/delegate-signature.js +4 -3
  41. package/clinkx-workflows/dist/delegate-signature.js.map +1 -1
  42. package/clinkx-workflows/dist/durable-file.d.ts +69 -0
  43. package/clinkx-workflows/dist/durable-file.js +145 -0
  44. package/clinkx-workflows/dist/durable-file.js.map +1 -0
  45. package/clinkx-workflows/dist/engine.d.ts +42 -7
  46. package/clinkx-workflows/dist/engine.js +196 -24
  47. package/clinkx-workflows/dist/engine.js.map +1 -1
  48. package/clinkx-workflows/dist/ping-pong/admission.d.ts +127 -0
  49. package/clinkx-workflows/dist/ping-pong/admission.js +522 -0
  50. package/clinkx-workflows/dist/ping-pong/admission.js.map +1 -0
  51. package/clinkx-workflows/dist/ping-pong/contract.d.ts +2539 -0
  52. package/clinkx-workflows/dist/ping-pong/contract.js +819 -0
  53. package/clinkx-workflows/dist/ping-pong/contract.js.map +1 -0
  54. package/clinkx-workflows/dist/ping-pong/control.d.ts +67 -0
  55. package/clinkx-workflows/dist/ping-pong/control.js +12 -0
  56. package/clinkx-workflows/dist/ping-pong/control.js.map +1 -0
  57. package/clinkx-workflows/dist/ping-pong/runtime-handle.d.ts +24 -0
  58. package/clinkx-workflows/dist/ping-pong/runtime-handle.js +55 -0
  59. package/clinkx-workflows/dist/ping-pong/runtime-handle.js.map +1 -0
  60. package/clinkx-workflows/dist/ping-pong/runtime.d.ts +235 -0
  61. package/clinkx-workflows/dist/ping-pong/runtime.js +1183 -0
  62. package/clinkx-workflows/dist/ping-pong/runtime.js.map +1 -0
  63. package/clinkx-workflows/dist/ping-pong/settle.d.ts +57 -0
  64. package/clinkx-workflows/dist/ping-pong/settle.js +58 -0
  65. package/clinkx-workflows/dist/ping-pong/settle.js.map +1 -0
  66. package/clinkx-workflows/dist/ping-pong/sidecar.d.ts +65 -0
  67. package/clinkx-workflows/dist/ping-pong/sidecar.js +138 -0
  68. package/clinkx-workflows/dist/ping-pong/sidecar.js.map +1 -0
  69. package/clinkx-workflows/dist/plan-review/publication.d.ts +2 -1
  70. package/clinkx-workflows/dist/plan-review/publication.js +5 -6
  71. package/clinkx-workflows/dist/plan-review/publication.js.map +1 -1
  72. package/clinkx-workflows/dist/plan-review/snapshot.d.ts +3 -2
  73. package/clinkx-workflows/dist/plan-review/snapshot.js +8 -8
  74. package/clinkx-workflows/dist/plan-review/snapshot.js.map +1 -1
  75. package/clinkx-workflows/dist/recipe-host.d.ts +315 -0
  76. package/clinkx-workflows/dist/recipe-host.js +183 -0
  77. package/clinkx-workflows/dist/recipe-host.js.map +1 -0
  78. package/clinkx-workflows/dist/recipe-seats.d.ts +96 -0
  79. package/clinkx-workflows/dist/recipe-seats.js +163 -0
  80. package/clinkx-workflows/dist/recipe-seats.js.map +1 -0
  81. package/clinkx-workflows/dist/recipe-shared/evidence.d.ts +67 -0
  82. package/clinkx-workflows/dist/recipe-shared/evidence.js +111 -0
  83. package/clinkx-workflows/dist/recipe-shared/evidence.js.map +1 -0
  84. package/clinkx-workflows/dist/reducers/index.d.ts +9 -1
  85. package/clinkx-workflows/dist/reducers/index.js +30 -0
  86. package/clinkx-workflows/dist/reducers/index.js.map +1 -1
  87. package/clinkx-workflows/dist/run-lock-reclaim.d.ts +44 -0
  88. package/clinkx-workflows/dist/run-lock-reclaim.js +86 -0
  89. package/clinkx-workflows/dist/run-lock-reclaim.js.map +1 -0
  90. package/clinkx-workflows/dist/state-schema.d.ts +11 -0
  91. package/clinkx-workflows/dist/state-schema.js +4 -1
  92. package/clinkx-workflows/dist/state-schema.js.map +1 -1
  93. package/clinkx-workflows/dist/state.d.ts +178 -3
  94. package/clinkx-workflows/dist/state.js +618 -83
  95. package/clinkx-workflows/dist/state.js.map +1 -1
  96. package/clinkx-workflows/dist/transport.d.ts +2 -1
  97. package/clinkx-workflows/dist/transport.js +5 -0
  98. package/clinkx-workflows/dist/transport.js.map +1 -1
  99. package/clinkx-workflows/dist/validators/architecture-arena.d.ts +6 -0
  100. package/clinkx-workflows/dist/validators/architecture-arena.js +16 -0
  101. package/clinkx-workflows/dist/validators/architecture-arena.js.map +1 -0
  102. package/clinkx-workflows/dist/validators/index.js +4 -0
  103. package/clinkx-workflows/dist/validators/index.js.map +1 -1
  104. package/clinkx-workflows/dist/validators/ping-pong.d.ts +6 -0
  105. package/clinkx-workflows/dist/validators/ping-pong.js +10 -0
  106. package/clinkx-workflows/dist/validators/ping-pong.js.map +1 -0
  107. package/clinkx-workflows/dist/workflow-tools.d.ts +51 -5
  108. package/clinkx-workflows/dist/workflow-tools.js +785 -34
  109. package/clinkx-workflows/dist/workflow-tools.js.map +1 -1
  110. package/clinkx-workflows/dist/workflow-verification-contract.d.ts +4 -4
  111. package/clinkx-workflows/templates/architecture-arena/candidate.txt +39 -0
  112. package/clinkx-workflows/templates/architecture-arena/judge.txt +34 -0
  113. package/clinkx-workflows/templates/ping-pong/implement.txt +14 -0
  114. package/clinkx-workflows/templates/ping-pong/remediate.txt +14 -0
  115. package/clinkx-workflows/templates/ping-pong/review.txt +27 -0
  116. package/clinkx-workflows/workflows/architecture-arena.yaml +127 -0
  117. package/clinkx-workflows/workflows/ping-pong.yaml +158 -0
  118. package/dist/context-builder/bundle.js +4 -3
  119. package/dist/context-builder/bundle.js.map +1 -1
  120. package/dist/context-builder/delegate-packet.d.ts +1 -0
  121. package/dist/context-builder/delegate-packet.js +66 -7
  122. package/dist/context-builder/delegate-packet.js.map +1 -1
  123. package/dist/context-builder/delegate-validation.d.ts +12 -3
  124. package/dist/context-builder/delegate-validation.js +23 -13
  125. package/dist/context-builder/delegate-validation.js.map +1 -1
  126. package/dist/context-builder/external-gaps.d.ts +14 -3
  127. package/dist/context-builder/external-gaps.js +124 -18
  128. package/dist/context-builder/external-gaps.js.map +1 -1
  129. package/dist/context-builder/handler.js +108 -191
  130. package/dist/context-builder/handler.js.map +1 -1
  131. package/dist/context-builder/review-coverage.js +27 -1
  132. package/dist/context-builder/review-coverage.js.map +1 -1
  133. package/dist/context-builder/secrets.js +1 -1
  134. package/dist/context-builder/secrets.js.map +1 -1
  135. package/dist/context-builder/versions.d.ts +10 -4
  136. package/dist/context-builder/versions.js +10 -4
  137. package/dist/context-builder/versions.js.map +1 -1
  138. package/dist/context-builder/workflow-runner.js +33 -24
  139. package/dist/context-builder/workflow-runner.js.map +1 -1
  140. package/dist/dashboard-cli.d.ts +2 -0
  141. package/dist/dashboard-cli.js +147 -57
  142. package/dist/dashboard-cli.js.map +1 -1
  143. package/dist/dashboard-companion/client.d.ts +10 -0
  144. package/dist/dashboard-companion/client.js +43 -1
  145. package/dist/dashboard-companion/client.js.map +1 -1
  146. package/dist/dashboard-companion/config.d.ts +19 -1
  147. package/dist/dashboard-companion/config.js +104 -3
  148. package/dist/dashboard-companion/config.js.map +1 -1
  149. package/dist/dashboard-companion/protocol.d.ts +16 -0
  150. package/dist/dashboard-companion/protocol.js +38 -1
  151. package/dist/dashboard-companion/protocol.js.map +1 -1
  152. package/dist/dashboard-companion/workstation-binding.d.ts +69 -0
  153. package/dist/dashboard-companion/workstation-binding.js +192 -0
  154. package/dist/dashboard-companion/workstation-binding.js.map +1 -0
  155. package/dist/dashboard-gateway/admin-cli.d.ts +10 -0
  156. package/dist/dashboard-gateway/admin-cli.js +266 -0
  157. package/dist/dashboard-gateway/admin-cli.js.map +1 -0
  158. package/dist/dashboard-gateway/config.d.ts +50 -0
  159. package/dist/dashboard-gateway/config.js +235 -1
  160. package/dist/dashboard-gateway/config.js.map +1 -1
  161. package/dist/dashboard-gateway/connection-registry.d.ts +100 -0
  162. package/dist/dashboard-gateway/connection-registry.js +228 -0
  163. package/dist/dashboard-gateway/connection-registry.js.map +1 -0
  164. package/dist/dashboard-gateway/control-plane/account-auth.d.ts +78 -0
  165. package/dist/dashboard-gateway/control-plane/account-auth.js +198 -0
  166. package/dist/dashboard-gateway/control-plane/account-auth.js.map +1 -0
  167. package/dist/dashboard-gateway/control-plane/billing.d.ts +264 -0
  168. package/dist/dashboard-gateway/control-plane/billing.js +787 -0
  169. package/dist/dashboard-gateway/control-plane/billing.js.map +1 -0
  170. package/dist/dashboard-gateway/control-plane/contracts.d.ts +1293 -0
  171. package/dist/dashboard-gateway/control-plane/contracts.js +280 -0
  172. package/dist/dashboard-gateway/control-plane/contracts.js.map +1 -0
  173. package/dist/dashboard-gateway/control-plane/cookies.d.ts +13 -0
  174. package/dist/dashboard-gateway/control-plane/cookies.js +46 -0
  175. package/dist/dashboard-gateway/control-plane/cookies.js.map +1 -0
  176. package/dist/dashboard-gateway/control-plane/credentials.d.ts +63 -0
  177. package/dist/dashboard-gateway/control-plane/credentials.js +66 -0
  178. package/dist/dashboard-gateway/control-plane/credentials.js.map +1 -0
  179. package/dist/dashboard-gateway/control-plane/entitlements.d.ts +118 -0
  180. package/dist/dashboard-gateway/control-plane/entitlements.js +329 -0
  181. package/dist/dashboard-gateway/control-plane/entitlements.js.map +1 -0
  182. package/dist/dashboard-gateway/control-plane/errors.d.ts +17 -0
  183. package/dist/dashboard-gateway/control-plane/errors.js +23 -0
  184. package/dist/dashboard-gateway/control-plane/errors.js.map +1 -0
  185. package/dist/dashboard-gateway/control-plane/hosts.d.ts +6 -0
  186. package/dist/dashboard-gateway/control-plane/hosts.js +16 -0
  187. package/dist/dashboard-gateway/control-plane/hosts.js.map +1 -0
  188. package/dist/dashboard-gateway/control-plane/http.d.ts +34 -0
  189. package/dist/dashboard-gateway/control-plane/http.js +331 -0
  190. package/dist/dashboard-gateway/control-plane/http.js.map +1 -0
  191. package/dist/dashboard-gateway/control-plane/schema.d.ts +9 -0
  192. package/dist/dashboard-gateway/control-plane/schema.js +247 -0
  193. package/dist/dashboard-gateway/control-plane/schema.js.map +1 -0
  194. package/dist/dashboard-gateway/control-plane/secrets.d.ts +20 -0
  195. package/dist/dashboard-gateway/control-plane/secrets.js +39 -0
  196. package/dist/dashboard-gateway/control-plane/secrets.js.map +1 -0
  197. package/dist/dashboard-gateway/control-plane/store.d.ts +579 -0
  198. package/dist/dashboard-gateway/control-plane/store.js +1115 -0
  199. package/dist/dashboard-gateway/control-plane/store.js.map +1 -0
  200. package/dist/dashboard-gateway/cookie-boundary.d.ts +60 -0
  201. package/dist/dashboard-gateway/cookie-boundary.js +205 -0
  202. package/dist/dashboard-gateway/cookie-boundary.js.map +1 -0
  203. package/dist/dashboard-gateway/index.js +271 -494
  204. package/dist/dashboard-gateway/index.js.map +1 -1
  205. package/dist/dashboard-gateway/main.js +7 -2
  206. package/dist/dashboard-gateway/main.js.map +1 -1
  207. package/dist/dashboard-gateway/routing.d.ts +43 -0
  208. package/dist/dashboard-gateway/routing.js +65 -0
  209. package/dist/dashboard-gateway/routing.js.map +1 -0
  210. package/dist/dashboard-gateway/tenant-gateway.d.ts +56 -0
  211. package/dist/dashboard-gateway/tenant-gateway.js +989 -0
  212. package/dist/dashboard-gateway/tenant-gateway.js.map +1 -0
  213. package/dist/dashboard-gateway/tenant-main.d.ts +41 -0
  214. package/dist/dashboard-gateway/tenant-main.js +303 -0
  215. package/dist/dashboard-gateway/tenant-main.js.map +1 -0
  216. package/dist/dashboard-gateway/tunnel-errors.d.ts +16 -0
  217. package/dist/dashboard-gateway/tunnel-errors.js +22 -0
  218. package/dist/dashboard-gateway/tunnel-errors.js.map +1 -0
  219. package/dist/dashboard-gateway/tunnel-http.d.ts +21 -0
  220. package/dist/dashboard-gateway/tunnel-http.js +175 -0
  221. package/dist/dashboard-gateway/tunnel-http.js.map +1 -0
  222. package/dist/handler.d.ts +6 -0
  223. package/dist/handler.js +17 -1
  224. package/dist/handler.js.map +1 -1
  225. package/dist/local-clink-backend.d.ts +2 -1
  226. package/dist/local-clink-backend.js +28 -4
  227. package/dist/local-clink-backend.js.map +1 -1
  228. package/dist/parsers/extract.d.ts +19 -1
  229. package/dist/parsers/extract.js +68 -3
  230. package/dist/parsers/extract.js.map +1 -1
  231. package/dist/pipeline.d.ts +17 -1
  232. package/dist/pipeline.js +34 -6
  233. package/dist/pipeline.js.map +1 -1
  234. package/dist/process-group.d.ts +65 -0
  235. package/dist/process-group.js +153 -0
  236. package/dist/process-group.js.map +1 -0
  237. package/dist/progress-report/schema.d.ts +23 -23
  238. package/dist/project-verification/files.js +1 -1
  239. package/dist/project-verification/files.js.map +1 -1
  240. package/dist/project-verification/process.js +23 -44
  241. package/dist/project-verification/process.js.map +1 -1
  242. package/dist/project-verification/service.js +9 -1
  243. package/dist/project-verification/service.js.map +1 -1
  244. package/dist/prompt.d.ts +7 -0
  245. package/dist/prompt.js +18 -1
  246. package/dist/prompt.js.map +1 -1
  247. package/dist/recipe-host/git-trust.d.ts +43 -0
  248. package/dist/recipe-host/git-trust.js +360 -0
  249. package/dist/recipe-host/git-trust.js.map +1 -0
  250. package/dist/recipe-host/git.d.ts +42 -0
  251. package/dist/recipe-host/git.js +207 -0
  252. package/dist/recipe-host/git.js.map +1 -0
  253. package/dist/recipe-host/native-recipe-host.d.ts +127 -0
  254. package/dist/recipe-host/native-recipe-host.js +880 -0
  255. package/dist/recipe-host/native-recipe-host.js.map +1 -0
  256. package/dist/recipe-host/seat-cwd.d.ts +16 -0
  257. package/dist/recipe-host/seat-cwd.js +170 -0
  258. package/dist/recipe-host/seat-cwd.js.map +1 -0
  259. package/dist/runner.d.ts +43 -1
  260. package/dist/runner.js +234 -35
  261. package/dist/runner.js.map +1 -1
  262. package/dist/server.js +9 -1
  263. package/dist/server.js.map +1 -1
  264. package/docs/configuration.md +24 -3
  265. package/docs/engineering-recipes.md +291 -0
  266. package/docs/security.md +84 -0
  267. package/docs/verification/project-checks.md +24 -2
  268. package/package.json +5 -1
  269. package/clinkx-workflows/dist/dashboard-ui/assets/index-BdpmbPps.js +0 -115
  270. package/clinkx-workflows/dist/dashboard-ui/assets/style-Im5i1iAs.css +0 -1
@@ -0,0 +1,329 @@
1
+ function denied(reason) {
2
+ return { allowed: false, reason, nextDeadline: null };
3
+ }
4
+ function until(cutoff, now, grantReason, expiredReason) {
5
+ if (cutoff === null)
6
+ return denied("unknown_state");
7
+ return now < cutoff ? { allowed: true, reason: grantReason, nextDeadline: cutoff } : denied(expiredReason);
8
+ }
9
+ function purchaseAccess(entitlement, now) {
10
+ switch (entitlement.subscriptionState) {
11
+ case "active":
12
+ case "trialing":
13
+ return until(entitlement.currentPeriodEnd, now, "paid_period", "period_ended");
14
+ case "past_due":
15
+ if (entitlement.graceDeadline === null)
16
+ return denied("grace_expired");
17
+ return until(entitlement.graceDeadline, now, "past_due_grace", "grace_expired");
18
+ case "incomplete":
19
+ return denied("payment_pending");
20
+ case "none":
21
+ return denied("no_purchase");
22
+ case "incomplete_expired":
23
+ case "unpaid":
24
+ case "canceled":
25
+ case "paused":
26
+ return denied("subscription_inactive");
27
+ case "unknown":
28
+ return denied("unknown_state");
29
+ }
30
+ }
31
+ /** The operator grant's cutoff while it still allows access, else `null`. */
32
+ export function activeGrantUntil(entitlement, now) {
33
+ const cutoff = entitlement?.grantExpiresAt ?? null;
34
+ return cutoff !== null && now < cutoff ? cutoff : null;
35
+ }
36
+ /**
37
+ * The access predicate over stored state and UTC deadlines only. Access ends
38
+ * exactly at the stored cutoff; a missing cutoff is a denial, never perpetual
39
+ * access. Suspension is checked first and nothing in billing state or an
40
+ * operator grant overrides it. An unexpired operator grant allows access on
41
+ * its own; when a purchase also allows, the purchase reason is reported and the
42
+ * later cutoff applies. Device credential revocation is a separate check on the device path.
43
+ */
44
+ export function evaluateEntitlementAccess(entitlement, now) {
45
+ if (!Number.isSafeInteger(now) || now <= 0)
46
+ throw new Error("access decisions need a valid UTC millisecond time");
47
+ if (entitlement === null)
48
+ return denied("no_purchase");
49
+ if (entitlement.suspendedAt !== null)
50
+ return denied("suspended");
51
+ const purchase = purchaseAccess(entitlement, now);
52
+ const grantUntil = activeGrantUntil(entitlement, now);
53
+ if (grantUntil === null)
54
+ return purchase;
55
+ if (!purchase.allowed || purchase.nextDeadline === null) {
56
+ return { allowed: true, reason: "operator_grant", nextDeadline: grantUntil };
57
+ }
58
+ return { allowed: true, reason: purchase.reason, nextDeadline: Math.max(purchase.nextDeadline, grantUntil) };
59
+ }
60
+ /**
61
+ * Whether a bound purchase is due for reconciliation. Informational only: it
62
+ * never grants, extends, or cuts access.
63
+ */
64
+ export function isEntitlementStale(entitlement, now, maxStalenessMs) {
65
+ if (entitlement === null || entitlement.stripeCustomerId === null)
66
+ return false;
67
+ return entitlement.lastReconciledAt === null || now - entitlement.lastReconciledAt > maxStalenessMs;
68
+ }
69
+ function iso(value) {
70
+ return value === null ? null : new Date(value).toISOString();
71
+ }
72
+ /** `maxStalenessMs` is `null` when billing is off: nothing reconciles, so nothing is reported stale. */
73
+ export function describeEntitlement(entitlement, now, maxStalenessMs) {
74
+ const decision = evaluateEntitlementAccess(entitlement, now);
75
+ return {
76
+ access: decision.allowed ? "granted" : "denied",
77
+ reason: decision.reason,
78
+ subscription_state: entitlement?.subscriptionState ?? "none",
79
+ access_until: iso(decision.nextDeadline),
80
+ grace_deadline: iso(entitlement?.graceDeadline ?? null),
81
+ suspended: entitlement?.suspendedAt != null,
82
+ grant_until: iso(activeGrantUntil(entitlement, now)),
83
+ last_reconciled_at: iso(entitlement?.lastReconciledAt ?? null),
84
+ stale: maxStalenessMs !== null && isEntitlementStale(entitlement, now, maxStalenessMs),
85
+ };
86
+ }
87
+ function positiveSeconds(name, value) {
88
+ if (!Number.isSafeInteger(value) || value <= 0 || !Number.isSafeInteger(value * 1000)) {
89
+ throw new Error(`${name} must be a positive whole number of seconds`);
90
+ }
91
+ return value * 1000;
92
+ }
93
+ export function createTenantAccessAuthority(options) {
94
+ const { store } = options;
95
+ const { billing } = options.config;
96
+ const graceMs = billing === null ? null : positiveSeconds("billing.graceSeconds", billing.graceSeconds);
97
+ const maxStalenessMs = billing === null ? null : positiveSeconds("billing.maxStalenessSeconds", billing.maxStalenessSeconds);
98
+ function decideTenantAccess(tenantId) {
99
+ const snapshot = store.readEntitlementAccess(tenantId);
100
+ return evaluateEntitlementAccess(snapshot.entitlement, snapshot.now);
101
+ }
102
+ return {
103
+ async checkTenantAccess(tenantId) {
104
+ try {
105
+ return decideTenantAccess(tenantId).allowed ? { ok: true } : { ok: false, code: "entitlement_inactive" };
106
+ }
107
+ catch (error) {
108
+ options.onError?.(error);
109
+ return { ok: false, code: "store_unavailable" };
110
+ }
111
+ },
112
+ decideTenantAccess,
113
+ entitlementStatus(tenantId) {
114
+ const snapshot = store.readEntitlementAccess(tenantId);
115
+ return describeEntitlement(snapshot.entitlement, snapshot.now, maxStalenessMs);
116
+ },
117
+ applyPastDue(input) {
118
+ if (graceMs === null)
119
+ throw new Error("billing is off; past-due purchases cannot be applied");
120
+ return store.applyPastDue({ ...input, graceMs });
121
+ },
122
+ };
123
+ }
124
+ /** Node clamps `setTimeout` delays above this to 1 ms. */
125
+ export const MAX_TIMER_DELAY_MS = 2_147_483_647;
126
+ export const DEFAULT_SCHEDULER_RETRY_MS = 5_000;
127
+ /** How often the gateway re-reads every entitlement to observe writes made by another process, such as the admin CLI. */
128
+ export const ENTITLEMENT_RESCAN_INTERVAL_MS = 60_000;
129
+ const NODE_TIMERS = {
130
+ setTimeout(callback, delayMs) {
131
+ const handle = setTimeout(callback, delayMs);
132
+ handle.unref();
133
+ return handle;
134
+ },
135
+ clearTimeout(handle) {
136
+ clearTimeout(handle);
137
+ },
138
+ };
139
+ function expiredReason(reason) {
140
+ if (reason === "operator_grant")
141
+ return "no_purchase";
142
+ return reason === "past_due_grace" ? "grace_expired" : "period_ended";
143
+ }
144
+ /**
145
+ * One in-process timer for the earliest upcoming access deadline. Stored
146
+ * deadlines stop access without any webhook: the timer re-scans the store when
147
+ * the earliest deadline arrives, and if the store cannot be read then, every
148
+ * known deadline that has passed is still enforced from memory.
149
+ *
150
+ * The startup scan reports every tenant without access, so a gateway that
151
+ * admitted connections before the scan, or a deadline that passed while the
152
+ * process was down, still results in a cutoff. After that a changed `allowed`
153
+ * is reported, and so is a denial read at a different revision than the last
154
+ * observation: between two rescans another process can grant access, let a
155
+ * companion connect, and deny it again, which no change of `allowed` reveals.
156
+ */
157
+ export function createEntitlementDeadlineScheduler(options) {
158
+ const { store } = options;
159
+ const now = options.now ?? Date.now;
160
+ const timers = options.timers ?? NODE_TIMERS;
161
+ const retryDelayMs = options.retryDelayMs ?? DEFAULT_SCHEDULER_RETRY_MS;
162
+ if (!Number.isSafeInteger(retryDelayMs) || retryDelayMs <= 0 || retryDelayMs > MAX_TIMER_DELAY_MS) {
163
+ throw new Error("retryDelayMs must be a positive timer delay");
164
+ }
165
+ const rescanIntervalMs = options.rescanIntervalMs ?? null;
166
+ if (rescanIntervalMs !== null &&
167
+ (!Number.isSafeInteger(rescanIntervalMs) || rescanIntervalMs <= 0 || rescanIntervalMs > MAX_TIMER_DELAY_MS)) {
168
+ throw new Error("rescanIntervalMs must be a positive timer delay");
169
+ }
170
+ const known = new Map();
171
+ let running = false;
172
+ let unsubscribe = null;
173
+ let timer = null;
174
+ let periodic = null;
175
+ let wakeAt = null;
176
+ let retryAt = null;
177
+ function report(error) {
178
+ try {
179
+ options.onError?.(error);
180
+ }
181
+ catch {
182
+ // Diagnostics must not break deadline enforcement.
183
+ }
184
+ }
185
+ function apply(tenantId, decision, revision) {
186
+ const previous = known.get(tenantId);
187
+ known.set(tenantId, { decision, revision });
188
+ const changed = previous === undefined
189
+ ? !decision.allowed
190
+ : previous.decision.allowed !== decision.allowed || (!decision.allowed && previous.revision !== revision);
191
+ if (!changed)
192
+ return;
193
+ try {
194
+ options.onAccessChange(tenantId, decision);
195
+ }
196
+ catch (error) {
197
+ report(error);
198
+ }
199
+ }
200
+ function forget(tenantId) {
201
+ const previous = known.get(tenantId);
202
+ if (previous === undefined)
203
+ return;
204
+ apply(tenantId, denied("no_purchase"), previous.revision);
205
+ known.delete(tenantId);
206
+ }
207
+ function expireKnown(at) {
208
+ for (const [tenantId, { decision, revision }] of [...known]) {
209
+ if (decision.allowed && decision.nextDeadline !== null && decision.nextDeadline <= at) {
210
+ apply(tenantId, denied(expiredReason(decision.reason)), revision);
211
+ }
212
+ }
213
+ }
214
+ /**
215
+ * A failed read leaves stored state unobserved until a full rescan succeeds.
216
+ * A pending retry time is absolute and only ever moves earlier, so later
217
+ * writes that re-arm the timer cannot postpone it. A rescan consumes a due
218
+ * retry before it runs, so a failed attempt schedules a fresh one.
219
+ */
220
+ function requestRetry() {
221
+ const at = now() + retryDelayMs;
222
+ if (retryAt === null || at < retryAt)
223
+ retryAt = at;
224
+ }
225
+ function disarm() {
226
+ if (timer !== null)
227
+ timers.clearTimeout(timer);
228
+ timer = null;
229
+ wakeAt = null;
230
+ }
231
+ function arm() {
232
+ disarm();
233
+ if (!running)
234
+ return;
235
+ const current = now();
236
+ let earliest = retryAt ?? Number.POSITIVE_INFINITY;
237
+ for (const { decision } of known.values()) {
238
+ if (decision.allowed && decision.nextDeadline !== null && decision.nextDeadline < earliest)
239
+ earliest = decision.nextDeadline;
240
+ }
241
+ if (earliest === Number.POSITIVE_INFINITY)
242
+ return;
243
+ const delay = Math.min(Math.max(earliest - current, 0), MAX_TIMER_DELAY_MS);
244
+ wakeAt = current + delay;
245
+ timer = timers.setTimeout(() => {
246
+ timer = null;
247
+ wakeAt = null;
248
+ rescan();
249
+ }, delay);
250
+ }
251
+ function schedulePeriodic() {
252
+ if (rescanIntervalMs === null || !running)
253
+ return;
254
+ periodic = timers.setTimeout(() => {
255
+ periodic = null;
256
+ rescan();
257
+ schedulePeriodic();
258
+ }, rescanIntervalMs);
259
+ }
260
+ function rescan() {
261
+ if (!running)
262
+ return;
263
+ if (retryAt !== null && retryAt <= now())
264
+ retryAt = null;
265
+ try {
266
+ const snapshot = store.snapshotEntitlements();
267
+ const seen = new Set();
268
+ for (const entitlement of snapshot.entitlements) {
269
+ seen.add(entitlement.tenantId);
270
+ apply(entitlement.tenantId, evaluateEntitlementAccess(entitlement, snapshot.now), entitlement.revision);
271
+ }
272
+ for (const tenantId of [...known.keys()]) {
273
+ if (!seen.has(tenantId))
274
+ forget(tenantId);
275
+ }
276
+ retryAt = null;
277
+ }
278
+ catch (error) {
279
+ report(error);
280
+ expireKnown(now());
281
+ requestRetry();
282
+ }
283
+ arm();
284
+ }
285
+ function refresh(tenantId) {
286
+ if (!running)
287
+ return;
288
+ try {
289
+ const snapshot = store.readEntitlementAccess(tenantId);
290
+ if (snapshot.entitlement === null)
291
+ forget(tenantId);
292
+ else
293
+ apply(tenantId, evaluateEntitlementAccess(snapshot.entitlement, snapshot.now), snapshot.entitlement.revision);
294
+ }
295
+ catch (error) {
296
+ report(error);
297
+ requestRetry();
298
+ }
299
+ expireKnown(now());
300
+ arm();
301
+ }
302
+ return {
303
+ start() {
304
+ if (running)
305
+ return;
306
+ running = true;
307
+ unsubscribe = store.onEntitlementChange(refresh);
308
+ rescan();
309
+ schedulePeriodic();
310
+ },
311
+ stop() {
312
+ running = false;
313
+ unsubscribe?.();
314
+ unsubscribe = null;
315
+ disarm();
316
+ if (periodic !== null)
317
+ timers.clearTimeout(periodic);
318
+ periodic = null;
319
+ retryAt = null;
320
+ known.clear();
321
+ },
322
+ rescan,
323
+ refresh,
324
+ get nextWakeAt() {
325
+ return wakeAt;
326
+ },
327
+ };
328
+ }
329
+ //# sourceMappingURL=entitlements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entitlements.js","sourceRoot":"","sources":["../../../src/dashboard-gateway/control-plane/entitlements.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KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { ControlErrorCode } from "./contracts.js";
2
+ export declare class ControlError extends Error {
3
+ readonly code: ControlErrorCode;
4
+ constructor(code: ControlErrorCode, message?: string, options?: {
5
+ cause?: unknown;
6
+ });
7
+ }
8
+ /** Any failure to read or write durable control state. Callers must deny access. */
9
+ export declare class ControlStoreUnavailableError extends ControlError {
10
+ constructor(message?: string, options?: {
11
+ cause?: unknown;
12
+ });
13
+ }
14
+ /** The database file was written by a newer or foreign schema; the gateway must not start. */
15
+ export declare class ControlSchemaVersionError extends ControlStoreUnavailableError {
16
+ constructor(message: string);
17
+ }
@@ -0,0 +1,23 @@
1
+ export class ControlError extends Error {
2
+ code;
3
+ constructor(code, message, options) {
4
+ super(message ?? code, options);
5
+ this.name = "ControlError";
6
+ this.code = code;
7
+ }
8
+ }
9
+ /** Any failure to read or write durable control state. Callers must deny access. */
10
+ export class ControlStoreUnavailableError extends ControlError {
11
+ constructor(message = "control store unavailable", options) {
12
+ super("store_unavailable", message, options);
13
+ this.name = "ControlStoreUnavailableError";
14
+ }
15
+ }
16
+ /** The database file was written by a newer or foreign schema; the gateway must not start. */
17
+ export class ControlSchemaVersionError extends ControlStoreUnavailableError {
18
+ constructor(message) {
19
+ super(message);
20
+ this.name = "ControlSchemaVersionError";
21
+ }
22
+ }
23
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/dashboard-gateway/control-plane/errors.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,IAAI,CAAmB;IAEhC,YAAY,IAAsB,EAAE,OAAgB,EAAE,OAA6B;QACjF,KAAK,CAAC,OAAO,IAAI,IAAI,EAAE,OAAO,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED,oFAAoF;AACpF,MAAM,OAAO,4BAA6B,SAAQ,YAAY;IAC5D,YAAY,OAAO,GAAG,2BAA2B,EAAE,OAA6B;QAC9E,KAAK,CAAC,mBAAmB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAC7C,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAC;IAC7C,CAAC;CACF;AAED,8FAA8F;AAC9F,MAAM,OAAO,yBAA0B,SAAQ,4BAA4B;IACzE,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC1C,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Whether a request carries exactly one Host line naming the public origin.
3
+ * Matching is exact on the canonical lowercase host; the port may appear only
4
+ * as the HTTPS default.
5
+ */
6
+ export declare function isPublicHost(values: readonly string[] | undefined, publicOrigin: string): boolean;
@@ -0,0 +1,16 @@
1
+ const HTTPS_DEFAULT_PORT_SUFFIX = ":443";
2
+ /**
3
+ * Whether a request carries exactly one Host line naming the public origin.
4
+ * Matching is exact on the canonical lowercase host; the port may appear only
5
+ * as the HTTPS default.
6
+ */
7
+ export function isPublicHost(values, publicOrigin) {
8
+ if (values === undefined || values.length !== 1)
9
+ return false;
10
+ const host = values[0] ?? "";
11
+ if (host.length === 0 || host.length > 300 || host !== host.toLowerCase())
12
+ return false;
13
+ const hostname = host.endsWith(HTTPS_DEFAULT_PORT_SUFFIX) ? host.slice(0, -HTTPS_DEFAULT_PORT_SUFFIX.length) : host;
14
+ return !hostname.includes(":") && `https://${hostname}` === publicOrigin;
15
+ }
16
+ //# sourceMappingURL=hosts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosts.js","sourceRoot":"","sources":["../../../src/dashboard-gateway/control-plane/hosts.ts"],"names":[],"mappings":"AAAA,MAAM,yBAAyB,GAAG,MAAM,CAAC;AAEzC;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,MAAqC,EAAE,YAAoB;IACtF,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9D,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,IAAI,IAAI,KAAK,IAAI,CAAC,WAAW,EAAE;QAAE,OAAO,KAAK,CAAC;IACxF,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACpH,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,WAAW,QAAQ,EAAE,KAAK,YAAY,CAAC;AAC3E,CAAC"}
@@ -0,0 +1,34 @@
1
+ import type { IncomingMessage, ServerResponse } from "node:http";
2
+ import type { AccountAuthority } from "./account-auth.js";
3
+ import type { BillingHttpService } from "./billing.js";
4
+ import { type ControlRouteName, type EntitlementStatus } from "./contracts.js";
5
+ import type { DeviceCredentialAuthority } from "./credentials.js";
6
+ export declare const DEFAULT_CONTROL_MAX_BODY_BYTES: number;
7
+ export interface CompanionConnectionView {
8
+ readonly connectionGeneration: number;
9
+ }
10
+ export interface ControlPlaneHttpOptions {
11
+ /** The single public origin; every other Host is `misdirected_request`. */
12
+ readonly publicOrigin: string;
13
+ readonly accountAuth: AccountAuthority;
14
+ readonly credentials: DeviceCredentialAuthority;
15
+ /** Wire entitlement status for the workspace view. Throws when the store fails. */
16
+ readonly entitlementStatus: (tenantId: string) => EntitlementStatus;
17
+ /** Checkout, Portal, status, and webhook intake. Without it billing is off and every billing route is `not_found`. */
18
+ readonly billing?: BillingHttpService;
19
+ readonly maxBodyBytes?: number;
20
+ /** Live companion socket for a workstation, from the connection registry. */
21
+ readonly workstationConnection?: (companionId: string) => CompanionConnectionView | null;
22
+ /** Close every live socket of this workstation; returns how many closed. */
23
+ readonly closeWorkstationConnections?: (companionId: string) => number;
24
+ /** Diagnostics for unexpected failures. Never receives secrets from this module. */
25
+ readonly onError?: (error: unknown, route: ControlRouteName) => void;
26
+ }
27
+ /** Resolves `false` when the request is outside `/api/control/` so the caller can route it elsewhere. */
28
+ export type ControlPlaneHttpHandler = (request: IncomingMessage, response: ServerResponse) => Promise<boolean>;
29
+ /**
30
+ * Dispatch `/api/control/*` on the single public origin. Host and Origin are
31
+ * matched exactly, identity comes only from the account-session cookie and
32
+ * server records, and every unexpected failure denies with `store_unavailable`.
33
+ */
34
+ export declare function createControlPlaneHttpHandler(options: ControlPlaneHttpOptions): ControlPlaneHttpHandler;