shapewall 0.0.0-stage → 0.2.2

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 (304) hide show
  1. package/CHANGELOG.md +139 -0
  2. package/Dockerfile.agent +45 -0
  3. package/LICENSE +202 -0
  4. package/NOTICE +12 -0
  5. package/README.md +651 -2
  6. package/THIRD_PARTY.md +165 -0
  7. package/bin/shapewall.js +29 -0
  8. package/dist/agent/package-lock.json +8384 -0
  9. package/dist/client/assets/BoardChat-D5SFd8HE.js +28 -0
  10. package/dist/client/assets/BuzzDialog-HWXBy52W.js +1 -0
  11. package/dist/client/assets/ChecksPanel-DTdImWoD.js +1 -0
  12. package/dist/client/assets/History-CEv6b-av.js +1 -0
  13. package/dist/client/assets/LocalSettings-C4vriEVQ.js +1 -0
  14. package/dist/client/assets/Management-DCfhcEUY.js +1 -0
  15. package/dist/client/assets/QuickConnect-DQGgUsl1.js +1 -0
  16. package/dist/client/assets/ShareDialog-C_plIto0.js +2 -0
  17. package/dist/client/assets/app-update-dialog-2hPz_N9G.js +1 -0
  18. package/dist/client/assets/circle-x-BZMPi8Zf.js +1 -0
  19. package/dist/client/assets/index-ByQRKVit.css +2 -0
  20. package/dist/client/assets/index-DweQ8Qtu.js +29 -0
  21. package/dist/client/assets/refresh-cw-CRow0Nbq.js +1 -0
  22. package/dist/client/assets/runtime-Bft6x_6E.js +4 -0
  23. package/dist/client/assets/square-A8EnIYLR.js +1 -0
  24. package/dist/client/assets/tts-dist-DYlBQmwG.js +18 -0
  25. package/dist/client/assets/tts-en-g2p-BPUtBFGG.js +1 -0
  26. package/dist/client/assets/tts-ort-wasm-simd-threaded-qh98TCA_.wasm +0 -0
  27. package/dist/client/assets/tts-ort.wasm.bundle.min-rEkcs_ow.js +12 -0
  28. package/dist/client/assets/tts-rolldown-runtime-D8NudN84.js +1 -0
  29. package/dist/client/assets/tts-spacy-en-tokenizer-6SNMl--A.json +1 -0
  30. package/dist/client/assets/tts-tts.worker-Bzm6aWbv.js +1 -0
  31. package/dist/client/assets/tts-us_gold-DcjeNMH1.json +92589 -0
  32. package/dist/client/assets/tts-us_silver-C964mEB5.json +93363 -0
  33. package/dist/client/assets/ui-CLbws0rx.js +41 -0
  34. package/dist/client/build-info.json +1 -0
  35. package/dist/client/favicon.svg +7 -0
  36. package/dist/client/icons/apple-touch-icon.png +0 -0
  37. package/dist/client/icons/icon-192.png +0 -0
  38. package/dist/client/icons/icon-512.png +0 -0
  39. package/dist/client/icons/maskable-512.png +0 -0
  40. package/dist/client/index.html +25 -0
  41. package/dist/client/manifest.webmanifest +15 -0
  42. package/dist/client/sw.js +53 -0
  43. package/dist/client/theme-boot.js +27 -0
  44. package/dist/console/assets/LocalAccountsApp-BQCcmj3x.js +1 -0
  45. package/dist/console/assets/LocalConsole-Bb2FUDs7.js +1 -0
  46. package/dist/console/assets/app-update-dialog-DIeYepLZ.js +1 -0
  47. package/dist/console/assets/console-C7uJLLOn.js +51 -0
  48. package/dist/console/assets/console-R8IBY3Am.css +2 -0
  49. package/dist/console/build-info.json +1 -0
  50. package/dist/console/console.html +21 -0
  51. package/dist/console/favicon.svg +7 -0
  52. package/dist/console/icons/apple-touch-icon.png +0 -0
  53. package/dist/console/icons/icon-192.png +0 -0
  54. package/dist/console/icons/icon-512.png +0 -0
  55. package/dist/console/icons/maskable-512.png +0 -0
  56. package/dist/console/manifest.webmanifest +15 -0
  57. package/dist/console/theme-boot.js +27 -0
  58. package/docs/agent-hardening.md +342 -0
  59. package/docs/agent-recipes.md +187 -0
  60. package/docs/agent-workflow.md +320 -0
  61. package/docs/agents.md +894 -0
  62. package/docs/architecture.md +242 -0
  63. package/docs/buzz.md +140 -0
  64. package/docs/capture-warnings.md +57 -0
  65. package/docs/config.md +489 -0
  66. package/docs/deployment.md +289 -0
  67. package/docs/design-system.md +162 -0
  68. package/docs/github.md +107 -0
  69. package/docs/hosted.md +764 -0
  70. package/docs/images/board-overview.png +0 -0
  71. package/docs/images/journeys.png +0 -0
  72. package/docs/images/live-comment.png +0 -0
  73. package/docs/images/phone-comment.png +0 -0
  74. package/docs/images/phone-overview.png +0 -0
  75. package/docs/images/variant.png +0 -0
  76. package/docs/interaction-audits.md +40 -0
  77. package/docs/journeys.md +137 -0
  78. package/docs/local-accounts.md +80 -0
  79. package/docs/notifications.md +237 -0
  80. package/docs/page-checks.md +69 -0
  81. package/docs/performance.md +174 -0
  82. package/docs/starter-agent.md +325 -0
  83. package/docs/updates.md +87 -0
  84. package/examples/audits/interaction.audit.json +17 -0
  85. package/package.json +132 -4
  86. package/src/accounts/avatar.js +121 -0
  87. package/src/accounts/local.js +464 -0
  88. package/src/agent/acp/command.js +204 -0
  89. package/src/agent/acp/detect.js +75 -0
  90. package/src/agent/acp/sandbox.js +160 -0
  91. package/src/agent/agent-health.js +75 -0
  92. package/src/agent/backends/acp.js +1297 -0
  93. package/src/agent/backends/index.js +61 -0
  94. package/src/agent/backends/openai.js +308 -0
  95. package/src/agent/composer.js +221 -0
  96. package/src/agent/config.js +338 -0
  97. package/src/agent/context.js +191 -0
  98. package/src/agent/control.js +122 -0
  99. package/src/agent/errors.js +17 -0
  100. package/src/agent/feedback-loop.js +137 -0
  101. package/src/agent/manage.js +94 -0
  102. package/src/agent/next-steps.js +51 -0
  103. package/src/agent/owner-mcp.js +38 -0
  104. package/src/agent/plain-text.js +52 -0
  105. package/src/agent/ratings-core.js +213 -0
  106. package/src/agent/ratings.js +100 -0
  107. package/src/agent/reply-text.js +67 -0
  108. package/src/agent/routes.js +1065 -0
  109. package/src/agent/run.js +326 -0
  110. package/src/agent/settings-routes.js +704 -0
  111. package/src/agent/showable.js +23 -0
  112. package/src/agent/starter/approvals.js +181 -0
  113. package/src/agent/starter/build-image.js +90 -0
  114. package/src/agent/starter/cli.js +163 -0
  115. package/src/agent/starter/disk.js +53 -0
  116. package/src/agent/starter/doctor.js +180 -0
  117. package/src/agent/starter/egress-proxy.js +351 -0
  118. package/src/agent/starter/gate.js +90 -0
  119. package/src/agent/starter/loop.js +114 -0
  120. package/src/agent/starter/model-relay.js +289 -0
  121. package/src/agent/starter/pause.js +14 -0
  122. package/src/agent/starter/probe.js +272 -0
  123. package/src/agent/starter/prompt.js +41 -0
  124. package/src/agent/starter/push-guard.js +146 -0
  125. package/src/agent/starter/rpc.js +164 -0
  126. package/src/agent/starter/runtime.js +287 -0
  127. package/src/agent/starter/sandbox-main.js +121 -0
  128. package/src/agent/starter/settings.js +290 -0
  129. package/src/agent/starter/source.js +69 -0
  130. package/src/agent/starter/supervisor.js +755 -0
  131. package/src/agent/starter/sweep.js +46 -0
  132. package/src/agent/starter/tools.js +524 -0
  133. package/src/agent/starter/watch.js +84 -0
  134. package/src/agent/starter/worktree.js +409 -0
  135. package/src/agent/text-diff.js +210 -0
  136. package/src/agent/thread-history.js +223 -0
  137. package/src/agent/threads.js +399 -0
  138. package/src/agent/tools.js +200 -0
  139. package/src/agent/turn-changes.js +424 -0
  140. package/src/agent/undo-state.js +26 -0
  141. package/src/agent/user-settings.js +308 -0
  142. package/src/auth/record.js +375 -0
  143. package/src/broken-links.js +164 -0
  144. package/src/buzz/client.js +75 -0
  145. package/src/buzz/config.js +151 -0
  146. package/src/buzz/environment.js +13 -0
  147. package/src/buzz/gateway.js +192 -0
  148. package/src/buzz/routes.js +61 -0
  149. package/src/buzz/signer-child.js +205 -0
  150. package/src/buzz/store.js +89 -0
  151. package/src/buzz/transport.js +60 -0
  152. package/src/buzz/verify.js +140 -0
  153. package/src/capture/actions.js +159 -0
  154. package/src/capture/capture.js +776 -0
  155. package/src/capture/dom-names.js +189 -0
  156. package/src/capture/element-map.js +509 -0
  157. package/src/capture/live.js +827 -0
  158. package/src/capture/media-scheme.js +317 -0
  159. package/src/capture/network-summary.js +86 -0
  160. package/src/capture/pacing.js +34 -0
  161. package/src/capture/requests.js +167 -0
  162. package/src/capture/sanitize.js +752 -0
  163. package/src/checks/accessibility.js +134 -0
  164. package/src/checks/budgets.js +58 -0
  165. package/src/checks/cli.js +55 -0
  166. package/src/checks/comparison.js +113 -0
  167. package/src/checks/environments.js +32 -0
  168. package/src/checks/flow-config.js +82 -0
  169. package/src/checks/flow-origin.js +53 -0
  170. package/src/checks/flows.js +398 -0
  171. package/src/checks/lighthouse-auth.js +145 -0
  172. package/src/checks/lighthouse-findings.js +130 -0
  173. package/src/checks/lighthouse.js +395 -0
  174. package/src/checks/robots.js +85 -0
  175. package/src/checks/routes.js +52 -0
  176. package/src/checks/run-control.js +259 -0
  177. package/src/checks/runner.js +724 -0
  178. package/src/checks/schema.js +133 -0
  179. package/src/checks/seo-analysis.js +443 -0
  180. package/src/checks/seo-probe.js +190 -0
  181. package/src/checks/seo-snapshot.js +99 -0
  182. package/src/checks/store.js +214 -0
  183. package/src/checks/transport.js +47 -0
  184. package/src/cli/args.js +319 -0
  185. package/src/cli/capture.js +79 -0
  186. package/src/cli/commands.js +92 -0
  187. package/src/cli/comments.js +84 -0
  188. package/src/cli/help.js +243 -0
  189. package/src/cli/init.js +214 -0
  190. package/src/cli/misc.js +64 -0
  191. package/src/cli/notify.js +87 -0
  192. package/src/cli/open.js +22 -0
  193. package/src/cli/serve.js +274 -0
  194. package/src/cli/variant.js +82 -0
  195. package/src/cli/watch.js +70 -0
  196. package/src/cli.js +130 -0
  197. package/src/comment-fields.js +76 -0
  198. package/src/comments-cli.js +208 -0
  199. package/src/config-reload.js +100 -0
  200. package/src/config.js +1061 -0
  201. package/src/devices-cli.js +21 -0
  202. package/src/diff.js +95 -0
  203. package/src/discover.js +284 -0
  204. package/src/doctor.js +295 -0
  205. package/src/event-log.js +268 -0
  206. package/src/events-cli.js +102 -0
  207. package/src/events.js +113 -0
  208. package/src/export.js +119 -0
  209. package/src/feedback.js +246 -0
  210. package/src/github.js +551 -0
  211. package/src/hosted/LICENSE.md +105 -0
  212. package/src/hosted/access-cli.js +78 -0
  213. package/src/hosted/admin.js +682 -0
  214. package/src/hosted/agent-approvals.js +163 -0
  215. package/src/hosted/agent-policy.js +189 -0
  216. package/src/hosted/app.js +510 -0
  217. package/src/hosted/auth-routes.js +540 -0
  218. package/src/hosted/auth.js +536 -0
  219. package/src/hosted/backup.js +483 -0
  220. package/src/hosted/board-context.js +35 -0
  221. package/src/hosted/board-routes.js +486 -0
  222. package/src/hosted/board-view.js +94 -0
  223. package/src/hosted/clean-worker.js +24 -0
  224. package/src/hosted/cleaner.js +89 -0
  225. package/src/hosted/comments.js +355 -0
  226. package/src/hosted/console-routes.js +401 -0
  227. package/src/hosted/cookies.js +18 -0
  228. package/src/hosted/crypto.js +80 -0
  229. package/src/hosted/db.js +496 -0
  230. package/src/hosted/device-routes.js +175 -0
  231. package/src/hosted/device.js +233 -0
  232. package/src/hosted/events.js +63 -0
  233. package/src/hosted/guards.js +172 -0
  234. package/src/hosted/guest-view.js +65 -0
  235. package/src/hosted/http.js +39 -0
  236. package/src/hosted/import.js +300 -0
  237. package/src/hosted/mail.js +73 -0
  238. package/src/hosted/mcp-http.js +71 -0
  239. package/src/hosted/membership.js +114 -0
  240. package/src/hosted/operator.js +478 -0
  241. package/src/hosted/ops-cli.js +345 -0
  242. package/src/hosted/pages.js +146 -0
  243. package/src/hosted/permissions.js +113 -0
  244. package/src/hosted/presence.js +372 -0
  245. package/src/hosted/projects.js +124 -0
  246. package/src/hosted/public.js +109 -0
  247. package/src/hosted/push.js +622 -0
  248. package/src/hosted/quotas.js +115 -0
  249. package/src/hosted/ratelimit.js +96 -0
  250. package/src/hosted/rebind.js +316 -0
  251. package/src/hosted/retention.js +128 -0
  252. package/src/hosted/server.js +260 -0
  253. package/src/hosted/setup-link.js +64 -0
  254. package/src/hosted/setup.js +323 -0
  255. package/src/hosted/shares.js +444 -0
  256. package/src/hosted/tailscale.js +204 -0
  257. package/src/hosted/tenancy.js +301 -0
  258. package/src/hosted/token-api.js +455 -0
  259. package/src/hosted/token-events.js +60 -0
  260. package/src/hosted/tokens.js +57 -0
  261. package/src/hosted/turnstile.js +49 -0
  262. package/src/hosted/usercontent.js +154 -0
  263. package/src/hosted/zip.js +155 -0
  264. package/src/invocation.js +58 -0
  265. package/src/journey-paths.js +282 -0
  266. package/src/journeys.js +189 -0
  267. package/src/links.js +106 -0
  268. package/src/local-projects.js +182 -0
  269. package/src/lock.js +193 -0
  270. package/src/mcp.js +417 -0
  271. package/src/mentions.js +151 -0
  272. package/src/net.js +15 -0
  273. package/src/notify/config.js +275 -0
  274. package/src/notify/index.js +301 -0
  275. package/src/notify/lease.js +73 -0
  276. package/src/notify/messages.js +212 -0
  277. package/src/notify/run.js +174 -0
  278. package/src/pixeldiff.js +49 -0
  279. package/src/png.js +143 -0
  280. package/src/reactions.js +111 -0
  281. package/src/remote/cli.js +133 -0
  282. package/src/remote/credentials.js +62 -0
  283. package/src/remote/ids.js +12 -0
  284. package/src/remote/login.js +155 -0
  285. package/src/remote/remote-mcp.js +237 -0
  286. package/src/remote/remote-watch.js +291 -0
  287. package/src/remote/remote.js +313 -0
  288. package/src/remote/share-state.js +78 -0
  289. package/src/remote/share.js +369 -0
  290. package/src/remote/terminal.js +13 -0
  291. package/src/serve-state.js +64 -0
  292. package/src/server/app.js +824 -0
  293. package/src/server/devices.js +186 -0
  294. package/src/server/local-console.js +28 -0
  295. package/src/server/local-user.js +59 -0
  296. package/src/server/pairing-routes.js +159 -0
  297. package/src/server/share-routes.js +89 -0
  298. package/src/server/tailscale.js +97 -0
  299. package/src/sitemap.js +431 -0
  300. package/src/store.js +983 -0
  301. package/src/tokens.js +11 -0
  302. package/src/update/routes.js +245 -0
  303. package/src/watch.js +403 -0
  304. package/src/which.js +58 -0
