@kabmo-labs/kabmo 0.35.0 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +435 -432
  3. package/dist/client/static/js/{CsvGrid-0amzgtd7.js → CsvGrid-xb429wvb.js} +2 -2
  4. package/dist/client/static/js/{DocxView-bxjhzxe9.js → DocxView-g58e0bs7.js} +2 -2
  5. package/dist/client/static/js/{DrawioView-7s1yqsf4.js → DrawioView-1j66avvy.js} +2 -2
  6. package/dist/client/static/js/{ImageView-ycfbn66h.js → ImageView-kraqkypn.js} +1 -1
  7. package/dist/client/static/js/{LayoutWrapper-tw1q1x0g.js → LayoutWrapper-85dhbn62.js} +2 -2
  8. package/dist/client/static/js/{Modal-wqjactyd.js → Modal-f0nfya07.js} +16 -16
  9. package/dist/client/static/js/{PdfView-x6dmtwvr.js → PdfView-nddkrky9.js} +1 -1
  10. package/dist/client/static/js/{SessionsView-t85wq0me.js → SessionsView-a595m6g1.js} +1 -1
  11. package/dist/client/static/js/{SheetView-n52nvz8s.js → SheetView-s2p4sk6b.js} +13 -13
  12. package/dist/client/static/js/{SvgPreview-59z7syme.js → SvgPreview-ppdx4yb9.js} +1 -1
  13. package/dist/client/static/js/{abnfDiagram-O67JEVCF-91gnt049.js → abnfDiagram-O67JEVCF-5cjzxcaq.js} +1 -1
  14. package/dist/client/static/js/architecture-7GRP2DOG-7ewrw5vc.js +1 -0
  15. package/dist/client/static/js/{architectureDiagram-NJMV4G6O-5b9qtff2.js → architectureDiagram-NJMV4G6O-62mygavm.js} +3 -3
  16. package/dist/client/static/js/{astro-31cbyw7b.js → astro-80bs6hvg.js} +1 -1
  17. package/dist/client/static/js/bash-b3rwyg5p.js +1 -0
  18. package/dist/client/static/js/{blockDiagram-BEXU5L5S-6f23fjkn.js → blockDiagram-BEXU5L5S-s5yz9hcd.js} +2 -2
  19. package/dist/client/static/js/{c4Diagram-YGBWAQC7-76t6d3am.js → c4Diagram-YGBWAQC7-rf9xkmrm.js} +2 -2
  20. package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-f9tb19xm.js → classDiagram-v2-NBCMYWYE-zfm2cj2a.js} +1 -1
  21. package/dist/client/static/js/{cose-bilkent-JH36ORCC-t6nwrbwj.js → cose-bilkent-JH36ORCC-fmgpv55e.js} +1 -1
  22. package/dist/client/static/js/cpp-y0t6mynx.js +1 -0
  23. package/dist/client/static/js/css-r2nhvzff.js +1 -0
  24. package/dist/client/static/js/cynefin-OW5HDTMX-yyyx3px0.js +1 -0
  25. package/dist/client/static/js/{cynefinDiagram-VND7K2PF-69gc244j.js → cynefinDiagram-VND7K2PF-468r5xc2.js} +1 -1
  26. package/dist/client/static/js/{dagre-6A5THRUB-54bry3ey.js → dagre-6A5THRUB-w370qmgj.js} +2 -2
  27. package/dist/client/static/js/{diagram-22UHCM2B-gfkebye6.js → diagram-22UHCM2B-sfvfjjsy.js} +3 -3
  28. package/dist/client/static/js/{diagram-3UASUU5V-a1mr319f.js → diagram-3UASUU5V-3r2c8s14.js} +1 -1
  29. package/dist/client/static/js/{diagram-ATOU4E4O-tkyk0qbe.js → diagram-ATOU4E4O-yathy97a.js} +3 -3
  30. package/dist/client/static/js/{diagram-CDSNMT55-np0hc9m2.js → diagram-CDSNMT55-kk437kxq.js} +2 -2
  31. package/dist/client/static/js/{diagram-MLGK6HIB-nh06fshp.js → diagram-MLGK6HIB-qdxfjjhf.js} +1 -1
  32. package/dist/client/static/js/{diagram-MPIPVDR6-27q2veks.js → diagram-MPIPVDR6-dfqeqa1d.js} +1 -1
  33. package/dist/client/static/js/{dockerfile-4rtt6c0f.js → dockerfile-yxrt509r.js} +1 -1
  34. package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-x9p9jqe8.js → ebnfDiagram-ZINNZB2B-s0b0vv4k.js} +1 -1
  35. package/dist/client/static/js/{elk-276RUBZZ-fw7waks3.js → elk-276RUBZZ-mtpw0spa.js} +1 -1
  36. package/dist/client/static/js/{erDiagram-OPXOYQCR-fdfgzr5d.js → erDiagram-OPXOYQCR-agjdsm1b.js} +4 -4
  37. package/dist/client/static/js/{erlang-trjm07as.js → erlang-6m6tpt72.js} +1 -1
  38. package/dist/client/static/js/eventmodeling-NTZA5JFV-cx3ztxfz.js +1 -0
  39. package/dist/client/static/js/flowDiagram-KWPJA3E3-267mw6sv.js +1 -0
  40. package/dist/client/static/js/{ganttDiagram-FUAMR5RP-2avbqgdr.js → ganttDiagram-FUAMR5RP-z6ywqqc1.js} +1 -1
  41. package/dist/client/static/js/gitGraph-4MIJSDKK-eg9r85ak.js +1 -0
  42. package/dist/client/static/js/{gitGraphDiagram-X574FWY7-9jmc0a3g.js → gitGraphDiagram-X574FWY7-bvbmfw6h.js} +2 -2
  43. package/dist/client/static/js/graphql-skw5krjr.js +1 -0
  44. package/dist/client/static/js/{index-a8ffattk.js → index-059qyaj0.js} +2 -2
  45. package/dist/client/static/js/{index-8f9x7ev8.js → index-09gx6edj.js} +1 -1
  46. package/dist/client/static/js/index-0mvcbbmy.js +12 -0
  47. package/dist/client/static/js/{index-fvc0x6nx.js → index-0sqa91wb.js} +3 -3
  48. package/dist/client/static/js/{index-8mwragbj.js → index-15zn3sns.js} +2 -2
  49. package/dist/client/static/js/{index-4vybd9e7.js → index-1tyvk778.js} +1 -1
  50. package/dist/client/static/js/{index-43qpbxjv.js → index-1y9r4frb.js} +2 -2
  51. package/dist/client/static/js/{index-a628fg4m.js → index-21b3zyrd.js} +2 -2
  52. package/dist/client/static/js/{index-vnw3hbeg.js → index-302d35e5.js} +27 -27
  53. package/dist/client/static/js/{index-jc1yagmk.js → index-3zc1b0dv.js} +2 -2
  54. package/dist/client/static/js/{index-t6c0pd43.js → index-49dhv8ry.js} +2 -2
  55. package/dist/client/static/js/{index-xxtsm2rb.js → index-5fn0agag.js} +2 -2
  56. package/dist/client/static/js/{index-yq39qbs1.js → index-64mb65wx.js} +2 -2
  57. package/dist/client/static/js/{index-xs1m0bpt.js → index-6q80csr0.js} +1 -1
  58. package/dist/client/static/js/{index-pc6eg8h2.js → index-72t6kqjx.js} +2 -2
  59. package/dist/client/static/js/{index-y3ms153k.js → index-7fdp9c7m.js} +2 -2
  60. package/dist/client/static/js/{index-py2k8std.js → index-7sa2e8mn.js} +2 -2
  61. package/dist/client/static/js/{index-7q02xnvq.js → index-83ts8zmk.js} +1 -1
  62. package/dist/client/static/js/{index-9ketbkh6.js → index-8e0s9p45.js} +1 -1
  63. package/dist/client/static/js/{index-tp7yb3bv.js → index-a0bdavdr.js} +2 -2
  64. package/dist/client/static/js/{index-7ct7qrsp.js → index-actppd4z.js} +2 -2
  65. package/dist/client/static/js/{index-k7q01ye4.js → index-cx89yk15.js} +2 -2
  66. package/dist/client/static/js/{index-vq6wts05.js → index-dt7e1328.js} +2 -2
  67. package/dist/client/static/js/{index-w7tpgt46.js → index-es3pt29g.js} +1 -1
  68. package/dist/client/static/js/{index-pzbssnsc.js → index-gbfg0anm.js} +2 -2
  69. package/dist/client/static/js/{index-qqz6bcdd.js → index-h7pn9qw6.js} +2 -2
  70. package/dist/client/static/js/{index-kdkfyrja.js → index-hbtk0c12.js} +2 -2
  71. package/dist/client/static/js/index-j7r414hf.js +2 -0
  72. package/dist/client/static/js/{index-ee2p07eg.js → index-jpkj6vqp.js} +1 -1
  73. package/dist/client/static/js/{index-nb8tp4mj.js → index-k06med7d.js} +30 -30
  74. package/dist/client/static/js/{index-8x9ecxb0.js → index-kzhtmrh0.js} +1 -1
  75. package/dist/client/static/js/{index-3ecsp1rx.js → index-m3j5yx5f.js} +3 -3
  76. package/dist/client/static/js/{index-sdby39w4.js → index-m87yykre.js} +3 -3
  77. package/dist/client/static/js/{index-ek2e773p.js → index-nmc30xaz.js} +1 -1
  78. package/dist/client/static/js/{index-p16scjt7.js → index-ntxm8pw3.js} +2 -2
  79. package/dist/client/static/js/{index-0v34a7wf.js → index-pd0140dx.js} +1 -1
  80. package/dist/client/static/js/{index-zh2jj56s.js → index-qkscve6n.js} +2 -2
  81. package/dist/client/static/js/{index-whbtxmwh.js → index-qz8mbxm9.js} +2 -2
  82. package/dist/client/static/js/{index-ncrenheb.js → index-qznwd6g8.js} +160 -160
  83. package/dist/client/static/js/{index-6f6cmcbq.js → index-sa9cp6km.js} +2 -2
  84. package/dist/client/static/js/{index-jmxqefe3.js → index-sezz011q.js} +1 -1
  85. package/dist/client/static/js/{index-rbgemjsp.js → index-t07b31ny.js} +3 -3
  86. package/dist/client/static/js/index-tcegdd2t.js +1 -0
  87. package/dist/client/static/js/{index-1wjp16f0.js → index-vtbbfwx0.js} +2 -2
  88. package/dist/client/static/js/{index-2v1nmxwr.js → index-w9zxmev3.js} +5 -5
  89. package/dist/client/static/js/{index-w5373tg1.js → index-we1rpftn.js} +2 -2
  90. package/dist/client/static/js/{index-b8s3xraa.js → index-xearvz2z.js} +5 -5
  91. package/dist/client/static/js/{index-rv89xpaf.js → index-xya34x4v.js} +2 -2
  92. package/dist/client/static/js/{index-mc4nefs7.js → index-z0frtyje.js} +1 -1
  93. package/dist/client/static/js/{index-7smwzkvq.js → index-z6g74h7g.js} +2 -2
  94. package/dist/client/static/js/{index-rkn0bxxt.js → index-z7qnffwj.js} +1 -1
  95. package/dist/client/static/js/{index-pnt0vc59.js → index-zvfvqvn9.js} +2 -2
  96. package/dist/client/static/js/info-A6RAGUB7-7qhah7fs.js +1 -0
  97. package/dist/client/static/js/{infoDiagram-VRGFBTTK-g2dky5xg.js → infoDiagram-VRGFBTTK-58bv28d4.js} +1 -1
  98. package/dist/client/static/js/ini-cg0a5wm3.js +1 -0
  99. package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-exrcjwp1.js → ishikawaDiagram-OU5B5YK6-tz6b0caw.js} +1 -1
  100. package/dist/client/static/js/java-vcck089n.js +1 -0
  101. package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-pn752qa5.js → journeyDiagram-ZHPQQLJL-ydamm17a.js} +2 -2
  102. package/dist/client/static/js/jsx-ht9zyzwa.js +1 -0
  103. package/dist/client/static/js/{julia-evn99h2m.js → julia-v7j460gw.js} +1 -1
  104. package/dist/client/static/js/{kanban-definition-PNTS6WVX-v8nvr373.js → kanban-definition-PNTS6WVX-7jxfsf17.js} +1 -1
  105. package/dist/client/static/js/lua-ke895s2q.js +1 -0
  106. package/dist/client/static/js/markdown-gwmsh53r.js +1 -0
  107. package/dist/client/static/js/{mermaid.core-egzv89zv.js → mermaid.core-vty0aq6f.js} +6 -6
  108. package/dist/client/static/js/{mindmap-definition-NLK3R4M7-t9njmv2w.js → mindmap-definition-NLK3R4M7-ra4wrts4.js} +2 -2
  109. package/dist/client/static/js/one-dark-pro-2pywnqrh.js +1 -0
  110. package/dist/client/static/js/one-light-vfgdt4wf.js +1 -0
  111. package/dist/client/static/js/packet-AYTQ26CC-ag2g7tbk.js +1 -0
  112. package/dist/client/static/js/{pegDiagram-GJSIUBJH-zhycy2b7.js → pegDiagram-GJSIUBJH-ydjcfea9.js} +1 -1
  113. package/dist/client/static/js/{perl-506fy8m8.js → perl-gg4jdkcr.js} +1 -1
  114. package/dist/client/static/js/{php-axtsvxck.js → php-2q8fm6k8.js} +1 -1
  115. package/dist/client/static/js/pie-WAS4IAKB-nqcyj3x1.js +1 -0
  116. package/dist/client/static/js/{pieDiagram-5QR66LMP-sgctvma2.js → pieDiagram-5QR66LMP-wh04y7wp.js} +1 -1
  117. package/dist/client/static/js/properties-mzvvbqg5.js +1 -0
  118. package/dist/client/static/js/python-3w64wsyd.js +1 -0
  119. package/dist/client/static/js/{quadrantDiagram-O4NWA36T-kzzhdcph.js → quadrantDiagram-O4NWA36T-4mhbag8n.js} +1 -1
  120. package/dist/client/static/js/r-32re2zwb.js +1 -0
  121. package/dist/client/static/js/radar-RG4KPBEZ-60gby7be.js +1 -0
  122. package/dist/client/static/js/railroad-74A4TZTK-cnkmcjse.js +1 -0
  123. package/dist/client/static/js/railroad-abnf-HS5TGJTU-qgfdnazd.js +1 -0
  124. package/dist/client/static/js/railroad-ebnf-LZEXJU2U-609h6cpx.js +1 -0
  125. package/dist/client/static/js/railroad-peg-WCYAUIDC-xqnytjhg.js +1 -0
  126. package/dist/client/static/js/{railroadDiagram-XR7U4H2S-nzjffwxm.js → railroadDiagram-XR7U4H2S-pagmr4hc.js} +1 -1
  127. package/dist/client/static/js/{requirementDiagram-PLB6GJNP-tz4xxn4d.js → requirementDiagram-PLB6GJNP-jhfhp4eq.js} +1 -1
  128. package/dist/client/static/js/{ruby-qp7zfk2m.js → ruby-vag6a82m.js} +1 -1
  129. package/dist/client/static/js/{rust-fz913fvw.js → rust-yntkm6hw.js} +1 -1
  130. package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-2wcb0xr6.js → sankeyDiagram-IPEJSGJF-qrfxzvp3.js} +2 -2
  131. package/dist/client/static/js/{sass-gnk9vsyp.js → sass-kbwea482.js} +1 -1
  132. package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-vqgebfns.js → sequenceDiagram-PO4LG4MO-fpznwnva.js} +5 -5
  133. package/dist/client/static/js/{sizeCapture-INFHLROL-xc314tes.js → sizeCapture-INFHLROL-3hz930jg.js} +1 -1
  134. package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-8bd9b1h8.js → stateDiagram-v2-GCMORJYK-2m99syxm.js} +2 -2
  135. package/dist/client/static/js/{svelte-brpgzrtv.js → svelte-mwtx07d9.js} +1 -1
  136. package/dist/client/static/js/{swimlanes-2SLR337P-t6hbdzcw.js → swimlanes-2SLR337P-hmhd360r.js} +1 -1
  137. package/dist/client/static/js/swimlanesDiagram-TC7HE7FX-a8b7z74e.js +8 -0
  138. package/dist/client/static/js/{timeline-definition-EJHVYXUP-2txxasx5.js → timeline-definition-EJHVYXUP-765y3ssa.js} +2 -2
  139. package/dist/client/static/js/treeView-Q6P3EWNA-8djqab8k.js +1 -0
  140. package/dist/client/static/js/treemap-WGGIJYW6-hdztnffk.js +1 -0
  141. package/dist/client/static/js/tsx-nm94hed6.js +1 -0
  142. package/dist/client/static/js/typescript-0s2t05jj.js +1 -0
  143. package/dist/client/static/js/{usecaseDiagram-POWQR4AR-3x353hn4.js → usecaseDiagram-POWQR4AR-rex2j507.js} +2 -2
  144. package/dist/client/static/js/{vennDiagram-UO4OBE2U-cerpss8e.js → vennDiagram-UO4OBE2U-wd51qq26.js} +1 -1
  145. package/dist/client/static/js/{vue-apnkw9qy.js → vue-j8vb9d7r.js} +1 -1
  146. package/dist/client/static/js/wardley-WFR3VGLG-avby77vv.js +1 -0
  147. package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-cx6jfsbf.js → wardleyDiagram-VNRHLVJA-6jdqn8f7.js} +1 -1
  148. package/dist/client/static/js/xml-81hxjjt4.js +1 -0
  149. package/dist/client/static/js/{xychartDiagram-PMCCYNJV-tgn23xj1.js → xychartDiagram-PMCCYNJV-kcz8y04e.js} +2 -2
  150. package/dist/client/static/js/yaml-yssayv8a.js +1 -0
  151. package/package.json +1 -1
  152. package/src/client/components/settings/apply-side-effects.test.ts +5 -4
  153. package/src/client/components/settings/categories/ConnectSettings.tsx +8 -1
  154. package/src/client/components/settings/categories/connect-settings/CloudflareConfig.test.tsx +84 -0
  155. package/src/client/components/settings/categories/connect-settings/CloudflareConfig.tsx +68 -0
  156. package/src/client/components/settings/categories/connect-settings/PairDialog.test.tsx +49 -49
  157. package/src/client/components/settings/categories/connect-settings/PairDialog.tsx +12 -8
  158. package/src/client/components/settings/categories/connect-settings/QrCode.tsx +19 -2
  159. package/src/client/hooks/connect/use-connect-status.ts +44 -19
  160. package/src/client/hooks/connect/use-pairing.ts +5 -0
  161. package/src/client/hooks/ui/icon-style.ts +7 -4
  162. package/src/client/hooks/ui/style-attributes.test.ts +11 -11
  163. package/src/client/hooks/ui/surface-style.ts +8 -5
  164. package/src/client/lib/notifications/watch.ts +4 -1
  165. package/src/server/lib/assets/shell-attributes.server.ts +12 -9
  166. package/src/server/lib/assets/shell-attributes.test.ts +18 -13
  167. package/src/server/lib/connect/cloudflared-config.server.ts +236 -0
  168. package/src/server/lib/connect/cloudflared-config.test.ts +245 -0
  169. package/src/server/lib/connect/cloudflared.lifecycle.test.ts +116 -15
  170. package/src/server/lib/connect/cloudflared.server.ts +53 -66
  171. package/src/server/lib/connect/pairing.server.ts +33 -0
  172. package/src/server/lib/connect/qr-png.server.test.ts +93 -0
  173. package/src/server/lib/connect/qr-png.server.ts +119 -0
  174. package/src/server/lib/connect/status.server.ts +10 -4
  175. package/src/server/routes/connect/index.ts +2 -0
  176. package/src/server/routes/connect/pair-qr.test.ts +72 -0
  177. package/src/server/routes/connect/pair-qr.ts +44 -0
  178. package/src/server/routes/connect/pair.ts +8 -2
  179. package/src/server/routes/connect/tunnels.test.ts +141 -0
  180. package/src/server/routes/connect/tunnels.ts +32 -7
  181. package/src/server/routes/notifications/stream.ts +11 -2
  182. package/src/shared/lib/connect/types.ts +7 -0
  183. package/src/shared/lib/icons/icon-paint-authority.ts +5 -3
  184. package/src/shared/lib/theme/icon-style.test.ts +8 -5
  185. package/src/shared/lib/theme/icon-style.ts +15 -7
  186. package/src/shared/lib/theme/surface-style.test.ts +8 -5
  187. package/src/shared/lib/theme/surface-style.ts +17 -7
  188. package/src/shared/lib/workspace/sidebar-style.test.ts +7 -8
  189. package/src/shared/lib/workspace/sidebar-style.ts +7 -8
  190. package/dist/client/static/js/architecture-7GRP2DOG-bajpnvy7.js +0 -1
  191. package/dist/client/static/js/bash-0h36tk0k.js +0 -1
  192. package/dist/client/static/js/cpp-4wp9sy20.js +0 -1
  193. package/dist/client/static/js/css-c9nsbkh6.js +0 -1
  194. package/dist/client/static/js/cynefin-OW5HDTMX-8q9e90m8.js +0 -1
  195. package/dist/client/static/js/eventmodeling-NTZA5JFV-kn4hsm3p.js +0 -1
  196. package/dist/client/static/js/flowDiagram-KWPJA3E3-ah8cvps1.js +0 -1
  197. package/dist/client/static/js/gitGraph-4MIJSDKK-hvavh16n.js +0 -1
  198. package/dist/client/static/js/graphql-hbkmxsty.js +0 -1
  199. package/dist/client/static/js/index-btr2w8cq.js +0 -12
  200. package/dist/client/static/js/index-dfzrpy54.js +0 -2
  201. package/dist/client/static/js/index-sbd5e816.js +0 -1
  202. package/dist/client/static/js/info-A6RAGUB7-fmjz8qwg.js +0 -1
  203. package/dist/client/static/js/ini-72yrpvd4.js +0 -1
  204. package/dist/client/static/js/java-ab5tb2ra.js +0 -1
  205. package/dist/client/static/js/jsx-25zj9j3k.js +0 -1
  206. package/dist/client/static/js/lua-j5w0c9wm.js +0 -1
  207. package/dist/client/static/js/markdown-j6hn4377.js +0 -1
  208. package/dist/client/static/js/one-dark-pro-bm3r4js7.js +0 -1
  209. package/dist/client/static/js/one-light-e07dt7sy.js +0 -1
  210. package/dist/client/static/js/packet-AYTQ26CC-cwr6n1cm.js +0 -1
  211. package/dist/client/static/js/pie-WAS4IAKB-h1ebfzgt.js +0 -1
  212. package/dist/client/static/js/properties-q8njes42.js +0 -1
  213. package/dist/client/static/js/python-vqxc7181.js +0 -1
  214. package/dist/client/static/js/r-0k5eej8m.js +0 -1
  215. package/dist/client/static/js/radar-RG4KPBEZ-k7p1m364.js +0 -1
  216. package/dist/client/static/js/railroad-74A4TZTK-d08dw3t0.js +0 -1
  217. package/dist/client/static/js/railroad-abnf-HS5TGJTU-txnjycgk.js +0 -1
  218. package/dist/client/static/js/railroad-ebnf-LZEXJU2U-p0r3cv6w.js +0 -1
  219. package/dist/client/static/js/railroad-peg-WCYAUIDC-sryk900a.js +0 -1
  220. package/dist/client/static/js/swimlanesDiagram-TC7HE7FX-c1czc7kv.js +0 -8
  221. package/dist/client/static/js/treeView-Q6P3EWNA-77kj68p1.js +0 -1
  222. package/dist/client/static/js/treemap-WGGIJYW6-rw94xc82.js +0 -1
  223. package/dist/client/static/js/tsx-yd5wt250.js +0 -1
  224. package/dist/client/static/js/typescript-v7z7crfe.js +0 -1
  225. package/dist/client/static/js/wardley-WFR3VGLG-18xe4fhz.js +0 -1
  226. package/dist/client/static/js/xml-94fhzrfs.js +0 -1
  227. package/dist/client/static/js/yaml-s8af9rnw.js +0 -1
  228. package/src/client/components/settings/categories/connect-settings/qr-image.ts +0 -76
  229. package/src/server/lib/connect/cloudflared.server.test.ts +0 -65
