@rocket.chat/houston 0.27.0-next.3 → 2.1.9

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 (294) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +109 -15
  3. package/bin/houston +62 -0
  4. package/data/docs/ARCHITECTURE.md +387 -0
  5. package/data/docs/automation.md +107 -0
  6. package/data/docs/e2ee.md +76 -0
  7. package/data/docs/eks.md +258 -0
  8. package/data/docs/gui.md +282 -0
  9. package/data/docs/guide.md +642 -0
  10. package/data/docs/kubernetes.md +138 -0
  11. package/data/docs/loadtest.md +264 -0
  12. package/data/docs/troubleshooting.md +203 -0
  13. package/data/docs/upgrading.md +84 -0
  14. package/data/docs/voice.md +253 -0
  15. package/data/iam/engineer-policy.json +11 -0
  16. package/data/iam/engineer-rbac.yaml +42 -0
  17. package/data/iam/operator-policy.json +211 -0
  18. package/data/loadtest/badbot.js +22 -0
  19. package/data/loadtest/common.js +170 -0
  20. package/data/loadtest/custom.js +20 -0
  21. package/data/loadtest/journey.js +58 -0
  22. package/data/loadtest/login.js +18 -0
  23. package/data/loadtest/messages.js +13 -0
  24. package/data/loadtest/mixed.js +57 -0
  25. package/data/loadtest/read.js +12 -0
  26. package/data/loadtest/webhook.js +20 -0
  27. package/data/monitoring/houston-logs.json +98 -0
  28. package/data/monitoring/k6-loadtest.json +610 -0
  29. package/data/monitoring/mongodb-exporter.json +3007 -0
  30. package/data/monitoring/node-exporter-full.json +16114 -0
  31. package/data/monitoring/rocketchat-metrics.json +6471 -0
  32. package/data/presets/airgapped.yaml +16 -0
  33. package/data/presets/default.yaml +9 -0
  34. package/data/seed/avatar-0.png +0 -0
  35. package/data/seed/avatar-1.png +0 -0
  36. package/data/seed/avatar-2.png +0 -0
  37. package/data/seed/avatar-3.png +0 -0
  38. package/data/seed/avatar-4.png +0 -0
  39. package/data/seed/avatar-5.png +0 -0
  40. package/data/seed/avatar-6.png +0 -0
  41. package/data/seed/avatar-7.png +0 -0
  42. package/data/seed/seed-metrics.csv +3 -0
  43. package/data/seed/seed-preview.png +0 -0
  44. package/data/seed/seed-report.pdf +32 -0
  45. package/data/seed/seed-runbook.txt +3 -0
  46. package/data/skill/SKILL.md +399 -0
  47. package/data/versions.yaml +55 -0
  48. package/data/voice/freeswitch/drachtio.xml +52 -0
  49. package/data/voice/freeswitch/public.xml +87 -0
  50. package/data/webui/app.css +2003 -0
  51. package/data/webui/index.html +678 -0
  52. package/data/webui/js/api.js +561 -0
  53. package/data/webui/js/boot.js +44 -0
  54. package/data/webui/js/clusters-tail.js +1377 -0
  55. package/data/webui/js/clusters.js +896 -0
  56. package/data/webui/js/create.js +276 -0
  57. package/data/webui/js/detail.js +507 -0
  58. package/data/webui/js/jobs.js +636 -0
  59. package/data/webui/js/logs.js +634 -0
  60. package/data/webui/js/main.js +14 -0
  61. package/data/webui/js/options.js +408 -0
  62. package/data/webui/js/people.js +438 -0
  63. package/data/webui/js/perf.js +303 -0
  64. package/data/webui/js/render.js +438 -0
  65. package/data/webui/js/shared.js +3 -0
  66. package/data/webui/js/state.js +583 -0
  67. package/data/webui/js/theme.js +123 -0
  68. package/data/webui/js/util.js +584 -0
  69. package/dist/cli/app.js +593 -0
  70. package/dist/cli/capabilities.js +76 -0
  71. package/dist/cli/cell-widths.js +495 -0
  72. package/dist/cli/entry.js +10 -0
  73. package/dist/cli/error-panel.js +492 -0
  74. package/dist/cli/handlers/actor.js +84 -0
  75. package/dist/cli/handlers/https.js +614 -0
  76. package/dist/cli/handlers/prompt.js +299 -0
  77. package/dist/cli/handlers/users.js +226 -0
  78. package/dist/cli/handlers.js +3694 -0
  79. package/dist/cli/help.js +183 -0
  80. package/dist/cli/index.js +15 -0
  81. package/dist/cli/perf.js +814 -0
  82. package/dist/cli/render.js +254 -0
  83. package/dist/cli/serve.js +858 -0
  84. package/dist/cli/spec-data.js +2599 -0
  85. package/dist/cli/spec-types.js +8 -0
  86. package/dist/cli/usage-error.js +520 -0
  87. package/dist/cli/wire.js +70 -0
  88. package/dist/core/audit.js +346 -0
  89. package/dist/core/backup-compat.js +85 -0
  90. package/dist/core/backup.js +1639 -0
  91. package/dist/core/cluster.js +1398 -0
  92. package/dist/core/configimport.js +345 -0
  93. package/dist/core/data.js +267 -0
  94. package/dist/core/database-of.js +82 -0
  95. package/dist/core/diagnose.js +159 -0
  96. package/dist/core/doctor.js +1518 -0
  97. package/dist/core/edge/acme.js +338 -0
  98. package/dist/core/edge/engine.js +500 -0
  99. package/dist/core/edge/networks.js +174 -0
  100. package/dist/core/edge/paths.js +107 -0
  101. package/dist/core/edge/routes.js +251 -0
  102. package/dist/core/edge/routeyml.js +195 -0
  103. package/dist/core/edge/runtime.js +493 -0
  104. package/dist/core/edge/spec.js +305 -0
  105. package/dist/core/edge/types.js +202 -0
  106. package/dist/core/eks-docs.js +135 -0
  107. package/dist/core/eks.js +2240 -0
  108. package/dist/core/envvars.js +562 -0
  109. package/dist/core/eventlog.js +541 -0
  110. package/dist/core/firstrun.js +153 -0
  111. package/dist/core/journal.js +694 -0
  112. package/dist/core/kube/ask.js +231 -0
  113. package/dist/core/kube/capabilities.js +269 -0
  114. package/dist/core/kube/certmanager.js +452 -0
  115. package/dist/core/kube/chart.js +413 -0
  116. package/dist/core/kube/cluster.js +196 -0
  117. package/dist/core/kube/context.js +545 -0
  118. package/dist/core/kube/endpoints.js +448 -0
  119. package/dist/core/kube/exec.js +195 -0
  120. package/dist/core/kube/forward.js +732 -0
  121. package/dist/core/kube/grafana-ingress.js +110 -0
  122. package/dist/core/kube/ingress.js +218 -0
  123. package/dist/core/kube/manifests.js +361 -0
  124. package/dist/core/kube/monitoring.js +768 -0
  125. package/dist/core/kube/names.js +237 -0
  126. package/dist/core/kube/namespace.js +678 -0
  127. package/dist/core/kube/operator.js +941 -0
  128. package/dist/core/kube/probe.js +202 -0
  129. package/dist/core/kube/reachability.js +163 -0
  130. package/dist/core/kube/release.js +439 -0
  131. package/dist/core/kube/replicaset.js +180 -0
  132. package/dist/core/kube/scale.js +398 -0
  133. package/dist/core/kube/status.js +633 -0
  134. package/dist/core/kube/tools.js +238 -0
  135. package/dist/core/kube/transfer.js +173 -0
  136. package/dist/core/kube/workspace.js +423 -0
  137. package/dist/core/lifecycle/admin.js +64 -0
  138. package/dist/core/lifecycle/create-docker.js +1549 -0
  139. package/dist/core/lifecycle/create-k8s.js +960 -0
  140. package/dist/core/lifecycle/destroy.js +339 -0
  141. package/dist/core/lifecycle/inspect.js +636 -0
  142. package/dist/core/lifecycle/naming.js +298 -0
  143. package/dist/core/lifecycle/notes.js +862 -0
  144. package/dist/core/lifecycle/ownership.js +313 -0
  145. package/dist/core/lifecycle/payload.js +401 -0
  146. package/dist/core/lifecycle/ports.js +388 -0
  147. package/dist/core/lifecycle/preconditions.js +367 -0
  148. package/dist/core/lifecycle/pruning.js +551 -0
  149. package/dist/core/lifecycle/ready.js +818 -0
  150. package/dist/core/lifecycle/request.js +510 -0
  151. package/dist/core/lifecycle/seeding.js +281 -0
  152. package/dist/core/lifecycle/sizing.js +392 -0
  153. package/dist/core/lifecycle/state.js +286 -0
  154. package/dist/core/lifecycle/tlsplan.js +704 -0
  155. package/dist/core/lifecycle/types.js +232 -0
  156. package/dist/core/loadtest.js +1051 -0
  157. package/dist/core/migrate.js +612 -0
  158. package/dist/core/monitor.js +494 -0
  159. package/dist/core/postready.js +976 -0
  160. package/dist/core/promote.js +804 -0
  161. package/dist/core/rcapi.js +1336 -0
  162. package/dist/core/recovery.js +75 -0
  163. package/dist/core/runner/engine.js +394 -0
  164. package/dist/core/runner/host.js +298 -0
  165. package/dist/core/runner/locks.js +129 -0
  166. package/dist/core/runner/paths.js +173 -0
  167. package/dist/core/runner/ports.js +172 -0
  168. package/dist/core/runner/queries.js +612 -0
  169. package/dist/core/runner/record.js +563 -0
  170. package/dist/core/scaleseed.js +271 -0
  171. package/dist/core/seed-db.js +208 -0
  172. package/dist/core/sessions.js +472 -0
  173. package/dist/core/skill.js +326 -0
  174. package/dist/core/sso-identities.js +172 -0
  175. package/dist/core/sso.js +703 -0
  176. package/dist/core/tls-local.js +311 -0
  177. package/dist/core/tls.js +878 -0
  178. package/dist/core/topology.js +482 -0
  179. package/dist/core/upgrade.js +877 -0
  180. package/dist/core/users.js +739 -0
  181. package/dist/lib/audit.js +100 -0
  182. package/dist/lib/close-matches.js +238 -0
  183. package/dist/lib/compose.js +672 -0
  184. package/dist/lib/config.js +1398 -0
  185. package/dist/lib/context.js +18 -0
  186. package/dist/lib/errors.js +305 -0
  187. package/dist/lib/events.js +208 -0
  188. package/dist/lib/float-text.js +126 -0
  189. package/dist/lib/format.js +1320 -0
  190. package/dist/lib/home.js +325 -0
  191. package/dist/lib/journal.js +122 -0
  192. package/dist/lib/json-text.js +733 -0
  193. package/dist/lib/jsonout.js +382 -0
  194. package/dist/lib/lock.js +516 -0
  195. package/dist/lib/login-name.js +202 -0
  196. package/dist/lib/map-limit.js +29 -0
  197. package/dist/lib/mkdir-parents.js +90 -0
  198. package/dist/lib/mongo-kernel.js +67 -0
  199. package/dist/lib/monitoring.js +492 -0
  200. package/dist/lib/platform-name.js +59 -0
  201. package/dist/lib/presets/common.js +390 -0
  202. package/dist/lib/presets/composite.js +326 -0
  203. package/dist/lib/presets/e2ee.js +143 -0
  204. package/dist/lib/presets/email.js +172 -0
  205. package/dist/lib/presets/guides.js +27 -0
  206. package/dist/lib/presets/index.js +490 -0
  207. package/dist/lib/presets/keycloak.js +371 -0
  208. package/dist/lib/presets/ldap.js +1285 -0
  209. package/dist/lib/presets/livechat.js +220 -0
  210. package/dist/lib/presets/multi-instance.js +124 -0
  211. package/dist/lib/presets/oidc.js +161 -0
  212. package/dist/lib/presets/public.js +496 -0
  213. package/dist/lib/presets/registry.js +64 -0
  214. package/dist/lib/presets/s3-minio.js +300 -0
  215. package/dist/lib/presets/saml.js +149 -0
  216. package/dist/lib/presets/scenario.js +51 -0
  217. package/dist/lib/presets/types.js +86 -0
  218. package/dist/lib/presets/voice-pbx.js +320 -0
  219. package/dist/lib/presets/voice.js +345 -0
  220. package/dist/lib/presets/webhooks.js +182 -0
  221. package/dist/lib/redact.js +106 -0
  222. package/dist/lib/seed-options.js +68 -0
  223. package/dist/lib/seed-profiles.js +59 -0
  224. package/dist/lib/targz.js +1383 -0
  225. package/dist/lib/teammode.js +25 -0
  226. package/dist/lib/tempdir.js +162 -0
  227. package/dist/lib/unicode-tables.js +2335 -0
  228. package/dist/lib/version-spec.js +357 -0
  229. package/dist/lib/versions.js +463 -0
  230. package/dist/lib/yaml-dump.js +1361 -0
  231. package/dist/perf/baseline.js +168 -0
  232. package/dist/perf/constrain.js +299 -0
  233. package/dist/perf/k6.js +235 -0
  234. package/dist/perf/mongoprof.js +171 -0
  235. package/dist/perf/rcmetrics.js +191 -0
  236. package/dist/perf/report.js +386 -0
  237. package/dist/perf/resources.js +236 -0
  238. package/dist/perf/slo.js +111 -0
  239. package/dist/perf/timeline.js +187 -0
  240. package/dist/perf/timings.js +85 -0
  241. package/dist/perf/verdict.js +201 -0
  242. package/dist/seams/aws-cli.js +126 -0
  243. package/dist/seams/docker-cli.js +280 -0
  244. package/dist/seams/exec.js +861 -0
  245. package/dist/seams/fs/lock.js +528 -0
  246. package/dist/seams/kubectl.js +83 -0
  247. package/dist/seams/rc-http.js +921 -0
  248. package/dist/seed/apply.js +190 -0
  249. package/dist/seed/assets.js +76 -0
  250. package/dist/seed/check.js +391 -0
  251. package/dist/seed/client.js +172 -0
  252. package/dist/seed/executor.js +726 -0
  253. package/dist/seed/history.js +281 -0
  254. package/dist/seed/kinds.js +91 -0
  255. package/dist/seed/plan.js +432 -0
  256. package/dist/seed/receipt.js +339 -0
  257. package/dist/seed/repairs.js +75 -0
  258. package/dist/seed/verification.js +363 -0
  259. package/dist/seed/wording.js +248 -0
  260. package/dist/web/app.js +326 -0
  261. package/dist/web/jobs.js +510 -0
  262. package/dist/web/route-deps.js +211 -0
  263. package/dist/web/route-table.js +213 -0
  264. package/dist/web/routes/backup.js +244 -0
  265. package/dist/web/routes/clusters.js +303 -0
  266. package/dist/web/routes/data.js +187 -0
  267. package/dist/web/routes/edge.js +82 -0
  268. package/dist/web/routes/index.js +63 -0
  269. package/dist/web/routes/jobs.js +95 -0
  270. package/dist/web/routes/logs.js +297 -0
  271. package/dist/web/routes/meta.js +191 -0
  272. package/dist/web/routes/people.js +151 -0
  273. package/dist/web/routes/perf.js +95 -0
  274. package/dist/web/routes/repros.js +550 -0
  275. package/dist/web/routes/session.js +361 -0
  276. package/dist/web/routes/spa.js +198 -0
  277. package/dist/web/security.js +475 -0
  278. package/dist/web/signin.js +246 -0
  279. package/package.json +70 -32
  280. package/.eslintrc +0 -94
  281. package/.swcrc +0 -18
  282. package/dist/bin.js +0 -3
  283. package/dist/cli.js +0 -184
  284. package/dist/commands/createBranch.js +0 -194
  285. package/dist/outputCI.js +0 -59
  286. package/src/bin.js +0 -4
  287. package/src/cli.ts +0 -25
  288. package/src/commands/createBranch.ts +0 -28
  289. package/src/outputCI.ts +0 -12
  290. package/src-old/logs.js +0 -323
  291. package/src-old/md.js +0 -191
  292. package/src-old/release-table.js +0 -60
  293. package/src-old/set-version.js +0 -614
  294. package/src-old/utils.js +0 -15
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+ /** Shared mechanics for route modules, below them in the dependency graph. */
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.RequestValidationError = void 0;
38
+ exports.bag = bag;
39
+ exports.requestBody = requestBody;
40
+ exports.markFormBody = markFormBody;
41
+ exports.strings = strings;
42
+ exports.actor = actor;
43
+ exports.submit = submit;
44
+ exports.bool = bool;
45
+ exports.queryBool = queryBool;
46
+ exports.queryInt = queryInt;
47
+ exports.queryText = queryText;
48
+ exports.text = text;
49
+ exports.orText = orText;
50
+ exports.kubeContext = kubeContext;
51
+ exports.oneDecimal = oneDecimal;
52
+ exports.number = number;
53
+ const config = __importStar(require("../lib/config"));
54
+ const format_1 = require("../lib/format");
55
+ const FORM_BODY = Symbol('houston form body');
56
+ /** The transport-level 422 for a request that fails validation, not a service error. */
57
+ class RequestValidationError extends Error {
58
+ constructor(detail) {
59
+ super('request validation failed');
60
+ this.detail = detail;
61
+ this.statusCode = 422;
62
+ this.name = 'RequestValidationError';
63
+ }
64
+ }
65
+ exports.RequestValidationError = RequestValidationError;
66
+ function bag(value) {
67
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
68
+ ? { ...value }
69
+ : {};
70
+ }
71
+ function requestBody(value, required) {
72
+ if (value === undefined || value === null) {
73
+ if (!required)
74
+ return {};
75
+ throw new RequestValidationError([
76
+ { type: 'missing', loc: ['body'], msg: 'Field required', input: null },
77
+ ]);
78
+ }
79
+ if (typeof value === 'object' && !Array.isArray(value) && FORM_BODY in value) {
80
+ const source = value[FORM_BODY];
81
+ if (source === '') {
82
+ if (!required)
83
+ return {};
84
+ throw new RequestValidationError([
85
+ { type: 'missing', loc: ['body'], msg: 'Field required', input: null },
86
+ ]);
87
+ }
88
+ throw new RequestValidationError([
89
+ {
90
+ type: 'dict_type',
91
+ loc: ['body'],
92
+ msg: 'Input should be a valid object',
93
+ input: source,
94
+ },
95
+ ]);
96
+ }
97
+ if (typeof value === 'object' && !Array.isArray(value)) {
98
+ return { ...value };
99
+ }
100
+ throw new RequestValidationError([
101
+ {
102
+ type: 'dict_type',
103
+ loc: ['body'],
104
+ msg: 'Input should be a valid object',
105
+ input: value,
106
+ },
107
+ ]);
108
+ }
109
+ /** Mark @fastify/formbody output without changing its enumerable handler value. */
110
+ function markFormBody(value, source) {
111
+ Object.defineProperty(value, FORM_BODY, { value: source });
112
+ return value;
113
+ }
114
+ function strings(value) {
115
+ return Array.isArray(value) ? value.map(format_1.storedText) : [];
116
+ }
117
+ function actor(request) {
118
+ return request.houstonActor || '';
119
+ }
120
+ function submit(app, kind, target, options = {}) {
121
+ return { job_id: app.jobs.submit(kind, target, options).id };
122
+ }
123
+ function bool(value, fallback = false) {
124
+ return value === undefined ? fallback : (0, format_1.isTruthy)(value);
125
+ }
126
+ /** The established bool query coercion, without treating the string "false" as truthy. */
127
+ function queryBool(value, fallback = false, name = 'boolean') {
128
+ value = queryScalar(value);
129
+ if (value === undefined)
130
+ return fallback;
131
+ if (typeof value === 'boolean')
132
+ return value;
133
+ if (value === 1)
134
+ return true;
135
+ if (value === 0)
136
+ return false;
137
+ const normalized = String(value).toLowerCase();
138
+ if (['1', 'true', 'on', 'yes'].includes(normalized))
139
+ return true;
140
+ if (['0', 'false', 'off', 'no'].includes(normalized))
141
+ return false;
142
+ throw new RequestValidationError([
143
+ {
144
+ type: 'bool_parsing',
145
+ loc: ['query', name],
146
+ msg: 'Input should be a valid boolean, unable to interpret input',
147
+ input: value,
148
+ },
149
+ ]);
150
+ }
151
+ function queryInt(value, fallback, name) {
152
+ value = queryScalar(value);
153
+ if (value === undefined)
154
+ return fallback;
155
+ const normalized = typeof value === 'string' ? value.trim() : value;
156
+ if (typeof normalized === 'number' && Number.isInteger(normalized))
157
+ return normalized;
158
+ if (typeof normalized === 'string' && /^[+-]?\d+(?:\.0+)?$/u.test(normalized)) {
159
+ const integral = normalized.replace(/\.0+$/u, '');
160
+ const parsed = BigInt(integral);
161
+ if (parsed > BigInt(Number.MAX_SAFE_INTEGER))
162
+ return Number.MAX_SAFE_INTEGER;
163
+ if (parsed < BigInt(Number.MIN_SAFE_INTEGER))
164
+ return Number.MIN_SAFE_INTEGER;
165
+ return Number(parsed);
166
+ }
167
+ throw new RequestValidationError([
168
+ {
169
+ type: 'int_parsing',
170
+ loc: ['query', name],
171
+ msg: 'Input should be a valid integer, unable to parse string as an integer',
172
+ input: value,
173
+ },
174
+ ]);
175
+ }
176
+ function queryScalar(value) {
177
+ return Array.isArray(value) ? value.at(-1) : value;
178
+ }
179
+ function queryText(value, fallback, name, required = false) {
180
+ const scalar = queryScalar(value);
181
+ if (scalar !== undefined)
182
+ return String(scalar);
183
+ if (!required)
184
+ return fallback;
185
+ throw new RequestValidationError([
186
+ { type: 'missing', loc: ['query', name], msg: 'Field required', input: null },
187
+ ]);
188
+ }
189
+ function text(value, fallback = '') {
190
+ return value === undefined ? fallback : (0, format_1.storedText)(value);
191
+ }
192
+ /** `value` as text when `isTruthy` holds it true, else `fallback`, for untyped JSON fields. */
193
+ function orText(value, fallback = '') {
194
+ return (0, format_1.isTruthy)(value) ? (0, format_1.storedText)(value) : fallback;
195
+ }
196
+ function kubeContext(value) {
197
+ const configured = bag(value)[config.EXTRA_CONTEXT];
198
+ if ((0, format_1.isTruthy)(configured))
199
+ return (0, format_1.storedText)(configured);
200
+ const names = require('../core/kube/names');
201
+ return names.CONTEXT;
202
+ }
203
+ function oneDecimal(value) {
204
+ return Number((0, format_1.formatFixed)(value, 1));
205
+ }
206
+ function number(value, fallback = 0) {
207
+ if (value === undefined || value === null || value === '')
208
+ return fallback;
209
+ const parsed = Number(value);
210
+ return Number.isFinite(parsed) ? parsed : fallback;
211
+ }
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ /**
3
+ * The web transport's privilege table and the invariant that keeps it complete.
4
+ *
5
+ * Keys stay in the `{name}` path-template spelling so the table is byte-for-byte
6
+ * comparable with the established one. Fastify's `:name` spelling is translated only at the
7
+ * boundary. This table must not move below `web/`: CLI actors are caller assertions,
8
+ * while web actors are identities the server authenticated.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.ROUTE_ROLES = void 0;
12
+ exports.toFastifyTemplate = toFastifyTemplate;
13
+ exports.toBraceTemplate = toBraceTemplate;
14
+ exports.toFastifyRouteKey = toFastifyRouteKey;
15
+ exports.toBraceRouteKey = toBraceRouteKey;
16
+ exports.routeRequirement = routeRequirement;
17
+ exports.ownerScoped = ownerScoped;
18
+ exports.unlistedRoutes = unlistedRoutes;
19
+ exports.installRouteCompleteness = installRouteCompleteness;
20
+ const headRouteModule = require('fastify/lib/head-route');
21
+ const FASTIFY_HEAD_ON_SEND = headRouteModule.parseHeadOnSendHandlers();
22
+ const OPEN = '';
23
+ const READ = 'readonly';
24
+ const WRITE = 'member';
25
+ const ADMIN = 'admin';
26
+ exports.ROUTE_ROLES = new Map([
27
+ ['GET /signin', OPEN],
28
+ ['POST /signin', OPEN],
29
+ ['POST /signout', OPEN],
30
+ ['GET /api/health', OPEN],
31
+ ['GET /api/session', OPEN],
32
+ ['POST /api/session', OPEN],
33
+ ['DELETE /api/session', OPEN],
34
+ ['GET /api/sessions', READ],
35
+ ['DELETE /api/sessions', READ],
36
+ ['GET /api/repros', READ],
37
+ ['GET /api/repros/{name}', READ],
38
+ ['GET /api/repros/{name}/detail', READ],
39
+ ['GET /api/repros/{name}/stats', READ],
40
+ ['GET /api/repros/{name}/tls', READ],
41
+ ['GET /api/repros/{name}/upgrade', READ],
42
+ ['GET /api/jobs', READ],
43
+ ['GET /api/jobs/{job_id}', READ],
44
+ ['GET /api/jobs/{job_id}/stream', READ],
45
+ ['POST /api/jobs/{job_id}/stop', WRITE],
46
+ ['GET /api/backups', READ],
47
+ ['POST /api/backups/compatibility', READ],
48
+ ['GET /api/doctor', READ],
49
+ ['GET /api/edge', READ],
50
+ ['DELETE /api/edge/hosts/{host}', ADMIN],
51
+ ['GET /api/kubernetes', READ],
52
+ ['GET /api/clusters', READ],
53
+ ['GET /api/clusters/status', READ],
54
+ ['GET /api/clusters/connection', READ],
55
+ ['POST /api/clusters/connect', ADMIN],
56
+ ['GET /api/clusters/iam-policy', READ],
57
+ ['POST /api/clusters/sweep', READ],
58
+ ['POST /api/clusters/prepare', ADMIN],
59
+ ['POST /api/clusters/create', ADMIN],
60
+ ['POST /api/clusters/delete', ADMIN],
61
+ ['POST /api/clusters/forget', ADMIN],
62
+ ['GET /api/clusters/overview', READ],
63
+ ['GET /api/clusters/estimate', READ],
64
+ ['GET /api/clusters/dns-check', READ],
65
+ ['POST /api/clusters/approve', ADMIN],
66
+ ['GET /api/docs/eks', READ],
67
+ ['GET /api/machine', READ],
68
+ ['GET /api/presets', READ],
69
+ ['GET /api/settings', READ],
70
+ ['GET /api/versions/{version}', READ],
71
+ ['GET /api/repros/{name}/logs', WRITE],
72
+ ['WS /api/repros/{name}/logs/stream', WRITE],
73
+ ['GET /api/repros/{name}/env', WRITE],
74
+ ['POST /api/repros', WRITE],
75
+ ['POST /api/repros/{name}/up', WRITE],
76
+ ['POST /api/repros/{name}/state', WRITE],
77
+ ['POST /api/repros/{name}/ready', WRITE],
78
+ ['POST /api/repros/{name}/seed', WRITE],
79
+ ['POST /api/repros/{name}/scale', WRITE],
80
+ ['DELETE /api/repros/{name}/scale', WRITE],
81
+ ['POST /api/repros/{name}/env', WRITE],
82
+ ['POST /api/repros/{name}/monitor', WRITE],
83
+ // The CLI's default for everybody on the box, so not one member's to move.
84
+ ['POST /api/repros/{name}/default', ADMIN],
85
+ ['POST /api/repros/{name}/owner', WRITE],
86
+ ['POST /api/repros/{name}/config-import', WRITE],
87
+ ['POST /api/repros/{name}/config-import/plan', WRITE],
88
+ ['POST /api/repros/{name}/backup', WRITE],
89
+ ['POST /api/repros/{name}/upgrade', WRITE],
90
+ ['POST /api/repros/{name}/upgrade/rollback', WRITE],
91
+ ['POST /api/repros/{name}/loadtest', WRITE],
92
+ ['POST /api/repros/{name}/capacity', WRITE],
93
+ ['POST /api/restore', WRITE],
94
+ ['POST /api/repros/{name}/pat', WRITE],
95
+ ['POST /api/repros/{name}/call', WRITE],
96
+ ['DELETE /api/repros/{name}', WRITE],
97
+ ['POST /api/prune', WRITE],
98
+ ['DELETE /api/backups', WRITE],
99
+ ['GET /api/users', ADMIN],
100
+ ['POST /api/users', ADMIN],
101
+ ['DELETE /api/users/{name}', ADMIN],
102
+ ['POST /api/users/{name}/role', ADMIN],
103
+ ['POST /api/users/{name}/password', ADMIN],
104
+ ['POST /api/me/password', READ],
105
+ ['GET /api/audit', READ],
106
+ ['GET /setup', OPEN],
107
+ ['GET /setup.js', OPEN],
108
+ ['POST /api/session/first-run', OPEN],
109
+ ]);
110
+ function key(method, template) {
111
+ return `${method.toUpperCase()} ${template}`;
112
+ }
113
+ /** `{one}`/`{two}` to Fastify `:one`/`:two`, for every path parameter. */
114
+ function toFastifyTemplate(template) {
115
+ return template.replaceAll(/\{([A-Za-z_][A-Za-z0-9_]*)\}/gu, ':$1');
116
+ }
117
+ /** Fastify `:one`/`:two` to `{one}`/`{two}`, for every path parameter. */
118
+ function toBraceTemplate(template) {
119
+ return template.replaceAll(/:([A-Za-z_][A-Za-z0-9_]*)/gu, '{$1}');
120
+ }
121
+ function toFastifyRouteKey([method, template]) {
122
+ // Explicitly preserve the unmatched-WebSocket sentinel. It is not a route to infer.
123
+ if (method.toUpperCase() === 'WS' && template === '')
124
+ return ['WS', ''];
125
+ return [method.toUpperCase(), toFastifyTemplate(template)];
126
+ }
127
+ function toBraceRouteKey([method, template]) {
128
+ // Same explicit sentinel in the reverse direction.
129
+ if (method.toUpperCase() === 'WS' && template === '')
130
+ return ['WS', ''];
131
+ return [method.toUpperCase(), toBraceTemplate(template)];
132
+ }
133
+ function routeRequirement(method, fastifyTemplate) {
134
+ const [translatedMethod, template] = toBraceRouteKey([method, fastifyTemplate]);
135
+ return exports.ROUTE_ROLES.get(key(translatedMethod, template)) ?? null;
136
+ }
137
+ /**
138
+ * Whether the route also needs the caller to own the workspace it names: every member route
139
+ * with a `{name}`. A member sees every workspace and changes only their own; an admin, the
140
+ * owner, and anyone on a workspace with no owner pass (`ownership.mayChange`). Derived, not
141
+ * listed, so a member route added later is covered without anyone remembering to.
142
+ */
143
+ function ownerScoped(method, fastifyTemplate) {
144
+ const [, template] = toBraceRouteKey([method, fastifyTemplate]);
145
+ return routeRequirement(method, fastifyTemplate) === WRITE && template.includes('{name}');
146
+ }
147
+ function methodsOf(method) {
148
+ return (Array.isArray(method) ? method : [method]).map(String);
149
+ }
150
+ function unlistedRoutes(routes) {
151
+ const ordinary = routes.filter((route) => !(route.config.houstonSpa === true &&
152
+ (route.url === '/' || route.url === '/*') &&
153
+ (route.method === 'GET' || route.method === 'HEAD')));
154
+ const getUrls = new Set(ordinary
155
+ .filter((route) => route.method === 'GET' && route.config.houstonTransport !== 'WS')
156
+ .map((route) => route.url));
157
+ const missing = [];
158
+ for (const route of ordinary) {
159
+ if (route.config.houstonTransport === 'WS') {
160
+ // Fastify registers a WebSocket endpoint as GET+generated HEAD. The marker is
161
+ // supplied at the registration site; never infer WS from a path or handler.
162
+ if (route.method === 'GET' && routeRequirement('WS', route.url) === null) {
163
+ missing.push(`WS ${route.url}`);
164
+ }
165
+ if (route.method === 'HEAD' && route.generatedHead !== true) {
166
+ missing.push(`HEAD ${route.url}`);
167
+ }
168
+ continue;
169
+ }
170
+ if (route.method === 'HEAD') {
171
+ // Fastify 5.12.5 generates exactly this HEAD beside every GET. It is ignored only
172
+ // when that exact GET was observed and declared; a hand-registered HEAD still fails.
173
+ if (route.generatedHead !== true ||
174
+ !getUrls.has(route.url) ||
175
+ routeRequirement('GET', route.url) === null) {
176
+ missing.push(`HEAD ${route.url}`);
177
+ }
178
+ continue;
179
+ }
180
+ if (routeRequirement(route.method, route.url) === null) {
181
+ missing.push(`${route.method} ${route.url}`);
182
+ }
183
+ }
184
+ return [...new Set(missing)].sort();
185
+ }
186
+ /** Capture the real Fastify registry and fail closed after every plugin has registered. */
187
+ function installRouteCompleteness(app) {
188
+ const registered = [];
189
+ const lastGetHandler = new Map();
190
+ app.addHook('onRoute', (options) => {
191
+ for (const method of methodsOf(options.method)) {
192
+ const onSend = Array.isArray(options.onSend) ? options.onSend : [options.onSend];
193
+ const generatedHead = method === 'HEAD' &&
194
+ lastGetHandler.get(options.url) === options.handler &&
195
+ onSend.includes(FASTIFY_HEAD_ON_SEND);
196
+ registered.push({
197
+ method,
198
+ url: options.url,
199
+ config: options.config ?? {},
200
+ ...(generatedHead ? { generatedHead: true } : {}),
201
+ });
202
+ if (method === 'GET')
203
+ lastGetHandler.set(options.url, options.handler);
204
+ }
205
+ });
206
+ app.addHook('onReady', () => {
207
+ const missing = unlistedRoutes(registered);
208
+ if (missing.length > 0) {
209
+ throw new Error(`registered routes missing from ROUTE_ROLES: ${missing.join(', ')}`);
210
+ }
211
+ });
212
+ return registered;
213
+ }
@@ -0,0 +1,244 @@
1
+ "use strict";
2
+ /** Managed backups, restores, upgrades, and rollbacks. */
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.register = register;
38
+ const path = __importStar(require("node:path"));
39
+ const naming_1 = require("../../core/lifecycle/naming");
40
+ const record_1 = require("../../core/runner/record");
41
+ const errors_1 = require("../../lib/errors");
42
+ const home_1 = require("../../lib/home");
43
+ const format_1 = require("../../lib/format");
44
+ const route_deps_1 = require("../route-deps");
45
+ const security_1 = require("../security");
46
+ function backupModule() {
47
+ return require('../../core/backup');
48
+ }
49
+ function ownershipModule() {
50
+ return require('../../core/lifecycle/ownership');
51
+ }
52
+ function backupCompatModule() {
53
+ return require('../../core/backup-compat');
54
+ }
55
+ function upgradeModule() {
56
+ return require('../../core/upgrade');
57
+ }
58
+ /**
59
+ * The caller's path, as a confined backup path takes it: `~` expanded, joined onto the
60
+ * RESOLVED managed directory when it is not absolute, and then resolved. `~` is expanded in
61
+ * the caller's path ONLY, and BEFORE the is-absolute check.
62
+ *
63
+ * An earlier version had it the other way round in both places. It expanded a `~` in the
64
+ * managed directory, which resolving that directory never does -- a `HOUSTON_HOME` spelled
65
+ * `~/x` is `x` under a directory named `~`, and was the home to this. And it asked whether
66
+ * the caller's path was absolute FIRST: `~/x` is not, so it became `<backups>/~/x` and was
67
+ * let through as inside the directory, where it must be expanded to `$HOME/x` and refused
68
+ * -- or, for `~/.houston/backups/a.rcbak`, read as that bundle rather than as a `~`
69
+ * directory inside the backups. A `~name` nobody has is a `HomeUnknown` out of the
70
+ * expansion, a 500, as it always has been.
71
+ *
72
+ * Resolved with `pathResolve`, not `path.resolve` and `fs.realpathSync`, which fold a `..`
73
+ * before any link is read: with `HOUSTON_HOME=link/../hh` and `link -> other/sub` the
74
+ * managed directory was `hh` under the working directory, where the kernel finds
75
+ * `other/hh`.
76
+ */
77
+ function confined(given, root) {
78
+ const expanded = (0, home_1.pathExpandUser)(given);
79
+ return (0, home_1.pathResolve)(expanded.startsWith('/') ? expanded : (0, home_1.joinPath)(root, expanded));
80
+ }
81
+ /** Whether `candidate` is neither `root` nor inside it, for two resolved paths. */
82
+ function outside(candidate, root) {
83
+ return candidate !== root && !candidate.startsWith(root === '/' ? '/' : `${root}/`);
84
+ }
85
+ /**
86
+ * '' when `who` may use the bundle at `inside` (already confined): it is a workspace's data,
87
+ * so a member deletes or restores only their own workspaces' bundles. One that names no
88
+ * workspace, or one that is gone, has nobody left to ask.
89
+ */
90
+ async function bundleRefusal(inside, who) {
91
+ // ITS OWN OWNER FIRST. A bundle outlives its workspace: once that was deleted, or a newer one
92
+ // took its name, the check below asked about nobody or about the wrong person, and a member
93
+ // could delete a colleague's only copy of their data.
94
+ const owner = await backupModule().bundleOwner(inside);
95
+ if (owner !== '') {
96
+ const [allowed, holder] = ownershipModule().ownedGate(owner, who);
97
+ return allowed
98
+ ? ''
99
+ : `this backup is ${holder}'s data — only ${holder} or an admin can use or delete it`;
100
+ }
101
+ let repro;
102
+ try {
103
+ repro = String((await backupModule().readManifest(inside)).repro ?? '');
104
+ }
105
+ catch {
106
+ return '';
107
+ }
108
+ return repro === '' ? '' : await (0, security_1.workspaceRefusal)(repro, who);
109
+ }
110
+ function confinedInput(bundle) {
111
+ if (bundle === '')
112
+ throw new errors_1.ValidationError('no bundle given');
113
+ const root = (0, home_1.pathResolve)(backupModule().backupsDir());
114
+ let candidate;
115
+ try {
116
+ candidate = confined(bundle, root);
117
+ }
118
+ catch (error) {
119
+ // Only a failed system call is "could not read"; the `HomeUnknown` of a `~` expansion
120
+ // or the error of a symlink loop is the 500 it has always been.
121
+ if (typeof error.errno !== 'number')
122
+ throw error;
123
+ throw new errors_1.ValidationError(`could not read ${(0, format_1.quotedText)(bundle)}: ${(0, format_1.fileErrorText)(error)}`);
124
+ }
125
+ if (outside(candidate, root)) {
126
+ throw new errors_1.ValidationError(`\`bundle\` must be inside ${root} — the HTTP API cannot read arbitrary paths on ` +
127
+ 'the server (the CLI still can)');
128
+ }
129
+ return candidate;
130
+ }
131
+ function confinedOutput(output) {
132
+ if (output === '')
133
+ return '';
134
+ // No catch around the resolve, unlike `confinedInput`: a failure here propagates as it is.
135
+ const root = (0, home_1.pathResolve)(backupModule().backupsDir());
136
+ const candidate = confined(output, root);
137
+ if (outside(candidate, root)) {
138
+ throw new errors_1.ValidationError(`\`out\` must be inside ${root} — the HTTP API cannot choose arbitrary paths on ` +
139
+ "the server (the CLI's --out still can)");
140
+ }
141
+ return candidate;
142
+ }
143
+ function register(app) {
144
+ app.post('/api/repros/:name/backup', async (request) => {
145
+ const backup = backupModule();
146
+ const body = (0, route_deps_1.requestBody)(request.body, false);
147
+ const target = await (0, naming_1.resolveName)(request.params.name);
148
+ const output = confinedOutput((0, route_deps_1.orText)(body.out));
149
+ return (0, route_deps_1.submit)(app, 'backup', (emit) => backup.create(target, {
150
+ out: output,
151
+ note: (0, route_deps_1.orText)(body.label),
152
+ live: (0, route_deps_1.bool)(body.live),
153
+ emit,
154
+ }), { label: target });
155
+ });
156
+ app.get('/api/backups', async (request) => ({
157
+ backups: await backupModule().listBackups((0, route_deps_1.queryText)(request.query.name, '', 'name')),
158
+ }));
159
+ app.delete('/api/backups', async (request) => {
160
+ const bundle = (0, route_deps_1.queryText)(request.query.path, '', 'path', true);
161
+ let inside = '';
162
+ try {
163
+ inside = confinedInput(bundle);
164
+ }
165
+ catch {
166
+ // outside the managed directory: `deleteBackup` refuses it, and nothing is read
167
+ }
168
+ const why = inside === '' ? '' : await bundleRefusal(inside, (0, route_deps_1.actor)(request));
169
+ if (why !== '')
170
+ throw new errors_1.ConflictError(why);
171
+ return await backupModule().deleteBackup(bundle);
172
+ });
173
+ app.post('/api/backups/compatibility', async (request) => {
174
+ const backup = backupModule();
175
+ const body = (0, route_deps_1.requestBody)(request.body, true);
176
+ const bundle = confinedInput((0, route_deps_1.orText)(body.bundle));
177
+ const manifest = await backup.readManifest(bundle);
178
+ const name = (0, route_deps_1.orText)(body.name);
179
+ if (name === '') {
180
+ // AS NEW, which builds the bundle's preset again, on side ports of its own: another
181
+ // workspace holding the preferred ones gives it the next free ones, so there is no
182
+ // holder to name. Whether THIS viewer may use the bundle at all is said here, so the
183
+ // dialog can say who can before a click is refused: '' when they may.
184
+ const refusal = await bundleRefusal(bundle, (0, route_deps_1.actor)(request));
185
+ return { manifest, compatibility: null, refusal };
186
+ }
187
+ const meta = await (0, record_1.readMeta)(await (0, naming_1.resolveName)(name));
188
+ return { manifest, compatibility: backupCompatModule().compatibility(manifest, meta) };
189
+ });
190
+ app.post('/api/restore', async (request) => {
191
+ const backup = backupModule();
192
+ const body = (0, route_deps_1.requestBody)(request.body, true);
193
+ const bundle = confinedInput((0, route_deps_1.orText)(body.bundle));
194
+ const name = (0, route_deps_1.orText)(body.name);
195
+ // Restored as new, a colleague's bundle would hand over their data and admin login.
196
+ const why = await bundleRefusal(bundle, (0, route_deps_1.actor)(request));
197
+ if (why !== '')
198
+ throw new errors_1.ConflictError(why);
199
+ return (0, route_deps_1.submit)(app, 'restore', (emit) => backup.restore(bundle, {
200
+ name,
201
+ new: (0, route_deps_1.bool)(body.new),
202
+ allowUpgrade: (0, route_deps_1.bool)(body.allow_upgrade),
203
+ force: (0, route_deps_1.bool)(body.force),
204
+ emit,
205
+ }), { label: name || path.basename(bundle) });
206
+ });
207
+ app.get('/api/repros/:name/upgrade', async (request) => {
208
+ const upgrade = upgradeModule();
209
+ const offline = (0, route_deps_1.queryBool)(request.query.offline, false, 'offline');
210
+ const state = await upgrade.canUpgrade(request.params.name);
211
+ const to = (0, route_deps_1.queryText)(request.query.to, '', 'to');
212
+ if (to !== '' && state.can_upgrade === true) {
213
+ state.plan = await upgrade.plan(request.params.name, to, {
214
+ offline,
215
+ });
216
+ }
217
+ return state;
218
+ });
219
+ app.post('/api/repros/:name/upgrade', async (request) => {
220
+ const upgrade = upgradeModule();
221
+ const body = (0, route_deps_1.requestBody)(request.body, true);
222
+ const target = await (0, naming_1.resolveName)(request.params.name);
223
+ const to = (0, route_deps_1.orText)(body.to);
224
+ if (to === '')
225
+ throw new errors_1.ValidationError('no target version given, e.g. {"to": "8.6.1"}');
226
+ return (0, route_deps_1.submit)(app, 'upgrade', (emit) => upgrade.run(target, to, {
227
+ offline: (0, route_deps_1.bool)(body.offline),
228
+ force: (0, route_deps_1.bool)(body.force),
229
+ noBackup: (0, route_deps_1.bool)(body.no_backup),
230
+ rollbackOnFailure: body.rollback_on_failure === undefined || (0, route_deps_1.bool)(body.rollback_on_failure),
231
+ emit,
232
+ }), { label: target });
233
+ });
234
+ app.post('/api/repros/:name/upgrade/rollback', async (request) => {
235
+ const upgrade = upgradeModule();
236
+ const body = (0, route_deps_1.requestBody)(request.body, false);
237
+ const target = await (0, naming_1.resolveName)(request.params.name);
238
+ const rawBundle = (0, route_deps_1.orText)(body.bundle);
239
+ const bundle = rawBundle === '' ? '' : confinedInput(rawBundle);
240
+ return (0, route_deps_1.submit)(app, 'rollback', (emit) => upgrade.rollback(target, { bundle, emit }), {
241
+ label: target,
242
+ });
243
+ });
244
+ }