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,69 @@
1
+ import { z } from "zod";
2
+ export declare const WORKSTATION_BINDING_FILENAME = "workstation-binding.json";
3
+ /**
4
+ * Ties this machine's passkey store to one workstation. It lives on the
5
+ * operator-override volume, never on the credential volume, so replacing the
6
+ * whole credential volume cannot also replace the identity it is checked against.
7
+ */
8
+ declare const WorkstationBindingSchema: z.ZodObject<{
9
+ version: z.ZodLiteral<1>;
10
+ companion_id: z.ZodString;
11
+ user_handle: z.ZodString;
12
+ rp_id: z.ZodString;
13
+ }, "strict", z.ZodTypeAny, {
14
+ version: 1;
15
+ companion_id: string;
16
+ user_handle: string;
17
+ rp_id: string;
18
+ }, {
19
+ version: 1;
20
+ companion_id: string;
21
+ user_handle: string;
22
+ rp_id: string;
23
+ }>;
24
+ export type WorkstationBinding = z.infer<typeof WorkstationBindingSchema>;
25
+ export type WorkstationBindingFailure = "rp_mismatch" | "passkey_volume_missing" | "passkey_volume_replaced" | "workstation_binding_mismatch" | "binding_unreadable";
26
+ export declare class WorkstationBindingError extends Error {
27
+ readonly reason: WorkstationBindingFailure;
28
+ constructor(reason: WorkstationBindingFailure, message: string);
29
+ }
30
+ /**
31
+ * An explicit operator-override directory holds the binding. Unset, that
32
+ * directory would be the state root, which contains the default credential
33
+ * directory, so the binding takes a sibling of `dashboard/webauthn` instead.
34
+ */
35
+ export declare function resolveWorkstationBindingDirectory(env?: NodeJS.ProcessEnv): string;
36
+ export declare function workstationBindingPath(directory: string): string;
37
+ /** `undefined` only when no binding exists; a present but unusable binding throws. */
38
+ export declare function readWorkstationBinding(directory: string): Promise<WorkstationBinding | undefined>;
39
+ /** Atomically publish the binding: private temp file, fsync, rename, then fsync the directory. */
40
+ export declare function writeWorkstationBinding(directory: string, binding: WorkstationBinding): Promise<void>;
41
+ /** Delete only the binding sidecar. Returns whether one existed. */
42
+ export declare function removeWorkstationBinding(directory: string): Promise<boolean>;
43
+ export declare function readPasskeyStoreIdentity(credentialDirectory: string): Promise<{
44
+ readonly rpId: string;
45
+ readonly userHandle: string;
46
+ }>;
47
+ /**
48
+ * The local checks, run before the passkey store opens and before the gateway
49
+ * is dialed. A bound store must still be the bound one: missing or empty,
50
+ * another RP ID, or another enrollment of the same RP ID all refuse to start.
51
+ * An unbound store for another RP ID refuses too. Nothing is modified.
52
+ */
53
+ export declare function inspectWorkstationBinding(input: {
54
+ readonly bindingDirectory: string;
55
+ readonly credentialDirectory: string;
56
+ readonly expectedRpId: string;
57
+ }): Promise<WorkstationBinding | undefined>;
58
+ /**
59
+ * The companion-id check, run when the gateway hello names the workstation
60
+ * the presented key belongs to. The first hello on an unbound store records
61
+ * the binding; later hellos must name the same workstation, so a key for
62
+ * another workstation is never served from this passkey store.
63
+ */
64
+ export declare function bindWorkstationOnHello(input: {
65
+ readonly bindingDirectory: string;
66
+ readonly credentialDirectory: string;
67
+ readonly companionId: string;
68
+ }): Promise<WorkstationBinding>;
69
+ export {};
@@ -0,0 +1,192 @@
1
+ import { randomBytes } from "node:crypto";
2
+ import { closeSync, fsyncSync, openSync } from "node:fs";
3
+ import { lstat, mkdir, open, readFile, rename, unlink } from "node:fs/promises";
4
+ import { join, resolve } from "node:path";
5
+ import { z } from "zod";
6
+ import { DASHBOARD_PROGRESS_REPORT_OVERRIDE_DIR_ENV, getProgressReportOverrideDir, getStateDir, } from "../../clinkx-workflows/dist/config.js";
7
+ import { inspectDashboardCredentialEnrollmentState } from "../../clinkx-workflows/dist/dashboard/auth/credential-store.js";
8
+ export const WORKSTATION_BINDING_FILENAME = "workstation-binding.json";
9
+ const MAX_WORKSTATION_BINDING_BYTES = 4 * 1_024;
10
+ /**
11
+ * Ties this machine's passkey store to one workstation. It lives on the
12
+ * operator-override volume, never on the credential volume, so replacing the
13
+ * whole credential volume cannot also replace the identity it is checked against.
14
+ */
15
+ const WorkstationBindingSchema = z
16
+ .object({
17
+ version: z.literal(1),
18
+ companion_id: z.string().regex(/^cmp_[A-Za-z0-9_-]{16,64}$/),
19
+ user_handle: z.string().min(1).max(512),
20
+ rp_id: z.string().min(1).max(253),
21
+ })
22
+ .strict();
23
+ export class WorkstationBindingError extends Error {
24
+ reason;
25
+ constructor(reason, message) {
26
+ super(`${reason}: ${message}`);
27
+ this.name = "WorkstationBindingError";
28
+ this.reason = reason;
29
+ }
30
+ }
31
+ const RESET_GUIDANCE = "restore the original volume, or stop the companion and run it once with --reset-passkey-binding to start a new local passkey enrollment";
32
+ function errnoCode(error) {
33
+ return error?.code;
34
+ }
35
+ /**
36
+ * An explicit operator-override directory holds the binding. Unset, that
37
+ * directory would be the state root, which contains the default credential
38
+ * directory, so the binding takes a sibling of `dashboard/webauthn` instead.
39
+ */
40
+ export function resolveWorkstationBindingDirectory(env = process.env) {
41
+ if ((env[DASHBOARD_PROGRESS_REPORT_OVERRIDE_DIR_ENV] ?? "") !== "")
42
+ return getProgressReportOverrideDir(env);
43
+ return join(resolve(getStateDir(env)), "dashboard", "binding");
44
+ }
45
+ export function workstationBindingPath(directory) {
46
+ return join(directory, WORKSTATION_BINDING_FILENAME);
47
+ }
48
+ /** `undefined` only when no binding exists; a present but unusable binding throws. */
49
+ export async function readWorkstationBinding(directory) {
50
+ const path = workstationBindingPath(directory);
51
+ let entry;
52
+ try {
53
+ entry = await lstat(path);
54
+ }
55
+ catch (error) {
56
+ if (errnoCode(error) === "ENOENT")
57
+ return undefined;
58
+ throw error;
59
+ }
60
+ const unreadable = (detail) => new WorkstationBindingError("binding_unreadable", `${path} ${detail}; ${RESET_GUIDANCE}`);
61
+ if (entry.isSymbolicLink() || !entry.isFile())
62
+ throw unreadable("is not a regular file");
63
+ if ((entry.mode & 0o077) !== 0)
64
+ throw unreadable("must not be readable by group or others");
65
+ if (entry.size > MAX_WORKSTATION_BINDING_BYTES)
66
+ throw unreadable("exceeds the size limit");
67
+ let value;
68
+ try {
69
+ value = JSON.parse(await readFile(path, "utf8"));
70
+ }
71
+ catch {
72
+ throw unreadable("is not valid JSON");
73
+ }
74
+ const parsed = WorkstationBindingSchema.safeParse(value);
75
+ if (!parsed.success)
76
+ throw unreadable("is invalid");
77
+ return parsed.data;
78
+ }
79
+ function syncDirectory(directory) {
80
+ const descriptor = openSync(directory, "r");
81
+ try {
82
+ fsyncSync(descriptor);
83
+ }
84
+ finally {
85
+ closeSync(descriptor);
86
+ }
87
+ }
88
+ /** Atomically publish the binding: private temp file, fsync, rename, then fsync the directory. */
89
+ export async function writeWorkstationBinding(directory, binding) {
90
+ const serialized = `${JSON.stringify(WorkstationBindingSchema.parse(binding), null, 2)}\n`;
91
+ const temporaryPath = join(directory, `.${WORKSTATION_BINDING_FILENAME}.${String(process.pid)}.${randomBytes(8).toString("hex")}.tmp`);
92
+ await mkdir(directory, { recursive: true, mode: 0o700 });
93
+ let temporaryCreated = false;
94
+ try {
95
+ const handle = await open(temporaryPath, "wx", 0o600);
96
+ temporaryCreated = true;
97
+ try {
98
+ await handle.writeFile(serialized, "utf8");
99
+ await handle.sync();
100
+ }
101
+ finally {
102
+ await handle.close();
103
+ }
104
+ await rename(temporaryPath, workstationBindingPath(directory));
105
+ temporaryCreated = false;
106
+ }
107
+ finally {
108
+ if (temporaryCreated)
109
+ await unlink(temporaryPath).catch(() => { });
110
+ }
111
+ syncDirectory(directory);
112
+ }
113
+ /** Delete only the binding sidecar. Returns whether one existed. */
114
+ export async function removeWorkstationBinding(directory) {
115
+ try {
116
+ await unlink(workstationBindingPath(directory));
117
+ }
118
+ catch (error) {
119
+ if (errnoCode(error) === "ENOENT")
120
+ return false;
121
+ throw error;
122
+ }
123
+ syncDirectory(directory);
124
+ return true;
125
+ }
126
+ const CredentialIdentitySchema = z.object({ rpId: z.string(), userHandle: z.string() }).passthrough();
127
+ export async function readPasskeyStoreIdentity(credentialDirectory) {
128
+ const raw = await readFile(join(credentialDirectory, "credentials.json"), "utf8");
129
+ const identity = CredentialIdentitySchema.parse(JSON.parse(raw));
130
+ return { rpId: identity.rpId, userHandle: identity.userHandle };
131
+ }
132
+ /**
133
+ * The local checks, run before the passkey store opens and before the gateway
134
+ * is dialed. A bound store must still be the bound one: missing or empty,
135
+ * another RP ID, or another enrollment of the same RP ID all refuse to start.
136
+ * An unbound store for another RP ID refuses too. Nothing is modified.
137
+ */
138
+ export async function inspectWorkstationBinding(input) {
139
+ const binding = await readWorkstationBinding(input.bindingDirectory);
140
+ if (binding !== undefined && binding.rp_id !== input.expectedRpId) {
141
+ throw new WorkstationBindingError("rp_mismatch", `the workstation binding is for RP ID ${JSON.stringify(binding.rp_id)}, not ${JSON.stringify(input.expectedRpId)}; ${RESET_GUIDANCE}`);
142
+ }
143
+ let state = "absent";
144
+ try {
145
+ await lstat(input.credentialDirectory);
146
+ state = await inspectDashboardCredentialEnrollmentState(input.credentialDirectory);
147
+ }
148
+ catch (error) {
149
+ if (errnoCode(error) !== "ENOENT")
150
+ throw error;
151
+ }
152
+ if (state === "absent") {
153
+ if (binding !== undefined) {
154
+ throw new WorkstationBindingError("passkey_volume_missing", `the passkey credential volume is missing or empty, but this machine is bound to workstation ${binding.companion_id}; ${RESET_GUIDANCE}`);
155
+ }
156
+ return undefined;
157
+ }
158
+ const identity = await readPasskeyStoreIdentity(input.credentialDirectory);
159
+ if (identity.rpId !== input.expectedRpId) {
160
+ throw new WorkstationBindingError("rp_mismatch", `the passkey credential store belongs to RP ID ${JSON.stringify(identity.rpId)}, not ${JSON.stringify(input.expectedRpId)}; the credential document was not modified`);
161
+ }
162
+ if (binding !== undefined && binding.user_handle !== identity.userHandle) {
163
+ throw new WorkstationBindingError("passkey_volume_replaced", `the passkey credential volume does not hold the enrollment bound to workstation ${binding.companion_id}; ${RESET_GUIDANCE}`);
164
+ }
165
+ return binding;
166
+ }
167
+ /**
168
+ * The companion-id check, run when the gateway hello names the workstation
169
+ * the presented key belongs to. The first hello on an unbound store records
170
+ * the binding; later hellos must name the same workstation, so a key for
171
+ * another workstation is never served from this passkey store.
172
+ */
173
+ export async function bindWorkstationOnHello(input) {
174
+ const existing = await readWorkstationBinding(input.bindingDirectory);
175
+ if (existing !== undefined) {
176
+ if (existing.companion_id !== input.companionId) {
177
+ throw new WorkstationBindingError("workstation_binding_mismatch", `this passkey store is bound to workstation ${existing.companion_id}, but the API key belongs to ${input.companionId}; `
178
+ + "use that workstation's key, or stop the companion and run it once with --reset-passkey-binding");
179
+ }
180
+ return existing;
181
+ }
182
+ const identity = await readPasskeyStoreIdentity(input.credentialDirectory);
183
+ const binding = {
184
+ version: 1,
185
+ companion_id: input.companionId,
186
+ user_handle: identity.userHandle,
187
+ rp_id: identity.rpId,
188
+ };
189
+ await writeWorkstationBinding(input.bindingDirectory, binding);
190
+ return binding;
191
+ }
192
+ //# sourceMappingURL=workstation-binding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workstation-binding.js","sourceRoot":"","sources":["../../src/dashboard-companion/workstation-binding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,0CAA0C,EAC1C,4BAA4B,EAC5B,WAAW,GACZ,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,yCAAy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space with its access\n grant <tenant-id> (--days <n> | --until <iso>) --reason <text>\n operator access until a cutoff (at most 400 days)\n revoke-grant <tenant-id> remove the operator grant\n suspend <tenant-id> --reason <text> deny access, whatever the grant or billing state\n unsuspend <tenant-id> lift a suspension\n\nThe database path defaults to $CLINKX_DASHBOARD_GATEWAY_CLOUD_DB_PATH. A running gateway applies a\nchange made here within 60 s and then closes the companion connections of a\nworkspace that lost access.";
2
+ export interface AdminCliIo {
3
+ readonly env?: Readonly<Record<string, string | undefined>>;
4
+ readonly stdout?: (line: string) => void;
5
+ readonly stderr?: (line: string) => void;
6
+ /** Clock for `--days`; the store re-checks the cutoff against its own clock. */
7
+ readonly now?: () => number;
8
+ }
9
+ /** Exit code: 0 on success, 1 when the command failed, 2 on a usage error. */
10
+ export declare function runAdminCli(argv: readonly string[], io?: AdminCliIo): number;
@@ -0,0 +1,266 @@
1
+ import { existsSync, realpathSync } from "node:fs";
2
+ import { pathToFileURL } from "node:url";
3
+ import { parseArgs } from "node:util";
4
+ import { TenantIdSchema } from "./control-plane/contracts.js";
5
+ import { ENTITLEMENT_RESCAN_INTERVAL_MS, activeGrantUntil, evaluateEntitlementAccess } from "./control-plane/entitlements.js";
6
+ import { MAX_OPERATOR_GRANT_MS, openControlPlaneStore } from "./control-plane/store.js";
7
+ const DB_PATH_ENV = "CLINKX_DASHBOARD_GATEWAY_CLOUD_DB_PATH";
8
+ const DAY_MS = 24 * 60 * 60_000;
9
+ const MAX_GRANT_DAYS = MAX_OPERATOR_GRANT_MS / DAY_MS;
10
+ const ISO_INSTANT = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.\d{1,3})?)?(?:Z|[+-]\d{2}:\d{2}))?$/;
11
+ export const ADMIN_CLI_USAGE = `Usage: node dist/dashboard-gateway/admin-cli.js [--db <path>] <command>
12
+
13
+ Commands:
14
+ list every workspace with its access
15
+ grant <tenant-id> (--days <n> | --until <iso>) --reason <text>
16
+ operator access until a cutoff (at most ${MAX_GRANT_DAYS} days)
17
+ revoke-grant <tenant-id> remove the operator grant
18
+ suspend <tenant-id> --reason <text> deny access, whatever the grant or billing state
19
+ unsuspend <tenant-id> lift a suspension
20
+
21
+ The database path defaults to $${DB_PATH_ENV}. A running gateway applies a
22
+ change made here within ${ENTITLEMENT_RESCAN_INTERVAL_MS / 1000} s and then closes the companion connections of a
23
+ workspace that lost access.`;
24
+ class UsageError extends Error {
25
+ }
26
+ class CommandError extends Error {
27
+ }
28
+ const COMMAND_OPTIONS = {
29
+ list: [],
30
+ grant: ["days", "until", "reason"],
31
+ "revoke-grant": [],
32
+ suspend: ["reason"],
33
+ unsuspend: [],
34
+ };
35
+ function iso(value) {
36
+ return value === null ? "-" : new Date(value).toISOString();
37
+ }
38
+ function tenantArgument(positionals, command) {
39
+ if (positionals.length !== 2)
40
+ throw new UsageError(`${command} takes exactly one <tenant-id>`);
41
+ const tenantId = positionals[1] ?? "";
42
+ if (!TenantIdSchema.safeParse(tenantId).success)
43
+ throw new UsageError(`${JSON.stringify(tenantId)} is not a tenant id`);
44
+ return tenantId;
45
+ }
46
+ function reasonOption(options) {
47
+ const reason = options.reason;
48
+ if (reason === undefined)
49
+ throw new UsageError("--reason <text> is required");
50
+ if (!/^[\x20-\x7e]{1,200}$/.test(reason))
51
+ throw new UsageError("--reason must be 1-200 printable ASCII characters");
52
+ return reason;
53
+ }
54
+ function grantCutoff(options, now) {
55
+ if ((options.days === undefined) === (options.until === undefined)) {
56
+ throw new UsageError("grant needs exactly one of --days <n> or --until <iso>");
57
+ }
58
+ if (options.days !== undefined) {
59
+ const days = /^[1-9][0-9]*$/.test(options.days) ? Number(options.days) : Number.NaN;
60
+ if (!Number.isSafeInteger(days) || days > MAX_GRANT_DAYS) {
61
+ throw new UsageError(`--days must be a whole number from 1 through ${MAX_GRANT_DAYS}`);
62
+ }
63
+ return now + days * DAY_MS;
64
+ }
65
+ const until = options.until ?? "";
66
+ const match = ISO_INSTANT.exec(until);
67
+ if (match !== null && !isCalendarInstant(match)) {
68
+ throw new UsageError(`--until ${until} names a date or time that does not exist on the calendar`);
69
+ }
70
+ const cutoff = match === null ? Number.NaN : Date.parse(until);
71
+ if (!Number.isSafeInteger(cutoff)) {
72
+ throw new UsageError("--until must be an ISO-8601 date (UTC) or a date-time with Z or an offset");
73
+ }
74
+ return cutoff;
75
+ }
76
+ /** `Date.parse` rolls an impossible date or time (February 30, hour 24) into the next valid one. */
77
+ function isCalendarInstant(match) {
78
+ const [year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0] = match.slice(1, 7).map((part) => Number(part ?? 0));
79
+ const date = new Date(0);
80
+ date.setUTCFullYear(year, month - 1, day);
81
+ date.setUTCHours(hour, minute, second, 0);
82
+ return (date.getUTCFullYear() === year &&
83
+ date.getUTCMonth() === month - 1 &&
84
+ date.getUTCDate() === day &&
85
+ date.getUTCHours() === hour &&
86
+ date.getUTCMinutes() === minute &&
87
+ date.getUTCSeconds() === second);
88
+ }
89
+ function readEntitlement(store, tenantId) {
90
+ const entitlement = store.getEntitlement(tenantId);
91
+ if (entitlement === null)
92
+ throw new CommandError(`unknown tenant ${tenantId}`);
93
+ return entitlement;
94
+ }
95
+ function concurrentChange(tenantId) {
96
+ return new CommandError(`${tenantId} changed while this command ran; nothing was written, run it again`);
97
+ }
98
+ function listTenants(store, out) {
99
+ const snapshot = store.listTenantsForOperator();
100
+ out(["tenant", "created_at", "owner", "workstations", "access", "reason", "access_until", "grant_until", "suspended"].join("\t"));
101
+ for (const tenant of snapshot.tenants) {
102
+ const decision = evaluateEntitlementAccess(tenant.entitlement, snapshot.now);
103
+ out([
104
+ tenant.tenantId,
105
+ iso(tenant.createdAt),
106
+ tenant.ownerAccountId ?? "-",
107
+ String(tenant.liveWorkstations),
108
+ decision.allowed ? "granted" : "denied",
109
+ decision.reason,
110
+ iso(decision.nextDeadline),
111
+ iso(activeGrantUntil(tenant.entitlement, snapshot.now)),
112
+ tenant.entitlement?.suspendedReason ?? "-",
113
+ ].join("\t"));
114
+ }
115
+ }
116
+ function runCommand(store, command, positionals, options, io) {
117
+ const out = io.stdout;
118
+ switch (command) {
119
+ case "list": {
120
+ if (positionals.length !== 1)
121
+ throw new UsageError("list takes no arguments");
122
+ listTenants(store, out);
123
+ return;
124
+ }
125
+ case "grant": {
126
+ const tenantId = tenantArgument(positionals, command);
127
+ const reason = reasonOption(options);
128
+ const expiresAt = grantCutoff(options, io.now());
129
+ const current = readEntitlement(store, tenantId);
130
+ const result = store.grantTenantAccess({ tenantId, expiresAt, reason, expectedRevision: current.revision });
131
+ if (result.status === "not_found")
132
+ throw new CommandError(`unknown tenant ${tenantId}`);
133
+ if (result.status === "stale_revision")
134
+ throw concurrentChange(tenantId);
135
+ if (result.status === "invalid_expiry") {
136
+ throw new CommandError(`grant cutoff ${iso(expiresAt)} must be after ${iso(result.now)} and at most ${MAX_GRANT_DAYS} days later`);
137
+ }
138
+ out(`granted ${tenantId} access until ${iso(expiresAt)} (was ${iso(current.grantExpiresAt)})`);
139
+ if (current.suspendedAt !== null)
140
+ out(`note: ${tenantId} is suspended; the grant applies once it is unsuspended`);
141
+ return;
142
+ }
143
+ case "revoke-grant": {
144
+ const tenantId = tenantArgument(positionals, command);
145
+ const current = readEntitlement(store, tenantId);
146
+ const result = store.revokeTenantGrant({ tenantId, expectedRevision: current.revision });
147
+ if (result.status === "not_found")
148
+ throw new CommandError(`unknown tenant ${tenantId}`);
149
+ if (result.status === "stale_revision")
150
+ throw concurrentChange(tenantId);
151
+ out(result.hadGrant ? `revoked the grant of ${tenantId} (was until ${iso(current.grantExpiresAt)})` : `${tenantId} has no grant`);
152
+ return;
153
+ }
154
+ case "suspend": {
155
+ const tenantId = tenantArgument(positionals, command);
156
+ const reason = reasonOption(options);
157
+ const current = readEntitlement(store, tenantId);
158
+ const result = store.suspendTenant({ tenantId, reason, expectedRevision: current.revision });
159
+ if (result.status === "not_found")
160
+ throw new CommandError(`unknown tenant ${tenantId}`);
161
+ if (result.status === "stale_revision")
162
+ throw concurrentChange(tenantId);
163
+ out(result.alreadySuspended
164
+ ? `${tenantId} was already suspended since ${iso(result.suspendedAt)}`
165
+ : `suspended ${tenantId} at ${iso(result.suspendedAt)}`);
166
+ return;
167
+ }
168
+ case "unsuspend": {
169
+ const tenantId = tenantArgument(positionals, command);
170
+ const current = readEntitlement(store, tenantId);
171
+ const result = store.unsuspendTenant(tenantId, { expectedRevision: current.revision });
172
+ if (result.status === "not_found")
173
+ throw new CommandError(`unknown tenant ${tenantId}`);
174
+ if (result.status === "stale_revision")
175
+ throw concurrentChange(tenantId);
176
+ out(result.wasSuspended ? `unsuspended ${tenantId}` : `${tenantId} was not suspended`);
177
+ return;
178
+ }
179
+ default:
180
+ throw new UsageError(`unknown command ${JSON.stringify(command)}`);
181
+ }
182
+ }
183
+ function describe(error) {
184
+ if (!(error instanceof Error))
185
+ return String(error);
186
+ return error.cause instanceof Error ? `${error.message} (${error.cause.message})` : error.message;
187
+ }
188
+ /** Exit code: 0 on success, 1 when the command failed, 2 on a usage error. */
189
+ export function runAdminCli(argv, io = {}) {
190
+ const resolved = {
191
+ env: io.env ?? process.env,
192
+ stdout: io.stdout ?? ((line) => process.stdout.write(`${line}\n`)),
193
+ stderr: io.stderr ?? ((line) => process.stderr.write(`${line}\n`)),
194
+ now: io.now ?? Date.now,
195
+ };
196
+ let store = null;
197
+ try {
198
+ let parsed;
199
+ try {
200
+ parsed = parseArgs({
201
+ args: [...argv],
202
+ allowPositionals: true,
203
+ strict: true,
204
+ options: {
205
+ db: { type: "string" },
206
+ days: { type: "string" },
207
+ until: { type: "string" },
208
+ reason: { type: "string" },
209
+ help: { type: "boolean", short: "h" },
210
+ },
211
+ });
212
+ }
213
+ catch (error) {
214
+ throw new UsageError(error instanceof Error ? error.message : String(error));
215
+ }
216
+ const { values, positionals } = parsed;
217
+ if (values.help === true) {
218
+ resolved.stdout(ADMIN_CLI_USAGE);
219
+ return 0;
220
+ }
221
+ const command = positionals[0];
222
+ if (command === undefined)
223
+ throw new UsageError("a command is required");
224
+ const allowed = COMMAND_OPTIONS[command];
225
+ if (allowed === undefined)
226
+ throw new UsageError(`unknown command ${JSON.stringify(command)}`);
227
+ for (const name of ["days", "until", "reason"]) {
228
+ if (values[name] !== undefined && !allowed.includes(name))
229
+ throw new UsageError(`${command} does not take --${name}`);
230
+ }
231
+ const path = values.db ?? resolved.env[DB_PATH_ENV];
232
+ if (path === undefined || path === "")
233
+ throw new UsageError(`pass --db <path> or set ${DB_PATH_ENV}`);
234
+ if (!existsSync(path))
235
+ throw new CommandError(`no control-plane database at ${path}`);
236
+ store = openControlPlaneStore({ path });
237
+ runCommand(store, command, positionals, values, resolved);
238
+ return 0;
239
+ }
240
+ catch (error) {
241
+ if (error instanceof UsageError) {
242
+ resolved.stderr(`error: ${error.message}`);
243
+ resolved.stderr(ADMIN_CLI_USAGE);
244
+ return 2;
245
+ }
246
+ resolved.stderr(`error: ${describe(error)}`);
247
+ return 1;
248
+ }
249
+ finally {
250
+ store?.close();
251
+ }
252
+ }
253
+ function isEntryPoint() {
254
+ const script = process.argv[1];
255
+ if (script === undefined)
256
+ return false;
257
+ try {
258
+ return import.meta.url === pathToFileURL(realpathSync(script)).href;
259
+ }
260
+ catch {
261
+ return false;
262
+ }
263
+ }
264
+ if (isEntryPoint())
265
+ process.exitCode = runAdminCli(process.argv.slice(2));
266
+ //# sourceMappingURL=admin-cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin-cli.js","sourceRoot":"","sources":["../../src/dashboard-gateway/admin-cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,8BAA8B,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,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,OAAO,CAAC,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -6,4 +6,54 @@ export interface DashboardGatewayConfig {
6
6
  type Environment = Readonly<Record<string, string | undefined>>;
