ref0-git 0.0.0 → 0.2.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 +122 -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 +547 -0
  197. package/app/apps/github/src/palette/recent.ts +116 -0
  198. package/app/apps/github/src/palette/rows.tsx +455 -0
  199. package/app/apps/github/src/palette/server.ts +104 -0
  200. package/app/apps/github/src/palette/targets.ts +306 -0
  201. package/app/apps/github/src/policy.ts +600 -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 +538 -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 +48 -0
  336. package/dist/cli/helpers.mjs +51 -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 +79 -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 +75 -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 +205 -0
  368. package/dist/init/node-app.mjs +189 -0
  369. package/dist/init/node.mjs +458 -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 +383 -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,600 @@
1
+ import { accept, refs, reject } from '@ref0/git';
2
+ import type {
3
+ ActorId,
4
+ AuthorizeInput,
5
+ GitAuthorize,
6
+ NamedActor,
7
+ PushRule,
8
+ RefName,
9
+ RepoId,
10
+ TokenInfo,
11
+ TokenOperation,
12
+ } from '@ref0/git';
13
+ import { defaultOrg, defaultPeople } from '@ref0/github';
14
+ import type {
15
+ GitHubAuthorization,
16
+ GitHubAuthorize,
17
+ GitHubOrg,
18
+ GitHubReadableRepos,
19
+ GitHubReadableReposInput,
20
+ GitHubTeam,
21
+ GitHubUser,
22
+ PeopleAnswer,
23
+ PeopleFor,
24
+ PeopleInput,
25
+ PeopleMembers,
26
+ PeopleMembership,
27
+ PeopleOrg,
28
+ PeopleSearch,
29
+ PeopleSearchAnswer,
30
+ PeopleTeam,
31
+ PeopleTeamMembers,
32
+ PeopleTeams,
33
+ PeopleUser,
34
+ PeopleViewer,
35
+ } from '@ref0/github';
36
+
37
+ import { type StarterApprovalOptions, starterApprovalPage } from './signin/approval.ts';
38
+ import type { Account, Avatars, Membership } from './context/context.ts';
39
+ import { admin } from './names/owners.ts';
40
+
41
+ export { admin };
42
+
43
+ import { orgTokenView, type Orgs } from './signin/orgs.ts';
44
+
45
+ /**
46
+ * The host's say, as a starter writes it: anyone reads a public repo, a person signed in owns the
47
+ * repos under their login and their orgs', and the admin makes repos and tokens but never pushes.
48
+ */
49
+
50
+ /** How long a sign-in lasts before the person signs in again. */
51
+ export const tokenDays = 30;
52
+
53
+ const ownerOf = (repo: RepoId) => repo.split('/', 1)[0];
54
+
55
+ /** A page of one of the directory's lists, as `People` answers one. */
56
+ interface Listed<Item> {
57
+ readonly items: Item[];
58
+ readonly next?: string;
59
+ }
60
+
61
+ /** A membership the policy read, and when: `Date.now()`'s. */
62
+ interface KeptMembership {
63
+ readonly at: number;
64
+ readonly answer: Promise<Membership | undefined>;
65
+ }
66
+
67
+ /**
68
+ * How long, in milliseconds, a membership read is kept on its actor: past one request's reads, and
69
+ * well under a stream's 9-second heartbeat, whose check then reads it again.
70
+ */
71
+ const membershipLife = 1_000;
72
+
73
+ /** What a people lookup answers a token that no longer holds: no one, and nothing listed. */
74
+ const refusedLookup = (input: PeopleInput): PeopleAnswer => {
75
+ switch (input.kind) {
76
+ case 'orgs':
77
+ case 'members':
78
+ case 'teams':
79
+ case 'team-members':
80
+ return { items: [] };
81
+ case 'membership':
82
+ return [];
83
+ case 'search':
84
+ return { found: [], incomplete: false };
85
+ default:
86
+ return undefined;
87
+ }
88
+ };
89
+
90
+ /** The orgs' list a directory answers, which the drop-in doesn't name apart. */
91
+ type PeopleOrgs = Extract<PeopleInput, { readonly kind: 'orgs' }>;
92
+
93
+ /** How many of an org's members, or of a person's orgs, a page lists when it names no `per_page`. */
94
+ const listedEach = 30;
95
+
96
+ /**
97
+ * Whether a token's coverage reaches into `org`: every repo, a prefix over or under the org's, or
98
+ * one of its repos (Q106). A host sign-in carries no token, and reaches every org.
99
+ */
100
+ const reaches = (input: PeopleOrgs, org: string) => {
101
+ const { token } = input;
102
+ if (token === undefined) return true;
103
+
104
+ const under = `${org}/`;
105
+ if (token.repo !== undefined) return token.repo.startsWith(under);
106
+
107
+ return under.startsWith(token.prefix) || token.prefix.startsWith(under);
108
+ };
109
+
110
+ /** What anyone signed in may do on a public repo they don't own, as on GitHub. */
111
+ const contributions: ReadonlySet<string> = new Set([
112
+ 'issue.create',
113
+ 'issue.comment',
114
+ 'comment.create',
115
+ 'pull.create',
116
+ 'pull.review',
117
+ 'review.create',
118
+ ]);
119
+
120
+ const signInFirst = reject({ message: 'Sign in first' });
121
+
122
+ /**
123
+ * The owner a token reaches past its subject's own login, if any: a repo token's repo's owner, by
124
+ * the repo's live name, or a prefix token's first segment. A session's token, over `prefix: ''`,
125
+ * names none.
126
+ */
127
+ const tokenOwner = (token: TokenInfo) => {
128
+ if (token.repo !== undefined) return ownerOf(token.repo);
129
+
130
+ const owner = token.prefix.split('/', 1)[0];
131
+
132
+ return owner === '' ? undefined : owner;
133
+ };
134
+
135
+ /**
136
+ * The org a token operation's coverage is over, as a member may hold one: all its repos, `<org>/`,
137
+ * or one of them, `<org>/<name>`. A deeper prefix, such as `acme/x/` or `acme//`, names none (Q740).
138
+ */
139
+ const orgCoverage = (operation: TokenOperation) => {
140
+ if (operation.repo !== undefined) return ownerOf(operation.repo);
141
+
142
+ if (!operation.prefix.endsWith('/')) return undefined;
143
+
144
+ const org = operation.prefix.slice(0, -1);
145
+
146
+ return org !== '' && !org.includes('/') ? org : undefined;
147
+ };
148
+
149
+ /** Who a call's token holds for, a token's caller or the host's own sign-in. */
150
+ interface Holder {
151
+ readonly actor: AuthorizeInput['actor'];
152
+ readonly subject?: ActorId;
153
+ readonly token?: TokenInfo;
154
+ }
155
+
156
+ /**
157
+ * The refusal of a token whose person left the org it's over, or joined it again after it was
158
+ * made: it works for nothing, public reads included, as GitHub's inactive token (Q740).
159
+ */
160
+ const tokenEnded = reject({ message: "This token's person no longer holds the org it's over" });
161
+
162
+ /** The host's policy and directory, the drop-in's and Git's, over its people and orgs. */
163
+ export interface HostPolicy {
164
+ readonly authorize: GitAuthorize;
165
+ readonly authorizeGitHub: GitHubAuthorize;
166
+ readonly people: PeopleFor;
167
+ readonly readableRepos: GitHubReadableRepos;
168
+ }
169
+
170
+ /**
171
+ * At most `most` of the private repos under `prefix`, and whether it holds more past them, listed
172
+ * through `host`, the drop-in's unchecked `repos.list` (Q788).
173
+ */
174
+ export type PrivateRepos = (
175
+ prefix: string,
176
+ most: number,
177
+ host: GitHubReadableReposInput['host'],
178
+ ) => Promise<{ readonly names: readonly RepoId[]; readonly more: boolean }>;
179
+
180
+ /**
181
+ * Where the drop-in's people find an uploaded picture (Q757): the app's origin, whose
182
+ * `/icons/{login}` route serves it, and the avatars' hashes, which each URL carries as `v`.
183
+ */
184
+ export interface Pictures {
185
+ readonly origin: string;
186
+ readonly avatars: Pick<Avatars, 'hash'>;
187
+ }
188
+
189
+ /**
190
+ * What the starter's policy reads past its orgs: its `Pictures`, both or neither, and
191
+ * `privateRepos`, which lists an owner's private repos for the owner index's hook. With none, it
192
+ * names no private repo.
193
+ */
194
+ export type HostPolicyOptions = (
195
+ | Pictures
196
+ | { readonly origin?: undefined; readonly avatars?: undefined }
197
+ ) & { readonly privateRepos?: PrivateRepos };
198
+
199
+ /**
200
+ * What of `owner`'s repos `token` covers: every one, those under the token's longer prefix, its
201
+ * one repo, or none.
202
+ */
203
+ const coverOf = (owner: string, token: GitHubReadableReposInput['token']) => {
204
+ const under = `${owner}/`;
205
+ if (token === undefined) return { prefix: under };
206
+
207
+ if (token.repo !== undefined)
208
+ return token.repo.startsWith(under) ? { repo: token.repo } : undefined;
209
+
210
+ if (under.startsWith(token.prefix)) return { prefix: under };
211
+
212
+ return token.prefix.startsWith(under) ? { prefix: token.prefix } : undefined;
213
+ };
214
+
215
+ /**
216
+ * The starter's policy over `orgs`: who owns what, by an org's `member` rows, and the drop-in's
217
+ * directory of people and orgs, by Better Auth's tables, with what `options` adds.
218
+ */
219
+ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPolicy => {
220
+ const { origin, avatars, privateRepos = async () => ({ names: [], more: false }) } = options;
221
+
222
+ /**
223
+ * The `avatar_url` of `login`, held by `account`, when it has an upload: the app's route, by its
224
+ * hash, so a new upload is a new URL. With none, the drop-in's default stays.
225
+ */
226
+ const pictureOf = async (login: string, account: Account | undefined) => {
227
+ if (origin === undefined || avatars === undefined || account === undefined) return {};
228
+
229
+ const hash = await avatars.hash(account.kind, account.id);
230
+ if (hash === undefined) return {};
231
+
232
+ return { avatar_url: `${origin}/icons/${encodeURIComponent(login)}?v=${hash}` };
233
+ };
234
+
235
+ /** An org as `defaultOrg` makes it, with its upload's `avatar_url` when it has one. */
236
+ const orgOf = async (login: string): Promise<GitHubOrg> => ({
237
+ ...(await defaultOrg(login)),
238
+ ...(await pictureOf(login, await orgs.account(login))),
239
+ });
240
+
241
+ /**
242
+ * Each org's membership of an actor, kept on the actor Git's `identify` made for the request, so
243
+ * a page that checks 32 of an org's repos asks D1 once (Q739), and for `membershipLife` at most.
244
+ * `identify` and `appAuth` make a new actor for each request, but a stream holds one caller for
245
+ * as long as it's open and asks `authorize` again before each batch and each heartbeat, so an
246
+ * answer kept for the request alone would let a member who left go on reading it (Q740).
247
+ */
248
+ const memberships = new WeakMap<ActorId, Map<string, KeptMembership>>();
249
+
250
+ /** `actor`'s membership of the org `org`, asked once a request, and again past its life. */
251
+ const membershipOf = (actor: ActorId, org: string) => {
252
+ const held = memberships.get(actor) ?? new Map<string, KeptMembership>();
253
+ memberships.set(actor, held);
254
+
255
+ const now = Date.now();
256
+ const kept = held.get(org);
257
+ if (kept !== undefined && now - kept.at < membershipLife) return kept.answer;
258
+
259
+ const answer = orgs.membership(org, actor.id);
260
+ held.set(org, { at: now, answer });
261
+
262
+ return answer;
263
+ };
264
+
265
+ /** Whether `actor` belongs to the org `org`, in any role. */
266
+ const belongs = async (actor: ActorId, org: string) =>
267
+ (await membershipOf(actor, org)) !== undefined;
268
+
269
+ /**
270
+ * Whether a call's token holds (Q740): one over an owner other than its subject holds only while
271
+ * the subject belongs to that owner, by a membership no newer than the token, so a leave refuses
272
+ * it at once and a rejoin doesn't bring it back. Within the second of a join, as the same
273
+ * Worker's clock reads both, a token made then holds. A session's token, the host's own sign-in
274
+ * and a token over the subject's own login hold as they are.
275
+ */
276
+ const tokenHolds = async ({ actor, subject, token }: Holder) => {
277
+ if (token === undefined || actor.anonymous === true) return true;
278
+
279
+ const person = subject !== undefined && subject.id !== actor.id ? subject : actor;
280
+ const owner = tokenOwner(token);
281
+ if (owner === undefined || owner === person.id) return true;
282
+
283
+ const membership = await membershipOf(person, owner);
284
+
285
+ return membership !== undefined && membership.since <= token.createdAt;
286
+ };
287
+
288
+ /** Whether `actor` owns what `owner` holds: their own login's, and each org's they belong to. */
289
+ const owns = async (actor: NamedActor, owner: string | undefined) =>
290
+ owner === actor.id || (owner !== undefined && (await belongs(actor, owner)));
291
+
292
+ /**
293
+ * Git's `authorize`: public repos for anyone to read and list, the rest for a repo's owner, once
294
+ * the caller's token still holds.
295
+ */
296
+ const authorize: GitAuthorize = async (input: AuthorizeInput) => {
297
+ const { actor, operation, repo } = input;
298
+ if (!(await tokenHolds(input))) return tokenEnded;
299
+
300
+ const reads = operation.kind === 'read' || operation.kind === 'fetch';
301
+ if (reads && repo?.public === true) return accept();
302
+
303
+ // Anyone lists: Git lists a caller not signed in only the public repos' own index, whose names
304
+ // the rule above lets anyone read, as GitHub lists an owner's public repos to anyone (Q791).
305
+ if (operation.kind === 'repo.list') return accept();
306
+
307
+ if (actor.anonymous === true) return signInFirst;
308
+
309
+ // A repo is made only under a login a person or an org holds, so no one's sign-up or org
310
+ // later finds repos waiting under its name.
311
+ if (operation.kind === 'repo.create') {
312
+ const owner = ownerOf(operation.repo);
313
+
314
+ if (owner === undefined || !(await orgs.held(owner))) {
315
+ return reject({ message: 'No person or org holds that owner' });
316
+ }
317
+ }
318
+
319
+ // A protected or locked ref stays so for everyone, the admin too: a rule asks this on each
320
+ // change it refuses, so accepting it would lift every rule for whoever passes.
321
+ if (operation.kind === 'protect.bypass' || operation.kind === 'lock.bypass') {
322
+ return reject({ message: 'No rule is lifted for anyone' });
323
+ }
324
+
325
+ if (actor.id === admin.id) {
326
+ return operation.kind === 'push'
327
+ ? reject({
328
+ message: "The admin token can't push",
329
+ hint: 'Sign in at /login, or make a write token for yourself: POST /repos/<repo>/-/tokens',
330
+ })
331
+ : accept();
332
+ }
333
+
334
+ // A person mints only for themselves, as no one else acts for them: a token's caller is its
335
+ // subject. The admin, above, mints for anyone.
336
+ if (
337
+ operation.kind === 'token.create' &&
338
+ (operation.subject.id !== actor.id || operation.actor !== undefined)
339
+ ) {
340
+ return reject({
341
+ message: 'Only tokens for yourself',
342
+ hint: 'The admin makes tokens for others',
343
+ });
344
+ }
345
+
346
+ if (
347
+ operation.kind === 'token.create' ||
348
+ operation.kind === 'token.list' ||
349
+ operation.kind === 'token.revoke'
350
+ ) {
351
+ return tokenRule(actor, operation);
352
+ }
353
+
354
+ // A fork lands under its holder, from any repo the person may read.
355
+ if (operation.kind === 'fork.create') {
356
+ return operation.holder === actor.id
357
+ ? accept()
358
+ : reject({ message: 'Fork under your own login' });
359
+ }
360
+
361
+ return 'repo' in operation && (await owns(actor, ownerOf(operation.repo)))
362
+ ? accept()
363
+ : reject({ message: 'Not yours' });
364
+ };
365
+
366
+ /**
367
+ * A person's token calls (Q521, Q740), the admin's being accepted above:
368
+ * - a revoke of a token whose record names them, wherever it's over, so a member always revokes
369
+ * their own;
370
+ * - a create or a list over their own login: one of their repos, or a prefix under it, but never
371
+ * a revoke of another's token there, which is theirs (Q521);
372
+ * - a create over an org they belong to at that moment: all its repos, `<org>/`, or one of
373
+ * them, never a deeper prefix;
374
+ * - a list, or a revoke of another's token, over an org they're an owner or an admin of,
375
+ * read at this call.
376
+ */
377
+ const tokenRule = async (actor: NamedActor | ActorId, operation: TokenOperation) => {
378
+ if (operation.kind === 'token.revoke' && operation.subject.id === actor.id) return accept();
379
+
380
+ const own =
381
+ operation.repo === undefined
382
+ ? operation.prefix.startsWith(`${actor.id}/`)
383
+ : ownerOf(operation.repo) === actor.id;
384
+ if (own && operation.kind !== 'token.revoke') return accept();
385
+
386
+ const org = orgCoverage(operation);
387
+ const membership = org === undefined ? undefined : await membershipOf(actor, org);
388
+
389
+ if (operation.kind === 'token.create') {
390
+ return membership === undefined
391
+ ? reject({
392
+ message: 'Only tokens over your own repos, or an org you belong to',
393
+ hint: "Over an org, a token covers all of its repos or one: '<org>/' or '<org>/<repo>'",
394
+ })
395
+ : accept();
396
+ }
397
+
398
+ return orgTokenView(membership) === 'all'
399
+ ? accept()
400
+ : reject({ message: "Only an org's owners and admins list and revoke its members' tokens" });
401
+ };
402
+
403
+ /**
404
+ * The drop-in's `authorize`: a public repo's reads for anyone, as Git's, and its contributions
405
+ * for anyone signed in, but a hook's for its owner. An org's members, teams and hooks are its
406
+ * own members' alone, as GitHub shows outsiders only public members and this host keeps none
407
+ * public (#644). A person's own account, such as their notifications, is theirs once signed in.
408
+ * Everything else is the owner's and the admin's. A token that no longer holds gets nothing, as
409
+ * in Git's, its own account included.
410
+ */
411
+ const authorizeGitHub: GitHubAuthorize = async (input: GitHubAuthorization) => {
412
+ const { actor, operation } = input;
413
+ if (!(await tokenHolds(input))) return tokenEnded;
414
+
415
+ if ('org' in operation) {
416
+ if (actor.anonymous === true) return signInFirst;
417
+
418
+ return actor.id === admin.id || (await owns(actor, operation.org))
419
+ ? accept()
420
+ : reject({ message: "Only the org's members may do this" });
421
+ }
422
+
423
+ if (!('repo' in operation)) return actor.anonymous === true ? signInFirst : accept();
424
+
425
+ // Visibility as Git's read of the repo answered this caller. A repo operation that reaches
426
+ // here without it is refused as a private repo's, for a caller outside TypeScript.
427
+ const visible = input.repo?.public === true;
428
+ // A hook's settings and deliveries are its owner's, even on a public repo: they hold payloads
429
+ // signed for its receiver, and the receiver's answers.
430
+ const ownersOnly = operation.kind.startsWith('hook.');
431
+ if (visible && operation.kind.endsWith('.read') && !ownersOnly) return accept();
432
+
433
+ if (actor.anonymous === true) return signInFirst;
434
+
435
+ if (actor.id === admin.id || (visible && contributions.has(operation.kind))) return accept();
436
+
437
+ return (await owns(actor, ownerOf(operation.repo)))
438
+ ? accept()
439
+ : reject({ message: 'Only the owner may do this' });
440
+ };
441
+
442
+ /**
443
+ * The owner index's hook: every private repo under `owner` for its owner, a person's own login
444
+ * or an org they belong to, and the admin, as `authorizeGitHub` lets them read it; none for
445
+ * anyone else. Only those the caller's token covers, listed under what it covers alone, so a
446
+ * token's own repos get the checks, and neither the names nor `more` show how many it can't read.
447
+ * A token over one repo names it alone, which `authorize` holds as any name. Git lists them newest
448
+ * made first, since it keeps no time a repo was updated.
449
+ */
450
+ const readableRepos: GitHubReadableRepos = async (input) => {
451
+ const { actor, owner, most, token, host } = input;
452
+ if (actor.anonymous === true || !(await tokenHolds(input))) return { names: [], more: false };
453
+
454
+ if (actor.id !== admin.id && !(await owns(actor, owner))) return { names: [], more: false };
455
+
456
+ const cover = coverOf(owner, token);
457
+ if (cover === undefined || most <= 0) return { names: [], more: false };
458
+
459
+ if (cover.repo !== undefined) return { names: [cover.repo], more: false };
460
+
461
+ return privateRepos(cover.prefix, most, host);
462
+ };
463
+
464
+ /**
465
+ * The host's directory, for the drop-in (Q522): a user only once they've signed up, an org only
466
+ * once it's made, and a person's orgs, an org's members and which of some logins are its members
467
+ * from `member` rows, each shaped as the drop-in's default shapes it: a person through its
468
+ * calls, and an org as `defaultOrg` makes it, repos or none, as anyone may see a person who
469
+ * signed up. The starter keeps no two-factor record, so a two-factor filter lists no one, and
470
+ * teams are the default's: none.
471
+ */
472
+ const people: PeopleFor = (context) => {
473
+ const base = defaultPeople(context);
474
+
475
+ // A person by the name they go by, as GitHub names someone who set one: a merge the drop-in
476
+ // makes for them is authored under it.
477
+ const user = async (input: PeopleUser): Promise<GitHubUser | undefined> => {
478
+ const person = await orgs.person(input.login);
479
+ if (person === undefined) return undefined;
480
+
481
+ const found = await base(input);
482
+ if (found === undefined) return undefined;
483
+
484
+ const picture = await pictureOf(input.login, { kind: 'user', id: person.id });
485
+
486
+ return { ...found, name: person.name, ...picture };
487
+ };
488
+
489
+ const org = async (input: PeopleOrg): Promise<GitHubOrg | undefined> =>
490
+ (await orgs.org(input.org)) ? orgOf(input.org) : undefined;
491
+
492
+ const members = async (input: PeopleMembers): Promise<Listed<GitHubUser>> => {
493
+ if (input.filter !== 'all') return { items: [] };
494
+
495
+ const page = { after: input.page?.after, limit: input.page?.limit ?? listedEach };
496
+ const listed = await orgs.members(input.org, { ...page, role: input.role });
497
+ const found = await Promise.all(
498
+ listed.logins.map(async (login) => user({ ...input, kind: 'user', login })),
499
+ );
500
+ const items = found.filter((each) => each !== undefined);
501
+
502
+ return listed.next === undefined ? { items } : { items, next: listed.next };
503
+ };
504
+
505
+ const orgsOf = async (input: PeopleOrgs): Promise<Listed<GitHubOrg>> => {
506
+ if (input.actor.anonymous === true) return { items: [] };
507
+
508
+ const page = { after: input.page?.after, limit: input.page?.limit ?? listedEach };
509
+ const listed = await orgs.orgsOf(input.actor.id, page);
510
+ const items = await Promise.all(
511
+ listed.logins.filter((login) => reaches(input, login)).map(orgOf),
512
+ );
513
+
514
+ return listed.next === undefined ? { items } : { items, next: listed.next };
515
+ };
516
+
517
+ function lookup(input: PeopleViewer | PeopleUser): Promise<GitHubUser | undefined>;
518
+ function lookup(input: PeopleOrg): Promise<GitHubOrg | undefined>;
519
+ function lookup(input: PeopleOrgs): Promise<Listed<GitHubOrg>>;
520
+ function lookup(input: PeopleMembers | PeopleTeamMembers): Promise<Listed<GitHubUser>>;
521
+ function lookup(input: PeopleTeams): Promise<Listed<GitHubTeam>>;
522
+ function lookup(input: PeopleMembership): Promise<readonly string[]>;
523
+ function lookup(input: PeopleTeam): Promise<GitHubTeam | undefined>;
524
+ function lookup(input: PeopleSearch): Promise<PeopleSearchAnswer>;
525
+ async function lookup(input: PeopleInput): Promise<PeopleAnswer> {
526
+ // A token whose person left the org it's over reads no one and lists nothing: `/user` 404s,
527
+ // as every other use of it is refused.
528
+ if (!(await tokenHolds(input))) return refusedLookup(input);
529
+
530
+ switch (input.kind) {
531
+ case 'viewer':
532
+ return input.actor.anonymous === true
533
+ ? undefined
534
+ : user({ ...input, kind: 'user', login: input.actor.id });
535
+ case 'user':
536
+ return user(input);
537
+ case 'org':
538
+ return org(input);
539
+ case 'orgs':
540
+ return orgsOf(input);
541
+ case 'search':
542
+ // A range of each index, read to the limit: it never stops short of its own accord.
543
+ return {
544
+ found: await orgs.search(input.prefix, input.limit, input.type),
545
+ incomplete: false,
546
+ };
547
+ case 'members':
548
+ return members(input);
549
+ case 'membership':
550
+ return orgs.among(input.org, input.logins);
551
+ case 'team-members':
552
+ return base(input);
553
+ case 'teams':
554
+ return base(input);
555
+ case 'team':
556
+ return base(input);
557
+ }
558
+ }
559
+
560
+ return lookup;
561
+ };
562
+
563
+ return { authorize, authorizeGitHub, people, readableRepos };
564
+ };
565
+
566
+ /** One of the host's push rules, beside the refs it covers on every repo. */
567
+ export interface HostRule {
568
+ readonly rule: PushRule;
569
+ readonly covers: readonly RefName[];
570
+ }
571
+
572
+ /**
573
+ * The host's push rules, which Git is made with and a repo's settings show. Delete a line to turn
574
+ * its rule off.
575
+ */
576
+ export const hostRules: readonly HostRule[] = [
577
+ // `main` takes fast-forwards only, so no one, an owner included, force-pushes or deletes it (#193).
578
+ { rule: refs.protect('refs/heads/main'), covers: ['refs/heads/main'] },
579
+ // Every branch and tag refuses a push that adds or changes one of these files, which usually
580
+ // hold secrets. `git push -o allow-files` asks `authorize` instead. Edit the list, or delete
581
+ // the line.
582
+ {
583
+ rule: refs.files(['*', 'refs/tags/*'], {
584
+ refuse: [
585
+ '.env',
586
+ '.env.*',
587
+ '!.env.example',
588
+ '!.env.sample',
589
+ '*.pem',
590
+ '**/id_rsa',
591
+ '**/id_ed25519',
592
+ ],
593
+ }),
594
+ covers: ['refs/heads/*', 'refs/tags/*'],
595
+ },
596
+ ];
597
+
598
+ /** The device flow's approval page: the person signed in approves a device for themselves. */
599
+ export const approvalPage = (options: Omit<StarterApprovalOptions, 'tokenDays'>) =>
600
+ starterApprovalPage({ ...options, tokenDays });
@@ -0,0 +1,47 @@
1
+ import type { Actor, GitServer, RepoId } from '@ref0/git';
2
+
3
+ import { admin } from './policy.ts';
4
+ import type { PrivateRepos } from './policy.ts';
5
+
6
+ /**
7
+ * At most `most` of the private repos under `prefix` on `git`, among the newest `most` there,
8
+ * newest made first: those `host` lists, unchecked, less what `git` lists a caller not signed in,
9
+ * which reads the public repos' own index. Both lists are one page of `most`, newest first by one
10
+ * key, a repo's created row, so the two windows hold the same repos and differ by the private ones
11
+ * alone. The search asks for as many as it checks of the owner, so a private repo is named as far
12
+ * down the owner's newest as a public one is reached (Q796). Past them, `more` says so.
13
+ *
14
+ * Its store calls stay within what the search leaves the hook, `most` and 6 more: the signed-out
15
+ * list reads the record of each public name in its page, one call a name, and of the name past
16
+ * it; the host's list reads its created rows and their entries, two; the public index, one; and a
17
+ * server's first sealed cursor reads its key, once for each list that races to it, two
18
+ * (`listPublic` and `listCreated` in Git's `store/catalogue.ts`, `cursorSeal` in
19
+ * `store/cursor-seal.ts`).
20
+ */
21
+ export const privateReposOf =
22
+ (git: Pick<GitServer, 'repos'>): PrivateRepos =>
23
+ async (prefix, most, host) => {
24
+ if (most <= 0) return { names: [], more: true };
25
+
26
+ const listed = async (list: GitServer['repos']['list'], actor: Actor) => {
27
+ const page = await list({
28
+ actor,
29
+ prefix,
30
+ order: 'newest',
31
+ page: { limit: most },
32
+ });
33
+ if (page.kind !== 'success') return { names: [], whole: false };
34
+
35
+ return { names: page.value.items, whole: page.value.next === undefined };
36
+ };
37
+
38
+ // The host's own calls read no actor: the admin's stands in, as `repos.list` takes one.
39
+ const [all, shown] = await Promise.all([
40
+ listed(host.list, admin),
41
+ listed(git.repos.list, { anonymous: true }),
42
+ ]);
43
+ const open = new Set<RepoId>(shown.names);
44
+ const hidden = all.names.filter((name) => !open.has(name));
45
+
46
+ return { names: hidden, more: !all.whole || !shown.whole };
47
+ };