ref0-git 0.10.0 → 0.12.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/src/clients/avatars.ts +27 -10
- package/app/apps/github/src/clients/host-calls.ts +7 -30
- package/app/apps/github/src/context/repo-icons.ts +39 -0
- package/app/apps/github/src/policy.ts +14 -0
- package/dist/init/app.mjs +1 -1
- package/dist/init/git-module.mjs +14 -5
- package/dist/init/metadata.mjs +1 -1
- package/dist/init/templates.mjs +9 -9
- package/dist/init/versions.mjs +1 -1
- package/package.json +5 -5
|
@@ -337,7 +337,14 @@ const mayChange = async (
|
|
|
337
337
|
return allowed.includes('repo.update');
|
|
338
338
|
};
|
|
339
339
|
|
|
340
|
-
/**
|
|
340
|
+
/** The account or repo at `place` as `changer` reads it, or `undefined`. */
|
|
341
|
+
const targetFor = (context: AvatarContext, changer: Changer, place: AvatarPlace) =>
|
|
342
|
+
readTarget(context, changer.origin, changer.admin ? undefined : changer.token, place);
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Whose avatar `change` is for, and who makes it, once `mayChange` lets its changer make it. Else
|
|
346
|
+
* the refusal.
|
|
347
|
+
*/
|
|
341
348
|
const changeable = async (
|
|
342
349
|
context: AvatarContext,
|
|
343
350
|
request: Request,
|
|
@@ -347,14 +354,13 @@ const changeable = async (
|
|
|
347
354
|
const changer = await changerOf(context, request);
|
|
348
355
|
if (changer instanceof Response) return changer;
|
|
349
356
|
|
|
350
|
-
const
|
|
351
|
-
const target = await readTarget(context, changer.origin, token, place);
|
|
357
|
+
const target = await targetFor(context, changer, place);
|
|
352
358
|
if (target === undefined) return notFound();
|
|
353
359
|
|
|
354
360
|
if (!(await mayChange(context, request, changer, change, place, target)))
|
|
355
361
|
return refused(403, changer.admin ? adminRefusal : changers[target.kind]);
|
|
356
362
|
|
|
357
|
-
return target;
|
|
363
|
+
return { changer, target };
|
|
358
364
|
};
|
|
359
365
|
|
|
360
366
|
/** Why the instance admin's upload is refused: their token only removes. */
|
|
@@ -365,7 +371,8 @@ export const adminRefusal = "The instance admin removes a picture but doesn't up
|
|
|
365
371
|
* A body that names more than 1 MB is refused before it's read, and one that sends more is refused
|
|
366
372
|
* once the count passes it (413). Bytes that aren't PNG, JPEG or WebP by their signature, or whose
|
|
367
373
|
* header can't be read, are refused whatever their Content-Type says (415), and a picture over 1024
|
|
368
|
-
* pixels a side is refused by its header (422).
|
|
374
|
+
* pixels a side is refused by its header (422). A repo its uploader no longer reads once the icon
|
|
375
|
+
* is written, deleted while its body came in, has the icon removed again and answers 404.
|
|
369
376
|
*/
|
|
370
377
|
export const uploadAvatar = async (
|
|
371
378
|
context: AvatarContext,
|
|
@@ -375,9 +382,10 @@ export const uploadAvatar = async (
|
|
|
375
382
|
const length = Number(request.headers.get('content-length') ?? 0);
|
|
376
383
|
if (!(length <= iconBytesMost)) return refused(413, iconTypeRefusal);
|
|
377
384
|
|
|
378
|
-
const
|
|
379
|
-
if (
|
|
385
|
+
const allowed = await changeable(context, request, place, 'upload');
|
|
386
|
+
if (allowed instanceof Response) return allowed;
|
|
380
387
|
|
|
388
|
+
const { changer, target } = allowed;
|
|
381
389
|
const bytes = await bytesUpTo(request.body, iconBytesMost);
|
|
382
390
|
if (bytes === undefined) return refused(413, iconTypeRefusal);
|
|
383
391
|
|
|
@@ -391,6 +399,15 @@ export const uploadAvatar = async (
|
|
|
391
399
|
const hash = await hashOf(bytes);
|
|
392
400
|
await context.avatars.put(target.kind, target.id, { type: sniffed.type, bytes, hash });
|
|
393
401
|
|
|
402
|
+
// A repo deleted while its body came in may have had its icon removed by `repo.deleted` before
|
|
403
|
+
// this write landed. Read after the write: a delete that committed first is seen here, and one
|
|
404
|
+
// that commits later removes this row on its own event (#2223).
|
|
405
|
+
if (target.kind === 'repo' && (await targetFor(context, changer, place))?.id !== target.id) {
|
|
406
|
+
await context.avatars.remove(target.kind, target.id);
|
|
407
|
+
|
|
408
|
+
return notFound();
|
|
409
|
+
}
|
|
410
|
+
|
|
394
411
|
return Response.json({ hash }, { headers: { 'cache-control': 'no-store' } });
|
|
395
412
|
};
|
|
396
413
|
|
|
@@ -403,10 +420,10 @@ export const removeAvatar = async (
|
|
|
403
420
|
request: Request,
|
|
404
421
|
place: AvatarPlace,
|
|
405
422
|
): Promise<Response> => {
|
|
406
|
-
const
|
|
407
|
-
if (
|
|
423
|
+
const allowed = await changeable(context, request, place, 'remove');
|
|
424
|
+
if (allowed instanceof Response) return allowed;
|
|
408
425
|
|
|
409
|
-
await context.avatars.remove(target.kind, target.id);
|
|
426
|
+
await context.avatars.remove(allowed.target.kind, allowed.target.id);
|
|
410
427
|
|
|
411
428
|
return new Response(null, { status: 204 });
|
|
412
429
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createServerFn } from '@tanstack/react-start';
|
|
2
2
|
import { getRequest } from '@tanstack/react-start/server';
|
|
3
3
|
import * as Effect from 'effect/Effect';
|
|
4
|
-
import * as Option from 'effect/Option';
|
|
5
4
|
import * as Schema from 'effect/Schema';
|
|
6
5
|
|
|
7
6
|
import type { TokenRecord as GitTokenRecord, TokenTarget } from '@ref0/git';
|
|
@@ -70,13 +69,12 @@ export type HostAsk = typeof HostAsk.Type;
|
|
|
70
69
|
export type HostOperation = HostAsk['operation'];
|
|
71
70
|
|
|
72
71
|
/**
|
|
73
|
-
* What `hostCallFor` asks with: the Worker's APIs, the session key, Git's `identify`, the
|
|
74
|
-
*
|
|
75
|
-
* through.
|
|
72
|
+
* What `hostCallFor` asks with: the Worker's APIs, the session key, Git's `identify`, the
|
|
73
|
+
* person's orgs, and Git's direct lists an org's tokens are read through.
|
|
76
74
|
*/
|
|
77
75
|
export type HostContext = Pick<
|
|
78
76
|
AppContext,
|
|
79
|
-
'api' | 'sealKey' | 'identify' | 'session' | '
|
|
77
|
+
'api' | 'sealKey' | 'identify' | 'session' | 'accounts' | 'git'
|
|
80
78
|
>;
|
|
81
79
|
|
|
82
80
|
/** A token of the person's, as Git's REST lists it. */
|
|
@@ -182,8 +180,6 @@ const segment = encodeURIComponent;
|
|
|
182
180
|
const repoPath = (owner: string, repo: string) =>
|
|
183
181
|
`/api/v3/repos/${segment(owner)}/${segment(repo)}`;
|
|
184
182
|
|
|
185
|
-
const repoId = Schema.decodeUnknownOption(Schema.Struct({ id: Schema.Number }));
|
|
186
|
-
|
|
187
183
|
/** A token place's list as host code reads it, `rows` at most, and whether more followed. */
|
|
188
184
|
const listed = async (tokens: TokenLists, target: TokenTarget, rows: number) => {
|
|
189
185
|
const items: GitTokenRecord[] = [];
|
|
@@ -283,32 +279,15 @@ const repoWrite = (ask: HostAsk, login: string) => {
|
|
|
283
279
|
path: repoPath(ask.owner, ask.repo),
|
|
284
280
|
json: encodeRepoSettings(ask.settings),
|
|
285
281
|
};
|
|
282
|
+
|
|
283
|
+
// Its icon goes on Git's `repo.deleted`, as one deleted through the API does (`repo-icons.ts`).
|
|
284
|
+
case 'repo.delete':
|
|
285
|
+
return { method: 'DELETE', path: repoPath(ask.owner, ask.repo) };
|
|
286
286
|
default:
|
|
287
287
|
return undefined;
|
|
288
288
|
}
|
|
289
289
|
};
|
|
290
290
|
|
|
291
|
-
/**
|
|
292
|
-
* The repo deleted as `login`, and its icon with it, by the repo's REST `id`, read first, since the
|
|
293
|
-
* delete answers none. A repo deleted around the app, straight through the API, keeps its icon's row.
|
|
294
|
-
*/
|
|
295
|
-
const deleteRepo = async (
|
|
296
|
-
context: HostContext,
|
|
297
|
-
origin: string,
|
|
298
|
-
login: string,
|
|
299
|
-
place: { readonly owner: string; readonly repo: string },
|
|
300
|
-
) => {
|
|
301
|
-
const path = repoPath(place.owner, place.repo);
|
|
302
|
-
const found = await callAs(context, origin, login, { method: 'GET', path });
|
|
303
|
-
const repo = found.ok ? Option.getOrUndefined(repoId(await found.json())) : undefined;
|
|
304
|
-
if (!found.ok) await found.body?.cancel();
|
|
305
|
-
|
|
306
|
-
const deleted = await callAs(context, origin, login, { method: 'DELETE', path });
|
|
307
|
-
if (deleted.ok && repo !== undefined) await context.avatars.remove('repo', String(repo.id));
|
|
308
|
-
|
|
309
|
-
return deleted;
|
|
310
|
-
};
|
|
311
|
-
|
|
312
291
|
/**
|
|
313
292
|
* `ask`, made as the session's person through the host's sign-in, or refused (Q520): only a POST
|
|
314
293
|
* from the app's own origin, only for a session whose token Git still takes, so sign-out ends it.
|
|
@@ -340,8 +319,6 @@ export const hostCallFor = async (
|
|
|
340
319
|
}
|
|
341
320
|
|
|
342
321
|
const login = session.login;
|
|
343
|
-
if (ask.operation === 'repo.delete') return deleteRepo(context, origin, login, ask);
|
|
344
|
-
|
|
345
322
|
const write = repoWrite(ask, login);
|
|
346
323
|
if (write !== undefined) return callAs(context, origin, login, write);
|
|
347
324
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Git, GitEvents } from '@ref0/git';
|
|
2
|
+
import { repoNumber } from '@ref0/github';
|
|
3
|
+
import * as Effect from 'effect/Effect';
|
|
4
|
+
import * as Schema from 'effect/Schema';
|
|
5
|
+
|
|
6
|
+
import type { Avatars } from './context.ts';
|
|
7
|
+
|
|
8
|
+
/** A deleted repo's icon the store didn't remove, by the repo's REST `id`: the run is sent again. */
|
|
9
|
+
class RepoIconUnremoved extends Schema.TaggedError<RepoIconUnremoved>()('RepoIconUnremoved', {
|
|
10
|
+
repo: Schema.Number,
|
|
11
|
+
cause: Schema.Unknown,
|
|
12
|
+
}) {}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A deleted repo's icon removed from `avatars`, however the repo was deleted: through the app, the
|
|
16
|
+
* API or `gh`. Git's `repo.deleted` names the repo by its internal ID, and its icon is kept under
|
|
17
|
+
* the REST `id` that `repoNumber` gives it. A remove that fails fails the run, which Git tries
|
|
18
|
+
* again as its delivery's retry says; once those tries are spent, the job stays failed, and its
|
|
19
|
+
* cursor holds, until the host retries or discards it (#2223).
|
|
20
|
+
*/
|
|
21
|
+
export const repoIcons = (avatars: Avatars) =>
|
|
22
|
+
Git.addDelivery(
|
|
23
|
+
'repo-icons',
|
|
24
|
+
GitEvents.group((on) =>
|
|
25
|
+
on.handle('repo.deleted', ({ events }) =>
|
|
26
|
+
Effect.forEach(
|
|
27
|
+
events,
|
|
28
|
+
({ internalId }) =>
|
|
29
|
+
Effect.flatMap(repoNumber(internalId), (id) =>
|
|
30
|
+
Effect.tryPromise({
|
|
31
|
+
try: () => avatars.remove('repo', String(id)),
|
|
32
|
+
catch: (cause) => new RepoIconUnremoved({ repo: id, cause }),
|
|
33
|
+
}),
|
|
34
|
+
),
|
|
35
|
+
{ discard: true },
|
|
36
|
+
),
|
|
37
|
+
),
|
|
38
|
+
),
|
|
39
|
+
);
|
|
@@ -25,6 +25,7 @@ import type {
|
|
|
25
25
|
PeopleFor,
|
|
26
26
|
PeopleInput,
|
|
27
27
|
PeopleMembers,
|
|
28
|
+
PeopleEmails,
|
|
28
29
|
PeopleMembership,
|
|
29
30
|
PeopleOrg,
|
|
30
31
|
PeopleSearch,
|
|
@@ -82,6 +83,7 @@ const refusedLookup = (input: PeopleInput): PeopleAnswer => {
|
|
|
82
83
|
case 'teams':
|
|
83
84
|
case 'team-members':
|
|
84
85
|
return { items: [] };
|
|
86
|
+
case 'emails':
|
|
85
87
|
case 'membership':
|
|
86
88
|
return [];
|
|
87
89
|
case 'search':
|
|
@@ -599,6 +601,15 @@ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPol
|
|
|
599
601
|
return { ...found, name: person.name, ...picture } satisfies GitHubUser;
|
|
600
602
|
});
|
|
601
603
|
|
|
604
|
+
// A login's commit addresses, the default's, for a person the app holds: none for a login
|
|
605
|
+
// with no account, as its user lookup answers none.
|
|
606
|
+
const emails = Effect.fnUntraced(function* (input: PeopleEmails) {
|
|
607
|
+
const person = yield* read(() => orgs.person(input.login));
|
|
608
|
+
if (person === undefined) return [];
|
|
609
|
+
|
|
610
|
+
return yield* base(input);
|
|
611
|
+
});
|
|
612
|
+
|
|
602
613
|
const org = Effect.fnUntraced(function* (input: PeopleOrg) {
|
|
603
614
|
return (yield* read(() => orgs.org(input.org))) ? yield* orgOf(input.org) : undefined;
|
|
604
615
|
});
|
|
@@ -660,6 +671,8 @@ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPol
|
|
|
660
671
|
return search(input);
|
|
661
672
|
case 'members':
|
|
662
673
|
return members(input);
|
|
674
|
+
case 'emails':
|
|
675
|
+
return emails(input);
|
|
663
676
|
case 'membership':
|
|
664
677
|
return read(() => orgs.among(input.org, input.logins));
|
|
665
678
|
case 'team-members':
|
|
@@ -680,6 +693,7 @@ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPol
|
|
|
680
693
|
input: PeopleMembers | PeopleTeamMembers,
|
|
681
694
|
): Effect.Effect<Listed<GitHubUser>, GitError>;
|
|
682
695
|
function lookup(input: PeopleTeams): Effect.Effect<Listed<GitHubTeam>, GitError>;
|
|
696
|
+
function lookup(input: PeopleEmails): Effect.Effect<readonly string[], GitError>;
|
|
683
697
|
function lookup(input: PeopleMembership): Effect.Effect<readonly string[], GitError>;
|
|
684
698
|
function lookup(input: PeopleTeam): Effect.Effect<GitHubTeam | undefined, GitError>;
|
|
685
699
|
function lookup(input: PeopleSearch): Effect.Effect<PeopleSearchAnswer, GitError>;
|
package/dist/init/app.mjs
CHANGED
|
@@ -156,7 +156,7 @@ const dialectOn = {
|
|
|
156
156
|
const nodeHead = (choices) => {
|
|
157
157
|
const queue = choices.queue === "on";
|
|
158
158
|
const dialect = dialectOn[choices.records];
|
|
159
|
-
return lines(firstImports(choices, false), dialect !== false && `${dialect}\n`, gitImport(choices), queue && "import type { MergeInput, MergePlan } from '@ref0/git';", githubImport(choices), "import * as Languages from '@ref0/github/languages';", infraImports(choices), "import { xdiff } from '@ref0/xdiff-wasm/node';", "import * as FetchHttpClient from 'effect/http/FetchHttpClient';", "import * as Layer from 'effect/Layer';", "import * as ManagedRuntime from 'effect/ManagedRuntime';", "", "import { hostLayer, peopleOver, repoListOn, runOn, tokenCallsOn } from './context/host.ts';", `import { env${partsOf(choices).length > 0 ? ", need" : ""} } from './env.ts';`, "import { admin, approvalPage, hostPolicy, hostRules, type Identify } from './policy.ts';", "import { privateReposOf } from './private-repos.ts';", "import { readyAdapter, readyAuth, starterAuth } from './signin/auth.ts';", "import { avatars } from './signin/avatars.ts';", "import { clientIpHeader } from './signin/client-ip.ts';", "import { appAuth } from './signin/host-session.ts';", "import { orgsOver } from './signin/orgs.ts';", "import { sealKey } from './signin/seal.ts';", "", "/** What the app reads from `.env`, as the server's entry reads it here. */", "export { env };", "", storeLines(choices), bucketLines(choices), "", peopleOn[choices.records], "");
|
|
159
|
+
return lines(firstImports(choices, false), dialect !== false && `${dialect}\n`, gitImport(choices), queue && "import type { MergeInput, MergePlan } from '@ref0/git';", githubImport(choices), "import * as Languages from '@ref0/github/languages';", infraImports(choices), "import { xdiff } from '@ref0/xdiff-wasm/node';", "import * as FetchHttpClient from 'effect/http/FetchHttpClient';", "import * as Layer from 'effect/Layer';", "import * as ManagedRuntime from 'effect/ManagedRuntime';", "", "import { hostLayer, peopleOver, repoListOn, runOn, tokenCallsOn } from './context/host.ts';", "import { repoIcons } from './context/repo-icons.ts';", `import { env${partsOf(choices).length > 0 ? ", need" : ""} } from './env.ts';`, "import { admin, approvalPage, hostPolicy, hostRules, type Identify } from './policy.ts';", "import { privateReposOf } from './private-repos.ts';", "import { readyAdapter, readyAuth, starterAuth } from './signin/auth.ts';", "import { avatars } from './signin/avatars.ts';", "import { clientIpHeader } from './signin/client-ip.ts';", "import { appAuth } from './signin/host-session.ts';", "import { orgsOver } from './signin/orgs.ts';", "import { sealKey } from './signin/seal.ts';", "", "/** What the app reads from `.env`, as the server's entry reads it here. */", "export { env };", "", storeLines(choices), bucketLines(choices), "", peopleOn[choices.records], "");
|
|
160
160
|
};
|
|
161
161
|
/** The app's `src/git.ts` on Node: `apps/github`'s own past its head, Node's head and parts in Cloudflare's place. */
|
|
162
162
|
const nodeGit = (choices) => filled(templates.appGitNode, {
|
package/dist/init/git-module.mjs
CHANGED
|
@@ -43,7 +43,7 @@ const gitNames = (choices, admins) => [
|
|
|
43
43
|
choices.serve === "github" && admins && "reject"
|
|
44
44
|
].filter(Predicate.isString);
|
|
45
45
|
/** The drop-in's names, under `--serve github`: Releases only beside a bucket. */
|
|
46
|
-
const githubNames = (choices) => [
|
|
46
|
+
const githubNames = (choices, admins) => [
|
|
47
47
|
"Apps",
|
|
48
48
|
"Deployments",
|
|
49
49
|
"GitHub",
|
|
@@ -53,15 +53,24 @@ const githubNames = (choices) => [
|
|
|
53
53
|
choices.objects === "packs" && "Releases",
|
|
54
54
|
"Search",
|
|
55
55
|
"Streams",
|
|
56
|
-
"Webhooks"
|
|
56
|
+
"Webhooks",
|
|
57
|
+
admins && "scopeFor"
|
|
57
58
|
].filter(Predicate.isString);
|
|
58
59
|
/** An import of `names` from `from`, as the formatter writes it: on one line where it fits. */
|
|
59
60
|
const namedImport = (names, from) => {
|
|
60
61
|
const line = `import { ${names.join(", ")} } from '${from}';`;
|
|
61
62
|
return line.length <= 100 ? line : `import {\n${names.map((name) => ` ${name},`).join("\n")}\n} from '${from}';`;
|
|
62
63
|
};
|
|
64
|
+
/**
|
|
65
|
+
* Git's types: the queue's merge plan's, and with `admins` the error a Worker's policy over its
|
|
66
|
+
* `ADMINS` names, reading the host's tokens.
|
|
67
|
+
*/
|
|
68
|
+
const gitTypes = (choices, admins) => {
|
|
69
|
+
const names = [...admins ? ["GitError"] : [], ...choices.queue === "on" ? ["MergeInput", "MergePlan"] : []];
|
|
70
|
+
return names.length > 0 && `import type { ${names.join(", ")} } from '@ref0/git';`;
|
|
71
|
+
};
|
|
63
72
|
/** Git's imports, from `@ref0/git` to the drop-in, with `admins` for a Worker's `ADMINS`. */
|
|
64
|
-
const gitImports = (choices, admins = false) => lines(namedImport(gitNames(choices, admins), "@ref0/git"), choices
|
|
73
|
+
const gitImports = (choices, admins = false) => lines(namedImport(gitNames(choices, admins), "@ref0/git"), gitTypes(choices, admins), choices.serve === "github" && lines(namedImport(githubNames(choices, admins), "@ref0/github"), "import * as Languages from '@ref0/github/languages';"));
|
|
65
74
|
/**
|
|
66
75
|
* Effect's imports, which the composition is written in, and with `admins` what a Worker's policy
|
|
67
76
|
* over its `ADMINS` reads the host's tokens with.
|
|
@@ -70,7 +79,7 @@ const effectImports = (choices, admins = false) => lines(admins && "import * as
|
|
|
70
79
|
/** Who `ADMIN_TOKEN` signs in as. */
|
|
71
80
|
const adminLines = lines("/** Who `ADMIN_TOKEN` signs in as: it makes repos and tokens, and never pushes. */", "const admin = { id: '_admin' };", "");
|
|
72
81
|
/** How the queue writes an entry onto `main`, when there's a queue. */
|
|
73
|
-
const mergeLines = (choices) => choices.queue === "on" && lines("/** How the queue writes an entry onto `main`: a merge commit, by whoever added it. */", "const merge = ({ entry }: MergeInput): MergePlan => ({", " method: 'merge',", " message: `Merge ${entry.source.replace(/^refs\\/heads\\//, '')}\\n`,", " author: {", " name: entry.actor.id,", " email: `${entry.actor.id}@users.noreply.git`,", " at
|
|
82
|
+
const mergeLines = (choices) => choices.queue === "on" && lines("/** How the queue writes an entry onto `main`: a merge commit, by whoever added it. */", "const merge = ({ entry, at }: MergeInput): MergePlan => ({", " method: 'merge',", " message: `Merge ${entry.source.replace(/^refs\\/heads\\//, '')}\\n`,", " author: {", " name: entry.actor.id,", " email: `${entry.actor.id}@users.noreply.git`,", " at,", " offset: 0,", " },", "});", "");
|
|
74
83
|
/** Who may do what: the admin's and a visitor's limits, as `Policy` decides them. */
|
|
75
84
|
const policyLines = lines("/**", " * Who may do what: a visitor signs in first, and the admin makes repos and tokens but never", " * pushes.", " */", "const policy = Policy.make(({ caller: { actor }, operation }) => {", " if (actor.anonymous === true) return Policy.reject({ message: 'Sign in first' });", "", " if (actor.id === admin.id && operation.kind === 'push') {", " return Policy.reject({", " message: \"The admin token can't push\",", " hint: 'Make a write token for yourself: npx ref0-git tokens create --help',", " });", " }", "", " return Policy.accept();", "});", "");
|
|
76
85
|
/** What one push may carry into `Objects.layerRecords()`, as `@ref0/git` holds it. */
|
|
@@ -108,7 +117,7 @@ const gitFeatures = (choices, parts) => {
|
|
|
108
117
|
*/
|
|
109
118
|
const unstableNextLine = ["// @effect", "diagnostics-next-line unstableApiUsage:off"].join("-");
|
|
110
119
|
/** The drop-in over Git's features, under `--serve github`: each of its features a line too. */
|
|
111
|
-
const githubFeatures = (choices, admins) => lines("/**", " * GitHub's REST, GraphQL, webhooks and Event Streams over Git's, so `gh` and Octokit work, and", " * the drop-in's features, each a line: delete one to turn it off.", " */", "const github = Layer.mergeAll(", " Inbox.layer(),", " Deployments.layer(),", " // Without it, a repo's `language` and `license` answer null.", " Languages.layer(),", " // Repo and user search, and `org:` and `user:` search over an owner's public repos.", " Search.layer(),", " // A repo's and an org's hooks, each delivery a `fetch`, and GitHub Apps, whose hooks they send.", " Layer.provideMerge(Apps.layer(), Webhooks.layer()),", " // GitHub's Event Streams over Git's event feeds.", " Streams.layer(),", " // A repo's import from GitHub, its releases among it.", " Imports.layer(),", ").pipe(", choices.objects === "packs" && " // A release's assets, in the bucket beside the packs.\n Layer.provideMerge(Releases.layer()),", " Layer.provideMerge(GitHub.layer()),", admins ? lines(" // The drop-in narrows nothing past `policy`'s, but its org and account routes ask it alone:", " // it refuses a visitor, the bootstrap
|
|
120
|
+
const githubFeatures = (choices, admins) => lines("/**", " * GitHub's REST, GraphQL, webhooks and Event Streams over Git's, so `gh` and Octokit work, and", " * the drop-in's features, each a line: delete one to turn it off.", " */", "const github = Layer.mergeAll(", " Inbox.layer(),", " Deployments.layer(),", " // Without it, a repo's `language` and `license` answer null.", " Languages.layer(),", " // Repo and user search, and `org:` and `user:` search over an owner's public repos.", " Search.layer(),", " // A repo's and an org's hooks, each delivery a `fetch`, and GitHub Apps, whose hooks they send.", " Layer.provideMerge(Apps.layer(), Webhooks.layer()),", " // GitHub's Event Streams over Git's event feeds.", " Streams.layer(),", " // A repo's import from GitHub, its releases among it.", " Imports.layer(),", ").pipe(", choices.objects === "packs" && " // A release's assets, in the bucket beside the packs.\n Layer.provideMerge(Releases.layer()),", " Layer.provideMerge(GitHub.layer()),", admins ? lines(" // The drop-in narrows nothing past `policy`'s, but its org and account routes ask it alone:", " // it refuses a visitor, the bootstrap, an `admin` token outside ADMINS and work saved for", " // someone who has left, as `policy` does.", " Layer.provideMerge(", " GitHubPolicy.layer(", " GitHubPolicy.make((asker) =>", " Effect.gen(function* () {", " if (asker.actor.anonymous === true || isBootstrap(asker) || adminOutside(asker)) {", " return reject({", " message: 'Only an admin in ADMINS reaches this, with their admin token',", " });", " }", "", " const org = 'org' in asker.operation ? asker.operation.org : undefined;", "", " const needs = scopeFor(asker.operation.kind);", "", " if (yield* savedLeft(asker, asker.repo?.name, org, needs)) {", " return reject({", " message:", " 'Whoever saved this work is out of ADMINS and holds no token that reaches it',", " });", " }", "", " return accept();", " }),", " ),", " ),", " ),") : lines(" // The drop-in's own permissions narrow nothing past `policy`'s.", " Layer.provideMerge(GitHubPolicy.layer(GitHubPolicy.make(() => Effect.succeed(accept())))),"), " Layer.provideMerge(features),", " // A webhook's deliveries and an import's calls to GitHub, each the platform's `fetch`.", ` ${unstableNextLine}`, " Layer.provide(FetchHttpClient.layer),", ");", "");
|
|
112
121
|
/** Git's features, and the drop-in's over them under `--serve github`. */
|
|
113
122
|
const featuresLines = (choices, parts) => lines(gitFeatures(choices, parts), choices.serve === "github" && githubFeatures(choices, parts.admins === true));
|
|
114
123
|
/**
|
package/dist/init/metadata.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/init/metadata.ts
|
|
2
2
|
/** The version `ref0-git`, `create-ref0-git` and Git's packages release at, all at once (Q738). */
|
|
3
|
-
const release = "0.
|
|
3
|
+
const release = "0.12.0";
|
|
4
4
|
/** The packages the app depends on, by their folder in a checkout's `packages/`. */
|
|
5
5
|
const appPackages = [
|
|
6
6
|
"infra",
|
package/dist/init/templates.mjs
CHANGED
|
@@ -19,7 +19,7 @@ var templates_default = {
|
|
|
19
19
|
"slot": "infraImport",
|
|
20
20
|
"text": "import {\n layer,\n layerR2,\n layerR2Signed,\n toJobObject,\n toRecordsObject,\n} from '@ref0/infra/cloudflare';"
|
|
21
21
|
},
|
|
22
|
-
"\nimport xdiff from '@ref0/xdiff-wasm/xdiff.wasm';\nimport { env as bindings } from 'cloudflare:workers';\nimport * as FetchHttpClient from 'effect/http/FetchHttpClient';\nimport * as Layer from 'effect/Layer';\nimport * as ManagedRuntime from 'effect/ManagedRuntime';\n\nimport { hostLayer, peopleOver, repoListOn, runOn, tokenCallsOn } from './context/host.ts';\nimport type { Env } from './env.ts';\nimport { admin, approvalPage, hostPolicy, hostRules, type Identify } from './policy.ts';\nimport { privateReposOf } from './private-repos.ts';\nimport { readyAdapter, readyAuth, starterAuth } from './signin/auth.ts';\nimport { avatars } from './signin/avatars.ts';\nimport { appAuth } from './signin/host-session.ts';\nimport { orgsOver } from './signin/orgs.ts';\nimport { sealKey } from './signin/seal.ts';\n\n// SAFETY: `wrangler.jsonc` ",
|
|
22
|
+
"\nimport xdiff from '@ref0/xdiff-wasm/xdiff.wasm';\nimport { env as bindings } from 'cloudflare:workers';\nimport * as FetchHttpClient from 'effect/http/FetchHttpClient';\nimport * as Layer from 'effect/Layer';\nimport * as ManagedRuntime from 'effect/ManagedRuntime';\n\nimport { hostLayer, peopleOver, repoListOn, runOn, tokenCallsOn } from './context/host.ts';\nimport { repoIcons } from './context/repo-icons.ts';\nimport type { Env } from './env.ts';\nimport { admin, approvalPage, hostPolicy, hostRules, type Identify } from './policy.ts';\nimport { privateReposOf } from './private-repos.ts';\nimport { readyAdapter, readyAuth, starterAuth } from './signin/auth.ts';\nimport { avatars } from './signin/avatars.ts';\nimport { appAuth } from './signin/host-session.ts';\nimport { orgsOver } from './signin/orgs.ts';\nimport { sealKey } from './signin/seal.ts';\n\n// SAFETY: `wrangler.jsonc` ",
|
|
23
23
|
{
|
|
24
24
|
"slot": "safety",
|
|
25
25
|
"text": "binds the objects, the bucket and D1"
|
|
@@ -31,7 +31,7 @@ var templates_default = {
|
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
33
|
"slot": "queueMerge",
|
|
34
|
-
"text": "/**\n * How the queue writes an entry's link onto `main`: a merge commit, by the person who added it, as\n * a pull request's merge button writes one, and titled as GitHub titles it for a pull request's\n * entry, keyed `pr-<number>`.\n */\nconst queueMerge = ({ entry }: MergeInput): MergePlan => {\n const [owner = ''] = entry.repo.split('/');\n const branch = entry.source.replace(/^refs\\/heads\\//, '');\n const pull = /^pr-([1-9]\\d*)$/.exec(entry.key)?.[1];\n const title =\n pull === undefined ? `Merge ${branch}` : `Merge pull request #${pull} from ${owner}/${branch}`;\n const login = entry.subject?.id ?? entry.actor.id;\n const hostname = new URL(env.APP_ORIGIN).hostname;\n\n return {\n method: 'merge',\n message: `${title}\\n`,\n author: { name: login, email: `${login}@users.noreply.${hostname}`, at
|
|
34
|
+
"text": "/**\n * How the queue writes an entry's link onto `main`: a merge commit, by the person who added it, as\n * a pull request's merge button writes one, and titled as GitHub titles it for a pull request's\n * entry, keyed `pr-<number>`.\n */\nconst queueMerge = ({ entry, at }: MergeInput): MergePlan => {\n const [owner = ''] = entry.repo.split('/');\n const branch = entry.source.replace(/^refs\\/heads\\//, '');\n const pull = /^pr-([1-9]\\d*)$/.exec(entry.key)?.[1];\n const title =\n pull === undefined ? `Merge ${branch}` : `Merge pull request #${pull} from ${owner}/${branch}`;\n const login = entry.subject?.id ?? entry.actor.id;\n const hostname = new URL(env.APP_ORIGIN).hostname;\n\n return {\n method: 'merge',\n message: `${title}\\n`,\n author: { name: login, email: `${login}@users.noreply.${hostname}`, at, offset: 0 },\n };\n};\n\n"
|
|
35
35
|
},
|
|
36
36
|
"/** The key sessions and host sessions are sealed under, derived once an isolate from its secret. */\nexport const sessionKey = sealKey(env.SESSION_SECRET);\n\n/**\n * Who owns what, and the drop-in's people and orgs, over Better Auth's tables, which `auth` makes\n * at the first request that reads them.\n */\nexport const directory = orgsOver(async () => readyAdapter(await auth()));\n\n/** People's, orgs' and repos' pictures, in Better Auth's database, as `directory` reads it. */\nexport const pictures = avatars(async () => readyAdapter(await auth()));\n\nexport const policy = hostPolicy(directory, {\n origin: env.APP_ORIGIN,\n avatars: pictures,\n privateRepos: async (prefix, most, host) => privateReposOf(repoListOn(run))(prefix, most, host),\n repoName: async (internalId, signal) =>\n (await runtime.runPromise(RepoRecords.record(internalId), { signal }))?.name,\n});\n\n",
|
|
37
37
|
{
|
|
@@ -48,7 +48,7 @@ var templates_default = {
|
|
|
48
48
|
"slot": "releases",
|
|
49
49
|
"text": " // A release's assets, in the bucket beside the packs.\n Releases.layer(),\n"
|
|
50
50
|
},
|
|
51
|
-
" // `org:` and `user:` search an owner's repos, its private ones by the policy's hook.\n Search.layer({ readableRepos: policy.readableRepos }),\n // Without it, a repo's `language` and `license` answer null.\n Languages.layer(),\n // A repo's and an org's hooks, each delivery a `fetch`, and GitHub Apps, whose hooks they send.\n // @effect-diagnostics-next-line unstableApiUsage:off\n Layer.provideMerge(Apps.layer(), Webhooks.layer().pipe(Layer.provide(FetchHttpClient.layer))),\n // GitHub's Event Streams over Git's event feeds, which a pull request's page follows.\n Streams.layer(),\n).pipe(\n Layer.provideMerge(GitHub.layer()),\n Layer.provideMerge(peopleOver(policy.people)),\n Layer.provideMerge(\n Layer.mergeAll(\n Rest.layer(),\n",
|
|
51
|
+
" // `org:` and `user:` search an owner's repos, its private ones by the policy's hook.\n Search.layer({ readableRepos: policy.readableRepos }),\n // Without it, a repo's `language` and `license` answer null.\n Languages.layer(),\n // A repo's and an org's hooks, each delivery a `fetch`, and GitHub Apps, whose hooks they send.\n // @effect-diagnostics-next-line unstableApiUsage:off\n Layer.provideMerge(Apps.layer(), Webhooks.layer().pipe(Layer.provide(FetchHttpClient.layer))),\n // GitHub's Event Streams over Git's event feeds, which a pull request's page follows.\n Streams.layer(),\n // A deleted repo's icon, removed however the repo was deleted.\n repoIcons(pictures),\n).pipe(\n Layer.provideMerge(GitHub.layer()),\n Layer.provideMerge(peopleOver(policy.people)),\n Layer.provideMerge(\n Layer.mergeAll(\n Rest.layer(),\n",
|
|
52
52
|
{
|
|
53
53
|
"slot": "lfs",
|
|
54
54
|
"text": " // Git LFS, its objects in the bucket beside the packs. An upload through the Worker may use\n // `limits.cpu_ms` from wrangler.jsonc: raise both together.\n Lfs.layer({ cpuMs: 300_000 }),\n"
|
|
@@ -66,11 +66,11 @@ var templates_default = {
|
|
|
66
66
|
appGitNode: [
|
|
67
67
|
{
|
|
68
68
|
"slot": "head",
|
|
69
|
-
"text": "import {\n Git,\n Lfs,\n Merges,\n MergeQueue,\n Objects,\n RepoRecords,\n Rest,\n SignIn,\n Tokens,\n} from '@ref0/git';\nimport type { MergeInput, MergePlan } from '@ref0/git';\nimport {\n Apps,\n Deployments,\n GitHub,\n Inbox,\n Releases,\n Search,\n Streams,\n Webhooks,\n} from '@ref0/github';\nimport * as Languages from '@ref0/github/languages';\nimport {\n layer,\n layerR2,\n layerR2Signed,\n toJobObject,\n toRecordsObject,\n} from '@ref0/infra/cloudflare';\nimport xdiff from '@ref0/xdiff-wasm/xdiff.wasm';\nimport { env as bindings } from 'cloudflare:workers';\nimport * as FetchHttpClient from 'effect/http/FetchHttpClient';\nimport * as Layer from 'effect/Layer';\nimport * as ManagedRuntime from 'effect/ManagedRuntime';\n\nimport { hostLayer, peopleOver, repoListOn, runOn, tokenCallsOn } from './context/host.ts';\nimport type { Env } from './env.ts';\nimport { admin, approvalPage, hostPolicy, hostRules, type Identify } from './policy.ts';\nimport { privateReposOf } from './private-repos.ts';\nimport { readyAdapter, readyAuth, starterAuth } from './signin/auth.ts';\nimport { avatars } from './signin/avatars.ts';\nimport { appAuth } from './signin/host-session.ts';\nimport { orgsOver } from './signin/orgs.ts';\nimport { sealKey } from './signin/seal.ts';\n\n// SAFETY: `wrangler.jsonc` binds the objects, the bucket and D1 and sets `APP_ORIGIN`; the\n// secrets come from `wrangler secret put`, or `.dev.vars` locally.\nexport const env = bindings as Env;\n\nconst {\n R2_ACCOUNT_ID: accountId,\n R2_ACCESS_KEY_ID: accessKeyId,\n R2_SECRET_ACCESS_KEY: secretAccessKey,\n} = env;\n\n// With R2's S3 credentials, the bucket signs parts, and a push's pack past 64 MiB may upload to\n// it in parts, past Workers' 100 MB body.\nconst signed =\n accountId === undefined || accessKeyId === undefined || secretAccessKey === undefined\n ? undefined\n : layerR2Signed(env.PACKS, {\n accountId,\n bucket: env.PACKS_BUCKET,\n accessKeyId,\n secretAccessKey,\n });\n\nconst bucket = signed ?? layerR2(env.PACKS);\n\nconst uploads =\n signed === undefined\n ? Layer.empty\n : Layer.provide(Git.layerUploads({ above: 64 * 1024 * 1024 }), signed);\n\n"
|
|
69
|
+
"text": "import {\n Git,\n Lfs,\n Merges,\n MergeQueue,\n Objects,\n RepoRecords,\n Rest,\n SignIn,\n Tokens,\n} from '@ref0/git';\nimport type { MergeInput, MergePlan } from '@ref0/git';\nimport {\n Apps,\n Deployments,\n GitHub,\n Inbox,\n Releases,\n Search,\n Streams,\n Webhooks,\n} from '@ref0/github';\nimport * as Languages from '@ref0/github/languages';\nimport {\n layer,\n layerR2,\n layerR2Signed,\n toJobObject,\n toRecordsObject,\n} from '@ref0/infra/cloudflare';\nimport xdiff from '@ref0/xdiff-wasm/xdiff.wasm';\nimport { env as bindings } from 'cloudflare:workers';\nimport * as FetchHttpClient from 'effect/http/FetchHttpClient';\nimport * as Layer from 'effect/Layer';\nimport * as ManagedRuntime from 'effect/ManagedRuntime';\n\nimport { hostLayer, peopleOver, repoListOn, runOn, tokenCallsOn } from './context/host.ts';\nimport { repoIcons } from './context/repo-icons.ts';\nimport type { Env } from './env.ts';\nimport { admin, approvalPage, hostPolicy, hostRules, type Identify } from './policy.ts';\nimport { privateReposOf } from './private-repos.ts';\nimport { readyAdapter, readyAuth, starterAuth } from './signin/auth.ts';\nimport { avatars } from './signin/avatars.ts';\nimport { appAuth } from './signin/host-session.ts';\nimport { orgsOver } from './signin/orgs.ts';\nimport { sealKey } from './signin/seal.ts';\n\n// SAFETY: `wrangler.jsonc` binds the objects, the bucket and D1 and sets `APP_ORIGIN`; the\n// secrets come from `wrangler secret put`, or `.dev.vars` locally.\nexport const env = bindings as Env;\n\nconst {\n R2_ACCOUNT_ID: accountId,\n R2_ACCESS_KEY_ID: accessKeyId,\n R2_SECRET_ACCESS_KEY: secretAccessKey,\n} = env;\n\n// With R2's S3 credentials, the bucket signs parts, and a push's pack past 64 MiB may upload to\n// it in parts, past Workers' 100 MB body.\nconst signed =\n accountId === undefined || accessKeyId === undefined || secretAccessKey === undefined\n ? undefined\n : layerR2Signed(env.PACKS, {\n accountId,\n bucket: env.PACKS_BUCKET,\n accessKeyId,\n secretAccessKey,\n });\n\nconst bucket = signed ?? layerR2(env.PACKS);\n\nconst uploads =\n signed === undefined\n ? Layer.empty\n : Layer.provide(Git.layerUploads({ above: 64 * 1024 * 1024 }), signed);\n\n"
|
|
70
70
|
},
|
|
71
71
|
{
|
|
72
72
|
"slot": "queueMerge",
|
|
73
|
-
"text": "/**\n * How the queue writes an entry's link onto `main`: a merge commit, by the person who added it, as\n * a pull request's merge button writes one, and titled as GitHub titles it for a pull request's\n * entry, keyed `pr-<number>`.\n */\nconst queueMerge = ({ entry }: MergeInput): MergePlan => {\n const [owner = ''] = entry.repo.split('/');\n const branch = entry.source.replace(/^refs\\/heads\\//, '');\n const pull = /^pr-([1-9]\\d*)$/.exec(entry.key)?.[1];\n const title =\n pull === undefined ? `Merge ${branch}` : `Merge pull request #${pull} from ${owner}/${branch}`;\n const login = entry.subject?.id ?? entry.actor.id;\n const hostname = new URL(env.APP_ORIGIN).hostname;\n\n return {\n method: 'merge',\n message: `${title}\\n`,\n author: { name: login, email: `${login}@users.noreply.${hostname}`, at
|
|
73
|
+
"text": "/**\n * How the queue writes an entry's link onto `main`: a merge commit, by the person who added it, as\n * a pull request's merge button writes one, and titled as GitHub titles it for a pull request's\n * entry, keyed `pr-<number>`.\n */\nconst queueMerge = ({ entry, at }: MergeInput): MergePlan => {\n const [owner = ''] = entry.repo.split('/');\n const branch = entry.source.replace(/^refs\\/heads\\//, '');\n const pull = /^pr-([1-9]\\d*)$/.exec(entry.key)?.[1];\n const title =\n pull === undefined ? `Merge ${branch}` : `Merge pull request #${pull} from ${owner}/${branch}`;\n const login = entry.subject?.id ?? entry.actor.id;\n const hostname = new URL(env.APP_ORIGIN).hostname;\n\n return {\n method: 'merge',\n message: `${title}\\n`,\n author: { name: login, email: `${login}@users.noreply.${hostname}`, at, offset: 0 },\n };\n};\n\n"
|
|
74
74
|
},
|
|
75
75
|
"/** The key sessions and host sessions are sealed under, derived once an isolate from its secret. */\nexport const sessionKey = sealKey(env.SESSION_SECRET);\n\n/**\n * Who owns what, and the drop-in's people and orgs, over Better Auth's tables, which `auth` makes\n * at the first request that reads them.\n */\nexport const directory = orgsOver(async () => readyAdapter(await auth()));\n\n/** People's, orgs' and repos' pictures, in Better Auth's database, as `directory` reads it. */\nexport const pictures = avatars(async () => readyAdapter(await auth()));\n\nexport const policy = hostPolicy(directory, {\n origin: env.APP_ORIGIN,\n avatars: pictures,\n privateRepos: async (prefix, most, host) => privateReposOf(repoListOn(run))(prefix, most, host),\n repoName: async (internalId, signal) =>\n (await runtime.runPromise(RepoRecords.record(internalId), { signal }))?.name,\n});\n\n",
|
|
76
76
|
{
|
|
@@ -87,7 +87,7 @@ var templates_default = {
|
|
|
87
87
|
"slot": "releases",
|
|
88
88
|
"text": " // A release's assets, in the bucket beside the packs.\n Releases.layer(),\n"
|
|
89
89
|
},
|
|
90
|
-
" // `org:` and `user:` search an owner's repos, its private ones by the policy's hook.\n Search.layer({ readableRepos: policy.readableRepos }),\n // Without it, a repo's `language` and `license` answer null.\n Languages.layer(),\n // A repo's and an org's hooks, each delivery a `fetch`, and GitHub Apps, whose hooks they send.\n // @effect-diagnostics-next-line unstableApiUsage:off\n Layer.provideMerge(Apps.layer(), Webhooks.layer().pipe(Layer.provide(FetchHttpClient.layer))),\n // GitHub's Event Streams over Git's event feeds, which a pull request's page follows.\n Streams.layer(),\n).pipe(\n Layer.provideMerge(GitHub.layer()),\n Layer.provideMerge(peopleOver(policy.people)),\n Layer.provideMerge(\n Layer.mergeAll(\n Rest.layer(),\n",
|
|
90
|
+
" // `org:` and `user:` search an owner's repos, its private ones by the policy's hook.\n Search.layer({ readableRepos: policy.readableRepos }),\n // Without it, a repo's `language` and `license` answer null.\n Languages.layer(),\n // A repo's and an org's hooks, each delivery a `fetch`, and GitHub Apps, whose hooks they send.\n // @effect-diagnostics-next-line unstableApiUsage:off\n Layer.provideMerge(Apps.layer(), Webhooks.layer().pipe(Layer.provide(FetchHttpClient.layer))),\n // GitHub's Event Streams over Git's event feeds, which a pull request's page follows.\n Streams.layer(),\n // A deleted repo's icon, removed however the repo was deleted.\n repoIcons(pictures),\n).pipe(\n Layer.provideMerge(GitHub.layer()),\n Layer.provideMerge(peopleOver(policy.people)),\n Layer.provideMerge(\n Layer.mergeAll(\n Rest.layer(),\n",
|
|
91
91
|
{
|
|
92
92
|
"slot": "lfs",
|
|
93
93
|
"text": " // Git LFS, its objects in the bucket beside the packs. An upload through the Worker may use\n // `limits.cpu_ms` from wrangler.jsonc: raise both together.\n Lfs.layer({ cpuMs: 300_000 }),\n"
|
|
@@ -191,7 +191,7 @@ var templates_default = {
|
|
|
191
191
|
},
|
|
192
192
|
{
|
|
193
193
|
"slot": "gitImports",
|
|
194
|
-
"text": "import {\n Auth,\n Git,\n Lfs,\n MergeQueue,\n Merges,\n Objects,\n Policy,\n Rest,\n Tokens,\n maxActorIdLength,\n} from '@ref0/git';\nimport type { MergeInput, MergePlan } from '@ref0/git';\n"
|
|
194
|
+
"text": "import {\n Auth,\n Git,\n Lfs,\n MergeQueue,\n Merges,\n Objects,\n Policy,\n Rest,\n Tokens,\n maxActorIdLength,\n} from '@ref0/git';\nimport type { GitError, MergeInput, MergePlan } from '@ref0/git';\n"
|
|
195
195
|
},
|
|
196
196
|
{
|
|
197
197
|
"slot": "infraImport",
|
|
@@ -219,9 +219,9 @@ var templates_default = {
|
|
|
219
219
|
},
|
|
220
220
|
{
|
|
221
221
|
"slot": "merge",
|
|
222
|
-
"text": "/** How the queue writes an entry onto `main`: a merge commit, by whoever added it. */\nconst merge = ({ entry }: MergeInput): MergePlan => ({\n method: 'merge',\n message: `Merge ${entry.source.replace(/^refs\\/heads\\//, '')}\\n`,\n author: {\n name: entry.actor.id,\n email: `${entry.actor.id}@users.noreply.git`,\n at
|
|
222
|
+
"text": "/** How the queue writes an entry onto `main`: a merge commit, by whoever added it. */\nconst merge = ({ entry, at }: MergeInput): MergePlan => ({\n method: 'merge',\n message: `Merge ${entry.source.replace(/^refs\\/heads\\//, '')}\\n`,\n author: {\n name: entry.actor.id,\n email: `${entry.actor.id}@users.noreply.git`,\n at,\n offset: 0,\n },\n});\n\n"
|
|
223
223
|
},
|
|
224
|
-
"/** How much of the whole host's tokens the bootstrap reads to find an admin's: pages of 200. */\nconst bootstrapReads = { pages: 10, limit: 200 };\n\n/**\n * Whether an admin in `admins` holds an active `admin` token, which retires the bootstrap. It
|
|
224
|
+
"/** How much of the whole host's tokens the bootstrap reads to find an admin's: pages of 200. */\nconst bootstrapReads = { pages: 10, limit: 200 };\n\n/**\n * Whether an admin in `admins` holds an active `admin` token over the whole host, as the\n * bootstrap mints one, which retires the bootstrap. It reads the tokens at prefix `''` from\n * `runtime`, which `policy` is part of. Past `bootstrapReads`, or with no `Tokens` to read, it\n * can't tell, and answers yes.\n */\nconst adminSignedIn = Effect.gen(function* () {\n const tokens = Context.getOption(yield* runtime.contextEffect, Tokens.Tokens);\n if (Option.isNone(tokens)) return true;\n\n let after: string | undefined;\n\n for (let read = 0; read < bootstrapReads.pages; read += 1) {\n const page =\n after === undefined\n ? { limit: bootstrapReads.limit }\n : { limit: bootstrapReads.limit, after };\n const listed = yield* tokens.value.list({ prefix: '' }, { page });\n const held = listed.items.some(\n (token) => token.scope === 'admin' && admins.has(token.subject.id),\n );\n if (held) return true;\n\n if (listed.next === undefined) return false;\n\n after = listed.next;\n }\n\n return true;\n});\n\n/**\n * How much of the tokens one ask of a saver reads: a page of 200 at each coverage, and at most 9\n * coverages, as a repo's name of 8 segments has. A coverage past a page can't be told, and is\n * refused.\n */\nconst saverReads = { targets: 9, limit: 200 };\n\n/**\n * Each token scope, from the least it reaches. A saver's token counts only where its scope meets\n * the operation's, as wiki `ff791a73f` rules: \"The token's scope must also meet what the operation\n * needs\".\n */\nconst scopeRank = { read: 0, report: 1, write: 2, admin: 3 };\n\n/** Git's kinds a `read` token reaches, as Git's own ceilings read them. */\nconst gitReads = new Set(['fetch', 'read', 'work.list', 'repo.list', 'refs.private', 'me']);\n\n/** Git's kinds a `write` token reaches besides a `report` one's, as Git's own ceilings read them. */\nconst gitWrites = new Set([\n 'push',\n 'files.allow',\n 'protect.bypass',\n 'lock.bypass',\n 'object.create',\n 'queue.add',\n 'queue.remove',\n]);\n\n/**\n * The scope a token needs for one of Git's operation kinds: `read` to fetch, read and list,\n * `report` to report a queue's checks, `write` to push, create objects and add to a queue, and\n * `admin` for every kind no lower scope reaches, such as a repo's creation or a token's, which a\n * saver's token never meets, so only `ADMINS` holds them. That's what saving the work takes, as\n * wiki `ff791a73f` says. `init`'s `GitHubPolicy` takes the drop-in's from `scopeFor`.\n */\nconst scopeNeeded = (kind: string): keyof typeof scopeRank =>\n gitReads.has(kind)\n ? 'read'\n : kind === 'queue.report'\n ? 'report'\n : gitWrites.has(kind)\n ? 'write'\n : 'admin';\n\n/**\n * Where a token that covers what an operation names may be, as a token's prefix is `''` or ends in\n * `/`: for a repo, `''` and each folder of its name, then the repo's own; for an org's operation\n * with no repo, `''` and the org's prefix; for any other, `''`. An org hook's saver is asked with\n * the repo of the event they're asked about, so its coverages are that repo's.\n */\nconst coveringTargets = (\n repo: string | undefined,\n org: string | undefined,\n): Tokens.TokenTarget[] => {\n if (repo !== undefined) {\n const folders = repo.split('/').slice(0, -1);\n const prefixes = folders.map((_, at) => `${folders.slice(0, at + 1).join('/')}/`);\n\n return [{ prefix: '' }, ...prefixes.map((prefix) => ({ prefix })), repo];\n }\n\n return org === undefined ? [{ prefix: '' }] : [{ prefix: '' }, { prefix: `${org}/` }];\n};\n\n/**\n * Each saved caller's answers, by where they were asked and the scope it needed, for as long as\n * Git holds that caller: a fan-out try asks a saver once and then calls as them, and each send\n * asks them again. A `read` answer never serves a `write` ask.\n */\nconst saverAnswers = new WeakMap<Policy.Input['caller'], Map<string, boolean>>();\n\n/**\n * Whether `caller` is work saved with no token, such as a hook's saver, for someone who has left:\n * out of `admins`, and holding no active token below `admin` whose scope meets `needs` and that\n * covers `repo`, or `org` for an org's operation with no repo, as `coveringTargets` says. A\n * coverage past a page, more coverages than `saverReads`, or no `Tokens` to read, and it can't\n * tell: it answers yes, and the work is refused.\n */\nconst savedLeft = (\n caller: Policy.Input['caller'],\n repo: string | undefined,\n org: string | undefined,\n needs: keyof typeof scopeRank,\n): Effect.Effect<boolean, GitError> =>\n Effect.gen(function* () {\n const { actor, token, grant, at } = caller;\n const saved = at === 'queued' && token === undefined && grant === undefined;\n if (!saved || actor.anonymous === true || admins.has(actor.id)) return false;\n\n const where = `${repo === undefined ? `org ${org ?? ''}` : `repo ${repo}`} ${needs}`;\n const answers = saverAnswers.get(caller) ?? new Map<string, boolean>();\n saverAnswers.set(caller, answers);\n const known = answers.get(where);\n if (known !== undefined) return known;\n\n const targets = coveringTargets(repo, org);\n const tokens = Context.getOption(yield* runtime.contextEffect, Tokens.Tokens);\n let held = false;\n\n if (Option.isSome(tokens) && targets.length <= saverReads.targets) {\n for (const target of targets) {\n const page = { limit: saverReads.limit };\n const listed = yield* tokens.value.list(target, { page });\n held = listed.items.some(\n (one) =>\n one.scope !== 'admin' &&\n scopeRank[one.scope] >= scopeRank[needs] &&\n one.subject.id === actor.id,\n );\n\n if (held || listed.next !== undefined) break;\n }\n }\n\n answers.set(where, !held);\n\n return !held;\n });\n\n/**\n * What the bootstrap may do: say who it is, as `ref0-git login` asks, and mint an `admin` token for\n * a login in `admins`, until one of them holds one. Then it's retired, and `ADMIN_TOKEN` is deleted.\n */\nconst bootstrapped = (operation: Policy.Input['operation']) =>\n Effect.gen(function* () {\n if (admins.size === 0) {\n return yield* Policy.reject({\n message: 'ADMINS names no one',\n hint: \"Add your login to ADMINS in wrangler.jsonc's vars, then deploy\",\n });\n }\n\n if (yield* adminSignedIn) {\n return yield* Policy.reject({\n message: 'The bootstrap secret is retired: an admin in ADMINS signs in. Delete ADMIN_TOKEN',\n hint: 'wrangler secret delete ADMIN_TOKEN',\n });\n }\n\n if (operation.kind === 'me') return yield* Policy.accept();\n\n const minted =\n operation.kind === 'token.create' &&\n operation.scope === 'admin' &&\n 'prefix' in operation &&\n operation.prefix === '' &&\n admins.has(operation.subject.id);\n if (minted) return yield* Policy.accept();\n\n return yield* Policy.reject({\n message: \"The bootstrap secret mints only an admin's first token\",\n hint: \"npx ref0-git tokens create --prefix '' --scope admin --subject <a login in ADMINS> --show-token\",\n });\n });\n\n/** Whether `caller` is the bootstrap: `ADMIN_TOKEN` signed in, not a token. */\nconst isBootstrap = ({ actor, token }: Policy.Input['caller']) =>\n actor.anonymous !== true && actor.id === bootstrap.id && token === undefined;\n\n/** Whether `caller` holds an `admin` token that isn't an admin's in `admins`. */\nconst adminOutside = ({ actor, subject, token }: Policy.Input['caller']) =>\n token?.scope === 'admin' &&\n !admins.has(subject?.id ?? (actor.anonymous === true ? '' : actor.id));\n\n/**\n * Who may do what: a visitor signs in first, the bootstrap only mints an admin's first token, an\n * `admin` token is only ever an admin's, and work saved for someone who has left does nothing.\n * Every other caller does what its token reaches.\n */\nconst policy = Policy.make(({ caller, operation, repo }) =>\n Effect.gen(function* () {\n if (caller.actor.anonymous === true) return yield* Policy.reject({ message: 'Sign in first' });\n\n if (isBootstrap(caller)) return yield* bootstrapped(operation);\n\n if (adminOutside(caller)) {\n return yield* Policy.reject({ message: 'An admin token works only for an admin in ADMINS' });\n }\n\n if (yield* savedLeft(caller, repo?.name, undefined, scopeNeeded(operation.kind))) {\n return yield* Policy.reject({\n message: 'Whoever saved this work is out of ADMINS and holds no token that reaches it',\n });\n }\n\n const mintsAdmin = operation.kind === 'token.create' && operation.scope === 'admin';\n\n if (mintsAdmin && !admins.has(operation.subject.id)) {\n return yield* Policy.reject({ message: 'An admin token is only for an admin in ADMINS' });\n }\n\n return yield* Policy.accept();\n }),\n);\n\n",
|
|
225
225
|
{
|
|
226
226
|
"slot": "features",
|
|
227
227
|
"text": "/** Git's features, each a line: delete one to turn it off. */\nconst features = Layer.mergeAll(\n // Git's REST, beside Git's protocol and sign-in.\n Rest.layer(),\n // Git LFS, its objects in the bucket beside the packs. An upload through the Worker may use\n // `limits.cpu_ms` from wrangler.jsonc: raise both together.\n Lfs.layer({ cpuMs: 300_000 }),\n // A push past 64 MiB may upload its pack, once the bucket signs parts.\n signed === undefined\n ? Layer.empty\n : Layer.provide(Git.layerUploads({ above: 64 * 1024 * 1024 }), signed),\n MergeQueue.layer({ target: 'refs/heads/main', keys: 'reusable', merge }),\n).pipe(Layer.provideMerge(Tokens.layer()), Layer.provideMerge(Merges.layer({ xdiff })));\n\n"
|
package/dist/init/versions.mjs
CHANGED
|
@@ -56,5 +56,5 @@ const initPacked = (name, at) => {
|
|
|
56
56
|
* the release, or the tarball `--from-checkout` names for that package. One it wrote moves to this
|
|
57
57
|
* run's spec; any other is the person's, a tarball of their own in `vendor/` too, and stays.
|
|
58
58
|
*/
|
|
59
|
-
const initWrote = (name, spec) => spec === "0.
|
|
59
|
+
const initWrote = (name, spec) => spec === "0.12.0" || spec !== void 0 && packedPath(name).test(spec);
|
|
60
60
|
export { catalog, contentNamed, frameworkPackages, initPacked, initWrote, nodeAppPackages, nodePackages, peerPackages, published, release, specOf, storePackages, unpacked, vercelPackages };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ref0-git",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "ref0-git, the CLI for a Git host built on @ref0/git, and git-remote-ref0, its remote helper",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@effect/platform-node-shared": "4.1.7",
|
|
27
|
-
"@ref0/git": "0.
|
|
28
|
-
"@ref0/infra": "0.
|
|
27
|
+
"@ref0/git": "0.12.0",
|
|
28
|
+
"@ref0/infra": "0.12.0",
|
|
29
29
|
"diff": "9.0.0",
|
|
30
30
|
"effect": "^4.1.7"
|
|
31
31
|
},
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"@effect/vitest": "4.1.7",
|
|
35
35
|
"@libsql/client": "0.18.0",
|
|
36
36
|
"@libsql/kysely-libsql": "0.4.1",
|
|
37
|
-
"@ref0/github": "0.
|
|
38
|
-
"@ref0/xdiff-wasm": "0.
|
|
37
|
+
"@ref0/github": "0.12.0",
|
|
38
|
+
"@ref0/xdiff-wasm": "0.12.0",
|
|
39
39
|
"@tanstack/react-start": "1.169.7",
|
|
40
40
|
"@types/node": "24.19.4",
|
|
41
41
|
"@types/pg": "8.23.1",
|