ref0-git 0.11.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/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.
|
|
@@ -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
|
@@ -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",
|
|
@@ -221,7 +221,7 @@ var templates_default = {
|
|
|
221
221
|
"slot": "merge",
|
|
222
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",
|