@@ -0,0 +1,345 @@
1
+ // The `shapewall hosted` command line: run the server (modes 1 and 2), the
2
+ // operator's `admin` commands, `backup` and `restore`. Mounted from src/cli.js
3
+ // with one line; the work is in server.js, setup.js, operator.js, backup.js
4
+ // and retention.js.
5
+
6
+ import fs from 'node:fs'
7
+ import path from 'node:path'
8
+
9
+ const DEFAULT_DATA = 'shapewall-hosted-data'
10
+ // eslint-disable-next-line no-control-regex
11
+ const CONTROL_RE = /[\u0000-\u001f\u007f]/g
12
+ const show = (value) => String(value ?? '').replace(CONTROL_RE, '')
13
+
14
+ const dataDirOf = (flags, env = process.env) => path.resolve(flags.data || env.SHAPEWALL_HOSTED_DATA || DEFAULT_DATA)
15
+
16
+ function intFlag(flags, name, { min, max, fallback }) {
17
+ if (flags[name] === undefined) return fallback
18
+ const value = Number(flags[name])
19
+ if (!Number.isInteger(value) || value < min || value > max) throw new Error(`--${name}: a whole number from ${min} to ${max}`)
20
+ return value
21
+ }
22
+
23
+ const mb = (bytes) => `${(bytes / 1048576).toFixed(1)} MB`
24
+
25
+ export async function hostedCommand(positional, flags, out, err = out) {
26
+ const [sub, ...rest] = positional
27
+ if (!sub) return flags.setup ? setup(flags, out) : serve(flags, out)
28
+ if (sub === 'setup-link' || sub === 'move-origin') {
29
+ const { operatorCommand } = await import('./access-cli.js')
30
+ await operatorCommand(sub, { dataDir: dataDirOf(flags), flags, env: process.env, out })
31
+ return 0
32
+ }
33
+ if (sub === 'admin') return admin(rest, flags, out)
34
+ if (sub === 'backup') return backupCommand(flags, out)
35
+ if (sub === 'restore') return restoreCommand(flags, out, err)
36
+ throw new Error(`unknown hosted command "${show(sub).slice(0, 40)}" (admin, backup, restore; or no command to run the server)`)
37
+ }
38
+
39
+ // ---- Run the server ----
40
+
41
+ async function serve(flags, out) {
42
+ const { startHosted } = await import('./server.js')
43
+ const env = process.env
44
+ const port = intFlag(flags, 'port', { min: 0, max: 65535, fallback: 4700 })
45
+ let tailscale = null
46
+ if (flags.tailscale) {
47
+ tailscale = {
48
+ httpsPort: intFlag(flags, 'tailscale-port', { min: 1, max: 65535, fallback: 443 }),
49
+ funnel: flags.funnel ? { httpsPort: intFlag(flags, 'funnel-port', { min: 1, max: 65535, fallback: 8443 }) } : null,
50
+ }
51
+ } else if (flags.funnel || flags['tailscale-port'] !== undefined || flags['funnel-port'] !== undefined) {
52
+ throw new Error('--funnel, --tailscale-port and --funnel-port go with --tailscale')
53
+ }
54
+ const trustEnv = env.SHAPEWALL_HOSTED_TRUST_PROXY
55
+ // "1": a proxy on this host; "uniquelocal" (Compose): one on a private network.
56
+ const trustProxy = flags['trust-proxy'] ? true : trustEnv === '1' ? true : trustEnv === 'uniquelocal' ? 'uniquelocal' : false
57
+ try {
58
+ await startHosted({
59
+ dataDir: dataDirOf(flags, env),
60
+ port,
61
+ host: flags.host || '127.0.0.1',
62
+ origin: flags.origin || env.SHAPEWALL_HOSTED_ORIGIN || null,
63
+ usercontentOrigin: flags['usercontent-origin'] || env.SHAPEWALL_USERCONTENT_ORIGIN || env.SHAPEWALL_HOSTED_USERCONTENT_ORIGIN || null,
64
+ previousOrigin: flags['previous-origin'] || env.SHAPEWALL_HOSTED_PREVIOUS_ORIGIN || null,
65
+ reportEmail: flags['report-email'] || env.SHAPEWALL_HOSTED_REPORT_EMAIL || null,
66
+ signup: flags.signup || env.SHAPEWALL_HOSTED_SIGNUP || 'invite',
67
+ trustProxy,
68
+ tailscale,
69
+ quotasFile: flags.quotas || env.SHAPEWALL_HOSTED_QUOTAS || null,
70
+ retentionHours: intFlag(flags, 'retention-hours', { min: 0, max: 24 * 30, fallback: undefined }),
71
+ retentionKeep: intFlag(flags, 'retention-keep', { min: 0, max: 100, fallback: undefined }),
72
+ out,
73
+ })
74
+ } catch (error) {
75
+ const { TailscaleError } = await import('./tailscale.js')
76
+ if (error instanceof TailscaleError) {
77
+ out(error.message)
78
+ return 1
79
+ }
80
+ throw error
81
+ }
82
+ return null
83
+ }
84
+
85
+ // ---- Mode 2 setup ----
86
+
87
+ async function setup(flags, out) {
88
+ const { SetupError, setupHosted, startCompose } = await import('./setup.js')
89
+ let result
90
+ try {
91
+ result = await setupHosted({
92
+ domain: flags.domain,
93
+ usercontentDomain: flags['usercontent-domain'] || null,
94
+ email: flags.email ?? null,
95
+ dir: flags.dir || 'shapewall-hosted',
96
+ ...(flags.source ? { source: flags.source } : {}),
97
+ dryRun: Boolean(flags['dry-run']),
98
+ force: Boolean(flags.force),
99
+ })
100
+ } catch (error) {
101
+ if (error instanceof SetupError) {
102
+ out(error.message)
103
+ return 1
104
+ }
105
+ throw error
106
+ }
107
+ out(
108
+ `${result.dryRun ? 'Would write' : 'Wrote'} ${Object.keys(result.files).join(', ')} to ${result.dir}${result.existing.length && result.dryRun ? ` (would overwrite ${result.existing.join(', ')}: pass --force)` : ''}`,
109
+ )
110
+ out(` https://${result.domain}${result.usercontentDomain ? ` and https://${result.usercontentDomain} (live HTML)` : ''}`)
111
+ for (const item of result.dns) out(`${item.ok && item.here ? 'ok ' : item.ok ? 'note' : 'todo'} DNS: ${item.message}`)
112
+ for (const warning of result.warnings) out(`note ${warning}`)
113
+ if (result.dryRun) {
114
+ out('\nDry run: nothing written. Without --dry-run the files are written; add --start to build and start it here.')
115
+ if (flags['print']) for (const [name, text] of Object.entries(result.files)) out(`\n----- ${name} -----\n${text}`)
116
+ return 0
117
+ }
118
+ if (!flags.start) {
119
+ out('\nNext:')
120
+ result.next.forEach((line, index) => out(` ${index + 1}. ${line}`))
121
+ return 0
122
+ }
123
+ try {
124
+ const started = await startCompose({ dir: result.dir, out })
125
+ if (started.setupLink) out(`\nNo accounts yet. Create the first one (works once, for 24 hours):\n ${started.setupLink}`)
126
+ else out(started.note)
127
+ return 0
128
+ } catch (error) {
129
+ if (error instanceof SetupError) {
130
+ out(error.message)
131
+ return 1
132
+ }
133
+ throw error
134
+ }
135
+ }
136
+
137
+ // ---- Operator commands ----
138
+
139
+ async function openExisting(flags) {
140
+ const dir = dataDirOf(flags)
141
+ const file = path.join(dir, 'shapewall.db')
142
+ if (!fs.existsSync(file)) throw new Error(`no hosted database at ${file} (pass --data, the server's data folder)`)
143
+ const { openDatabase, quietSqliteWarning } = await import('./db.js')
144
+ quietSqliteWarning()
145
+ return { dir, db: await openDatabase(file) }
146
+ }
147
+
148
+ const ADMIN_HELP = `shapewall hosted admin <command> --data DIR (on the server's machine)
149
+ list workspaces with usage, owners, open reports
150
+ suspend WS --reason TEXT read-only, share links off, tokens refused (the reason is shown to its admins)
151
+ resume WS [--note TEXT]
152
+ delete WS --confirm NAME everything in it, files included (type its name)
153
+ export WS --out FILE.zip the same zip as the console's "Download a copy"
154
+ reports [--all] abuse reports (open ones; --all with closed)
155
+ reports close ID [--note TEXT]
156
+ retention WS --keep N|default older versions kept per page and viewport
157
+ retention --run [--dry-run] prune now (the server also does it every 6 hours)
158
+ log [--limit N] the operator log
159
+ --operator NAME who you are in the operator log (default user@host)
160
+ --json machine-readable output`
161
+
162
+ async function admin(positional, flags, out) {
163
+ const [action, target, extra] = positional
164
+ if (!action || action === 'help') {
165
+ out(ADMIN_HELP)
166
+ return action ? 0 : 1
167
+ }
168
+ const ops = await import('./operator.js')
169
+ const { dir, db } = await openExisting(flags)
170
+ const operator = ops.operatorName(flags.operator)
171
+ const json = (value) => {
172
+ out(JSON.stringify(value, null, 2))
173
+ return 0
174
+ }
175
+ const say = (text) => {
176
+ out(text)
177
+ return 0
178
+ }
179
+ try {
180
+ switch (action) {
181
+ case 'list': {
182
+ ops.recordOperatorRead(db, { action: 'list', operator })
183
+ const { createQuotas } = await import('./quotas.js')
184
+ const quotaFile = flags.quotas || (fs.existsSync(path.join(dir, 'quotas.json')) ? path.join(dir, 'quotas.json') : null)
185
+ const rows = ops.listWorkspaces(db, { quotas: createQuotas({ file: quotaFile }) })
186
+ if (flags.json) return json(rows)
187
+ if (!rows.length) return say('No workspaces yet.')
188
+ for (const row of rows) {
189
+ const state = row.suspendedAt ? `SUSPENDED ${row.suspendedAt.slice(0, 10)}: ${show(row.suspendedReason)}` : 'active'
190
+ out(
191
+ `${row.id} ${show(row.name)} [${state}]\n owners ${row.owners.map(show).join(', ') || 'none'}; ${row.members} people, ${row.projects} projects, ${row.boards} boards, ` +
192
+ `${mb(row.bytes)} of ${mb(row.storageQuotaBytes)}; last push ${row.lastPushAt || 'never'}${row.openReports ? `; ${row.openReports} open reports` : ''}`,
193
+ )
194
+ }
195
+ return 0
196
+ }
197
+ case 'suspend': {
198
+ const result = ops.suspendWorkspace(db, { workspaceId: target, reason: flags.reason, operator })
199
+ if (flags.json) return json(result)
200
+ out(
201
+ `Suspended ${result.id} (${show(result.name)}): read-only, share links off, tokens refused. Undo: shapewall hosted admin resume ${result.id}`,
202
+ )
203
+ return 0
204
+ }
205
+ case 'resume': {
206
+ const result = ops.resumeWorkspace(db, { workspaceId: target, note: flags.note, operator })
207
+ if (flags.json) return json(result)
208
+ out(`Resumed ${result.id} (${show(result.name)}).`)
209
+ return 0
210
+ }
211
+ case 'delete': {
212
+ const result = ops.deleteWorkspace(db, dir, { workspaceId: target, confirm: flags.confirm, operator })
213
+ if (flags.json) return json(result)
214
+ out(
215
+ `Deleted ${result.id} (${show(result.name)}) with ${result.projects} projects and their files. Backups keep it until they age out.`,
216
+ )
217
+ return 0
218
+ }
219
+ case 'export': {
220
+ if (!flags.out) throw new ops.OperatorError('--out FILE.zip: where to write the export')
221
+ const result = await ops.exportWorkspace(db, dir, { workspaceId: target, out: flags.out, operator })
222
+ if (flags.json) return json(result)
223
+ out(`Exported ${result.id} (${show(result.name)}): ${result.files} files, ${mb(result.bytes)} in ${result.file} (mode 0600)`)
224
+ return 0
225
+ }
226
+ case 'reports': {
227
+ if (target === 'close') {
228
+ const result = ops.closeReport(db, { id: extra, note: flags.note, operator })
229
+ if (flags.json) return json(result)
230
+ out(`Closed ${result.id}.`)
231
+ return 0
232
+ }
233
+ if (target) throw new ops.OperatorError(`unknown reports action "${show(target).slice(0, 40)}" (close)`)
234
+ ops.recordOperatorRead(db, { action: 'reports', operator })
235
+ const rows = ops.listReports(db, { all: Boolean(flags.all) })
236
+ if (flags.json) return json(rows)
237
+ if (!rows.length) return say(flags.all ? 'No reports.' : 'No open reports.')
238
+ for (const row of rows) {
239
+ out(
240
+ `${row.id} ${row.createdAt.slice(0, 16).replace('T', ' ')} ${row.reason}${row.workspace ? ` workspace ${row.workspace}` : ''}${row.closedAt ? ' (closed)' : ''}\n ${show(row.url)}` +
241
+ `${row.details ? `\n ${show(row.details).slice(0, 300)}` : ''}${row.contact ? `\n contact: ${show(row.contact)}` : ''}`,
242
+ )
243
+ }
244
+ return 0
245
+ }
246
+ case 'retention': {
247
+ if (flags.run) {
248
+ const { runRetention } = await import('./retention.js')
249
+ const dryRun = Boolean(flags['dry-run'])
250
+ const result = runRetention({
251
+ db,
252
+ dataDir: dir,
253
+ dryRun,
254
+ ...(flags.keep !== undefined ? { keepDefault: intFlag(flags, 'keep', { min: 0, max: 100 }) } : {}),
255
+ })
256
+ ops.recordRetentionRun(db, { operator, result, dryRun })
257
+ if (flags.json) return json(result)
258
+ out(
259
+ `${dryRun ? 'Would remove' : 'Removed'} ${result.files} old version files (${mb(result.bytes)}) from ${result.boards} boards in ${result.workspaces} workspaces.`,
260
+ )
261
+ return 0
262
+ }
263
+ if (!target || flags.keep === undefined)
264
+ throw new ops.OperatorError('usage: hosted admin retention WS --keep N|default, or hosted admin retention --run [--dry-run]')
265
+ const keep = flags.keep === 'default' ? null : intFlag(flags, 'keep', { min: 0, max: 100 })
266
+ const result = ops.setRetention(db, { workspaceId: target, keep, operator })
267
+ if (flags.json) return json(result)
268
+ out(
269
+ `${result.id} (${show(result.name)}) keeps ${keep === null ? 'the server default number of' : keep} older versions per page and viewport.`,
270
+ )
271
+ return 0
272
+ }
273
+ case 'log': {
274
+ ops.recordOperatorRead(db, { action: 'log', operator })
275
+ const rows = ops.operatorLog(db, { limit: intFlag(flags, 'limit', { min: 1, max: 10_000, fallback: 50 }) })
276
+ if (flags.json) return json(rows)
277
+ if (!rows.length) return say('The operator log is empty.')
278
+ for (const row of rows)
279
+ out(
280
+ `${row.at.slice(0, 19).replace('T', ' ')} ${show(row.operator)} ${row.action}${row.target ? ` ${row.target}` : ''} ${show(JSON.stringify(row.detail))}`,
281
+ )
282
+ return 0
283
+ }
284
+ default:
285
+ throw new ops.OperatorError(`unknown admin command "${show(action).slice(0, 40)}"\n\n${ADMIN_HELP}`)
286
+ }
287
+ } catch (error) {
288
+ if (error instanceof ops.OperatorError) {
289
+ out(error.message)
290
+ return 1
291
+ }
292
+ throw error
293
+ } finally {
294
+ db.close()
295
+ }
296
+ }
297
+
298
+ // ---- Backup and restore ----
299
+
300
+ async function backupCommand(flags, out) {
301
+ if (!flags.to) throw new Error('usage: shapewall hosted backup --to DIR [--data DIR] [--keep-days N]')
302
+ const { backup } = await import('./backup.js')
303
+ const result = await backup({
304
+ dataDir: dataDirOf(flags),
305
+ to: flags.to,
306
+ keepDays: intFlag(flags, 'keep-days', { min: 1, max: 3650, fallback: null }),
307
+ })
308
+ if (flags.json) {
309
+ out(JSON.stringify({ dir: result.dir, manifest: result.manifest, pruned: result.pruned }, null, 2))
310
+ return 0
311
+ }
312
+ const { counts, files } = result.manifest
313
+ out(`Backed up to ${result.dir}`)
314
+ out(
315
+ ` ${counts.users} accounts, ${counts.workspaces} workspaces, ${counts.projects} projects, ${counts.boards} boards, ${counts.comments} comments; ${files.files} files (${mb(files.bytes)})`,
316
+ )
317
+ if (result.pruned.length) out(` Removed ${result.pruned.length} backups older than ${flags['keep-days']} days`)
318
+ out(' It holds everything, the signing key included: keep it as private as the server.')
319
+ return 0
320
+ }
321
+
322
+ async function restoreCommand(flags, out) {
323
+ if (!flags.from)
324
+ throw new Error('usage: shapewall hosted restore --from BACKUP --data NEW_DIR, or --from BACKUP --check (the restore drill)')
325
+ const { BackupError, restore, restoreDrill } = await import('./backup.js')
326
+ try {
327
+ if (flags.check) {
328
+ out('Restore drill: restoring into a scratch folder and starting a server on it...')
329
+ const result = await restoreDrill({ from: flags.from, out })
330
+ out(result.ok ? `Restore drill passed for ${result.backup}` : `Restore drill FAILED for ${result.backup}`)
331
+ return result.ok ? 0 : 1
332
+ }
333
+ if (!flags.data) throw new BackupError('--data NEW_DIR: an empty folder to restore into (never the live one)')
334
+ const result = await restore({ from: flags.from, data: flags.data })
335
+ out(`Restored ${result.from} into ${result.data} (schema ${result.schema}, ${result.files.files} files)`)
336
+ out(`Start the server on it: shapewall hosted --data ${result.data} ... (same --origin as before, or passkeys stop working)`)
337
+ return 0
338
+ } catch (error) {
339
+ if (error instanceof BackupError) {
340
+ out(error.message)
341
+ return 1
342
+ }
343
+ throw error
344
+ }
345
+ }
@@ -0,0 +1,146 @@
1
+ // The hosted app's pages (src/hosted/app.js): the console (a React app
2
+ // built into dist/console) and the board client for members, public
3
+ // projects and share link guests.
4
+
5
+ import fs from 'node:fs'
6
+ import path from 'node:path'
7
+ import express from 'express'
8
+ import { assetHeaders } from '../server/app.js'
9
+ import { ID_PATTERNS, randomToken } from './crypto.js'
10
+ import { createProjectStore } from './projects.js'
11
+ import { readPublic } from './public.js'
12
+ import { readGuest } from './shares.js'
13
+ import { roleIn, tenant } from './tenancy.js'
14
+ import { TURNSTILE_ORIGIN } from './turnstile.js'
15
+
16
+ const CONSOLE_CSP =
17
+ "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; connect-src 'self'; frame-src 'none'; frame-ancestors 'none'; base-uri 'none'; form-action 'none'; object-src 'none'"
18
+
19
+ // The service worker served under each board path (see below).
20
+ const removeWorker = (req, res) => {
21
+ res.setHeader('Cache-Control', 'no-cache')
22
+ res
23
+ .type('js')
24
+ .send(
25
+ "self.addEventListener('install', () => self.skipWaiting())\nself.addEventListener('activate', () => self.registration.unregister())\n",
26
+ )
27
+ }
28
+
29
+ export function mountPages(app, { db, dataDir, consoleDir, clientDir, turnstile, sessionOf, BOARD_PAGE_CSP, deps }) {
30
+ // ---- Pages: the console and the board client ----
31
+ // The console page gets a fresh nonce per response: the only inline thing
32
+ // it allows is a <style> element that the dialog's scroll lock adds with
33
+ // that nonce. Scripts come from 'self' only.
34
+ const consoleFile = path.join(consoleDir, 'console.html')
35
+ const consoleHtml = fs.existsSync(consoleFile) ? fs.readFileSync(consoleFile, 'utf8') : null
36
+ const sendConsole = (req, res, status = 200) => {
37
+ if (!consoleHtml) return res.status(status).type('text').send('The Shapewall console is not built yet. Run "npm run build".')
38
+ res.status(status)
39
+ const nonce = randomToken(18)
40
+ let csp = CONSOLE_CSP.replace("style-src 'self'", `style-src 'self' 'nonce-${nonce}'`)
41
+ // The bot check's widget, only on a server that has one.
42
+ if (turnstile)
43
+ csp = csp
44
+ .replace("script-src 'self'", `script-src 'self' ${TURNSTILE_ORIGIN}`)
45
+ .replace("frame-src 'none'", `frame-src ${TURNSTILE_ORIGIN}`)
46
+ res.setHeader('Content-Security-Policy', csp)
47
+ res.setHeader('X-Frame-Options', 'DENY')
48
+ res.setHeader('Cache-Control', 'no-store')
49
+ res.type('html').send(consoleHtml.replace('__SW_NONCE__', nonce))
50
+ }
51
+ app.use('/_console/assets', express.static(path.join(consoleDir, 'assets'), { immutable: true, maxAge: '1y', fallthrough: false }))
52
+ app.use('/_console', express.static(consoleDir, { index: false, maxAge: '1h', fallthrough: false }))
53
+ for (const route of [
54
+ '/',
55
+ '/signin',
56
+ '/signup',
57
+ '/account',
58
+ '/invite',
59
+ '/share',
60
+ '/device',
61
+ '/rebind',
62
+ '/moving',
63
+ '/w/:ws',
64
+ '/w/:ws/:section',
65
+ '/w/:ws/projects/:pid',
66
+ ])
67
+ app.get(route, (req, res) => sendConsole(req, res))
68
+
69
+ const clientBuilt = fs.existsSync(path.join(clientDir, 'index.html'))
70
+ // The client's own files under each project path; they hold no data.
71
+ // The board's offline service worker caches the app shell; hosted boards
72
+ // sit behind a session, so this one only removes itself.
73
+ app.get('/w/:ws/p/:pid/index.html', (req, res) => res.redirect(302, './'))
74
+ app.get('/w/:ws/p/:pid/sw.js', removeWorker)
75
+ if (clientBuilt) {
76
+ app.use(
77
+ '/w/:ws/p/:pid/assets',
78
+ express.static(path.join(clientDir, 'assets'), { immutable: true, maxAge: '1y', fallthrough: false, setHeaders: assetHeaders }),
79
+ )
80
+ app.use('/w/:ws/p/:pid', express.static(clientDir, { index: false, maxAge: '1h' }))
81
+ }
82
+ // Routing is not strict about the trailing slash, but the client's
83
+ // relative API paths need it.
84
+ app.get('/w/:ws/p/:pid', (req, res) => {
85
+ if (!req.path.endsWith('/')) {
86
+ const query = req.originalUrl.includes('?') ? req.originalUrl.slice(req.originalUrl.indexOf('?')) : ''
87
+ return res.redirect(302, `/w/${encodeURIComponent(req.params.ws)}/p/${encodeURIComponent(req.params.pid)}/${query}`)
88
+ }
89
+ const current = sessionOf(req)
90
+ if (!current) return res.redirect(302, `/signin?next=${encodeURIComponent(req.originalUrl)}`)
91
+ const ws = req.params.ws
92
+ const role = ID_PATTERNS.workspace.test(ws) ? roleIn(db, current.user.id, ws) : null
93
+ const project = role ? createProjectStore(tenant(db, ws), { db, dataDir }).get(req.params.pid) : null
94
+ // No access (removed, never a member, or no such board): the console's
95
+ // own page says so, with a way to sign in as someone else. Still a 404.
96
+ if (!project) return sendConsole(req, res, 404)
97
+ if (!clientBuilt) return res.type('text').send('The Shapewall client is not built yet. Run "npm run build".')
98
+ res.setHeader('Permissions-Policy', 'camera=(), microphone=(self), geolocation=()')
99
+ res.setHeader('Content-Security-Policy', BOARD_PAGE_CSP)
100
+ res.setHeader('X-Frame-Options', 'DENY')
101
+ res.setHeader('Cache-Control', 'no-cache')
102
+ res.sendFile('index.html', { root: clientDir })
103
+ })
104
+
105
+ // A public project's board: the same client on the view-only API. No
106
+ // cookie is read here; an unknown or switched-off id is a plain 404.
107
+ app.get('/p/:pubid/index.html', (req, res) => res.redirect(302, './'))
108
+ app.get('/p/:pubid/sw.js', removeWorker)
109
+ if (clientBuilt) {
110
+ app.use(
111
+ '/p/:pubid/assets',
112
+ express.static(path.join(clientDir, 'assets'), { immutable: true, maxAge: '1y', fallthrough: false, setHeaders: assetHeaders }),
113
+ )
114
+ app.use('/p/:pubid', express.static(clientDir, { index: false, maxAge: '1h' }))
115
+ }
116
+ app.get('/p/:pubid', (req, res) => {
117
+ if (!req.path.endsWith('/')) return res.redirect(302, `/p/${encodeURIComponent(req.params.pubid)}/`)
118
+ if (!readPublic(req, db)) return res.status(404).type('text').send('Not found')
119
+ if (!clientBuilt) return res.type('text').send('The Shapewall client is not built yet. Run "npm run build".')
120
+ res.setHeader('Content-Security-Policy', BOARD_PAGE_CSP)
121
+ res.setHeader('X-Frame-Options', 'DENY')
122
+ res.setHeader('Cache-Control', 'no-store')
123
+ res.sendFile('index.html', { root: clientDir })
124
+ })
125
+
126
+ // A share link's board: the same client, for a guest with the cookie that
127
+ // /api/shares/open set for this path. Without it, back to the share page.
128
+ app.get('/s/:sid/index.html', (req, res) => res.redirect(302, './'))
129
+ app.get('/s/:sid/sw.js', removeWorker)
130
+ if (clientBuilt) {
131
+ app.use(
132
+ '/s/:sid/assets',
133
+ express.static(path.join(clientDir, 'assets'), { immutable: true, maxAge: '1y', fallthrough: false, setHeaders: assetHeaders }),
134
+ )
135
+ app.use('/s/:sid', express.static(clientDir, { index: false, maxAge: '1h' }))
136
+ }
137
+ app.get('/s/:sid', (req, res) => {
138
+ if (!req.path.endsWith('/')) return res.redirect(302, `/s/${encodeURIComponent(req.params.sid)}/`)
139
+ if (!readGuest(req, deps)) return res.redirect(302, '/share?ended=1')
140
+ if (!clientBuilt) return res.type('text').send('The Shapewall client is not built yet. Run "npm run build".')
141
+ res.setHeader('Content-Security-Policy', BOARD_PAGE_CSP)
142
+ res.setHeader('X-Frame-Options', 'DENY')
143
+ res.setHeader('Cache-Control', 'no-store')
144
+ res.sendFile('index.html', { root: clientDir })
145
+ })
146
+ }
@@ -0,0 +1,113 @@
1
+ // Who may do what in a hosted workspace: the rules in one place, as plain
2
+ // functions with no imports, so the server (app.js, admin.js, shares.js), the
3
+ // console and the public demo's in-browser backend (client/src/demo) all
4
+ // decide the same way. The server still enforces every rule itself; the
5
+ // console only uses these to hide what would be refused.
6
+ //
7
+ // viewer sees projects, boards and comments
8
+ // member + comments, replies, reactions, resolve and reopen; edits and deletes their own
9
+ // admin + projects, tokens, invites (up to admin), share links, members
10
+ // and viewers, any comment, the access overview, audit log, settings
11
+ // owner + admins and owners, owner invites, deleting the workspace
12
+ // guest a share link visitor: one project; comments and replies on a
13
+ // comment link, nothing else
14
+
15
+ export const ROLES = ['viewer', 'member', 'admin', 'owner']
16
+ export const roleAtLeast = (role, wanted) => ROLES.indexOf(role) >= ROLES.indexOf(wanted) && ROLES.includes(role)
17
+
18
+ // What each workspace role can do on every project of the workspace (Access).
19
+ export const ROLE_ACCESS = {
20
+ viewer: 'view',
21
+ member: 'comment',
22
+ admin: 'manage',
23
+ owner: 'own',
24
+ }
25
+
26
+ // The least role for each part of the console API.
27
+ export const NEEDS = {
28
+ workspace: 'viewer',
29
+ members: 'viewer',
30
+ leave: 'viewer',
31
+ rename: 'admin',
32
+ settings: 'admin',
33
+ invites: 'admin',
34
+ changeRole: 'admin',
35
+ projects: 'admin',
36
+ tokens: 'admin',
37
+ shares: 'admin',
38
+ access: 'admin',
39
+ audit: 'admin',
40
+ export: 'admin',
41
+ deleteWorkspace: 'owner',
42
+ }
43
+ export const can = (role, need) => roleAtLeast(role, NEEDS[need])
44
+
45
+ // What a person may do on a board, from their workspace role.
46
+ // `react`: emoji reactions on comments and replies.
47
+ export function boardPermissions(role) {
48
+ const write = roleAtLeast(role, 'member')
49
+ return { comment: write, reply: write, resolve: write, edit: write, delete: write, react: write }
50
+ }
51
+
52
+ // What a share link guest may do: comment links add comments and replies.
53
+ // Guests do not react: a link has no account to tell its guests apart.
54
+ export function guestPermissions(mode) {
55
+ const comment = mode === 'comment'
56
+ return { comment, reply: comment, resolve: false, edit: false, delete: false, react: false }
57
+ }
58
+
59
+ // Comment changes beyond resolving: only the author edits the text; the
60
+ // author or an admin deletes.
61
+ export const canEditComment = ({ isAuthor }) => Boolean(isAuthor)
62
+ export const canDeleteComment = ({ role, isAuthor }) => roleAtLeast(role, 'member') && (Boolean(isAuthor) || roleAtLeast(role, 'admin'))
63
+
64
+ // Roles: admins manage members and viewers (and may make admins); only
65
+ // owners change owners or admins. `newRole` null asks about removing.
66
+ export function canManage(actorRole, targetRole, newRole = null) {
67
+ if (actorRole === 'owner') return true
68
+ if (actorRole !== 'admin') return false
69
+ if (['owner', 'admin'].includes(targetRole)) return false
70
+ return newRole === null || newRole !== 'owner'
71
+ }
72
+
73
+ // What the actor may set the target's role to (empty: nothing).
74
+ export function assignableRoles(actorRole, targetRole) {
75
+ return ROLES.filter((role) => canManage(actorRole, targetRole, role) && roleAtLeast(actorRole, 'admin'))
76
+ }
77
+
78
+ export const canRemoveMember = (actorRole, targetRole, { self = false } = {}) => self || canManage(actorRole, targetRole)
79
+
80
+ // Invites go up to the inviter's own level; only owners invite owners.
81
+ export const canInvite = (actorRole, role) =>
82
+ can(actorRole, 'invites') && ROLES.includes(role) && (role !== 'owner' || actorRole === 'owner')
83
+ export const invitableRoles = (actorRole) => ROLES.filter((role) => canInvite(actorRole, role))
84
+
85
+ // Changes that need a passkey check in the last 10 minutes.
86
+ export const inviteNeedsFresh = (role) => role === 'owner' || role === 'admin'
87
+ export const roleChangeNeedsFresh = (targetRole, newRole) =>
88
+ newRole === 'owner' || newRole === 'admin' || (['owner', 'admin'].includes(targetRole) && targetRole !== newRole)
89
+ export const removalNeedsFresh = (targetRole, { self = false } = {}) => !self && ['owner', 'admin'].includes(targetRole)
90
+
91
+ // A workspace always keeps an owner.
92
+ export const leavesNoOwner = ({ targetRole, newRole = null, owners }) => targetRole === 'owner' && newRole !== 'owner' && owners <= 1
93
+
94
+ // What goes when someone leaves (newRole null), is removed or demoted: the
95
+ // pending invites they can no longer make (all of them below admin, owner
96
+ // invites below owner) and, below admin, their share links and API tokens.
97
+ // (Removing someone may keep their tokens, revoked or not they stop working:
98
+ // tokenCreatorOk below is checked on every request.)
99
+ export function grantsToRevoke(newRole) {
100
+ if (newRole === 'owner') return { invites: 'none', shares: false, tokens: false }
101
+ if (newRole === 'admin') return { invites: 'owner', shares: false, tokens: false }
102
+ return { invites: 'all', shares: true, tokens: true }
103
+ }
104
+
105
+ // An invite works only while its creator could still make it; a share link
106
+ // only while its creator is still an admin or owner.
107
+ export const inviteCreatorOk = (creatorRole, inviteRole) => Boolean(creatorRole) && canInvite(creatorRole, inviteRole)
108
+ export const shareCreatorOk = (creatorRole) => roleAtLeast(creatorRole, 'admin')
109
+ // An API token works only while the person who made it is still a member
110
+ // with a role that makes tokens (admin or owner). There are no service
111
+ // tokens: every token has a maker, and a token whose maker left, was demoted
112
+ // or deleted their account stops working.
113
+ export const tokenCreatorOk = (creatorRole) => roleAtLeast(creatorRole, NEEDS.tokens)