ref0-git 0.0.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (385) hide show
  1. package/app/apps/github/.dev.vars.example +6 -0
  2. package/app/apps/github/README.md +70 -0
  3. package/app/apps/github/THIRD_PARTY_NOTICES.md +214 -0
  4. package/app/apps/github/components.json +25 -0
  5. package/app/apps/github/generated/git-rest.ts +10444 -0
  6. package/app/apps/github/generated/routeTree.gen.ts +1242 -0
  7. package/app/apps/github/migrations/postgres/0001_auth.sql +46 -0
  8. package/app/apps/github/migrations/sql/0001_auth.sql +19 -0
  9. package/app/apps/github/migrations/sql/0002_passkeys.sql +9 -0
  10. package/app/apps/github/migrations/sql/0003_orgs.sql +22 -0
  11. package/app/apps/github/migrations/sql/0004_avatars.sql +6 -0
  12. package/app/apps/github/package.json +80 -0
  13. package/app/apps/github/src/branches/branch-list.tsx +385 -0
  14. package/app/apps/github/src/branches/branches.ts +55 -0
  15. package/app/apps/github/src/clients/allowed.ts +213 -0
  16. package/app/apps/github/src/clients/at-most.ts +17 -0
  17. package/app/apps/github/src/clients/avatars.ts +410 -0
  18. package/app/apps/github/src/clients/cached.ts +65 -0
  19. package/app/apps/github/src/clients/calls.ts +160 -0
  20. package/app/apps/github/src/clients/clients.ts +82 -0
  21. package/app/apps/github/src/clients/graphql.ts +50 -0
  22. package/app/apps/github/src/clients/host-answer.ts +28 -0
  23. package/app/apps/github/src/clients/host-calls.ts +382 -0
  24. package/app/apps/github/src/clients/icon-bytes.ts +203 -0
  25. package/app/apps/github/src/clients/proxy.ts +59 -0
  26. package/app/apps/github/src/clients/session-ended.ts +18 -0
  27. package/app/apps/github/src/clients/transfers.ts +212 -0
  28. package/app/apps/github/src/code/breadcrumbs.tsx +50 -0
  29. package/app/apps/github/src/code/code-page.tsx +147 -0
  30. package/app/apps/github/src/code/code-tree.tsx +338 -0
  31. package/app/apps/github/src/code/controls.tsx +230 -0
  32. package/app/apps/github/src/code/file-view.tsx +450 -0
  33. package/app/apps/github/src/code/files.ts +332 -0
  34. package/app/apps/github/src/code/folder-list.tsx +122 -0
  35. package/app/apps/github/src/code/go-to-file.tsx +131 -0
  36. package/app/apps/github/src/code/highlighted.tsx +58 -0
  37. package/app/apps/github/src/code/lines.ts +46 -0
  38. package/app/apps/github/src/code/load.ts +147 -0
  39. package/app/apps/github/src/code/markdown-files.ts +58 -0
  40. package/app/apps/github/src/code/places.ts +88 -0
  41. package/app/apps/github/src/code/ref-pages.ts +179 -0
  42. package/app/apps/github/src/code/ref-switcher.tsx +203 -0
  43. package/app/apps/github/src/code/refs.ts +142 -0
  44. package/app/apps/github/src/code/repo-home.tsx +240 -0
  45. package/app/apps/github/src/code/repo.ts +105 -0
  46. package/app/apps/github/src/code/saved-reads.ts +199 -0
  47. package/app/apps/github/src/code/saved.ts +110 -0
  48. package/app/apps/github/src/code/tree-fold.ts +186 -0
  49. package/app/apps/github/src/code/trees.ts +136 -0
  50. package/app/apps/github/src/components/avatar-picture.ts +53 -0
  51. package/app/apps/github/src/components/avatar-url.ts +16 -0
  52. package/app/apps/github/src/components/confirm-action.tsx +100 -0
  53. package/app/apps/github/src/components/count.tsx +24 -0
  54. package/app/apps/github/src/components/create-button.tsx +38 -0
  55. package/app/apps/github/src/components/file-icons/file-icons.css +225 -0
  56. package/app/apps/github/src/components/file-icons/file-icons.tsx +138 -0
  57. package/app/apps/github/src/components/filter.tsx +35 -0
  58. package/app/apps/github/src/components/hotkeys/hotkeys.tsx +255 -0
  59. package/app/apps/github/src/components/item-list.tsx +65 -0
  60. package/app/apps/github/src/components/language-dot.tsx +29 -0
  61. package/app/apps/github/src/components/list-toolbar.tsx +82 -0
  62. package/app/apps/github/src/components/markdown/editor.tsx +57 -0
  63. package/app/apps/github/src/components/markdown/markdown.css +177 -0
  64. package/app/apps/github/src/components/markdown/markdown.tsx +82 -0
  65. package/app/apps/github/src/components/owner-card.tsx +196 -0
  66. package/app/apps/github/src/components/pull-status.tsx +34 -0
  67. package/app/apps/github/src/components/recent.ts +41 -0
  68. package/app/apps/github/src/components/relative-time.tsx +78 -0
  69. package/app/apps/github/src/components/repos/icon-hashes.ts +91 -0
  70. package/app/apps/github/src/components/repos/new-repo-form.tsx +196 -0
  71. package/app/apps/github/src/components/repos/repo-icon.tsx +47 -0
  72. package/app/apps/github/src/components/repos/repo-list.tsx +528 -0
  73. package/app/apps/github/src/components/repos/your-repos.tsx +124 -0
  74. package/app/apps/github/src/components/review-state.tsx +75 -0
  75. package/app/apps/github/src/components/route-dialog.tsx +137 -0
  76. package/app/apps/github/src/components/save-button.tsx +58 -0
  77. package/app/apps/github/src/components/shell/app-shell.tsx +164 -0
  78. package/app/apps/github/src/components/shell/create-org-dialog.tsx +118 -0
  79. package/app/apps/github/src/components/shell/create-row.tsx +49 -0
  80. package/app/apps/github/src/components/shell/link-menu.tsx +94 -0
  81. package/app/apps/github/src/components/shell/nav-user.tsx +97 -0
  82. package/app/apps/github/src/components/shell/owner-repos.tsx +247 -0
  83. package/app/apps/github/src/components/shell/owner-switcher.tsx +104 -0
  84. package/app/apps/github/src/components/shell/repo-switcher.tsx +179 -0
  85. package/app/apps/github/src/components/shell/sections.ts +31 -0
  86. package/app/apps/github/src/components/shell/submenu-chevron.ts +147 -0
  87. package/app/apps/github/src/components/signin/device-card.tsx +139 -0
  88. package/app/apps/github/src/components/signin/login-form.tsx +88 -0
  89. package/app/apps/github/src/components/signin/signin-page.tsx +33 -0
  90. package/app/apps/github/src/components/signin/signup-form.tsx +106 -0
  91. package/app/apps/github/src/components/states/live-status.tsx +42 -0
  92. package/app/apps/github/src/components/states/states.tsx +126 -0
  93. package/app/apps/github/src/components/tab-indicator.tsx +143 -0
  94. package/app/apps/github/src/components/theme-choice.tsx +108 -0
  95. package/app/apps/github/src/components/theme-provider.tsx +126 -0
  96. package/app/apps/github/src/components/tones.ts +23 -0
  97. package/app/apps/github/src/components/ui/alert-dialog.tsx +187 -0
  98. package/app/apps/github/src/components/ui/alert.tsx +78 -0
  99. package/app/apps/github/src/components/ui/avatar.tsx +106 -0
  100. package/app/apps/github/src/components/ui/badge.tsx +51 -0
  101. package/app/apps/github/src/components/ui/breadcrumb.tsx +124 -0
  102. package/app/apps/github/src/components/ui/button-group.tsx +87 -0
  103. package/app/apps/github/src/components/ui/button.tsx +61 -0
  104. package/app/apps/github/src/components/ui/calendar.tsx +221 -0
  105. package/app/apps/github/src/components/ui/card.tsx +102 -0
  106. package/app/apps/github/src/components/ui/checkbox.tsx +26 -0
  107. package/app/apps/github/src/components/ui/collapsible.tsx +19 -0
  108. package/app/apps/github/src/components/ui/combobox.tsx +304 -0
  109. package/app/apps/github/src/components/ui/command.tsx +208 -0
  110. package/app/apps/github/src/components/ui/dialog.tsx +156 -0
  111. package/app/apps/github/src/components/ui/dropdown-menu.tsx +290 -0
  112. package/app/apps/github/src/components/ui/empty.tsx +100 -0
  113. package/app/apps/github/src/components/ui/field.tsx +236 -0
  114. package/app/apps/github/src/components/ui/hover-card.tsx +48 -0
  115. package/app/apps/github/src/components/ui/input-group.tsx +163 -0
  116. package/app/apps/github/src/components/ui/input.tsx +19 -0
  117. package/app/apps/github/src/components/ui/item.tsx +201 -0
  118. package/app/apps/github/src/components/ui/kbd.tsx +27 -0
  119. package/app/apps/github/src/components/ui/label.tsx +33 -0
  120. package/app/apps/github/src/components/ui/popover.tsx +87 -0
  121. package/app/apps/github/src/components/ui/radio-group.tsx +35 -0
  122. package/app/apps/github/src/components/ui/select.tsx +198 -0
  123. package/app/apps/github/src/components/ui/separator.tsx +22 -0
  124. package/app/apps/github/src/components/ui/sheet.tsx +138 -0
  125. package/app/apps/github/src/components/ui/sidebar.tsx +724 -0
  126. package/app/apps/github/src/components/ui/skeleton.tsx +13 -0
  127. package/app/apps/github/src/components/ui/sonner.tsx +47 -0
  128. package/app/apps/github/src/components/ui/styles.css +242 -0
  129. package/app/apps/github/src/components/ui/table.tsx +113 -0
  130. package/app/apps/github/src/components/ui/tabs.tsx +79 -0
  131. package/app/apps/github/src/components/ui/textarea.tsx +17 -0
  132. package/app/apps/github/src/components/ui/title.ts +6 -0
  133. package/app/apps/github/src/components/ui/toggle-group.tsx +89 -0
  134. package/app/apps/github/src/components/ui/toggle.tsx +42 -0
  135. package/app/apps/github/src/components/ui/tooltip.tsx +63 -0
  136. package/app/apps/github/src/components/user-avatar.tsx +145 -0
  137. package/app/apps/github/src/components/view-tabs.tsx +42 -0
  138. package/app/apps/github/src/context/context.ts +133 -0
  139. package/app/apps/github/src/diffs/blobs.ts +94 -0
  140. package/app/apps/github/src/diffs/diff-view.tsx +155 -0
  141. package/app/apps/github/src/diffs/files.ts +121 -0
  142. package/app/apps/github/src/diffs/hunks.tsx +454 -0
  143. package/app/apps/github/src/diffs/patch.ts +131 -0
  144. package/app/apps/github/src/diffs/rows.ts +137 -0
  145. package/app/apps/github/src/history/commit-diff.ts +54 -0
  146. package/app/apps/github/src/history/commit-list.tsx +207 -0
  147. package/app/apps/github/src/history/commit-page.tsx +147 -0
  148. package/app/apps/github/src/history/history.ts +129 -0
  149. package/app/apps/github/src/hooks/allowed.ts +31 -0
  150. package/app/apps/github/src/hooks/answers.ts +65 -0
  151. package/app/apps/github/src/hooks/avatars.ts +54 -0
  152. package/app/apps/github/src/hooks/draft.ts +38 -0
  153. package/app/apps/github/src/hooks/open-counts.ts +127 -0
  154. package/app/apps/github/src/hooks/profiles.ts +120 -0
  155. package/app/apps/github/src/hooks/repos.ts +440 -0
  156. package/app/apps/github/src/hooks/use-mobile.ts +19 -0
  157. package/app/apps/github/src/hooks/viewer.ts +39 -0
  158. package/app/apps/github/src/inbox/count.ts +70 -0
  159. package/app/apps/github/src/inbox/inbox-item.tsx +66 -0
  160. package/app/apps/github/src/inbox/inbox-page.tsx +572 -0
  161. package/app/apps/github/src/inbox/marks.ts +130 -0
  162. package/app/apps/github/src/inbox/release-tags.ts +65 -0
  163. package/app/apps/github/src/inbox/search.ts +97 -0
  164. package/app/apps/github/src/inbox/subjects.ts +184 -0
  165. package/app/apps/github/src/inbox/subscription-controls.tsx +184 -0
  166. package/app/apps/github/src/inbox/subscriptions.ts +189 -0
  167. package/app/apps/github/src/inbox/threads.ts +198 -0
  168. package/app/apps/github/src/issues/changes.ts +332 -0
  169. package/app/apps/github/src/issues/counts.ts +62 -0
  170. package/app/apps/github/src/issues/issue-list.tsx +682 -0
  171. package/app/apps/github/src/issues/issue-page.tsx +533 -0
  172. package/app/apps/github/src/issues/issues.ts +566 -0
  173. package/app/apps/github/src/issues/label-dialog.tsx +310 -0
  174. package/app/apps/github/src/issues/labels-page.tsx +119 -0
  175. package/app/apps/github/src/issues/new-issue.tsx +79 -0
  176. package/app/apps/github/src/issues/parts.tsx +71 -0
  177. package/app/apps/github/src/issues/picker.tsx +298 -0
  178. package/app/apps/github/src/issues/search.ts +238 -0
  179. package/app/apps/github/src/issues/sidebar.tsx +236 -0
  180. package/app/apps/github/src/lib/cn.ts +8 -0
  181. package/app/apps/github/src/lib/highlighting.ts +13 -0
  182. package/app/apps/github/src/live/follow.ts +129 -0
  183. package/app/apps/github/src/live/sse.ts +74 -0
  184. package/app/apps/github/src/live/use-follow.ts +37 -0
  185. package/app/apps/github/src/markdown/README.md +53 -0
  186. package/app/apps/github/src/markdown/allowed-html.ts +69 -0
  187. package/app/apps/github/src/markdown/context.ts +206 -0
  188. package/app/apps/github/src/markdown/images.ts +81 -0
  189. package/app/apps/github/src/markdown/lookup.ts +127 -0
  190. package/app/apps/github/src/markdown/patches.ts +299 -0
  191. package/app/apps/github/src/markdown/query.ts +25 -0
  192. package/app/apps/github/src/markdown/references.ts +158 -0
  193. package/app/apps/github/src/markdown/render.ts +103 -0
  194. package/app/apps/github/src/names/owners.ts +51 -0
  195. package/app/apps/github/src/names/repos.ts +24 -0
  196. package/app/apps/github/src/palette/palette.tsx +562 -0
  197. package/app/apps/github/src/palette/recent.ts +116 -0
  198. package/app/apps/github/src/palette/rows.tsx +487 -0
  199. package/app/apps/github/src/palette/server.ts +107 -0
  200. package/app/apps/github/src/palette/targets.ts +306 -0
  201. package/app/apps/github/src/policy.ts +606 -0
  202. package/app/apps/github/src/private-repos.ts +47 -0
  203. package/app/apps/github/src/pulls/compare-page.tsx +342 -0
  204. package/app/apps/github/src/pulls/files-tab.tsx +776 -0
  205. package/app/apps/github/src/pulls/live.ts +124 -0
  206. package/app/apps/github/src/pulls/merge-box.tsx +367 -0
  207. package/app/apps/github/src/pulls/merge-button.ts +86 -0
  208. package/app/apps/github/src/pulls/pull-list.tsx +235 -0
  209. package/app/apps/github/src/pulls/pull-page.tsx +474 -0
  210. package/app/apps/github/src/pulls/pull.ts +468 -0
  211. package/app/apps/github/src/pulls/pulls.ts +318 -0
  212. package/app/apps/github/src/pulls/review.ts +350 -0
  213. package/app/apps/github/src/pulls/search.ts +130 -0
  214. package/app/apps/github/src/queue/queue-page.tsx +405 -0
  215. package/app/apps/github/src/queue/queue.ts +231 -0
  216. package/app/apps/github/src/releases/latest-release.tsx +55 -0
  217. package/app/apps/github/src/releases/overview.tsx +30 -0
  218. package/app/apps/github/src/releases/release-form.tsx +353 -0
  219. package/app/apps/github/src/releases/release-list.tsx +173 -0
  220. package/app/apps/github/src/releases/release-view.tsx +183 -0
  221. package/app/apps/github/src/releases/releases.ts +308 -0
  222. package/app/apps/github/src/releases/tag-list.tsx +134 -0
  223. package/app/apps/github/src/router.tsx +46 -0
  224. package/app/apps/github/src/routes/$owner/$repo/_code/blob/$.tsx +33 -0
  225. package/app/apps/github/src/routes/$owner/$repo/_code/tree/$.tsx +28 -0
  226. package/app/apps/github/src/routes/$owner/$repo/_code.tsx +11 -0
  227. package/app/apps/github/src/routes/$owner/$repo/_releases/releases/index.tsx +19 -0
  228. package/app/apps/github/src/routes/$owner/$repo/_releases/tags.tsx +19 -0
  229. package/app/apps/github/src/routes/$owner/$repo/_releases.tsx +23 -0
  230. package/app/apps/github/src/routes/$owner/$repo/branches.tsx +39 -0
  231. package/app/apps/github/src/routes/$owner/$repo/commit/$sha.tsx +34 -0
  232. package/app/apps/github/src/routes/$owner/$repo/commits/$.tsx +42 -0
  233. package/app/apps/github/src/routes/$owner/$repo/compare/$.tsx +19 -0
  234. package/app/apps/github/src/routes/$owner/$repo/index.tsx +24 -0
  235. package/app/apps/github/src/routes/$owner/$repo/issues/$number.tsx +50 -0
  236. package/app/apps/github/src/routes/$owner/$repo/issues/index.tsx +53 -0
  237. package/app/apps/github/src/routes/$owner/$repo/issues/new.tsx +43 -0
  238. package/app/apps/github/src/routes/$owner/$repo/labels.tsx +22 -0
  239. package/app/apps/github/src/routes/$owner/$repo/pull/$number/checks.tsx +15 -0
  240. package/app/apps/github/src/routes/$owner/$repo/pull/$number/commits.tsx +15 -0
  241. package/app/apps/github/src/routes/$owner/$repo/pull/$number/files.tsx +15 -0
  242. package/app/apps/github/src/routes/$owner/$repo/pull/$number/index.tsx +19 -0
  243. package/app/apps/github/src/routes/$owner/$repo/pull/$number/route.tsx +52 -0
  244. package/app/apps/github/src/routes/$owner/$repo/pulls/index.tsx +48 -0
  245. package/app/apps/github/src/routes/$owner/$repo/queue.tsx +22 -0
  246. package/app/apps/github/src/routes/$owner/$repo/releases/edit/$.tsx +58 -0
  247. package/app/apps/github/src/routes/$owner/$repo/releases/new.tsx +40 -0
  248. package/app/apps/github/src/routes/$owner/$repo/releases/tag/$.tsx +35 -0
  249. package/app/apps/github/src/routes/$owner/$repo/route.tsx +102 -0
  250. package/app/apps/github/src/routes/$owner/$repo/settings/access.tsx +9 -0
  251. package/app/apps/github/src/routes/$owner/$repo/settings/hooks/index.tsx +16 -0
  252. package/app/apps/github/src/routes/$owner/$repo/settings/hooks/new.tsx +25 -0
  253. package/app/apps/github/src/routes/$owner/$repo/settings/index.tsx +17 -0
  254. package/app/apps/github/src/routes/$owner/$repo/settings/route.tsx +28 -0
  255. package/app/apps/github/src/routes/$owner/$repo/settings/rules.tsx +12 -0
  256. package/app/apps/github/src/routes/$owner/$repo/tokens.tsx +16 -0
  257. package/app/apps/github/src/routes/$owner/index.tsx +45 -0
  258. package/app/apps/github/src/routes/-nav.tsx +293 -0
  259. package/app/apps/github/src/routes/-root-testing.ts +107 -0
  260. package/app/apps/github/src/routes/__root.tsx +225 -0
  261. package/app/apps/github/src/routes/api.auth.$.ts +18 -0
  262. package/app/apps/github/src/routes/downloads/$owner/$repo/$asset.tsx +10 -0
  263. package/app/apps/github/src/routes/file-icons[.]svg.ts +21 -0
  264. package/app/apps/github/src/routes/icons/$owner/$repo.tsx +14 -0
  265. package/app/apps/github/src/routes/icons/$owner/index.tsx +14 -0
  266. package/app/apps/github/src/routes/icons/index.tsx +12 -0
  267. package/app/apps/github/src/routes/index.tsx +48 -0
  268. package/app/apps/github/src/routes/login.tsx +24 -0
  269. package/app/apps/github/src/routes/login_.code.tsx +31 -0
  270. package/app/apps/github/src/routes/new.tsx +91 -0
  271. package/app/apps/github/src/routes/notifications.tsx +20 -0
  272. package/app/apps/github/src/routes/orgs/$owner/issues.tsx +8 -0
  273. package/app/apps/github/src/routes/orgs/$owner/pulls.tsx +8 -0
  274. package/app/apps/github/src/routes/orgs/$owner/releases.tsx +8 -0
  275. package/app/apps/github/src/routes/orgs/$owner/route.tsx +25 -0
  276. package/app/apps/github/src/routes/orgs/$owner/settings.tsx +30 -0
  277. package/app/apps/github/src/routes/orgs/$owner/tokens.tsx +15 -0
  278. package/app/apps/github/src/routes/settings.tsx +54 -0
  279. package/app/apps/github/src/routes/signup.tsx +24 -0
  280. package/app/apps/github/src/routes/uploads/$owner/$repo/$release.tsx +10 -0
  281. package/app/apps/github/src/seed/acme.ts +498 -0
  282. package/app/apps/github/src/seed/licenses.ts +114 -0
  283. package/app/apps/github/src/seed/seed.ts +528 -0
  284. package/app/apps/github/src/server.ts +97 -0
  285. package/app/apps/github/src/settings/account-avatar.tsx +43 -0
  286. package/app/apps/github/src/settings/avatar-section.tsx +140 -0
  287. package/app/apps/github/src/settings/avatar.ts +58 -0
  288. package/app/apps/github/src/settings/general-settings.tsx +439 -0
  289. package/app/apps/github/src/settings/general.ts +73 -0
  290. package/app/apps/github/src/settings/hook-form.tsx +195 -0
  291. package/app/apps/github/src/settings/hook-list.tsx +166 -0
  292. package/app/apps/github/src/settings/hooks.ts +87 -0
  293. package/app/apps/github/src/settings/org-settings.tsx +228 -0
  294. package/app/apps/github/src/settings/orgs.ts +116 -0
  295. package/app/apps/github/src/settings/rule-list.tsx +72 -0
  296. package/app/apps/github/src/settings/rules.ts +27 -0
  297. package/app/apps/github/src/settings/settings-layout.tsx +114 -0
  298. package/app/apps/github/src/signin/approval.ts +186 -0
  299. package/app/apps/github/src/signin/auth-client.ts +127 -0
  300. package/app/apps/github/src/signin/auth.ts +753 -0
  301. package/app/apps/github/src/signin/avatars.ts +126 -0
  302. package/app/apps/github/src/signin/client-ip.ts +39 -0
  303. package/app/apps/github/src/signin/credentials.ts +26 -0
  304. package/app/apps/github/src/signin/device-code.ts +95 -0
  305. package/app/apps/github/src/signin/device-prompt.ts +125 -0
  306. package/app/apps/github/src/signin/errors.ts +135 -0
  307. package/app/apps/github/src/signin/host-session.ts +68 -0
  308. package/app/apps/github/src/signin/orgs.ts +283 -0
  309. package/app/apps/github/src/signin/owner-names.ts +183 -0
  310. package/app/apps/github/src/signin/person-lock.ts +104 -0
  311. package/app/apps/github/src/signin/seal.ts +88 -0
  312. package/app/apps/github/src/signin/seed-people.ts +92 -0
  313. package/app/apps/github/src/signin/session.ts +48 -0
  314. package/app/apps/github/src/signin/unborn.ts +110 -0
  315. package/app/apps/github/src/signin/viewer-orgs.ts +47 -0
  316. package/app/apps/github/src/signin/viewer.ts +74 -0
  317. package/app/apps/github/src/signin/with-headers.ts +14 -0
  318. package/app/apps/github/src/tokens/tokens-page.tsx +529 -0
  319. package/app/apps/github/src/tokens/tokens.ts +54 -0
  320. package/app/apps/github/tsconfig.json +25 -0
  321. package/app/apps/github/tsconfig.worker.json +24 -0
  322. package/app/apps/github/vite.config.ts +21 -0
  323. package/app/pnpm-workspace.yaml +216 -0
  324. package/app/tsconfig.base.json +127 -0
  325. package/dist/LICENSE +202 -0
  326. package/dist/cli/child.mjs +42 -0
  327. package/dist/cli/commands.mjs +23 -0
  328. package/dist/cli/credentials.mjs +84 -0
  329. package/dist/cli/documents.mjs +214 -0
  330. package/dist/cli/events.mjs +55 -0
  331. package/dist/cli/failure.mjs +105 -0
  332. package/dist/cli/folders.mjs +32 -0
  333. package/dist/cli/git-remote-ref0.d.mts +1 -0
  334. package/dist/cli/git-remote-ref0.mjs +29 -0
  335. package/dist/cli/git.mjs +69 -0
  336. package/dist/cli/helpers.mjs +184 -0
  337. package/dist/cli/hosts.mjs +127 -0
  338. package/dist/cli/node.mjs +15 -0
  339. package/dist/cli/output.mjs +135 -0
  340. package/dist/cli/prompt.mjs +35 -0
  341. package/dist/cli/queue.mjs +215 -0
  342. package/dist/cli/ref0-git.d.mts +1 -0
  343. package/dist/cli/ref0-git.mjs +144 -0
  344. package/dist/cli/repos.mjs +162 -0
  345. package/dist/cli/resources.mjs +131 -0
  346. package/dist/cli/run-end.mjs +57 -0
  347. package/dist/cli/runtime.mjs +50 -0
  348. package/dist/cli/setup.mjs +1410 -0
  349. package/dist/cli/sign-in.mjs +162 -0
  350. package/dist/cli/sign-ins.mjs +136 -0
  351. package/dist/cli/sqlite.mjs +28 -0
  352. package/dist/cli/tokens.mjs +141 -0
  353. package/dist/cli/vendor.mjs +123 -0
  354. package/dist/init/app.mjs +231 -0
  355. package/dist/init/astro.mjs +49 -0
  356. package/dist/init/choices.mjs +497 -0
  357. package/dist/init/cloudflare.mjs +324 -0
  358. package/dist/init/create.mjs +151 -0
  359. package/dist/init/detect.mjs +297 -0
  360. package/dist/init/files.mjs +80 -0
  361. package/dist/init/frameworks.mjs +248 -0
  362. package/dist/init/git-module.mjs +49 -0
  363. package/dist/init/github-routes.mjs +66 -0
  364. package/dist/init/jsonc.mjs +143 -0
  365. package/dist/init/metadata.mjs +48 -0
  366. package/dist/init/mounts.mjs +109 -0
  367. package/dist/init/next.mjs +203 -0
  368. package/dist/init/node-app.mjs +189 -0
  369. package/dist/init/node.mjs +460 -0
  370. package/dist/init/nuxt.mjs +115 -0
  371. package/dist/init/output.mjs +21 -0
  372. package/dist/init/plan.mjs +82 -0
  373. package/dist/init/range-major.mjs +257 -0
  374. package/dist/init/react-router.mjs +59 -0
  375. package/dist/init/routes.mjs +148 -0
  376. package/dist/init/shell.mjs +4 -0
  377. package/dist/init/stores.mjs +51 -0
  378. package/dist/init/sveltekit.mjs +139 -0
  379. package/dist/init/template.mjs +142 -0
  380. package/dist/init/templates.mjs +343 -0
  381. package/dist/init/vercel.mjs +384 -0
  382. package/dist/init/versions.mjs +32 -0
  383. package/dist/init/workspace.mjs +20 -0
  384. package/package.json +48 -6
  385. package/README.md +0 -5
