ref0-git 0.8.0 → 0.10.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.
@@ -5968,6 +5968,10 @@ export interface operations {
5968
5968
  query: {
5969
5969
  ref: string;
5970
5970
  path?: string;
5971
+ authors?: string[];
5972
+ committers?: string[];
5973
+ since?: string | ("Infinity" | "-Infinity" | "NaN");
5974
+ until?: string | ("Infinity" | "-Infinity" | "NaN");
5971
5975
  after?: string;
5972
5976
  limit?: string;
5973
5977
  objects?: string;
@@ -1,7 +1,7 @@
1
1
  import { choices, movesOf, platformOf, recovered, saysOf, settle, withDefaults } from "../init/choices.mjs";
2
2
  import { appOutput, checkedManifest, copied, entered } from "../init/app.mjs";
3
3
  import { nodeAppOutput, startOrigin } from "../init/node-app.mjs";
4
- import { configParts, gitClasses, gitSecrets } from "../init/cloudflare.mjs";
4
+ import { adminsVar, configParts, gitClasses, gitSecrets } from "../init/cloudflare.mjs";
5
5
  import { platforms } from "../init/template.mjs";
6
6
  import { pnpmManual, withPnpmOverrides, wroteOf } from "../init/files.mjs";
7
7
  import { keepsData, mainOrigin, nodeNeeds, routed, routedFindings } from "../init/node.mjs";
@@ -1486,8 +1486,29 @@ const setupCommands = [init, Command.make("doctor", {
1486
1486
  const served = platformOf(project.detected) === "node" && starter === void 0 && !routed(project.framework) && project.layout.kind !== "mount" ? project.held?.app === "ref0" ? startOrigin : mainOrigin : void 0;
1487
1487
  const signIn = served === void 0 ? "sign in to it with its admin token, <host> being where it's served" : "sign in to it with its admin token";
1488
1488
  const tokenFiles = secretFilesOf(withDefaults(project.held ?? {}, project.project));
1489
- const next = {
1490
- says: platformOf(project.detected) === "node" ? starter !== void 0 ? `Build it with \`${project.packageManager.value} run build\`, start it with ${starter.start(project.packageManager.value)}, ${signIn}, then push a scratch repo through it` : routed(project.framework) ? `Build it with \`${project.packageManager.value} run build\`, start it with ${routedStart(project.framework, project.packageManager.value)}, ${signIn}, then push a scratch repo through it` : project.layout.kind === "mount" ? `Start your server with \`node --env-file-if-exists=.env\`, which loads what src/git.ts reads, ${signIn}, then push a scratch repo through it` : `Start it with \`${project.packageManager.value} start\`, ${project.held?.app === "ref0" ? "sign up on it, setting APP_ORIGIN to where it's served first" : signIn}, then push a scratch repo through it` : vercel ? `Check Production has each variable with \`vercel env ls production\`, deploy it with Vercel's CLI or a Git import, ${signIn}, then push a scratch repo through it` : `${project.held?.app === "ref0" ? "Set APP_ORIGIN to where it's served, make AUTH_DB and its tables with `wrangler d1`, deploy" : "Deploy"} it with \`wrangler deploy\`, set ${secretsOf(withDefaults(project.held ?? {}, project.project)).join(" and ")} with \`wrangler secret put\`, ${signIn}, then push a scratch repo through it`,
1489
+ const bootstrapped = platformOf(project.detected) !== "node" && !vercel && project.held?.app !== "ref0";
1490
+ const next = bootstrapped ? {
1491
+ says: `Set ${adminsVar} in the Worker's vars to your login, deploy it with \`wrangler deploy\`, set ${secretsOf(withDefaults(project.held ?? {}, project.project)).join(" and ")} with \`wrangler secret put\`, sign in to it with that bootstrap secret, <host> being where it's served, and mint your admin token. Then sign in with yours, run \`doctor --verify\`, and delete ${gitSecrets.join(" and ")}`,
1492
+ run: [[
1493
+ "login",
1494
+ `<host>${base}`,
1495
+ "--with-token"
1496
+ ], [
1497
+ "tokens",
1498
+ "create",
1499
+ "--host",
1500
+ `<host>${base}`,
1501
+ "--prefix",
1502
+ "",
1503
+ "--scope",
1504
+ "admin",
1505
+ "--subject",
1506
+ "<your login>",
1507
+ "--show-token"
1508
+ ]],
1509
+ stdinFrom: "ADMIN_TOKEN"
1510
+ } : {
1511
+ says: platformOf(project.detected) === "node" ? starter !== void 0 ? `Build it with \`${project.packageManager.value} run build\`, start it with ${starter.start(project.packageManager.value)}, ${signIn}, then push a scratch repo through it` : routed(project.framework) ? `Build it with \`${project.packageManager.value} run build\`, start it with ${routedStart(project.framework, project.packageManager.value)}, ${signIn}, then push a scratch repo through it` : project.layout.kind === "mount" ? `Start your server with \`node --env-file-if-exists=.env\`, which loads what src/git.ts reads, ${signIn}, then push a scratch repo through it` : `Start it with \`${project.packageManager.value} start\`, ${project.held?.app === "ref0" ? "sign up on it, setting APP_ORIGIN to where it's served first" : signIn}, then push a scratch repo through it` : vercel ? `Check Production has each variable with \`vercel env ls production\`, deploy it with Vercel's CLI or a Git import, ${signIn}, then push a scratch repo through it` : `Set APP_ORIGIN to where it's served, make AUTH_DB and its tables with \`wrangler d1\`, deploy it with \`wrangler deploy\`, set ${secretsOf(withDefaults(project.held ?? {}, project.project)).join(" and ")} with \`wrangler secret put\`, ${signIn}, then push a scratch repo through it`,
1491
1512
  run: [[
1492
1513
  "login",
1493
1514
  `${served ?? "<host>"}${base}`,
@@ -1502,7 +1523,7 @@ const setupCommands = [init, Command.make("doctor", {
1502
1523
  });
1503
1524
  yield* receipt({
1504
1525
  done: "Ready to deploy",
1505
- fields: [["Admin token", `ADMIN_TOKEN, in ${tokenFiles.join(" or ")} locally, or the host's secret`]],
1526
+ fields: [bootstrapped ? ["Bootstrap", `ADMIN_TOKEN, in ${tokenFiles.join(" or ")} locally, or the host's secret, until an admin in ${adminsVar} signs in`] : ["Admin token", `ADMIN_TOKEN, in ${tokenFiles.join(" or ")} locally, or the host's secret`]],
1506
1527
  next
1507
1528
  });
1508
1529
  })).pipe(Command.withDescription("Check a folder's Git setup, or with --verify a host end to end (experimental)"))];
@@ -13,8 +13,10 @@ import * as Redacted from "effect/Redacted";
13
13
  */
14
14
  /** The files that hold secrets on Cloudflare: `.gitignore` ends with them, and `init` refuses one Git tracks. */
15
15
  const secretFiles = [".dev.vars"];
16
- /** The secrets Git's Worker takes: the admin's, which signs in to make repos and tokens. */
16
+ /** The secrets Git's Worker takes: the bootstrap's, which mints the first admin's token. */
17
17
  const gitSecrets = ["ADMIN_TOKEN"];
18
+ /** The var that names the Worker's admins, logins between commas: the person's to fill in. */
19
+ const adminsVar = "ADMINS";
18
20
  /** What an entry that falls through to its host's own `fetch` imports, to route Git's URLs first. */
19
21
  const fallThroughImports = lines("import { Git } from '@ref0/git';", "import * as Option from 'effect/Option';");
20
22
  /** Git's answer to `request` on the module's runtime, `undefined` for a URL no route of Git's owns. */
@@ -38,20 +40,22 @@ const gitModule = (choices, envFile, cpu) => {
38
40
  const packs = choices.objects === "packs";
39
41
  return filled(templates.workerGit, {
40
42
  header: `${header(choices, "Cloudflare")}\n`,
41
- gitImports: `${gitImports(choices)}\n`,
43
+ gitImports: `${gitImports(choices, true)}\n`,
42
44
  infraImport: unless(packs, looseInfraImport),
43
- effectImports: `${effectImports(choices)}\n`,
45
+ effectImports: `${effectImports(choices, true)}\n`,
44
46
  envFile: `'${envFile}'`,
45
47
  safety: unless(packs, "binds the objects"),
46
48
  bucket: unless(packs, looseAdapter),
47
49
  merge: unless(choices.queue === "on", ""),
48
50
  features: `${featuresLines(choices, {
51
+ admins: true,
49
52
  cpu,
50
53
  merges: "{ xdiff }",
51
54
  uploads: packs && uploads
52
55
  })}\n`,
53
56
  runtime: `${runtimeLines(choices, {
54
57
  token: "env.ADMIN_TOKEN",
58
+ bootstrap: true,
55
59
  adapter: "adapter"
56
60
  })}\n`
57
61
  });
@@ -102,7 +106,7 @@ const wranglerConfig = (choices, name) => {
102
106
  name: ` "name": ${jsonString(name)},`,
103
107
  limits: limitsLine,
104
108
  bucket: bucketLine(choices, name),
105
- vars: packs ? ` "vars": { "PACKS_BUCKET": "${bucketName(name)}" },\n` : ""
109
+ vars: packs ? ` "vars": { "PACKS_BUCKET": "${bucketName(name)}", "${adminsVar}": "" },\n` : ` "vars": { "${adminsVar}": "" },\n`
106
110
  });
107
111
  };
108
112
  /** The classes a config's migrations make, and how many migrations it has. */
@@ -186,6 +190,7 @@ const mergeWrangler = (text, choices, name, main) => {
186
190
  bucket_name: packsBucket
187
191
  }]), (from) => withEntries(from, ["vars"], { PACKS_BUCKET: packsBucket }));
188
192
  }
193
+ steps.push((from) => withEntries(from, ["vars"], { [adminsVar]: "" }));
189
194
  if (main !== void 0) steps.push((from) => withValue(from, ["main"], main));
190
195
  return steps.reduce((from, step) => step(from), text);
191
196
  };
