ref0-git 0.0.0-stage → 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.
- package/app/apps/github/.dev.vars.example +6 -0
- package/app/apps/github/README.md +70 -0
- package/app/apps/github/THIRD_PARTY_NOTICES.md +214 -0
- package/app/apps/github/components.json +25 -0
- package/app/apps/github/generated/git-rest.ts +10444 -0
- package/app/apps/github/generated/routeTree.gen.ts +1242 -0
- package/app/apps/github/migrations/postgres/0001_auth.sql +46 -0
- package/app/apps/github/migrations/sql/0001_auth.sql +19 -0
- package/app/apps/github/migrations/sql/0002_passkeys.sql +9 -0
- package/app/apps/github/migrations/sql/0003_orgs.sql +22 -0
- package/app/apps/github/migrations/sql/0004_avatars.sql +6 -0
- package/app/apps/github/package.json +80 -0
- package/app/apps/github/src/branches/branch-list.tsx +385 -0
- package/app/apps/github/src/branches/branches.ts +55 -0
- package/app/apps/github/src/clients/allowed.ts +213 -0
- package/app/apps/github/src/clients/at-most.ts +17 -0
- package/app/apps/github/src/clients/avatars.ts +410 -0
- package/app/apps/github/src/clients/cached.ts +65 -0
- package/app/apps/github/src/clients/calls.ts +160 -0
- package/app/apps/github/src/clients/clients.ts +82 -0
- package/app/apps/github/src/clients/graphql.ts +50 -0
- package/app/apps/github/src/clients/host-answer.ts +28 -0
- package/app/apps/github/src/clients/host-calls.ts +382 -0
- package/app/apps/github/src/clients/icon-bytes.ts +203 -0
- package/app/apps/github/src/clients/proxy.ts +59 -0
- package/app/apps/github/src/clients/session-ended.ts +18 -0
- package/app/apps/github/src/clients/transfers.ts +212 -0
- package/app/apps/github/src/code/breadcrumbs.tsx +50 -0
- package/app/apps/github/src/code/code-page.tsx +147 -0
- package/app/apps/github/src/code/code-tree.tsx +338 -0
- package/app/apps/github/src/code/controls.tsx +230 -0
- package/app/apps/github/src/code/file-view.tsx +450 -0
- package/app/apps/github/src/code/files.ts +332 -0
- package/app/apps/github/src/code/folder-list.tsx +122 -0
- package/app/apps/github/src/code/go-to-file.tsx +131 -0
- package/app/apps/github/src/code/highlighted.tsx +58 -0
- package/app/apps/github/src/code/lines.ts +46 -0
- package/app/apps/github/src/code/load.ts +147 -0
- package/app/apps/github/src/code/markdown-files.ts +58 -0
- package/app/apps/github/src/code/places.ts +88 -0
- package/app/apps/github/src/code/ref-pages.ts +179 -0
- package/app/apps/github/src/code/ref-switcher.tsx +203 -0
- package/app/apps/github/src/code/refs.ts +142 -0
- package/app/apps/github/src/code/repo-home.tsx +240 -0
- package/app/apps/github/src/code/repo.ts +105 -0
- package/app/apps/github/src/code/saved-reads.ts +199 -0
- package/app/apps/github/src/code/saved.ts +110 -0
- package/app/apps/github/src/code/tree-fold.ts +186 -0
- package/app/apps/github/src/code/trees.ts +136 -0
- package/app/apps/github/src/components/avatar-picture.ts +53 -0
- package/app/apps/github/src/components/avatar-url.ts +16 -0
- package/app/apps/github/src/components/confirm-action.tsx +100 -0
- package/app/apps/github/src/components/count.tsx +24 -0
- package/app/apps/github/src/components/create-button.tsx +38 -0
- package/app/apps/github/src/components/file-icons/file-icons.css +225 -0
- package/app/apps/github/src/components/file-icons/file-icons.tsx +138 -0
- package/app/apps/github/src/components/filter.tsx +35 -0
- package/app/apps/github/src/components/hotkeys/hotkeys.tsx +255 -0
- package/app/apps/github/src/components/item-list.tsx +65 -0
- package/app/apps/github/src/components/language-dot.tsx +29 -0
- package/app/apps/github/src/components/list-toolbar.tsx +82 -0
- package/app/apps/github/src/components/markdown/editor.tsx +57 -0
- package/app/apps/github/src/components/markdown/markdown.css +177 -0
- package/app/apps/github/src/components/markdown/markdown.tsx +82 -0
- package/app/apps/github/src/components/owner-card.tsx +196 -0
- package/app/apps/github/src/components/pull-status.tsx +34 -0
- package/app/apps/github/src/components/recent.ts +41 -0
- package/app/apps/github/src/components/relative-time.tsx +78 -0
- package/app/apps/github/src/components/repos/icon-hashes.ts +91 -0
- package/app/apps/github/src/components/repos/new-repo-form.tsx +196 -0
- package/app/apps/github/src/components/repos/repo-icon.tsx +47 -0
- package/app/apps/github/src/components/repos/repo-list.tsx +528 -0
- package/app/apps/github/src/components/repos/your-repos.tsx +124 -0
- package/app/apps/github/src/components/review-state.tsx +75 -0
- package/app/apps/github/src/components/route-dialog.tsx +137 -0
- package/app/apps/github/src/components/save-button.tsx +58 -0
- package/app/apps/github/src/components/shell/app-shell.tsx +164 -0
- package/app/apps/github/src/components/shell/create-org-dialog.tsx +118 -0
- package/app/apps/github/src/components/shell/create-row.tsx +49 -0
- package/app/apps/github/src/components/shell/link-menu.tsx +94 -0
- package/app/apps/github/src/components/shell/nav-user.tsx +97 -0
- package/app/apps/github/src/components/shell/owner-repos.tsx +247 -0
- package/app/apps/github/src/components/shell/owner-switcher.tsx +104 -0
- package/app/apps/github/src/components/shell/repo-switcher.tsx +179 -0
- package/app/apps/github/src/components/shell/sections.ts +31 -0
- package/app/apps/github/src/components/shell/submenu-chevron.ts +147 -0
- package/app/apps/github/src/components/signin/device-card.tsx +139 -0
- package/app/apps/github/src/components/signin/login-form.tsx +88 -0
- package/app/apps/github/src/components/signin/signin-page.tsx +33 -0
- package/app/apps/github/src/components/signin/signup-form.tsx +106 -0
- package/app/apps/github/src/components/states/live-status.tsx +42 -0
- package/app/apps/github/src/components/states/states.tsx +126 -0
- package/app/apps/github/src/components/tab-indicator.tsx +143 -0
- package/app/apps/github/src/components/theme-choice.tsx +108 -0
- package/app/apps/github/src/components/theme-provider.tsx +126 -0
- package/app/apps/github/src/components/tones.ts +23 -0
- package/app/apps/github/src/components/ui/alert-dialog.tsx +187 -0
- package/app/apps/github/src/components/ui/alert.tsx +78 -0
- package/app/apps/github/src/components/ui/avatar.tsx +106 -0
- package/app/apps/github/src/components/ui/badge.tsx +51 -0
- package/app/apps/github/src/components/ui/breadcrumb.tsx +124 -0
- package/app/apps/github/src/components/ui/button-group.tsx +87 -0
- package/app/apps/github/src/components/ui/button.tsx +61 -0
- package/app/apps/github/src/components/ui/calendar.tsx +221 -0
- package/app/apps/github/src/components/ui/card.tsx +102 -0
- package/app/apps/github/src/components/ui/checkbox.tsx +26 -0
- package/app/apps/github/src/components/ui/collapsible.tsx +19 -0
- package/app/apps/github/src/components/ui/combobox.tsx +304 -0
- package/app/apps/github/src/components/ui/command.tsx +208 -0
- package/app/apps/github/src/components/ui/dialog.tsx +156 -0
- package/app/apps/github/src/components/ui/dropdown-menu.tsx +290 -0
- package/app/apps/github/src/components/ui/empty.tsx +100 -0
- package/app/apps/github/src/components/ui/field.tsx +236 -0
- package/app/apps/github/src/components/ui/hover-card.tsx +48 -0
- package/app/apps/github/src/components/ui/input-group.tsx +163 -0
- package/app/apps/github/src/components/ui/input.tsx +19 -0
- package/app/apps/github/src/components/ui/item.tsx +201 -0
- package/app/apps/github/src/components/ui/kbd.tsx +27 -0
- package/app/apps/github/src/components/ui/label.tsx +33 -0
- package/app/apps/github/src/components/ui/popover.tsx +87 -0
- package/app/apps/github/src/components/ui/radio-group.tsx +35 -0
- package/app/apps/github/src/components/ui/select.tsx +198 -0
- package/app/apps/github/src/components/ui/separator.tsx +22 -0
- package/app/apps/github/src/components/ui/sheet.tsx +138 -0
- package/app/apps/github/src/components/ui/sidebar.tsx +724 -0
- package/app/apps/github/src/components/ui/skeleton.tsx +13 -0
- package/app/apps/github/src/components/ui/sonner.tsx +47 -0
- package/app/apps/github/src/components/ui/styles.css +242 -0
- package/app/apps/github/src/components/ui/table.tsx +113 -0
- package/app/apps/github/src/components/ui/tabs.tsx +79 -0
- package/app/apps/github/src/components/ui/textarea.tsx +17 -0
- package/app/apps/github/src/components/ui/title.ts +6 -0
- package/app/apps/github/src/components/ui/toggle-group.tsx +89 -0
- package/app/apps/github/src/components/ui/toggle.tsx +42 -0
- package/app/apps/github/src/components/ui/tooltip.tsx +63 -0
- package/app/apps/github/src/components/user-avatar.tsx +145 -0
- package/app/apps/github/src/components/view-tabs.tsx +42 -0
- package/app/apps/github/src/context/context.ts +133 -0
- package/app/apps/github/src/diffs/blobs.ts +94 -0
- package/app/apps/github/src/diffs/diff-view.tsx +155 -0
- package/app/apps/github/src/diffs/files.ts +121 -0
- package/app/apps/github/src/diffs/hunks.tsx +454 -0
- package/app/apps/github/src/diffs/patch.ts +131 -0
- package/app/apps/github/src/diffs/rows.ts +137 -0
- package/app/apps/github/src/history/commit-diff.ts +54 -0
- package/app/apps/github/src/history/commit-list.tsx +207 -0
- package/app/apps/github/src/history/commit-page.tsx +147 -0
- package/app/apps/github/src/history/history.ts +129 -0
- package/app/apps/github/src/hooks/allowed.ts +31 -0
- package/app/apps/github/src/hooks/answers.ts +65 -0
- package/app/apps/github/src/hooks/avatars.ts +54 -0
- package/app/apps/github/src/hooks/draft.ts +38 -0
- package/app/apps/github/src/hooks/open-counts.ts +127 -0
- package/app/apps/github/src/hooks/profiles.ts +120 -0
- package/app/apps/github/src/hooks/repos.ts +440 -0
- package/app/apps/github/src/hooks/use-mobile.ts +19 -0
- package/app/apps/github/src/hooks/viewer.ts +39 -0
- package/app/apps/github/src/inbox/count.ts +70 -0
- package/app/apps/github/src/inbox/inbox-item.tsx +66 -0
- package/app/apps/github/src/inbox/inbox-page.tsx +572 -0
- package/app/apps/github/src/inbox/marks.ts +130 -0
- package/app/apps/github/src/inbox/release-tags.ts +65 -0
- package/app/apps/github/src/inbox/search.ts +97 -0
- package/app/apps/github/src/inbox/subjects.ts +184 -0
- package/app/apps/github/src/inbox/subscription-controls.tsx +184 -0
- package/app/apps/github/src/inbox/subscriptions.ts +189 -0
- package/app/apps/github/src/inbox/threads.ts +198 -0
- package/app/apps/github/src/issues/changes.ts +332 -0
- package/app/apps/github/src/issues/counts.ts +62 -0
- package/app/apps/github/src/issues/issue-list.tsx +682 -0
- package/app/apps/github/src/issues/issue-page.tsx +533 -0
- package/app/apps/github/src/issues/issues.ts +566 -0
- package/app/apps/github/src/issues/label-dialog.tsx +310 -0
- package/app/apps/github/src/issues/labels-page.tsx +119 -0
- package/app/apps/github/src/issues/new-issue.tsx +79 -0
- package/app/apps/github/src/issues/parts.tsx +71 -0
- package/app/apps/github/src/issues/picker.tsx +298 -0
- package/app/apps/github/src/issues/search.ts +238 -0
- package/app/apps/github/src/issues/sidebar.tsx +236 -0
- package/app/apps/github/src/lib/cn.ts +8 -0
- package/app/apps/github/src/lib/highlighting.ts +13 -0
- package/app/apps/github/src/live/follow.ts +129 -0
- package/app/apps/github/src/live/sse.ts +74 -0
- package/app/apps/github/src/live/use-follow.ts +37 -0
- package/app/apps/github/src/markdown/README.md +53 -0
- package/app/apps/github/src/markdown/allowed-html.ts +69 -0
- package/app/apps/github/src/markdown/context.ts +206 -0
- package/app/apps/github/src/markdown/images.ts +81 -0
- package/app/apps/github/src/markdown/lookup.ts +122 -0
- package/app/apps/github/src/markdown/patches.ts +299 -0
- package/app/apps/github/src/markdown/query.ts +25 -0
- package/app/apps/github/src/markdown/references.ts +158 -0
- package/app/apps/github/src/markdown/render.ts +103 -0
- package/app/apps/github/src/names/owners.ts +51 -0
- package/app/apps/github/src/names/repos.ts +24 -0
- package/app/apps/github/src/palette/palette.tsx +547 -0
- package/app/apps/github/src/palette/recent.ts +116 -0
- package/app/apps/github/src/palette/rows.tsx +455 -0
- package/app/apps/github/src/palette/server.ts +104 -0
- package/app/apps/github/src/palette/targets.ts +306 -0
- package/app/apps/github/src/policy.ts +600 -0
- package/app/apps/github/src/private-repos.ts +47 -0
- package/app/apps/github/src/pulls/compare-page.tsx +342 -0
- package/app/apps/github/src/pulls/files-tab.tsx +776 -0
- package/app/apps/github/src/pulls/live.ts +124 -0
- package/app/apps/github/src/pulls/merge-box.tsx +367 -0
- package/app/apps/github/src/pulls/merge-button.ts +86 -0
- package/app/apps/github/src/pulls/pull-list.tsx +235 -0
- package/app/apps/github/src/pulls/pull-page.tsx +474 -0
- package/app/apps/github/src/pulls/pull.ts +468 -0
- package/app/apps/github/src/pulls/pulls.ts +318 -0
- package/app/apps/github/src/pulls/review.ts +350 -0
- package/app/apps/github/src/pulls/search.ts +130 -0
- package/app/apps/github/src/queue/queue-page.tsx +405 -0
- package/app/apps/github/src/queue/queue.ts +231 -0
- package/app/apps/github/src/releases/latest-release.tsx +55 -0
- package/app/apps/github/src/releases/overview.tsx +30 -0
- package/app/apps/github/src/releases/release-form.tsx +353 -0
- package/app/apps/github/src/releases/release-list.tsx +173 -0
- package/app/apps/github/src/releases/release-view.tsx +183 -0
- package/app/apps/github/src/releases/releases.ts +308 -0
- package/app/apps/github/src/releases/tag-list.tsx +134 -0
- package/app/apps/github/src/router.tsx +46 -0
- package/app/apps/github/src/routes/$owner/$repo/_code/blob/$.tsx +33 -0
- package/app/apps/github/src/routes/$owner/$repo/_code/tree/$.tsx +28 -0
- package/app/apps/github/src/routes/$owner/$repo/_code.tsx +11 -0
- package/app/apps/github/src/routes/$owner/$repo/_releases/releases/index.tsx +19 -0
- package/app/apps/github/src/routes/$owner/$repo/_releases/tags.tsx +19 -0
- package/app/apps/github/src/routes/$owner/$repo/_releases.tsx +23 -0
- package/app/apps/github/src/routes/$owner/$repo/branches.tsx +39 -0
- package/app/apps/github/src/routes/$owner/$repo/commit/$sha.tsx +34 -0
- package/app/apps/github/src/routes/$owner/$repo/commits/$.tsx +42 -0
- package/app/apps/github/src/routes/$owner/$repo/compare/$.tsx +19 -0
- package/app/apps/github/src/routes/$owner/$repo/index.tsx +24 -0
- package/app/apps/github/src/routes/$owner/$repo/issues/$number.tsx +50 -0
- package/app/apps/github/src/routes/$owner/$repo/issues/index.tsx +53 -0
- package/app/apps/github/src/routes/$owner/$repo/issues/new.tsx +43 -0
- package/app/apps/github/src/routes/$owner/$repo/labels.tsx +22 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/checks.tsx +15 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/commits.tsx +15 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/files.tsx +15 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/index.tsx +19 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/route.tsx +52 -0
- package/app/apps/github/src/routes/$owner/$repo/pulls/index.tsx +48 -0
- package/app/apps/github/src/routes/$owner/$repo/queue.tsx +22 -0
- package/app/apps/github/src/routes/$owner/$repo/releases/edit/$.tsx +58 -0
- package/app/apps/github/src/routes/$owner/$repo/releases/new.tsx +40 -0
- package/app/apps/github/src/routes/$owner/$repo/releases/tag/$.tsx +35 -0
- package/app/apps/github/src/routes/$owner/$repo/route.tsx +102 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/access.tsx +9 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/hooks/index.tsx +16 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/hooks/new.tsx +25 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/index.tsx +17 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/route.tsx +28 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/rules.tsx +12 -0
- package/app/apps/github/src/routes/$owner/$repo/tokens.tsx +16 -0
- package/app/apps/github/src/routes/$owner/index.tsx +45 -0
- package/app/apps/github/src/routes/-nav.tsx +293 -0
- package/app/apps/github/src/routes/-root-testing.ts +107 -0
- package/app/apps/github/src/routes/__root.tsx +225 -0
- package/app/apps/github/src/routes/api.auth.$.ts +18 -0
- package/app/apps/github/src/routes/downloads/$owner/$repo/$asset.tsx +10 -0
- package/app/apps/github/src/routes/file-icons[.]svg.ts +21 -0
- package/app/apps/github/src/routes/icons/$owner/$repo.tsx +14 -0
- package/app/apps/github/src/routes/icons/$owner/index.tsx +14 -0
- package/app/apps/github/src/routes/icons/index.tsx +12 -0
- package/app/apps/github/src/routes/index.tsx +48 -0
- package/app/apps/github/src/routes/login.tsx +24 -0
- package/app/apps/github/src/routes/login_.code.tsx +31 -0
- package/app/apps/github/src/routes/new.tsx +91 -0
- package/app/apps/github/src/routes/notifications.tsx +20 -0
- package/app/apps/github/src/routes/orgs/$owner/issues.tsx +8 -0
- package/app/apps/github/src/routes/orgs/$owner/pulls.tsx +8 -0
- package/app/apps/github/src/routes/orgs/$owner/releases.tsx +8 -0
- package/app/apps/github/src/routes/orgs/$owner/route.tsx +25 -0
- package/app/apps/github/src/routes/orgs/$owner/settings.tsx +30 -0
- package/app/apps/github/src/routes/orgs/$owner/tokens.tsx +15 -0
- package/app/apps/github/src/routes/settings.tsx +54 -0
- package/app/apps/github/src/routes/signup.tsx +24 -0
- package/app/apps/github/src/routes/uploads/$owner/$repo/$release.tsx +10 -0
- package/app/apps/github/src/seed/acme.ts +498 -0
- package/app/apps/github/src/seed/licenses.ts +114 -0
- package/app/apps/github/src/seed/seed.ts +538 -0
- package/app/apps/github/src/server.ts +97 -0
- package/app/apps/github/src/settings/account-avatar.tsx +43 -0
- package/app/apps/github/src/settings/avatar-section.tsx +140 -0
- package/app/apps/github/src/settings/avatar.ts +58 -0
- package/app/apps/github/src/settings/general-settings.tsx +439 -0
- package/app/apps/github/src/settings/general.ts +73 -0
- package/app/apps/github/src/settings/hook-form.tsx +195 -0
- package/app/apps/github/src/settings/hook-list.tsx +166 -0
- package/app/apps/github/src/settings/hooks.ts +87 -0
- package/app/apps/github/src/settings/org-settings.tsx +228 -0
- package/app/apps/github/src/settings/orgs.ts +116 -0
- package/app/apps/github/src/settings/rule-list.tsx +72 -0
- package/app/apps/github/src/settings/rules.ts +27 -0
- package/app/apps/github/src/settings/settings-layout.tsx +114 -0
- package/app/apps/github/src/signin/approval.ts +186 -0
- package/app/apps/github/src/signin/auth-client.ts +127 -0
- package/app/apps/github/src/signin/auth.ts +753 -0
- package/app/apps/github/src/signin/avatars.ts +126 -0
- package/app/apps/github/src/signin/client-ip.ts +39 -0
- package/app/apps/github/src/signin/credentials.ts +26 -0
- package/app/apps/github/src/signin/device-code.ts +95 -0
- package/app/apps/github/src/signin/device-prompt.ts +125 -0
- package/app/apps/github/src/signin/errors.ts +135 -0
- package/app/apps/github/src/signin/host-session.ts +68 -0
- package/app/apps/github/src/signin/orgs.ts +283 -0
- package/app/apps/github/src/signin/owner-names.ts +183 -0
- package/app/apps/github/src/signin/person-lock.ts +104 -0
- package/app/apps/github/src/signin/seal.ts +88 -0
- package/app/apps/github/src/signin/seed-people.ts +92 -0
- package/app/apps/github/src/signin/session.ts +48 -0
- package/app/apps/github/src/signin/unborn.ts +110 -0
- package/app/apps/github/src/signin/viewer-orgs.ts +47 -0
- package/app/apps/github/src/signin/viewer.ts +74 -0
- package/app/apps/github/src/signin/with-headers.ts +14 -0
- package/app/apps/github/src/tokens/tokens-page.tsx +529 -0
- package/app/apps/github/src/tokens/tokens.ts +54 -0
- package/app/apps/github/tsconfig.json +25 -0
- package/app/apps/github/tsconfig.worker.json +24 -0
- package/app/apps/github/vite.config.ts +21 -0
- package/app/pnpm-workspace.yaml +216 -0
- package/app/tsconfig.base.json +127 -0
- package/dist/LICENSE +202 -0
- package/dist/cli/child.mjs +42 -0
- package/dist/cli/commands.mjs +23 -0
- package/dist/cli/credentials.mjs +84 -0
- package/dist/cli/documents.mjs +214 -0
- package/dist/cli/events.mjs +55 -0
- package/dist/cli/failure.mjs +105 -0
- package/dist/cli/folders.mjs +32 -0
- package/dist/cli/git-remote-ref0.d.mts +1 -0
- package/dist/cli/git-remote-ref0.mjs +29 -0
- package/dist/cli/git.mjs +48 -0
- package/dist/cli/helpers.mjs +51 -0
- package/dist/cli/hosts.mjs +127 -0
- package/dist/cli/node.mjs +15 -0
- package/dist/cli/output.mjs +135 -0
- package/dist/cli/prompt.mjs +35 -0
- package/dist/cli/queue.mjs +215 -0
- package/dist/cli/ref0-git.d.mts +1 -0
- package/dist/cli/ref0-git.mjs +144 -0
- package/dist/cli/repos.mjs +162 -0
- package/dist/cli/resources.mjs +131 -0
- package/dist/cli/run-end.mjs +57 -0
- package/dist/cli/runtime.mjs +50 -0
- package/dist/cli/setup.mjs +1410 -0
- package/dist/cli/sign-in.mjs +162 -0
- package/dist/cli/sign-ins.mjs +79 -0
- package/dist/cli/sqlite.mjs +28 -0
- package/dist/cli/tokens.mjs +141 -0
- package/dist/cli/vendor.mjs +123 -0
- package/dist/init/app.mjs +231 -0
- package/dist/init/astro.mjs +49 -0
- package/dist/init/choices.mjs +497 -0
- package/dist/init/cloudflare.mjs +324 -0
- package/dist/init/create.mjs +151 -0
- package/dist/init/detect.mjs +297 -0
- package/dist/init/files.mjs +75 -0
- package/dist/init/frameworks.mjs +248 -0
- package/dist/init/git-module.mjs +49 -0
- package/dist/init/github-routes.mjs +66 -0
- package/dist/init/jsonc.mjs +143 -0
- package/dist/init/metadata.mjs +48 -0
- package/dist/init/mounts.mjs +109 -0
- package/dist/init/next.mjs +205 -0
- package/dist/init/node-app.mjs +189 -0
- package/dist/init/node.mjs +458 -0
- package/dist/init/nuxt.mjs +115 -0
- package/dist/init/output.mjs +21 -0
- package/dist/init/plan.mjs +82 -0
- package/dist/init/range-major.mjs +257 -0
- package/dist/init/react-router.mjs +59 -0
- package/dist/init/routes.mjs +148 -0
- package/dist/init/shell.mjs +4 -0
- package/dist/init/stores.mjs +51 -0
- package/dist/init/sveltekit.mjs +139 -0
- package/dist/init/template.mjs +142 -0
- package/dist/init/templates.mjs +343 -0
- package/dist/init/vercel.mjs +383 -0
- package/dist/init/versions.mjs +32 -0
- package/dist/init/workspace.mjs +20 -0
- package/package.json +52 -3
- package/README.md +0 -3
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import type { GitAuthorize, TokenScope } from '@ref0/git';
|
|
2
|
+
import type { GitHubOperationKind } from '@ref0/github';
|
|
3
|
+
import { authorizeOperation, credentialCeiling } from '@ref0/github';
|
|
4
|
+
import { createServerFn } from '@tanstack/react-start';
|
|
5
|
+
import { getRequest } from '@tanstack/react-start/server';
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
7
|
+
|
|
8
|
+
import type { AppContext } from '../context/context.ts';
|
|
9
|
+
import { forward } from './calls.ts';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The writes a page makes through a host call (Q520), which Git's `authorize` decides for the
|
|
13
|
+
* session's person, since no token reaches them: a repo's General settings and its deletion. A
|
|
14
|
+
* `push` with no updates asks whether Git would let the person push at all, for the controls that
|
|
15
|
+
* make and delete branches.
|
|
16
|
+
*/
|
|
17
|
+
export const hostOperations = [
|
|
18
|
+
'repo.update',
|
|
19
|
+
'repo.delete',
|
|
20
|
+
'push',
|
|
21
|
+
] as const satisfies readonly Parameters<GitAuthorize>[0]['operation']['kind'][];
|
|
22
|
+
|
|
23
|
+
type HostOperation = (typeof hostOperations)[number];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The operations the drop-in decides that a page draws a control for. Each control shows only to
|
|
27
|
+
* a caller the drop-in would let make its call, and a refused one is hidden, never offered to fail.
|
|
28
|
+
*/
|
|
29
|
+
const gitHubOperations = [
|
|
30
|
+
'issue.create',
|
|
31
|
+
'issue.update',
|
|
32
|
+
'issue.comment',
|
|
33
|
+
'comment.update',
|
|
34
|
+
'label.create',
|
|
35
|
+
'label.update',
|
|
36
|
+
'milestone.create',
|
|
37
|
+
'pull.create',
|
|
38
|
+
'pull.update',
|
|
39
|
+
'pull.merge',
|
|
40
|
+
'pull.review',
|
|
41
|
+
'release.create',
|
|
42
|
+
'release.update',
|
|
43
|
+
'release.delete',
|
|
44
|
+
'hook.read',
|
|
45
|
+
'hook.create',
|
|
46
|
+
'hook.delete',
|
|
47
|
+
] as const satisfies readonly GitHubOperationKind[];
|
|
48
|
+
|
|
49
|
+
type GitHubPageOperation = (typeof gitHubOperations)[number];
|
|
50
|
+
|
|
51
|
+
/** Every operation a page draws a control for: the drop-in's, then the host calls'. */
|
|
52
|
+
export const pageOperations = [...gitHubOperations, ...hostOperations] as const;
|
|
53
|
+
|
|
54
|
+
export type PageOperation = (typeof pageOperations)[number];
|
|
55
|
+
|
|
56
|
+
const isHostOperation = (kind: PageOperation): kind is HostOperation =>
|
|
57
|
+
hostOperations.some((each) => each === kind);
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* What the drop-in decides each operation on: the issue, by its number, or the repo alone, as its
|
|
61
|
+
* routes ask. A new issue, label, milestone or pull request, an edited comment or label, a release
|
|
62
|
+
* and a hook are the repo's. Asking for reviews is `pull.update`, merging or queueing a pull request is
|
|
63
|
+
* `pull.merge`, and a review, a comment on its lines or discarding a pending review is
|
|
64
|
+
* `pull.review`.
|
|
65
|
+
*/
|
|
66
|
+
const decidedOn: Readonly<Record<GitHubPageOperation, 'issue' | 'repo'>> = {
|
|
67
|
+
'issue.create': 'repo',
|
|
68
|
+
'issue.update': 'issue',
|
|
69
|
+
'issue.comment': 'issue',
|
|
70
|
+
'comment.update': 'repo',
|
|
71
|
+
'label.create': 'repo',
|
|
72
|
+
'label.update': 'repo',
|
|
73
|
+
'milestone.create': 'repo',
|
|
74
|
+
'pull.create': 'repo',
|
|
75
|
+
'pull.update': 'issue',
|
|
76
|
+
'pull.merge': 'issue',
|
|
77
|
+
'pull.review': 'issue',
|
|
78
|
+
'release.create': 'repo',
|
|
79
|
+
'release.update': 'repo',
|
|
80
|
+
'release.delete': 'repo',
|
|
81
|
+
'hook.read': 'repo',
|
|
82
|
+
'hook.create': 'repo',
|
|
83
|
+
'hook.delete': 'repo',
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/** The repo's `permissions` for its caller, as the drop-in answers them. */
|
|
87
|
+
export interface Permissions {
|
|
88
|
+
readonly push: boolean;
|
|
89
|
+
readonly pull: boolean;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Git's ceiling on the caller at the repo, as the drop-in gives it in `permissions`: `write` is
|
|
94
|
+
* `push`. A `report` token's ceiling reads as `read`, which hides more, never less.
|
|
95
|
+
*/
|
|
96
|
+
export const ceilingOf = (permissions: Permissions | undefined): TokenScope | undefined => {
|
|
97
|
+
if (permissions === undefined) return undefined;
|
|
98
|
+
|
|
99
|
+
return permissions.push ? 'write' : permissions.pull ? 'read' : undefined;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const Ask = Schema.Struct({
|
|
103
|
+
owner: Schema.String,
|
|
104
|
+
repo: Schema.String,
|
|
105
|
+
/** The issue the operations are on, when they're on one. */
|
|
106
|
+
number: Schema.optional(Schema.Number),
|
|
107
|
+
kinds: Schema.Array(Schema.Literals(pageOperations)),
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const RepoAnswer = Schema.Struct({
|
|
111
|
+
full_name: Schema.String,
|
|
112
|
+
private: Schema.Boolean,
|
|
113
|
+
permissions: Schema.optional(Schema.Struct({ push: Schema.Boolean, pull: Schema.Boolean })),
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const repoAnswer = Schema.decodeUnknownSync(RepoAnswer);
|
|
117
|
+
|
|
118
|
+
/** What `allowedFor` asks with: the request's context's own Git and drop-in, and both `authorize`s. */
|
|
119
|
+
export type AllowedContext = Pick<AppContext, 'api' | 'identify' | 'authorize' | 'authorizeGitHub'>;
|
|
120
|
+
|
|
121
|
+
/** What a page asks about: operations on a repo, or on one of its issues. */
|
|
122
|
+
export type Ask = typeof Ask.Type;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Of `ask.kinds`, those the holder of `token` may make on the repo, or on its issue `number`. It
|
|
126
|
+
* asks the drop-in's own `authorizeOperation` (Q517): of the caller Git identifies by the token, at
|
|
127
|
+
* Git's ceiling on them there, under the repo's current name, and then of the host's `authorize`.
|
|
128
|
+
* A host call's operation is Git's `authorize`'s to decide, for the person a session's token
|
|
129
|
+
* names, as `hostCall` makes it, past the token's ceiling; the admin's bearer holds no session.
|
|
130
|
+
* It asks about every kind at once, and answers them in the order `ask.kinds` names them.
|
|
131
|
+
*/
|
|
132
|
+
export const allowedFor = async (
|
|
133
|
+
context: AllowedContext,
|
|
134
|
+
access: {
|
|
135
|
+
readonly origin: string;
|
|
136
|
+
readonly token: string | undefined;
|
|
137
|
+
readonly signal: AbortSignal;
|
|
138
|
+
},
|
|
139
|
+
ask: Ask,
|
|
140
|
+
): Promise<readonly PageOperation[]> => {
|
|
141
|
+
const { origin, token, signal } = access;
|
|
142
|
+
const headers: HeadersInit = token === undefined ? {} : { authorization: `Bearer ${token}` };
|
|
143
|
+
const path = `/repos/${encodeURIComponent(ask.owner)}/${encodeURIComponent(ask.repo)}`;
|
|
144
|
+
// Who the token names and the caller's own read of the repo don't wait on each other.
|
|
145
|
+
const [identified, answered] = await Promise.all([
|
|
146
|
+
context.identify(new Request(`${origin}/api/v3/`, { headers })),
|
|
147
|
+
forward({ api: 'github', method: 'GET', path }, { origin, token, api: context.api }),
|
|
148
|
+
]);
|
|
149
|
+
if (identified.kind === 'error' || !answered.ok) return [];
|
|
150
|
+
|
|
151
|
+
const caller = identified.value;
|
|
152
|
+
const repo = repoAnswer(await answered.json());
|
|
153
|
+
const ceiling = ceilingOf(repo.permissions);
|
|
154
|
+
// The repo as the caller's own read of it answered, just above.
|
|
155
|
+
const visibility = { id: repo.full_name, public: !repo.private };
|
|
156
|
+
|
|
157
|
+
/** Whether the caller may make `kind` on the repo, or on its issue. */
|
|
158
|
+
const allows = async (kind: PageOperation) => {
|
|
159
|
+
// A host call is made for a session, whose credential is always one of Git's tokens.
|
|
160
|
+
if (isHostOperation(kind)) {
|
|
161
|
+
if (caller.token === undefined) return false;
|
|
162
|
+
|
|
163
|
+
const operation =
|
|
164
|
+
kind === 'push'
|
|
165
|
+
? { kind, repo: repo.full_name, updates: [] }
|
|
166
|
+
: { kind, repo: repo.full_name };
|
|
167
|
+
const decided = await context.authorize({
|
|
168
|
+
actor: caller.actor,
|
|
169
|
+
operation,
|
|
170
|
+
repo: visibility,
|
|
171
|
+
signal,
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
return decided.kind === 'accept';
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const onIssue = decidedOn[kind] === 'issue' && ask.number !== undefined;
|
|
178
|
+
const target = onIssue
|
|
179
|
+
? { repo: repo.full_name, number: ask.number }
|
|
180
|
+
: { repo: repo.full_name };
|
|
181
|
+
const refused = await authorizeOperation({
|
|
182
|
+
caller,
|
|
183
|
+
ceiling: credentialCeiling(ceiling),
|
|
184
|
+
operation: { ...target, kind },
|
|
185
|
+
repo: visibility,
|
|
186
|
+
host: context.authorizeGitHub,
|
|
187
|
+
signal,
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
return refused === undefined;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// Every check at once: one that throws rejects the whole answer, so no control is half decided.
|
|
194
|
+
const kinds = [...new Set(ask.kinds)];
|
|
195
|
+
const decided = await Promise.all(kinds.map(allows));
|
|
196
|
+
|
|
197
|
+
return kinds.filter((_, index) => decided[index] === true);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/** `allowedFor`, for the session's holder: the server function each page's controls ask. */
|
|
201
|
+
export const allowedOperations = createServerFn({ method: 'GET' })
|
|
202
|
+
.validator(Schema.decodeUnknownSync(Ask))
|
|
203
|
+
.handler(async ({ data, context }) => {
|
|
204
|
+
const request = getRequest();
|
|
205
|
+
const session = await context.session(request);
|
|
206
|
+
const access = {
|
|
207
|
+
origin: new URL(request.url).origin,
|
|
208
|
+
token: session?.token,
|
|
209
|
+
signal: request.signal,
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
return allowedFor(context, access, data);
|
|
213
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** `each` over `items`, at most `most` running at once, its answers in `items`' order. */
|
|
2
|
+
export const atMost = async <T, R>(
|
|
3
|
+
most: number,
|
|
4
|
+
items: readonly T[],
|
|
5
|
+
each: (item: T) => Promise<R>,
|
|
6
|
+
): Promise<R[]> => {
|
|
7
|
+
const answers = Array<R>(items.length);
|
|
8
|
+
// One iterator the runners share, so each item is taken by exactly one of them.
|
|
9
|
+
const pending = items.entries();
|
|
10
|
+
const runner = async () => {
|
|
11
|
+
for (const [at, item] of pending) answers[at] = await each(item);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
await Promise.all(Array.from({ length: Math.min(most, items.length) }, runner));
|
|
15
|
+
|
|
16
|
+
return answers;
|
|
17
|
+
};
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import * as Option from 'effect/Option';
|
|
2
|
+
import * as Schema from 'effect/Schema';
|
|
3
|
+
|
|
4
|
+
import type { AppContext, AvatarKind } from '../context/context.ts';
|
|
5
|
+
import { admin } from '../names/owners.ts';
|
|
6
|
+
import { allowedFor } from './allowed.ts';
|
|
7
|
+
import { forward } from './calls.ts';
|
|
8
|
+
import {
|
|
9
|
+
bytesUpTo,
|
|
10
|
+
hashOf,
|
|
11
|
+
iconBytesMost,
|
|
12
|
+
iconSideMost,
|
|
13
|
+
iconSideRefusal,
|
|
14
|
+
iconTypeRefusal,
|
|
15
|
+
sniffIcon,
|
|
16
|
+
} from './icon-bytes.ts';
|
|
17
|
+
import { atMost } from './at-most.ts';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* An avatar (Q757): a person's or an org's picture at `/icons/{login}`, which whoever the API's
|
|
21
|
+
* account lookup answers sees, and a repo's icon at `/icons/{owner}/{repo}`, which whoever can read
|
|
22
|
+
* the repo sees. Each is found as the session's holder, so one they can't see is a 404, the same
|
|
23
|
+
* as one with no picture. Each is set
|
|
24
|
+
* or removed from the app's own pages: a person's by them, an org's by its owners and admins, and
|
|
25
|
+
* a repo's by whoever may change its settings; the instance admin removes any.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/** What an avatar's route needs of the request's context: the drop-in, the policy and the avatars. */
|
|
29
|
+
export type AvatarContext = Pick<
|
|
30
|
+
AppContext,
|
|
31
|
+
'api' | 'session' | 'identify' | 'authorize' | 'authorizeGitHub' | 'avatars' | 'accounts'
|
|
32
|
+
>;
|
|
33
|
+
|
|
34
|
+
/** The account or repo an avatar is of, by its path's parts: a login, then a repo's name if any. */
|
|
35
|
+
export interface AvatarPlace {
|
|
36
|
+
readonly owner: string;
|
|
37
|
+
readonly repo?: string | undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Whose avatar a path names: its kind and the ID its row is under, and whether it's private. */
|
|
41
|
+
interface Target {
|
|
42
|
+
readonly kind: AvatarKind;
|
|
43
|
+
readonly id: string;
|
|
44
|
+
readonly private: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** An owner or a repo in an avatar's path: a name, never `.` or `..`, and never a `/`. */
|
|
48
|
+
const named = (name: string) => /^[A-Za-z0-9_.-]{1,100}$/.test(name) && !/^\.\.?$/.test(name);
|
|
49
|
+
|
|
50
|
+
const refused = (status: number, message: string) =>
|
|
51
|
+
Response.json({ message }, { status, headers: { 'cache-control': 'no-store' } });
|
|
52
|
+
|
|
53
|
+
const notFound = () => refused(404, 'Not Found');
|
|
54
|
+
|
|
55
|
+
const RepoAnswer = Schema.Struct({ id: Schema.Number, private: Schema.Boolean });
|
|
56
|
+
|
|
57
|
+
const repoAnswer = Schema.decodeUnknownOption(RepoAnswer);
|
|
58
|
+
|
|
59
|
+
/** The repo as the holder of `token` reads it, its REST `id` and whether it's private, or `undefined`. */
|
|
60
|
+
const readRepo = async (
|
|
61
|
+
context: AvatarContext,
|
|
62
|
+
origin: string,
|
|
63
|
+
token: string | undefined,
|
|
64
|
+
place: { readonly owner: string; readonly repo: string },
|
|
65
|
+
): Promise<Target | undefined> => {
|
|
66
|
+
if (!named(place.owner) || !named(place.repo)) return undefined;
|
|
67
|
+
|
|
68
|
+
const path = `/repos/${place.owner}/${place.repo}`;
|
|
69
|
+
const answer = await forward(
|
|
70
|
+
{ api: 'github', method: 'GET', path },
|
|
71
|
+
{ origin, token, api: context.api },
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
if (!answer.ok) {
|
|
75
|
+
await answer.body?.cancel();
|
|
76
|
+
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const read = Option.map(repoAnswer(await answer.json()), (repo) => ({
|
|
81
|
+
kind: 'repo' as const,
|
|
82
|
+
id: String(repo.id),
|
|
83
|
+
private: repo.private,
|
|
84
|
+
}));
|
|
85
|
+
|
|
86
|
+
return Option.getOrUndefined(read);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/** Whether the API's own `GET /users/{login}` answers `login` to the holder of `token`. */
|
|
90
|
+
const looksUp = async (
|
|
91
|
+
context: AvatarContext,
|
|
92
|
+
origin: string,
|
|
93
|
+
token: string | undefined,
|
|
94
|
+
login: string,
|
|
95
|
+
) => {
|
|
96
|
+
const answer = await forward(
|
|
97
|
+
{ api: 'github', method: 'GET', path: `/users/${login}` },
|
|
98
|
+
{ origin, token, api: context.api },
|
|
99
|
+
);
|
|
100
|
+
await answer.body?.cancel();
|
|
101
|
+
|
|
102
|
+
return answer.ok;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The person or org holding `login`, as the holder of `token` may see them: the API's own account
|
|
107
|
+
* lookup decides, so the picture has no access rule of its own, and an account it hides is a 404
|
|
108
|
+
* (the coordinator, 22 Nov). Its picture is private to the caller unless the lookup answers for
|
|
109
|
+
* anyone too, which a signed-in caller's second, anonymous lookup decides: one more at most.
|
|
110
|
+
* `accounts` only names the row's key, the account's Better Auth ID.
|
|
111
|
+
*/
|
|
112
|
+
const readAccount = async (
|
|
113
|
+
context: AvatarContext,
|
|
114
|
+
origin: string,
|
|
115
|
+
token: string | undefined,
|
|
116
|
+
login: string,
|
|
117
|
+
): Promise<Target | undefined> => {
|
|
118
|
+
if (!(await looksUp(context, origin, token, login))) return undefined;
|
|
119
|
+
|
|
120
|
+
const account = await context.accounts.account(login);
|
|
121
|
+
if (account === undefined) return undefined;
|
|
122
|
+
|
|
123
|
+
const hidden = token !== undefined && !(await looksUp(context, origin, undefined, login));
|
|
124
|
+
|
|
125
|
+
return { ...account, private: hidden };
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/** Whom an avatar may be cached for: the browser alone for a private one, else anyone. */
|
|
129
|
+
const cachedFor = (target: Target) => (target.private ? 'private' : 'public');
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Whose avatar `place` names, as the holder of `token` may see it: a repo as they read it, or the
|
|
133
|
+
* person or org holding the login as the account lookup answers them. Else `undefined`.
|
|
134
|
+
*/
|
|
135
|
+
const readTarget = async (
|
|
136
|
+
context: AvatarContext,
|
|
137
|
+
origin: string,
|
|
138
|
+
token: string | undefined,
|
|
139
|
+
place: AvatarPlace,
|
|
140
|
+
): Promise<Target | undefined> => {
|
|
141
|
+
if (place.repo !== undefined)
|
|
142
|
+
return readRepo(context, origin, token, { ...place, repo: place.repo });
|
|
143
|
+
|
|
144
|
+
return named(place.owner) ? readAccount(context, origin, token, place.owner) : undefined;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/** Whether `If-None-Match` names `etag`, as one of its list or as `*`. */
|
|
148
|
+
const matches = (header: string | null, etag: string) =>
|
|
149
|
+
header !== null &&
|
|
150
|
+
header.split(',').some((tag) => {
|
|
151
|
+
const each = tag.trim();
|
|
152
|
+
|
|
153
|
+
return each === '*' || each === etag || each === `W/${etag}`;
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* `GET /icons/{login}[?v={hash}]` or `GET /icons/{owner}/{repo}[?v={hash}]`: the avatar's bytes as
|
|
158
|
+
* their sniffed type, never sniffed again by the browser, and sandboxed. A private repo's icon is
|
|
159
|
+
* cached only by the browser, and so is a picture of an account the lookup hides from anyone
|
|
160
|
+
* signed out; a public repo's icon, and every other picture, by anyone.
|
|
161
|
+
* With the avatar's own hash as `v`, it's cached for a year; otherwise it's revalidated by its ETag
|
|
162
|
+
* each time, which answers 304 for the one the browser holds.
|
|
163
|
+
*/
|
|
164
|
+
export const serveAvatar = async (
|
|
165
|
+
context: AvatarContext,
|
|
166
|
+
request: Request,
|
|
167
|
+
place: AvatarPlace,
|
|
168
|
+
): Promise<Response> => {
|
|
169
|
+
const url = new URL(request.url);
|
|
170
|
+
const session = await context.session(request);
|
|
171
|
+
const target = await readTarget(context, url.origin, session?.token, place);
|
|
172
|
+
if (target === undefined) return notFound();
|
|
173
|
+
|
|
174
|
+
const icon = await context.avatars.get(target.kind, target.id);
|
|
175
|
+
if (icon === undefined) return notFound();
|
|
176
|
+
|
|
177
|
+
const etag = `"${icon.hash}"`;
|
|
178
|
+
const scope = cachedFor(target);
|
|
179
|
+
const kept = url.searchParams.get('v') === icon.hash ? 'max-age=31536000, immutable' : 'no-cache';
|
|
180
|
+
const headers = new Headers({ etag, 'cache-control': `${scope}, ${kept}` });
|
|
181
|
+
if (matches(request.headers.get('if-none-match'), etag))
|
|
182
|
+
return new Response(null, { status: 304, headers });
|
|
183
|
+
|
|
184
|
+
headers.set('content-type', icon.type);
|
|
185
|
+
headers.set('content-length', String(icon.bytes.length));
|
|
186
|
+
headers.set('x-content-type-options', 'nosniff');
|
|
187
|
+
headers.set('content-security-policy', "default-src 'none'; sandbox");
|
|
188
|
+
|
|
189
|
+
return new Response(new Uint8Array(icon.bytes), { headers });
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
/** The most repos one `GET /icons?repos=` names. */
|
|
193
|
+
export const iconHashesMost = 100;
|
|
194
|
+
|
|
195
|
+
/** How many of a batch's repos are read at once. */
|
|
196
|
+
export const iconReadsAtOnce = 8;
|
|
197
|
+
|
|
198
|
+
/** A batch's `{owner}/{repo}` as its owner and name, or `undefined` for anything else. */
|
|
199
|
+
const repoNamed = (name: string) => {
|
|
200
|
+
const [owner = '', repo = '', ...rest] = name.split('/');
|
|
201
|
+
|
|
202
|
+
return rest.length === 0 ? { owner, repo } : undefined;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
/** `names` once each, whatever their case, each as first asked. */
|
|
206
|
+
const firstOfEach = (names: readonly string[]) => {
|
|
207
|
+
const first = new Map<string, string>();
|
|
208
|
+
|
|
209
|
+
for (const name of names) {
|
|
210
|
+
const key = name.toLowerCase();
|
|
211
|
+
if (!first.has(key)) first.set(key, name);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return [...first.values()];
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* `GET /icons?repos={owner}/{repo},…`: the hash of each named repo's icon, keyed by its name as
|
|
219
|
+
* first asked, or `null` for a repo with none, which a repo the caller can't read, or one that
|
|
220
|
+
* doesn't exist, answers too. Each name gets `serveAvatar`'s own check, `GET /repos/{owner}/{repo}`
|
|
221
|
+
* as the caller, at most `iconReadsAtOnce` at once, and a name asked twice, in any case, once;
|
|
222
|
+
* then one read of their rows by REST id. More than `iconHashesMost` names is a 422, before any
|
|
223
|
+
* read. The answer is the caller's own, so it's `private, no-cache`.
|
|
224
|
+
*/
|
|
225
|
+
export const serveIconHashes = async (context: AvatarContext, request: Request) => {
|
|
226
|
+
const url = new URL(request.url);
|
|
227
|
+
const names = (url.searchParams.get('repos') ?? '').split(',').filter((name) => name !== '');
|
|
228
|
+
|
|
229
|
+
if (names.length > iconHashesMost) {
|
|
230
|
+
return refused(422, `A batch names at most ${iconHashesMost} repositories`);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const asked = firstOfEach(names);
|
|
234
|
+
const session = await context.session(request);
|
|
235
|
+
const repos = await atMost(iconReadsAtOnce, asked, async (name) => {
|
|
236
|
+
const place = repoNamed(name);
|
|
237
|
+
|
|
238
|
+
return place === undefined ? undefined : readRepo(context, url.origin, session?.token, place);
|
|
239
|
+
});
|
|
240
|
+
const ids = repos.flatMap((repo) => (repo === undefined ? [] : [repo.id]));
|
|
241
|
+
const hashes = await context.avatars.hashes('repo', ids);
|
|
242
|
+
|
|
243
|
+
const answer = Object.fromEntries(
|
|
244
|
+
asked.map((name, at) => {
|
|
245
|
+
const id = repos[at]?.id;
|
|
246
|
+
|
|
247
|
+
return [name, id === undefined ? null : (hashes.get(id) ?? null)];
|
|
248
|
+
}),
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
return Response.json(answer, { headers: { 'cache-control': 'private, no-cache' } });
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
/** Whom an avatar's change may be made by, as its refusal names them. */
|
|
255
|
+
const changers: Record<AvatarKind, string> = {
|
|
256
|
+
user: 'Only you change your own picture',
|
|
257
|
+
org: "Only the org's owners and admins change its picture",
|
|
258
|
+
repo: "Only the repo's admins change its icon",
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
/** What a write does to an avatar: sets it, or removes it. */
|
|
262
|
+
type Change = 'upload' | 'remove';
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Who asks to change an avatar: the session's person, from the app's own page, with their Git
|
|
266
|
+
* token, or the instance admin, by `ADMIN_TOKEN`'s bearer, from anywhere, as the API takes it,
|
|
267
|
+
* who reads the target as a visitor does.
|
|
268
|
+
*/
|
|
269
|
+
type Changer =
|
|
270
|
+
| { readonly admin: true; readonly origin: string }
|
|
271
|
+
| {
|
|
272
|
+
readonly admin: false;
|
|
273
|
+
readonly origin: string;
|
|
274
|
+
readonly token: string;
|
|
275
|
+
readonly login: string;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
/** The changer a write's request names, or the refusal to answer it. */
|
|
279
|
+
const changerOf = async (context: AvatarContext, request: Request) => {
|
|
280
|
+
const url = new URL(request.url);
|
|
281
|
+
|
|
282
|
+
if (request.headers.has('authorization')) {
|
|
283
|
+
const held = await context.identify(request);
|
|
284
|
+
const actor = held.kind === 'success' ? held.value.actor : undefined;
|
|
285
|
+
if (actor === undefined || actor.anonymous === true || actor.id !== admin.id)
|
|
286
|
+
return refused(403, 'Change the picture from the app');
|
|
287
|
+
|
|
288
|
+
return { admin: true, origin: url.origin } satisfies Changer;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (request.headers.get('origin') !== url.origin)
|
|
292
|
+
return refused(403, 'Change the picture from the app');
|
|
293
|
+
|
|
294
|
+
const session = await context.session(request);
|
|
295
|
+
if (session === undefined) return refused(401, 'Sign in to change a picture');
|
|
296
|
+
|
|
297
|
+
return {
|
|
298
|
+
admin: false,
|
|
299
|
+
origin: url.origin,
|
|
300
|
+
token: session.token,
|
|
301
|
+
login: session.login,
|
|
302
|
+
} satisfies Changer;
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* The one decision on who may make `change` to `target`, found at `place`: the instance admin
|
|
307
|
+
* removes any and uploads none; a person changes their own picture, an org's owners and admins
|
|
308
|
+
* its, and whoever Git's `authorize` lets change a repo's settings its icon, deciding
|
|
309
|
+
* `repo.update` for them as the settings page's controls ask.
|
|
310
|
+
*/
|
|
311
|
+
const mayChange = async (
|
|
312
|
+
context: AvatarContext,
|
|
313
|
+
request: Request,
|
|
314
|
+
changer: Changer,
|
|
315
|
+
change: Change,
|
|
316
|
+
place: AvatarPlace,
|
|
317
|
+
target: Target,
|
|
318
|
+
) => {
|
|
319
|
+
if (changer.admin) return change === 'remove';
|
|
320
|
+
|
|
321
|
+
// The login found the person, and logins differ in more than case, so case is no other person.
|
|
322
|
+
if (target.kind === 'user') return changer.login.toLowerCase() === place.owner.toLowerCase();
|
|
323
|
+
|
|
324
|
+
if (target.kind === 'org')
|
|
325
|
+
return (await context.accounts.membership(place.owner, changer.login))?.admin === true;
|
|
326
|
+
|
|
327
|
+
const repo = place.repo ?? '';
|
|
328
|
+
const { origin, token } = changer;
|
|
329
|
+
const allowed = await allowedFor(
|
|
330
|
+
context,
|
|
331
|
+
{ origin, token, signal: request.signal },
|
|
332
|
+
{ owner: place.owner, repo, kinds: ['repo.update'] },
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
return allowed.includes('repo.update');
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
/** Whose avatar `change` is for, once `mayChange` lets its changer make it. Else the refusal. */
|
|
339
|
+
const changeable = async (
|
|
340
|
+
context: AvatarContext,
|
|
341
|
+
request: Request,
|
|
342
|
+
place: AvatarPlace,
|
|
343
|
+
change: Change,
|
|
344
|
+
) => {
|
|
345
|
+
const changer = await changerOf(context, request);
|
|
346
|
+
if (changer instanceof Response) return changer;
|
|
347
|
+
|
|
348
|
+
const token = changer.admin ? undefined : changer.token;
|
|
349
|
+
const target = await readTarget(context, changer.origin, token, place);
|
|
350
|
+
if (target === undefined) return notFound();
|
|
351
|
+
|
|
352
|
+
if (!(await mayChange(context, request, changer, change, place, target)))
|
|
353
|
+
return refused(403, changer.admin ? adminRefusal : changers[target.kind]);
|
|
354
|
+
|
|
355
|
+
return target;
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
/** Why the instance admin's upload is refused: their token only removes. */
|
|
359
|
+
export const adminRefusal = "The instance admin removes a picture but doesn't upload one";
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* `PUT /icons/{login}` or `PUT /icons/{owner}/{repo}`: the body as the avatar, answering its hash.
|
|
363
|
+
* A body that names more than 1 MB is refused before it's read, and one that sends more is refused
|
|
364
|
+
* once the count passes it (413). Bytes that aren't PNG, JPEG or WebP by their signature, or whose
|
|
365
|
+
* header can't be read, are refused whatever their Content-Type says (415), and a picture over 1024
|
|
366
|
+
* pixels a side is refused by its header (422).
|
|
367
|
+
*/
|
|
368
|
+
export const uploadAvatar = async (
|
|
369
|
+
context: AvatarContext,
|
|
370
|
+
request: Request,
|
|
371
|
+
place: AvatarPlace,
|
|
372
|
+
): Promise<Response> => {
|
|
373
|
+
const length = Number(request.headers.get('content-length') ?? 0);
|
|
374
|
+
if (!(length <= iconBytesMost)) return refused(413, iconTypeRefusal);
|
|
375
|
+
|
|
376
|
+
const target = await changeable(context, request, place, 'upload');
|
|
377
|
+
if (target instanceof Response) return target;
|
|
378
|
+
|
|
379
|
+
const bytes = await bytesUpTo(request.body, iconBytesMost);
|
|
380
|
+
if (bytes === undefined) return refused(413, iconTypeRefusal);
|
|
381
|
+
|
|
382
|
+
const sniffed = sniffIcon(bytes);
|
|
383
|
+
if (sniffed === undefined) return refused(415, iconTypeRefusal);
|
|
384
|
+
|
|
385
|
+
if (sniffed.width > iconSideMost || sniffed.height > iconSideMost) {
|
|
386
|
+
return refused(422, iconSideRefusal);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const hash = await hashOf(bytes);
|
|
390
|
+
await context.avatars.put(target.kind, target.id, { type: sniffed.type, bytes, hash });
|
|
391
|
+
|
|
392
|
+
return Response.json({ hash }, { headers: { 'cache-control': 'no-store' } });
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* `DELETE /icons/{login}` or `DELETE /icons/{owner}/{repo}`: the avatar removed, by whoever may
|
|
397
|
+
* change it, or by the instance admin, whose token removes any.
|
|
398
|
+
*/
|
|
399
|
+
export const removeAvatar = async (
|
|
400
|
+
context: AvatarContext,
|
|
401
|
+
request: Request,
|
|
402
|
+
place: AvatarPlace,
|
|
403
|
+
): Promise<Response> => {
|
|
404
|
+
const target = await changeable(context, request, place, 'remove');
|
|
405
|
+
if (target instanceof Response) return target;
|
|
406
|
+
|
|
407
|
+
await context.avatars.remove(target.kind, target.id);
|
|
408
|
+
|
|
409
|
+
return new Response(null, { status: 204 });
|
|
410
|
+
};
|