@rocket.chat/houston 0.27.0-next.2 → 2.1.8

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 (291) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +108 -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 +669 -0
  10. package/data/docs/kubernetes.md +138 -0
  11. package/data/docs/troubleshooting.md +193 -0
  12. package/data/docs/upgrading.md +84 -0
  13. package/data/docs/voice.md +253 -0
  14. package/data/iam/engineer-policy.json +11 -0
  15. package/data/iam/engineer-rbac.yaml +42 -0
  16. package/data/iam/operator-policy.json +211 -0
  17. package/data/loadtest/badbot.js +22 -0
  18. package/data/loadtest/common.js +168 -0
  19. package/data/loadtest/custom.js +20 -0
  20. package/data/loadtest/journey.js +58 -0
  21. package/data/loadtest/login.js +18 -0
  22. package/data/loadtest/messages.js +13 -0
  23. package/data/loadtest/mixed.js +39 -0
  24. package/data/loadtest/read.js +12 -0
  25. package/data/loadtest/webhook.js +20 -0
  26. package/data/monitoring/houston-logs.json +98 -0
  27. package/data/monitoring/k6-loadtest.json +610 -0
  28. package/data/monitoring/mongodb-exporter.json +3007 -0
  29. package/data/monitoring/node-exporter-full.json +16114 -0
  30. package/data/monitoring/rocketchat-metrics.json +6471 -0
  31. package/data/presets/airgapped.yaml +16 -0
  32. package/data/presets/default.yaml +9 -0
  33. package/data/seed/avatar-0.png +0 -0
  34. package/data/seed/avatar-1.png +0 -0
  35. package/data/seed/avatar-2.png +0 -0
  36. package/data/seed/avatar-3.png +0 -0
  37. package/data/seed/avatar-4.png +0 -0
  38. package/data/seed/avatar-5.png +0 -0
  39. package/data/seed/avatar-6.png +0 -0
  40. package/data/seed/avatar-7.png +0 -0
  41. package/data/seed/seed-metrics.csv +3 -0
  42. package/data/seed/seed-preview.png +0 -0
  43. package/data/seed/seed-report.pdf +32 -0
  44. package/data/seed/seed-runbook.txt +3 -0
  45. package/data/skill/SKILL.md +399 -0
  46. package/data/versions.yaml +55 -0
  47. package/data/voice/freeswitch/drachtio.xml +52 -0
  48. package/data/voice/freeswitch/public.xml +87 -0
  49. package/data/webui/app.css +2003 -0
  50. package/data/webui/index.html +678 -0
  51. package/data/webui/js/api.js +561 -0
  52. package/data/webui/js/boot.js +44 -0
  53. package/data/webui/js/clusters-tail.js +1377 -0
  54. package/data/webui/js/clusters.js +896 -0
  55. package/data/webui/js/create.js +276 -0
  56. package/data/webui/js/detail.js +507 -0
  57. package/data/webui/js/jobs.js +636 -0
  58. package/data/webui/js/logs.js +634 -0
  59. package/data/webui/js/main.js +14 -0
  60. package/data/webui/js/options.js +408 -0
  61. package/data/webui/js/people.js +438 -0
  62. package/data/webui/js/perf.js +303 -0
  63. package/data/webui/js/render.js +438 -0
  64. package/data/webui/js/shared.js +3 -0
  65. package/data/webui/js/state.js +583 -0
  66. package/data/webui/js/theme.js +123 -0
  67. package/data/webui/js/util.js +584 -0
  68. package/dist/cli/app.js +593 -0
  69. package/dist/cli/capabilities.js +76 -0
  70. package/dist/cli/cell-widths.js +495 -0
  71. package/dist/cli/entry.js +10 -0
  72. package/dist/cli/error-panel.js +492 -0
  73. package/dist/cli/handlers/actor.js +84 -0
  74. package/dist/cli/handlers/https.js +614 -0
  75. package/dist/cli/handlers/prompt.js +299 -0
  76. package/dist/cli/handlers/users.js +226 -0
  77. package/dist/cli/handlers.js +3678 -0
  78. package/dist/cli/help.js +183 -0
  79. package/dist/cli/index.js +15 -0
  80. package/dist/cli/perf.js +810 -0
  81. package/dist/cli/render.js +254 -0
  82. package/dist/cli/serve.js +858 -0
  83. package/dist/cli/spec-data.js +2593 -0
  84. package/dist/cli/spec-types.js +8 -0
  85. package/dist/cli/usage-error.js +520 -0
  86. package/dist/cli/wire.js +70 -0
  87. package/dist/core/audit.js +346 -0
  88. package/dist/core/backup-compat.js +85 -0
  89. package/dist/core/backup.js +1639 -0
  90. package/dist/core/cluster.js +1398 -0
  91. package/dist/core/configimport.js +344 -0
  92. package/dist/core/data.js +267 -0
  93. package/dist/core/database-of.js +82 -0
  94. package/dist/core/diagnose.js +159 -0
  95. package/dist/core/doctor.js +1518 -0
  96. package/dist/core/edge/acme.js +338 -0
  97. package/dist/core/edge/engine.js +500 -0
  98. package/dist/core/edge/networks.js +174 -0
  99. package/dist/core/edge/paths.js +107 -0
  100. package/dist/core/edge/routes.js +251 -0
  101. package/dist/core/edge/routeyml.js +195 -0
  102. package/dist/core/edge/runtime.js +493 -0
  103. package/dist/core/edge/spec.js +305 -0
  104. package/dist/core/edge/types.js +202 -0
  105. package/dist/core/eks-docs.js +135 -0
  106. package/dist/core/eks.js +2240 -0
  107. package/dist/core/envvars.js +562 -0
  108. package/dist/core/eventlog.js +541 -0
  109. package/dist/core/firstrun.js +153 -0
  110. package/dist/core/journal.js +691 -0
  111. package/dist/core/kube/ask.js +231 -0
  112. package/dist/core/kube/capabilities.js +269 -0
  113. package/dist/core/kube/certmanager.js +452 -0
  114. package/dist/core/kube/chart.js +413 -0
  115. package/dist/core/kube/cluster.js +196 -0
  116. package/dist/core/kube/context.js +545 -0
  117. package/dist/core/kube/endpoints.js +448 -0
  118. package/dist/core/kube/exec.js +195 -0
  119. package/dist/core/kube/forward.js +732 -0
  120. package/dist/core/kube/grafana-ingress.js +110 -0
  121. package/dist/core/kube/ingress.js +218 -0
  122. package/dist/core/kube/manifests.js +361 -0
  123. package/dist/core/kube/monitoring.js +768 -0
  124. package/dist/core/kube/names.js +237 -0
  125. package/dist/core/kube/namespace.js +678 -0
  126. package/dist/core/kube/operator.js +941 -0
  127. package/dist/core/kube/probe.js +202 -0
  128. package/dist/core/kube/reachability.js +163 -0
  129. package/dist/core/kube/release.js +439 -0
  130. package/dist/core/kube/replicaset.js +180 -0
  131. package/dist/core/kube/scale.js +398 -0
  132. package/dist/core/kube/status.js +633 -0
  133. package/dist/core/kube/tools.js +238 -0
  134. package/dist/core/kube/transfer.js +173 -0
  135. package/dist/core/kube/workspace.js +423 -0
  136. package/dist/core/lifecycle/admin.js +64 -0
  137. package/dist/core/lifecycle/create-docker.js +1533 -0
  138. package/dist/core/lifecycle/create-k8s.js +939 -0
  139. package/dist/core/lifecycle/destroy.js +339 -0
  140. package/dist/core/lifecycle/inspect.js +635 -0
  141. package/dist/core/lifecycle/naming.js +298 -0
  142. package/dist/core/lifecycle/notes.js +726 -0
  143. package/dist/core/lifecycle/ownership.js +313 -0
  144. package/dist/core/lifecycle/payload.js +401 -0
  145. package/dist/core/lifecycle/ports.js +388 -0
  146. package/dist/core/lifecycle/preconditions.js +367 -0
  147. package/dist/core/lifecycle/pruning.js +551 -0
  148. package/dist/core/lifecycle/ready.js +753 -0
  149. package/dist/core/lifecycle/request.js +525 -0
  150. package/dist/core/lifecycle/seeding.js +281 -0
  151. package/dist/core/lifecycle/sizing.js +392 -0
  152. package/dist/core/lifecycle/state.js +286 -0
  153. package/dist/core/lifecycle/tlsplan.js +704 -0
  154. package/dist/core/lifecycle/types.js +232 -0
  155. package/dist/core/loadtest.js +995 -0
  156. package/dist/core/migrate.js +612 -0
  157. package/dist/core/monitor.js +494 -0
  158. package/dist/core/postready.js +969 -0
  159. package/dist/core/promote.js +804 -0
  160. package/dist/core/rcapi.js +1285 -0
  161. package/dist/core/recovery.js +75 -0
  162. package/dist/core/runner/engine.js +394 -0
  163. package/dist/core/runner/host.js +298 -0
  164. package/dist/core/runner/locks.js +129 -0
  165. package/dist/core/runner/paths.js +173 -0
  166. package/dist/core/runner/ports.js +172 -0
  167. package/dist/core/runner/queries.js +612 -0
  168. package/dist/core/runner/record.js +563 -0
  169. package/dist/core/scaleseed.js +271 -0
  170. package/dist/core/seed-db.js +208 -0
  171. package/dist/core/sessions.js +472 -0
  172. package/dist/core/skill.js +326 -0
  173. package/dist/core/sso-identities.js +172 -0
  174. package/dist/core/sso.js +703 -0
  175. package/dist/core/tls-local.js +311 -0
  176. package/dist/core/tls.js +878 -0
  177. package/dist/core/topology.js +482 -0
  178. package/dist/core/upgrade.js +868 -0
  179. package/dist/core/users.js +739 -0
  180. package/dist/lib/audit.js +100 -0
  181. package/dist/lib/close-matches.js +238 -0
  182. package/dist/lib/compose.js +672 -0
  183. package/dist/lib/config.js +1398 -0
  184. package/dist/lib/context.js +18 -0
  185. package/dist/lib/errors.js +305 -0
  186. package/dist/lib/events.js +208 -0
  187. package/dist/lib/float-text.js +126 -0
  188. package/dist/lib/format.js +1320 -0
  189. package/dist/lib/home.js +325 -0
  190. package/dist/lib/journal.js +122 -0
  191. package/dist/lib/json-text.js +733 -0
  192. package/dist/lib/jsonout.js +382 -0
  193. package/dist/lib/lock.js +516 -0
  194. package/dist/lib/login-name.js +202 -0
  195. package/dist/lib/map-limit.js +29 -0
  196. package/dist/lib/mkdir-parents.js +90 -0
  197. package/dist/lib/mongo-kernel.js +67 -0
  198. package/dist/lib/monitoring.js +492 -0
  199. package/dist/lib/platform-name.js +59 -0
  200. package/dist/lib/presets/common.js +390 -0
  201. package/dist/lib/presets/composite.js +326 -0
  202. package/dist/lib/presets/e2ee.js +143 -0
  203. package/dist/lib/presets/email.js +172 -0
  204. package/dist/lib/presets/guides.js +27 -0
  205. package/dist/lib/presets/index.js +490 -0
  206. package/dist/lib/presets/keycloak.js +369 -0
  207. package/dist/lib/presets/ldap.js +1285 -0
  208. package/dist/lib/presets/livechat.js +220 -0
  209. package/dist/lib/presets/multi-instance.js +124 -0
  210. package/dist/lib/presets/oidc.js +161 -0
  211. package/dist/lib/presets/public.js +496 -0
  212. package/dist/lib/presets/registry.js +64 -0
  213. package/dist/lib/presets/s3-minio.js +300 -0
  214. package/dist/lib/presets/saml.js +149 -0
  215. package/dist/lib/presets/scenario.js +51 -0
  216. package/dist/lib/presets/types.js +86 -0
  217. package/dist/lib/presets/voice-pbx.js +320 -0
  218. package/dist/lib/presets/voice.js +345 -0
  219. package/dist/lib/presets/webhooks.js +182 -0
  220. package/dist/lib/redact.js +106 -0
  221. package/dist/lib/seed-options.js +68 -0
  222. package/dist/lib/seed-profiles.js +59 -0
  223. package/dist/lib/targz.js +1383 -0
  224. package/dist/lib/teammode.js +25 -0
  225. package/dist/lib/tempdir.js +162 -0
  226. package/dist/lib/unicode-tables.js +2335 -0
  227. package/dist/lib/version-spec.js +357 -0
  228. package/dist/lib/versions.js +463 -0
  229. package/dist/lib/yaml-dump.js +1361 -0
  230. package/dist/perf/baseline.js +168 -0
  231. package/dist/perf/constrain.js +296 -0
  232. package/dist/perf/k6.js +235 -0
  233. package/dist/perf/mongoprof.js +171 -0
  234. package/dist/perf/rcmetrics.js +178 -0
  235. package/dist/perf/report.js +386 -0
  236. package/dist/perf/resources.js +224 -0
  237. package/dist/perf/slo.js +111 -0
  238. package/dist/perf/timeline.js +187 -0
  239. package/dist/perf/timings.js +85 -0
  240. package/dist/perf/verdict.js +201 -0
  241. package/dist/seams/aws-cli.js +126 -0
  242. package/dist/seams/docker-cli.js +280 -0
  243. package/dist/seams/exec.js +861 -0
  244. package/dist/seams/fs/lock.js +528 -0
  245. package/dist/seams/kubectl.js +83 -0
  246. package/dist/seams/rc-http.js +921 -0
  247. package/dist/seed/apply.js +190 -0
  248. package/dist/seed/assets.js +76 -0
  249. package/dist/seed/check.js +391 -0
  250. package/dist/seed/client.js +172 -0
  251. package/dist/seed/executor.js +726 -0
  252. package/dist/seed/history.js +281 -0
  253. package/dist/seed/kinds.js +91 -0
  254. package/dist/seed/plan.js +432 -0
  255. package/dist/seed/receipt.js +339 -0
  256. package/dist/seed/repairs.js +75 -0
  257. package/dist/seed/verification.js +363 -0
  258. package/dist/seed/wording.js +248 -0
  259. package/dist/web/app.js +326 -0
  260. package/dist/web/jobs.js +510 -0
  261. package/dist/web/route-deps.js +211 -0
  262. package/dist/web/route-table.js +213 -0
  263. package/dist/web/routes/backup.js +244 -0
  264. package/dist/web/routes/clusters.js +303 -0
  265. package/dist/web/routes/data.js +187 -0
  266. package/dist/web/routes/edge.js +82 -0
  267. package/dist/web/routes/index.js +63 -0
  268. package/dist/web/routes/jobs.js +95 -0
  269. package/dist/web/routes/logs.js +297 -0
  270. package/dist/web/routes/meta.js +191 -0
  271. package/dist/web/routes/people.js +151 -0
  272. package/dist/web/routes/perf.js +95 -0
  273. package/dist/web/routes/repros.js +550 -0
  274. package/dist/web/routes/session.js +361 -0
  275. package/dist/web/routes/spa.js +198 -0
  276. package/dist/web/security.js +475 -0
  277. package/dist/web/signin.js +246 -0
  278. package/package.json +67 -32
  279. package/.eslintrc +0 -94
  280. package/.swcrc +0 -18
  281. package/dist/bin.js +0 -3
  282. package/dist/cli.js +0 -184
  283. package/dist/commands/createBranch.js +0 -192
  284. package/src/bin.js +0 -4
  285. package/src/cli.ts +0 -25
  286. package/src/commands/createBranch.ts +0 -25
  287. package/src-old/logs.js +0 -323
  288. package/src-old/md.js +0 -191
  289. package/src-old/release-table.js +0 -60
  290. package/src-old/set-version.js +0 -614
  291. package/src-old/utils.js +0 -15