@@ -0,0 +1,126 @@
1
+ import type { BetterAuthPlugin, DBAdapter } from 'better-auth';
2
+
3
+ import type { AvatarKind, Avatars, StoredIcon } from '../context/context.ts';
4
+
5
+ /**
6
+ * Avatars in `AUTH_DB`, the app's only database, which it reaches through Better Auth's adapter,
7
+ * as `owner_names` does: a person's, an org's and a repo's picture in one table, each under an ID a
8
+ * rename keeps (Q757). Better Auth keys a row by one `id`, so a row's is its kind and its owner's
9
+ * ID together, `repo:42` or `user:u-pip`, and its kind is a column too.
10
+ */
11
+
12
+ /** Better Auth's model for the avatars, and the table it keeps them in. */
13
+ const model = 'avatar';
14
+
15
+ /**
16
+ * The plugin that gives Better Auth's adapter `avatar`: the row's kind, the picture's sniffed type,
17
+ * its bytes as base64, their count, their SHA-256 in hex, and when it was set.
18
+ */
19
+ export const avatarTable = () =>
20
+ ({
21
+ id: 'avatars',
22
+ schema: {
23
+ [model]: {
24
+ modelName: 'avatar',
25
+ fields: {
26
+ kind: { type: 'string', required: true },
27
+ type: { type: 'string', required: true },
28
+ bytes: { type: 'string', required: true },
29
+ size: { type: 'number', required: true },
30
+ hash: { type: 'string', required: true },
31
+ updatedAt: { type: 'date', required: true },
32
+ },
33
+ },
34
+ },
35
+ }) satisfies BetterAuthPlugin;
36
+
37
+ const base64Of = (bytes: Uint8Array) => {
38
+ let text = '';
39
+
40
+ for (let at = 0; at < bytes.length; at += 0x8000) {
41
+ text += String.fromCharCode(...bytes.subarray(at, at + 0x8000));
42
+ }
43
+
44
+ return btoa(text);
45
+ };
46
+
47
+ const bytesOf = (base64: string) => Uint8Array.from(atob(base64), (char) => char.charCodeAt(0));
48
+
49
+ interface Row {
50
+ readonly type: string;
51
+ readonly bytes: string;
52
+ readonly hash: string;
53
+ }
54
+
55
+ /** The row's `id` for `kind`'s owner `id`. */
56
+ /**
57
+ * The most ids one read binds: D1 takes 100 bound parameters a query, and the read binds its
58
+ * `LIMIT` too.
59
+ */
60
+ export const idsPerRead = 99;
61
+
62
+ const rowId = (kind: AvatarKind, id: string) => `${kind}:${id}`;
63
+
64
+ const by = (kind: AvatarKind, id: string) => [{ field: 'id', value: rowId(kind, id) }];
65
+
66
+ /** The avatars over Better Auth's adapter, which `adapter` gives once its schema check settled. */
67
+ export const avatars = (adapter: () => Promise<DBAdapter>): Avatars => ({
68
+ get: async (kind, id) => {
69
+ const row = await (await adapter()).findOne<Row>({ model, where: by(kind, id) });
70
+
71
+ return row === null ? undefined : { type: row.type, bytes: bytesOf(row.bytes), hash: row.hash };
72
+ },
73
+
74
+ hash: async (kind, id) => {
75
+ const row = await (
76
+ await adapter()
77
+ ).findOne<Pick<Row, 'hash'>>({ model, where: by(kind, id), select: ['hash'] });
78
+
79
+ return row?.hash;
80
+ },
81
+
82
+ hashes: async (kind, ids) => {
83
+ const held = await adapter();
84
+ const reads = Array.from({ length: Math.ceil(ids.length / idsPerRead) }, (_, n) =>
85
+ ids.slice(n * idsPerRead, (n + 1) * idsPerRead),
86
+ );
87
+ const rows = await Promise.all(
88
+ reads.map((some) =>
89
+ held.findMany<{ readonly id: string; readonly hash: string }>({
90
+ model,
91
+ where: [{ field: 'id', operator: 'in', value: some.map((id) => rowId(kind, id)) }],
92
+ select: ['id', 'hash'],
93
+ limit: some.length,
94
+ }),
95
+ ),
96
+ );
97
+
98
+ return new Map(rows.flat().map((row) => [row.id.slice(`${kind}:`.length), row.hash]));
99
+ },
100
+
101
+ put: async (kind, id, icon: StoredIcon) => {
102
+ const held = await adapter();
103
+ const data = {
104
+ kind,
105
+ type: icon.type,
106
+ bytes: base64Of(icon.bytes),
107
+ size: icon.bytes.length,
108
+ hash: icon.hash,
109
+ updatedAt: new Date(),
110
+ };
111
+ const where = by(kind, id);
112
+ if ((await held.updateMany({ model, where, update: data })) > 0) return;
113
+
114
+ // A first picture. Two first uploads at once: the one whose insert loses updates the row
115
+ // instead, and an insert that failed for any other reason, with no row to update, fails it.
116
+ try {
117
+ await held.create({ model, data: { id: rowId(kind, id), ...data }, forceAllowId: true });
118
+ } catch (error) {
119
+ if ((await held.updateMany({ model, where, update: data })) === 0) throw error;
120
+ }
121
+ },
122
+
123
+ remove: async (kind, id) => {
124
+ await (await adapter()).deleteMany({ model, where: by(kind, id) });
125
+ },
126
+ });
@@ -0,0 +1,39 @@
1
+ import { withHeaders } from './with-headers.ts';
2
+
3
+ /**
4
+ * The caller's address for Better Auth's rate limit, on a server that isn't Cloudflare's. Better
5
+ * Auth keys each limit on the address a header names, and any caller can send any header, so the
6
+ * server sets its own, `clientIpHeader`, on every request, after dropping every copy the caller
7
+ * sent. On Cloudflare, `cf-connecting-ip` is Cloudflare's own, and this isn't used.
8
+ */
9
+
10
+ /** The header the server sets with the caller's address, which `starterAuth` reads on Node. */
11
+ export const clientIpHeader = 'x-ref0-client-ip';
12
+
13
+ /** A request as srvx gives it to the app on Node: `ip` is its socket's remote address. */
14
+ interface Located {
15
+ readonly ip?: string | undefined;
16
+ }
17
+
18
+ /** The address `proxyHeader`'s value names: `x-forwarded-for`'s rightmost, which the host's own proxy appended. */
19
+ const proxied = (proxyHeader: string, value: string) =>
20
+ (proxyHeader === 'x-forwarded-for' ? (value.split(',').at(-1) ?? '') : value).trim();
21
+
22
+ /**
23
+ * `incoming` with the caller's address in `clientIpHeader`, and none the caller sent there. It's
24
+ * the socket's address, unless `proxyHeader` names the header the proxy in front sets, such as
25
+ * `x-real-ip`, which only a proxy that overwrites it makes trustworthy. A request whose proxy
26
+ * header is missing or empty keeps the socket's address, the proxy's own.
27
+ */
28
+ export const withClientIp = (incoming: Request & Located, proxyHeader: string | undefined) => {
29
+ const headers = new Headers(incoming.headers);
30
+ headers.delete(clientIpHeader);
31
+
32
+ const named =
33
+ proxyHeader === undefined || proxyHeader === '' ? undefined : proxyHeader.toLowerCase();
34
+ const sent = named === undefined ? '' : proxied(named, incoming.headers.get(named) ?? '');
35
+ const address = sent === '' ? incoming.ip : sent;
36
+ if (address !== undefined && address !== '') headers.set(clientIpHeader, address);
37
+
38
+ return withHeaders(incoming, headers);
39
+ };
@@ -0,0 +1,26 @@
1
+ import { sql } from 'kysely';
2
+
3
+ import type { AuthDatabase } from './auth.ts';
4
+ import { withPersonLocked } from './person-lock.ts';
5
+
6
+ /** A passkey of a person's, by its row's ID. */
7
+ export interface PasskeyOf {
8
+ readonly userId: string;
9
+ readonly id: string;
10
+ }
11
+
12
+ /**
13
+ * Deletes a person's passkey unless it's the last thing that signs them in, and answers whether
14
+ * it did: another passkey or a password must stay, since the hidden email reaches no one. It's
15
+ * one statement under `withPersonLocked`, so two deletes of a person's last two passkeys at once
16
+ * can't both find the other still there.
17
+ */
18
+ export const deleteUnlessLast = (database: AuthDatabase, passkey: PasskeyOf) =>
19
+ withPersonLocked(database, passkey.userId, async (write) => {
20
+ const { userId, id } = passkey;
21
+ const deleted = await write(
22
+ sql`delete from "passkey" where "id" = ${id} and "userId" = ${userId} and (exists (select 1 from "passkey" where "userId" = ${userId} and "id" <> ${id}) or exists (select 1 from "account" where "userId" = ${userId} and "providerId" = 'credential'))`,
23
+ );
24
+
25
+ return deleted > 0;
26
+ });
@@ -0,0 +1,95 @@
1
+ import { createServerFn } from '@tanstack/react-start';
2
+ import { getRequest } from '@tanstack/react-start/server';
3
+ import { flow } from 'effect/Function';
4
+ import * as Option from 'effect/Option';
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ import { clientLabel, openPrompt, openRetry } from './device-prompt.ts';
8
+
9
+ /**
10
+ * What `/login/code`'s Card shows: the Code field, with any error under it; the confirm, with a
11
+ * device's client, the person it would act as, its code, its scopes and the sealed prompt its
12
+ * Approve and Deny post back; or what was decided, with no form.
13
+ */
14
+ export type DeviceCardState =
15
+ | {
16
+ readonly kind: 'enter';
17
+ readonly error?: string;
18
+ /** What was typed, kept after an error: only from a `retry` sealed for this session. */
19
+ readonly userCode?: string;
20
+ }
21
+ | {
22
+ readonly kind: 'confirm';
23
+ /** Who's asking, named only as far as the client ID proves: see `clientLabel`. */
24
+ readonly client: string;
25
+ readonly login: string;
26
+ readonly userCode: string;
27
+ /** What Approve grants: write to every repo `login` may write, for this many days. */
28
+ readonly days: number;
29
+ /** The scopes the device asked for, which the starter doesn't narrow the grant to. */
30
+ readonly scopes: readonly string[];
31
+ /** The sealed prompt, posted back in a hidden field beside `user_code` and `decision`. */
32
+ readonly prompt: string;
33
+ }
34
+ | { readonly kind: 'done'; readonly text: string };
35
+
36
+ /** `/login/code`'s query, as Git's redirects from `/login/device` name it. */
37
+ const CodeSearch = Schema.Struct({
38
+ prompt: Schema.optional(Schema.String),
39
+ error: Schema.optional(Schema.Literals(['invalid-code', 'expired-code'])),
40
+ retry: Schema.optional(Schema.String),
41
+ done: Schema.optional(Schema.Literals(['approved', 'denied'])),
42
+ });
43
+
44
+ export type CodeSearch = typeof CodeSearch.Type;
45
+
46
+ /** `/login/code`'s query, read: one it can't read shows the Code field. */
47
+ export const codeSearch = flow(
48
+ Schema.decodeUnknownOption(CodeSearch),
49
+ Option.getOrElse((): CodeSearch => ({})),
50
+ );
51
+
52
+ const expired = 'That code has expired: start again on your device';
53
+
54
+ const errors = { 'invalid-code': 'No sign-in is waiting under that code', 'expired-code': expired };
55
+
56
+ const decided = {
57
+ approved: 'Device approved: go back to your device',
58
+ denied: 'Device denied: you can close this window',
59
+ };
60
+
61
+ /** The Card's state, read on the server, where the prompt opens: a person signed out enters a code. */
62
+ export const deviceCard = createServerFn({ method: 'GET' })
63
+ .validator(codeSearch)
64
+ .handler(async ({ context, data }): Promise<DeviceCardState> => {
65
+ if (data.done !== undefined) return { kind: 'done', text: decided[data.done] };
66
+
67
+ const session = await context.session(getRequest());
68
+
69
+ if (data.error !== undefined) {
70
+ const error = errors[data.error];
71
+ const typed =
72
+ data.retry === undefined || session === undefined
73
+ ? undefined
74
+ : await openRetry(context.sealKey, data.retry, session, Date.now());
75
+
76
+ return typed === undefined
77
+ ? { kind: 'enter', error }
78
+ : { kind: 'enter', error, userCode: typed };
79
+ }
80
+
81
+ if (data.prompt === undefined || session === undefined) return { kind: 'enter' };
82
+
83
+ const opened = await openPrompt(context.sealKey, data.prompt, session.login, Date.now());
84
+ if (opened === undefined) return { kind: 'enter', error: expired };
85
+
86
+ return {
87
+ kind: 'confirm',
88
+ client: clientLabel(opened.clientId),
89
+ login: session.login,
90
+ userCode: opened.userCode,
91
+ days: opened.days,
92
+ scopes: opened.scopes,
93
+ prompt: data.prompt,
94
+ };
95
+ });
@@ -0,0 +1,125 @@
1
+ import type { DeviceApproval } from '@ref0/git';
2
+ import { ghClientId } from '@ref0/git/auth';
3
+ import * as Option from 'effect/Option';
4
+ import * as Schema from 'effect/Schema';
5
+
6
+ import { open, seal } from './seal.ts';
7
+
8
+ /**
9
+ * A device's prompt, as `/login/code` shows it: what Git's record of the user code says, sealed so
10
+ * a hand-made URL can't name another client or other scopes; for the person whose browser typed the
11
+ * code, so a link that names it shows no one else; and for 10 minutes, so an old page's Approve
12
+ * decides nothing.
13
+ */
14
+ const Prompt = Schema.Struct({
15
+ login: Schema.String,
16
+ clientId: Schema.String,
17
+ scopes: Schema.Array(Schema.String),
18
+ userCode: Schema.String,
19
+ expiresAt: Schema.Number,
20
+ /** How long a token Approve mints lasts, which the Card says. */
21
+ days: Schema.Number,
22
+ until: Schema.Number,
23
+ });
24
+
25
+ export type OpenedPrompt = typeof Prompt.Type;
26
+
27
+ const encodePrompt = Schema.encodeSync(Schema.fromJsonString(Prompt));
28
+
29
+ const decodePrompt = Schema.decodeUnknownOption(Schema.fromJsonString(Prompt));
30
+
31
+ const purpose = 'device-prompt';
32
+
33
+ /** How long a sealed prompt holds. */
34
+ const promptLife = 10 * 60 * 1000;
35
+
36
+ /** What Approve would grant: write as `login`, over every repo they may write, for `days`. */
37
+ export interface Grant {
38
+ readonly login: string;
39
+ readonly days: number;
40
+ }
41
+
42
+ /** Git's prompt, with what Approve would grant, sealed until 10 minutes from `now`. */
43
+ export const sealPrompt = (key: CryptoKey, prompt: DeviceApproval, grant: Grant, now: number) => {
44
+ const { clientId, scopes, userCode, expiresAt } = prompt;
45
+ const { login, days } = grant;
46
+ const until = now + promptLife;
47
+
48
+ return seal(
49
+ key,
50
+ purpose,
51
+ encodePrompt({ login, clientId, scopes, userCode, expiresAt, days, until }),
52
+ );
53
+ };
54
+
55
+ /**
56
+ * The prompt `text` seals for `login`, or `undefined` for one that doesn't open, was sealed for
57
+ * someone else, or is past its 10 minutes.
58
+ */
59
+ export const openPrompt = async (
60
+ key: CryptoKey,
61
+ text: string,
62
+ login: string,
63
+ now: number,
64
+ ): Promise<OpenedPrompt | undefined> => {
65
+ const opened = await open(key, purpose, text);
66
+ const prompt = opened === undefined ? undefined : Option.getOrUndefined(decodePrompt(opened));
67
+
68
+ return prompt?.login === login && now < prompt.until ? prompt : undefined;
69
+ };
70
+
71
+ /**
72
+ * Whose Code field a typed code fills again: the session's login, and its Git token's ID, which that
73
+ * session alone holds, since each sign-in mints its own.
74
+ */
75
+ export interface Typist {
76
+ readonly login: string;
77
+ readonly tokenId: string;
78
+ }
79
+
80
+ /**
81
+ * A code the person typed that Git found no sign-in under, sealed for the Code field to show again:
82
+ * sealed for the session that typed it, so a link that carries it fills no one else's field.
83
+ */
84
+ const Retry = Schema.Struct({
85
+ login: Schema.String,
86
+ tokenId: Schema.String,
87
+ userCode: Schema.String,
88
+ until: Schema.Number,
89
+ });
90
+
91
+ const encodeRetry = Schema.encodeSync(Schema.fromJsonString(Retry));
92
+
93
+ const decodeRetry = Schema.decodeUnknownOption(Schema.fromJsonString(Retry));
94
+
95
+ const retryPurpose = 'device-retry';
96
+
97
+ /** The code `typist` typed, sealed for their session until 10 minutes from `now`. */
98
+ export const sealRetry = (key: CryptoKey, userCode: string, typist: Typist, now: number) => {
99
+ const { login, tokenId } = typist;
100
+
101
+ return seal(
102
+ key,
103
+ retryPurpose,
104
+ encodeRetry({ login, tokenId, userCode, until: now + promptLife }),
105
+ );
106
+ };
107
+
108
+ /**
109
+ * The typed code `text` seals for `typist`'s session, or `undefined` for one that doesn't open, was
110
+ * typed in another session, or is past its 10 minutes.
111
+ */
112
+ export const openRetry = async (key: CryptoKey, text: string, typist: Typist, now: number) => {
113
+ const opened = await open(key, retryPurpose, text);
114
+ const retry = opened === undefined ? undefined : Option.getOrUndefined(decodeRetry(opened));
115
+ const theirs = retry?.login === typist.login && retry.tokenId === typist.tokenId;
116
+
117
+ return theirs && now < retry.until ? retry.userCode : undefined;
118
+ };
119
+
120
+ /**
121
+ * The client a prompt names, as the Card shows it: `gh` and `ref0-git login` send the same client
122
+ * ID, so it names both, and any other client shows its raw ID (GHSA-q84f).
123
+ */
124
+ export const clientLabel = (clientId: string) =>
125
+ clientId === ghClientId ? 'GitHub CLI or ref0-git' : clientId;
@@ -0,0 +1,135 @@
1
+ /** Better Auth's error code for a login no person may take: one of `reservedOwners`. */
2
+ export const reservedCode = 'LOGIN_RESERVED';
3
+
4
+ /** Better Auth's error code for deleting the passkey a person with no password signs in with. */
5
+ export const lastCredentialCode = 'LAST_CREDENTIAL';
6
+
7
+ /** Better Auth's error code for a passkey sign-up on a host that set `SIGN_UP=closed`. */
8
+ export const closedCode = 'SIGN_UP_CLOSED';
9
+
10
+ /** Better Auth's answer to a refused sign-up or sign-in, as its client hands it back. */
11
+ export interface AuthRefusal {
12
+ readonly status: number;
13
+ readonly code?: string | undefined;
14
+ readonly message?: string | undefined;
15
+ }
16
+
17
+ /** Where a refusal's text shows: under a field, above the passkey button, or above the form. */
18
+ export type RefusalPlace = 'login' | 'password' | 'passkey' | 'form';
19
+
20
+ /** A refusal's text, and where it shows. */
21
+ export interface RefusalText {
22
+ readonly place: RefusalPlace;
23
+ readonly text: string;
24
+ }
25
+
26
+ const pattern = 'Use letters, digits and single hyphens, up to 39, not starting or ending with one';
27
+
28
+ const tooMany = {
29
+ place: 'form',
30
+ text: 'Too many tries: wait a few seconds and try again',
31
+ } as const;
32
+
33
+ const otherwise = { place: 'form', text: 'Something went wrong: try again' } as const;
34
+
35
+ /** Sign-up's text for Better Auth's `code`. */
36
+ const signUpText = (code: string | undefined): RefusalText => {
37
+ switch (code) {
38
+ case 'INVALID_USERNAME':
39
+ case 'USERNAME_TOO_SHORT':
40
+ case 'USERNAME_TOO_LONG':
41
+ return { place: 'login', text: pattern };
42
+ // The hidden email is the login's, so a taken email is a taken login.
43
+ case 'USERNAME_IS_ALREADY_TAKEN':
44
+ case 'USER_ALREADY_EXISTS':
45
+ case 'USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL':
46
+ return { place: 'login', text: 'That username is taken' };
47
+ case 'PASSWORD_TOO_SHORT':
48
+ return { place: 'password', text: 'Use at least 15 characters' };
49
+ case 'PASSWORD_TOO_LONG':
50
+ return { place: 'password', text: 'Use at most 256 characters' };
51
+ case 'EMAIL_PASSWORD_SIGN_UP_DISABLED':
52
+ case closedCode:
53
+ return { place: 'form', text: 'Sign-up is closed on this host' };
54
+ default:
55
+ return otherwise;
56
+ }
57
+ };
58
+
59
+ /** Sign-in's one text for every refusal of the login or password, so it never says which. */
60
+ const noMatch = { place: 'form', text: "That username and password don't match" } as const;
61
+
62
+ /** What the sign-up page shows for `refusal`. */
63
+ export const signUpRefusal = (refusal: AuthRefusal): RefusalText => {
64
+ if (refusal.status === 429) return tooMany;
65
+
66
+ if (refusal.code === reservedCode) {
67
+ return { place: 'login', text: refusal.message ?? 'That username is reserved' };
68
+ }
69
+
70
+ return signUpText(refusal.code);
71
+ };
72
+
73
+ /** What the sign-in page shows for `refusal`. */
74
+ export const signInRefusal = (refusal: AuthRefusal): RefusalText => {
75
+ if (refusal.status === 429) return tooMany;
76
+
77
+ return refusal.status === 401 || refusal.status === 422 || refusal.status === 400
78
+ ? noMatch
79
+ : otherwise;
80
+ };
81
+
82
+ /** Sign-up's text for a passkey not saved: the browser's cancel, or the server's refusal of it. */
83
+ const passkeyNotSaved = {
84
+ place: 'passkey',
85
+ text: "The passkey wasn't saved: try again, or use a password",
86
+ } as const;
87
+
88
+ /**
89
+ * What the sign-up page shows for a refused passkey sign-up: the login's and the host's refusals as
90
+ * a password sign-up shows them, and any other as the passkey not saved.
91
+ */
92
+ export const passkeySignUpRefusal = (refusal: AuthRefusal): RefusalText => {
93
+ const text = signUpRefusal(refusal);
94
+
95
+ return text === otherwise ? passkeyNotSaved : text;
96
+ };
97
+
98
+ /** What the sign-in page shows for a refused passkey, whichever the browser or the server refused. */
99
+ export const passkeySignInRefusal = (refusal: AuthRefusal): RefusalText =>
100
+ refusal.status === 429 ? tooMany : { place: 'form', text: "That passkey didn't sign you in" };
101
+
102
+ /** What the passkeys' settings show when adding or removing one is refused. */
103
+ export const passkeySettingsRefusal = (refusal: AuthRefusal): RefusalText => {
104
+ if (refusal.status === 429) return tooMany;
105
+
106
+ switch (refusal.code) {
107
+ case 'SESSION_NOT_FRESH':
108
+ return { place: 'form', text: 'Sign in again to add a passkey' };
109
+ case lastCredentialCode:
110
+ return {
111
+ place: 'form',
112
+ text: 'Add another passkey or a password before you remove this one',
113
+ };
114
+ default:
115
+ return otherwise;
116
+ }
117
+ };
118
+
119
+ /** What the Create organization form shows for `refusal`, under its one field. */
120
+ export const createOrgRefusal = (refusal: AuthRefusal): string => {
121
+ if (refusal.status === 429) return tooMany.text;
122
+
123
+ switch (refusal.code) {
124
+ case reservedCode:
125
+ case 'INVALID_SLUG':
126
+ return refusal.message ?? pattern;
127
+ case 'ORGANIZATION_ALREADY_EXISTS':
128
+ case 'ORGANIZATION_SLUG_ALREADY_TAKEN':
129
+ return 'That name is taken';
130
+ case 'YOU_HAVE_REACHED_THE_MAXIMUM_NUMBER_OF_ORGANIZATIONS':
131
+ return 'You have as many organizations as this host allows';
132
+ default:
133
+ return otherwise.text;
134
+ }
135
+ };
@@ -0,0 +1,68 @@
1
+ import type { GitAuth, NamedActor } from '@ref0/git';
2
+ import { bearer } from '@ref0/git/auth';
3
+ import * as Option from 'effect/Option';
4
+ import * as Schema from 'effect/Schema';
5
+
6
+ import { loginProblem } from '../names/owners.ts';
7
+ import { open, seal } from './seal.ts';
8
+ import { withHeaders } from './with-headers.ts';
9
+
10
+ /**
11
+ * The header a host call carries its signed-in person in (Q520). Only the app's server sets it, on
12
+ * a request it hands the drop-in or Git in this Worker; `server.ts` strips it from every request
13
+ * that comes in, before any routing, so no browser or client can send one.
14
+ */
15
+ export const hostSessionHeader = 'x-ref0-host-session';
16
+
17
+ const purpose = 'host-session';
18
+
19
+ /** How long a host session's seal opens: one call's time, never the session's. */
20
+ const lifetime = 60_000;
21
+
22
+ const HostSession = Schema.Struct({ login: Schema.String, expiresAt: Schema.Number });
23
+
24
+ const hostSessionOf = Schema.decodeUnknownOption(Schema.fromJsonString(HostSession));
25
+
26
+ /** `request` with no host session on it: what the Worker serves, whoever sent it. */
27
+ export const withoutHostSession = (request: Request): Request => {
28
+ if (!request.headers.has(hostSessionHeader)) return request;
29
+
30
+ const headers = new Headers(request.headers);
31
+ headers.delete(hostSessionHeader);
32
+
33
+ return withHeaders(request, headers);
34
+ };
35
+
36
+ /** The header's value for `login`, sealed under the session key, which opens for a minute. */
37
+ export const hostSessionFor = (key: CryptoKey, login: string): Promise<string> =>
38
+ seal(key, purpose, JSON.stringify({ login, expiresAt: Date.now() + lifetime }));
39
+
40
+ /**
41
+ * Git's `auth` for the app: the admin's bearer secret, or, on a request with no credential, a
42
+ * host session the app's server sealed, as its person, when its login is one. It never reads
43
+ * Better Auth's cookie, so a browser's session acts only through its capped Git token (Q520). Git's own tokens never reach it: Git reads
44
+ * them first, and a token's holder stays capped by its scope.
45
+ */
46
+ export const appAuth = (options: {
47
+ readonly adminToken: string;
48
+ readonly admin: NamedActor;
49
+ readonly key: Promise<CryptoKey>;
50
+ }): GitAuth => {
51
+ const asAdmin = bearer({ token: options.adminToken, actor: options.admin });
52
+
53
+ return async (input) => {
54
+ if (input.credentials !== undefined) return asAdmin(input);
55
+
56
+ const text = input.request.headers.get(hostSessionHeader);
57
+ if (text === null) return undefined;
58
+
59
+ const opened = await open(await options.key, purpose, text);
60
+ const session = opened === undefined ? Option.none() : hostSessionOf(opened);
61
+ if (Option.isNone(session) || session.value.expiresAt <= Date.now()) return undefined;
62
+
63
+ // A person's ID is their login, never the admin's `_admin`, however the session was made.
64
+ const login = session.value.login;
65
+
66
+ return loginProblem(login) === undefined ? { id: login } : undefined;
67
+ };
68
+ };