@@ -241,6 +246,7 @@ const alchemyLines = (choices, _name) => [
241
246
  ...abortUploads,
242
247
  " }),"
243
248
  ] : [],
249
+ ` ${adminsVar}: "",`,
244
250
  " ADMIN_TOKEN: Config.Redacted(\"ADMIN_TOKEN\"),"
245
251
  ];
246
252
  /** The lines a `wrangler.toml` needs, since `init` writes no TOML. */
@@ -255,8 +261,9 @@ const tomlLines = (choices, name) => [
255
261
  "binding = \"PACKS\"",
256
262
  `bucket_name = "${bucketName(name)}"`,
257
263
  "[vars]",
258
- `PACKS_BUCKET = "${bucketName(name)}"`
259
- ] : [],
264
+ `PACKS_BUCKET = "${bucketName(name)}"`,
265
+ `${adminsVar} = ""`
266
+ ] : ["[vars]", `${adminsVar} = ""`],
260
267
  "[[migrations]]",
261
268
  "tag = \"git-v1\"",
262
269
  "new_sqlite_classes = [\"Records\", \"Jobs\"]"
@@ -361,9 +368,9 @@ const cloudflareOutput = (choices, project, secret, vendor) => {
361
368
  lines: entryLines(choices)
362
369
  }] : []],
