ref0-git 0.0.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +48 -6
- package/README.md +0 -5
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import type { PeopleAccountKind, PeopleFound, PeopleOrgRole } from '@ref0/github';
|
|
2
|
+
import type { DBAdapter } from 'better-auth';
|
|
3
|
+
|
|
4
|
+
import type { Accounts, Membership } from '../context/context.ts';
|
|
5
|
+
import { isHeld } from './owner-names.ts';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The host's people and orgs, as Better Auth's tables keep them (Q636): a person by their
|
|
9
|
+
* username, an org by its slug, and who belongs to which by the organization plugin's `member`
|
|
10
|
+
* rows, read through Better Auth's adapter, never its HTTP routes.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** A page of logins, in login order, and the login to go on after when more follow. */
|
|
14
|
+
export interface Logins {
|
|
15
|
+
readonly logins: readonly string[];
|
|
16
|
+
readonly next?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Where a page of logins starts, past `after`, and how many it holds at most. */
|
|
20
|
+
export interface LoginsPage {
|
|
21
|
+
readonly after?: string | undefined;
|
|
22
|
+
readonly limit: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A person who has signed up: the name they go by, which is their login when they gave none, and
|
|
27
|
+
* their row's ID, which a rename keeps.
|
|
28
|
+
*/
|
|
29
|
+
export interface SignedUp {
|
|
30
|
+
readonly name: string;
|
|
31
|
+
readonly id: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface Orgs extends Accounts {
|
|
35
|
+
/** Whether a person or an org holds `login`, so a repo may be made under it. */
|
|
36
|
+
readonly held: (login: string) => Promise<boolean>;
|
|
37
|
+
/** The person who signed up as `login`, or `undefined` when no one has. */
|
|
38
|
+
readonly person: (login: string) => Promise<SignedUp | undefined>;
|
|
39
|
+
/** Whether an org was made as `login`. */
|
|
40
|
+
readonly org: (login: string) => Promise<boolean>;
|
|
41
|
+
/** Which of `logins` belong to the org `org`, in any role, each once, in login order. */
|
|
42
|
+
readonly among: (org: string, logins: readonly string[]) => Promise<readonly string[]>;
|
|
43
|
+
/**
|
|
44
|
+
* A page of the org's members in `role`, as GitHub's `role` reads: `admin` its owners and admins,
|
|
45
|
+
* `member` the rest, and `all` each.
|
|
46
|
+
*/
|
|
47
|
+
readonly members: (
|
|
48
|
+
org: string,
|
|
49
|
+
page: LoginsPage & { readonly role: PeopleOrgRole },
|
|
50
|
+
) => Promise<Logins>;
|
|
51
|
+
/** A page of the orgs the person `login` belongs to. */
|
|
52
|
+
readonly orgsOf: (login: string, page: LoginsPage) => Promise<Logins>;
|
|
53
|
+
/**
|
|
54
|
+
* The people whose username starts with `prefix`, in any case, and the orgs whose slug does, at
|
|
55
|
+
* most `limit` in all, people first, each in login order: a range of each table's unique index,
|
|
56
|
+
* so nothing scans. A person's name isn't matched: no index holds it.
|
|
57
|
+
*/
|
|
58
|
+
readonly search: (
|
|
59
|
+
prefix: string,
|
|
60
|
+
limit: number,
|
|
61
|
+
type?: PeopleAccountKind,
|
|
62
|
+
) => Promise<readonly PeopleFound[]>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The adapter's calls the directory makes. */
|
|
66
|
+
export type OrgsAdapter = Pick<DBAdapter, 'findOne' | 'findMany'>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The most `member` rows one read takes, for an org's members or a person's orgs: each list is
|
|
70
|
+
* read whole and sorted by login, so a page past this many is short.
|
|
71
|
+
*/
|
|
72
|
+
const maxMembers = 1_000;
|
|
73
|
+
|
|
74
|
+
interface Row {
|
|
75
|
+
readonly id: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface PersonRow extends Row {
|
|
79
|
+
readonly name: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
interface MemberRow {
|
|
83
|
+
readonly userId: string;
|
|
84
|
+
readonly organizationId: string;
|
|
85
|
+
readonly role: string;
|
|
86
|
+
readonly createdAt: Date | number | string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Each comma-separated role a member row holds, as the plugin writes several. */
|
|
90
|
+
const roles = (row: MemberRow) => row.role.split(',').map((role) => role.trim());
|
|
91
|
+
|
|
92
|
+
/** Whether a member row is an owner's or an admin's, which GitHub's `admin` role lists. */
|
|
93
|
+
const isAdmin = (row: MemberRow) => roles(row).some((role) => role === 'owner' || role === 'admin');
|
|
94
|
+
|
|
95
|
+
const paged = (sorted: readonly string[], page: LoginsPage): Logins => {
|
|
96
|
+
const after = sorted.filter((login) => page.after === undefined || login > page.after);
|
|
97
|
+
const logins = after.slice(0, page.limit);
|
|
98
|
+
const last = logins.at(-1);
|
|
99
|
+
|
|
100
|
+
return after.length > page.limit && last !== undefined ? { logins, next: last } : { logins };
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/** The directory over the adapter `adapterOf` answers, which Better Auth makes at first use. */
|
|
104
|
+
/**
|
|
105
|
+
* Which of an org's tokens a person lists and revokes, by their membership read at that call
|
|
106
|
+
* (Q740): every member's for its owners and admins, their own for a plain member, and none for
|
|
107
|
+
* anyone outside it. The policy's token rule and the Tokens page's list both ask it.
|
|
108
|
+
*/
|
|
109
|
+
export const orgTokenView = (membership: Membership | undefined): 'all' | 'member' | undefined => {
|
|
110
|
+
if (membership === undefined) return undefined;
|
|
111
|
+
|
|
112
|
+
return membership.admin ? 'all' : 'member';
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export const orgsOver = (adapterOf: () => Promise<OrgsAdapter>): Orgs => {
|
|
116
|
+
const personRow = async (login: string) => {
|
|
117
|
+
const adapter = await adapterOf();
|
|
118
|
+
|
|
119
|
+
return adapter.findOne<PersonRow>({
|
|
120
|
+
model: 'user',
|
|
121
|
+
where: [{ field: 'username', value: login }],
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const personId = async (login: string) => (await personRow(login))?.id;
|
|
126
|
+
|
|
127
|
+
const orgId = async (login: string) => {
|
|
128
|
+
const adapter = await adapterOf();
|
|
129
|
+
const row = await adapter.findOne<Row>({
|
|
130
|
+
model: 'organization',
|
|
131
|
+
where: [{ field: 'slug', value: login }],
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
return row?.id;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/** The person `login`'s member row in the org `org`, or `undefined` when they aren't in it. */
|
|
138
|
+
const memberRow = async (org: string, login: string) => {
|
|
139
|
+
const [organizationId, userId] = await Promise.all([orgId(org), personId(login)]);
|
|
140
|
+
if (organizationId === undefined || userId === undefined) return undefined;
|
|
141
|
+
|
|
142
|
+
const adapter = await adapterOf();
|
|
143
|
+
const row = await adapter.findOne<MemberRow>({
|
|
144
|
+
model: 'member',
|
|
145
|
+
where: [
|
|
146
|
+
{ field: 'organizationId', value: organizationId },
|
|
147
|
+
{ field: 'userId', value: userId },
|
|
148
|
+
],
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
return row ?? undefined;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/** The `login`-ordered `field` of each row of `model` whose ID is one of `ids`. */
|
|
155
|
+
const loginsOf = async (model: 'user' | 'organization', field: string, ids: string[]) => {
|
|
156
|
+
if (ids.length === 0) return [];
|
|
157
|
+
|
|
158
|
+
const adapter = await adapterOf();
|
|
159
|
+
const rows = await adapter.findMany<Record<string, string>>({
|
|
160
|
+
model,
|
|
161
|
+
where: [{ field: 'id', operator: 'in', value: ids }],
|
|
162
|
+
limit: maxMembers,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
return rows.map((row) => row[field] ?? '').sort();
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const membersOf = async (where: { readonly field: string; readonly value: string }) => {
|
|
169
|
+
const adapter = await adapterOf();
|
|
170
|
+
|
|
171
|
+
return adapter.findMany<MemberRow>({ model: 'member', where: [where], limit: maxMembers });
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
held: async (login) => isHeld(await adapterOf(), login),
|
|
176
|
+
person: async (login) => {
|
|
177
|
+
const row = await personRow(login);
|
|
178
|
+
|
|
179
|
+
return row === null ? undefined : { name: row.name, id: row.id };
|
|
180
|
+
},
|
|
181
|
+
org: async (login) => (await orgId(login)) !== undefined,
|
|
182
|
+
account: async (login) => {
|
|
183
|
+
const [userId, organizationId] = await Promise.all([personId(login), orgId(login)]);
|
|
184
|
+
if (userId !== undefined) return { kind: 'user', id: userId };
|
|
185
|
+
|
|
186
|
+
return organizationId === undefined ? undefined : { kind: 'org', id: organizationId };
|
|
187
|
+
},
|
|
188
|
+
membership: async (org, login) => {
|
|
189
|
+
const row = await memberRow(org, login);
|
|
190
|
+
|
|
191
|
+
return row === undefined
|
|
192
|
+
? undefined
|
|
193
|
+
: { admin: isAdmin(row), since: new Date(row.createdAt).getTime() };
|
|
194
|
+
},
|
|
195
|
+
among: async (org, logins) => {
|
|
196
|
+
const asked = [...new Set(logins)];
|
|
197
|
+
const organizationId = asked.length === 0 ? undefined : await orgId(org);
|
|
198
|
+
if (organizationId === undefined) return [];
|
|
199
|
+
|
|
200
|
+
// Three reads, whatever the count: the org, the people by login, then the org's rows for them.
|
|
201
|
+
const adapter = await adapterOf();
|
|
202
|
+
const people = await adapter.findMany<Record<string, string>>({
|
|
203
|
+
model: 'user',
|
|
204
|
+
where: [{ field: 'username', operator: 'in', value: asked }],
|
|
205
|
+
limit: asked.length,
|
|
206
|
+
});
|
|
207
|
+
const ids = people.map((row) => row.id ?? '');
|
|
208
|
+
if (ids.length === 0) return [];
|
|
209
|
+
|
|
210
|
+
const rows = await adapter.findMany<MemberRow>({
|
|
211
|
+
model: 'member',
|
|
212
|
+
where: [
|
|
213
|
+
{ field: 'organizationId', value: organizationId },
|
|
214
|
+
{ field: 'userId', operator: 'in', value: ids },
|
|
215
|
+
],
|
|
216
|
+
limit: ids.length,
|
|
217
|
+
});
|
|
218
|
+
const joined = new Set(rows.map((row) => row.userId));
|
|
219
|
+
|
|
220
|
+
return people
|
|
221
|
+
.filter((row) => joined.has(row.id ?? ''))
|
|
222
|
+
.map((row) => row.username ?? '')
|
|
223
|
+
.sort();
|
|
224
|
+
},
|
|
225
|
+
members: async (org, page) => {
|
|
226
|
+
const organizationId = await orgId(org);
|
|
227
|
+
if (organizationId === undefined) return { logins: [] };
|
|
228
|
+
|
|
229
|
+
const rows = await membersOf({ field: 'organizationId', value: organizationId });
|
|
230
|
+
const shown =
|
|
231
|
+
page.role === 'all' ? rows : rows.filter((row) => isAdmin(row) === (page.role === 'admin'));
|
|
232
|
+
|
|
233
|
+
const logins = await loginsOf(
|
|
234
|
+
'user',
|
|
235
|
+
'username',
|
|
236
|
+
shown.map((row) => row.userId),
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
return paged(logins, page);
|
|
240
|
+
},
|
|
241
|
+
orgsOf: async (login, page) => {
|
|
242
|
+
const userId = await personId(login);
|
|
243
|
+
if (userId === undefined) return { logins: [] };
|
|
244
|
+
|
|
245
|
+
const rows = await membersOf({ field: 'userId', value: userId });
|
|
246
|
+
|
|
247
|
+
const slugs = await loginsOf(
|
|
248
|
+
'organization',
|
|
249
|
+
'slug',
|
|
250
|
+
rows.map((row) => row.organizationId),
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
return paged(slugs, page);
|
|
254
|
+
},
|
|
255
|
+
search: async (prefix, limit, type) => {
|
|
256
|
+
const adapter = await adapterOf();
|
|
257
|
+
const start = prefix.toLowerCase();
|
|
258
|
+
// Logins and slugs are stored lowercased, so a range from the prefix is their unique index's,
|
|
259
|
+
// where the adapter's `starts_with` is a `LIKE` that scans and reads `%` and `_` as patterns.
|
|
260
|
+
const starting = async (model: string, field: string, most: number) => {
|
|
261
|
+
const rows = await adapter.findMany<Record<string, string>>({
|
|
262
|
+
model,
|
|
263
|
+
where: [
|
|
264
|
+
{ field, operator: 'gte', value: start },
|
|
265
|
+
{ field, operator: 'lt', value: `${start}\u{10FFFF}` },
|
|
266
|
+
],
|
|
267
|
+
sortBy: { field, direction: 'asc' },
|
|
268
|
+
limit: most,
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
return rows.map((row) => row[field] ?? '').filter((login) => login.startsWith(start));
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const people = type === 'org' ? [] : await starting('user', 'username', limit);
|
|
275
|
+
const found = people.map((login): PeopleFound => ({ kind: 'user', login }));
|
|
276
|
+
if (type === 'user' || found.length >= limit) return found;
|
|
277
|
+
|
|
278
|
+
const slugs = await starting('organization', 'slug', limit - found.length);
|
|
279
|
+
|
|
280
|
+
return [...found, ...slugs.map((login): PeopleFound => ({ kind: 'org', login }))];
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import type { BetterAuthPlugin, DBAdapter } from 'better-auth';
|
|
2
|
+
import * as Schema from 'effect/Schema';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* One namespace for people's logins and orgs' slugs (Q631): Better Auth checks a username only
|
|
6
|
+
* against `user` and a slug only against `organization`, so each create claims its login first in
|
|
7
|
+
* `owner_names`, whose login is the primary key. The unique insert decides a race, with or without
|
|
8
|
+
* transactions.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Better Auth's model for the claims, and the table it keeps them in. */
|
|
12
|
+
const model = 'ownerName';
|
|
13
|
+
|
|
14
|
+
/** A claim no holder took this long after it's made is a create that died, and anyone retakes it. */
|
|
15
|
+
export const staleAfter = 60_000;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The plugin that gives Better Auth's adapter `owner_names`: a claim's login as its `id`, the token
|
|
19
|
+
* of the create it's for, when it was claimed, and `held` once that create made its person or org,
|
|
20
|
+
* after which it's never retaken.
|
|
21
|
+
*/
|
|
22
|
+
export const ownerNames = () =>
|
|
23
|
+
({
|
|
24
|
+
id: 'owner-names',
|
|
25
|
+
schema: {
|
|
26
|
+
[model]: {
|
|
27
|
+
modelName: 'owner_names',
|
|
28
|
+
fields: {
|
|
29
|
+
claim: { type: 'string', required: true },
|
|
30
|
+
claimedAt: { type: 'date', required: true },
|
|
31
|
+
held: { type: 'boolean', required: true, defaultValue: false },
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
}) satisfies BetterAuthPlugin;
|
|
36
|
+
|
|
37
|
+
/** The adapter's calls the claims make. */
|
|
38
|
+
export type Claims = Pick<DBAdapter, 'create' | 'findOne' | 'updateMany'>;
|
|
39
|
+
|
|
40
|
+
/** Whether a person or an org holds `login` now: a `user` by username, or an `organization` by slug. */
|
|
41
|
+
export const isHeld = async (adapter: Pick<DBAdapter, 'findOne'>, login: string) => {
|
|
42
|
+
const person = await adapter.findOne({
|
|
43
|
+
model: 'user',
|
|
44
|
+
where: [{ field: 'username', value: login }],
|
|
45
|
+
});
|
|
46
|
+
if (person !== null) return true;
|
|
47
|
+
|
|
48
|
+
const org = await adapter.findOne({
|
|
49
|
+
model: 'organization',
|
|
50
|
+
where: [{ field: 'slug', value: login }],
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return org !== null;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Whether a create of `login` now would be refused, taking no claim: a person or org holds it, or
|
|
58
|
+
* its claim is held, or live within `staleAfter`.
|
|
59
|
+
*/
|
|
60
|
+
export const isTaken = async (
|
|
61
|
+
adapter: Pick<DBAdapter, 'findOne'>,
|
|
62
|
+
login: string,
|
|
63
|
+
now = Date.now(),
|
|
64
|
+
) => {
|
|
65
|
+
if (await isHeld(adapter, login)) return true;
|
|
66
|
+
|
|
67
|
+
const row = await adapter.findOne<{ held: boolean; claimedAt: Date }>({
|
|
68
|
+
model,
|
|
69
|
+
where: [{ field: 'id', value: login }],
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return row !== null && (row.held || new Date(row.claimedAt).getTime() >= now - staleAfter);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A database's refusal of a row whose key it holds, as each driver says so: Postgres's SQLSTATE
|
|
77
|
+
* `23505`, better-sqlite3's extended code by name, and `node:sqlite`'s by number, a primary key's
|
|
78
|
+
* or a unique index's. D1 gives no code, only SQLite's message, which names a primary key's
|
|
79
|
+
* refusal as a unique one too.
|
|
80
|
+
*/
|
|
81
|
+
const DuplicateKey = Schema.Union([
|
|
82
|
+
Schema.Struct({
|
|
83
|
+
code: Schema.Literals(['23505', 'SQLITE_CONSTRAINT_PRIMARYKEY', 'SQLITE_CONSTRAINT_UNIQUE']),
|
|
84
|
+
}),
|
|
85
|
+
Schema.Struct({
|
|
86
|
+
code: Schema.Literal('ERR_SQLITE_ERROR'),
|
|
87
|
+
errcode: Schema.Literals([1555, 2067]),
|
|
88
|
+
}),
|
|
89
|
+
Schema.Struct({
|
|
90
|
+
message: Schema.TemplateLiteral(['D1_ERROR: UNIQUE constraint failed: ', Schema.String]),
|
|
91
|
+
}),
|
|
92
|
+
]);
|
|
93
|
+
|
|
94
|
+
const isDuplicateKey = Schema.is(DuplicateKey);
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Inserts `login`'s claim, answering false when the login's row is already there. Any other
|
|
98
|
+
* failure, such as the database being down, is the create's error, not a taken login.
|
|
99
|
+
*/
|
|
100
|
+
const inserted = async (adapter: Claims, login: string, claim: string, now: number) => {
|
|
101
|
+
try {
|
|
102
|
+
await adapter.create({
|
|
103
|
+
model,
|
|
104
|
+
data: { id: login, claim, claimedAt: new Date(now), held: false },
|
|
105
|
+
forceAllowId: true,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return true;
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if (isDuplicateKey(error)) return false;
|
|
111
|
+
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/** Retakes `login`'s claim for `claim` when no create held it within `staleAfter`. */
|
|
117
|
+
const retaken = async (adapter: Claims, login: string, claim: string, now: number) =>
|
|
118
|
+
(await adapter.updateMany({
|
|
119
|
+
model,
|
|
120
|
+
where: [
|
|
121
|
+
{ field: 'id', value: login },
|
|
122
|
+
{ field: 'held', value: false },
|
|
123
|
+
{ field: 'claimedAt', operator: 'lt', value: new Date(now - staleAfter) },
|
|
124
|
+
],
|
|
125
|
+
update: { claim, claimedAt: new Date(now) },
|
|
126
|
+
})) === 1;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Claims `login` for a create about to happen, answering the claim's token when it's this create's:
|
|
130
|
+
* a fresh insert, or a retake of a claim no create held within `staleAfter`. A retake is one
|
|
131
|
+
* conditional update of the claim row, so on Postgres a second retaker waits on the row, rechecks
|
|
132
|
+
* `held` and `claimedAt` on its new version, and changes nothing. A held claim, a live one, or one
|
|
133
|
+
* whose login a person or org holds is refused.
|
|
134
|
+
*/
|
|
135
|
+
export const claimLogin = async (adapter: Claims, login: string, now = Date.now()) => {
|
|
136
|
+
const claim = crypto.randomUUID();
|
|
137
|
+
if (await inserted(adapter, login, claim, now)) return claim;
|
|
138
|
+
|
|
139
|
+
// A person or org made with the claim, whose request stopped before it held the claim, keeps
|
|
140
|
+
// its login here: the row was committed long before the claim went stale. Under READ COMMITTED
|
|
141
|
+
// this read misses a row committed while the retake runs, so a create that both stops before
|
|
142
|
+
// its `held` and commits within these few milliseconds stays a known gap.
|
|
143
|
+
if (await isHeld(adapter, login)) return undefined;
|
|
144
|
+
|
|
145
|
+
return (await retaken(adapter, login, claim, now)) ? claim : undefined;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Claims `login` inside a create's own transaction, on its connection, answering the claim's
|
|
150
|
+
* token, or `undefined` once the transaction can only roll back. A claim taken beside the
|
|
151
|
+
* transaction would need a second connection from the pool the transaction holds one of, so a
|
|
152
|
+
* full pool would wait on itself for good. It retakes first and inserts last: an insert that
|
|
153
|
+
* loses aborts the transaction, which is the create's answer then, since the login is taken. A
|
|
154
|
+
* concurrent create's insert waits on this one's row until it commits or rolls back.
|
|
155
|
+
*/
|
|
156
|
+
export const claimInTransaction = async (adapter: Claims, login: string, now = Date.now()) => {
|
|
157
|
+
if (await isHeld(adapter, login)) return undefined;
|
|
158
|
+
|
|
159
|
+
const claim = crypto.randomUUID();
|
|
160
|
+
if (await retaken(adapter, login, claim, now)) return claim;
|
|
161
|
+
|
|
162
|
+
return (await inserted(adapter, login, claim, now)) ? claim : undefined;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Marks `login`'s claim held for the create whose token `claim` is, answering whether it still was
|
|
167
|
+
* that create's: a retake replaced the token, and then the create must fail. Its person or org is
|
|
168
|
+
* an actor once it's held, and the claim is never retaken or freed.
|
|
169
|
+
*/
|
|
170
|
+
export const holdLogin = async (
|
|
171
|
+
adapter: Pick<DBAdapter, 'updateMany'>,
|
|
172
|
+
login: string,
|
|
173
|
+
claim: string,
|
|
174
|
+
) =>
|
|
175
|
+
(await adapter.updateMany({
|
|
176
|
+
model,
|
|
177
|
+
where: [
|
|
178
|
+
{ field: 'id', value: login },
|
|
179
|
+
{ field: 'claim', value: claim },
|
|
180
|
+
{ field: 'held', value: false },
|
|
181
|
+
],
|
|
182
|
+
update: { held: true },
|
|
183
|
+
})) === 1;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DummyDriver,
|
|
3
|
+
Kysely,
|
|
4
|
+
type Dialect,
|
|
5
|
+
type QueryExecutorProvider,
|
|
6
|
+
type RawBuilder,
|
|
7
|
+
SqliteAdapter,
|
|
8
|
+
SqliteIntrospector,
|
|
9
|
+
SqliteQueryCompiler,
|
|
10
|
+
sql,
|
|
11
|
+
} from 'kysely';
|
|
12
|
+
|
|
13
|
+
import type { AuthDatabase, NodeSqliteValue } from './auth.ts';
|
|
14
|
+
|
|
15
|
+
/** Runs one write, and answers how many rows it changed. */
|
|
16
|
+
export type Write = (statement: RawBuilder<unknown>) => Promise<number>;
|
|
17
|
+
|
|
18
|
+
/** One query engine per dialect, since a Kysely of its own would open the dialect's driver again. */
|
|
19
|
+
const engines = new WeakMap<Dialect, Kysely<unknown>>();
|
|
20
|
+
|
|
21
|
+
const engineOf = (dialect: Dialect) => {
|
|
22
|
+
const known = engines.get(dialect);
|
|
23
|
+
if (known !== undefined) return known;
|
|
24
|
+
|
|
25
|
+
const made = new Kysely<unknown>({ dialect });
|
|
26
|
+
engines.set(dialect, made);
|
|
27
|
+
|
|
28
|
+
return made;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* SQLite's compiler alone, for D1 and `node:sqlite`, which speak SQLite though no Kysely dialect
|
|
33
|
+
* of either is ours.
|
|
34
|
+
*/
|
|
35
|
+
const sqliteOnly = new Kysely<unknown>({
|
|
36
|
+
dialect: {
|
|
37
|
+
createAdapter: () => new SqliteAdapter(),
|
|
38
|
+
createDriver: () => new DummyDriver(),
|
|
39
|
+
createIntrospector: (db) => new SqliteIntrospector(db),
|
|
40
|
+
createQueryCompiler: () => new SqliteQueryCompiler(),
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const throughEngine =
|
|
45
|
+
(engine: QueryExecutorProvider): Write =>
|
|
46
|
+
async (statement) => {
|
|
47
|
+
const ran = await statement.execute(engine);
|
|
48
|
+
|
|
49
|
+
return Number(ran.numAffectedRows ?? 0n);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Runs a person's guarded writes, each a statement that checks what the person holds as it
|
|
54
|
+
* writes, such as deleting their row only while no session is theirs.
|
|
55
|
+
*
|
|
56
|
+
* D1, SQLite and libSQL run one writer at a time, so each such statement sees every write before
|
|
57
|
+
* it, and runs as it is. Postgres at READ COMMITTED doesn't: a statement's snapshot misses a write
|
|
58
|
+
* not yet committed, such as a session whose insert holds the person's row, or another passkey's
|
|
59
|
+
* delete. There the writes run in one transaction that first locks the person's row `for update`,
|
|
60
|
+
* so it waits for any of theirs in flight, and each statement after it sees what they committed.
|
|
61
|
+
* The level is set, not taken from the database, since REPEATABLE READ would keep the snapshot
|
|
62
|
+
* from before the lock.
|
|
63
|
+
*/
|
|
64
|
+
export const withPersonLocked = async <A>(
|
|
65
|
+
database: AuthDatabase,
|
|
66
|
+
id: string,
|
|
67
|
+
writes: (write: Write) => Promise<A>,
|
|
68
|
+
): Promise<A> => {
|
|
69
|
+
// `node:sqlite`'s database closes, and D1's binding doesn't.
|
|
70
|
+
if ('close' in database) {
|
|
71
|
+
return writes(async (statement) => {
|
|
72
|
+
const compiled = statement.compile(sqliteOnly);
|
|
73
|
+
// SAFETY: every guarded write binds ids, as text: a person's and a passkey's.
|
|
74
|
+
const values = compiled.parameters as readonly NodeSqliteValue[];
|
|
75
|
+
const ran = database.prepare(compiled.sql).run(...values);
|
|
76
|
+
|
|
77
|
+
return Number(ran.changes);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (!('dialect' in database)) {
|
|
82
|
+
return writes(async (statement) => {
|
|
83
|
+
const compiled = statement.compile(sqliteOnly);
|
|
84
|
+
const ran = await database
|
|
85
|
+
.prepare(compiled.sql)
|
|
86
|
+
.bind(...compiled.parameters)
|
|
87
|
+
.run();
|
|
88
|
+
|
|
89
|
+
return ran.meta.changes;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const engine = engineOf(database.dialect);
|
|
94
|
+
if (database.type !== 'postgres') return writes(throughEngine(engine));
|
|
95
|
+
|
|
96
|
+
return engine
|
|
97
|
+
.transaction()
|
|
98
|
+
.setIsolationLevel('read committed')
|
|
99
|
+
.execute(async (locked) => {
|
|
100
|
+
await sql`select 1 from "user" where "id" = ${id} for update`.execute(locked);
|
|
101
|
+
|
|
102
|
+
return writes(throughEngine(locked));
|
|
103
|
+
});
|
|
104
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sealed cookie values: text encrypted with AES-GCM under a key from the host's session secret, so
|
|
3
|
+
* the browser holds the session but can neither read nor change it. A value sealed under another
|
|
4
|
+
* secret, cut, or changed opens as `undefined`.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const encoder = new TextEncoder();
|
|
8
|
+
|
|
9
|
+
/** The key every seal in this Worker uses, from `SESSION_SECRET` through HKDF. */
|
|
10
|
+
export const sealKey = async (secret: string): Promise<CryptoKey> => {
|
|
11
|
+
if (secret.length < 32) throw new Error('SESSION_SECRET must be at least 32 characters');
|
|
12
|
+
|
|
13
|
+
const material = await crypto.subtle.importKey('raw', encoder.encode(secret), 'HKDF', false, [
|
|
14
|
+
'deriveKey',
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
return crypto.subtle.deriveKey(
|
|
18
|
+
{
|
|
19
|
+
name: 'HKDF',
|
|
20
|
+
hash: 'SHA-256',
|
|
21
|
+
salt: encoder.encode('ref0-github-app'),
|
|
22
|
+
info: encoder.encode('session cookie'),
|
|
23
|
+
},
|
|
24
|
+
material,
|
|
25
|
+
{ name: 'AES-GCM', length: 256 },
|
|
26
|
+
false,
|
|
27
|
+
['encrypt', 'decrypt'],
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const base64url = (bytes: Uint8Array) =>
|
|
32
|
+
btoa(String.fromCharCode(...bytes))
|
|
33
|
+
.replaceAll('+', '-')
|
|
34
|
+
.replaceAll('/', '_')
|
|
35
|
+
.replace(/=+$/, '');
|
|
36
|
+
|
|
37
|
+
const fromBase64url = (text: string): Uint8Array<ArrayBuffer> | undefined => {
|
|
38
|
+
if (!/^[A-Za-z0-9_-]*$/.test(text)) return undefined;
|
|
39
|
+
|
|
40
|
+
const binary = atob(text.replaceAll('-', '+').replaceAll('_', '/'));
|
|
41
|
+
|
|
42
|
+
return Uint8Array.from(binary, (character) => character.charCodeAt(0));
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** `value`, sealed for one `purpose`, so a seal made for one cookie never opens as another. */
|
|
46
|
+
export const seal = async (key: CryptoKey, purpose: string, value: string): Promise<string> => {
|
|
47
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
48
|
+
const sealed = await crypto.subtle.encrypt(
|
|
49
|
+
{ name: 'AES-GCM', iv, additionalData: encoder.encode(purpose) },
|
|
50
|
+
key,
|
|
51
|
+
encoder.encode(value),
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
return `${base64url(iv)}.${base64url(new Uint8Array(sealed))}`;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** What `seal` sealed for `purpose`, or `undefined` for anything else. */
|
|
58
|
+
export const open = async (
|
|
59
|
+
key: CryptoKey,
|
|
60
|
+
purpose: string,
|
|
61
|
+
text: string,
|
|
62
|
+
): Promise<string | undefined> => {
|
|
63
|
+
const [ivText = '', sealedText = '', ...rest] = text.split('.');
|
|
64
|
+
|
|
65
|
+
// `atob` throws for a length no base64 has, and `decrypt` for a seal that doesn't open.
|
|
66
|
+
try {
|
|
67
|
+
const iv = fromBase64url(ivText);
|
|
68
|
+
const sealed = fromBase64url(sealedText);
|
|
69
|
+
if (iv?.length !== 12 || sealed === undefined || rest.length > 0) return undefined;
|
|
70
|
+
|
|
71
|
+
const plain = await crypto.subtle.decrypt(
|
|
72
|
+
{ name: 'AES-GCM', iv, additionalData: encoder.encode(purpose) },
|
|
73
|
+
key,
|
|
74
|
+
sealed,
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
return new TextDecoder().decode(plain);
|
|
78
|
+
} catch {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** A random value for a PKCE verifier or an OAuth `state`: 32 bytes, as base64url. */
|
|
84
|
+
export const randomToken = () => base64url(crypto.getRandomValues(new Uint8Array(32)));
|
|
85
|
+
|
|
86
|
+
/** The S256 challenge for a PKCE verifier. */
|
|
87
|
+
export const challengeOf = async (verifier: string) =>
|
|
88
|
+
base64url(new Uint8Array(await crypto.subtle.digest('SHA-256', encoder.encode(verifier))));
|