7
7
  export declare function parseDashboardGatewayEndpoint(value: string): string;
8
8
  export declare function loadDashboardGatewayConfig(env?: Environment): DashboardGatewayConfig;
9
+ export type DashboardGatewayMode = "legacy" | "tenant";
10
+ export type StripeEnvironment = "test" | "live";
11
+ export type DashboardGatewayBillingMode = "off" | "stripe";
12
+ interface DashboardGatewayTenantCoreConfig {
13
+ mode: "tenant";
14
+ host: string;
15
+ port: number;
16
+ cloudDbPath: string;
17
+ /** The single public origin: canonical `https://host`, no port. Every other Host is refused. */
18
+ publicOrigin: string;
19
+ oidc: {
20
+ issuer: string;
21
+ clientId: string;
22
+ clientSecretEnv: string;
23
+ };
24
+ /** Refuse to start unless the store's directory is on a mounted volume. */
25
+ requirePersistentDb: boolean;
26
+ }
27
+ export interface DashboardGatewayStripeBillingConfig {
28
+ stripe: {
29
+ environment: StripeEnvironment;
30
+ secretKeyEnv: string;
31
+ webhookSecretEnv: string;
32
+ /** The first entry is the Checkout price; every entry confers entitlement. */
33
+ priceIds: readonly string[];
34
+ };
35
+ billing: {
36
+ graceSeconds: number;
37
+ reconciliationIntervalSeconds: number;
38
+ maxStalenessSeconds: number;
39
+ };
40
+ }
41
+ /** With billing `off`, access comes only from operator grants; no Stripe setting is read or accepted. */
42
+ export type DashboardGatewayTenantConfig = DashboardGatewayTenantCoreConfig & ({
43
+ billingMode: "off";
44
+ } | ({
45
+ billingMode: "stripe";
46
+ } & DashboardGatewayStripeBillingConfig));
47
+ export type DashboardGatewayModeConfig = ({
48
+ mode: "legacy";
49
+ } & DashboardGatewayConfig) | DashboardGatewayTenantConfig;
50
+ /** Tenant settings every tenant deployment sets, whatever its billing mode. */
51
+ export declare const DASHBOARD_GATEWAY_TENANT_CORE_ENV_NAMES: readonly string[];
52
+ /** Stripe settings: required with `CLINKX_DASHBOARD_GATEWAY_BILLING=stripe`, refused with `off`. */
53
+ export declare const DASHBOARD_GATEWAY_TENANT_BILLING_ENV_NAMES: readonly string[];
54
+ export declare const DASHBOARD_GATEWAY_TENANT_ENV_NAMES: readonly string[];
55
+ /** Not a tenant setting: the image sets it, so legacy mode accepts and ignores it. */
56
+ export declare const REQUIRE_PERSISTENT_DB_ENV = "CLINKX_DASHBOARD_GATEWAY_REQUIRE_PERSISTENT_DB";
57
+ export declare function resolveDashboardGatewayMode(env?: Environment): DashboardGatewayMode;
58
+ export declare function loadDashboardGatewayModeConfig(env?: Environment): DashboardGatewayModeConfig;
9
59
  export {};