ref0-git 0.0.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +127 -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 +562 -0
- package/app/apps/github/src/palette/recent.ts +116 -0
- package/app/apps/github/src/palette/rows.tsx +487 -0
- package/app/apps/github/src/palette/server.ts +107 -0
- package/app/apps/github/src/palette/targets.ts +306 -0
- package/app/apps/github/src/policy.ts +606 -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 +528 -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 +69 -0
- package/dist/cli/helpers.mjs +184 -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 +136 -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 +80 -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 +203 -0
- package/dist/init/node-app.mjs +189 -0
- package/dist/init/node.mjs +460 -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 +384 -0
- package/dist/init/versions.mjs +32 -0
- package/dist/init/workspace.mjs +20 -0
- package/package.json +48 -6
- package/README.md +0 -5
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import { createServerFn } from '@tanstack/react-start';
|
|
2
|
+
import { getRequest } from '@tanstack/react-start/server';
|
|
3
|
+
import * as Option from 'effect/Option';
|
|
4
|
+
import * as Schema from 'effect/Schema';
|
|
5
|
+
|
|
6
|
+
import type { TokenRecord as GitTokenRecord, TokenTarget } from '@ref0/git';
|
|
7
|
+
|
|
8
|
+
import type { AppContext, HostGit } from '../context/context.ts';
|
|
9
|
+
import { admin } from '../names/owners.ts';
|
|
10
|
+
import { hostSessionFor, hostSessionHeader } from '../signin/host-session.ts';
|
|
11
|
+
import { orgTokenView } from '../signin/orgs.ts';
|
|
12
|
+
import { atMost } from './at-most.ts';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The writes no Git token reaches, which the app makes as its signed-in person under the host's
|
|
16
|
+
* own sign-in (Q520): each named, with its route fixed here, never a path a page sends.
|
|
17
|
+
*/
|
|
18
|
+
const RepoSettings = Schema.Struct({
|
|
19
|
+
name: Schema.optional(Schema.String),
|
|
20
|
+
description: Schema.optional(Schema.String),
|
|
21
|
+
default_branch: Schema.optional(Schema.String),
|
|
22
|
+
private: Schema.optional(Schema.Boolean),
|
|
23
|
+
has_issues: Schema.optional(Schema.Boolean),
|
|
24
|
+
allow_merge_commit: Schema.optional(Schema.Boolean),
|
|
25
|
+
allow_squash_merge: Schema.optional(Schema.Boolean),
|
|
26
|
+
allow_rebase_merge: Schema.optional(Schema.Boolean),
|
|
27
|
+
delete_branch_on_merge: Schema.optional(Schema.Boolean),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const Repo = { owner: Schema.String, repo: Schema.String };
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The most days a token made here lives: a year, Git's `maxTokenLife`, which refuses a longer one.
|
|
34
|
+
* No entry point of @ref0/git exports it.
|
|
35
|
+
*/
|
|
36
|
+
export const tokenDaysMost = 365;
|
|
37
|
+
|
|
38
|
+
export const HostAsk = Schema.Union([
|
|
39
|
+
Schema.Struct({
|
|
40
|
+
operation: Schema.Literal('repo.create'),
|
|
41
|
+
owner: Schema.String,
|
|
42
|
+
name: Schema.String,
|
|
43
|
+
description: Schema.String,
|
|
44
|
+
private: Schema.Boolean,
|
|
45
|
+
}),
|
|
46
|
+
Schema.Struct({ operation: Schema.Literal('repo.update'), ...Repo, settings: RepoSettings }),
|
|
47
|
+
Schema.Struct({ operation: Schema.Literal('repo.delete'), ...Repo }),
|
|
48
|
+
Schema.Struct({
|
|
49
|
+
operation: Schema.Literal('token.list'),
|
|
50
|
+
/** The person's own login when absent, or an org of theirs (Q740). */
|
|
51
|
+
owner: Schema.optional(Schema.String),
|
|
52
|
+
/** Only the tokens that reach this one of the owner's repos, by its name, when given. */
|
|
53
|
+
repo: Schema.optional(Schema.String),
|
|
54
|
+
}),
|
|
55
|
+
Schema.Struct({
|
|
56
|
+
operation: Schema.Literal('token.create'),
|
|
57
|
+
scope: Schema.Literals(['read', 'report', 'write']),
|
|
58
|
+
/** The person's own login when absent, or an org they belong to (Q740). */
|
|
59
|
+
owner: Schema.optional(Schema.String),
|
|
60
|
+
/** One of the owner's repos, by its name under the owner, or all of them when absent. */
|
|
61
|
+
repo: Schema.optional(Schema.String),
|
|
62
|
+
days: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: tokenDaysMost })),
|
|
63
|
+
}),
|
|
64
|
+
Schema.Struct({ operation: Schema.Literal('token.revoke'), id: Schema.String }),
|
|
65
|
+
]);
|
|
66
|
+
|
|
67
|
+
export type HostAsk = typeof HostAsk.Type;
|
|
68
|
+
|
|
69
|
+
export type HostOperation = HostAsk['operation'];
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* What `hostCallFor` asks with: the Worker's APIs, the session key, Git's `identify`, the repo
|
|
73
|
+
* icons a repo's delete deletes, the person's orgs, and Git's direct lists an org's tokens are read
|
|
74
|
+
* through.
|
|
75
|
+
*/
|
|
76
|
+
export type HostContext = Pick<
|
|
77
|
+
AppContext,
|
|
78
|
+
'api' | 'sealKey' | 'identify' | 'session' | 'avatars' | 'accounts' | 'git'
|
|
79
|
+
>;
|
|
80
|
+
|
|
81
|
+
/** A token of the person's, as Git's REST lists it. */
|
|
82
|
+
export const TokenRecord = Schema.Struct({
|
|
83
|
+
id: Schema.String,
|
|
84
|
+
scope: Schema.String,
|
|
85
|
+
expiresAt: Schema.Number,
|
|
86
|
+
subject: Schema.Struct({ id: Schema.String }),
|
|
87
|
+
createdAt: Schema.Number,
|
|
88
|
+
revokedAt: Schema.optional(Schema.Number),
|
|
89
|
+
repo: Schema.optional(Schema.String),
|
|
90
|
+
prefix: Schema.optional(Schema.String),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
export type TokenRecord = typeof TokenRecord.Type;
|
|
94
|
+
|
|
95
|
+
/** How many of the person's repos their tokens are read from, and how many tokens each place. */
|
|
96
|
+
export const tokenRepos = 100;
|
|
97
|
+
|
|
98
|
+
export const tokensEach = 200;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* How many rows of each of an org's lists a plain member's tokens are found among, since every
|
|
102
|
+
* member's share them: past this many, `more` (Q740).
|
|
103
|
+
*/
|
|
104
|
+
const memberRowsEach = 1_000;
|
|
105
|
+
|
|
106
|
+
/** How many of Git's token lists a list reads at once. */
|
|
107
|
+
export const listsAtOnce = 8;
|
|
108
|
+
|
|
109
|
+
/** A token list's answer: the tokens read, whether Git held more, and whether they're everyone's. */
|
|
110
|
+
export const TokenListing = Schema.Struct({
|
|
111
|
+
tokens: Schema.Array(TokenRecord),
|
|
112
|
+
more: Schema.Boolean,
|
|
113
|
+
all: Schema.Boolean,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
export type TokenListing = typeof TokenListing.Type;
|
|
117
|
+
|
|
118
|
+
const refusal = (status: number, message: string) => Response.json({ message }, { status });
|
|
119
|
+
|
|
120
|
+
/** Git's token lists, as host code reads them. */
|
|
121
|
+
type TokenLists = NonNullable<HostGit['tokens']>;
|
|
122
|
+
|
|
123
|
+
/** A token's record as the page shows it, from Git's. */
|
|
124
|
+
const tokenRecord = (token: GitTokenRecord): TokenRecord => {
|
|
125
|
+
const coverage = token.repo === undefined ? { prefix: token.prefix } : { repo: token.repo };
|
|
126
|
+
const record = {
|
|
127
|
+
id: token.id,
|
|
128
|
+
scope: token.scope,
|
|
129
|
+
expiresAt: token.expiresAt,
|
|
130
|
+
createdAt: token.createdAt,
|
|
131
|
+
subject: { id: token.subject.id },
|
|
132
|
+
...coverage,
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
return token.revokedAt === undefined ? record : { ...record, revokedAt: token.revokedAt };
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/** The bodies these writes send the drop-in, each as GitHub's or Git's REST takes it, as JSON. */
|
|
139
|
+
const encodeRepoCreate = Schema.encodeSync(
|
|
140
|
+
Schema.fromJsonString(
|
|
141
|
+
Schema.Struct({ name: Schema.String, description: Schema.String, private: Schema.Boolean }),
|
|
142
|
+
),
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
const encodeRepoSettings = Schema.encodeSync(Schema.fromJsonString(RepoSettings));
|
|
146
|
+
|
|
147
|
+
const encodeTokenCreate = Schema.encodeSync(
|
|
148
|
+
Schema.fromJsonString(
|
|
149
|
+
Schema.Struct({
|
|
150
|
+
scope: Schema.Literals(['read', 'report', 'write']),
|
|
151
|
+
expiresAt: Schema.Number,
|
|
152
|
+
subject: Schema.Struct({ id: Schema.String }),
|
|
153
|
+
}),
|
|
154
|
+
),
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
/** One call as the host session of `login`, to `path` on the Worker's origin. */
|
|
158
|
+
const callAs = async (
|
|
159
|
+
context: HostContext,
|
|
160
|
+
origin: string,
|
|
161
|
+
login: string,
|
|
162
|
+
call: { readonly method: string; readonly path: string; readonly json?: string },
|
|
163
|
+
) => {
|
|
164
|
+
const headers = new Headers({ accept: 'application/json' });
|
|
165
|
+
headers.set(hostSessionHeader, await hostSessionFor(context.sealKey, login));
|
|
166
|
+
|
|
167
|
+
if (call.json !== undefined) headers.set('content-type', 'application/json');
|
|
168
|
+
|
|
169
|
+
return context.api(
|
|
170
|
+
new Request(new URL(call.path, origin), {
|
|
171
|
+
method: call.method,
|
|
172
|
+
headers,
|
|
173
|
+
body: call.json ?? null,
|
|
174
|
+
}),
|
|
175
|
+
);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const segment = encodeURIComponent;
|
|
179
|
+
|
|
180
|
+
/** A repo's route on the drop-in, as GitHub's. */
|
|
181
|
+
const repoPath = (owner: string, repo: string) =>
|
|
182
|
+
`/api/v3/repos/${segment(owner)}/${segment(repo)}`;
|
|
183
|
+
|
|
184
|
+
const repoId = Schema.decodeUnknownOption(Schema.Struct({ id: Schema.Number }));
|
|
185
|
+
|
|
186
|
+
/** A token place's list as host code reads it, `rows` at most, and whether more followed. */
|
|
187
|
+
const listed = async (tokens: TokenLists, target: TokenTarget, rows: number) => {
|
|
188
|
+
const items: GitTokenRecord[] = [];
|
|
189
|
+
let after: string | undefined;
|
|
190
|
+
|
|
191
|
+
while (items.length < rows) {
|
|
192
|
+
const limit = Math.min(tokensEach, rows - items.length);
|
|
193
|
+
const page = await tokens.list(target, {
|
|
194
|
+
state: 'all',
|
|
195
|
+
page: after === undefined ? { limit } : { limit, after },
|
|
196
|
+
});
|
|
197
|
+
if (page.kind !== 'success') return page;
|
|
198
|
+
|
|
199
|
+
items.push(...page.value.items);
|
|
200
|
+
after = page.value.next;
|
|
201
|
+
|
|
202
|
+
if (after === undefined) return { kind: 'success' as const, items, more: false };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return { kind: 'success' as const, items, more: true };
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/** Git couldn't answer one of a list's reads, so the list isn't whole: 503, never a short list. */
|
|
209
|
+
const listUnavailable = () => refusal(503, "Git couldn't list the tokens: try again");
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* The tokens over `owner`, the person's own login or an org, or over `owner/repo` and all of
|
|
213
|
+
* `owner`'s, read through Git's direct calls once the person's place there decided (Q521, Q740):
|
|
214
|
+
* their own over their login, every member's for an org's owner or admin, `all`, and their own
|
|
215
|
+
* for a plain member. Each list holds the first `tokensEach` rows, or `memberRowsEach` for a plain
|
|
216
|
+
* member's, which every member's share. 404 for an org the person isn't in, or a repo that isn't
|
|
217
|
+
* there, and 503 when Git couldn't answer.
|
|
218
|
+
*/
|
|
219
|
+
const tokensOf = async (
|
|
220
|
+
context: HostContext,
|
|
221
|
+
login: string,
|
|
222
|
+
place: { readonly owner: string; readonly repo?: string | undefined },
|
|
223
|
+
) => {
|
|
224
|
+
const missing = refusal(404, place.repo === undefined ? 'No such org' : 'No such repo');
|
|
225
|
+
// Whose tokens the person sees here: their own login's, an org's as a member, or everyone's.
|
|
226
|
+
const view =
|
|
227
|
+
place.owner === login
|
|
228
|
+
? 'self'
|
|
229
|
+
: orgTokenView(await context.accounts.membership(place.owner, login));
|
|
230
|
+
const tokens = context.git.tokens;
|
|
231
|
+
if (view === undefined || tokens === undefined) return missing;
|
|
232
|
+
|
|
233
|
+
const prefix = `${place.owner}/`;
|
|
234
|
+
const repos =
|
|
235
|
+
place.repo === undefined
|
|
236
|
+
? await context.git.repos.list({ actor: admin, prefix, page: { limit: tokenRepos } })
|
|
237
|
+
: { kind: 'success' as const, value: { items: [`${prefix}${place.repo}`] } };
|
|
238
|
+
if (repos.kind !== 'success') return listUnavailable();
|
|
239
|
+
|
|
240
|
+
const rows = view === 'member' ? memberRowsEach : tokensEach;
|
|
241
|
+
const targets: TokenTarget[] = [{ prefix }, ...repos.value.items];
|
|
242
|
+
const lists = await atMost(listsAtOnce, targets, async (target) => listed(tokens, target, rows));
|
|
243
|
+
const failed = lists.some((list) => list.kind === 'error' && list.error.code !== 'NOT_FOUND');
|
|
244
|
+
if (failed) return listUnavailable();
|
|
245
|
+
|
|
246
|
+
// A repo deleted since its name was read holds no tokens, but the one asked for is missing.
|
|
247
|
+
if (place.repo !== undefined && lists[1]?.kind !== 'success') return missing;
|
|
248
|
+
|
|
249
|
+
const read = lists.flatMap((list) => (list.kind === 'success' ? [list] : []));
|
|
250
|
+
const every = read.flatMap((list) => list.items).map((token) => tokenRecord(token));
|
|
251
|
+
const more =
|
|
252
|
+
('next' in repos.value && repos.value.next !== undefined) || read.some((list) => list.more);
|
|
253
|
+
|
|
254
|
+
const all = view === 'all';
|
|
255
|
+
const answer: TokenListing = {
|
|
256
|
+
tokens: all ? every : every.filter((token) => token.subject.id === login),
|
|
257
|
+
more,
|
|
258
|
+
all,
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
return Response.json(answer);
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
/** The route each repo write takes, as the drop-in serves GitHub's. */
|
|
265
|
+
const repoWrite = (ask: HostAsk, login: string) => {
|
|
266
|
+
switch (ask.operation) {
|
|
267
|
+
case 'repo.create': {
|
|
268
|
+
const json = encodeRepoCreate({
|
|
269
|
+
name: ask.name,
|
|
270
|
+
description: ask.description,
|
|
271
|
+
private: ask.private,
|
|
272
|
+
});
|
|
273
|
+
const path =
|
|
274
|
+
ask.owner === login ? '/api/v3/user/repos' : `/api/v3/orgs/${segment(ask.owner)}/repos`;
|
|
275
|
+
|
|
276
|
+
return { method: 'POST', path, json };
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
case 'repo.update':
|
|
280
|
+
return {
|
|
281
|
+
method: 'PATCH',
|
|
282
|
+
path: repoPath(ask.owner, ask.repo),
|
|
283
|
+
json: encodeRepoSettings(ask.settings),
|
|
284
|
+
};
|
|
285
|
+
default:
|
|
286
|
+
return undefined;
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* The repo deleted as `login`, and its icon with it, by the repo's REST `id`, read first, since the
|
|
292
|
+
* delete answers none. A repo deleted around the app, straight through the API, keeps its icon's row.
|
|
293
|
+
*/
|
|
294
|
+
const deleteRepo = async (
|
|
295
|
+
context: HostContext,
|
|
296
|
+
origin: string,
|
|
297
|
+
login: string,
|
|
298
|
+
place: { readonly owner: string; readonly repo: string },
|
|
299
|
+
) => {
|
|
300
|
+
const path = repoPath(place.owner, place.repo);
|
|
301
|
+
const found = await callAs(context, origin, login, { method: 'GET', path });
|
|
302
|
+
const repo = found.ok ? Option.getOrUndefined(repoId(await found.json())) : undefined;
|
|
303
|
+
if (!found.ok) await found.body?.cancel();
|
|
304
|
+
|
|
305
|
+
const deleted = await callAs(context, origin, login, { method: 'DELETE', path });
|
|
306
|
+
if (deleted.ok && repo !== undefined) await context.avatars.remove('repo', String(repo.id));
|
|
307
|
+
|
|
308
|
+
return deleted;
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* `ask`, made as the session's person through the host's sign-in, or refused (Q520): only a POST
|
|
313
|
+
* from the app's own origin, only for a session whose token Git still takes, so sign-out ends it.
|
|
314
|
+
* A token is made for the person alone, its subject set here, over their own login or an org they
|
|
315
|
+
* belong to (Q521, Q740), as the policy decides. An org's tokens are listed once the person's role
|
|
316
|
+
* there is read: every member's for its owners and admins, their own for anyone else. A revoke is
|
|
317
|
+
* Git's, as the person, which the policy decides by the token's own subject.
|
|
318
|
+
*/
|
|
319
|
+
export const hostCallFor = async (
|
|
320
|
+
context: HostContext,
|
|
321
|
+
request: Request,
|
|
322
|
+
ask: HostAsk,
|
|
323
|
+
): Promise<Response> => {
|
|
324
|
+
const origin = new URL(request.url).origin;
|
|
325
|
+
|
|
326
|
+
if (request.method !== 'POST' || request.headers.get('origin') !== origin) {
|
|
327
|
+
return refusal(403, 'Make this change from the app');
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const session = await context.session(request);
|
|
331
|
+
if (session === undefined) return refusal(401, 'Sign in first');
|
|
332
|
+
|
|
333
|
+
const headers = { authorization: `Bearer ${session.token}` };
|
|
334
|
+
const held = await context.identify(new Request(origin, { headers }));
|
|
335
|
+
const actor = held.kind === 'success' ? held.value.actor : undefined;
|
|
336
|
+
|
|
337
|
+
if (actor === undefined || actor.anonymous === true || actor.id !== session.login) {
|
|
338
|
+
return refusal(401, 'Your sign-in has ended: sign in again');
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const login = session.login;
|
|
342
|
+
if (ask.operation === 'repo.delete') return deleteRepo(context, origin, login, ask);
|
|
343
|
+
|
|
344
|
+
const write = repoWrite(ask, login);
|
|
345
|
+
if (write !== undefined) return callAs(context, origin, login, write);
|
|
346
|
+
|
|
347
|
+
if (ask.operation === 'token.list') {
|
|
348
|
+
return tokensOf(context, login, { owner: ask.owner ?? login, repo: ask.repo });
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (ask.operation === 'token.create') {
|
|
352
|
+
const owner = ask.owner ?? login;
|
|
353
|
+
const path =
|
|
354
|
+
ask.repo === undefined
|
|
355
|
+
? `/tokens?prefix=${segment(`${owner}/`)}`
|
|
356
|
+
: `/repos/${segment(owner)}/${segment(ask.repo)}/-/tokens`;
|
|
357
|
+
const json = encodeTokenCreate({
|
|
358
|
+
scope: ask.scope,
|
|
359
|
+
expiresAt: Date.now() + ask.days * 24 * 60 * 60 * 1000,
|
|
360
|
+
subject: { id: login },
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
return callAs(context, origin, login, { method: 'POST', path, json });
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (ask.operation !== 'token.revoke') return refusal(400, 'Not a host call');
|
|
367
|
+
|
|
368
|
+
// Git asks the policy with the token's own subject, so a person revokes their own, and an org's
|
|
369
|
+
// owners and admins any over it; any other is the unknown ID's `NOT_FOUND` (Q740).
|
|
370
|
+
const path = `/tokens/${segment(ask.id)}`;
|
|
371
|
+
const revoked = await callAs(context, origin, login, { method: 'DELETE', path });
|
|
372
|
+
if (revoked.status !== 404) return revoked;
|
|
373
|
+
|
|
374
|
+
await revoked.body?.cancel();
|
|
375
|
+
|
|
376
|
+
return refusal(404, 'No such token of yours');
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
/** `hostCallFor`, as the server function a page's settings and tokens forms call. */
|
|
380
|
+
export const hostCall = createServerFn({ method: 'POST' })
|
|
381
|
+
.validator(Schema.decodeUnknownSync(HostAsk))
|
|
382
|
+
.handler(({ data, context }) => hostCallFor(context, getRequest(), data));
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A repo icon's bytes, judged by the bytes alone (Q756): its type from its signature, never a
|
|
3
|
+
* Content-Type or a file name, its pixels from its header, and its count as it's read.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** The most bytes an icon has: 1 MB. */
|
|
7
|
+
export const iconBytesMost = 1_048_576;
|
|
8
|
+
|
|
9
|
+
/** The most pixels an icon's side has. */
|
|
10
|
+
export const iconSideMost = 1024;
|
|
11
|
+
|
|
12
|
+
/** The refusal of bytes that aren't PNG, JPEG or WebP, or are too many. */
|
|
13
|
+
export const iconTypeRefusal = 'Icons must be PNG, JPEG or WebP, up to 1 MB';
|
|
14
|
+
|
|
15
|
+
/** The refusal of an icon wider or taller than `iconSideMost`. */
|
|
16
|
+
export const iconSideRefusal = 'Icons must be at most 1024 by 1024 pixels';
|
|
17
|
+
|
|
18
|
+
/** The types an icon may have, each served as itself. */
|
|
19
|
+
export type IconType = 'image/png' | 'image/jpeg' | 'image/webp';
|
|
20
|
+
|
|
21
|
+
/** An icon's type, from its signature, and its pixels, from its header. */
|
|
22
|
+
export interface Sniffed {
|
|
23
|
+
readonly type: IconType;
|
|
24
|
+
readonly width: number;
|
|
25
|
+
readonly height: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const startsWith = (bytes: Uint8Array, at: number, expected: readonly number[]) =>
|
|
29
|
+
bytes.length >= at + expected.length &&
|
|
30
|
+
expected.every((byte, index) => bytes[at + index] === byte);
|
|
31
|
+
|
|
32
|
+
const ascii = (text: string) => Array.from(new TextEncoder().encode(text));
|
|
33
|
+
|
|
34
|
+
const bigEndian = (bytes: Uint8Array, at: number, count: number) => {
|
|
35
|
+
let value = 0;
|
|
36
|
+
|
|
37
|
+
for (let index = 0; index < count; index += 1) value = value * 256 + (bytes[at + index] ?? 0);
|
|
38
|
+
|
|
39
|
+
return value;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const littleEndian = (bytes: Uint8Array, at: number, count: number) => {
|
|
43
|
+
let value = 0;
|
|
44
|
+
|
|
45
|
+
for (let index = count - 1; index >= 0; index -= 1)
|
|
46
|
+
value = value * 256 + (bytes[at + index] ?? 0);
|
|
47
|
+
|
|
48
|
+
return value;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** Pixels a header names, or `undefined` for a side of none. */
|
|
52
|
+
const sides = (type: IconType, width: number, height: number): Sniffed | undefined =>
|
|
53
|
+
width > 0 && height > 0 ? { type, width, height } : undefined;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* PNG's: its signature, then IHDR, whose width and height are its first eight bytes. The chunk is
|
|
57
|
+
* whole, its length 13 and its 13 bytes and CRC all there, or a cut-off file passes as a picture.
|
|
58
|
+
*/
|
|
59
|
+
const png = (bytes: Uint8Array) => {
|
|
60
|
+
if (!startsWith(bytes, 0, [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])) return undefined;
|
|
61
|
+
|
|
62
|
+
if (bytes.length < 33 || bigEndian(bytes, 8, 4) !== 13 || !startsWith(bytes, 12, ascii('IHDR'))) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return sides('image/png', bigEndian(bytes, 16, 4), bigEndian(bytes, 20, 4));
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/** The markers that stand alone, with no length: TEM, and RST0 to RST7. */
|
|
70
|
+
const standalone = (marker: number) => marker === 0x01 || (marker >= 0xd0 && marker <= 0xd7);
|
|
71
|
+
|
|
72
|
+
/** A start of frame, SOF0 to SOF15: every Cn but DHT (C4), JPG (C8) and DAC (CC). */
|
|
73
|
+
const startOfFrame = (marker: number) =>
|
|
74
|
+
marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc;
|
|
75
|
+
|
|
76
|
+
/** JPEG's: its markers walked from SOI to the first start of frame, which holds its height and width. */
|
|
77
|
+
const jpeg = (bytes: Uint8Array) => {
|
|
78
|
+
if (!startsWith(bytes, 0, [0xff, 0xd8, 0xff])) return undefined;
|
|
79
|
+
|
|
80
|
+
let at = 2;
|
|
81
|
+
|
|
82
|
+
while (at < bytes.length) {
|
|
83
|
+
if (bytes[at] !== 0xff) return undefined;
|
|
84
|
+
|
|
85
|
+
// Any number of 0xFF fill bytes may come before a marker.
|
|
86
|
+
while (bytes[at] === 0xff) at += 1;
|
|
87
|
+
const marker = bytes[at];
|
|
88
|
+
at += 1;
|
|
89
|
+
|
|
90
|
+
if (marker === undefined) return undefined;
|
|
91
|
+
|
|
92
|
+
if (standalone(marker)) continue;
|
|
93
|
+
|
|
94
|
+
// An image's end or its scan before a frame: no frame to read.
|
|
95
|
+
if (marker === 0xd9 || marker === 0xda) return undefined;
|
|
96
|
+
|
|
97
|
+
const length = bigEndian(bytes, at, 2);
|
|
98
|
+
if (length < 2 || at + length > bytes.length) return undefined;
|
|
99
|
+
|
|
100
|
+
if (startOfFrame(marker)) {
|
|
101
|
+
if (length < 7) return undefined;
|
|
102
|
+
|
|
103
|
+
return sides('image/jpeg', bigEndian(bytes, at + 5, 2), bigEndian(bytes, at + 3, 2));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
at += length;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return undefined;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/** WebP's: RIFF's `WEBP`, then its first chunk, VP8, VP8L or VP8X, each with its own header. */
|
|
113
|
+
const webp = (bytes: Uint8Array) => {
|
|
114
|
+
if (!startsWith(bytes, 0, ascii('RIFF')) || !startsWith(bytes, 8, ascii('WEBP')))
|
|
115
|
+
return undefined;
|
|
116
|
+
|
|
117
|
+
const data = 20;
|
|
118
|
+
|
|
119
|
+
// Lossy: a key frame's three-byte tag, its start code, then 14-bit width and height.
|
|
120
|
+
if (startsWith(bytes, 12, ascii('VP8 '))) {
|
|
121
|
+
if (bytes.length < data + 10 || !startsWith(bytes, data + 3, [0x9d, 0x01, 0x2a]))
|
|
122
|
+
return undefined;
|
|
123
|
+
|
|
124
|
+
const width = littleEndian(bytes, data + 6, 2) & 0x3fff;
|
|
125
|
+
const height = littleEndian(bytes, data + 8, 2) & 0x3fff;
|
|
126
|
+
|
|
127
|
+
return sides('image/webp', width, height);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Lossless: its signature byte, then 14 bits each of width less one and height less one.
|
|
131
|
+
if (startsWith(bytes, 12, ascii('VP8L'))) {
|
|
132
|
+
if (bytes.length < data + 5 || bytes[data] !== 0x2f) return undefined;
|
|
133
|
+
|
|
134
|
+
const bits = littleEndian(bytes, data + 1, 4);
|
|
135
|
+
const width = (bits & 0x3fff) + 1;
|
|
136
|
+
const height = ((bits >>> 14) & 0x3fff) + 1;
|
|
137
|
+
|
|
138
|
+
return sides('image/webp', width, height);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Extended: flags and reserved bytes, then 24 bits each of canvas width less one and height less one.
|
|
142
|
+
if (startsWith(bytes, 12, ascii('VP8X'))) {
|
|
143
|
+
if (bytes.length < data + 10) return undefined;
|
|
144
|
+
|
|
145
|
+
const width = littleEndian(bytes, data + 4, 3) + 1;
|
|
146
|
+
const height = littleEndian(bytes, data + 7, 3) + 1;
|
|
147
|
+
|
|
148
|
+
return sides('image/webp', width, height);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return undefined;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/** The icon `bytes` are, by their signature and header, or `undefined` for anything else. */
|
|
155
|
+
export const sniffIcon = (bytes: Uint8Array): Sniffed | undefined =>
|
|
156
|
+
png(bytes) ?? jpeg(bytes) ?? webp(bytes);
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* A body's bytes, counted as they're read, or `undefined` once the count passes `most`: the read
|
|
160
|
+
* stops there and the rest is never read, whether or not the body named its length.
|
|
161
|
+
*/
|
|
162
|
+
export const bytesUpTo = async (
|
|
163
|
+
body: ReadableStream<Uint8Array> | null,
|
|
164
|
+
most: number,
|
|
165
|
+
): Promise<Uint8Array | undefined> => {
|
|
166
|
+
if (body === null) return new Uint8Array();
|
|
167
|
+
|
|
168
|
+
const reader = body.getReader();
|
|
169
|
+
const chunks: Uint8Array[] = [];
|
|
170
|
+
let count = 0;
|
|
171
|
+
|
|
172
|
+
for (;;) {
|
|
173
|
+
const { done, value } = await reader.read();
|
|
174
|
+
if (done) break;
|
|
175
|
+
|
|
176
|
+
count += value.length;
|
|
177
|
+
|
|
178
|
+
if (count > most) {
|
|
179
|
+
await reader.cancel();
|
|
180
|
+
|
|
181
|
+
return undefined;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
chunks.push(value);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const bytes = new Uint8Array(count);
|
|
188
|
+
let at = 0;
|
|
189
|
+
|
|
190
|
+
for (const chunk of chunks) {
|
|
191
|
+
bytes.set(chunk, at);
|
|
192
|
+
at += chunk.length;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return bytes;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/** The SHA-256 of `bytes`, in hex: an icon's ETag and its version. */
|
|
199
|
+
export const hashOf = async (bytes: Uint8Array) => {
|
|
200
|
+
const digest = new Uint8Array(await crypto.subtle.digest('SHA-256', new Uint8Array(bytes)));
|
|
201
|
+
|
|
202
|
+
return Array.from(digest, (byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
203
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createServerFn } from '@tanstack/react-start';
|
|
2
|
+
import { getRequest } from '@tanstack/react-start/server';
|
|
3
|
+
|
|
4
|
+
import type { AppContext } from '../context/context.ts';
|
|
5
|
+
import { type ApiCall, forward, parseCall } from './calls.ts';
|
|
6
|
+
import { endedHeader } from './session-ended.ts';
|
|
7
|
+
|
|
8
|
+
/** What a proxied call asks with: the APIs, and the request's session, which it can end. */
|
|
9
|
+
export type ProxyContext = Pick<AppContext, 'api' | 'session' | 'endSession'>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* `answer`, marked with `endedHeader`: the session it was asked under has ended. It's never
|
|
13
|
+
* stored, so no cache gives the mark, or the answer the session was refused with, again.
|
|
14
|
+
*/
|
|
15
|
+
const markedEnded = (answer: Response) => {
|
|
16
|
+
const headers = new Headers(answer.headers);
|
|
17
|
+
headers.set(endedHeader, 'true');
|
|
18
|
+
headers.set('cache-control', 'no-store');
|
|
19
|
+
|
|
20
|
+
return new Response(answer.body, {
|
|
21
|
+
status: answer.status,
|
|
22
|
+
statusText: answer.statusText,
|
|
23
|
+
headers,
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* `call`, sent as the request's session's holder. When Git refuses the token, revoked or lost with
|
|
29
|
+
* Git's state, the session ends, and the answer is marked with `endedHeader`. A read is sent again
|
|
30
|
+
* as no one, so its answer is a visitor's. A write keeps its 401: sending it again would change who
|
|
31
|
+
* asks, and a host that lets a visitor write would take it as theirs.
|
|
32
|
+
*/
|
|
33
|
+
export const proxied = async (
|
|
34
|
+
context: ProxyContext,
|
|
35
|
+
request: Request,
|
|
36
|
+
call: ApiCall,
|
|
37
|
+
): Promise<Response> => {
|
|
38
|
+
const origin = new URL(request.url).origin;
|
|
39
|
+
const session = await context.session(request);
|
|
40
|
+
const answer = await forward(call, { origin, token: session?.token, api: context.api });
|
|
41
|
+
if (session === undefined || answer.status !== 401) return answer;
|
|
42
|
+
|
|
43
|
+
await context.endSession(request);
|
|
44
|
+
|
|
45
|
+
if (call.method !== 'GET' && call.method !== 'HEAD') return markedEnded(answer);
|
|
46
|
+
|
|
47
|
+
await answer.body?.cancel();
|
|
48
|
+
|
|
49
|
+
return markedEnded(await forward(call, { origin, token: undefined, api: context.api }));
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* One API call, made on the server as the session's holder and answered with the API's own
|
|
54
|
+
* response. The browser sends the call and never sees the token; a call outside its API's URLs
|
|
55
|
+
* is refused before it's sent, and a redirect is followed here, within the API.
|
|
56
|
+
*/
|
|
57
|
+
export const callApi = createServerFn({ method: 'POST' })
|
|
58
|
+
.validator(parseCall)
|
|
59
|
+
.handler(async ({ data, context }) => proxied(context, getRequest(), data));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** The header `callApi` marks its answer with once Git refused the session's token and it ended. */
|
|
2
|
+
export const endedHeader = 'x-ref0-session-ended';
|
|
3
|
+
|
|
4
|
+
const listeners = new Set<() => void>();
|
|
5
|
+
|
|
6
|
+
/** Calls `listener` each time an answer says the session ended, until the returned call stops it. */
|
|
7
|
+
export const onSessionEnded = (listener: () => void): (() => void) => {
|
|
8
|
+
listeners.add(listener);
|
|
9
|
+
|
|
10
|
+
return () => {
|
|
11
|
+
listeners.delete(listener);
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/** Tells each listener the session ended: the browser's clients call it on an `endedHeader`. */
|
|
16
|
+
export const sessionEnded = () => {
|
|
17
|
+
for (const listener of listeners) listener();
|
|
18
|
+
};
|