@@ -17,11 +17,28 @@
17
17
  */
18
18
 
19
19
  import type { JSX } from 'preact';
20
- import { QUIET_ZONE, qrGeometry } from '@/client/components/settings/categories/connect-settings/qr-image';
21
20
  import type { QrMatrix } from '@/shared/lib/connect/types';
22
21
 
22
+ const QUIET_ZONE = 4;
23
+
24
+ /**
25
+ * The widest the code is drawn, in CSS pixels.
26
+ *
27
+ * A screenshot of this dialog is what a camera-less device uploads, so the size
28
+ * is a functional choice, not a layout one: at 260 px a ~100-module code is under
29
+ * 3 px per module, and `jsQR` failed to read a real capture of it ("no QR code
30
+ * found") while the same code at 4 px per module decoded every time.
31
+ */
32
+ const TARGET_EDGE = 340;
33
+
23
34
  export function QrCode({ matrix, label }: { matrix: QrMatrix; label: string }) {
24
- const { span, edge } = qrGeometry(matrix);
35
+ const span = matrix.size + QUIET_ZONE * 2;
36
+ // An INTEGER number of pixels per module. A fractional size makes the browser
37
+ // antialias every module edge, which is exactly what a binarizer cannot read —
38
+ // and it is why the same code scanned from a phone camera but not from a
39
+ // screenshot.
40
+ const modulePx = Math.max(3, Math.floor(TARGET_EDGE / span));
41
+ const edge = span * modulePx;
25
42
  const rects: JSX.Element[] = [];
26
43
  for (let row = 0; row < matrix.size; row += 1) {
27
44
  const line = matrix.rows[row] ?? '';
@@ -30,6 +30,7 @@ export interface UseConnectStatusResult {
30
30
  busy: string | null;
31
31
  refresh: () => Promise<void>;
32
32
  setTunnel: (provider: TunnelProvider, verb: TunnelVerb) => Promise<string | null>;
33
+ setCloudflareConfig: (path: string) => Promise<string | null>;
33
34
  revoke: (id: string) => Promise<string | null>;
34
35
  }
35
36
 
@@ -38,6 +39,34 @@ interface StatusEnvelope {
38
39
  error?: string;
39
40
  }
40
41
 
42
+ interface PostOutcome {
43
+ payload: StatusEnvelope | null;
44
+ message: string | null;
45
+ }
46
+
47
+ async function postTunnel(body: Record<string, unknown>): Promise<PostOutcome> {
48
+ try {
49
+ const response = await fetch('/api/connect/tunnels', {
50
+ method: 'POST',
51
+ headers: { 'content-type': 'application/json' },
52
+ body: JSON.stringify(body),
53
+ });
54
+ const payload = (await response.json().catch(() => null)) as StatusEnvelope | null;
55
+ if (!response.ok) {
56
+ return {
57
+ payload,
58
+ message: payload?.error ?? `The tunnel did not change (HTTP ${response.status}).`,
59
+ };
60
+ }
61
+ return { payload, message: null };
62
+ } catch (cause) {
63
+ return {
64
+ payload: null,
65
+ message: cause instanceof Error ? cause.message : 'The tunnel did not change.',
66
+ };
67
+ }
68
+ }
69
+
41
70
  export function useConnectStatus(): UseConnectStatusResult {
42
71
  const [status, setStatus] = useState<ConnectStatus | null>(null);
43
72
  const [error, setError] = useState<string | null>(null);
@@ -61,26 +90,12 @@ export function useConnectStatus(): UseConnectStatusResult {
61
90
  void refresh();
62
91
  }, [refresh]);
63
92
 
64
- const setTunnel = useCallback(
65
- async (provider: TunnelProvider, verb: TunnelVerb): Promise<string | null> => {
66
- setBusy(`${provider}:${verb}`);
93
+ const applyTunnel = useCallback(
94
+ async (busyKey: string, body: Record<string, unknown>): Promise<string | null> => {
95
+ setBusy(busyKey);
67
96
  try {
68
- const response = await fetch('/api/connect/tunnels', {
69
- method: 'POST',
70
- headers: { 'content-type': 'application/json' },
71
- body: JSON.stringify({ provider, action: verb }),
72
- });
73
- const payload = (await response.json().catch(() => null)) as StatusEnvelope | null;
97
+ const { payload, message } = await postTunnel(body);
74
98
  if (payload?.status) setStatus(payload.status);
75
- if (!response.ok) {
76
- const message = payload?.error ?? `The tunnel did not change (HTTP ${response.status}).`;
77
- setError(message);
78
- return message;
79
- }
80
- setError(null);
81
- return null;
82
- } catch (cause) {
83
- const message = cause instanceof Error ? cause.message : 'The tunnel did not change.';
84
99
  setError(message);
85
100
  return message;
86
101
  } finally {
@@ -90,6 +105,16 @@ export function useConnectStatus(): UseConnectStatusResult {
90
105
  [],
91
106
  );
92
107
 
108
+ const setTunnel = useCallback(
109
+ (provider: TunnelProvider, verb: TunnelVerb) => applyTunnel(`${provider}:${verb}`, { provider, action: verb }),
110
+ [applyTunnel],
111
+ );
112
+
113
+ const setCloudflareConfig = useCallback(
114
+ (path: string) => applyTunnel('cloudflare:config', { provider: 'cloudflare', action: 'config', path }),
115
+ [applyTunnel],
116
+ );
117
+
93
118
  const revoke = useCallback(async (id: string): Promise<string | null> => {
94
119
  setBusy(`device:${id}`);
95
120
  try {
@@ -112,5 +137,5 @@ export function useConnectStatus(): UseConnectStatusResult {
112
137
  }
113
138
  }, []);
114
139
 
115
- return { status, error, busy, refresh, setTunnel, revoke };
140
+ return { status, error, busy, refresh, setTunnel, setCloudflareConfig, revoke };
116
141
  }
@@ -22,6 +22,8 @@ export interface PairingCode {
22
22
  link: string;
23
23
  /** The `https://…/pair#…` link a browser can open. This is what the QR holds. */
24
24
  webLink: string;
25
+ /** The same code as a downloadable PNG, served by this origin. */
26
+ qrUrl: string;
25
27
  candidates: ConnectCandidate[];
26
28
  qr: { size: number; rows: string[] };
27
29
  }
@@ -66,6 +68,9 @@ export function usePairing(): UsePairingResult {
66
68
  expiresAt: payload.expiresAt ?? '',
67
69
  link: payload.link,
68
70
  webLink: payload.webLink ?? payload.link,
71
+ // A server too old to serve the PNG still mints a scannable code; the
72
+ // dialog then leaves the download out rather than pointing it at nothing.
73
+ qrUrl: payload.qrUrl ?? '',
69
74
  candidates: payload.candidates ?? [],
70
75
  qr: payload.qr,
71
76
  });
@@ -15,9 +15,9 @@
15
15
 
16
16
  import { readKabmoSetting } from '@/shared/lib/settings/client';
17
17
  import {
18
- DEFAULT_ICON_STYLE,
19
18
  ICON_STYLE_ATTRIBUTE,
20
19
  ICON_STYLE_SETTING_KEY,
20
+ ICON_STYLE_WITHOUT_ATTRIBUTE,
21
21
  resolveIconStyle,
22
22
  } from '@/shared/lib/theme/icon-style';
23
23
  import {
@@ -54,14 +54,17 @@ export function applyIconPaper(theme?: string): void {
54
54
  /**
55
55
  * Point the document at `style`.
56
56
  *
57
- * The default is REMOVED rather than written, so the ink rule in CSS is the
58
- * single statement of what "no attribute" means.
57
+ * `monochrome` is REMOVED rather than written, because the ink pass in CSS is
58
+ * stated as the absence of the attribute (`:root:not([data-icon-style="color"])`).
59
+ * The comparison is against that ABSENT state, not against `DEFAULT_ICON_STYLE`:
60
+ * the default is `color`, and omitting the attribute for it would paint every
61
+ * mark ink while the setting says full colour.
59
62
  */
60
63
  export function applyIconStyle(style: unknown): void {
61
64
  if (typeof document === 'undefined') return;
62
65
  const root = document.documentElement;
63
66
  const resolved = resolveIconStyle(style);
64
- if (resolved === DEFAULT_ICON_STYLE) root.removeAttribute(ICON_STYLE_ATTRIBUTE);
67
+ if (resolved === ICON_STYLE_WITHOUT_ATTRIBUTE) root.removeAttribute(ICON_STYLE_ATTRIBUTE);
65
68
  else root.setAttribute(ICON_STYLE_ATTRIBUTE, resolved);
66
69
  // The bucket belongs to the same writer: a document that states one style
67
70
  // without the other paints a `mid` palette with the `deep` table.
@@ -8,10 +8,10 @@
8
8
  *
9
9
  * Both writers exist because the value reaches CSS through the document, not a
10
10
  * prop — so the facts worth pinning are the ones a wrong implementation breaks
11
- * silently: the default must CLEAR the attribute (a document carrying it and a
12
- * document not carrying it have to be the same state), an unknown stored value
13
- * must not produce an attribute no rule matches, and the boot path must read
14
- * the primed settings snapshot rather than hardcode the default.
11
+ * silently: the style CSS paints with no attribute (`classic` / `monochrome`)
12
+ * must CLEAR it, an unknown stored value must resolve to the shipped default
13
+ * (`glass` / `color`) and write THAT, and the boot path must read the primed
14
+ * settings snapshot rather than hardcode the default.
15
15
  *
16
16
  * The settings client keeps a module-level snapshot, so each case primes it
17
17
  * explicitly instead of relying on file order.
@@ -59,23 +59,23 @@ describe('the stored keys', () => {
59
59
  });
60
60
 
61
61
  describe('applySurfaceStyle', () => {
62
- test('writes the non-default style as the attribute CSS keys on', () => {
62
+ test('writes glass as the attribute CSS keys on', () => {
63
63
  applySurfaceStyle('glass');
64
64
 
65
65
  expect(document.documentElement.getAttribute('data-surface')).toBe('glass');
66
66
  });
67
67
 
68
- test('the default CLEARS the attribute instead of writing it', () => {
68
+ test('classic CLEARS the attribute instead of writing it', () => {
69
69
  applySurfaceStyle('glass');
70
70
  applySurfaceStyle('classic');
71
71
 
72
72
  expect(document.documentElement.hasAttribute('data-surface')).toBe(false);
73
73
  });
74
74
 
75
- test('an unknown value resolves to the default rather than an unmatched rule', () => {
75
+ test('an unknown value resolves to the glass default and writes it', () => {
76
76
  applySurfaceStyle('liquid');
77
77
 
78
- expect(document.documentElement.hasAttribute('data-surface')).toBe(false);
78
+ expect(document.documentElement.getAttribute('data-surface')).toBe('glass');
79
79
  });
80
80
  });
81
81
 
@@ -109,12 +109,12 @@ describe('the boot path', () => {
109
109
  expect(document.documentElement.getAttribute('data-icon-style')).toBe('color');
110
110
  });
111
111
 
112
- test('an install with no stored preference boots opaque and monochrome', () => {
112
+ test('an install with no stored preference boots glass and full colour', () => {
113
113
  primeKabmoSettings({});
114
114
  initSurfaceStyle();
115
115
  initIconStyle();
116
116
 
117
- expect(document.documentElement.hasAttribute('data-surface')).toBe(false);
118
- expect(document.documentElement.hasAttribute('data-icon-style')).toBe(false);
117
+ expect(document.documentElement.getAttribute('data-surface')).toBe('glass');
118
+ expect(document.documentElement.getAttribute('data-icon-style')).toBe('color');
119
119
  });
120
120
  });
@@ -23,24 +23,27 @@
23
23
 
24
24
  import { readKabmoSetting } from '@/shared/lib/settings/client';
25
25
  import {
26
- DEFAULT_SURFACE_STYLE,
27
26
  SURFACE_ATTRIBUTE,
28
27
  SURFACE_STYLE_SETTING_KEY,
28
+ SURFACE_STYLE_WITHOUT_ATTRIBUTE,
29
29
  resolveSurfaceStyle,
30
30
  } from '@/shared/lib/theme/surface-style';
31
31
 
32
32
  /**
33
33
  * Point the document at `style`.
34
34
  *
35
- * The default is REMOVED rather than written, so a document carrying `classic`
36
- * and a document carrying nothing are the same state — which is what makes the
37
- * `:root` fallback in CSS the single statement of the opaque default.
35
+ * The style CSS paints with no attribute is REMOVED rather than written, so a
36
+ * document carrying `classic` and a document carrying nothing are the same
37
+ * state — which is what makes the `:root` fallback in CSS the single statement
38
+ * of the opaque look. The comparison is against that ABSENT state, not against
39
+ * `DEFAULT_SURFACE_STYLE`: the default is `glass`, and omitting the attribute
40
+ * for it would paint the opaque shell while the setting says glass.
38
41
  */
39
42
  export function applySurfaceStyle(style: unknown): void {
40
43
  if (typeof document === 'undefined') return;
41
44
  const root = document.documentElement;
42
45
  const resolved = resolveSurfaceStyle(style);
43
- if (resolved === DEFAULT_SURFACE_STYLE) root.removeAttribute(SURFACE_ATTRIBUTE);
46
+ if (resolved === SURFACE_STYLE_WITHOUT_ATTRIBUTE) root.removeAttribute(SURFACE_ATTRIBUTE);
44
47
  else root.setAttribute(SURFACE_ATTRIBUTE, resolved);
45
48
  }
46
49
 
@@ -9,7 +9,10 @@
9
9
  * The event switches live in the server's settings, and the shell has no page
10
10
  * to ask once the app is backgrounded — so the answer is pushed to it here, on
11
11
  * boot and whenever a switch changes. The shell persists it and starts its
12
- * watcher from `onStop` only when it is armed.
12
+ * watcher from that command, while the console is still visible (Android 12+
13
+ * refuses a foreground-service start from the background); it also refuses to
14
+ * start when the OS notification permission is missing, and `MainActivity`
15
+ * re-arms on the next resume once the grant exists.
13
16
  *
14
17
  * A no-op outside a phone shell: the desktop shells and a browser have no
15
18
  * background watcher, and their notifications are posted by the page itself.
@@ -18,24 +18,27 @@
18
18
  * - **`data-theme` and `data-theme-variant` are ALWAYS written.** They are the
19
19
  * palette; `applyDocumentTheme` owns them after hydration, and a document
20
20
  * served without them keeps `:root`'s shipped palette.
21
- * - **The two style attributes are written only when they are not the default.**
22
- * `applySurfaceStyle` / `applyIconStyle` remove the attribute for the default,
23
- * so emitting `data-surface="classic"` here would make the server and the
24
- * client disagree about the document's own state — and every CSS rule keys on
25
- * the value, not on its absence.
21
+ * - **The two style attributes are written only when the style is not the one
22
+ * CSS paints with no attribute** (`classic` / `monochrome`). The client's
23
+ * `applySurfaceStyle` / `applyIconStyle` remove the attribute for exactly
24
+ * those values, so emitting `data-surface="classic"` here would make the
25
+ * server and the client disagree about the document's own state — and every
26
+ * CSS rule keys on the value, not on its absence. This is NOT the same test
27
+ * as `DEFAULT_*`: the defaults are now `glass` / `color`, and those must be
28
+ * emitted so the first frame is already frosted and coloured.
26
29
  */
27
30
 
28
31
  import type { ThemePalette } from '@/shared/types/theme';
29
32
  import {
30
- DEFAULT_ICON_STYLE,
31
33
  ICON_STYLE_ATTRIBUTE,
34
+ ICON_STYLE_WITHOUT_ATTRIBUTE,
32
35
  resolveIconStyle,
33
36
  } from '@/shared/lib/theme/icon-style';
34
37
  import { ICON_PAPER_ATTRIBUTE } from '@/shared/lib/icons/tint';
35
38
  import { paperBucketOf } from '@/shared/lib/icons/icon-tone';
36
39
  import {
37
- DEFAULT_SURFACE_STYLE,
38
40
  SURFACE_ATTRIBUTE,
41
+ SURFACE_STYLE_WITHOUT_ATTRIBUTE,
39
42
  resolveSurfaceStyle,
40
43
  } from '@/shared/lib/theme/surface-style';
41
44
 
@@ -59,8 +62,8 @@ export function styleAttributes(surfaceStyle: unknown, iconStyle: unknown, palet
59
62
  const surface = resolveSurfaceStyle(surfaceStyle);
60
63
  const icon = resolveIconStyle(iconStyle);
61
64
  const parts: string[] = [];
62
- if (surface !== DEFAULT_SURFACE_STYLE) parts.push(`${SURFACE_ATTRIBUTE}="${surface}"`);
63
- if (icon !== DEFAULT_ICON_STYLE) parts.push(`${ICON_STYLE_ATTRIBUTE}="${icon}"`);
65
+ if (surface !== SURFACE_STYLE_WITHOUT_ATTRIBUTE) parts.push(`${SURFACE_ATTRIBUTE}="${surface}"`);
66
+ if (icon !== ICON_STYLE_WITHOUT_ATTRIBUTE) parts.push(`${ICON_STYLE_ATTRIBUTE}="${icon}"`);
64
67
  // The paper bucket is written for EVERY light palette, including the default
65
68
  // one, because it is not a preference: without it the first frame paints the
66
69
  // `deep` icon table on a `mid` paper — one step darker than the palette allows,
@@ -7,11 +7,13 @@
7
7
  * The first frame's `<html>` attributes.
8
8
  *
9
9
  * The rule worth pinning is the ASYMMETRY: the palette is always written, and
10
- * the two presentation styles are written only when they are not the default —
11
- * because the client's writers REMOVE the attribute for the default, and a
12
- * server that emitted `data-surface="classic"` would leave a document the
13
- * client thinks is "explicitly classic" and a reload flipping between two
14
- * spellings of the same state.
10
+ * the two presentation styles are written only when they are not the style CSS
11
+ * paints with no attribute (`classic` / `monochrome`) — because the client's
12
+ * writers REMOVE the attribute for exactly those values, and a server that
13
+ * emitted `data-surface="classic"` would leave a document the client thinks is
14
+ * "explicitly classic" and a reload flipping between two spellings of the same
15
+ * state. The shipped DEFAULTS (`glass` / `color`) are therefore emitted, so the
16
+ * first frame is already frosted and coloured.
15
17
  */
16
18
 
17
19
  import { describe, expect, test } from 'bun:test';
@@ -35,13 +37,18 @@ const light = KABMO_PALETTES[0];
35
37
  const dark = THEMES.find((theme) => theme.variant === 'dark')!;
36
38
 
37
39
  describe('styleAttributes', () => {
38
- test('the defaults add nothing at all', () => {
40
+ test('the styles CSS paints with no attribute add nothing', () => {
39
41
  expect(styleAttributes('classic', 'monochrome')).toBe('');
40
- expect(styleAttributes(undefined, undefined)).toBe('');
41
- expect(styleAttributes('nonsense', 'nonsense')).toBe('');
42
42
  });
43
43
 
44
- test('each non-default style contributes its own attribute', () => {
44
+ test('the shipped defaults are emitted so the first frame is frosted and coloured', () => {
45
+ const defaults = ' data-surface="glass" data-icon-style="color"';
46
+ expect(styleAttributes(undefined, undefined)).toBe(defaults);
47
+ expect(styleAttributes('nonsense', 'nonsense')).toBe(defaults);
48
+ expect(styleAttributes('glass', 'color')).toBe(defaults);
49
+ });
50
+
51
+ test('each style contributes its own attribute independently', () => {
45
52
  expect(styleAttributes('glass', 'monochrome')).toBe(' data-surface="glass"');
46
53
  expect(styleAttributes('classic', 'color')).toBe(' data-icon-style="color"');
47
54
  expect(styleAttributes('glass', 'color')).toBe(' data-surface="glass" data-icon-style="color"');
@@ -58,7 +65,7 @@ describe('styleAttributes', () => {
58
65
  });
59
66
 
60
67
  describe('applyShellDocumentFacts', () => {
61
- test('writes the palette and the chrome colour, and nothing else by default', () => {
68
+ test('writes the palette, the shipped styles and the chrome colour', () => {
62
69
  const html = applyShellDocumentFacts(TEMPLATE, {
63
70
  palette: light,
64
71
  surfaceStyle: undefined,
@@ -67,11 +74,9 @@ describe('applyShellDocumentFacts', () => {
67
74
  });
68
75
 
69
76
  expect(html).toContain(
70
- `<html lang="en" data-theme="${light.id}" data-icon-paper="mid" data-theme-variant="${light.variant}">`,
77
+ `<html lang="en" data-theme="${light.id}" data-surface="glass" data-icon-style="color" data-icon-paper="mid" data-theme-variant="${light.variant}">`,
71
78
  );
72
79
  expect(html).toContain('<meta name="theme-color" content="#123456" />');
73
- expect(html).not.toContain('data-surface');
74
- expect(html).not.toContain('data-icon-style');
75
80
  });
76
81
 
77
82
  test('a stored glass style lands on the FIRST frame, not after hydration', () => {
@@ -0,0 +1,236 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The cloudflared config: where it is, what it says, and the copy cloudflared
8
+ * actually runs.
9
+ *
10
+ * Two facts decide the tunnel's destination. The config path is a stored
11
+ * preference (page), an environment override (`CLOUDFLARED_CONFIG`) or the
12
+ * documented default; the ingress `service:` is what cloudflared dials, and it
13
+ * must be THIS instance's port or a second Kabmo silently gets the first one's
14
+ * traffic. `--url` cannot fix that — see `deriveCloudflaredRunConfig`.
15
+ */
16
+
17
+ import fs from 'fs';
18
+ import os from 'os';
19
+ import path from 'path';
20
+ import { getDb } from '@/server/db.server';
21
+ import { readSettingsJson, writeSettingsJson } from '@/server/lib/db/settings-store';
22
+
23
+ /** `app_settings` key holding the config path chosen on the Connect page. */
24
+ const CLOUDFLARE_CONFIG_KEY = 'connect.cloudflareConfigPath';
25
+
26
+ export interface CloudflaredConfig {
27
+ /** The tunnel name or UUID from `tunnel:`. */
28
+ tunnel: string | null;
29
+ /** The first public hostname in the ingress list. */
30
+ hostname: string | null;
31
+ }
32
+
33
+ /** Where cloudflared looks for its config, honouring the documented override. */
34
+ export function cloudflaredConfigPath(): string {
35
+ const override = (Bun.env.CLOUDFLARED_CONFIG ?? '').trim();
36
+ if (override) return override;
37
+ return path.join(os.homedir(), '.cloudflared', 'config.yml');
38
+ }
39
+
40
+ function expandHome(value: string): string {
41
+ if (value === '~') return os.homedir();
42
+ if (value.startsWith('~/')) return path.join(os.homedir(), value.slice(2));
43
+ return value;
44
+ }
45
+
46
+ /**
47
+ * The config the Connect page and the start path agree on.
48
+ *
49
+ * A path saved on the page wins over `CLOUDFLARED_CONFIG`, which wins over
50
+ * `~/.cloudflared/config.yml`. The page allows the override because a config
51
+ * kept outside the home directory (a secret store, a work profile) is a normal
52
+ * setup, and editing an environment variable before every start is not.
53
+ */
54
+ export async function resolveCloudflaredConfigPath(): Promise<string> {
55
+ const db = await getDb();
56
+ const stored = await readSettingsJson<unknown>(db, CLOUDFLARE_CONFIG_KEY, null);
57
+ if (typeof stored === 'string' && stored.trim()) return stored.trim();
58
+ return cloudflaredConfigPath();
59
+ }
60
+
61
+ export interface SaveConfigOutcome {
62
+ ok: boolean;
63
+ /** The path now in effect, when the save succeeded. */
64
+ path: string | null;
65
+ reason: string | null;
66
+ }
67
+
68
+ /**
69
+ * Persist a config path after proving cloudflared could run from it.
70
+ *
71
+ * A saved path that is missing or has no ingress hostname would put a dead
72
+ * switch on the page, so the write is refused with the reason the reader can
73
+ * act on. An empty string resets to the environment/default path.
74
+ */
75
+ export async function saveCloudflaredConfigPath(raw: unknown): Promise<SaveConfigOutcome> {
76
+ if (typeof raw !== 'string') {
77
+ return { ok: false, path: null, reason: 'Expected a config path.' };
78
+ }
79
+ const db = await getDb();
80
+ const trimmed = raw.trim();
81
+ if (!trimmed) {
82
+ await writeSettingsJson(db, CLOUDFLARE_CONFIG_KEY, null);
83
+ return { ok: true, path: cloudflaredConfigPath(), reason: null };
84
+ }
85
+
86
+ const expanded = expandHome(trimmed);
87
+ if (!path.isAbsolute(expanded)) {
88
+ return { ok: false, path: null, reason: 'The config path must be absolute.' };
89
+ }
90
+ const resolved = path.resolve(expanded);
91
+ let isFile = false;
92
+ try {
93
+ isFile = fs.statSync(resolved).isFile();
94
+ } catch {
95
+ return { ok: false, path: null, reason: `No config file at ${resolved}.` };
96
+ }
97
+ if (!isFile) {
98
+ return { ok: false, path: null, reason: `${resolved} is not a file.` };
99
+ }
100
+
101
+ const config = readCloudflaredConfig(resolved);
102
+ if (!config) {
103
+ return {
104
+ ok: false,
105
+ path: null,
106
+ reason: `${resolved} is not a cloudflared config: it has no tunnel: or ingress: entry.`,
107
+ };
108
+ }
109
+ if (!config.hostname) {
110
+ return {
111
+ ok: false,
112
+ path: null,
113
+ reason: `The config at ${resolved} has no ingress hostname, so there is no public URL to show.`,
114
+ };
115
+ }
116
+
117
+ await writeSettingsJson(db, CLOUDFLARE_CONFIG_KEY, resolved);
118
+ return { ok: true, path: resolved, reason: null };
119
+ }
120
+
121
+ /**
122
+ * Read the two facts this page needs out of the YAML.
123
+ *
124
+ * A line scan rather than a YAML parser: the file is written by
125
+ * `cloudflared tunnel create` and by hand, and the only fields read here are a
126
+ * top-level `tunnel:` and the first `hostname:` under `ingress:`. Pulling in a
127
+ * parser for two scalars would be a dependency the rest of the server does not
128
+ * have, and a malformed file must degrade to "not configured" rather than throw.
129
+ */
130
+ export function readCloudflaredConfig(file: string): CloudflaredConfig | null {
131
+ let text: string;
132
+ try {
133
+ text = fs.readFileSync(file, 'utf8');
134
+ } catch {
135
+ return null;
136
+ }
137
+
138
+ let tunnel: string | null = null;
139
+ let hostname: string | null = null;
140
+ let inIngress = false;
141
+ for (const rawLine of text.split('\n')) {
142
+ const line = rawLine.replace(/\s+#.*$/, '');
143
+ if (/^tunnel:\s*/.test(line)) {
144
+ tunnel = line.replace(/^tunnel:\s*/, '').trim().replace(/^["']|["']$/g, '') || null;
145
+ continue;
146
+ }
147
+ if (/^ingress:\s*$/.test(line)) {
148
+ inIngress = true;
149
+ continue;
150
+ }
151
+ if (inIngress && /^\S/.test(line)) {
152
+ // A new top-level key ends the ingress block.
153
+ inIngress = false;
154
+ }
155
+ if (inIngress && hostname === null) {
156
+ const match = /^\s*-\s*hostname:\s*(\S+)/.exec(line) ?? /^\s*hostname:\s*(\S+)/.exec(line);
157
+ if (match?.[1]) hostname = match[1].replace(/^["']|["']$/g, '');
158
+ }
159
+ }
160
+
161
+ if (!tunnel && !hostname) return null;
162
+ return { tunnel, hostname };
163
+ }
164
+
165
+ /**
166
+ * The config cloudflared actually runs with, pointed at this instance's port.
167
+ *
168
+ * `--url` does NOT override an `ingress:` block: cloudflared parses the config's
169
+ * rules first and only falls back to the CLI origin when `ingress` is empty
170
+ * (`ingress.ParseIngressFromConfigAndCLI`). Kabmo refuses a config without an
171
+ * ingress hostname, so every config it accepts would ignore `--url` and send
172
+ * traffic to whatever `service:` names — often a different port or a different
173
+ * app. The first rule that names a hostname therefore gets its `service:`
174
+ * rewritten in a runtime copy; the user's file is never touched.
175
+ *
176
+ * Returns null when there is no ingress rule with a hostname to rewrite.
177
+ */
178
+ export function deriveCloudflaredRunConfig(text: string, port: number): string | null {
179
+ const lines = text.split('\n');
180
+ const ingressAt = lines.findIndex((line) => /^ingress:\s*$/.test(line.replace(/\s+#.*$/, '')));
181
+ if (ingressAt === -1) return null;
182
+
183
+ // A new top-level key ends the ingress block.
184
+ let end = lines.length;
185
+ for (let i = ingressAt + 1; i < lines.length; i++) {
186
+ if (/^\S/.test(lines[i])) {
187
+ end = i;
188
+ break;
189
+ }
190
+ }
191
+
192
+ // Only items at the first rule's indentation start a new rule; a nested
193
+ // `ipRules:` list under `originRequest` must not cut the rule in two.
194
+ const itemPattern = /^(\s*)-\s/;
195
+ const items: Array<{ at: number; indent: string }> = [];
196
+ for (let i = ingressAt + 1; i < end; i++) {
197
+ const item = itemPattern.exec(lines[i]);
198
+ if (item) items.push({ at: i, indent: item[1] });
199
+ }
200
+ if (items.length === 0) return null;
201
+ const ruleIndent = items[0].indent;
202
+ const starts = items.filter((item) => item.indent === ruleIndent).map((item) => item.at);
203
+
204
+ const hostnamePattern = /^(\s*)(-\s*)?hostname:\s*(\S+)/;
205
+ const servicePattern = /^(\s*)service:\s*/;
206
+ for (let rule = 0; rule < starts.length; rule++) {
207
+ const from = starts[rule];
208
+ const to = rule + 1 < starts.length ? starts[rule + 1] : end;
209
+ let hostnameAt = -1;
210
+ for (let i = from; i < to; i++) {
211
+ if (hostnamePattern.test(lines[i])) {
212
+ hostnameAt = i;
213
+ break;
214
+ }
215
+ }
216
+ if (hostnameAt === -1) continue;
217
+
218
+ const copy = lines.slice();
219
+ for (let i = from; i < to; i++) {
220
+ const service = servicePattern.exec(lines[i]);
221
+ if (!service) continue;
222
+ const cr = lines[i].endsWith('\r') ? '\r' : '';
223
+ copy[i] = `${service[1]}service: http://127.0.0.1:${port}${cr}`;
224
+ return copy.join('\n');
225
+ }
226
+
227
+ // The rule has a hostname but no service of its own: add one beside it.
228
+ const hostname = hostnamePattern.exec(lines[hostnameAt]) as RegExpExecArray;
229
+ const indent = hostname[1] + (hostname[2] ? ' ' : '');
230
+ const cr = lines[hostnameAt].endsWith('\r') ? '\r' : '';
231
+ copy.splice(hostnameAt + 1, 0, `${indent}service: http://127.0.0.1:${port}${cr}`);
232
+ return copy.join('\n');
233
+ }
234
+
235
+ return null;
236
+ }