@ref0/git 0.7.0 → 0.8.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/access/private-refs.mjs +0 -2
- package/dist/auth/authorize.mjs +31 -24
- package/dist/auth/bridge.mjs +8 -8
- package/dist/auth/fences.d.mts +0 -1
- package/dist/auth/fences.mjs +1 -1
- package/dist/auth/grants.d.mts +0 -1
- package/dist/auth/grants.mjs +2 -2
- package/dist/auth/host-function.d.mts +1 -7
- package/dist/auth/host-function.mjs +38 -38
- package/dist/auth/identify.d.mts +0 -1
- package/dist/auth/identify.mjs +1 -1
- package/dist/auth/policy.d.mts +7 -4
- package/dist/auth/policy.mjs +13 -10
- package/dist/auth/token-rows.mjs +2 -5
- package/dist/auth/tokens-layer.d.mts +0 -2
- package/dist/auth/tokens-public.d.mts +3 -3
- package/dist/auth/tokens-public.mjs +4 -2
- package/dist/auth/tokens.d.mts +6 -1
- package/dist/auth/tokens.mjs +7 -1
- package/dist/client/client.d.mts +22 -15
- package/dist/client/client.mjs +31 -27
- package/dist/client/git-http.mjs +22 -5
- package/dist/client/local.mjs +1 -1
- package/dist/client/namespace.d.mts +2 -0
- package/dist/client/push-upload.d.mts +1 -0
- package/dist/client/push-upload.mjs +169 -2
- package/dist/client/remote-helper.mjs +2 -4
- package/dist/client/remote.mjs +37 -15
- package/dist/client/run-remote-helper.mjs +4 -4
- package/dist/client/transport.mjs +26 -19
- package/dist/contracts/actors.d.mts +57 -28
- package/dist/contracts/actors.mjs +38 -2
- package/dist/contracts/authorize.d.mts +21 -15
- package/dist/contracts/callers.mjs +40 -0
- package/dist/contracts/client.d.mts +16 -9
- package/dist/contracts/events.d.mts +12 -10
- package/dist/contracts/events.mjs +8 -6
- package/dist/contracts/files.d.mts +42 -42
- package/dist/contracts/forks.d.mts +0 -24
- package/dist/contracts/git-hooks.d.mts +217 -0
- package/dist/contracts/git-hooks.mjs +3 -1
- package/dist/contracts/grants.d.mts +46 -27
- package/dist/contracts/lfs.d.mts +17 -4
- package/dist/contracts/merges.d.mts +7 -7
- package/dist/contracts/objects.d.mts +20 -4
- package/dist/contracts/opaque.mjs +19 -1
- package/dist/contracts/operations.d.mts +8 -1
- package/dist/contracts/operations.mjs +209 -0
- package/dist/contracts/queue.d.mts +3 -3
- package/dist/contracts/queue.mjs +5 -18
- package/dist/contracts/remote.d.mts +13 -4
- package/dist/contracts/remote.mjs +3 -3
- package/dist/contracts/repos.d.mts +11 -40
- package/dist/contracts/repos.mjs +11 -10
- package/dist/contracts/result.d.mts +28 -11
- package/dist/contracts/result.mjs +32 -2
- package/dist/contracts/rules.d.mts +706 -46
- package/dist/contracts/rules.mjs +81 -2
- package/dist/contracts/server.d.mts +5 -275
- package/dist/contracts/services.d.mts +0 -3
- package/dist/contracts/services.mjs +1 -3
- package/dist/contracts/signin.d.mts +2 -2
- package/dist/contracts/signin.mjs +4 -5
- package/dist/contracts/sync.d.mts +1 -4
- package/dist/contracts/tokens.d.mts +29 -17
- package/dist/contracts/tokens.mjs +14 -3
- package/dist/contracts/topics.d.mts +38 -11
- package/dist/contracts/topics.mjs +8 -2
- package/dist/core/access.d.mts +0 -2
- package/dist/core/access.mjs +15 -4
- package/dist/core/events/deliver.mjs +19 -1
- package/dist/core/forks.mjs +30 -11
- package/dist/core/hooks/groups.d.mts +0 -1
- package/dist/core/hooks/groups.mjs +8 -9
- package/dist/core/loose-tally.mjs +46 -0
- package/dist/core/objects/writing.mjs +1 -0
- package/dist/core/promise.mjs +1 -15
- package/dist/core/purge.mjs +14 -9
- package/dist/core/push.mjs +13 -6
- package/dist/core/ref-view.mjs +14 -6
- package/dist/core/repack.mjs +19 -14
- package/dist/core/repo-info.mjs +8 -6
- package/dist/core/repos.mjs +1 -0
- package/dist/core/rules/check.mjs +10 -10
- package/dist/core/rules/context.d.mts +3 -1
- package/dist/core/rules/context.mjs +16 -13
- package/dist/core/rules/fetch.mjs +17 -23
- package/dist/core/tokens.mjs +2 -1
- package/dist/effect.d.mts +2 -4
- package/dist/effect.mjs +2 -4
- package/dist/engine/commits.mjs +19 -47
- package/dist/engine/failures.d.mts +1 -2
- package/dist/engine/failures.mjs +1 -3
- package/dist/engine/merge-base-walk.mjs +57 -142
- package/dist/engine/merge-bases.mjs +5 -5
- package/dist/engine/merge.mjs +16 -14
- package/dist/extend.d.mts +1 -2
- package/dist/extend.mjs +1 -2
- package/dist/http/core-parts.mjs +1 -2
- package/dist/http/handler.mjs +11 -31
- package/dist/http/parts.d.mts +0 -1
- package/dist/index.d.mts +28 -21
- package/dist/index.mjs +5 -2
- package/dist/lfs/base.d.mts +6 -3
- package/dist/lfs/base.mjs +2 -1
- package/dist/lfs/layer.d.mts +4 -3
- package/dist/lfs/layer.mjs +23 -9
- package/dist/lfs/objects.mjs +90 -41
- package/dist/lfs/pointers.mjs +69 -18
- package/dist/lfs/purge.mjs +6 -2
- package/dist/lfs/rows.mjs +24 -7
- package/dist/lfs/service.d.mts +6 -3
- package/dist/lfs/service.mjs +8 -2
- package/dist/lfs/upkeep.mjs +44 -26
- package/dist/lfs/upload-most.mjs +41 -0
- package/dist/lfs/uploaded.mjs +59 -0
- package/dist/protocol/bytes/sha256-hasher.mjs +51 -0
- package/dist/protocol/bytes/text.mjs +6 -1
- package/dist/protocol/objects/fsck.mjs +6 -3
- package/dist/queue/advance.mjs +38 -8
- package/dist/queue/calls.mjs +4 -14
- package/dist/queue/lanes.mjs +1 -1
- package/dist/queue/rows.mjs +8 -0
- package/dist/queue/schedule.mjs +1 -1
- package/dist/queue/search.mjs +3 -4
- package/dist/rest/client-namespace.d.mts +2 -0
- package/dist/rest/client.d.mts +32 -8
- package/dist/rest/client.mjs +308 -382
- package/dist/rest/commits.d.mts +240 -240
- package/dist/rest/files.d.mts +18 -18
- package/dist/rest/forks.d.mts +45 -57
- package/dist/rest/handlers.mjs +2 -1
- package/dist/rest/listen.d.mts +8 -6
- package/dist/rest/listen.mjs +31 -75
- package/dist/rest/me.d.mts +2 -2
- package/dist/rest/merges.d.mts +7 -7
- package/dist/rest/refs.d.mts +139 -139
- package/dist/rest/repos.d.mts +54 -66
- package/dist/rest/tokens.d.mts +12 -12
- package/dist/rest/topics.d.mts +110 -110
- package/dist/rest/trees.d.mts +66 -66
- package/dist/rest/wire.d.mts +1 -1
- package/dist/rest.d.mts +1 -7
- package/dist/rest.mjs +1 -5
- package/dist/server/git-layer.d.mts +10 -2
- package/dist/server/git-layer.mjs +29 -10
- package/dist/server/joined.d.mts +1 -1
- package/dist/server/server.d.mts +0 -1
- package/dist/server/server.mjs +26 -45
- package/dist/signin/context.d.mts +0 -1
- package/dist/signin/context.mjs +5 -9
- package/dist/storage/clean-up.mjs +3 -1
- package/dist/storage/fsck.mjs +12 -2
- package/dist/storage/graph-rebuild.mjs +262 -0
- package/dist/storage/index-build.mjs +100 -12
- package/dist/storage/lfs-pointers.d.mts +5 -5
- package/dist/storage/lfs-pointers.mjs +37 -11
- package/dist/storage/loose.mjs +4 -1
- package/dist/storage/memory-budget.mjs +1 -1
- package/dist/storage/merge-fence.mjs +81 -19
- package/dist/storage/merge-most.mjs +1 -0
- package/dist/storage/merge-row.mjs +16 -4
- package/dist/storage/merge-stream.mjs +9 -6
- package/dist/storage/object-rows.mjs +17 -1
- package/dist/storage/pack-receive.mjs +10 -6
- package/dist/storage/packs.mjs +58 -27
- package/dist/storage/prune.mjs +68 -40
- package/dist/storage/ready.d.mts +1 -1
- package/dist/storage/ready.mjs +12 -3
- package/dist/storage/receive-state.mjs +1 -1
- package/dist/storage/repack-contained.mjs +22 -14
- package/dist/storage/repack.d.mts +1 -1
- package/dist/storage/repack.mjs +3 -2
- package/dist/storage/unpack.mjs +7 -0
- package/dist/store/call-count.d.mts +23 -3
- package/dist/store/call-count.mjs +36 -13
- package/dist/store/records.mjs +10 -4
- package/dist/store/repo-record.mjs +29 -12
- package/dist/store/scopes.mjs +6 -1
- package/dist/sync/import.mjs +14 -2
- package/dist/sync/layer.d.mts +5 -1
- package/dist/sync/layer.mjs +7 -2
- package/dist/sync/step.mjs +15 -15
- package/dist/topics/advance.mjs +7 -6
- package/dist/topics/members.mjs +38 -9
- package/package.json +3 -3
- package/dist/engine/merge-base-walk.d.mts +0 -3
- package/dist/server/routes.d.mts +0 -32
- package/dist/server/routes.mjs +0 -69
- package/dist/sync/bridge.d.mts +0 -6
- package/dist/sync/bridge.mjs +0 -29
|
@@ -135,8 +135,6 @@ const wholeView = (all) => ({
|
|
|
135
135
|
* Until private branches are whole, it hides less than its name says:
|
|
136
136
|
* - **Objects by ID:** an object no ref the caller sees reaches answers as one the repo lacks,
|
|
137
137
|
* on every surface that takes an ID, and so does a Git LFS object none points at.
|
|
138
|
-
* - **LFS pushes:** a push's pointer check asks only whether the repo lists an object, so a
|
|
139
|
-
* caller who knows a hidden object's SHA-256 and size can push a pointer to it, then read it.
|
|
140
138
|
* - **Jobs:** the server's jobs and host calls read every ref, so a pull request, a webhook
|
|
141
139
|
* payload or an import can copy a hidden ref's name or commits where its readers see them,
|
|
142
140
|
* until piece 3. A fork copies only the refs its caller sees, and a mirror's every try asks the
|
package/dist/auth/authorize.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { utf8 } from "../protocol/bytes/text.mjs";
|
|
|
6
6
|
import { internalIdOf } from "../store/catalogue.mjs";
|
|
7
7
|
import { actingOf } from "./acting.mjs";
|
|
8
8
|
import { isTokenOf } from "./token-text.mjs";
|
|
9
|
-
import { hostCall,
|
|
9
|
+
import { hostCall, logRefusal, rejectedError } from "./host-function.mjs";
|
|
10
10
|
import * as Effect from "effect/Effect";
|
|
11
11
|
import * as Schema from "effect/Schema";
|
|
12
12
|
// src/auth/authorize.ts
|
|
@@ -35,7 +35,7 @@ const reports = [...reads, "queue.report"];
|
|
|
35
35
|
* `repos.list` filters to the token's coverage (Q122), and asks who its caller is. A kind no scope
|
|
36
36
|
* names, a new one too, is outside every credential. No scope reaches a repo's creation, update
|
|
37
37
|
* or deletion, tokens, forks, a queue's holds and restarts, or work's writes: those need the
|
|
38
|
-
* host's own sign-in.
|
|
38
|
+
* host's own sign-in, or an `admin` token, which reaches every kind and covers the whole host.
|
|
39
39
|
*/
|
|
40
40
|
const ceilings = {
|
|
41
41
|
read: new Set(reads),
|
|
@@ -79,7 +79,7 @@ const aboutOf = (caller, operation) => {
|
|
|
79
79
|
* its `reaches`, which answers for one repo. `undefined` for a caller with neither, such as a
|
|
80
80
|
* host's session, which Git sets no ceiling for. `ceilingOf` and `accessOf` both read it (Q251).
|
|
81
81
|
*/
|
|
82
|
-
const credentialOf = (
|
|
82
|
+
const credentialOf = (grants, caller, about) => {
|
|
83
83
|
const { token } = caller;
|
|
84
84
|
if (token !== void 0) return {
|
|
85
85
|
scope: token.scope,
|
|
@@ -89,7 +89,7 @@ const credentialOf = (hosts, grants, caller, about) => {
|
|
|
89
89
|
if (grant === void 0) return void 0;
|
|
90
90
|
return {
|
|
91
91
|
scope: grant.scope,
|
|
92
|
-
reaches: (name, internalId) => name === void 0 ? Effect.succeed(false) : hostCall(
|
|
92
|
+
reaches: (name, internalId) => name === void 0 ? Effect.succeed(false) : hostCall("grants", about, (signal) => grant.reaches(internalId === void 0 ? {
|
|
93
93
|
repo: name,
|
|
94
94
|
signal
|
|
95
95
|
} : {
|
|
@@ -106,12 +106,14 @@ const shortOf = (scope) => reject({
|
|
|
106
106
|
hint: `Sign in again asking for the \`${ghWriteScope}\` scope`
|
|
107
107
|
});
|
|
108
108
|
/** A credential's own ceiling: a Git token's scope and coverage, or an extension's grant. */
|
|
109
|
-
const ceilingOf = /* @__PURE__ */ Effect.fnUntraced(function* (
|
|
110
|
-
const credential = credentialOf(
|
|
109
|
+
const ceilingOf = /* @__PURE__ */ Effect.fnUntraced(function* (grants, { caller, operation, repo: checked }) {
|
|
110
|
+
const credential = credentialOf(grants, caller, aboutOf(caller, operation));
|
|
111
111
|
if (credential === void 0) return accept();
|
|
112
|
-
|
|
112
|
+
const { scope } = credential;
|
|
113
|
+
if (scope === "admin") return accept();
|
|
114
|
+
if (!ceilings[scope].has(operation.kind)) {
|
|
113
115
|
if (!(caller.token !== void 0 && ceilings.write.has(operation.kind))) return outside();
|
|
114
|
-
return (yield* credential.reaches(operationRepo(operation), checked?.internalId)) ? shortOf(
|
|
116
|
+
return (yield* credential.reaches(operationRepo(operation), checked?.internalId)) ? shortOf(scope) : outside();
|
|
115
117
|
}
|
|
116
118
|
if (operation.kind === "repo.list" && caller.token !== void 0) return accept();
|
|
117
119
|
if (operation.kind === "me") return accept();
|
|
@@ -120,18 +122,20 @@ const ceilingOf = /* @__PURE__ */ Effect.fnUntraced(function* (hosts, grants, {
|
|
|
120
122
|
/**
|
|
121
123
|
* The ceiling Git's calls apply to `caller` on `repo` (Q251): its token's scope when the token
|
|
122
124
|
* covers the repo, its grant's when the grant reaches it, and `undefined` when either doesn't. A
|
|
123
|
-
* caller with neither meets no ceiling of Git's, so it answers `'write'`,
|
|
124
|
-
* `authorize` alone decides. A repo token is checked against `internalId`, the repo the caller
|
|
125
|
+
* caller with neither, or on an `admin` token, meets no ceiling of Git's, so it answers `'write'`,
|
|
126
|
+
* and the host's `authorize` alone decides. A repo token is checked against `internalId`, the repo the caller
|
|
125
127
|
* holds the name to, or without it the repo now under the name.
|
|
126
128
|
*/
|
|
127
|
-
const accessOf = /* @__PURE__ */ Effect.fnUntraced(function* (
|
|
128
|
-
const credential = credentialOf(
|
|
129
|
+
const accessOf = /* @__PURE__ */ Effect.fnUntraced(function* (grants, store, caller, repo, pinned) {
|
|
130
|
+
const credential = credentialOf(grants, caller, {
|
|
129
131
|
repo,
|
|
130
132
|
actor: caller.actor
|
|
131
133
|
});
|
|
132
134
|
if (credential === void 0) return "write";
|
|
135
|
+
const { scope } = credential;
|
|
136
|
+
if (scope === "admin") return "write";
|
|
133
137
|
const internalId = pinned !== void 0 || caller.token === void 0 ? pinned : yield* internalIdOf(store, repo).pipe(Effect.catch((error) => error.code === "NOT_FOUND" ? Effect.succeed(void 0) : Effect.fail(error)));
|
|
134
|
-
return (yield* credential.reaches(repo, internalId)) ?
|
|
138
|
+
return (yield* credential.reaches(repo, internalId)) ? scope : void 0;
|
|
135
139
|
});
|
|
136
140
|
/**
|
|
137
141
|
* The `authorize` of host code's own calls, which name no caller (Q223): it skips every check but
|
|
@@ -186,13 +190,13 @@ const inputOf = ({ caller, operation, repo }) => {
|
|
|
186
190
|
* A server's `authorize`: the credential's ceiling first, then the host's `Policy`. A refusal reaches the caller as `refusalError` makes it: a host's own code exactly as
|
|
187
191
|
* returned. A refusal of anything but a read or a create, whatever its code, is told only to a
|
|
188
192
|
* caller that may read that repo, as `readersError` says, as HTTP's push and the core's do, so a
|
|
189
|
-
* write to a private repo answers a stranger as for a repo that isn't there. A refusal
|
|
190
|
-
* `
|
|
193
|
+
* write to a private repo answers a stranger as for a repo that isn't there. A refusal is logged
|
|
194
|
+
* at `Debug`.
|
|
191
195
|
*/
|
|
192
196
|
const authorizer = (options) => {
|
|
193
197
|
/** The ceiling's answer, then the host's when the ceiling lets it through. */
|
|
194
198
|
const answerOf = Effect.fnUntraced(function* (check) {
|
|
195
|
-
const ceiling = yield* ceilingOf(options.
|
|
199
|
+
const ceiling = yield* ceilingOf(options.grants, check);
|
|
196
200
|
if (ceiling.kind === "reject") return ceiling;
|
|
197
201
|
return yield* options.policy.authorize(check);
|
|
198
202
|
});
|
|
@@ -220,7 +224,7 @@ const authorizer = (options) => {
|
|
|
220
224
|
actor,
|
|
221
225
|
missing: check.repo === void 0
|
|
222
226
|
});
|
|
223
|
-
|
|
227
|
+
yield* logRefusal("authorize", aboutOf(caller, operation), error);
|
|
224
228
|
return yield* Effect.fail(error);
|
|
225
229
|
});
|
|
226
230
|
};
|
|
@@ -232,7 +236,7 @@ const isAudience = /* @__PURE__ */ Schema.is(RefAudience);
|
|
|
232
236
|
/**
|
|
233
237
|
* `answer` as a ref audience over `patterns`: none for a refusal or an `accept()` with no value.
|
|
234
238
|
* An audience naming a pattern it wasn't asked about, or any other value, is the host's mistake,
|
|
235
|
-
* thrown so the call fails `UNAVAILABLE` and
|
|
239
|
+
* thrown so the call fails `UNAVAILABLE` and the host's log has it: no caller sees a ref on it.
|
|
236
240
|
*/
|
|
237
241
|
const audienceIn = (answer, patterns) => {
|
|
238
242
|
if (answer.kind === "reject" || answer.value === void 0) return noAudience;
|
|
@@ -251,23 +255,26 @@ const audienceIn = (answer, patterns) => {
|
|
|
251
255
|
* `Policy`. `Policy.signedIn` accepts with no value, so a host that passes `access` and doesn't
|
|
252
256
|
* answer it shows no caller a private ref. Unlike `authorize`, a refusal isn't an error: it reads
|
|
253
257
|
* no private pattern, as an answer with neither list does. An answer `audienceIn` can't read fails
|
|
254
|
-
* the call `UNAVAILABLE`, and
|
|
258
|
+
* the call `UNAVAILABLE`, and the host's log has it.
|
|
255
259
|
*/
|
|
256
|
-
const audienceOf = (options) => Effect.fnUntraced(function* ({ caller, repo, patterns }) {
|
|
260
|
+
const audienceOf = (options) => Effect.fnUntraced(function* ({ caller, repo, creating, patterns }) {
|
|
257
261
|
const operation = {
|
|
258
262
|
kind: "refs.private",
|
|
259
|
-
repo: repo.name,
|
|
263
|
+
repo: repo === void 0 ? creating : repo.name,
|
|
260
264
|
patterns
|
|
261
265
|
};
|
|
262
|
-
const check = {
|
|
266
|
+
const check = repo === void 0 ? {
|
|
267
|
+
caller,
|
|
268
|
+
operation
|
|
269
|
+
} : {
|
|
263
270
|
caller,
|
|
264
271
|
operation,
|
|
265
272
|
repo
|
|
266
273
|
};
|
|
267
274
|
const long = longActorId(caller.actor, caller.subject);
|
|
268
275
|
if (long !== void 0) return yield* Effect.fail(long);
|
|
269
|
-
if ((yield* ceilingOf(options.
|
|
276
|
+
if ((yield* ceilingOf(options.grants, check)).kind === "reject") return noAudience;
|
|
270
277
|
const answer = yield* options.policy.authorize(check);
|
|
271
|
-
return yield* hostCall(
|
|
278
|
+
return yield* hostCall("authorize", aboutOf(caller, operation), () => audienceIn(answer, patterns));
|
|
272
279
|
});
|
|
273
280
|
export { aboutOf, accessOf, audienceOf, authorizer, bypassKinds, hostAuthorize, inputOf, longActorId, operationRepo, readKinds };
|
package/dist/auth/bridge.mjs
CHANGED
|
@@ -7,23 +7,23 @@ import * as Option from "effect/Option";
|
|
|
7
7
|
// src/auth/bridge.ts
|
|
8
8
|
/**
|
|
9
9
|
* The `Policy` of a server made with `authorize`, or `Policy.signedIn` with none. Each answer runs
|
|
10
|
-
* as a host function: a throw is `UNAVAILABLE`, and
|
|
10
|
+
* as a host function: a throw is `UNAVAILABLE`, and the host's log names it as `'authorize'`'s.
|
|
11
11
|
*/
|
|
12
|
-
const policyOf = (hook
|
|
12
|
+
const policyOf = (hook) => hook === void 0 ? signedIn : { authorize: (input) => hostCall("authorize", aboutOf(input.caller, input.operation), (signal) => hook({
|
|
13
13
|
...inputOf(input),
|
|
14
14
|
signal
|
|
15
15
|
})) };
|
|
16
16
|
/** A host's own `Policy` and `Auth` make no call through Git's doors. */
|
|
17
17
|
const hostDecider = /* @__PURE__ */ uncounted("the host's own Policy and Auth");
|
|
18
18
|
/**
|
|
19
|
-
* The host's `Policy` as `
|
|
20
|
-
* so a failure or a defect is `UNAVAILABLE` and reaches
|
|
19
|
+
* The host's `Policy` as `Git.layer` asks it: a host function, like the `authorize` option,
|
|
20
|
+
* so a failure or a defect is `UNAVAILABLE` and reaches the host's log, never the caller as it is.
|
|
21
21
|
*/
|
|
22
|
-
const hostPolicy = (policy
|
|
23
|
-
/** The host's `Auth` as `
|
|
24
|
-
const hostAuth = (auth
|
|
22
|
+
const hostPolicy = (policy) => ({ authorize: (input) => hostCall("authorize", aboutOf(input.caller, input.operation), (signal) => runIn(policy.authorize(input), hostDecider, signal)) });
|
|
23
|
+
/** The host's `Auth` as `Git.layer` asks it, a host function like the `auth` option. */
|
|
24
|
+
const hostAuth = (auth) => auth === void 0 ? void 0 : { identify: (input) => hostCall("auth", {}, (signal) => runIn(auth.identify(input), hostDecider, signal)) };
|
|
25
25
|
/** The `Auth` of a server made with `auth`, which runs as a host function, as `'auth'`'s. */
|
|
26
|
-
const authOf = (hook
|
|
26
|
+
const authOf = (hook) => hook === void 0 ? void 0 : { identify: (input) => Effect.map(hostCall("auth", {}, (signal) => hook({
|
|
27
27
|
...input,
|
|
28
28
|
signal
|
|
29
29
|
})), Option.fromNullishOr) };
|
package/dist/auth/fences.d.mts
CHANGED
|
@@ -3,7 +3,6 @@ import { Caller } from "../contracts/actors.mjs";
|
|
|
3
3
|
import { InternalRepoId, RepoName } from "../contracts/ids.mjs";
|
|
4
4
|
import { GitError } from "../contracts/result.mjs";
|
|
5
5
|
import "./grants.mjs";
|
|
6
|
-
import "./host-function.mjs";
|
|
7
6
|
import * as Effect from "effect/Effect";
|
|
8
7
|
import { Read, Row } from "@ref0/infra";
|
|
9
8
|
/** The repo a write commits to: its scope's ID and its name now. */
|
package/dist/auth/fences.mjs
CHANGED
|
@@ -54,7 +54,7 @@ const grantFences = (options) => {
|
|
|
54
54
|
repo: repo.name,
|
|
55
55
|
actor: caller.actor
|
|
56
56
|
};
|
|
57
|
-
if (!(yield* hostCall(
|
|
57
|
+
if (!(yield* hostCall("grants", about, (signal) => grant.reaches({
|
|
58
58
|
repo: repo.name,
|
|
59
59
|
signal
|
|
60
60
|
})))) return yield* Effect.fail(unreached());
|
package/dist/auth/grants.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import "../index.mjs";
|
|
2
2
|
import { Caller } from "../contracts/actors.mjs";
|
|
3
3
|
import { Grant } from "../contracts/grants.mjs";
|
|
4
|
-
import "./host-function.mjs";
|
|
5
4
|
import "effect/Effect";
|
|
6
5
|
/**
|
|
7
6
|
* Each caller's grant, kept beside the caller by the server whose `identify` or `grantAgain` made
|
package/dist/auth/grants.mjs
CHANGED
|
@@ -43,11 +43,11 @@ const grantCaller = (grants, grant, resolver) => {
|
|
|
43
43
|
* or one with another `id`. The one way Git finds a resolver by name. The resolver's signal is
|
|
44
44
|
* Git's own, joined with `input.signal`.
|
|
45
45
|
*/
|
|
46
|
-
const grantAgain = /* @__PURE__ */ Effect.fnUntraced(function* (grants,
|
|
46
|
+
const grantAgain = /* @__PURE__ */ Effect.fnUntraced(function* (grants, resolvers, resolver, input) {
|
|
47
47
|
const found = resolvers.find((one) => one.name === resolver);
|
|
48
48
|
if (found === void 0) return void 0;
|
|
49
49
|
const { signal: asked, ...again } = input;
|
|
50
|
-
const grant = yield* hostCall(
|
|
50
|
+
const grant = yield* hostCall("grants", { actor: input.actor }, (signal) => found.again({
|
|
51
51
|
...again,
|
|
52
52
|
signal: asked === void 0 ? signal : AbortSignal.any([asked, signal])
|
|
53
53
|
}));
|
|
@@ -2,10 +2,4 @@ import "../contracts/actors.mjs";
|
|
|
2
2
|
import "../contracts/ids.mjs";
|
|
3
3
|
import "../contracts/operations.mjs";
|
|
4
4
|
import "../contracts/result.mjs";
|
|
5
|
-
import
|
|
6
|
-
import "effect/Effect";
|
|
7
|
-
/** Where a server's host functions report: `GitServerOptions`' `onError` and `onRefused`. */
|
|
8
|
-
export interface HostReports {
|
|
9
|
-
readonly onError?: (cause: unknown, failed: HostFunctionFailure) => void;
|
|
10
|
-
readonly onRefused?: (refusal: Refusal) => void;
|
|
11
|
-
}
|
|
5
|
+
import "effect/Effect";
|
|
@@ -6,83 +6,83 @@ import * as Effect from "effect/Effect";
|
|
|
6
6
|
import * as Schema from "effect/Schema";
|
|
7
7
|
import * as Cause from "effect/Cause";
|
|
8
8
|
// src/auth/host-function.ts
|
|
9
|
-
/** A failure's ID, which the caller sees in the error's context and
|
|
9
|
+
/** A failure's ID, which the caller sees in the error's context and the host's log names. */
|
|
10
10
|
const failureId = () => `e_${randomText(8)}`;
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
const annotationsOf = (name, about) => {
|
|
12
|
+
const annotations = { function: name };
|
|
13
|
+
if (about.repo !== void 0) annotations.repo = about.repo;
|
|
14
|
+
if (about.operation !== void 0) annotations.operation = about.operation.kind;
|
|
15
|
+
return annotations;
|
|
16
16
|
};
|
|
17
|
-
/**
|
|
18
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Logs a host function's failure at `Error`, with its cause, annotated with the failure's ID the
|
|
19
|
+
* caller sees, and fails with the caller's error for it.
|
|
20
|
+
*/
|
|
21
|
+
const failed = (name, about, cause, timedOut) => Effect.suspend(() => {
|
|
19
22
|
const id = failureId();
|
|
20
|
-
const
|
|
21
|
-
id,
|
|
22
|
-
function: name,
|
|
23
|
-
timedOut
|
|
24
|
-
};
|
|
25
|
-
if (about.repo !== void 0) failure.repo = about.repo;
|
|
26
|
-
if (about.operation !== void 0) failure.operation = about.operation;
|
|
27
|
-
report(() => reports.onError?.(cause, failure));
|
|
28
|
-
return timedOut ? gitError("DEADLINE_EXCEEDED", "The server could not check this in time", {
|
|
23
|
+
const error = timedOut ? gitError("DEADLINE_EXCEEDED", "The server could not check this in time", {
|
|
29
24
|
hint: `Try again (${id})`,
|
|
30
25
|
context: { id }
|
|
31
26
|
}) : gitError("UNAVAILABLE", "The server could not check this", {
|
|
32
27
|
hint: `Try again (${id})`,
|
|
33
28
|
context: { id }
|
|
34
29
|
});
|
|
30
|
+
const message = timedOut ? `${name} ran out of time` : `${name} failed`;
|
|
31
|
+
return Effect.logError(message, Cause.die(cause)).pipe(Effect.annotateLogs({
|
|
32
|
+
...annotationsOf(name, about),
|
|
33
|
+
failure: id
|
|
34
|
+
}), Effect.andThen(Effect.fail(error)));
|
|
35
|
+
});
|
|
36
|
+
/** A host function's throw, carried out of `tryClosing` to be logged. */
|
|
37
|
+
var Threw = class {
|
|
38
|
+
cause;
|
|
39
|
+
constructor(cause) {
|
|
40
|
+
this.cause = cause;
|
|
41
|
+
}
|
|
35
42
|
};
|
|
36
43
|
/**
|
|
37
44
|
* Runs a host function: a throw is `UNAVAILABLE`, and a run past `timeout` `DEADLINE_EXCEEDED`,
|
|
38
|
-
* each with a fixed sentence and the failure's ID, which
|
|
45
|
+
* each with a fixed sentence and the failure's ID, which the host's log names beside the cause. A throw
|
|
39
46
|
* of a call bound Git or the store refused past, such as a hook's `changes` past its push's
|
|
40
47
|
* count, is no failure of the host's: it's the defect `CallsSpent` again, so the request stops
|
|
41
48
|
* whole, as it would have had Git made the call itself. Its `signal` aborts when the call
|
|
42
49
|
* is interrupted or runs out of time.
|
|
43
50
|
*/
|
|
44
|
-
const hostCall = (
|
|
45
|
-
const call = tryClosing(async (signal) => run(signal), (cause) =>
|
|
51
|
+
const hostCall = (name, about, run, options = {}) => {
|
|
52
|
+
const call = Effect.catch(tryClosing(async (signal) => run(signal), (cause) => new Threw(cause)), (threw) => failed(name, about, threw.cause, false));
|
|
46
53
|
const { timeout } = options;
|
|
47
54
|
if (timeout === void 0) return call;
|
|
48
55
|
return Effect.timeoutOrElse(call, {
|
|
49
56
|
duration: timeout,
|
|
50
|
-
orElse: () =>
|
|
57
|
+
orElse: () => failed(name, about, /* @__PURE__ */ new Error(`${name} ran past ${timeout} ms`), true)
|
|
51
58
|
});
|
|
52
59
|
};
|
|
53
60
|
/**
|
|
54
61
|
* Runs a host function that's an Effect, such as a rule's check, in the caller's fiber: its failure
|
|
55
|
-
* or its defect is `UNAVAILABLE`, as `hostCall` makes a throw, which
|
|
62
|
+
* or its defect is `UNAVAILABLE`, as `hostCall` makes a throw, which the host's log names with the
|
|
56
63
|
* cause. A call bound spent and a closed server stay the defects they are, so the request stops
|
|
57
64
|
* whole, and an interrupt stays one. Past `timeout`, it interrupts the Effect and reports
|
|
58
65
|
* `timedOut: true` with `DEADLINE_EXCEEDED`.
|
|
59
66
|
*/
|
|
60
|
-
const hostEffect = (
|
|
67
|
+
const hostEffect = (name, about, effect, options = {}) => {
|
|
61
68
|
const call = Effect.catchCause(effect, (cause) => {
|
|
62
69
|
if (Cause.hasInterruptsOnly(cause)) return Effect.interrupt;
|
|
63
70
|
const thrown = Cause.squash(cause);
|
|
64
71
|
if (spentAt(thrown) !== void 0 || isServerClosed(thrown)) return Effect.die(thrown);
|
|
65
|
-
return
|
|
72
|
+
return failed(name, about, thrown, false);
|
|
66
73
|
});
|
|
67
74
|
const { timeout, label = name } = options;
|
|
68
75
|
if (timeout === void 0) return call;
|
|
69
76
|
return Effect.timeoutOrElse(call, {
|
|
70
77
|
duration: timeout,
|
|
71
|
-
orElse: () =>
|
|
78
|
+
orElse: () => failed(name, about, /* @__PURE__ */ new Error(`${label} ran past ${timeout} ms`), true)
|
|
72
79
|
});
|
|
73
80
|
};
|
|
74
|
-
/**
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
function: name
|
|
80
|
-
};
|
|
81
|
-
if (about.repo !== void 0) refusal.repo = about.repo;
|
|
82
|
-
if (about.operation !== void 0) refusal.operation = about.operation;
|
|
83
|
-
if (about.actor !== void 0) refusal.actor = about.actor;
|
|
84
|
-
report(() => reports.onRefused?.(refusal));
|
|
85
|
-
};
|
|
81
|
+
/** Logs a host function's refusal at `Debug`, as the caller is answered with it. */
|
|
82
|
+
const logRefusal = (name, about, error) => Effect.logDebug(`${name} refused: ${error.message}`).pipe(Effect.annotateLogs({
|
|
83
|
+
...annotationsOf(name, about),
|
|
84
|
+
code: error.code
|
|
85
|
+
}));
|
|
86
86
|
const isBody = /* @__PURE__ */ Schema.is(GitErrorBody);
|
|
87
87
|
/**
|
|
88
88
|
* A host function's refusal as it reads: `NOT_ALLOWED` when it names no code. Its context's
|
|
@@ -102,4 +102,4 @@ const rejectedError = (rejected) => {
|
|
|
102
102
|
})) input.context = context;
|
|
103
103
|
return gitError(code, message, input);
|
|
104
104
|
};
|
|
105
|
-
export { hostCall, hostEffect,
|
|
105
|
+
export { hostCall, hostEffect, logRefusal, rejectedError };
|
package/dist/auth/identify.d.mts
CHANGED
|
@@ -5,7 +5,6 @@ import { GitError } from "../contracts/result.mjs";
|
|
|
5
5
|
import "../contracts/tokens.mjs";
|
|
6
6
|
import "./auth.mjs";
|
|
7
7
|
import "./grants.mjs";
|
|
8
|
-
import "./host-function.mjs";
|
|
9
8
|
import * as Effect from "effect/Effect";
|
|
10
9
|
/** Who sent a request: its `Caller`, or `UNAUTHENTICATED` for a credential no one knows. */
|
|
11
10
|
export type Identify = (request: Request) => Effect.Effect<Caller, GitError>;
|
package/dist/auth/identify.mjs
CHANGED
|
@@ -48,7 +48,7 @@ const tokenCaller = ({ record }) => {
|
|
|
48
48
|
const identifier = (options) => {
|
|
49
49
|
const fromGrants = Effect.fnUntraced(function* (request, credentials) {
|
|
50
50
|
for (const resolver of options.grants()) {
|
|
51
|
-
const grant = yield* hostCall(
|
|
51
|
+
const grant = yield* hostCall("grants", {}, (signal) => resolver.resolve({
|
|
52
52
|
credentials,
|
|
53
53
|
request,
|
|
54
54
|
signal
|
package/dist/auth/policy.d.mts
CHANGED
|
@@ -18,9 +18,11 @@ export type Input = AuthorizeRequest;
|
|
|
18
18
|
export type Answer = DecisionAnswer | Accepted<RefAudience>;
|
|
19
19
|
export interface PolicyService {
|
|
20
20
|
/**
|
|
21
|
-
* Asked after core's own checks and a credential's ceiling: it narrows, and never opens.
|
|
22
|
-
* `
|
|
23
|
-
*
|
|
21
|
+
* Asked after core's own checks and a credential's ceiling: it narrows, and never opens. An
|
|
22
|
+
* `admin` token's ceiling is every kind, so the policy decides alone who may hold one, and a
|
|
23
|
+
* policy that doesn't accept it, as `signedIn` doesn't, refuses it. A `reject` is the caller's
|
|
24
|
+
* answer. A failure or a defect is `UNAVAILABLE`, logged at `Error` as `'authorize'`'s, so what
|
|
25
|
+
* the host's error says never reaches the caller. The default
|
|
24
26
|
* refusal, no code, `NOT_ALLOWED` or `NOT_FOUND`, answers a stranger as for a repo that isn't
|
|
25
27
|
* there, and a code of its own reaches only a caller who may read the repo.
|
|
26
28
|
*/
|
|
@@ -51,7 +53,8 @@ export declare const reject: (refusal: RejectInput) => Effect.Effect<Answer>;
|
|
|
51
53
|
* A `protect.bypass` or `lock.bypass` isn't, for anyone: a rule asks one on every change it
|
|
52
54
|
* refuses, so accepting it would lift every `Rules.protect` and `Rules.lock` for whoever may push.
|
|
53
55
|
* It allows every other operation kind, one Git adds later too, to any signed-in caller, so a host
|
|
54
|
-
* that wants a new kind closed until it decides writes its own policy.
|
|
56
|
+
* that wants a new kind closed until it decides writes its own policy. It names no one an admin:
|
|
57
|
+
* it refuses a caller on an `admin` token, and the minting of one.
|
|
55
58
|
*/
|
|
56
59
|
export declare const signedIn: PolicyService;
|
|
57
60
|
export { policy_d_exports };
|
package/dist/auth/policy.mjs
CHANGED
|
@@ -28,14 +28,11 @@ const accept = (value) => Effect.succeed(value === void 0 ? accept$1() : accept$
|
|
|
28
28
|
/** A refusal: `code` is `NOT_ALLOWED` when it's left out. Was `reject()`. */
|
|
29
29
|
const reject = (refusal) => Effect.succeed(reject$1(refusal));
|
|
30
30
|
/**
|
|
31
|
-
* Whether `
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* token or a grant, and no token scope or grant reaches any token operation, so only a host's own
|
|
35
|
-
* sign-in mints. If a token or a grant may ever mint, this must compare against
|
|
36
|
-
* `caller.subject ?? actor` instead.
|
|
31
|
+
* Whether `self`, the caller's `subject ?? actor`, mints `token` for themselves: they're its
|
|
32
|
+
* subject, with no one else acting. A caller on a token or a grant is its `subject`, and an
|
|
33
|
+
* `admin` token reaches token operations, so it's never the actor alone.
|
|
37
34
|
*/
|
|
38
|
-
const mintsForSelf = (
|
|
35
|
+
const mintsForSelf = (self, token) => token.subject.id === self.id && token.actor === void 0;
|
|
39
36
|
/**
|
|
40
37
|
* Git's own rules, which a host names when it has none of its own: a signed-in caller may do
|
|
41
38
|
* anything its credential's ceiling lets it but mint a token for anyone else, and an anonymous one
|
|
@@ -46,11 +43,17 @@ const mintsForSelf = (actor, token) => token.subject.id === actor.id && token.ac
|
|
|
46
43
|
* A `protect.bypass` or `lock.bypass` isn't, for anyone: a rule asks one on every change it
|
|
47
44
|
* refuses, so accepting it would lift every `Rules.protect` and `Rules.lock` for whoever may push.
|
|
48
45
|
* It allows every other operation kind, one Git adds later too, to any signed-in caller, so a host
|
|
49
|
-
* that wants a new kind closed until it decides writes its own policy.
|
|
46
|
+
* that wants a new kind closed until it decides writes its own policy. It names no one an admin:
|
|
47
|
+
* it refuses a caller on an `admin` token, and the minting of one.
|
|
50
48
|
*/
|
|
51
|
-
const signedIn = make(({ caller
|
|
49
|
+
const signedIn = make(({ caller, operation, repo }) => {
|
|
52
50
|
if (bypassKinds.has(operation.kind)) return reject({ message: "No rule is lifted for anyone" });
|
|
53
|
-
if (
|
|
51
|
+
if (caller.token?.scope === "admin" || operation.kind === "token.create" && operation.scope === "admin") return reject({ message: "No one holds an admin token here" });
|
|
52
|
+
const { actor } = caller;
|
|
53
|
+
if (actor.anonymous !== true) {
|
|
54
|
+
const self = caller.subject ?? actor;
|
|
55
|
+
return operation.kind === "token.create" && !mintsForSelf(self, operation) ? reject({ message: "Only tokens for yourself" }) : accept();
|
|
56
|
+
}
|
|
54
57
|
return operation.kind === "repo.list" || repo?.public === true && readKinds.has(operation.kind) ? accept() : reject({ message: "Sign in first" });
|
|
55
58
|
});
|
|
56
59
|
export { Policy, accept, layer, make, policy_exports, reject, signedIn };
|
package/dist/auth/token-rows.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TokenScope } from "../contracts/tokens.mjs";
|
|
1
2
|
import { decodeRow, storeCall } from "../store/errors.mjs";
|
|
2
3
|
import { StoredRepo } from "../store/records.mjs";
|
|
3
4
|
import { collections, selfKey } from "../store/scopes.mjs";
|
|
@@ -12,11 +13,7 @@ const Party = /* @__PURE__ */ Schema.Struct({ id: Schema.String });
|
|
|
12
13
|
*/
|
|
13
14
|
const TokenRow = /* @__PURE__ */ Schema.Struct({
|
|
14
15
|
hash: Schema.String,
|
|
15
|
-
scope:
|
|
16
|
-
"read",
|
|
17
|
-
"report",
|
|
18
|
-
"write"
|
|
19
|
-
]),
|
|
16
|
+
scope: TokenScope,
|
|
20
17
|
expiresAt: Schema.Int,
|
|
21
18
|
subject: Party,
|
|
22
19
|
actor: Schema.optionalKey(Party),
|
|
@@ -2,7 +2,6 @@ import { Git } from "../contracts/git.mjs";
|
|
|
2
2
|
import { Store } from "../contracts/promises.mjs";
|
|
3
3
|
import { GitError } from "../contracts/result.mjs";
|
|
4
4
|
import { Tokens } from "../contracts/tokens.mjs";
|
|
5
|
-
import { HostReports } from "./host-function.mjs";
|
|
6
5
|
import { HeldTokenCalls } from "./tokens.mjs";
|
|
7
6
|
import * as Effect from "effect/Effect";
|
|
8
7
|
import { Moment } from "@ref0/infra";
|
|
@@ -14,7 +13,6 @@ export interface HeldTokens {
|
|
|
14
13
|
readonly tokens: HeldTokenCalls;
|
|
15
14
|
readonly store: Store;
|
|
16
15
|
readonly now: Effect.Effect<Moment>;
|
|
17
|
-
readonly reports: HostReports;
|
|
18
16
|
readonly through: <A, E>(effect: Effect.Effect<A, E>) => Effect.Effect<A, E>;
|
|
19
17
|
readonly refuse: (error: GitError) => Response;
|
|
20
18
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CreatedToken, PrefixTarget, TokenCalls, TokenCoverage, TokenCreate, TokenCreateInput, TokenFields, TokenId, TokenInfo, TokenKey, TokenKeyInput, TokenList, TokenListInput, TokenRecord, TokenScope, TokenState, TokenTarget, Tokens, TokensFeature, TrustedWriteInput, VerifiedToken, create, get, list, revoke, revokeKey, tokenScopes, tokenStates } from "../contracts/tokens.mjs";
|
|
1
|
+
import { CreatedToken, GrantScope, PrefixTarget, TokenCalls, TokenCoverage, TokenCreate, TokenCreateInput, TokenFields, TokenId, TokenInfo, TokenKey, TokenKeyInput, TokenList, TokenListInput, TokenRecord, TokenScope, TokenState, TokenTarget, Tokens, TokensFeature, TrustedWriteInput, VerifiedToken, create, get, grantScopes, list, revoke, revokeKey, tokenScopes, tokenStates } from "../contracts/tokens.mjs";
|
|
2
2
|
import { layer } from "./tokens-layer.mjs";
|
|
3
3
|
declare namespace tokens_public_d_exports {
|
|
4
|
-
export { CreatedToken, PrefixTarget, TokenCalls, TokenCoverage, TokenCreate, TokenCreateInput, TokenFields, TokenId, TokenInfo, TokenKey, TokenKeyInput, TokenList, TokenListInput, TokenRecord, TokenScope, TokenState, TokenTarget, Tokens, TokensFeature, TrustedWriteInput, VerifiedToken, create, get, layer, list, revoke, revokeKey, tokenScopes, tokenStates };
|
|
4
|
+
export { CreatedToken, GrantScope, PrefixTarget, TokenCalls, TokenCoverage, TokenCreate, TokenCreateInput, TokenFields, TokenId, TokenInfo, TokenKey, TokenKeyInput, TokenList, TokenListInput, TokenRecord, TokenScope, TokenState, TokenTarget, Tokens, TokensFeature, TrustedWriteInput, VerifiedToken, create, get, grantScopes, layer, list, revoke, revokeKey, tokenScopes, tokenStates };
|
|
5
5
|
}
|
|
6
|
-
export { CreatedToken, PrefixTarget, TokenCalls, TokenCoverage, TokenCreate, TokenCreateInput, TokenFields, TokenId, TokenInfo, TokenKey, TokenKeyInput, TokenList, TokenListInput, TokenRecord, TokenScope, TokenState, TokenTarget, Tokens, TokensFeature, TrustedWriteInput, VerifiedToken, create, get, layer, list, revoke, revokeKey, tokenScopes, tokenStates, tokens_public_d_exports };
|
|
6
|
+
export { CreatedToken, GrantScope, PrefixTarget, TokenCalls, TokenCoverage, TokenCreate, TokenCreateInput, TokenFields, TokenId, TokenInfo, TokenKey, TokenKeyInput, TokenList, TokenListInput, TokenRecord, TokenScope, TokenState, TokenTarget, Tokens, TokensFeature, TrustedWriteInput, VerifiedToken, create, get, grantScopes, layer, list, revoke, revokeKey, tokenScopes, tokenStates, tokens_public_d_exports };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
|
|
2
|
-
import { CreatedToken, PrefixTarget, TokenCoverage, TokenCreate, TokenFields, TokenId, TokenInfo, TokenKey, TokenList, TokenRecord, TokenScope, TokenState, TokenTarget, Tokens, create, get, list, revoke, revokeKey, tokenScopes, tokenStates } from "../contracts/tokens.mjs";
|
|
2
|
+
import { CreatedToken, GrantScope, PrefixTarget, TokenCoverage, TokenCreate, TokenFields, TokenId, TokenInfo, TokenKey, TokenList, TokenRecord, TokenScope, TokenState, TokenTarget, Tokens, create, get, grantScopes, list, revoke, revokeKey, tokenScopes, tokenStates } from "../contracts/tokens.mjs";
|
|
3
3
|
import { layer } from "./tokens-layer.mjs";
|
|
4
4
|
// src/auth/tokens-public.ts
|
|
5
5
|
var tokens_public_exports = /* @__PURE__ */ __exportAll({
|
|
6
6
|
CreatedToken: () => CreatedToken,
|
|
7
|
+
GrantScope: () => GrantScope,
|
|
7
8
|
PrefixTarget: () => PrefixTarget,
|
|
8
9
|
TokenCoverage: () => TokenCoverage,
|
|
9
10
|
TokenCreate: () => TokenCreate,
|
|
@@ -19,6 +20,7 @@ var tokens_public_exports = /* @__PURE__ */ __exportAll({
|
|
|
19
20
|
Tokens: () => Tokens,
|
|
20
21
|
create: () => create,
|
|
21
22
|
get: () => get,
|
|
23
|
+
grantScopes: () => grantScopes,
|
|
22
24
|
layer: () => layer,
|
|
23
25
|
list: () => list,
|
|
24
26
|
revoke: () => revoke,
|
|
@@ -26,4 +28,4 @@ var tokens_public_exports = /* @__PURE__ */ __exportAll({
|
|
|
26
28
|
tokenScopes: () => tokenScopes,
|
|
27
29
|
tokenStates: () => tokenStates
|
|
28
30
|
});
|
|
29
|
-
export { CreatedToken, PrefixTarget, TokenCoverage, TokenCreate, TokenFields, TokenId, TokenInfo, TokenKey, TokenList, TokenRecord, TokenScope, TokenState, TokenTarget, Tokens, create, get, layer, list, revoke, revokeKey, tokenScopes, tokenStates, tokens_public_exports };
|
|
31
|
+
export { CreatedToken, GrantScope, PrefixTarget, TokenCoverage, TokenCreate, TokenFields, TokenId, TokenInfo, TokenKey, TokenList, TokenRecord, TokenScope, TokenState, TokenTarget, Tokens, create, get, grantScopes, layer, list, revoke, revokeKey, tokenScopes, tokenStates, tokens_public_exports };
|
package/dist/auth/tokens.d.mts
CHANGED
|
@@ -9,7 +9,12 @@ import { TokenCalls, TokensFeature } from "../contracts/tokens.mjs";
|
|
|
9
9
|
import "../store/outbox.mjs";
|
|
10
10
|
import "effect/Effect";
|
|
11
11
|
import { JobDefinition, Moment, Read, Row } from "@ref0/infra";
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Turns on Git's own tokens. A token's scope is its ceiling, which the host's `Policy` narrows and
|
|
14
|
+
* never opens: an `admin` token, over the whole host alone, reaches every operation, but only as
|
|
15
|
+
* far as the policy accepts it. `Policy.signedIn` refuses it, so a host that mints one writes its
|
|
16
|
+
* own policy, naming who may hold it.
|
|
17
|
+
*/
|
|
13
18
|
export declare const tokens: () => TokensFeature;
|
|
14
19
|
/** Git's token calls, where a create or a list may name the repo `authorize` checked, as `held`. */
|
|
15
20
|
export interface HeldTokenCalls extends EffectCalls<TokenCalls> {
|
package/dist/auth/tokens.mjs
CHANGED
|
@@ -14,7 +14,12 @@ import * as Schema from "effect/Schema";
|
|
|
14
14
|
import { CurrentJob, Job } from "@ref0/infra";
|
|
15
15
|
import * as Random from "effect/Random";
|
|
16
16
|
// src/auth/tokens.ts
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Turns on Git's own tokens. A token's scope is its ceiling, which the host's `Policy` narrows and
|
|
19
|
+
* never opens: an `admin` token, over the whole host alone, reaches every operation, but only as
|
|
20
|
+
* far as the policy accepts it. `Policy.signedIn` refuses it, so a host that mints one writes its
|
|
21
|
+
* own policy, naming who may hold it.
|
|
22
|
+
*/
|
|
18
23
|
const tokens = () => ({ kind: "tokens" });
|
|
19
24
|
const day = 864e5;
|
|
20
25
|
/** The longest a token may live. */
|
|
@@ -145,6 +150,7 @@ const tokenCalls = (options) => {
|
|
|
145
150
|
const long = longActorId(input.subject, input.actor);
|
|
146
151
|
if (long !== void 0) return yield* Effect.fail(long);
|
|
147
152
|
yield* checkWriteKey(input.key);
|
|
153
|
+
if (input.scope === "admin" && !(isPrefixTarget(target) && target.prefix === "")) return yield* fail("INVALID_ARGUMENT", "An admin token covers the whole host: use prefix ''");
|
|
148
154
|
const now = yield* options.now;
|
|
149
155
|
const expiresAt = yield* tokenExpiry(now, input.expiresAt);
|
|
150
156
|
const pause = missedPauses();
|
package/dist/client/client.d.mts
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
import { GitClient, GitClientOptions, PagedInput } from "../contracts/client.mjs";
|
|
2
|
-
import { Result } from "../contracts/result.mjs";
|
|
3
1
|
import { EffectCalls } from "../contracts/services.mjs";
|
|
2
|
+
import "../effect.mjs";
|
|
3
|
+
import { GitClientCalls, GitClientOptions, GitClientPromises, PagedInput } from "../contracts/client.mjs";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
4
5
|
import { Listing } from "@ref0/infra";
|
|
6
|
+
import * as Context from "effect/Context";
|
|
7
|
+
import * as Stream from "effect/Stream";
|
|
8
|
+
declare namespace client_d_exports {
|
|
9
|
+
export { GitClient, GitClientCalls, make, paginate };
|
|
10
|
+
}
|
|
11
|
+
declare const GitClient_base: Context.ServiceClass<GitClient, "@ref0/git/GitClient", EffectCalls<GitClientPromises, never>>;
|
|
5
12
|
/**
|
|
6
|
-
* A client of one remote
|
|
7
|
-
*
|
|
8
|
-
* this, as a service. Each is an edge a host calls, as the server's Effect face is: a spent bound,
|
|
9
|
-
* a `CallBudget`'s or the platform's cap, is answered as its refusal, never a defect.
|
|
13
|
+
* A client of one remote as a service, for a program that's handed one: with `GitClient` from
|
|
14
|
+
* `@ref0/git`, `Layer.succeed(GitClient.GitClient, GitClient.make(options))` provides it.
|
|
10
15
|
*/
|
|
11
|
-
export declare
|
|
16
|
+
export declare class GitClient extends /* @__PURE__ */ GitClient_base {}
|
|
12
17
|
/**
|
|
13
|
-
* A client of `options.url
|
|
14
|
-
* calls on its own storage,
|
|
15
|
-
*
|
|
18
|
+
* A client of `options.url`, as Effects: `remoteRefs`, `fetch` and `push` on the remote over Git's
|
|
19
|
+
* smart HTTP, and the server's calls on its own storage, which a fetch fills and a push reads. Each
|
|
20
|
+
* is an edge a host calls, as the server's Effect face is: a spent bound, a `CallBudget`'s or the
|
|
21
|
+
* platform's cap, fails as its refusal, never a defect. Interrupting a call stops it.
|
|
16
22
|
*/
|
|
17
|
-
export declare const
|
|
23
|
+
export declare const make: (options: GitClientOptions) => GitClientCalls;
|
|
18
24
|
/**
|
|
19
|
-
* Each item `list` answers, a page at a time, from the input's `page` on: the next page asked
|
|
20
|
-
*
|
|
21
|
-
*
|
|
25
|
+
* Each item `list` answers, a page at a time, from the input's `page` on: the next page asked for
|
|
26
|
+
* only once the last one's items are taken. A refused page fails the stream with its own error,
|
|
27
|
+
* after the items of the pages before it.
|
|
22
28
|
*/
|
|
23
|
-
export declare
|
|
29
|
+
export declare const paginate: <Args extends unknown[], Input extends PagedInput, Item, E, R>(list: (...args: [...Args, Input]) => Effect.Effect<Listing<Item>, E, R>, ...args: [...Args, Input]) => Stream.Stream<Item, E, R>;
|
|
30
|
+
export { type GitClientCalls, client_d_exports };
|