@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/dist/LICENSE +202 -0
- package/dist/access/private-refs.d.mts +27 -0
- package/dist/access/private-refs.mjs +173 -0
- package/dist/access.d.mts +2 -0
- package/dist/access.mjs +1 -0
- package/dist/auth/access-jwt.d.mts +21 -0
- package/dist/auth/access-jwt.mjs +102 -0
- package/dist/auth/acting.mjs +15 -0
- package/dist/auth/authorize.d.mts +5 -0
- package/dist/auth/authorize.mjs +292 -0
- package/dist/auth/credentials.mjs +57 -0
- package/dist/auth/fences.d.mts +5 -0
- package/dist/auth/fences.mjs +65 -0
- package/dist/auth/grants.mjs +61 -0
- package/dist/auth/helpers.d.mts +17 -0
- package/dist/auth/helpers.mjs +25 -0
- package/dist/auth/host-function.d.mts +4 -0
- package/dist/auth/host-function.mjs +69 -0
- package/dist/auth/identify.d.mts +6 -0
- package/dist/auth/identify.mjs +97 -0
- package/dist/auth/token-rows.mjs +100 -0
- package/dist/auth/token-text.mjs +66 -0
- package/dist/auth/tokens.d.mts +10 -0
- package/dist/auth/tokens.mjs +347 -0
- package/dist/auth.d.mts +7 -0
- package/dist/auth.mjs +6 -0
- package/dist/client/answer.mjs +141 -0
- package/dist/client/client.d.mts +23 -0
- package/dist/client/client.mjs +50 -0
- package/dist/client/git-http.mjs +201 -0
- package/dist/client/helper-node.mjs +19 -0
- package/dist/client/local.mjs +170 -0
- package/dist/client/negotiate.mjs +170 -0
- package/dist/client/push-upload.mjs +53 -0
- package/dist/client/remote-helper.mjs +129 -0
- package/dist/client/remote.mjs +398 -0
- package/dist/client/run-remote-helper.d.mts +35 -0
- package/dist/client/run-remote-helper.mjs +259 -0
- package/dist/client/scrub.d.mts +18 -0
- package/dist/client/scrub.mjs +38 -0
- package/dist/client/transport.d.mts +2 -0
- package/dist/client/transport.mjs +211 -0
- package/dist/contracts/access.d.mts +87 -0
- package/dist/contracts/actors.d.mts +144 -0
- package/dist/contracts/blobs.d.mts +38 -0
- package/dist/contracts/calls-spent.d.mts +11 -0
- package/dist/contracts/calls-spent.mjs +151 -0
- package/dist/contracts/client.d.mts +90 -0
- package/dist/contracts/commits.d.mts +126 -0
- package/dist/contracts/engine.d.mts +134 -0
- package/dist/contracts/events.d.mts +276 -0
- package/dist/contracts/files.d.mts +75 -0
- package/dist/contracts/forks.d.mts +78 -0
- package/dist/contracts/grants.d.mts +60 -0
- package/dist/contracts/handlers.d.mts +11 -0
- package/dist/contracts/ids.d.mts +15 -0
- package/dist/contracts/ids.mjs +15 -0
- package/dist/contracts/lfs.d.mts +27 -0
- package/dist/contracts/merges.d.mts +33 -0
- package/dist/contracts/objects.d.mts +645 -0
- package/dist/contracts/objects.mjs +54 -0
- package/dist/contracts/operations.d.mts +133 -0
- package/dist/contracts/promises.d.mts +38 -0
- package/dist/contracts/promises.mjs +13 -0
- package/dist/contracts/push-uploads.d.mts +44 -0
- package/dist/contracts/queue.d.mts +402 -0
- package/dist/contracts/refs.d.mts +95 -0
- package/dist/contracts/remote.d.mts +50 -0
- package/dist/contracts/repos.d.mts +153 -0
- package/dist/contracts/result.d.mts +133 -0
- package/dist/contracts/result.mjs +34 -0
- package/dist/contracts/rules.d.mts +159 -0
- package/dist/contracts/server.d.mts +272 -0
- package/dist/contracts/services.d.mts +36 -0
- package/dist/contracts/services.mjs +13 -0
- package/dist/contracts/signin.d.mts +126 -0
- package/dist/contracts/store.d.mts +41 -0
- package/dist/contracts/sync.d.mts +210 -0
- package/dist/contracts/sync.mjs +8 -0
- package/dist/contracts/tags.d.mts +50 -0
- package/dist/contracts/tags.mjs +6 -0
- package/dist/contracts/tokens.d.mts +87 -0
- package/dist/contracts/tokens.mjs +15 -0
- package/dist/contracts/topics.d.mts +180 -0
- package/dist/contracts/trees.d.mts +84 -0
- package/dist/contracts/work.d.mts +31 -0
- package/dist/core/access.d.mts +22 -0
- package/dist/core/access.mjs +262 -0
- package/dist/core/ancestry.mjs +235 -0
- package/dist/core/call-names.d.mts +1 -0
- package/dist/core/call-names.mjs +93 -0
- package/dist/core/clock.mjs +18 -0
- package/dist/core/events/deliver.mjs +475 -0
- package/dist/core/events/stream.d.mts +19 -0
- package/dist/core/events/stream.mjs +297 -0
- package/dist/core/forks.mjs +1027 -0
- package/dist/core/hooks/post-receive.mjs +212 -0
- package/dist/core/hooks/pre-receive.d.mts +5 -0
- package/dist/core/hooks/pre-receive.mjs +34 -0
- package/dist/core/index-job.mjs +198 -0
- package/dist/core/names.mjs +30 -0
- package/dist/core/objects/blobs.mjs +60 -0
- package/dist/core/objects/commit-writes.mjs +185 -0
- package/dist/core/objects/commits.mjs +172 -0
- package/dist/core/objects/files.mjs +211 -0
- package/dist/core/objects/lines.mjs +42 -0
- package/dist/core/objects/merges.mjs +83 -0
- package/dist/core/objects/peel.mjs +166 -0
- package/dist/core/objects/reading.mjs +284 -0
- package/dist/core/objects/tags.mjs +96 -0
- package/dist/core/objects/tree-edits.mjs +266 -0
- package/dist/core/objects/trees.mjs +229 -0
- package/dist/core/objects/writing.mjs +266 -0
- package/dist/core/own-writes.mjs +94 -0
- package/dist/core/promise.mjs +64 -0
- package/dist/core/publish.mjs +142 -0
- package/dist/core/push-decide.mjs +206 -0
- package/dist/core/push.mjs +1070 -0
- package/dist/core/receipts.d.mts +7 -0
- package/dist/core/receipts.mjs +234 -0
- package/dist/core/ref-conflicts.mjs +27 -0
- package/dist/core/refs.mjs +359 -0
- package/dist/core/repack.mjs +521 -0
- package/dist/core/repos.mjs +752 -0
- package/dist/core/rules/changes.mjs +57 -0
- package/dist/core/rules/check.mjs +101 -0
- package/dist/core/rules/commit-changes.mjs +216 -0
- package/dist/core/rules/context.d.mts +9 -0
- package/dist/core/rules/context.mjs +120 -0
- package/dist/core/rules/define.d.mts +5 -0
- package/dist/core/rules/define.mjs +13 -0
- package/dist/core/rules/facts.mjs +13 -0
- package/dist/core/rules/fetch.d.mts +5 -0
- package/dist/core/rules/fetch.mjs +59 -0
- package/dist/core/rules/file-globs.mjs +55 -0
- package/dist/core/rules/files.mjs +142 -0
- package/dist/core/rules/patterns.mjs +23 -0
- package/dist/core/rules/protect.d.mts +9 -0
- package/dist/core/rules/protect.mjs +116 -0
- package/dist/core/seam.d.mts +26 -0
- package/dist/core/seam.mjs +54 -0
- package/dist/core/sight.mjs +99 -0
- package/dist/core/tokens.mjs +95 -0
- package/dist/core/view.d.mts +9 -0
- package/dist/core/view.mjs +221 -0
- package/dist/core/work.mjs +92 -0
- package/dist/effect.d.mts +20 -0
- package/dist/effect.mjs +18 -0
- package/dist/engine/allotted-xdiff.d.mts +4 -0
- package/dist/engine/allotted-xdiff.mjs +80 -0
- package/dist/engine/attribute-patterns.mjs +163 -0
- package/dist/engine/attributes.mjs +226 -0
- package/dist/engine/combined.mjs +653 -0
- package/dist/engine/commits.mjs +90 -0
- package/dist/engine/content.d.mts +4 -0
- package/dist/engine/content.mjs +221 -0
- package/dist/engine/diff.mjs +49 -0
- package/dist/engine/engine.d.mts +25 -0
- package/dist/engine/engine.mjs +49 -0
- package/dist/engine/failures.d.mts +4 -0
- package/dist/engine/failures.mjs +23 -0
- package/dist/engine/line-count.mjs +23 -0
- package/dist/engine/merge-base-walk.d.mts +2 -0
- package/dist/engine/merge-base-walk.mjs +265 -0
- package/dist/engine/merge-bases.mjs +27 -0
- package/dist/engine/merge-renames.mjs +165 -0
- package/dist/engine/merge.mjs +1125 -0
- package/dist/engine/parts.d.mts +8 -0
- package/dist/engine/parts.mjs +9 -0
- package/dist/engine/reads.d.mts +5 -0
- package/dist/engine/reads.mjs +105 -0
- package/dist/engine/walk.mjs +328 -0
- package/dist/engine/xdiff/NOTICE.md +63 -0
- package/dist/engine/xdiff/compiled.d.mts +7 -0
- package/dist/engine/xdiff/compiled.mjs +9 -0
- package/dist/engine/xdiff/embedded.mjs +4 -0
- package/dist/engine/xdiff/node.d.mts +7 -0
- package/dist/engine/xdiff/node.mjs +10 -0
- package/dist/engine/xdiff/upstream/LGPL-2.1 +511 -0
- package/dist/engine/xdiff/xdiff.wasm +0 -0
- package/dist/engine/xdiff.d.mts +34 -0
- package/dist/engine/xdiff.mjs +380 -0
- package/dist/engine.d.mts +3 -0
- package/dist/engine.mjs +3 -0
- package/dist/extend.d.mts +4 -0
- package/dist/extend.mjs +3 -0
- package/dist/http/answers.mjs +74 -0
- package/dist/http/bodies.mjs +143 -0
- package/dist/http/core-parts.mjs +252 -0
- package/dist/http/fetch-depth.mjs +26 -0
- package/dist/http/handler.mjs +94 -0
- package/dist/http/node.d.mts +70 -0
- package/dist/http/node.mjs +178 -0
- package/dist/http/paths.d.mts +9 -0
- package/dist/http/paths.mjs +118 -0
- package/dist/http/push-uploads.mjs +286 -0
- package/dist/http/receive-pack.mjs +235 -0
- package/dist/http/upload-pack.mjs +229 -0
- package/dist/index.d.mts +46 -0
- package/dist/index.mjs +16 -0
- package/dist/lfs/calls.mjs +16 -0
- package/dist/lfs/locks.mjs +161 -0
- package/dist/lfs/objects.mjs +370 -0
- package/dist/lfs/pointers.mjs +141 -0
- package/dist/lfs/repo.mjs +42 -0
- package/dist/lfs/rows.mjs +108 -0
- package/dist/lfs/service.mjs +34 -0
- package/dist/lfs/upkeep.mjs +162 -0
- package/dist/lfs/wire.mjs +102 -0
- package/dist/node.d.mts +3 -0
- package/dist/node.mjs +3 -0
- package/dist/protocol/bytes/buffers.d.mts +38 -0
- package/dist/protocol/bytes/buffers.mjs +62 -0
- package/dist/protocol/bytes/crc32.d.mts +4 -0
- package/dist/protocol/bytes/crc32.mjs +14 -0
- package/dist/protocol/bytes/deflate.d.mts +78 -0
- package/dist/protocol/bytes/deflate.mjs +175 -0
- package/dist/protocol/bytes/errors.d.mts +20 -0
- package/dist/protocol/bytes/errors.mjs +19 -0
- package/dist/protocol/bytes/hex.mjs +16 -0
- package/dist/protocol/bytes/hmac-sha256.mjs +91 -0
- package/dist/protocol/bytes/inflate.d.mts +40 -0
- package/dist/protocol/bytes/inflate.mjs +109 -0
- package/dist/protocol/bytes/joined.d.mts +2 -0
- package/dist/protocol/bytes/joined.mjs +25 -0
- package/dist/protocol/bytes/sha1-hasher.d.mts +20 -0
- package/dist/protocol/bytes/sha1-hasher.mjs +72 -0
- package/dist/protocol/bytes/sha1.d.mts +35 -0
- package/dist/protocol/bytes/sha1.mjs +409 -0
- package/dist/protocol/bytes/sha256.mjs +156 -0
- package/dist/protocol/bytes/streams.mjs +11 -0
- package/dist/protocol/bytes/text.mjs +19 -0
- package/dist/protocol/diff/diff-raw.d.mts +29 -0
- package/dist/protocol/diff/diff-raw.mjs +73 -0
- package/dist/protocol/diff/patch.mjs +92 -0
- package/dist/protocol/diff/paths.mjs +67 -0
- package/dist/protocol/diff/read.d.mts +62 -0
- package/dist/protocol/diff/read.mjs +342 -0
- package/dist/protocol/diff/rename-similarity.mjs +428 -0
- package/dist/protocol/diff/text.mjs +12 -0
- package/dist/protocol/diff/tree-diff.d.mts +41 -0
- package/dist/protocol/diff/tree-diff.mjs +607 -0
- package/dist/protocol/framing/band.d.mts +10 -0
- package/dist/protocol/framing/band.mjs +16 -0
- package/dist/protocol/framing/pkt-line.d.mts +48 -0
- package/dist/protocol/framing/pkt-line.mjs +92 -0
- package/dist/protocol/objects/checked-blobs.mjs +127 -0
- package/dist/protocol/objects/commit.d.mts +25 -0
- package/dist/protocol/objects/commit.mjs +138 -0
- package/dist/protocol/objects/fsck-gitmodules.mjs +296 -0
- package/dist/protocol/objects/fsck-names.mjs +189 -0
- package/dist/protocol/objects/fsck.mjs +297 -0
- package/dist/protocol/objects/headers.mjs +109 -0
- package/dist/protocol/objects/held.mjs +56 -0
- package/dist/protocol/objects/iconv.mjs +145 -0
- package/dist/protocol/objects/ident.mjs +111 -0
- package/dist/protocol/objects/lfs-pointer.d.mts +8 -0
- package/dist/protocol/objects/lfs-pointer.mjs +63 -0
- package/dist/protocol/objects/links-raw.mjs +89 -0
- package/dist/protocol/objects/object-rules.mjs +75 -0
- package/dist/protocol/objects/object.d.mts +16 -0
- package/dist/protocol/objects/object.mjs +29 -0
- package/dist/protocol/objects/tag.d.mts +21 -0
- package/dist/protocol/objects/tag.mjs +96 -0
- package/dist/protocol/objects/tree.d.mts +43 -0
- package/dist/protocol/objects/tree.mjs +162 -0
- package/dist/protocol/objects/utf8-verify.mjs +71 -0
- package/dist/protocol/packs/delta.d.mts +57 -0
- package/dist/protocol/packs/delta.mjs +229 -0
- package/dist/protocol/packs/graph.mjs +78 -0
- package/dist/protocol/packs/idx.d.mts +54 -0
- package/dist/protocol/packs/idx.mjs +274 -0
- package/dist/protocol/packs/indexer.d.mts +167 -0
- package/dist/protocol/packs/indexer.mjs +507 -0
- package/dist/protocol/packs/parts.d.mts +40 -0
- package/dist/protocol/packs/parts.mjs +89 -0
- package/dist/protocol/packs/pos.mjs +51 -0
- package/dist/protocol/packs/reader.d.mts +180 -0
- package/dist/protocol/packs/reader.mjs +414 -0
- package/dist/protocol/packs/rev.d.mts +32 -0
- package/dist/protocol/packs/rev.mjs +99 -0
- package/dist/protocol/packs/step.d.mts +10 -0
- package/dist/protocol/packs/step.mjs +12 -0
- package/dist/protocol/packs/write-error.d.mts +12 -0
- package/dist/protocol/packs/write-error.mjs +27 -0
- package/dist/protocol/packs/writer.d.mts +157 -0
- package/dist/protocol/packs/writer.mjs +353 -0
- package/dist/protocol/wire/advertisement.d.mts +72 -0
- package/dist/protocol/wire/advertisement.mjs +161 -0
- package/dist/protocol/wire/fetch.d.mts +155 -0
- package/dist/protocol/wire/fetch.mjs +458 -0
- package/dist/protocol/wire/lines.mjs +107 -0
- package/dist/protocol/wire/push-uploads.mjs +43 -0
- package/dist/protocol/wire/receive-pack.d.mts +71 -0
- package/dist/protocol/wire/receive-pack.mjs +157 -0
- package/dist/protocol/wire/report-status.d.mts +47 -0
- package/dist/protocol/wire/report-status.mjs +119 -0
- package/dist/protocol/wire/v2.d.mts +90 -0
- package/dist/protocol/wire/v2.mjs +185 -0
- package/dist/protocol.d.mts +31 -0
- package/dist/protocol.mjs +31 -0
- package/dist/queue/advance.mjs +1037 -0
- package/dist/queue/callers.mjs +134 -0
- package/dist/queue/calls.mjs +1154 -0
- package/dist/queue/commit.mjs +85 -0
- package/dist/queue/host.d.mts +15 -0
- package/dist/queue/host.mjs +88 -0
- package/dist/queue/ids.d.mts +5 -0
- package/dist/queue/ids.mjs +21 -0
- package/dist/queue/lanes.mjs +86 -0
- package/dist/queue/limits.mjs +99 -0
- package/dist/queue/pages.mjs +76 -0
- package/dist/queue/push-option.mjs +62 -0
- package/dist/queue/rows.mjs +206 -0
- package/dist/queue/schedule.mjs +132 -0
- package/dist/queue/search.mjs +315 -0
- package/dist/queue/state.mjs +325 -0
- package/dist/queue/steps.mjs +317 -0
- package/dist/remote-helper.d.mts +3 -0
- package/dist/remote-helper.mjs +3 -0
- package/dist/rest/api.d.mts +23 -0
- package/dist/rest/api.mjs +27 -0
- package/dist/rest/blobs.d.mts +58 -0
- package/dist/rest/blobs.mjs +41 -0
- package/dist/rest/caller.d.mts +102 -0
- package/dist/rest/caller.mjs +18 -0
- package/dist/rest/client.d.mts +18 -0
- package/dist/rest/client.mjs +587 -0
- package/dist/rest/commits.d.mts +435 -0
- package/dist/rest/commits.mjs +140 -0
- package/dist/rest/errors.d.mts +44 -0
- package/dist/rest/errors.mjs +186 -0
- package/dist/rest/events.d.mts +38 -0
- package/dist/rest/events.mjs +74 -0
- package/dist/rest/files.d.mts +179 -0
- package/dist/rest/files.mjs +92 -0
- package/dist/rest/forks.d.mts +205 -0
- package/dist/rest/forks.mjs +51 -0
- package/dist/rest/handler.d.mts +18 -0
- package/dist/rest/handler.mjs +129 -0
- package/dist/rest/handlers.d.mts +8 -0
- package/dist/rest/handlers.mjs +592 -0
- package/dist/rest/listen.d.mts +24 -0
- package/dist/rest/listen.mjs +142 -0
- package/dist/rest/me.d.mts +55 -0
- package/dist/rest/me.mjs +21 -0
- package/dist/rest/merges.d.mts +90 -0
- package/dist/rest/merges.mjs +39 -0
- package/dist/rest/paths.mjs +86 -0
- package/dist/rest/queue.d.mts +486 -0
- package/dist/rest/queue.mjs +228 -0
- package/dist/rest/refs.d.mts +232 -0
- package/dist/rest/refs.mjs +86 -0
- package/dist/rest/repos.d.mts +223 -0
- package/dist/rest/repos.mjs +93 -0
- package/dist/rest/tags.d.mts +153 -0
- package/dist/rest/tags.mjs +72 -0
- package/dist/rest/tokens.d.mts +297 -0
- package/dist/rest/tokens.mjs +88 -0
- package/dist/rest/topics.d.mts +257 -0
- package/dist/rest/topics.mjs +116 -0
- package/dist/rest/trees.d.mts +158 -0
- package/dist/rest/trees.mjs +118 -0
- package/dist/rest/wire.mjs +57 -0
- package/dist/rest/work.d.mts +107 -0
- package/dist/rest/work.mjs +77 -0
- package/dist/rest.d.mts +8 -0
- package/dist/rest.mjs +5 -0
- package/dist/server/extension.d.mts +17 -0
- package/dist/server/extension.mjs +93 -0
- package/dist/server/lifecycle.d.mts +3 -0
- package/dist/server/lifecycle.mjs +89 -0
- package/dist/server/routes.d.mts +28 -0
- package/dist/server/routes.mjs +60 -0
- package/dist/server/server.d.mts +8 -0
- package/dist/server/server.mjs +615 -0
- package/dist/signin/codes.mjs +47 -0
- package/dist/signin/context.d.mts +9 -0
- package/dist/signin/context.mjs +121 -0
- package/dist/signin/device.mjs +122 -0
- package/dist/signin/forms.mjs +157 -0
- package/dist/signin/grants.d.mts +5 -0
- package/dist/signin/grants.mjs +257 -0
- package/dist/signin/route.mjs +68 -0
- package/dist/signin/web.mjs +125 -0
- package/dist/signin/wire.d.mts +42 -0
- package/dist/signin/wire.mjs +43 -0
- package/dist/storage/allotted.mjs +102 -0
- package/dist/storage/bits.mjs +41 -0
- package/dist/storage/budget.mjs +96 -0
- package/dist/storage/calls.d.mts +18 -0
- package/dist/storage/calls.mjs +273 -0
- package/dist/storage/clean-up.mjs +124 -0
- package/dist/storage/distinct-ids.mjs +39 -0
- package/dist/storage/ewah.mjs +97 -0
- package/dist/storage/fetch.d.mts +15 -0
- package/dist/storage/fetch.mjs +998 -0
- package/dist/storage/fsck.mjs +77 -0
- package/dist/storage/held-memo.mjs +188 -0
- package/dist/storage/index-bitmaps.d.mts +4 -0
- package/dist/storage/index-bitmaps.mjs +654 -0
- package/dist/storage/index-build.d.mts +15 -0
- package/dist/storage/index-build.mjs +1447 -0
- package/dist/storage/index-fetch.d.mts +10 -0
- package/dist/storage/index-fetch.mjs +677 -0
- package/dist/storage/index-files.mjs +232 -0
- package/dist/storage/index-graph.d.mts +3 -0
- package/dist/storage/index-graph.mjs +1049 -0
- package/dist/storage/index-layers.mjs +317 -0
- package/dist/storage/index-reach.mjs +216 -0
- package/dist/storage/index-remap.d.mts +8 -0
- package/dist/storage/index-remap.mjs +592 -0
- package/dist/storage/layout.mjs +69 -0
- package/dist/storage/lfs-pointers.d.mts +21 -0
- package/dist/storage/lfs-pointers.mjs +175 -0
- package/dist/storage/link-join.mjs +106 -0
- package/dist/storage/links.mjs +105 -0
- package/dist/storage/loose.d.mts +15 -0
- package/dist/storage/loose.mjs +121 -0
- package/dist/storage/memory-budget.d.mts +8 -0
- package/dist/storage/memory-budget.mjs +546 -0
- package/dist/storage/merge.mjs +416 -0
- package/dist/storage/object-rows.d.mts +6 -0
- package/dist/storage/object-rows.mjs +211 -0
- package/dist/storage/pack-order.d.mts +8 -0
- package/dist/storage/pack-order.mjs +781 -0
- package/dist/storage/pack-ranges.d.mts +5 -0
- package/dist/storage/pack-ranges.mjs +284 -0
- package/dist/storage/pack-reads.d.mts +11 -0
- package/dist/storage/pack-reads.mjs +1007 -0
- package/dist/storage/pack-receive.d.mts +11 -0
- package/dist/storage/pack-receive.mjs +449 -0
- package/dist/storage/packs.d.mts +56 -0
- package/dist/storage/packs.mjs +603 -0
- package/dist/storage/prune.mjs +506 -0
- package/dist/storage/push-allotment.mjs +109 -0
- package/dist/storage/push-uploads.mjs +152 -0
- package/dist/storage/pushed-commits.mjs +136 -0
- package/dist/storage/quarantine.mjs +98 -0
- package/dist/storage/raw-ids.mjs +44 -0
- package/dist/storage/ready.d.mts +19 -0
- package/dist/storage/ready.mjs +328 -0
- package/dist/storage/receive-links.mjs +297 -0
- package/dist/storage/repack-job.mjs +48 -0
- package/dist/storage/repack.d.mts +31 -0
- package/dist/storage/repack.mjs +182 -0
- package/dist/storage/roots.mjs +42 -0
- package/dist/storage/rows.d.mts +4 -0
- package/dist/storage/rows.mjs +71 -0
- package/dist/storage/send-list.d.mts +8 -0
- package/dist/storage/send-list.mjs +319 -0
- package/dist/storage/shallow.d.mts +4 -0
- package/dist/storage/shallow.mjs +128 -0
- package/dist/storage/stream-whole.mjs +236 -0
- package/dist/storage/unpack.mjs +238 -0
- package/dist/storage/visible.mjs +137 -0
- package/dist/storage/walk.d.mts +8 -0
- package/dist/storage/walk.mjs +176 -0
- package/dist/storage/wants.mjs +362 -0
- package/dist/store/call-count.d.mts +47 -0
- package/dist/store/call-count.mjs +207 -0
- package/dist/store/catalogue.d.mts +7 -0
- package/dist/store/catalogue.mjs +643 -0
- package/dist/store/closed.d.mts +21 -0
- package/dist/store/closed.mjs +34 -0
- package/dist/store/crossing.mjs +69 -0
- package/dist/store/cursor-seal.d.mts +2 -0
- package/dist/store/cursor-seal.mjs +88 -0
- package/dist/store/errors.d.mts +12 -0
- package/dist/store/errors.mjs +135 -0
- package/dist/store/git-store.mjs +75 -0
- package/dist/store/list-job.mjs +35 -0
- package/dist/store/outbox.d.mts +7 -0
- package/dist/store/outbox.mjs +297 -0
- package/dist/store/promises.d.mts +5 -0
- package/dist/store/promises.mjs +258 -0
- package/dist/store/queue-jobs.mjs +43 -0
- package/dist/store/random.mjs +28 -0
- package/dist/store/records.d.mts +4 -0
- package/dist/store/records.mjs +192 -0
- package/dist/store/ref-rows.d.mts +4 -0
- package/dist/store/ref-rows.mjs +30 -0
- package/dist/store/repo-record.mjs +100 -0
- package/dist/store/reservations.mjs +82 -0
- package/dist/store/scopes.mjs +170 -0
- package/dist/store/settle.mjs +63 -0
- package/dist/store/topic-jobs.mjs +62 -0
- package/dist/sync/bound.d.mts +7 -0
- package/dist/sync/bound.mjs +34 -0
- package/dist/sync/github.d.mts +12 -0
- package/dist/sync/github.mjs +297 -0
- package/dist/sync/import.d.mts +8 -0
- package/dist/sync/import.mjs +154 -0
- package/dist/sync/jobs.d.mts +9 -0
- package/dist/sync/jobs.mjs +83 -0
- package/dist/sync/mirror.d.mts +9 -0
- package/dist/sync/mirror.mjs +227 -0
- package/dist/sync/publish.d.mts +5 -0
- package/dist/sync/publish.mjs +117 -0
- package/dist/sync/records.mjs +73 -0
- package/dist/sync/smart-http.d.mts +8 -0
- package/dist/sync/smart-http.mjs +23 -0
- package/dist/sync/step.mjs +334 -0
- package/dist/sync/tries.mjs +126 -0
- package/dist/sync.d.mts +8 -0
- package/dist/sync.mjs +8 -0
- package/dist/topics/advance.mjs +555 -0
- package/dist/topics/calls.mjs +346 -0
- package/dist/topics/directory.mjs +107 -0
- package/dist/topics/host.d.mts +11 -0
- package/dist/topics/host.mjs +71 -0
- package/dist/topics/members.mjs +177 -0
- package/dist/topics/rows.mjs +99 -0
- package/dist/topics/topic.mjs +141 -0
- package/package.json +86 -5
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { gitError } from "../store/errors.mjs";
|
|
2
|
+
import { longActorId } from "./authorize.mjs";
|
|
3
|
+
import { credentialSecret, requestCredentials } from "./credentials.mjs";
|
|
4
|
+
import { grantCaller } from "./grants.mjs";
|
|
5
|
+
import { hostCall } from "./host-function.mjs";
|
|
6
|
+
import { verifyToken } from "./token-rows.mjs";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
// src/auth/identify.ts
|
|
9
|
+
const unknownCredential = () => gitError("UNAUTHENTICATED", "This credential isn't one this server knows", { hint: "Send a token or credentials it issued" });
|
|
10
|
+
const anonymous = { actor: { anonymous: true } };
|
|
11
|
+
/** What a caller knows of a token from its record: its ID, scope, expiry, making and coverage. */
|
|
12
|
+
const tokenInfoOf = (record) => {
|
|
13
|
+
const fields = {
|
|
14
|
+
id: record.id,
|
|
15
|
+
scope: record.scope,
|
|
16
|
+
expiresAt: record.expiresAt,
|
|
17
|
+
createdAt: record.createdAt
|
|
18
|
+
};
|
|
19
|
+
return record.repo === void 0 ? {
|
|
20
|
+
...fields,
|
|
21
|
+
prefix: record.prefix
|
|
22
|
+
} : {
|
|
23
|
+
...fields,
|
|
24
|
+
repo: record.repo
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
/** A token's caller: its actor, or its subject when it names none, for whom the actor acts. */
|
|
28
|
+
const tokenCaller = ({ record }) => {
|
|
29
|
+
const token = tokenInfoOf(record);
|
|
30
|
+
if (record.actor === void 0) return {
|
|
31
|
+
actor: { id: record.subject.id },
|
|
32
|
+
token
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
actor: { id: record.actor.id },
|
|
36
|
+
subject: { id: record.subject.id },
|
|
37
|
+
token
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* A server's `identify`: Git's own tokens first, then each extension's grant resolver, then the
|
|
42
|
+
* host's `auth`. A request with no credential is anonymous, unless `auth` names it; a credential
|
|
43
|
+
* none of them knows is `UNAUTHENTICATED`, even where an anonymous caller could read, so a
|
|
44
|
+
* mistyped token is never quietly anonymous. An `auth` answer or a grant naming an ID past
|
|
45
|
+
* `maxActorIdLength` bytes is `INVALID_ARGUMENT`.
|
|
46
|
+
*/
|
|
47
|
+
const identifier = (options) => {
|
|
48
|
+
const fromGrants = Effect.fnUntraced(function* (request, credentials) {
|
|
49
|
+
for (const resolver of options.grants()) {
|
|
50
|
+
const grant = yield* hostCall(options.reports, "grants", {}, (signal) => resolver.resolve({
|
|
51
|
+
credentials,
|
|
52
|
+
request,
|
|
53
|
+
signal
|
|
54
|
+
}));
|
|
55
|
+
if (grant === void 0) continue;
|
|
56
|
+
const long = longActorId(grant.actor, grant.subject);
|
|
57
|
+
if (long !== void 0) return yield* Effect.fail(long);
|
|
58
|
+
return grantCaller(grant, resolver.name);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
const fromAuth = (request, credentials) => {
|
|
62
|
+
const { auth } = options;
|
|
63
|
+
if (auth === void 0) return Effect.succeed(void 0);
|
|
64
|
+
return hostCall(options.reports, "auth", {}, (signal) => auth(credentials === void 0 ? {
|
|
65
|
+
request,
|
|
66
|
+
signal
|
|
67
|
+
} : {
|
|
68
|
+
request,
|
|
69
|
+
credentials,
|
|
70
|
+
signal
|
|
71
|
+
})).pipe(Effect.flatMap((actor) => {
|
|
72
|
+
const long = longActorId(actor);
|
|
73
|
+
return long === void 0 ? Effect.succeed(actor) : Effect.fail(long);
|
|
74
|
+
}));
|
|
75
|
+
};
|
|
76
|
+
return Effect.fnUntraced(function* (request) {
|
|
77
|
+
const read = requestCredentials(request);
|
|
78
|
+
if (read.kind === "unreadable") return yield* Effect.fail(unknownCredential());
|
|
79
|
+
if (read.kind === "none") {
|
|
80
|
+
const actor = yield* fromAuth(request, void 0);
|
|
81
|
+
return actor === void 0 ? anonymous : { actor };
|
|
82
|
+
}
|
|
83
|
+
const { credentials } = read;
|
|
84
|
+
const secret = credentialSecret(credentials);
|
|
85
|
+
if (options.tokens && secret.startsWith("gt_")) {
|
|
86
|
+
const held = yield* verifyToken(options.store, secret, yield* options.now);
|
|
87
|
+
if (held === void 0) return yield* Effect.fail(unknownCredential());
|
|
88
|
+
return tokenCaller(held);
|
|
89
|
+
}
|
|
90
|
+
const granted = yield* fromGrants(request, credentials);
|
|
91
|
+
if (granted !== void 0) return granted;
|
|
92
|
+
const actor = yield* fromAuth(request, credentials);
|
|
93
|
+
if (actor === void 0 || actor.anonymous === true) return yield* Effect.fail(unknownCredential());
|
|
94
|
+
return { actor };
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
export { identifier, tokenInfoOf };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { decodeRow, storeCall } from "../store/errors.mjs";
|
|
2
|
+
import { StoredRepo } from "../store/records.mjs";
|
|
3
|
+
import { collections, selfKey } from "../store/scopes.mjs";
|
|
4
|
+
import { hashSecret, placeScope, readTokenText, sameHash, tokenIdPlace } from "./token-text.mjs";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Schema from "effect/Schema";
|
|
7
|
+
// src/auth/token-rows.ts
|
|
8
|
+
const Party = Schema.Struct({ id: Schema.String });
|
|
9
|
+
/**
|
|
10
|
+
* A token's row, `tokens/<id>` in its place's scope. A repo token's repo is the record's name
|
|
11
|
+
* when it's read, so a rename keeps it working; a prefix token's prefix is in its ID.
|
|
12
|
+
*/
|
|
13
|
+
const TokenRow = Schema.Struct({
|
|
14
|
+
hash: Schema.String,
|
|
15
|
+
scope: Schema.Literals([
|
|
16
|
+
"read",
|
|
17
|
+
"report",
|
|
18
|
+
"write"
|
|
19
|
+
]),
|
|
20
|
+
expiresAt: Schema.Int,
|
|
21
|
+
subject: Party,
|
|
22
|
+
actor: Schema.optionalKey(Party),
|
|
23
|
+
createdAt: Schema.Int,
|
|
24
|
+
revokedAt: Schema.optionalKey(Schema.Int),
|
|
25
|
+
key: Schema.optionalKey(Schema.String)
|
|
26
|
+
});
|
|
27
|
+
const tokenKey = (id) => ({
|
|
28
|
+
collection: collections.tokens,
|
|
29
|
+
id
|
|
30
|
+
});
|
|
31
|
+
const selfRead = {
|
|
32
|
+
collection: selfKey.collection,
|
|
33
|
+
id: selfKey.id
|
|
34
|
+
};
|
|
35
|
+
/** The record a row answers as: its coverage, and who it acts for. */
|
|
36
|
+
const tokenRecord = (id, row, coverage) => {
|
|
37
|
+
const record = {
|
|
38
|
+
id,
|
|
39
|
+
scope: row.scope,
|
|
40
|
+
expiresAt: row.expiresAt,
|
|
41
|
+
createdAt: row.createdAt,
|
|
42
|
+
subject: row.subject,
|
|
43
|
+
...coverage
|
|
44
|
+
};
|
|
45
|
+
if (row.actor !== void 0) record.actor = row.actor;
|
|
46
|
+
if (row.revokedAt !== void 0) record.revokedAt = row.revokedAt;
|
|
47
|
+
return record;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Reads token `id`'s row, a repo token's repo record beside it, and `reads`, at one version:
|
|
51
|
+
* `undefined` for an ID Git never made, a row that isn't there, or a repo that's gone.
|
|
52
|
+
*/
|
|
53
|
+
const readToken = Effect.fnUntraced(function* (store, id, reads = []) {
|
|
54
|
+
const place = tokenIdPlace(id);
|
|
55
|
+
if (place === void 0) return void 0;
|
|
56
|
+
const own = place.kind === "repo" ? [tokenKey(id), selfRead] : [tokenKey(id)];
|
|
57
|
+
const snapshot = yield* storeCall(() => store.read(placeScope(place), [...own, ...reads]));
|
|
58
|
+
const [found] = snapshot.results[0] ?? [];
|
|
59
|
+
if (found === void 0) return void 0;
|
|
60
|
+
const row = yield* decodeRow(TokenRow, found, `Token '${id}'`);
|
|
61
|
+
const { version } = snapshot;
|
|
62
|
+
const results = snapshot.results.slice(own.length);
|
|
63
|
+
if (place.kind === "prefix") return {
|
|
64
|
+
place,
|
|
65
|
+
version,
|
|
66
|
+
row,
|
|
67
|
+
record: tokenRecord(id, row, { prefix: place.prefix }),
|
|
68
|
+
results
|
|
69
|
+
};
|
|
70
|
+
const [self] = snapshot.results[1] ?? [];
|
|
71
|
+
if (self === void 0) return void 0;
|
|
72
|
+
const repo = yield* decodeRow(StoredRepo, self, `Repo '${place.internalId}'`);
|
|
73
|
+
if (repo.deleted === true) return void 0;
|
|
74
|
+
return {
|
|
75
|
+
place,
|
|
76
|
+
version,
|
|
77
|
+
row,
|
|
78
|
+
record: tokenRecord(id, row, { repo: repo.name }),
|
|
79
|
+
repo,
|
|
80
|
+
results
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
/** A row's state at `now`: revoked, past its expiry, or active. */
|
|
84
|
+
const tokenState = (row, now) => {
|
|
85
|
+
if (row.revokedAt !== void 0) return "revoked";
|
|
86
|
+
return row.expiresAt <= now ? "expired" : "active";
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* The live token `text` is, or `undefined` for one Git never made, one whose secret doesn't match
|
|
90
|
+
* its row, or one revoked or past its expiry at `now`.
|
|
91
|
+
*/
|
|
92
|
+
const verifyToken = Effect.fnUntraced(function* (store, text, now) {
|
|
93
|
+
const read = readTokenText(text);
|
|
94
|
+
if (read === void 0) return void 0;
|
|
95
|
+
const held = yield* readToken(store, read.id);
|
|
96
|
+
if (held === void 0 || tokenState(held.row, now) !== "active") return void 0;
|
|
97
|
+
const hash = yield* Effect.promise(() => hashSecret(read.secret));
|
|
98
|
+
return sameHash(hash, held.row.hash) ? held : void 0;
|
|
99
|
+
});
|
|
100
|
+
export { TokenRow, readToken, tokenKey, tokenRecord, tokenState, verifyToken };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { isInternalId } from "../contracts/ids.mjs";
|
|
2
|
+
import { utf8 } from "../protocol/bytes/text.mjs";
|
|
3
|
+
import { fromBase64Url, randomText, toBase64Url } from "../store/random.mjs";
|
|
4
|
+
import { repoScope } from "../store/scopes.mjs";
|
|
5
|
+
// src/auth/token-text.ts
|
|
6
|
+
const prefixText = "gt_";
|
|
7
|
+
const placeText = (place) => place.kind === "repo" ? place.internalId : `p_${toBase64Url(utf8(place.prefix))}`;
|
|
8
|
+
/** The scope a token's row is in: its repo's, or `git/tokens/p_<prefix>` for a prefix's. */
|
|
9
|
+
const placeScope = (place) => place.kind === "repo" ? repoScope(place.internalId) : `git/tokens/${placeText(place)}`;
|
|
10
|
+
/** A token's ID: where it is, then 12 random bytes, so two never share a row. */
|
|
11
|
+
const newTokenId = (place) => `${placeText(place)}.${randomText(12)}`;
|
|
12
|
+
/** A token's text: `gt_<place>.<random>.<secret>`, where the secret is 32 random bytes. */
|
|
13
|
+
const tokenText = (id, secret) => `${prefixText}${id}.${secret}`;
|
|
14
|
+
const newSecret = () => randomText(32);
|
|
15
|
+
const readPlace = (text) => {
|
|
16
|
+
if (isInternalId(text)) return {
|
|
17
|
+
kind: "repo",
|
|
18
|
+
internalId: text
|
|
19
|
+
};
|
|
20
|
+
if (!text.startsWith("p_")) return void 0;
|
|
21
|
+
const prefix = fromBase64Url(text.slice(2));
|
|
22
|
+
if (prefix === void 0 || !(prefix === "" || prefix.endsWith("/"))) return void 0;
|
|
23
|
+
return {
|
|
24
|
+
kind: "prefix",
|
|
25
|
+
prefix
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
/** Reads a token's text, or `undefined` for a credential that isn't one of Git's tokens. */
|
|
29
|
+
const readTokenText = (text) => {
|
|
30
|
+
if (!text.startsWith(prefixText)) return void 0;
|
|
31
|
+
const parts = text.slice(3).split(".");
|
|
32
|
+
if (parts.length !== 3) return void 0;
|
|
33
|
+
const [placePart = "", random = "", secret = ""] = parts;
|
|
34
|
+
if (!/^[A-Za-z0-9_-]{16}$/.test(random) || !/^[A-Za-z0-9_-]{43}$/.test(secret)) return void 0;
|
|
35
|
+
const place = readPlace(placePart);
|
|
36
|
+
if (place === void 0) return void 0;
|
|
37
|
+
return {
|
|
38
|
+
id: `${placePart}.${random}`,
|
|
39
|
+
place,
|
|
40
|
+
secret
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/** The place a token's ID names, or `undefined` for an ID Git never made. */
|
|
44
|
+
const tokenIdPlace = (id) => {
|
|
45
|
+
const [placePart = "", random = "", ...rest] = id.split(".");
|
|
46
|
+
if (rest.length > 0 || !/^[A-Za-z0-9_-]{16}$/.test(random)) return void 0;
|
|
47
|
+
return readPlace(placePart);
|
|
48
|
+
};
|
|
49
|
+
/** Whether token `id` was made in repo `internalId`'s scope: a repo token of that repo. */
|
|
50
|
+
const isTokenOf = (id, internalId) => {
|
|
51
|
+
const place = tokenIdPlace(id);
|
|
52
|
+
return place?.kind === "repo" && place.internalId === internalId;
|
|
53
|
+
};
|
|
54
|
+
/** The SHA-256 of a secret, as lowercase hex: all a token's row keeps of it. */
|
|
55
|
+
const hashSecret = async (secret) => {
|
|
56
|
+
const digest = await crypto.subtle.digest("SHA-256", utf8(secret));
|
|
57
|
+
return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
58
|
+
};
|
|
59
|
+
/** Compares two hashes in time that doesn't depend on where they differ. */
|
|
60
|
+
const sameHash = (a, b) => {
|
|
61
|
+
if (a.length !== b.length) return false;
|
|
62
|
+
let difference = 0;
|
|
63
|
+
for (let index = 0; index < a.length; index += 1) difference |= a.charCodeAt(index) ^ b.charCodeAt(index);
|
|
64
|
+
return difference === 0;
|
|
65
|
+
};
|
|
66
|
+
export { hashSecret, isTokenOf, newSecret, newTokenId, placeScope, placeText, readTokenText, sameHash, tokenIdPlace, tokenText };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import "../contracts/promises.mjs";
|
|
2
|
+
import "../contracts/actors.mjs";
|
|
3
|
+
import "../contracts/operations.mjs";
|
|
4
|
+
import "../contracts/services.mjs";
|
|
5
|
+
import { TokensFeature } from "../contracts/tokens.mjs";
|
|
6
|
+
import "../store/outbox.mjs";
|
|
7
|
+
import { JobDefinition, Moment, Read, Row } from "@ref0/infra";
|
|
8
|
+
import "effect/Effect";
|
|
9
|
+
/** Turns on Git's own tokens. */
|
|
10
|
+
export declare const tokens: () => TokensFeature;
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import { resolveRepo } from "../store/catalogue.mjs";
|
|
2
|
+
import { decodeRow, fail, storeCall } from "../store/errors.mjs";
|
|
3
|
+
import { runJobTry } from "../store/crossing.mjs";
|
|
4
|
+
import { appendEvents, decodeOutbox, outboxReads } from "../store/outbox.mjs";
|
|
5
|
+
import { collections, newChangeId } from "../store/scopes.mjs";
|
|
6
|
+
import { settleName } from "../store/settle.mjs";
|
|
7
|
+
import { longActorId } from "./authorize.mjs";
|
|
8
|
+
import { TokenRow, readToken, tokenKey, tokenRecord, tokenState } from "./token-rows.mjs";
|
|
9
|
+
import { hashSecret, newSecret, newTokenId, placeScope, tokenText } from "./token-text.mjs";
|
|
10
|
+
import { defineJob } from "@ref0/infra";
|
|
11
|
+
import * as Effect from "effect/Effect";
|
|
12
|
+
import * as Schema from "effect/Schema";
|
|
13
|
+
// src/auth/tokens.ts
|
|
14
|
+
/** Turns on Git's own tokens. */
|
|
15
|
+
const tokens = () => ({ kind: "tokens" });
|
|
16
|
+
const day = 864e5;
|
|
17
|
+
/** The longest a token may live. */
|
|
18
|
+
const maxTokenLife = 365 * day;
|
|
19
|
+
/** How long a row is kept past its expiry, so a list still shows what just ended. */
|
|
20
|
+
const keptAfterExpiry = 7 * day;
|
|
21
|
+
const cleanupBatch = 100;
|
|
22
|
+
/** How often a write tries again when its scope moved under it before giving up. */
|
|
23
|
+
const attempts = 5;
|
|
24
|
+
const tokenCleanupName = "git.tokens.cleanup";
|
|
25
|
+
const ExpiryRow = Schema.Struct({ key: Schema.optionalKey(Schema.String) });
|
|
26
|
+
/** A key's row: the token it made, or none while `revokeKey` holds it. */
|
|
27
|
+
const KeyRow = Schema.Struct({ id: Schema.optionalKey(Schema.String) });
|
|
28
|
+
const keyRead = (key) => ({
|
|
29
|
+
collection: collections.tokenKeys,
|
|
30
|
+
id: key
|
|
31
|
+
});
|
|
32
|
+
/** A row in `token-expiry`, ordered by when its token expires, then by its ID. */
|
|
33
|
+
const expiryId = (expiresAt, id) => `${String(expiresAt).padStart(16, "0")}.${id}`;
|
|
34
|
+
const expiryOf = (row) => Number(row.id.slice(0, 16));
|
|
35
|
+
const contended = () => fail("UNAVAILABLE", "Too many writes reached these tokens at once", { hint: "Try again" });
|
|
36
|
+
/** Whether a target names a prefix's tokens, not a repo's. */
|
|
37
|
+
const isPrefixTarget = Schema.is(Schema.Struct({ prefix: Schema.String }));
|
|
38
|
+
/** A create's parties, as its row keeps them: the actor only when it isn't the subject. */
|
|
39
|
+
const tokenParties = (input) => input.actor === void 0 || input.actor.id === input.subject.id ? { subject: { id: input.subject.id } } : {
|
|
40
|
+
subject: { id: input.subject.id },
|
|
41
|
+
actor: { id: input.actor.id }
|
|
42
|
+
};
|
|
43
|
+
const moved = () => fail("UNAVAILABLE", "The repo moved while this call ran", { hint: "Try again" });
|
|
44
|
+
/**
|
|
45
|
+
* The place and coverage a target names, read with `reads` at one version of its scope. `held` is
|
|
46
|
+
* the repo `authorize` checked for a caller: a name that points at another one since, or at none,
|
|
47
|
+
* is refused without saying where any repo went, since `authorize` let the caller on only `held`.
|
|
48
|
+
*/
|
|
49
|
+
const readTarget = Effect.fnUntraced(function* (store, target, reads, held) {
|
|
50
|
+
if (!isPrefixTarget(target)) {
|
|
51
|
+
const resolved = resolveRepo(store, target, reads);
|
|
52
|
+
const { name, internalId, record, snapshot } = yield* held === void 0 ? resolved : resolved.pipe(Effect.catch((error) => error.code === "NOT_FOUND" ? moved() : Effect.fail(error)));
|
|
53
|
+
if (held !== void 0 && internalId !== held) return yield* moved();
|
|
54
|
+
return {
|
|
55
|
+
place: {
|
|
56
|
+
kind: "repo",
|
|
57
|
+
internalId
|
|
58
|
+
},
|
|
59
|
+
coverage: { repo: record.name },
|
|
60
|
+
confirmed: name,
|
|
61
|
+
version: snapshot.version,
|
|
62
|
+
results: snapshot.results.slice(1)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const { prefix } = target;
|
|
66
|
+
if (prefix !== "" && !prefix.endsWith("/")) return yield* fail("INVALID_ARGUMENT", `A prefix ends in '/' or is empty, not '${prefix}'`);
|
|
67
|
+
const place = {
|
|
68
|
+
kind: "prefix",
|
|
69
|
+
prefix
|
|
70
|
+
};
|
|
71
|
+
const snapshot = yield* storeCall(() => store.read(placeScope(place), [...reads]));
|
|
72
|
+
return {
|
|
73
|
+
place,
|
|
74
|
+
coverage: { prefix },
|
|
75
|
+
confirmed: void 0,
|
|
76
|
+
version: snapshot.version,
|
|
77
|
+
results: snapshot.results
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
/**
|
|
81
|
+
* A token event's actor: for `token.created`, who made it, else who it acts for; for
|
|
82
|
+
* `token.revoked`, the caller's when it named one, and none for the host's own revoke (Q180).
|
|
83
|
+
*/
|
|
84
|
+
const tokenActor = (type, row, caller) => {
|
|
85
|
+
if (caller !== void 0 && caller.actor.anonymous !== true) return { id: caller.actor.id };
|
|
86
|
+
return type === "token.created" ? row.actor ?? row.subject : void 0;
|
|
87
|
+
};
|
|
88
|
+
/** A token's event: what it is, and what it covers, IDs only. */
|
|
89
|
+
const tokenEvent = (type, id, row, coverage, caller) => {
|
|
90
|
+
const event = {
|
|
91
|
+
type,
|
|
92
|
+
token: id,
|
|
93
|
+
scope: row.scope,
|
|
94
|
+
subject: row.subject,
|
|
95
|
+
...coverage
|
|
96
|
+
};
|
|
97
|
+
const actor = tokenActor(type, row, caller);
|
|
98
|
+
return actor === void 0 ? event : {
|
|
99
|
+
...event,
|
|
100
|
+
actor
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
const momentOf = (at) => at instanceof Date ? at.getTime() : at;
|
|
104
|
+
/** A new token's expiry as a moment: in the future, and at most a year after `now`. */
|
|
105
|
+
const tokenExpiry = (now, at) => {
|
|
106
|
+
const expiresAt = momentOf(at);
|
|
107
|
+
if (!Number.isSafeInteger(expiresAt) || expiresAt <= now) return fail("INVALID_ARGUMENT", "A token's expiry is in the future");
|
|
108
|
+
if (expiresAt > now + 31536e6) return fail("INVALID_ARGUMENT", "A token lives at most a year", { hint: "Create a new one before it expires" });
|
|
109
|
+
return Effect.succeed(expiresAt);
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Git's own tokens: a row each, in its repo's scope or its prefix's, holding only the secret's
|
|
113
|
+
* hash. Direct calls trust host code; over HTTP, `identify` and `authorize` run first.
|
|
114
|
+
*/
|
|
115
|
+
const tokenCalls = (options) => {
|
|
116
|
+
const { store } = options;
|
|
117
|
+
const create = Effect.fnUntraced(function* (target, input, held) {
|
|
118
|
+
const long = longActorId(input.subject, input.actor);
|
|
119
|
+
if (long !== void 0) return yield* Effect.fail(long);
|
|
120
|
+
const now = yield* options.now;
|
|
121
|
+
const expiresAt = yield* tokenExpiry(now, input.expiresAt);
|
|
122
|
+
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
123
|
+
const reads = input.key === void 0 ? [] : [keyRead(input.key)];
|
|
124
|
+
const read = yield* readTarget(store, target, [...reads, ...outboxReads], held);
|
|
125
|
+
const { place, coverage, version } = read;
|
|
126
|
+
const results = read.results.slice(0, reads.length);
|
|
127
|
+
const outbox = yield* decodeOutbox(read.results.slice(reads.length));
|
|
128
|
+
if ((results[0]?.length ?? 0) > 0) return yield* fail("ALREADY_EXISTS", "This key made a token already", {
|
|
129
|
+
hint: "A token's secret is shown once: create one with a new key",
|
|
130
|
+
context: { reason: "key-reused" }
|
|
131
|
+
});
|
|
132
|
+
const id = newTokenId(place);
|
|
133
|
+
const secret = newSecret();
|
|
134
|
+
const row = {
|
|
135
|
+
hash: yield* Effect.promise(() => hashSecret(secret)),
|
|
136
|
+
scope: input.scope,
|
|
137
|
+
expiresAt,
|
|
138
|
+
...tokenParties(input),
|
|
139
|
+
createdAt: now
|
|
140
|
+
};
|
|
141
|
+
const expiry = {};
|
|
142
|
+
const put = [{
|
|
143
|
+
...tokenKey(id),
|
|
144
|
+
value: row
|
|
145
|
+
}];
|
|
146
|
+
if (input.key !== void 0) {
|
|
147
|
+
row.key = input.key;
|
|
148
|
+
expiry.key = input.key;
|
|
149
|
+
put.push({
|
|
150
|
+
collection: collections.tokenKeys,
|
|
151
|
+
id: input.key,
|
|
152
|
+
value: { id }
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
put.push({
|
|
156
|
+
collection: collections.tokenExpiry,
|
|
157
|
+
id: expiryId(expiresAt, id),
|
|
158
|
+
value: expiry
|
|
159
|
+
});
|
|
160
|
+
const job = options.cleanup.job({
|
|
161
|
+
key: "cleanup",
|
|
162
|
+
data: {},
|
|
163
|
+
at: expiresAt + keptAfterExpiry
|
|
164
|
+
});
|
|
165
|
+
const scope = placeScope(place);
|
|
166
|
+
const event = tokenEvent("token.created", id, row, coverage);
|
|
167
|
+
const appended = yield* appendEvents(options.events, outbox, [event], {
|
|
168
|
+
scope,
|
|
169
|
+
at: now,
|
|
170
|
+
confirmed: read.confirmed
|
|
171
|
+
});
|
|
172
|
+
const change = {
|
|
173
|
+
id: newChangeId(),
|
|
174
|
+
expect: version,
|
|
175
|
+
put: [...put, ...appended.put],
|
|
176
|
+
delete: appended.delete,
|
|
177
|
+
jobs: [job, ...appended.jobs]
|
|
178
|
+
};
|
|
179
|
+
if (!(yield* storeCall(() => store.commit(scope, change))).ok) continue;
|
|
180
|
+
return {
|
|
181
|
+
...tokenRecord(id, row, coverage),
|
|
182
|
+
secret: tokenText(id, secret)
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
return yield* contended();
|
|
186
|
+
});
|
|
187
|
+
const list = Effect.fnUntraced(function* (target, input = {}, held) {
|
|
188
|
+
const now = yield* options.now;
|
|
189
|
+
const limit = Math.min(input.page?.limit ?? 50, 200);
|
|
190
|
+
const read = {
|
|
191
|
+
collection: collections.tokens,
|
|
192
|
+
limit
|
|
193
|
+
};
|
|
194
|
+
if (input.page?.after !== void 0) read.after = input.page.after;
|
|
195
|
+
const { coverage, results } = yield* readTarget(store, target, [read], held);
|
|
196
|
+
const rows = results[0] ?? [];
|
|
197
|
+
const state = input.state ?? "active";
|
|
198
|
+
const items = [];
|
|
199
|
+
for (const found of rows) {
|
|
200
|
+
const row = yield* decodeRow(TokenRow, found, `Token '${found.id}'`);
|
|
201
|
+
if (state === "all" || tokenState(row, now) === state) items.push(tokenRecord(found.id, row, coverage));
|
|
202
|
+
}
|
|
203
|
+
const last = rows.at(-1);
|
|
204
|
+
return rows.length === limit && last !== void 0 ? {
|
|
205
|
+
items,
|
|
206
|
+
next: last.id
|
|
207
|
+
} : { items };
|
|
208
|
+
});
|
|
209
|
+
const get = Effect.fnUntraced(function* (id) {
|
|
210
|
+
const held = yield* readToken(store, id);
|
|
211
|
+
if (held === void 0) return yield* fail("NOT_FOUND", `No token '${id}'`);
|
|
212
|
+
return held.record;
|
|
213
|
+
});
|
|
214
|
+
const revoke = Effect.fnUntraced(function* (id, _input, caller) {
|
|
215
|
+
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
216
|
+
const held = yield* readToken(store, id, outboxReads);
|
|
217
|
+
if (held === void 0) return yield* fail("NOT_FOUND", `No token '${id}'`);
|
|
218
|
+
if (held.row.revokedAt !== void 0) return;
|
|
219
|
+
const at = yield* options.now;
|
|
220
|
+
const scope = placeScope(held.place);
|
|
221
|
+
const outbox = yield* decodeOutbox(held.results);
|
|
222
|
+
const settling = {
|
|
223
|
+
version: held.version,
|
|
224
|
+
head: outbox.head,
|
|
225
|
+
record: held.repo
|
|
226
|
+
};
|
|
227
|
+
if (yield* settleName(store, scope, settling)) continue;
|
|
228
|
+
const coverage = held.record.repo === void 0 ? { prefix: held.record.prefix } : { repo: held.record.repo };
|
|
229
|
+
const event = tokenEvent("token.revoked", id, held.row, coverage, caller);
|
|
230
|
+
const appended = yield* appendEvents(options.events, outbox, [event], {
|
|
231
|
+
scope,
|
|
232
|
+
at,
|
|
233
|
+
exempt: true
|
|
234
|
+
});
|
|
235
|
+
const value = {
|
|
236
|
+
...held.row,
|
|
237
|
+
revokedAt: at
|
|
238
|
+
};
|
|
239
|
+
const change = {
|
|
240
|
+
id: newChangeId(),
|
|
241
|
+
expect: held.version,
|
|
242
|
+
put: [{
|
|
243
|
+
...tokenKey(id),
|
|
244
|
+
value
|
|
245
|
+
}, ...appended.put],
|
|
246
|
+
delete: appended.delete,
|
|
247
|
+
jobs: appended.jobs
|
|
248
|
+
};
|
|
249
|
+
if ((yield* storeCall(() => store.commit(scope, change))).ok) return;
|
|
250
|
+
}
|
|
251
|
+
return yield* contended();
|
|
252
|
+
});
|
|
253
|
+
return {
|
|
254
|
+
create,
|
|
255
|
+
list,
|
|
256
|
+
get,
|
|
257
|
+
revoke,
|
|
258
|
+
revokeKey: Effect.fnUntraced(function* (target, key, input) {
|
|
259
|
+
const now = yield* options.now;
|
|
260
|
+
const until = input.until instanceof Date ? input.until.getTime() : input.until;
|
|
261
|
+
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
262
|
+
const read = yield* readTarget(store, target, [keyRead(key)]);
|
|
263
|
+
const found = read.results[0]?.[0];
|
|
264
|
+
if (found !== void 0) {
|
|
265
|
+
const { id } = yield* decodeRow(KeyRow, found, `Token key '${key}'`);
|
|
266
|
+
return id === void 0 ? void 0 : yield* revoke(id);
|
|
267
|
+
}
|
|
268
|
+
if (until <= now) return;
|
|
269
|
+
const change = {
|
|
270
|
+
id: newChangeId(),
|
|
271
|
+
expect: read.version,
|
|
272
|
+
put: [{
|
|
273
|
+
collection: collections.tokenKeys,
|
|
274
|
+
id: key,
|
|
275
|
+
value: {}
|
|
276
|
+
}, {
|
|
277
|
+
collection: collections.tokenExpiry,
|
|
278
|
+
id: expiryId(until, newTokenId(read.place)),
|
|
279
|
+
value: { key }
|
|
280
|
+
}],
|
|
281
|
+
jobs: [options.cleanup.job({
|
|
282
|
+
key: "cleanup",
|
|
283
|
+
data: {},
|
|
284
|
+
at: until + keptAfterExpiry
|
|
285
|
+
})]
|
|
286
|
+
};
|
|
287
|
+
if ((yield* storeCall(() => store.commit(placeScope(read.place), change))).ok) return;
|
|
288
|
+
}
|
|
289
|
+
return yield* contended();
|
|
290
|
+
})
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
/**
|
|
294
|
+
* One batch of `git.tokens.cleanup` in a scope: deletes up to 100 tokens a week past their expiry,
|
|
295
|
+
* oldest first, with their keys, and runs again for the next batch or the next to come due.
|
|
296
|
+
*/
|
|
297
|
+
const cleanupScope = Effect.fnUntraced(function* (store, scope, now) {
|
|
298
|
+
const read = {
|
|
299
|
+
collection: collections.tokenExpiry,
|
|
300
|
+
limit: 101
|
|
301
|
+
};
|
|
302
|
+
const snapshot = yield* storeCall(() => store.read(scope, [read]));
|
|
303
|
+
const rows = snapshot.results[0] ?? [];
|
|
304
|
+
const due = rows.filter((row) => expiryOf(row) + keptAfterExpiry <= now).slice(0, cleanupBatch);
|
|
305
|
+
const deleted = [];
|
|
306
|
+
for (const row of due) {
|
|
307
|
+
const { key } = yield* decodeRow(ExpiryRow, row, `Token expiry '${row.id}'`);
|
|
308
|
+
const id = row.id.slice(17);
|
|
309
|
+
deleted.push({
|
|
310
|
+
collection: collections.tokenExpiry,
|
|
311
|
+
id: row.id
|
|
312
|
+
}, tokenKey(id));
|
|
313
|
+
if (key !== void 0) deleted.push({
|
|
314
|
+
collection: collections.tokenKeys,
|
|
315
|
+
id: key
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
if (deleted.length > 0) {
|
|
319
|
+
const change = {
|
|
320
|
+
id: newChangeId(),
|
|
321
|
+
expect: snapshot.version,
|
|
322
|
+
delete: deleted
|
|
323
|
+
};
|
|
324
|
+
if (!(yield* storeCall(() => store.commit(scope, change))).ok) return { kind: "more" };
|
|
325
|
+
}
|
|
326
|
+
const next = rows[due.length];
|
|
327
|
+
if (next === void 0) return void 0;
|
|
328
|
+
return {
|
|
329
|
+
kind: "more",
|
|
330
|
+
at: Math.max(now, expiryOf(next) + keptAfterExpiry)
|
|
331
|
+
};
|
|
332
|
+
});
|
|
333
|
+
/** `git.tokens.cleanup`'s try, on the server's clock. */
|
|
334
|
+
const cleanupHandler = (now) => (job, context) => runJobTry(Effect.flatMap(now, (at) => cleanupScope(context.store, job.scope, at)));
|
|
335
|
+
/** `git.tokens.cleanup`, on the server's clock. */
|
|
336
|
+
const tokenCleanupJob = (now) => defineJob({
|
|
337
|
+
name: tokenCleanupName,
|
|
338
|
+
schema: Schema.toStandardSchemaV1(Schema.Struct({})),
|
|
339
|
+
retry: {
|
|
340
|
+
limit: 10,
|
|
341
|
+
delay: "1 second",
|
|
342
|
+
backoff: "exponential",
|
|
343
|
+
maxDelay: "5 minutes"
|
|
344
|
+
},
|
|
345
|
+
handler: cleanupHandler(now)
|
|
346
|
+
});
|
|
347
|
+
export { cleanupHandler, isPrefixTarget, keptAfterExpiry, maxTokenLife, readTarget, tokenCalls, tokenCleanupJob, tokenCleanupName, tokenExpiry, tokenParties, tokens };
|
package/dist/auth.d.mts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AccessJwtIdentity, AccessJwtOptions, accessHeader, accessJwt } from "./auth/access-jwt.mjs";
|
|
2
|
+
import { BasicOptions, BearerOptions, basic, bearer } from "./auth/helpers.mjs";
|
|
3
|
+
import { tokens } from "./auth/tokens.mjs";
|
|
4
|
+
import { ghClientId } from "./signin/context.mjs";
|
|
5
|
+
import { AccessTokenAnswer, DeviceCodeAnswer, deviceGrant, readAccessTokenAnswer, readDeviceCodeAnswer, signInPaths } from "./signin/wire.mjs";
|
|
6
|
+
import { TokensFeature } from "./contracts/tokens.mjs";
|
|
7
|
+
export { type AccessJwtIdentity, type AccessJwtOptions, type AccessTokenAnswer, type BasicOptions, type BearerOptions, type DeviceCodeAnswer, type TokensFeature, accessHeader, accessJwt, basic, bearer, deviceGrant, ghClientId, readAccessTokenAnswer, readDeviceCodeAnswer, signInPaths, tokens };
|
package/dist/auth.mjs
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { accessHeader, accessJwt } from "./auth/access-jwt.mjs";
|
|
2
|
+
import { basic, bearer } from "./auth/helpers.mjs";
|
|
3
|
+
import { tokens } from "./auth/tokens.mjs";
|
|
4
|
+
import { ghClientId } from "./signin/context.mjs";
|
|
5
|
+
import { deviceGrant, readAccessTokenAnswer, readDeviceCodeAnswer, signInPaths } from "./signin/wire.mjs";
|
|
6
|
+
export { accessHeader, accessJwt, basic, bearer, deviceGrant, ghClientId, readAccessTokenAnswer, readDeviceCodeAnswer, signInPaths, tokens };
|