@@ -0,0 +1,492 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.PROCESS_CONSOLE = void 0;
37
+ exports.characterCells = characterCells;
38
+ exports.cellLen = cellLen;
39
+ exports.wrap = wrap;
40
+ exports.printed = printed;
41
+ exports.errorPanel = errorPanel;
42
+ exports.consoleWidth = consoleWidth;
43
+ exports.consoleColumns = consoleColumns;
44
+ exports.formatterColumns = formatterColumns;
45
+ /**
46
+ * What a usage error is drawn with: the console's width, word wrapping in terminal cells,
47
+ * and the rounded `Error` panel.
48
+ *
49
+ * The frozen CLI reports a usage error as one block: the Usage line, a
50
+ * `Try '<command> --help' for help.` line, then the message inside a panel as wide as the
51
+ * console. The owner's decision is that the TypeScript CLI prints those bytes exactly as
52
+ * earlier releases did, uncoloured -- so the width, the wrap and the point where a message
53
+ * is cut are the established ones. Every function here reproduces one step of that
54
+ * rendering exactly; nothing is a lookalike.
55
+ *
56
+ * LEFT OUT, on purpose: colour and styles (the owner chose uncoloured output; on a terminal
57
+ * the established output also carries SGR codes and this does not), legacy Windows consoles,
58
+ * Jupyter, the ASCII box substituted on a non-UTF-8 stream, and the `UNICODE_VERSION`
59
+ * override -- the width table is the latest one, which is what applies when that is unset.
60
+ */
61
+ const tty = __importStar(require("node:tty"));
62
+ const format_1 = require("../lib/format");
63
+ const cell_widths_1 = require("./cell-widths");
64
+ // ---------------------------------------------------------------------------- cells
65
+ /** Characters known to be one cell wide without a table lookup. */
66
+ const SINGLE_CELL_RANGES = [
67
+ [0x20, 0x7e],
68
+ [0xa0, 0xac],
69
+ [0xae, 0x2ff],
70
+ [0x370, 0x482],
71
+ [0x2500, 0x25fc],
72
+ [0x2800, 0x28ff],
73
+ ];
74
+ const ZWJ = 0x200d;
75
+ const VS16 = 0xfe0f;
76
+ function codes(text) {
77
+ return Array.from(text, (ch) => ch.codePointAt(0));
78
+ }
79
+ function fromCodes(points) {
80
+ return String.fromCodePoint(...points);
81
+ }
82
+ function isSingleCell(point) {
83
+ return SINGLE_CELL_RANGES.some(([start, end]) => point >= start && point <= end);
84
+ }
85
+ /** A code point's width: 0, 1 or 2 cells. */
86
+ function characterCells(point) {
87
+ if ((point && point < 32) || (point >= 0x7f && point < 0xa0))
88
+ return 0;
89
+ const last = cell_widths_1.CELL_WIDTHS[cell_widths_1.CELL_WIDTHS.length - 1];
90
+ if (point > last[1])
91
+ return 1;
92
+ let lower = 0;
93
+ let upper = cell_widths_1.CELL_WIDTHS.length - 1;
94
+ while (lower <= upper) {
95
+ const index = (lower + upper) >> 1;
96
+ const [start, end, width] = cell_widths_1.CELL_WIDTHS[index];
97
+ if (point < start)
98
+ upper = index - 1;
99
+ else if (point > end)
100
+ lower = index + 1;
101
+ else
102
+ return width;
103
+ }
104
+ return 1;
105
+ }
106
+ /** The cells `text` occupies, zero-width joiners and VS16 included. */
107
+ function cellLen(text) {
108
+ return cellLenOf(codes(text));
109
+ }
110
+ function cellLenOf(points) {
111
+ if (points.every(isSingleCell))
112
+ return points.length;
113
+ if (!points.includes(ZWJ) && !points.includes(VS16)) {
114
+ return points.reduce((sum, point) => sum + characterCells(point), 0);
115
+ }
116
+ let total = 0;
117
+ let last = null;
118
+ for (let index = 0; index < points.length; index += 1) {
119
+ const point = points[index];
120
+ if (point === ZWJ) {
121
+ // The joiner AND the character it joins are skipped: the count advances twice here.
122
+ index += 1;
123
+ continue;
124
+ }
125
+ if (point === VS16) {
126
+ if (last !== null) {
127
+ total += cell_widths_1.NARROW_TO_WIDE.has(last) ? 1 : 0;
128
+ last = null;
129
+ }
130
+ continue;
131
+ }
132
+ const width = characterCells(point);
133
+ if (width) {
134
+ last = point;
135
+ total += width;
136
+ }
137
+ }
138
+ return total;
139
+ }
140
+ /** One span per grapheme, covering every code point. */
141
+ function splitGraphemes(points) {
142
+ const spans = [];
143
+ let index = 0;
144
+ let last = null;
145
+ while (index < points.length) {
146
+ const point = points[index];
147
+ if (point === ZWJ || point === VS16) {
148
+ if (spans.length === 0) {
149
+ spans.push([index, index + 1, 0]);
150
+ index += 1;
151
+ continue;
152
+ }
153
+ const previous = spans[spans.length - 1];
154
+ if (point === ZWJ) {
155
+ index += index < points.length - 1 ? 2 : 1;
156
+ spans[spans.length - 1] = [previous[0], index, previous[2]];
157
+ }
158
+ else {
159
+ index += 1;
160
+ let cells = previous[2];
161
+ if (last !== null && cell_widths_1.NARROW_TO_WIDE.has(last)) {
162
+ last = null;
163
+ cells += 1;
164
+ }
165
+ spans[spans.length - 1] = [previous[0], index, cells];
166
+ }
167
+ continue;
168
+ }
169
+ const width = characterCells(point);
170
+ if (width) {
171
+ last = point;
172
+ spans.push([index, index + 1, width]);
173
+ }
174
+ else if (spans.length > 0) {
175
+ const previous = spans[spans.length - 1];
176
+ spans[spans.length - 1] = [previous[0], index + 1, previous[2]];
177
+ }
178
+ else {
179
+ spans.push([index, index + 1, 0]);
180
+ }
181
+ index += 1;
182
+ }
183
+ return spans;
184
+ }
185
+ /** `text` in pieces of at most `width` cells. */
186
+ function chopCells(points, width) {
187
+ // The established rendering fails outright on a zero width; a console that narrow draws
188
+ // nothing useful either way, and this must not loop.
189
+ if (width < 1)
190
+ return [[...points]];
191
+ if (points.every(isSingleCell)) {
192
+ const out = [];
193
+ for (let at = 0; at < points.length; at += width)
194
+ out.push(points.slice(at, at + width));
195
+ return out;
196
+ }
197
+ const lines = [];
198
+ let size = 0;
199
+ let offset = 0;
200
+ for (const [start, , cells] of splitGraphemes(points)) {
201
+ if (size + cells > width) {
202
+ lines.push(points.slice(offset, start));
203
+ offset = start;
204
+ size = 0;
205
+ }
206
+ size += cells;
207
+ }
208
+ if (size)
209
+ lines.push(points.slice(offset));
210
+ return lines;
211
+ }
212
+ /** A crop: the longest prefix within `total` cells. */
213
+ function cropCells(points, total) {
214
+ if (points.every(isSingleCell))
215
+ return points.slice(0, total);
216
+ if (total <= 0)
217
+ return [];
218
+ const out = [];
219
+ let size = 0;
220
+ for (const [start, end, cells] of splitGraphemes(points)) {
221
+ if (size + cells > total) {
222
+ // A double-width character cut in half becomes a space.
223
+ if (size < total)
224
+ out.push(0x20);
225
+ break;
226
+ }
227
+ out.push(...points.slice(start, end));
228
+ size += cells;
229
+ }
230
+ return out;
231
+ }
232
+ // -------------------------------------------------------------------------- wrapping
233
+ /**
234
+ * What the wrap treats as whitespace: TAB through CR, the separators 0x1C-0x1F, space, NEL,
235
+ * and every Unicode space, line and paragraph separator.
236
+ */
237
+ const SPACE_CHARS = new Set([
238
+ 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x85, 0xa0, 0x1680, 0x2000, 0x2001,
239
+ 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200a, 0x2028, 0x2029, 0x202f,
240
+ 0x205f, 0x3000,
241
+ ]);
242
+ /** A line's words: `\s*\S+\s*` matched repeatedly from the start, `\s` being `SPACE_CHARS`. */
243
+ function words(points) {
244
+ const out = [];
245
+ let at = 0;
246
+ while (at < points.length) {
247
+ const start = at;
248
+ while (at < points.length && SPACE_CHARS.has(points[at]))
249
+ at += 1;
250
+ if (at === points.length)
251
+ break;
252
+ while (at < points.length && !SPACE_CHARS.has(points[at]))
253
+ at += 1;
254
+ while (at < points.length && SPACE_CHARS.has(points[at]))
255
+ at += 1;
256
+ out.push([start, points.slice(start, at)]);
257
+ }
258
+ return out;
259
+ }
260
+ function rstripped(points) {
261
+ let end = points.length;
262
+ while (end > 0 && SPACE_CHARS.has(points[end - 1]))
263
+ end -= 1;
264
+ return points.slice(0, end);
265
+ }
266
+ /** The code point offsets to break `text` at, a word wider than `width` folded. */
267
+ function divideLine(points, width) {
268
+ const breaks = [];
269
+ let offset = 0;
270
+ for (const [begin, word] of words(points)) {
271
+ let start = begin;
272
+ const wordLength = cellLenOf(rstripped(word));
273
+ const remaining = width - offset;
274
+ if (remaining >= wordLength) {
275
+ offset += cellLenOf(word);
276
+ }
277
+ else if (wordLength > width) {
278
+ const folded = chopCells(word, width);
279
+ folded.forEach((line, index) => {
280
+ if (start)
281
+ breaks.push(start);
282
+ if (index === folded.length - 1)
283
+ offset = cellLenOf(line);
284
+ else
285
+ start += line.length;
286
+ });
287
+ }
288
+ else if (offset && start) {
289
+ breaks.push(start);
290
+ offset = cellLenOf(word);
291
+ }
292
+ }
293
+ return breaks;
294
+ }
295
+ /** BEL, BS, VT, FF and CR, which are removed from the text on the way in. */
296
+ const STRIPPED = new Set([0x07, 0x08, 0x0b, 0x0c, 0x0d]);
297
+ function stripControlCodes(text) {
298
+ return Array.from(text)
299
+ .filter((ch) => !STRIPPED.has(ch.codePointAt(0)))
300
+ .join('');
301
+ }
302
+ /** Tabs expanded at 8: each tab to a space, then out to the next multiple of eight. */
303
+ function expandTabs(points) {
304
+ if (!points.includes(0x09))
305
+ return [...points];
306
+ const out = [];
307
+ let part = [];
308
+ let position = 0;
309
+ for (const point of points) {
310
+ part.push(point);
311
+ if (point === 0x09) {
312
+ part[part.length - 1] = 0x20;
313
+ position += cellLenOf(part);
314
+ const remainder = position % 8;
315
+ if (remainder) {
316
+ for (let pad = 0; pad < 8 - remainder; pad += 1)
317
+ part.push(0x20);
318
+ position += 8 - remainder;
319
+ }
320
+ out.push(...part);
321
+ part = [];
322
+ }
323
+ }
324
+ out.push(...part);
325
+ return out;
326
+ }
327
+ /**
328
+ * `text` wrapped at `width` -- no justification, a word wider than the line folded -- as
329
+ * its lines. A line may end in a space: whitespace a break leaves at the end of a line is
330
+ * kept unless the line is longer than `width`.
331
+ */
332
+ function wrap(text, width) {
333
+ const out = [];
334
+ for (const raw of stripControlCodes(text).split('\n')) {
335
+ const points = expandTabs(codes(raw));
336
+ const offsets = divideLine(points, width);
337
+ const bounds = [0, ...offsets, points.length];
338
+ for (let at = 0; at < bounds.length - 1; at += 1) {
339
+ let line = points.slice(bounds[at], bounds[at + 1]);
340
+ if (line.length > width) {
341
+ const trailing = line.length - rstripped(line).length;
342
+ line = line.slice(0, line.length - Math.min(trailing, line.length - width));
343
+ }
344
+ if (cellLenOf(line) > width)
345
+ line = cropCells(line, width);
346
+ out.push(fromCodes(line));
347
+ }
348
+ }
349
+ return out;
350
+ }
351
+ /** `text` printed at `width`: each wrapped line and a newline. */
352
+ function printed(text, width) {
353
+ return wrap(text, width)
354
+ .map((line) => `${line}\n`)
355
+ .join('');
356
+ }
357
+ /** A line padded with spaces, or cropped, to exactly `width` cells. */
358
+ function fitCells(line, width) {
359
+ const points = codes(line);
360
+ const size = cellLenOf(points);
361
+ if (size > width)
362
+ return fromCodes(cropCells(points, width));
363
+ return line + ' '.repeat(width - size);
364
+ }
365
+ /**
366
+ * The boxed error panel printed at `width`: the ROUNDED box, the `Error` title on the left
367
+ * and padded by one space each side, the message wrapped inside one space of padding on
368
+ * each side.
369
+ */
370
+ function errorPanel(message, width) {
371
+ const title = ' Error ';
372
+ const inner = width - 2;
373
+ let top;
374
+ if (width <= 4)
375
+ top = `╭${'─'.repeat(Math.max(0, inner))}╮`;
376
+ else {
377
+ // The title left-aligned in `width - 4`: cropped to the room, then rule.
378
+ const room = width - 4;
379
+ const shown = cellLen(title) > room ? fromCodes(cropCells(codes(title), room)) : title;
380
+ top = `╭─${shown}${'─'.repeat(room - cellLen(shown))}─╮`;
381
+ }
382
+ const body = wrap(message, Math.max(0, inner - 2)).map((line) => `│ ${fitCells(line, Math.max(0, inner - 2))} │`);
383
+ return `${[top, ...body, `╰${'─'.repeat(Math.max(0, inner))}╯`].join('\n')}\n`;
384
+ }
385
+ function terminalColumns(fd) {
386
+ if (!tty.isatty(fd))
387
+ return null;
388
+ if (fd === 1 && process.stdout.isTTY)
389
+ return process.stdout.columns;
390
+ if (fd === 2 && process.stderr.isTTY)
391
+ return process.stderr.columns;
392
+ // Nothing in Node sizes a terminal on stdin, so a write stream is opened on it just long
393
+ // enough to ask. This only runs on the way out of a usage error.
394
+ try {
395
+ const stream = new tty.WriteStream(fd);
396
+ const columns = stream.columns;
397
+ stream.destroy();
398
+ return columns;
399
+ }
400
+ catch {
401
+ return null;
402
+ }
403
+ }
404
+ exports.PROCESS_CONSOLE = {
405
+ env: process.env,
406
+ isatty: (fd) => tty.isatty(fd),
407
+ columns: terminalColumns,
408
+ };
409
+ const DIGITS = /^[0-9]+$/u;
410
+ /** Whether stderr counts as a terminal, the environment's overrides decided first. */
411
+ function isTerminal(host) {
412
+ const env = host.env;
413
+ if (env._TYPER_FORCE_DISABLE_TERMINAL)
414
+ return false;
415
+ if (env.GITHUB_ACTIONS || env.FORCE_COLOR || env.PY_COLORS)
416
+ return true;
417
+ if (env.TTY_COMPATIBLE === '0')
418
+ return false;
419
+ if (env.TTY_COMPATIBLE === '1')
420
+ return true;
421
+ if (env.FORCE_COLOR !== undefined)
422
+ return env.FORCE_COLOR !== '';
423
+ return host.isatty(2);
424
+ }
425
+ /**
426
+ * The width a usage error is drawn at, on stderr.
427
+ *
428
+ * `TERMINAL_WIDTH`, else `COLUMNS`, fixes it -- but only wins outright together with
429
+ * `LINES`; otherwise a dumb terminal is 80 first. Without either, the size of the first of
430
+ * stdin, stdout and stderr that is a terminal, and 80 when none is. The terminal size is
431
+ * read from STDIN first, so `houston up --bogus 2>err.txt` at a terminal is as wide as that
432
+ * terminal.
433
+ */
434
+ function consoleWidth(host = exports.PROCESS_CONSOLE) {
435
+ const env = host.env;
436
+ const terminalWidth = env.TERMINAL_WIDTH;
437
+ let fixed = null;
438
+ if (terminalWidth)
439
+ fixed = strictInt(terminalWidth);
440
+ else if (env.COLUMNS !== undefined && DIGITS.test(env.COLUMNS))
441
+ fixed = Number(env.COLUMNS);
442
+ const lines = env.LINES !== undefined && DIGITS.test(env.LINES) ? Number(env.LINES) : null;
443
+ if (fixed !== null && lines !== null)
444
+ return fixed;
445
+ const term = (env.TERM ?? '').toLowerCase();
446
+ if (isTerminal(host) && (term === 'dumb' || term === 'unknown'))
447
+ return 80;
448
+ if (fixed !== null)
449
+ return fixed;
450
+ let width = null;
451
+ for (const fd of [0, 1, 2]) {
452
+ width = host.isatty(fd) ? host.columns(fd) : null;
453
+ if (width !== null)
454
+ break;
455
+ }
456
+ if (env.COLUMNS !== undefined && DIGITS.test(env.COLUMNS))
457
+ width = Number(env.COLUMNS);
458
+ return width || 80;
459
+ }
460
+ /**
461
+ * The terminal's columns: `COLUMNS` when `toInt` reads a positive number from it, else
462
+ * STDOUT's terminal, else `fallback`.
463
+ *
464
+ * `toInt`, not `parseInt`: `COLUMNS=100abc` is no width, so the terminal is asked, while
465
+ * `parseInt` reads 100; `COLUMNS=' 60 '` and `6_0` are 60, and so are `٦٠` and `60`, since
466
+ * any Unicode decimal digit reads as its ASCII value -- which `toInt` first did not, drawing
467
+ * an 84-column `houston presets` box where earlier releases drew a 56-column one. A
468
+ * terminal that answers 0 columns is the fallback.
469
+ */
470
+ function consoleColumns(fallback, host = exports.PROCESS_CONSOLE) {
471
+ const columns = host.env.COLUMNS === undefined ? null : strictInt(host.env.COLUMNS);
472
+ if (columns !== null && columns > 0)
473
+ return columns;
474
+ const stdout = host.isatty(1) ? host.columns(1) : null;
475
+ return stdout || fallback;
476
+ }
477
+ /**
478
+ * The columns the help formatter sizes the Usage line by: `COLUMNS` when it is a positive
479
+ * integer, else STDOUT's terminal, else 80.
480
+ */
481
+ function formatterColumns(host = exports.PROCESS_CONSOLE) {
482
+ return consoleColumns(80, host);
483
+ }
484
+ /** `toInt(text)`, or null where it throws. */
485
+ function strictInt(text) {
486
+ try {
487
+ return (0, format_1.toInt)(text);
488
+ }
489
+ catch {
490
+ return null;
491
+ }
492
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.cliActorAndOrigin = cliActorAndOrigin;
37
+ /**
38
+ * Who is running the CLI, and how confident the answer is.
39
+ *
40
+ * An earlier version had no equivalent at all: the web layer sets the acting user per
41
+ * request, and nothing set it for the CLI. So with accounts present, two people running
42
+ * `houston up -v 8.5.1` derived the SAME workspace name -- the exact data-loss bug per-user
43
+ * naming exists to prevent -- every owner gate compared an empty actor, `down --volumes`
44
+ * could not say whose data it was about to delete, and every audit line read `-`.
45
+ *
46
+ * The origin is the audit log's evidence column:
47
+ * local the OS login matched a known account -- the OS said so;
48
+ * asserted HOUSTON_USER was set, honoured even for an unknown name -- a claim;
49
+ * system no accounts (team mode is opt-in, from the first `users add`), or no match.
50
+ */
51
+ const config = __importStar(require("../../lib/config"));
52
+ const login_name_1 = require("../../lib/login-name");
53
+ const float_text_1 = require("../../lib/float-text");
54
+ /**
55
+ * The login name (`getlogin`), falling back to `$USER` where there is none (cron, a
56
+ * container).
57
+ *
58
+ * An earlier version read `os.userInfo()` -- the EFFECTIVE uid's name, with `$USER` only for a
59
+ * uid the password database lacks. Under `sudo -u vbob` that named the target account where
60
+ * the established actor is the person who logged in, so a member ran an admin's chown; and
61
+ * in a container or under cron, where there is no login uid, it named `root` or a service
62
+ * account -- no account here, so an empty actor, which the owner gates allow -- where the
63
+ * established actor is `$USER`.
64
+ */
65
+ function loginName() {
66
+ return (0, login_name_1.getlogin)() ?? process.env.USER ?? '';
67
+ }
68
+ function cliActorAndOrigin() {
69
+ const users = require('../../core/users');
70
+ if (!users.anyUsers())
71
+ return ['', 'system'];
72
+ const known = new Set(users.listUsers().map((user) => user.name));
73
+ // `stripText`, which is not `trim()`: it strips \x1c-\x1f and NEL and keeps a BOM, so
74
+ // HOUSTON_USER=$'\x1falice' is alice to it and was a stranger here -- refused a chown
75
+ // alice may make -- while $'\ufeffalice' was alice here and a stranger there. Every gate,
76
+ // audit line and event-log actor the CLI writes starts from this.
77
+ const named = (0, float_text_1.stripText)(config.env('HOUSTON_USER')).toLowerCase();
78
+ // Explicit: honoured even if unknown, so the mismatch shows up in `list` rather than
79
+ // silently falling back to the shared namespace.
80
+ if (named !== '')
81
+ return [named, 'asserted'];
82
+ const login = (0, float_text_1.stripText)(loginName()).toLowerCase();
83
+ return known.has(login) ? [login, 'local'] : ['', 'system'];
84
+ }