ref0-git 0.11.0 → 0.14.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/generated/git-rest.ts +152 -3
- package/app/apps/github/migrations/postgres/0001_auth.sql +8 -1
- package/app/apps/github/migrations/sql/0005_repo_grants.sql +10 -0
- package/app/apps/github/src/clients/allowed.ts +9 -4
- package/app/apps/github/src/components/repos/your-repos.tsx +57 -11
- package/app/apps/github/src/context/context.ts +45 -2
- package/app/apps/github/src/context/repo-grants.ts +35 -0
- package/app/apps/github/src/hooks/repos.ts +14 -3
- package/app/apps/github/src/policy.ts +485 -92
- package/app/apps/github/src/routes/$owner/$repo/settings/access.tsx +1 -1
- package/app/apps/github/src/routes/index.tsx +2 -1
- package/app/apps/github/src/settings/access-page.tsx +308 -0
- package/app/apps/github/src/settings/access.ts +156 -0
- package/app/apps/github/src/settings/settings-layout.tsx +0 -16
- package/app/apps/github/src/signin/auth.ts +2 -0
- package/app/apps/github/src/signin/orgs.ts +57 -14
- package/app/apps/github/src/signin/repo-grants.ts +141 -0
- package/app/pnpm-workspace.yaml +2 -2
- package/dist/cli/child.mjs +73 -3
- package/dist/cli/commands.mjs +2 -0
- package/dist/cli/documents.mjs +42 -2
- package/dist/cli/keys.mjs +431 -0
- package/dist/cli/main.mjs +148 -0
- package/dist/cli/prompt.mjs +40 -1
- package/dist/cli/ref0-git.mjs +4 -141
- package/dist/cli/setup.mjs +115 -13
- package/dist/cli/sign-in.mjs +1 -1
- package/dist/cli/tools-node.mjs +20 -0
- package/dist/cli/tools.mjs +12 -0
- package/dist/init/app.mjs +3 -1
- package/dist/init/git-module.mjs +23 -9
- package/dist/init/metadata.mjs +1 -1
- package/dist/init/template.mjs +1 -0
- package/dist/init/templates.mjs +17 -12
- package/dist/init/versions.mjs +1 -1
- package/package.json +5 -5
package/dist/init/templates.mjs
CHANGED
|
@@ -12,14 +12,19 @@ var templates_default = {
|
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
14
|
"slot": "githubImport",
|
|
15
|
-
"text": "import {\n Apps,\n Deployments,\n GitHub,\n Inbox,\n Releases,\n Search,\n Streams,\n Webhooks,\n} from '@ref0/github';"
|
|
15
|
+
"text": "import {\n Apps,\n Deployments,\n GitHub,\n Inbox,\n Releases,\n RepoGrants,\n Search,\n Streams,\n Webhooks,\n} from '@ref0/github';"
|
|
16
16
|
},
|
|
17
|
-
"\nimport * as Languages from '@ref0/github/languages';\n",
|
|
17
|
+
"\nimport * as Collaborators from '@ref0/github/collaborators';\nimport * as Languages from '@ref0/github/languages';\n",
|
|
18
18
|
{
|
|
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';\
|
|
22
|
+
"\nimport xdiff from '@ref0/xdiff-wasm/xdiff.wasm';\nimport { env as bindings } from 'cloudflare:workers';\n",
|
|
23
|
+
{
|
|
24
|
+
"slot": "effectImport",
|
|
25
|
+
"text": "import * as Effect from 'effect/Effect';\n"
|
|
26
|
+
},
|
|
27
|
+
"import * 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 { repoGrantsDropped } from './context/repo-grants.ts';\nimport { repoIcons } from './context/repo-icons.ts';\nimport type { Env } from './env.ts';\nimport {\n admin,\n approvalPage,\n type GrantsPolicy,\n hostPolicy,\n hostRules,\n type Identify,\n} 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 { grantsOver } from './signin/repo-grants.ts';\nimport { sealKey } from './signin/seal.ts';\n\n// SAFETY: `wrangler.jsonc` ",
|
|
23
28
|
{
|
|
24
29
|
"slot": "safety",
|
|
25
30
|
"text": "binds the objects, the bucket and D1"
|
|
@@ -27,13 +32,13 @@ var templates_default = {
|
|
|
27
32
|
" and sets `APP_ORIGIN`; the\n// secrets come from `wrangler secret put`, or `.dev.vars` locally.\nexport const env = bindings as Env;\n\n",
|
|
28
33
|
{
|
|
29
34
|
"slot": "bucket",
|
|
30
|
-
"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\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"
|
|
35
|
+
"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// With none, Git LFS's bytes go through the Worker, under its CPU and body limits: a warning\n// says so once an isolate, as the runtime builds the bucket.\nconst unsigned = Layer.effectDiscard(\n Effect.logWarning(\n \"LFS: through the Worker (no signing key). Run `ref0-git keys` in the Worker's folder to sign its links straight to R2\",\n ),\n);\n\nconst bucket = signed ?? Layer.merge(layerR2(env.PACKS), unsigned);\n\nconst uploads =\n signed === undefined\n ? Layer.empty\n : Layer.provide(Git.layerUploads({ above: 64 * 1024 * 1024 }), signed);\n\n"
|
|
31
36
|
},
|
|
32
37
|
{
|
|
33
38
|
"slot": "queueMerge",
|
|
34
39
|
"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
40
|
},
|
|
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",
|
|
41
|
+
"/** 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\n/** Each repo's grants to people, its collaborators, in Better Auth's database, as `directory` reads it. */\nexport const grants = grantsOver(async () => readyAdapter(await auth()));\n\nexport const policy: GrantsPolicy = 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 // Who else may do what on a repo, by its grants, and which repo a token over one names now.\n grants,\n repoId: async (name, signal) =>\n (await runtime.runPromise(RepoRecords.pin(name), { signal }))?.internalId,\n});\n\n",
|
|
37
42
|
{
|
|
38
43
|
"slot": "adapter",
|
|
39
44
|
"text": "/** The records and job objects, and the bucket. */\nconst adapter = Layer.merge(layer({ records: env.RECORDS, jobs: env.JOBS }), bucket);"
|
|
@@ -48,7 +53,7 @@ var templates_default = {
|
|
|
48
53
|
"slot": "releases",
|
|
49
54
|
"text": " // A release's assets, in the bucket beside the packs.\n Releases.layer(),\n"
|
|
50
55
|
},
|
|
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",
|
|
56
|
+
" // `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 // A repo's collaborators and teams, which its settings list and change.\n Collaborators.layer(),\n // A deleted repo's collaborators, removed however the repo was deleted.\n repoGrantsDropped(grants),\n).pipe(\n Layer.provideMerge(GitHub.layer()),\n // The directory, and a repo's collaborators, which its settings list and change: the drop-in\n // takes both as it's built.\n Layer.provideMerge(Layer.merge(peopleOver(policy.people), RepoGrants.layer(policy.repoGrants))),\n Layer.provideMerge(\n Layer.mergeAll(\n Rest.layer(),\n",
|
|
52
57
|
{
|
|
53
58
|
"slot": "lfs",
|
|
54
59
|
"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,13 +71,13 @@ var templates_default = {
|
|
|
66
71
|
appGitNode: [
|
|
67
72
|
{
|
|
68
73
|
"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 { repoIcons } from './context/repo-icons.ts';\nimport type { Env } from './env.ts';\nimport {
|
|
74
|
+
"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 RepoGrants,\n Search,\n Streams,\n Webhooks,\n} from '@ref0/github';\nimport * as Collaborators from '@ref0/github/collaborators';\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 Effect from 'effect/Effect';\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 { repoGrantsDropped } from './context/repo-grants.ts';\nimport { repoIcons } from './context/repo-icons.ts';\nimport type { Env } from './env.ts';\nimport {\n admin,\n approvalPage,\n type GrantsPolicy,\n hostPolicy,\n hostRules,\n type Identify,\n} 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 { grantsOver } from './signin/repo-grants.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\n// With none, Git LFS's bytes go through the Worker, under its CPU and body limits: a warning\n// says so once an isolate, as the runtime builds the bucket.\nconst unsigned = Layer.effectDiscard(\n Effect.logWarning(\n \"LFS: through the Worker (no signing key). Run `ref0-git keys` in the Worker's folder to sign its links straight to R2\",\n ),\n);\n\nconst bucket = signed ?? Layer.merge(layerR2(env.PACKS), unsigned);\n\nconst uploads =\n signed === undefined\n ? Layer.empty\n : Layer.provide(Git.layerUploads({ above: 64 * 1024 * 1024 }), signed);\n\n"
|
|
70
75
|
},
|
|
71
76
|
{
|
|
72
77
|
"slot": "queueMerge",
|
|
73
78
|
"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
79
|
},
|
|
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",
|
|
80
|
+
"/** 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\n/** Each repo's grants to people, its collaborators, in Better Auth's database, as `directory` reads it. */\nexport const grants = grantsOver(async () => readyAdapter(await auth()));\n\nexport const policy: GrantsPolicy = 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 // Who else may do what on a repo, by its grants, and which repo a token over one names now.\n grants,\n repoId: async (name, signal) =>\n (await runtime.runPromise(RepoRecords.pin(name), { signal }))?.internalId,\n});\n\n",
|
|
76
81
|
{
|
|
77
82
|
"slot": "adapter",
|
|
78
83
|
"text": "/** The records and job objects, and the bucket. */\nconst adapter = Layer.merge(layer({ records: env.RECORDS, jobs: env.JOBS }), bucket);"
|
|
@@ -87,7 +92,7 @@ var templates_default = {
|
|
|
87
92
|
"slot": "releases",
|
|
88
93
|
"text": " // A release's assets, in the bucket beside the packs.\n Releases.layer(),\n"
|
|
89
94
|
},
|
|
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",
|
|
95
|
+
" // `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 // A repo's collaborators and teams, which its settings list and change.\n Collaborators.layer(),\n // A deleted repo's collaborators, removed however the repo was deleted.\n repoGrantsDropped(grants),\n).pipe(\n Layer.provideMerge(GitHub.layer()),\n // The directory, and a repo's collaborators, which its settings list and change: the drop-in\n // takes both as it's built.\n Layer.provideMerge(Layer.merge(peopleOver(policy.people), RepoGrants.layer(policy.repoGrants))),\n Layer.provideMerge(\n Layer.mergeAll(\n Rest.layer(),\n",
|
|
91
96
|
{
|
|
92
97
|
"slot": "lfs",
|
|
93
98
|
"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 +196,7 @@ var templates_default = {
|
|
|
191
196
|
},
|
|
192
197
|
{
|
|
193
198
|
"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"
|
|
199
|
+
"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
200
|
},
|
|
196
201
|
{
|
|
197
202
|
"slot": "infraImport",
|
|
@@ -215,13 +220,13 @@ var templates_default = {
|
|
|
215
220
|
", 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
221
|
{
|
|
217
222
|
"slot": "bucket",
|
|
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"
|
|
223
|
+
"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// With none, Git LFS's bytes go through the Worker, under its CPU and body limits: a warning\n// says so once an isolate, as the runtime builds the bucket.\nconst unsigned = Layer.effectDiscard(\n Effect.logWarning(\n \"LFS: through the Worker (no signing key). Run `ref0-git keys` in the Worker's folder to sign its links straight to R2\",\n ),\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 ?? Layer.merge(layerR2(env.PACKS), unsigned),\n);\n\n"
|
|
219
224
|
},
|
|
220
225
|
{
|
|
221
226
|
"slot": "merge",
|
|
222
227
|
"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
228
|
},
|
|
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
|
|
229
|
+
"/** 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
230
|
{
|
|
226
231
|
"slot": "features",
|
|
227
232
|
"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.14.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.14.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.14.0",
|
|
28
|
+
"@ref0/infra": "0.14.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.14.0",
|
|
38
|
+
"@ref0/xdiff-wasm": "0.14.0",
|
|
39
39
|
"@tanstack/react-start": "1.169.7",
|
|
40
40
|
"@types/node": "24.19.4",
|
|
41
41
|
"@types/pg": "8.23.1",
|