ref0-git 0.4.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/apps/github/README.md +3 -7
- package/app/apps/github/generated/git-rest.ts +12 -12
- package/app/apps/github/src/clients/allowed.ts +7 -9
- package/app/apps/github/src/clients/avatars.ts +5 -3
- package/app/apps/github/src/clients/graphql.ts +12 -2
- package/app/apps/github/src/clients/host-calls.ts +2 -1
- package/app/apps/github/src/clients/transfers.ts +56 -19
- package/app/apps/github/src/context/context.ts +5 -5
- package/app/apps/github/src/context/host.ts +115 -0
- package/app/apps/github/src/ingress.ts +28 -0
- package/app/apps/github/src/policy.ts +143 -79
- package/app/apps/github/src/private-repos.ts +7 -7
- package/app/apps/github/src/pulls/review.ts +2 -1
- package/app/apps/github/src/releases/release-form.tsx +40 -4
- package/app/apps/github/src/releases/releases.ts +148 -22
- package/app/apps/github/src/routes/uploads/$owner/$repo/$release.tsx +9 -2
- package/app/apps/github/src/seed/seed.ts +9 -2
- package/app/apps/github/src/server.ts +28 -11
- package/app/apps/github/src/signin/approval.ts +20 -15
- package/app/apps/github/src/signin/attempts.ts +306 -0
- package/app/apps/github/src/signin/auth.ts +9 -0
- package/app/apps/github/src/signin/host-session.ts +30 -18
- package/app/apps/github/src/signin/limits.ts +35 -0
- package/app/pnpm-workspace.yaml +39 -35
- package/dist/cli/setup.mjs +1 -1
- package/dist/init/app.mjs +43 -22
- package/dist/init/cloudflare.mjs +8 -4
- package/dist/init/create.mjs +1 -1
- package/dist/init/detect.mjs +5 -3
- package/dist/init/files.mjs +6 -1
- package/dist/init/git-module.mjs +4 -6
- package/dist/init/metadata.mjs +6 -6
- package/dist/init/node-app.mjs +5 -2
- package/dist/init/stores.mjs +3 -2
- package/dist/init/template.mjs +13 -7
- package/dist/init/templates.mjs +51 -39
- package/dist/init/vercel.mjs +1 -1
- package/dist/init/versions.mjs +1 -1
- package/package.json +13 -13
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { accept, gitError, Rules, reject } from '@ref0/git';
|
|
1
|
+
import { accept, gitError, Policy, Rules, reject } from '@ref0/git';
|
|
2
2
|
import type {
|
|
3
3
|
ActorId,
|
|
4
4
|
AuthorizeInput,
|
|
5
|
+
Caller,
|
|
5
6
|
GitError,
|
|
6
|
-
|
|
7
|
+
InternalRepoId,
|
|
7
8
|
NamedActor,
|
|
8
9
|
PushRule,
|
|
9
10
|
RefName,
|
|
@@ -34,6 +35,7 @@ import type {
|
|
|
34
35
|
PeopleUser,
|
|
35
36
|
PeopleViewer,
|
|
36
37
|
} from '@ref0/github';
|
|
38
|
+
import * as Clock from 'effect/Clock';
|
|
37
39
|
import * as Effect from 'effect/Effect';
|
|
38
40
|
|
|
39
41
|
import { type StarterApprovalOptions, starterApprovalPage } from './signin/approval.ts';
|
|
@@ -60,7 +62,7 @@ interface Listed<Item> {
|
|
|
60
62
|
readonly next?: string;
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
/** A membership the policy read, and when
|
|
65
|
+
/** A membership the policy read, and when, by the `Clock`. */
|
|
64
66
|
interface KeptMembership {
|
|
65
67
|
readonly at: number;
|
|
66
68
|
readonly answer: Promise<Membership | undefined>;
|
|
@@ -143,7 +145,10 @@ const authorsOwn: ReadonlySet<string> = new Set([
|
|
|
143
145
|
'review.resolve',
|
|
144
146
|
]);
|
|
145
147
|
|
|
146
|
-
const
|
|
148
|
+
const signInFirstRefusal = { message: 'Sign in first' };
|
|
149
|
+
|
|
150
|
+
/** `signInFirstRefusal`, as the drop-in's half answers it. */
|
|
151
|
+
const signInFirst = reject(signInFirstRefusal);
|
|
147
152
|
|
|
148
153
|
/**
|
|
149
154
|
* The owner a token reaches past its subject's own login, if any: a repo token's repo's owner, by
|
|
@@ -174,7 +179,7 @@ const orgCoverage = (operation: TokenOperation) => {
|
|
|
174
179
|
|
|
175
180
|
/** Who a call's token holds for, a token's caller or the host's own sign-in. */
|
|
176
181
|
interface Holder {
|
|
177
|
-
readonly actor: AuthorizeInput['actor'];
|
|
182
|
+
readonly actor: AuthorizeInput['actor'] | Caller['actor'];
|
|
178
183
|
readonly subject?: ActorId;
|
|
179
184
|
readonly token?: TokenInfo;
|
|
180
185
|
}
|
|
@@ -183,14 +188,25 @@ interface Holder {
|
|
|
183
188
|
* The refusal of a token whose person left the org it's over, or joined it again after it was
|
|
184
189
|
* made: it works for nothing, public reads included, as GitHub's inactive token (Q740).
|
|
185
190
|
*/
|
|
186
|
-
const
|
|
191
|
+
const tokenEndedRefusal = { message: "This token's person no longer holds the org it's over" };
|
|
192
|
+
|
|
193
|
+
/** `tokenEndedRefusal`, as the drop-in's half answers it. */
|
|
194
|
+
const tokenEnded = reject(tokenEndedRefusal);
|
|
195
|
+
|
|
196
|
+
/** At most `most` of an owner's private repos the caller may read, as the owner index asks. */
|
|
197
|
+
export type ReadableRepos = (
|
|
198
|
+
input: GitHubReadableReposInput,
|
|
199
|
+
) => Effect.Effect<Awaited<ReturnType<GitHubReadableRepos>>, GitError>;
|
|
187
200
|
|
|
188
|
-
/**
|
|
201
|
+
/**
|
|
202
|
+
* The host's policy and directory, the drop-in's and Git's, over its people and orgs: Git's
|
|
203
|
+
* `Policy`'s decision, the drop-in's `authorize` and `People`, and the owner index's hook.
|
|
204
|
+
*/
|
|
189
205
|
export interface HostPolicy {
|
|
190
|
-
readonly authorize:
|
|
206
|
+
readonly authorize: Policy.PolicyService['authorize'];
|
|
191
207
|
readonly authorizeGitHub: GitHubAuthorize;
|
|
192
208
|
readonly people: PeopleFor;
|
|
193
|
-
readonly readableRepos:
|
|
209
|
+
readonly readableRepos: ReadableRepos;
|
|
194
210
|
}
|
|
195
211
|
|
|
196
212
|
/**
|
|
@@ -212,15 +228,22 @@ export interface Pictures {
|
|
|
212
228
|
readonly avatars: Pick<Avatars, 'hash'>;
|
|
213
229
|
}
|
|
214
230
|
|
|
231
|
+
/** The name `internalId`'s repo has now, `undefined` once none holds it. */
|
|
232
|
+
export type RepoNameOf = (
|
|
233
|
+
internalId: InternalRepoId,
|
|
234
|
+
signal: AbortSignal,
|
|
235
|
+
) => Promise<RepoName | undefined>;
|
|
236
|
+
|
|
215
237
|
/**
|
|
216
|
-
* What the starter's policy reads past its orgs: its `Pictures`, both or neither,
|
|
217
|
-
* `privateRepos`, which lists an owner's private repos for the owner index's hook
|
|
218
|
-
* names no private
|
|
238
|
+
* What the starter's policy reads past its orgs: its `Pictures`, both or neither,
|
|
239
|
+
* `privateRepos`, which lists an owner's private repos for the owner index's hook, and
|
|
240
|
+
* `repoName`, which the drop-in's owner check reads. With no `privateRepos`, it names no private
|
|
241
|
+
* repo, and with no `repoName`, the owner check reads the name the request named.
|
|
219
242
|
*/
|
|
220
243
|
export type HostPolicyOptions = (
|
|
221
244
|
| Pictures
|
|
222
245
|
| { readonly origin?: undefined; readonly avatars?: undefined }
|
|
223
|
-
) & { readonly privateRepos?: PrivateRepos };
|
|
246
|
+
) & { readonly privateRepos?: PrivateRepos; readonly repoName?: RepoNameOf };
|
|
224
247
|
|
|
225
248
|
/**
|
|
226
249
|
* What of `owner`'s repos `token` covers: every one, those under the token's longer prefix, its
|
|
@@ -243,7 +266,12 @@ const coverOf = (owner: string, token: GitHubReadableReposInput['token']) => {
|
|
|
243
266
|
* directory of people and orgs, by Better Auth's tables, with what `options` adds.
|
|
244
267
|
*/
|
|
245
268
|
export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPolicy => {
|
|
246
|
-
const {
|
|
269
|
+
const {
|
|
270
|
+
origin,
|
|
271
|
+
avatars,
|
|
272
|
+
privateRepos = async () => ({ names: [], more: false }),
|
|
273
|
+
repoName,
|
|
274
|
+
} = options;
|
|
247
275
|
|
|
248
276
|
/**
|
|
249
277
|
* The `avatar_url` of `login`, held by `account`, when it has an upload: the app's route, by its
|
|
@@ -276,23 +304,23 @@ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPol
|
|
|
276
304
|
const memberships = new WeakMap<ActorId, Map<string, KeptMembership>>();
|
|
277
305
|
|
|
278
306
|
/** `actor`'s membership of the org `org`, asked once a request, and again past its life. */
|
|
279
|
-
const membershipOf = (actor: ActorId, org: string) =>
|
|
280
|
-
|
|
281
|
-
|
|
307
|
+
const membershipOf = (actor: ActorId, org: string) =>
|
|
308
|
+
Effect.flatMap(Clock.currentTimeMillis, (now) => {
|
|
309
|
+
const held = memberships.get(actor) ?? new Map<string, KeptMembership>();
|
|
310
|
+
memberships.set(actor, held);
|
|
282
311
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
if (kept !== undefined && now - kept.at < membershipLife) return kept.answer;
|
|
312
|
+
const kept = held.get(org);
|
|
313
|
+
if (kept !== undefined && now - kept.at < membershipLife) return read(() => kept.answer);
|
|
286
314
|
|
|
287
|
-
|
|
288
|
-
|
|
315
|
+
const answer = orgs.membership(org, actor.id);
|
|
316
|
+
held.set(org, { at: now, answer });
|
|
289
317
|
|
|
290
|
-
|
|
291
|
-
|
|
318
|
+
return read(() => answer);
|
|
319
|
+
});
|
|
292
320
|
|
|
293
321
|
/** Whether `actor` belongs to the org `org`, in any role. */
|
|
294
|
-
const belongs =
|
|
295
|
-
(
|
|
322
|
+
const belongs = (actor: ActorId, org: string) =>
|
|
323
|
+
Effect.map(membershipOf(actor, org), (membership) => membership !== undefined);
|
|
296
324
|
|
|
297
325
|
/**
|
|
298
326
|
* Whether a call's token holds (Q740): one over an owner other than its subject holds only while
|
|
@@ -301,65 +329,92 @@ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPol
|
|
|
301
329
|
* Worker's clock reads both, a token made then holds. A session's token, the host's own sign-in
|
|
302
330
|
* and a token over the subject's own login hold as they are.
|
|
303
331
|
*/
|
|
304
|
-
const tokenHolds =
|
|
332
|
+
const tokenHolds = Effect.fnUntraced(function* ({ actor, subject, token }: Holder) {
|
|
305
333
|
if (token === undefined || actor.anonymous === true) return true;
|
|
306
334
|
|
|
307
335
|
const person = subject !== undefined && subject.id !== actor.id ? subject : actor;
|
|
308
336
|
const owner = tokenOwner(token);
|
|
309
337
|
if (owner === undefined || owner === person.id) return true;
|
|
310
338
|
|
|
311
|
-
const membership =
|
|
339
|
+
const membership = yield* membershipOf(person, owner);
|
|
312
340
|
|
|
313
341
|
return membership !== undefined && membership.since <= token.createdAt;
|
|
314
|
-
};
|
|
342
|
+
});
|
|
315
343
|
|
|
316
344
|
/** Whether `actor` owns what `owner` holds: their own login's, and each org's they belong to. */
|
|
317
|
-
const owns =
|
|
318
|
-
owner === actor.id
|
|
345
|
+
const owns = (actor: NamedActor, owner: string | undefined) =>
|
|
346
|
+
owner === actor.id
|
|
347
|
+
? Effect.succeed(true)
|
|
348
|
+
: owner === undefined
|
|
349
|
+
? Effect.succeed(false)
|
|
350
|
+
: belongs(actor, owner);
|
|
319
351
|
|
|
320
352
|
/**
|
|
321
|
-
*
|
|
322
|
-
*
|
|
353
|
+
* The owner now of the repo a drop-in operation on `name` acts on: its current name's, read by
|
|
354
|
+
* `repoName` from the repo's internal ID, so a repo transferred since the request named it is
|
|
355
|
+
* its new owner's, and none once no name holds it or the input names no repo. With no
|
|
356
|
+
* `repoName`, the owner of `name`.
|
|
323
357
|
*/
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
|
|
358
|
+
const ownerNow = Effect.fnUntraced(function* (name: RepoName, input: GitHubAuthorization) {
|
|
359
|
+
if (repoName === undefined) return ownerOf(name);
|
|
360
|
+
|
|
361
|
+
const { repo } = input;
|
|
362
|
+
if (repo === undefined) return undefined;
|
|
363
|
+
|
|
364
|
+
const now = yield* read(() => repoName(repo.internalId, input.signal));
|
|
365
|
+
|
|
366
|
+
return now === undefined ? undefined : ownerOf(now);
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Git's `Policy`: public repos for anyone to read and list, who they are for anyone signed in,
|
|
371
|
+
* and the rest for a repo's owner, once the caller's token still holds. A directory read that
|
|
372
|
+
* fails fails the decision, which Git answers `UNAVAILABLE`, never an accept.
|
|
373
|
+
*/
|
|
374
|
+
const authorize: Policy.PolicyService['authorize'] = Effect.fnUntraced(function* (
|
|
375
|
+
input: Policy.Input,
|
|
376
|
+
) {
|
|
377
|
+
const { caller, operation, repo } = input;
|
|
378
|
+
const { actor } = caller;
|
|
379
|
+
if (!(yield* tokenHolds(caller))) return yield* Policy.reject(tokenEndedRefusal);
|
|
327
380
|
|
|
328
381
|
// Who the caller is, at Git's `/me`: theirs, once their token holds.
|
|
329
|
-
if (operation.kind === 'me')
|
|
382
|
+
if (operation.kind === 'me') {
|
|
383
|
+
return yield* actor.anonymous === true ? Policy.reject(signInFirstRefusal) : Policy.accept();
|
|
384
|
+
}
|
|
330
385
|
|
|
331
386
|
const reads = operation.kind === 'read' || operation.kind === 'fetch';
|
|
332
|
-
if (reads && repo?.public === true) return accept();
|
|
387
|
+
if (reads && repo?.public === true) return yield* Policy.accept();
|
|
333
388
|
|
|
334
389
|
// Anyone lists: Git lists a caller not signed in only the public repos' own index, whose names
|
|
335
390
|
// the rule above lets anyone read, as GitHub lists an owner's public repos to anyone (Q791).
|
|
336
|
-
if (operation.kind === 'repo.list') return accept();
|
|
391
|
+
if (operation.kind === 'repo.list') return yield* Policy.accept();
|
|
337
392
|
|
|
338
|
-
if (actor.anonymous === true) return
|
|
393
|
+
if (actor.anonymous === true) return yield* Policy.reject(signInFirstRefusal);
|
|
339
394
|
|
|
340
395
|
// A repo is made only under a login a person or an org holds, so no one's sign-up or org
|
|
341
396
|
// later finds repos waiting under its name.
|
|
342
397
|
if (operation.kind === 'repo.create') {
|
|
343
398
|
const owner = ownerOf(operation.repo);
|
|
344
399
|
|
|
345
|
-
if (owner === undefined || !(
|
|
346
|
-
return reject({ message: 'No person or org holds that owner' });
|
|
400
|
+
if (owner === undefined || !(yield* read(() => orgs.held(owner)))) {
|
|
401
|
+
return yield* Policy.reject({ message: 'No person or org holds that owner' });
|
|
347
402
|
}
|
|
348
403
|
}
|
|
349
404
|
|
|
350
405
|
// A protected or locked ref stays so for everyone, the admin too: a rule asks this on each
|
|
351
406
|
// change it refuses, so accepting it would lift every rule for whoever passes.
|
|
352
407
|
if (operation.kind === 'protect.bypass' || operation.kind === 'lock.bypass') {
|
|
353
|
-
return reject({ message: 'No rule is lifted for anyone' });
|
|
408
|
+
return yield* Policy.reject({ message: 'No rule is lifted for anyone' });
|
|
354
409
|
}
|
|
355
410
|
|
|
356
411
|
if (actor.id === admin.id) {
|
|
357
|
-
return operation.kind === 'push'
|
|
358
|
-
? reject({
|
|
412
|
+
return yield* operation.kind === 'push'
|
|
413
|
+
? Policy.reject({
|
|
359
414
|
message: "The admin token can't push",
|
|
360
415
|
hint: 'Sign in at /login, or make a write token for yourself: POST /repos/<repo>/-/tokens',
|
|
361
416
|
})
|
|
362
|
-
: accept();
|
|
417
|
+
: Policy.accept();
|
|
363
418
|
}
|
|
364
419
|
|
|
365
420
|
// A person mints only for themselves, as no one else acts for them: a token's caller is its
|
|
@@ -368,7 +423,7 @@ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPol
|
|
|
368
423
|
operation.kind === 'token.create' &&
|
|
369
424
|
(operation.subject.id !== actor.id || operation.actor !== undefined)
|
|
370
425
|
) {
|
|
371
|
-
return reject({
|
|
426
|
+
return yield* Policy.reject({
|
|
372
427
|
message: 'Only tokens for yourself',
|
|
373
428
|
hint: 'The admin makes tokens for others',
|
|
374
429
|
});
|
|
@@ -379,20 +434,20 @@ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPol
|
|
|
379
434
|
operation.kind === 'token.list' ||
|
|
380
435
|
operation.kind === 'token.revoke'
|
|
381
436
|
) {
|
|
382
|
-
return tokenRule(actor, operation);
|
|
437
|
+
return yield* tokenRule(actor, operation);
|
|
383
438
|
}
|
|
384
439
|
|
|
385
440
|
// A fork lands under its holder, from any repo the person may read.
|
|
386
441
|
if (operation.kind === 'fork.create') {
|
|
387
|
-
return operation.holder === actor.id
|
|
388
|
-
? accept()
|
|
389
|
-
: reject({ message: 'Fork under your own login' });
|
|
442
|
+
return yield* operation.holder === actor.id
|
|
443
|
+
? Policy.accept()
|
|
444
|
+
: Policy.reject({ message: 'Fork under your own login' });
|
|
390
445
|
}
|
|
391
446
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
};
|
|
447
|
+
const mine = 'repo' in operation && (yield* owns(actor, ownerOf(operation.repo)));
|
|
448
|
+
|
|
449
|
+
return yield* mine ? Policy.accept() : Policy.reject({ message: 'Not yours' });
|
|
450
|
+
});
|
|
396
451
|
|
|
397
452
|
/**
|
|
398
453
|
* A person's token calls (Q521, Q740), the admin's being accepted above:
|
|
@@ -405,31 +460,38 @@ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPol
|
|
|
405
460
|
* - a list, or a revoke of another's token, over an org they're an owner or an admin of,
|
|
406
461
|
* read at this call.
|
|
407
462
|
*/
|
|
408
|
-
const tokenRule =
|
|
409
|
-
|
|
463
|
+
const tokenRule = Effect.fnUntraced(function* (
|
|
464
|
+
actor: NamedActor | ActorId,
|
|
465
|
+
operation: TokenOperation,
|
|
466
|
+
) {
|
|
467
|
+
if (operation.kind === 'token.revoke' && operation.subject.id === actor.id) {
|
|
468
|
+
return yield* Policy.accept();
|
|
469
|
+
}
|
|
410
470
|
|
|
411
471
|
const own =
|
|
412
472
|
operation.repo === undefined
|
|
413
473
|
? operation.prefix.startsWith(`${actor.id}/`)
|
|
414
474
|
: ownerOf(operation.repo) === actor.id;
|
|
415
|
-
if (own && operation.kind !== 'token.revoke') return accept();
|
|
475
|
+
if (own && operation.kind !== 'token.revoke') return yield* Policy.accept();
|
|
416
476
|
|
|
417
477
|
const org = orgCoverage(operation);
|
|
418
|
-
const membership = org === undefined ? undefined :
|
|
478
|
+
const membership = org === undefined ? undefined : yield* membershipOf(actor, org);
|
|
419
479
|
|
|
420
480
|
if (operation.kind === 'token.create') {
|
|
421
|
-
return membership === undefined
|
|
422
|
-
? reject({
|
|
481
|
+
return yield* membership === undefined
|
|
482
|
+
? Policy.reject({
|
|
423
483
|
message: 'Only tokens over your own repos, or an org you belong to',
|
|
424
484
|
hint: "Over an org, a token covers all of its repos or one: '<org>/' or '<org>/<repo>'",
|
|
425
485
|
})
|
|
426
|
-
: accept();
|
|
486
|
+
: Policy.accept();
|
|
427
487
|
}
|
|
428
488
|
|
|
429
|
-
return orgTokenView(membership) === 'all'
|
|
430
|
-
? accept()
|
|
431
|
-
: reject({
|
|
432
|
-
|
|
489
|
+
return yield* orgTokenView(membership) === 'all'
|
|
490
|
+
? Policy.accept()
|
|
491
|
+
: Policy.reject({
|
|
492
|
+
message: "Only an org's owners and admins list and revoke its members' tokens",
|
|
493
|
+
});
|
|
494
|
+
});
|
|
433
495
|
|
|
434
496
|
/**
|
|
435
497
|
* The drop-in's `authorize`: a public repo's reads for anyone, as Git's, and its contributions
|
|
@@ -445,12 +507,12 @@ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPol
|
|
|
445
507
|
input: GitHubAuthorization,
|
|
446
508
|
) {
|
|
447
509
|
const { actor, operation } = input;
|
|
448
|
-
if (!(yield*
|
|
510
|
+
if (!(yield* tokenHolds(input))) return tokenEnded;
|
|
449
511
|
|
|
450
512
|
if ('org' in operation) {
|
|
451
513
|
if (actor.anonymous === true) return signInFirst;
|
|
452
514
|
|
|
453
|
-
return actor.id === admin.id || (yield*
|
|
515
|
+
return actor.id === admin.id || (yield* owns(actor, operation.org))
|
|
454
516
|
? accept()
|
|
455
517
|
: reject({ message: "Only the org's members may do this" });
|
|
456
518
|
}
|
|
@@ -482,7 +544,7 @@ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPol
|
|
|
482
544
|
// holding the repo is all that's left to ask.
|
|
483
545
|
if (operation.asAuthor === true && authorsOwn.has(operation.kind)) return accept();
|
|
484
546
|
|
|
485
|
-
return (yield*
|
|
547
|
+
return (yield* owns(actor, yield* ownerNow(operation.repo, input)))
|
|
486
548
|
? accept()
|
|
487
549
|
: reject({ message: 'Only the owner may do this' });
|
|
488
550
|
});
|
|
@@ -495,19 +557,22 @@ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPol
|
|
|
495
557
|
* A token over one repo names it alone, which `authorize` holds as any name. Git lists them newest
|
|
496
558
|
* made first, since it keeps no time a repo was updated.
|
|
497
559
|
*/
|
|
498
|
-
const readableRepos:
|
|
560
|
+
const readableRepos: ReadableRepos = Effect.fnUntraced(function* (input) {
|
|
499
561
|
const { actor, owner, most, token, host } = input;
|
|
500
|
-
|
|
562
|
+
const none = { names: [], more: false };
|
|
563
|
+
if (actor.anonymous === true || !(yield* tokenHolds(input))) return none;
|
|
501
564
|
|
|
502
|
-
if (actor.id !== admin.id && !(
|
|
565
|
+
if (actor.id !== admin.id && !(yield* owns(actor, owner))) return none;
|
|
503
566
|
|
|
504
567
|
const cover = coverOf(owner, token);
|
|
505
|
-
if (cover === undefined || most <= 0) return
|
|
568
|
+
if (cover === undefined || most <= 0) return none;
|
|
506
569
|
|
|
507
570
|
if (cover.repo !== undefined) return { names: [cover.repo], more: false };
|
|
508
571
|
|
|
509
|
-
|
|
510
|
-
|
|
572
|
+
const { prefix } = cover;
|
|
573
|
+
|
|
574
|
+
return yield* read(() => privateRepos(prefix, most, host));
|
|
575
|
+
});
|
|
511
576
|
|
|
512
577
|
/**
|
|
513
578
|
* The host's directory, for the drop-in (Q522): a user only once they've signed up, an org only
|
|
@@ -621,9 +686,8 @@ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPol
|
|
|
621
686
|
function lookup(input: PeopleInput): Effect.Effect<PeopleAnswer, GitError> {
|
|
622
687
|
// A token whose person left the org it's over reads no one and lists nothing: `/user` 404s,
|
|
623
688
|
// as every other use of it is refused.
|
|
624
|
-
return Effect.flatMap(
|
|
625
|
-
|
|
626
|
-
(holds) => (holds ? answer(input) : Effect.succeed(refusedLookup(input))),
|
|
689
|
+
return Effect.flatMap(tokenHolds(input), (holds) =>
|
|
690
|
+
holds ? answer(input) : Effect.succeed(refusedLookup(input)),
|
|
627
691
|
);
|
|
628
692
|
}
|
|
629
693
|
|
|
@@ -667,7 +731,7 @@ export const hostRules: readonly HostRule[] = [
|
|
|
667
731
|
|
|
668
732
|
/**
|
|
669
733
|
* Git's `identify`, as the approval page asks it. A host's `git.ts` gives its callback this return
|
|
670
|
-
* type, since
|
|
734
|
+
* type, since the runtime's type is inferred from Layers whose approval page names it.
|
|
671
735
|
*/
|
|
672
736
|
export type Identify = StarterApprovalOptions['identify'];
|
|
673
737
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { Actor,
|
|
1
|
+
import type { Actor, RepoCalls, RepoName } from '@ref0/git';
|
|
2
2
|
|
|
3
3
|
import { admin } from './policy.ts';
|
|
4
4
|
import type { PrivateRepos } from './policy.ts';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* At most `most` of the private repos under `prefix
|
|
8
|
-
*
|
|
7
|
+
* At most `most` of the private repos under `prefix`, among the newest `most` there, newest made
|
|
8
|
+
* first: those `host` lists, unchecked, less what Git's `list` lists a caller not signed in,
|
|
9
9
|
* which reads the public repos' own index. Both lists are one page of `most`, newest first by one
|
|
10
10
|
* key, a repo's created row, so the two windows hold the same repos and differ by the private ones
|
|
11
11
|
* alone. The search asks for as many as it checks of the owner, so a private repo is named as far
|
|
@@ -19,12 +19,12 @@ import type { PrivateRepos } from './policy.ts';
|
|
|
19
19
|
* `store/catalogue.ts`, `cursorSeal` in `store/cursor-seal.ts`).
|
|
20
20
|
*/
|
|
21
21
|
export const privateReposOf =
|
|
22
|
-
(
|
|
22
|
+
(list: RepoCalls['list']): PrivateRepos =>
|
|
23
23
|
async (prefix, most, host) => {
|
|
24
24
|
if (most <= 0) return { names: [], more: true };
|
|
25
25
|
|
|
26
|
-
const listed = async (
|
|
27
|
-
const page = await
|
|
26
|
+
const listed = async (from: RepoCalls['list'], actor: Actor) => {
|
|
27
|
+
const page = await from({
|
|
28
28
|
actor,
|
|
29
29
|
prefix,
|
|
30
30
|
order: 'newest',
|
|
@@ -38,7 +38,7 @@ export const privateReposOf =
|
|
|
38
38
|
// The host's own calls read no actor: the admin's stands in, as `repos.list` takes one.
|
|
39
39
|
const [all, shown] = await Promise.all([
|
|
40
40
|
listed(host.list, admin),
|
|
41
|
-
listed(
|
|
41
|
+
listed(list, { anonymous: true }),
|
|
42
42
|
]);
|
|
43
43
|
const open = new Set<RepoName>(shown.names);
|
|
44
44
|
const hidden = all.names.filter((name) => !open.has(name));
|
|
@@ -324,7 +324,8 @@ export const resolveThread = async (clients: Clients, thread: ThreadState, resol
|
|
|
324
324
|
|
|
325
325
|
/**
|
|
326
326
|
* The drafts of the viewer's pending review `review`, as the drop-in keeps them: written here, in
|
|
327
|
-
* another tab, or with `gh`, so a reload shows each. Every page
|
|
327
|
+
* another tab, or with `gh`, so a reload shows each. Every page: each draft is a row of its own,
|
|
328
|
+
* and a count bounds how many a review holds.
|
|
328
329
|
*/
|
|
329
330
|
export const pendingCommentsOf = (
|
|
330
331
|
clients: Clients,
|
|
@@ -3,7 +3,7 @@ import { useNavigate } from '@tanstack/react-router';
|
|
|
3
3
|
import { LockIcon, PackageIcon } from 'lucide-react';
|
|
4
4
|
import { useRef, useState } from 'react';
|
|
5
5
|
|
|
6
|
-
import { assetBytesMost } from '../clients/transfers.ts';
|
|
6
|
+
import { assetBytesMost, partBytes } from '../clients/transfers.ts';
|
|
7
7
|
import { sizeText } from '../code/controls.tsx';
|
|
8
8
|
import { useClients } from '../clients/clients.ts';
|
|
9
9
|
import { releaseHref, type RepoPlace } from '../code/places.ts';
|
|
@@ -100,6 +100,11 @@ function ReleaseFields({ place, target, release }: FormProps) {
|
|
|
100
100
|
const held = useRef(release);
|
|
101
101
|
// Files sent whose answer never came: each may have landed.
|
|
102
102
|
const unsure = useRef(new Set<File>());
|
|
103
|
+
// The upload under way, which the page's stop aborts.
|
|
104
|
+
const stopper = useRef<AbortController | undefined>(undefined);
|
|
105
|
+
const [uploading, setUploading] = useState<
|
|
106
|
+
{ file: File; sent: number; checking: boolean } | undefined
|
|
107
|
+
>();
|
|
103
108
|
const draft = useDraft(
|
|
104
109
|
{
|
|
105
110
|
tag: release?.tag ?? '',
|
|
@@ -154,7 +159,15 @@ function ReleaseFields({ place, target, release }: FormProps) {
|
|
|
154
159
|
setAssets((shown) => [...shown, ...landed]);
|
|
155
160
|
|
|
156
161
|
for (const file of files.filter((each) => !done.has(each))) {
|
|
157
|
-
const
|
|
162
|
+
const stop = new AbortController();
|
|
163
|
+
stopper.current = stop;
|
|
164
|
+
setUploading({ file, sent: 0, checking: false });
|
|
165
|
+
const asset = await uploadAsset(place, made.id, file, {
|
|
166
|
+
lost: () => unsure.current.add(file),
|
|
167
|
+
sent: (sent) => setUploading({ file, sent, checking: false }),
|
|
168
|
+
checking: () => setUploading({ file, sent: file.size, checking: true }),
|
|
169
|
+
signal: stop.signal,
|
|
170
|
+
}).finally(() => setUploading(undefined));
|
|
158
171
|
setFiles((left) => left.filter((each) => each !== file));
|
|
159
172
|
setAssets((shown) => [...shown, asset]);
|
|
160
173
|
}
|
|
@@ -299,8 +312,8 @@ function ReleaseFields({ place, target, release }: FormProps) {
|
|
|
299
312
|
onChange={(event) => setFiles([...(event.target.files ?? [])])}
|
|
300
313
|
/>
|
|
301
314
|
<FieldDescription>
|
|
302
|
-
Each file at most {sizeText(assetBytesMost)}, the drop-in's limit, as GitHub's.
|
|
303
|
-
|
|
315
|
+
Each file at most {sizeText(assetBytesMost)}, the drop-in's limit, as GitHub's. One past{' '}
|
|
316
|
+
{sizeText(partBytes)} uploads in parts.
|
|
304
317
|
</FieldDescription>
|
|
305
318
|
{files.length > 0 && (
|
|
306
319
|
<FieldDescription>
|
|
@@ -343,6 +356,29 @@ function ReleaseFields({ place, target, release }: FormProps) {
|
|
|
343
356
|
<HotkeyHint keys={hotkeys.submit} />
|
|
344
357
|
</SaveButton>
|
|
345
358
|
</div>
|
|
359
|
+
{uploading !== undefined && (
|
|
360
|
+
<div role="status" className="flex items-center justify-end gap-2 text-sm">
|
|
361
|
+
<span className="wrap-anywhere">
|
|
362
|
+
{uploading.checking
|
|
363
|
+
? `Checking ${uploading.file.name}…`
|
|
364
|
+
: `Uploading ${uploading.file.name}: ${sizeText(uploading.sent)} of ${sizeText(uploading.file.size)}`}
|
|
365
|
+
</span>
|
|
366
|
+
{/* Checking has no bytes to count, so its bar shows only that it's working. */}
|
|
367
|
+
<progress
|
|
368
|
+
aria-label={`${uploading.file.name}'s upload`}
|
|
369
|
+
value={uploading.checking ? undefined : uploading.sent}
|
|
370
|
+
max={uploading.file.size}
|
|
371
|
+
/>
|
|
372
|
+
<Button
|
|
373
|
+
type="button"
|
|
374
|
+
variant="outline"
|
|
375
|
+
size="sm"
|
|
376
|
+
onClick={() => stopper.current?.abort()}
|
|
377
|
+
>
|
|
378
|
+
Stop upload
|
|
379
|
+
</Button>
|
|
380
|
+
</div>
|
|
381
|
+
)}
|
|
346
382
|
{[saved.error, removed.error].map(
|
|
347
383
|
(error) =>
|
|
348
384
|
error !== null && (
|