363
370
  packages: gitPackages(choices),
364
- needs: [],
371
+ needs: [adminsVar],
365
372
  secret: "ADMIN_TOKEN, made for wrangler dev, in .dev.vars",
366
373
  next: "Check it, then deploy it"
367
374
  };
368
375
  };
369
- export { bucketLine, bucketName, cloudflareOutput, configCpu, configParts, devVars, gitClasses, gitModule, gitSecrets, limitsLine, looseAdapter, looseInfraImport, mergePackage, mergeWrangler, secretFiles };
376
+ export { adminsVar, bucketLine, bucketName, cloudflareOutput, configCpu, configParts, devVars, gitClasses, gitModule, gitSecrets, limitsLine, looseAdapter, looseInfraImport, mergePackage, mergeWrangler, secretFiles };
@@ -24,8 +24,11 @@ const gitDependencies = (choices, vendor) => [...gitPackages(choices).map((each)
24
24
  const repoHint = lines("// Nothing here makes a repo over HTTP: make one from code, as", "// `runtime.runPromise(Repos.create({ name: 'acme/app' }))`.");
25
25
  /** `src/git.ts`'s first lines: what it serves, on `on`, and whose file it is. */
26
26
  const header = (choices, on) => lines(`// Git on ${on}, ${served[choices.serve]}${choices.queue === "on" ? ", with a merge queue on `main`" : ""}. Written by`, "// `ref0-git init`, and yours to change: `init` rewrites it only while it reads as written, and", "// `ref0-git doctor` checks it.", choices.serve === "git" && repoHint);
27
- /** The `@ref0/git` names the composition uses, as chosen. */
28
- const gitNames = (choices) => [
27
+ /**
28
+ * The `@ref0/git` names the composition uses, as chosen, and with `admins` the bound on a login
29
+ * that a Worker checks its `ADMINS` against.
30
+ */
31
+ const gitNames = (choices, admins) => [
29
32
  choices.serve === "github" && "accept",
30
33
  "Auth",
31
34
  "Git",
@@ -35,7 +38,9 @@ const gitNames = (choices) => [
35
38
  "Objects",
36
39
  "Policy",
37
40
  choices.serve !== "git" && "Rest",
38
- "Tokens"
41
+ "Tokens",
42
+ admins && "maxActorIdLength",
43
+ choices.serve === "github" && admins && "reject"
39
44
  ].filter(Predicate.isString);
40
45
  /** The drop-in's names, under `--serve github`: Releases only beside a bucket. */
41
46
  const githubNames = (choices) => [
@@ -45,22 +50,23 @@ const githubNames = (choices) => [
45
50
  "GitHubPolicy",
46
51
  "Imports",
47
52
  "Inbox",
48
- "People",
49
53
  choices.objects === "packs" && "Releases",
50
54
  "Search",
51
55
  "Streams",
52
- "Webhooks",
53
- "defaultPeople"
56
+ "Webhooks"
54
57
  ].filter(Predicate.isString);
55
58
  /** An import of `names` from `from`, as the formatter writes it: on one line where it fits. */
56
59
  const namedImport = (names, from) => {
57
60
  const line = `import { ${names.join(", ")} } from '${from}';`;
58
61
  return line.length <= 100 ? line : `import {\n${names.map((name) => ` ${name},`).join("\n")}\n} from '${from}';`;
59
62
  };
60
- /** Git's imports, from `@ref0/git` to the drop-in. */
61
- const gitImports = (choices) => lines(namedImport(gitNames(choices), "@ref0/git"), choices.queue === "on" && "import type { MergeInput, MergePlan } from '@ref0/git';", choices.serve === "github" && lines("import { JoinedCalls } from '@ref0/git/extend';", namedImport(githubNames(choices), "@ref0/github"), "import * as Languages from '@ref0/github/languages';"));
62
- /** Effect's imports, which the composition is written in. */
63
- const effectImports = (choices) => lines(choices.serve === "github" && lines("import * as Effect from 'effect/Effect';", "import * as FetchHttpClient from 'effect/http/FetchHttpClient';"), "import * as Layer from 'effect/Layer';", "import * as ManagedRuntime from 'effect/ManagedRuntime';", "import * as Redacted from 'effect/Redacted';");
63
+ /** 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.queue === "on" && "import type { MergeInput, MergePlan } from '@ref0/git';", choices.serve === "github" && lines(namedImport(githubNames(choices), "@ref0/github"), "import * as Languages from '@ref0/github/languages';"));
65
+ /**
66
+ * Effect's imports, which the composition is written in, and with `admins` what a Worker's policy
67
+ * over its `ADMINS` reads the host's tokens with.
68
+ */
69
+ const effectImports = (choices, admins = false) => lines(admins && "import * as Context from 'effect/Context';", (admins || choices.serve === "github") && "import * as Effect from 'effect/Effect';", choices.serve === "github" && "import * as FetchHttpClient from 'effect/http/FetchHttpClient';", "import * as Layer from 'effect/Layer';", "import * as ManagedRuntime from 'effect/ManagedRuntime';", admins && "import * as Option from 'effect/Option';", "import * as Redacted from 'effect/Redacted';");
64
70
  /** Who `ADMIN_TOKEN` signs in as. */
65
71
  const adminLines = lines("/** Who `ADMIN_TOKEN` signs in as: it makes repos and tokens, and never pushes. */", "const admin = { id: '_admin' };", "");
66
72
  /** How the queue writes an entry onto `main`, when there's a queue. */
@@ -102,9 +108,9 @@ const gitFeatures = (choices, parts) => {
102
108
  */
103
109
  const unstableNextLine = ["// @effect", "diagnostics-next-line unstableApiUsage:off"].join("-");
104
110
  /** The drop-in over Git's features, under `--serve github`: each of its features a line too. */
105
- const githubFeatures = (choices) => 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()),", " // The drop-in's own permissions narrow nothing past `policy`'s.", " Layer.provideMerge(GitHubPolicy.layer(GitHubPolicy.make(() => Effect.succeed(accept())))),", " // Who's who, by login, from Git's own records.", " Layer.provideMerge(", " People.layer(", " Effect.map(Effect.service(JoinedCalls), (joined) =>", " defaultPeople({ git: joined.effectHostCalls }),", " ),", " ),", " ),", " Layer.provideMerge(features),", " // A webhook's deliveries and an import's calls to GitHub, each the platform's `fetch`.", ` ${unstableNextLine}`, " Layer.provide(FetchHttpClient.layer),", ");", "");
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 and an `admin` token outside ADMINS, as `policy` does.", " Layer.provideMerge(", " GitHubPolicy.layer(", " GitHubPolicy.make((asker) =>", " Effect.succeed(", " asker.actor.anonymous === true || isBootstrap(asker) || adminOutside(asker)", " ? reject({ message: 'Only an admin in ADMINS reaches this, with their admin token' })", " : 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),", ");", "");
106
112
  /** Git's features, and the drop-in's over them under `--serve github`. */
107
- const featuresLines = (choices, parts) => lines(gitFeatures(choices, parts), choices.serve === "github" && githubFeatures(choices));
113
+ const featuresLines = (choices, parts) => lines(gitFeatures(choices, parts), choices.serve === "github" && githubFeatures(choices, parts.admins === true));
108
114
  /**
109
115
  * `Git.layer`'s options: Git's URLs under the base path, when there's one, and the platform's
110
116
  * `maxDuration`, when it sets one.
@@ -117,5 +123,5 @@ const gitOptions = (choices, maxDuration) => {
117
123
  * The admin's sign-in, then `export const runtime`: the whole host, Git with its features over the
118
124
  * adapter, one runtime that every entry, object and job runner takes.
119
125
  */
120
- const runtimeLines = (choices, parts) => lines("/** The admin's sign-in: `ADMIN_TOKEN`, as a Bearer token or as Basic's password. */", `const auth = Auth.bearer({ token: Redacted.make(${parts.token}), actor: admin });`, "", "/**", " * The whole host, one runtime that every request and job shares: Git and its features over the", " * adapter, deciding with `policy`, and the admin signing in with `auth`.", parts.jobs !== void 0 && ` * ${parts.jobs}`, " */", "export const runtime = ManagedRuntime.make(", parts.maxDuration !== void 0 && lines(" // The functions' `maxDuration`, from `vercel.json`: a clone that would outrun it ends first,", " // with Git's own message."), ` Git.layer(${gitOptions(choices, parts.maxDuration)}, ${choices.serve === "github" ? "github" : "features"}).pipe(`, " Layer.provide(Policy.layer(policy)),", " Layer.provide(Auth.layer(auth)),", choices.objects === "packs" ? " Layer.provide(Objects.layer())," : ` // Each object a row in its push's commit: no bucket, ${looseSays}.\n Layer.provide(Objects.layerRecords()),`, ` Layer.provideMerge(${parts.adapter}),`, " ),", ");", "");
126
+ const runtimeLines = (choices, parts) => lines(parts.bootstrap === true ? lines("/** The bootstrap's sign-in, while `ADMIN_TOKEN` holds one: a Bearer token, or Basic's password. */", "const auth =", ` ${parts.token} === undefined || ${parts.token} === ''`, " ? Layer.empty", ` : Auth.layer(Auth.bearer({ token: Redacted.make(${parts.token}), actor: bootstrap }));`) : lines("/** The admin's sign-in: `ADMIN_TOKEN`, as a Bearer token or as Basic's password. */", `const auth = Auth.bearer({ token: Redacted.make(${parts.token}), actor: admin });`), "", "/**", " * The whole host, one runtime that every request and job shares: Git and its features over the", ` * adapter, deciding with \`policy\`, and the ${parts.bootstrap === true ? "bootstrap" : "admin"} signing in with \`auth\`.`, parts.jobs !== void 0 && ` * ${parts.jobs}`, " */", "export const runtime = ManagedRuntime.make(", parts.maxDuration !== void 0 && lines(" // The functions' `maxDuration`, from `vercel.json`: a clone that would outrun it ends first,", " // with Git's own message."), ` Git.layer(${gitOptions(choices, parts.maxDuration)}, ${choices.serve === "github" ? "github" : "features"}).pipe(`, " Layer.provide(Policy.layer(policy)),", parts.bootstrap === true ? " Layer.provide(auth)," : " Layer.provide(Auth.layer(auth)),", choices.objects === "packs" ? " Layer.provide(Objects.layer())," : ` // Each object a row in its push's commit: no bucket, ${looseSays}.\n Layer.provide(Objects.layerRecords()),`, ` Layer.provideMerge(${parts.adapter}),`, " ),", ");", "");
121
127
  export { adminLines, effectImports, featuresLines, gitDependencies, gitImports, gitPackages, header, lfsLines, looseSays, mergeLines, policyLines, queueLine, repoHint, runtimeLines, writtenCpu };
@@ -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.8.0";
3
+ const release = "0.10.0";
4
4
  /** The packages the app depends on, by their folder in a checkout's `packages/`. */
5
5
  const appPackages = [
6
6
  "infra",
@@ -191,7 +191,7 @@ var templates_default = {
191
191
  },
192
192
  {
193
193
  "slot": "gitImports",
194
- "text": "import { Auth, Git, Lfs, MergeQueue, Merges, Objects, Policy, Rest, Tokens } 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 { MergeInput, MergePlan } from '@ref0/git';\n"
195
195
  },
196
196
  {
197
197
  "slot": "infraImport",
@@ -200,7 +200,7 @@ var templates_default = {
200
200
  "\nimport xdiff from '@ref0/xdiff-wasm/xdiff.wasm';\nimport { env as bindings } from 'cloudflare:workers';\n",
201
201
  {
202
202
  "slot": "effectImports",
203
- "text": "import * as Layer from 'effect/Layer';\nimport * as ManagedRuntime from 'effect/ManagedRuntime';\nimport * as Redacted from 'effect/Redacted';\n"
203
+ "text": "import * as Context from 'effect/Context';\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\nimport * as ManagedRuntime from 'effect/ManagedRuntime';\nimport * as Option from 'effect/Option';\nimport * as Redacted from 'effect/Redacted';\n"
204
204
  },
205
205
  "\nimport type { Env } from ",
206
206
  {
@@ -212,7 +212,7 @@ var templates_default = {
212
212
  "slot": "safety",
213
213
  "text": "binds the objects and the bucket"
214
214
  },
215
- ", and `ADMIN_TOKEN` is its secret.\nconst env = bindings as Env;\n\n/** Who `ADMIN_TOKEN` signs in as: it makes repos and tokens, and never pushes. */\nconst admin = { id: '_admin' };\n\n",
215
+ ", and sets `ADMINS`.\nconst env = bindings as Env;\n\n/**\n * Who `ADMIN_TOKEN` signs in as, while it's set: it mints a listed admin's first `admin` token, and\n * nothing else. No login can be it.\n */\nconst bootstrap = { id: '_admin' };\n\n/**\n * The host's admins: `ADMINS`, from `wrangler.jsonc`'s vars, logins between commas. Each signs in\n * as themselves with an `admin` token, and makes repos, mints tokens and pushes. Adding one is a\n * vars edit and a deploy. A login that can't be one stops the Worker's start, so a deploy that\n * names it fails.\n */\nconst admins = new Set(\n (env.ADMINS ?? '')\n .split(',')\n .map((login) => login.trim())\n .filter((login) => login !== ''),\n);\n\nfor (const login of admins) {\n if (login === bootstrap.id || new TextEncoder().encode(login).length > maxActorIdLength) {\n throw new Error(`ADMINS names '${login}', which can't be a login`);\n }\n}\n\n",
216
216
  {
217
217
  "slot": "bucket",
218
218
  "text": "const {\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\n/** The records and job objects, and the packs' bucket. */\nconst adapter = Layer.merge(\n layer({ records: env.RECORDS, jobs: env.JOBS }),\n signed ?? layerR2(env.PACKS),\n);\n\n"
@@ -221,14 +221,14 @@ 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 }: 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: Date.now(),\n offset: 0,\n },\n});\n\n"
223
223
  },
224
- "/**\n * Who may do what: a visitor signs in first, and the admin makes repos and tokens but never\n * pushes.\n */\nconst policy = Policy.make(({ caller: { actor }, operation }) => {\n if (actor.anonymous === true) return Policy.reject({ message: 'Sign in first' });\n\n if (actor.id === admin.id && operation.kind === 'push') {\n return Policy.reject({\n message: \"The admin token can't push\",\n hint: 'Make a write token for yourself: npx ref0-git tokens create --help',\n });\n }\n\n return Policy.accept();\n});\n\n",
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\n * reads the whole host's tokens from `runtime`, which `policy` is part of. Past `bootstrapReads`,\n * or with no `Tokens` to read, it 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 * 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, and\n * an `admin` token is only ever an admin's. Every other caller does what its token reaches.\n */\nconst policy = Policy.make(({ caller, operation }) =>\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 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"
228
228
  },
229
229
  {
230
230
  "slot": "runtime",
231
- "text": "/** The admin's sign-in: `ADMIN_TOKEN`, as a Bearer token or as Basic's password. */\nconst auth = Auth.bearer({ token: Redacted.make(env.ADMIN_TOKEN), actor: admin });\n\n/**\n * The whole host, one runtime that every request and job shares: Git and its features over the\n * adapter, deciding with `policy`, and the admin signing in with `auth`.\n */\nexport const runtime = ManagedRuntime.make(\n Git.layer({}, features).pipe(\n Layer.provide(Policy.layer(policy)),\n Layer.provide(Auth.layer(auth)),\n Layer.provide(Objects.layer()),\n Layer.provideMerge(adapter),\n ),\n);\n\n"
231
+ "text": "/** The bootstrap's sign-in, while `ADMIN_TOKEN` holds one: a Bearer token, or Basic's password. */\nconst auth =\n env.ADMIN_TOKEN === undefined || env.ADMIN_TOKEN === ''\n ? Layer.empty\n : Auth.layer(Auth.bearer({ token: Redacted.make(env.ADMIN_TOKEN), actor: bootstrap }));\n\n/**\n * The whole host, one runtime that every request and job shares: Git and its features over the\n * adapter, deciding with `policy`, and the bootstrap signing in with `auth`.\n */\nexport const runtime = ManagedRuntime.make(\n Git.layer({}, features).pipe(\n Layer.provide(Policy.layer(policy)),\n Layer.provide(auth),\n Layer.provide(Objects.layer()),\n Layer.provideMerge(adapter),\n ),\n);\n\n"
232
232
  },
233
233
  "/** The records objects, one per scope, as `wrangler.jsonc`'s `class_name`s name them. */\nexport const Records = toRecordsObject(runtime);\n\n/** The job objects, one per scope and job, which a records object's alarm rings. */\nexport const Jobs = toJobObject(runtime);\n"
234
234
  ],
@@ -254,7 +254,7 @@ var templates_default = {
254
254
  "slot": "bucket",
255
255
  "text": " /** The packs' bucket, and its name, which a signed link names. */\n readonly PACKS: R2Bucket;\n readonly PACKS_BUCKET: string;\n"
256
256
  },
257
- " /** Signs in as the admin, who makes repos and tokens and never pushes. */\n readonly ADMIN_TOKEN: string;\n",
257
+ " /** The host's admins, logins between commas: each signs in as themselves with an `admin` token. */\n readonly ADMINS?: string;\n /** The bootstrap secret: it mints a listed admin's first `admin` token, then is deleted. */\n readonly ADMIN_TOKEN?: string;\n",
258
258
  {
259
259
  "slot": "signing",
260
260
  "text": " /** R2's S3 credentials for the packs' bucket: with all three, a large push uploads its pack. */\n readonly R2_ACCOUNT_ID?: string;\n readonly R2_ACCESS_KEY_ID?: string;\n readonly R2_SECRET_ACCESS_KEY?: string;\n"
@@ -267,7 +267,7 @@ var templates_default = {
267
267
  "slot": "about",
268
268
  "text": "Durable Object classes, and an R2 bucket"
269
269
  },
270
- ". Written by\n// `ref0-git init`. `ADMIN_TOKEN` is its one secret: `wrangler secret put ADMIN_TOKEN`.\n",
270
+ ". Written by\n// `ref0-git init`. `ADMINS` names its admins, logins between commas. `ADMIN_TOKEN`, its one\n// secret, mints the first one's token: `wrangler secret put ADMIN_TOKEN`, deleted once they have it.\n",
271
271
  {
272
272
  "slot": "signing",
273
273
  "text": "// With R2's S3 credentials too, as the secrets `R2_ACCOUNT_ID`, `R2_ACCESS_KEY_ID` and\n// `R2_SECRET_ACCESS_KEY`, a large push uploads its pack to the bucket in parts.\n"
@@ -289,7 +289,7 @@ var templates_default = {
289
289
  },
290
290
  {
291
291
  "slot": "vars",
292
- "text": " \"vars\": { \"PACKS_BUCKET\": \"git-packs\" },\n"
292
+ "text": " \"vars\": { \"PACKS_BUCKET\": \"git-packs\", \"ADMINS\": \"\" },\n"
293
293
  },
294
294
  " \"migrations\": [{ \"tag\": \"v1\", \"new_sqlite_classes\": [\"Records\", \"Jobs\"] }],\n}\n"
295
295
  ],
@@ -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.8.0" || spec !== void 0 && packedPath(name).test(spec);
59
+ const initWrote = (name, spec) => spec === "0.10.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.8.0",
3
+ "version": "0.10.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.8.0",
28
- "@ref0/infra": "0.8.0",
27
+ "@ref0/git": "0.10.0",
28
+ "@ref0/infra": "0.10.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.8.0",
38
- "@ref0/xdiff-wasm": "0.8.0",
37
+ "@ref0/github": "0.10.0",
38
+ "@ref0/xdiff-wasm": "0.10.0",
39
39
  "@tanstack/react-start": "1.169.7",
40
40
  "@types/node": "24.19.4",
41
41
  "@types/pg": "8.23.1",