ref0-git 0.26.0 → 0.29.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.
Files changed (49) hide show
  1. package/app/apps/github/README.md +1 -5
  2. package/app/apps/github/package.json +0 -1
  3. package/app/apps/github/src/signin/auth.ts +17 -89
  4. package/app/apps/github/src/signin/credentials.ts +10 -14
  5. package/app/apps/github/src/signin/guarded-write.ts +19 -0
  6. package/app/apps/github/src/signin/owner-names.ts +11 -41
  7. package/app/apps/github/src/signin/unborn.ts +20 -30
  8. package/app/apps/github/tsconfig.json +0 -2
  9. package/app/pnpm-workspace.yaml +14 -34
  10. package/dist/cli/documents.mjs +39 -25
  11. package/dist/cli/keys.mjs +9 -3
  12. package/dist/cli/node.mjs +1 -2
  13. package/dist/cli/runtime.mjs +3 -4
  14. package/dist/cli/setup.mjs +216 -468
  15. package/dist/cli/tools-node.mjs +8 -7
  16. package/dist/cli/tools.mjs +3 -3
  17. package/dist/cli/vercel-stores.mjs +287 -0
  18. package/dist/init/app.mjs +4 -37
  19. package/dist/init/choices.mjs +62 -209
  20. package/dist/init/cloudflare.mjs +1 -2
  21. package/dist/init/detect.mjs +77 -167
  22. package/dist/init/files.mjs +2 -12
  23. package/dist/init/frameworks.mjs +50 -174
  24. package/dist/init/git-module.mjs +5 -1
  25. package/dist/init/metadata.mjs +4 -22
  26. package/dist/init/next.mjs +13 -66
  27. package/dist/init/output.mjs +3 -6
  28. package/dist/init/plan.mjs +1 -29
  29. package/dist/init/routes.mjs +1 -78
  30. package/dist/init/stores.mjs +6 -35
  31. package/dist/init/template.mjs +14 -49
  32. package/dist/init/templates.mjs +30 -115
  33. package/dist/init/vercel-regions.mjs +87 -0
  34. package/dist/init/vercel.mjs +313 -212
  35. package/dist/init/versions.mjs +3 -3
  36. package/package.json +5 -11
  37. package/app/apps/github/migrations/postgres/0001_auth.sql +0 -53
  38. package/app/apps/github/src/camo/lookup.ts +0 -23
  39. package/app/apps/github/src/camo/node.ts +0 -50
  40. package/app/apps/github/src/signin/person-lock.ts +0 -104
  41. package/dist/cli/sqlite.mjs +0 -28
  42. package/dist/init/astro.mjs +0 -49
  43. package/dist/init/create.mjs +0 -152
  44. package/dist/init/mounts.mjs +0 -104
  45. package/dist/init/node-app.mjs +0 -196
  46. package/dist/init/node.mjs +0 -446
  47. package/dist/init/nuxt.mjs +0 -240
  48. package/dist/init/react-router.mjs +0 -59
  49. package/dist/init/sveltekit.mjs +0 -141
@@ -68,64 +68,6 @@ var templates_default = {
68
68
  },
69
69
  " // The device flow's sign-in for `gh` and `ref0-git login`, which the page decides in the\n // person's session, from the Better Auth below and Git's own `identify`.\n SignIn.layer({\n approvalPage: approvalPage({\n auth: () => auth(),\n sealKey: sessionKey,\n identify: (request): ReturnType<Identify> => host(Git.identify(request)),\n origin: env.APP_ORIGIN,\n }),\n }),\n ),\n ),\n Layer.provideMerge(Tokens.layer()),\n Layer.provideMerge(Merges.layer({ xdiff })),\n);\n\n/**\n * The whole host, one runtime a process: Git and its features over the records, the jobs and the\n * bucket, as the policy decides, with `hostRules` its push rules.\n */\nexport const runtime = Git.runtime(\n hostLayer(adapter, objects, features, {\n authorize: policy.authorize,\n auth: appAuth({ adminToken: env.ADMIN_TOKEN, admin, key: sessionKey }),\n authorizeGitHub: policy.authorizeGitHub,\n rules: hostRules.map((each) => each.rule),\n }),\n);\n\n/**\n * Better Auth, made at a request that needs it, not the isolate's start: who signs up and in, in\n * `AUTH_DB`, each session with a Git token of its own. It's kept once a request's check settles.\n */\nexport const auth = readyAuth(() =>\n starterAuth({\n database: env.AUTH_DB,\n secret: env.SESSION_SECRET,\n origin: env.APP_ORIGIN,\n signUp: env.SIGN_UP !== 'closed',\n key: sessionKey,\n tokens: tokensOn(host),\n // Cloudflare's own, which it sets on every request in place of any the caller sent.\n ipHeader: 'cf-connecting-ip',\n ownsRepos: (login) =>\n Effect.match(host(Repos.list({ actor: admin, prefix: `${login}/`, page: { limit: 1 } })), {\n onFailure: () => true,\n onSuccess: (listed) => listed.items.length > 0,\n }),\n }),\n);\n\n/** The records objects, one per scope, as `wrangler.jsonc`'s `class_name`s name them. */\nexport const Records = toRecordsObject(store);\n\n/** The job objects, one per scope and job, which a records object's alarm rings. */\nexport const Jobs = toJobObject(runtime);\n"
70
70
  ],
71
- appGitNode: [
72
- {
73
- "slot": "head",
74
- "text": "import { Git, Lfs, Merges, MergeQueue, Objects, Repos, Rest, SignIn, Tokens } from '@ref0/git';\nimport type { MergeInput, MergePlan } from '@ref0/git';\nimport {\n Apps,\n Deployments,\n GitHub,\n Inbox,\n IssueLists,\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';\n\nimport {\n hostLayer,\n onHost,\n type OnHost,\n peopleOver,\n repoRecordsOn,\n tokensOn,\n} 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"
75
- },
76
- {
77
- "slot": "queueMerge",
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"
79
- },
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\n/**\n * Git's services on the runtime below, in the caller's fiber: the policy reads its repos' records\n * through it within the request it decides, its store calls counted on that request's.\n */\nexport const host: OnHost = onHost(() => runtime);\n\nconst { repoName, repoId } = repoRecordsOn(host);\n\nexport const policy: GrantsPolicy = hostPolicy(directory, {\n origin: env.APP_ORIGIN,\n avatars: pictures,\n privateRepos: privateReposOf(host),\n repoName,\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,\n});\n\n",
81
- {
82
- "slot": "adapter",
83
- "text": "/** The records and job objects, and the bucket. */\nconst store = layer({\n records: env.RECORDS,\n jobs: env.JOBS,\n // `limits.cpu_ms` from wrangler.jsonc, so a job object chains its tries within one alarm:\n // raise both together.\n requestLimits: { cpuMs: 300_000 },\n});\n\nconst adapter = Layer.merge(store, bucket);"
84
- },
85
- "\n\n",
86
- {
87
- "slot": "objects",
88
- "text": "/** Git's objects, in packs in the bucket. */\nconst objects = Objects.layer();"
89
- },
90
- "\n\n/**\n * Git's features and the drop-in's, over the host's directory: delete a line to turn its feature\n * off (Q832).\n */\nconst features = Layer.mergeAll(\n Inbox.layer(),\n Deployments.layer(),\n",
91
- {
92
- "slot": "releases",
93
- "text": " // A release's assets, in the bucket beside the packs.\n Releases.layer(),\n"
94
- },
95
- " // `org:` and `user:` search an owner's repos, its private ones by the policy's hook.\n Search.layer({ readableRepos: policy.readableRepos }),\n // Each person's index of the issues and pull requests they take part in, across every repo:\n // `/issues`, an org's issues, and a search that names no repo read it.\n IssueLists.layer(),\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",
96
- {
97
- "slot": "lfs",
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"
99
- },
100
- {
101
- "slot": "uploads",
102
- "text": " // A push past 64 MiB may upload its pack, once the bucket signs parts.\n uploads,\n"
103
- },
104
- {
105
- "slot": "queue",
106
- "text": " // Each repo's `main` has a merge queue, beside the merge button: its protection still takes\n // a direct merge, as GitHub's does on a branch whose rules don't ask for the queue.\n MergeQueue.layer({ target: 'refs/heads/main', keys: 'once', merge: queueMerge }),\n"
107
- },
108
- " // The device flow's sign-in for `gh` and `ref0-git login`, which the page decides in the\n // person's session, from the Better Auth below and Git's own `identify`.\n SignIn.layer({\n approvalPage: approvalPage({\n auth: () => auth(),\n sealKey: sessionKey,\n identify: (request): ReturnType<Identify> => host(Git.identify(request)),\n origin: env.APP_ORIGIN,\n }),\n }),\n ),\n ),\n Layer.provideMerge(Tokens.layer()),\n",
109
- {
110
- "slot": "xdiff",
111
- "text": " Layer.provideMerge(Merges.layer({ xdiff })),"
112
- },
113
- "\n);\n\n/**\n * The whole host, one runtime a process: Git and its features over the records, the jobs and the\n * bucket, as the policy decides, with `hostRules` its push rules.\n */\nexport const runtime = Git.runtime(\n hostLayer(adapter, objects, features, {\n authorize: policy.authorize,\n auth: appAuth({ adminToken: env.ADMIN_TOKEN, admin, key: sessionKey }),\n authorizeGitHub: policy.authorizeGitHub,\n rules: hostRules.map((each) => each.rule),\n }),\n);\n\n/**\n * Better Auth, made at a request that needs it, not the isolate's start: who signs up and in, in\n * `AUTH_DB`, each session with a Git token of its own. It's kept once a request's check settles.\n */\nexport const auth = readyAuth(() =>\n starterAuth({\n",
114
- {
115
- "slot": "database",
116
- "text": " database: env.AUTH_DB,"
117
- },
118
- "\n secret: env.SESSION_SECRET,\n origin: env.APP_ORIGIN,\n signUp: env.SIGN_UP !== 'closed',\n key: sessionKey,\n tokens: tokensOn(host),\n",
119
- {
120
- "slot": "ipHeader",
121
- "text": " // Cloudflare's own, which it sets on every request in place of any the caller sent.\n ipHeader: 'cf-connecting-ip',\n"
122
- },
123
- " ownsRepos: (login) =>\n Effect.match(host(Repos.list({ actor: admin, prefix: `${login}/`, page: { limit: 1 } })), {\n onFailure: () => true,\n onSuccess: (listed) => listed.items.length > 0,\n }),\n }),\n);\n",
124
- {
125
- "slot": "classes",
126
- "text": "\n/** The records objects, one per scope, as `wrangler.jsonc`'s `class_name`s name them. */\nexport const Records = toRecordsObject(store);\n\n/** The job objects, one per scope and job, which a records object's alarm rings. */\nexport const Jobs = toJobObject(runtime);\n"
127
- }
128
- ],
129
71
  appEnv: [
130
72
  {
131
73
  "slot": "types",
@@ -182,13 +124,9 @@ var templates_default = {
182
124
  "\n ],\n \"migrations\": [{ \"tag\": \"v1\", \"new_sqlite_classes\": [\"Records\", \"Jobs\"] }],\n}\n"
183
125
  ],
184
126
  appConfigs: {
185
- "tsconfig.json": "// The app's pages, routes, clients and sign-in: DOM, as a browser runs them, and Start's server\n// functions beside them. The Worker's entry and Git are `tsconfig.worker.json`'s, typed by\n// workers-types with no DOM, and the tests `tsconfig.test.json`'s, in Node. Each file is in the\n// one whose globals it runs with, and the root's `tsconfig.json` references all three.\n{\n \"extends\": \"./tsconfig.base.json\",\n \"compilerOptions\": {\n \"composite\": true,\n \"jsx\": \"react-jsx\",\n \"lib\": [\"ES2023\", \"DOM\", \"DOM.Iterable\"],\n \"tsBuildInfoFile\": \"./node_modules/.cache/tsconfig.tsbuildinfo\",\n \"types\": [\"vite-plus/client\"]\n },\n \"include\": [\"src/**/*.ts\", \"src/**/*.tsx\", \"generated/**/*.ts\"],\n \"exclude\": [\n \"src/**/*.test.ts\",\n \"src/**/testing/**\",\n \"src/seed/**\",\n \"src/server.ts\",\n \"src/git.ts\",\n \"src/policy.ts\",\n \"src/env.ts\",\n \"src/signin/approval.ts\",\n \"src/camo/lookup.ts\",\n \"src/camo/node.ts\",\n \"src/markdown/words-plugin.ts\"\n ]\n}\n",
127
+ "tsconfig.json": "// The app's pages, routes, clients and sign-in: DOM, as a browser runs them, and Start's server\n// functions beside them. The Worker's entry and Git are `tsconfig.worker.json`'s, typed by\n// workers-types with no DOM, and the tests `tsconfig.test.json`'s, in Node. Each file is in the\n// one whose globals it runs with, and the root's `tsconfig.json` references all three.\n{\n \"extends\": \"./tsconfig.base.json\",\n \"compilerOptions\": {\n \"composite\": true,\n \"jsx\": \"react-jsx\",\n \"lib\": [\"ES2023\", \"DOM\", \"DOM.Iterable\"],\n \"tsBuildInfoFile\": \"./node_modules/.cache/tsconfig.tsbuildinfo\",\n \"types\": [\"vite-plus/client\"]\n },\n \"include\": [\"src/**/*.ts\", \"src/**/*.tsx\", \"generated/**/*.ts\"],\n \"exclude\": [\n \"src/**/*.test.ts\",\n \"src/**/testing/**\",\n \"src/seed/**\",\n \"src/server.ts\",\n \"src/git.ts\",\n \"src/policy.ts\",\n \"src/env.ts\",\n \"src/signin/approval.ts\",\n \"src/markdown/words-plugin.ts\"\n ]\n}\n",
186
128
  "tsconfig.worker.json": "// The Worker, typed as Cloudflare types one: workers-types' globals and no DOM, so `Request` and\n// `Response` are a Worker's. The pages are `tsconfig.app.json`'s, and the files both run, sealing\n// and names, are in each.\n{\n \"extends\": \"./tsconfig.base.json\",\n \"compilerOptions\": {\n \"composite\": true,\n \"lib\": [\"ES2023\"],\n \"tsBuildInfoFile\": \"./node_modules/.cache/tsconfig.worker.tsbuildinfo\",\n \"types\": [\"@cloudflare/workers-types\", \"vite-plus/client\"]\n },\n \"include\": [\n \"src/server.ts\",\n \"src/git.ts\",\n \"src/policy.ts\",\n \"src/env.ts\",\n \"src/context/**/*.ts\",\n \"src/names/**/*.ts\",\n \"src/seed/**/*.ts\",\n \"src/signin/approval.ts\",\n \"src/signin/seal.ts\"\n ],\n \"exclude\": [\"src/**/*.test.ts\", \"src/seed/testing/built-app.ts\"]\n}\n"
187
129
  },
188
- nodeServer: "import { Git, Repos } from '@ref0/git';\nimport { Records } from '@ref0/infra';\nimport handler, { createServerEntry } from '@tanstack/react-start/server-entry';\nimport * as Effect from 'effect/Effect';\n\nimport { nodeFetch } from './camo/node.ts';\nimport { imageProxy } from './camo/proxy.ts';\nimport type { AppContext, HostGit } from './context/context.ts';\nimport { auth, directory, env, host, pictures, policy, runtime, sessionKey } from './git.ts';\nimport { routeOn, tokensOn } from './context/host.ts';\nimport { ingressOf } from './ingress.ts';\nimport { hostRules } from './policy.ts';\nimport { shownRules } from './settings/rules.ts';\nimport { deviceAttemptAnswer, deviceAttemptGate } from './signin/attempts.ts';\nimport { sessionCookieOf, sessionEnder, sessionFrom, sessionIdFrom } from './signin/auth.ts';\nimport { clientIpHeader, withClientIp } from './signin/client-ip.ts';\nimport { withoutHostSession } from './signin/host-session.ts';\n\n/**\n * The device page's attempts (#1962), counted in Git's records, by the address the platform sets\n * and the session Better Auth checks, before Git reads a code.\n */\nconst gate = deviceAttemptGate({\n answer: (who) => runtime.runPromise(deviceAttemptAnswer(who)),\n addressHeader: clientIpHeader,\n session: async (request) => sessionIdFrom(await auth())(request),\n});\n\n/** The front door, then Git's routes, the drop-in's among them, for outside and the app alike. */\nconst { owned, api } = ingressOf({ gate, git: routeOn(runtime) });\n\n/** Git's own calls, as host calls read them, each an Effect, which the server function runs. */\nconst git = {\n repos: { list: (input) => host(Repos.list(input)) },\n tokens: tokensOn(host),\n} satisfies HostGit;\n\n/**\n * The image proxy (Q860): a text's remote images load through `/_camo/`, and the pages' CSP loads\n * no other. Without it, and with `IMAGE_PROXY=off`, they load from their own origin.\n */\nconst images = imageProxy({\n secret: env.SESSION_SECRET,\n appOrigin: env.APP_ORIGIN,\n setting: env.IMAGE_PROXY,\n fetch: nodeFetch,\n});\n\n/** The host's push rules, as a repo's settings show them. */\nconst rules = shownRules(hostRules);\n\n/** Whether the dev seed runs: `vite.config.ts` sets it true only under the dev server. */\ndeclare const __DEV_SEED__: boolean;\n\nlet seeding: Promise<void> | undefined;\n\n/**\n * In dev only, the seed, once an isolate, before its first answer: Pip and Mo sign up with\n * `DEMO_PASSWORD` and make the demo org `acme`, a host with no repos gets its repos, and a seed cut\n * off finishes. It signs them up in whatever database `AUTH_DB` points at under the dev server,\n * the local D1 unless the host sets `\"remote\": true` on it, so `.dev.vars.example`'s known\n * `DEMO_PASSWORD` is changed before the dev server points at a remote database.\n */\nconst seeded = () => {\n seeding ??= Promise.all([import('./signin/seed-people.ts'), import('./seed/seed.ts')])\n .then(async ([{ seedPeople }, { seed }]) => {\n if (env.DEMO_PASSWORD === undefined) throw new Error('Set DEMO_PASSWORD in .env');\n\n await seedPeople(await auth(), { origin: env.APP_ORIGIN, password: env.DEMO_PASSWORD });\n\n return seed({\n fetch: api,\n origin: env.APP_ORIGIN,\n adminToken: env.ADMIN_TOKEN,\n // Git's records, on its runtime, keep the seed's progress beside Git's own.\n store: {\n read: (scope, reads) => runtime.runPromise(Records.read(scope, reads)),\n commit: (scope, change) => runtime.runPromise(Records.commit(scope, change)),\n },\n });\n })\n .then(\n () => undefined,\n (cause: unknown) =>\n runtime.runPromise(\n Effect.logError('The seed stopped, and goes on at the next start', cause),\n ),\n );\n\n return seeding;\n};\n\n/** Q8's order: the drop-in, then Git, then the app. A URL one owns never falls through. */\nexport default createServerEntry({\n fetch: images.around(async (incoming) => {\n // A host session is the app's server's to set in this Worker, never a caller's to send\n // (Q520): every route, the APIs, the app and any upgrade, sees the request without one.\n // The caller's address, for the rate limit, set by this server in place of any the caller sent.\n const request = withoutHostSession(withClientIp(incoming, env.CLIENT_IP_HEADER));\n if (__DEV_SEED__) await seeded();\n\n const answered = await owned(request);\n if (answered !== undefined) return answered;\n\n const context: AppContext = {\n api,\n sealKey: await sessionKey,\n // Better Auth is made only for a request that reads it, and checked in that request (#480).\n auth: async (each) => (await auth()).handler(each),\n session: async (each) => sessionFrom(await auth(), sessionKey)(each),\n endSession: async (each) => sessionEnder(await auth())(each),\n sessionCookie: async () => sessionCookieOf(await auth())(),\n // The server functions' own edge: who a credential names, as their Promise reads it.\n identify: (each) =>\n runtime.runPromise(\n Effect.match(Git.identify(each), {\n onFailure: (error) => ({ kind: 'error', error }) as const,\n onSuccess: (value) => ({ kind: 'success', value }) as const,\n }),\n ),\n authorize: policy.authorize,\n authorizeGitHub: policy.authorizeGitHub,\n rules,\n avatars: pictures,\n accounts: directory,\n git,\n images,\n };\n\n return handler.fetch(request, { context });\n }),\n});\n",
189
- nodeConfigs: { "tsconfig.json": "// The app's pages, routes, clients and sign-in: DOM, as a browser runs them, and Start's server\n// functions beside them. The server and Git are `tsconfig.server.json`'s, typed by\n// Node's types with no DOM, and the tests `tsconfig.test.json`'s, in Node. Each file is in the\n// one whose globals it runs with, and the root's `tsconfig.json` references all three.\n{\n \"extends\": \"./tsconfig.base.json\",\n \"compilerOptions\": {\n \"composite\": true,\n \"jsx\": \"react-jsx\",\n \"lib\": [\"ES2023\", \"DOM\", \"DOM.Iterable\"],\n \"tsBuildInfoFile\": \"./node_modules/.cache/tsconfig.tsbuildinfo\",\n \"types\": [\"vite-plus/client\"]\n },\n \"include\": [\"src/**/*.ts\", \"src/**/*.tsx\", \"generated/**/*.ts\"],\n \"exclude\": [\n \"src/**/*.test.ts\",\n \"src/**/testing/**\",\n \"src/seed/**\",\n \"src/server.ts\",\n \"src/git.ts\",\n \"src/policy.ts\",\n \"src/env.ts\",\n \"src/signin/approval.ts\",\n \"src/camo/lookup.ts\",\n \"src/camo/node.ts\",\n \"src/markdown/words-plugin.ts\"\n ]\n}\n" },
190
- nodeServerConfig: "// The server, typed as Node runs it: Node's globals and no DOM. The pages are `tsconfig.json`'s,\n// and the files both run, sealing and names, are in each.\n{\n \"extends\": \"./tsconfig.base.json\",\n \"compilerOptions\": {\n \"composite\": true,\n \"lib\": [\"ES2023\"],\n \"tsBuildInfoFile\": \"./node_modules/.cache/tsconfig.server.tsbuildinfo\",\n \"types\": [\"node\", \"vite-plus/client\"]\n },\n \"include\": [\n \"src/server.ts\",\n \"src/camo/lookup.ts\",\n \"src/camo/node.ts\",\n \"server/**/*.ts\",\n \"scripts/**/*.ts\",\n \"src/git.ts\",\n \"src/policy.ts\",\n \"src/env.ts\",\n \"src/context/**/*.ts\",\n \"src/names/**/*.ts\",\n \"src/seed/**/*.ts\",\n \"src/signin/approval.ts\",\n \"src/signin/seal.ts\"\n ],\n \"exclude\": [\"src/**/*.test.ts\", \"src/seed/testing/built-app.ts\"]\n}\n",
191
- nodeVite: "import tailwindcss from '@tailwindcss/vite';\nimport { tanstackStart } from '@tanstack/react-start/plugin/vite';\nimport viteReact from '@vitejs/plugin-react';\nimport { nitro } from 'nitro/vite';\nimport { defineConfig } from 'vite-plus';\n\nimport { wordsMemoryMax } from './src/markdown/words-plugin.ts';\n\n// Start's server build runs in Node through Nitro, which scans `server/` for the jobs' plugin.\nexport default defineConfig(({ command }) => ({\n // The dev seed is on only under the dev server, `vp dev`: every build drops it and its imports,\n // whatever its mode or `NODE_ENV`.\n define: { __DEV_SEED__: JSON.stringify(command === 'serve') },\n // The diff and highlight Workers are modules: `@pierre/diffs`' loads its highlighter lazily.\n worker: { format: 'es' },\n plugins: [\n // Words' WebAssembly under the drop-in's most on its memory (#1098): in Node, the module is\n // compiled at load from words' own bytes, edited.\n wordsMemoryMax(),\n tanstackStart({\n // NodeNext, as the repo types it, resolves only imports that name their extension.\n router: { generatedRouteTree: '../generated/routeTree.gen.ts', addExtensions: true },\n }),\n nitro({ serverDir: './server' }),\n viteReact(),\n tailwindcss(),\n ],\n}));\n",
192
130
  workerGit: [
193
131
  {
194
132
  "slot": "header",
@@ -311,59 +249,36 @@ var templates_default = {
311
249
  },
312
250
  " \"migrations\": [{ \"tag\": \"v1\", \"new_sqlite_classes\": [\"Records\", \"Jobs\"] }],\n}\n"
313
251
  ],
314
- platforms: {
315
- "cloudflare": {
316
- "secrets": ["ADMIN_TOKEN", "SESSION_SECRET"],
317
- "bound": [
318
- "RECORDS",
319
- "JOBS",
320
- "PACKS",
321
- "PACKS_BUCKET",
322
- "AUTH_DB",
323
- "APP_ORIGIN"
324
- ],
325
- "optional": [
326
- "SIGN_UP",
327
- "IMAGE_PROXY",
328
- "R2_ACCOUNT_ID",
329
- "R2_ACCESS_KEY_ID",
330
- "R2_SECRET_ACCESS_KEY",
331
- "CLIENT_IP_HEADER"
332
- ],
333
- "signing": [
334
- "R2_ACCOUNT_ID",
335
- "R2_ACCESS_KEY_ID",
336
- "R2_SECRET_ACCESS_KEY"
337
- ],
338
- "dev": ["DEMO_PASSWORD"],
339
- "secretFile": ".dev.vars",
340
- "database": {
341
- "binding": "AUTH_DB",
342
- "migrations": "migrations/sql"
343
- }
344
- },
345
- "node": {
346
- "required": [
347
- "ADMIN_TOKEN",
348
- "SESSION_SECRET",
349
- "APP_ORIGIN"
350
- ],
351
- "secrets": ["ADMIN_TOKEN", "SESSION_SECRET"],
352
- "optional": [
353
- "SIGN_UP",
354
- "IMAGE_PROXY",
355
- "CLIENT_IP_HEADER"
356
- ],
357
- "dev": ["DEMO_PASSWORD"],
358
- "secretFile": ".env",
359
- "database": {
360
- "file": ".data/auth.db",
361
- "migrations": "migrations"
362
- },
363
- "entry": "src/server.ts",
364
- "jobs": "server/plugins/jobs.ts"
252
+ platforms: { "cloudflare": {
253
+ "secrets": ["ADMIN_TOKEN", "SESSION_SECRET"],
254
+ "bound": [
255
+ "RECORDS",
256
+ "JOBS",
257
+ "PACKS",
258
+ "PACKS_BUCKET",
259
+ "AUTH_DB",
260
+ "APP_ORIGIN"
261
+ ],
262
+ "optional": [
263
+ "SIGN_UP",
264
+ "IMAGE_PROXY",
265
+ "R2_ACCOUNT_ID",
266
+ "R2_ACCESS_KEY_ID",
267
+ "R2_SECRET_ACCESS_KEY",
268
+ "CLIENT_IP_HEADER"
269
+ ],
270
+ "signing": [
271
+ "R2_ACCOUNT_ID",
272
+ "R2_ACCESS_KEY_ID",
273
+ "R2_SECRET_ACCESS_KEY"
274
+ ],
275
+ "dev": ["DEMO_PASSWORD"],
276
+ "secretFile": ".dev.vars",
277
+ "database": {
278
+ "binding": "AUTH_DB",
279
+ "migrations": "migrations/sql"
365
280
  }
366
- },
281
+ } },
367
282
  appYours: [
368
283
  ["`src/policy.ts`", "Who may read and write what: by default, anyone reads a public repo, a person writes under their own login, an org's members write under its login, and a repo is made only under a login someone holds"],
369
284
  ["`src/git.ts`", "Git's features and the drop-in's, a line each: each repo's `main` has a merge queue beside the merge button, and the checks the queue waits on"],
@@ -0,0 +1,87 @@
1
+ import * as Effect from "effect/Effect";
2
+ // src/init/vercel-regions.ts
3
+ /**
4
+ * The regions `--region` takes: where Neon's Postgres, a Vercel Blob store, the Functions and a
5
+ * Daemon can all sit together. Vercel's CLI 68 makes Neon in these alone
6
+ * (`vercel integration add neon --meta region=<region>`), and each is one a Daemon's `instances`
7
+ * and Blob's `create-store --region` take, so each request and job reaches its stores in-region.
8
+ */
9
+ const vercelRegions = [
10
+ "cle1",
11
+ "fra1",
12
+ "gru1",
13
+ "iad1",
14
+ "lhr1",
15
+ "pdx1",
16
+ "sin1",
17
+ "syd1"
18
+ ];
19
+ /** `value`, when it names one of `vercelRegions`. */
20
+ const regionNamed = (value) => vercelRegions.find((region) => region === value);
21
+ /** The Vercel region beside each AWS region Neon makes a database in, for the eight above. */
22
+ const besideNeon = {
23
+ "us-east-1": "iad1",
24
+ "us-east-2": "cle1",
25
+ "us-west-2": "pdx1",
26
+ "eu-central-1": "fra1",
27
+ "eu-west-2": "lhr1",
28
+ "sa-east-1": "gru1",
29
+ "ap-southeast-1": "sin1",
30
+ "ap-southeast-2": "syd1"
31
+ };
32
+ /** Where each region is, as the prompt says it, by the city Vercel names. */
33
+ const places = {
34
+ cle1: "Cleveland, US",
35
+ fra1: "Frankfurt, Germany",
36
+ gru1: "São Paulo, Brazil",
37
+ iad1: "Washington, D.C., US",
38
+ lhr1: "London, UK",
39
+ pdx1: "Portland, US",
40
+ sin1: "Singapore",
41
+ syd1: "Sydney, Australia"
42
+ };
43
+ /**
44
+ * The region of the Neon database at `url`, read from its host, as `ep-….c-5.us-west-2.aws.neon.tech`,
45
+ * with the Vercel region beside it: undefined for a URL that isn't one of Neon's on AWS.
46
+ */
47
+ const neonRegionOf = (url) => {
48
+ const host = URL.parse(url)?.hostname ?? "";
49
+ const aws = /\.([a-z]{2}-[a-z]+-\d)\.aws\.neon\.tech$/.exec(host)?.[1];
50
+ const beside = aws === void 0 ? void 0 : Object.entries(besideNeon).find(([each]) => each === aws)?.[1];
51
+ return aws === void 0 || beside === void 0 ? void 0 : {
52
+ aws,
53
+ beside
54
+ };
55
+ };
56
+ /** The prompt's question, which says where to put the region, since a store's is fixed when it's made. */
57
+ const regionQuestion = "Which region? Pick the one your database and Blob store are in, or will be: a store's region is fixed when it's made";
58
+ /** Each region as the prompt offers it: its city, and the Neon region beside it. */
59
+ const regionOffers = vercelRegions.map((region) => ({
60
+ value: region,
61
+ says: `${region}, ${places[region]}`,
62
+ why: `Neon's ${Object.entries(besideNeon).find(([, beside]) => beside === region)?.[0] ?? region}`
63
+ }));
64
+ /** Why `init` stops on Vercel with no region: it has none to take unasked. */
65
+ const regionNotGiven = {
66
+ reason: "region_not_given",
67
+ headline: `On Vercel, init takes --region, where your database and Blob store are or will be, since a store's region is fixed when it's made: ${vercelRegions.join(", ")}`
68
+ };
69
+ /**
70
+ * The region the Functions and the Daemon run in: `--region`'s, else the one `vercel.json` holds,
71
+ * else `ask`'s answer. There's no default, since a store's region is fixed when it's made and one
72
+ * taken unasked can put the Functions apart from it: with no `ask`, or no answer, it's refused.
73
+ */
74
+ const settleRegion = /* @__PURE__ */ Effect.fnUntraced(function* (flag, held, ask) {
75
+ if (flag !== void 0) return {
76
+ value: flag,
77
+ from: "flag"
78
+ };
79
+ if (held !== void 0) return held;
80
+ const asked = regionNamed(ask === void 0 ? void 0 : yield* ask(regionOffers));
81
+ if (asked === void 0) return yield* Effect.fail(regionNotGiven);
82
+ return {
83
+ value: asked,
84
+ from: "prompt"
85
+ };
86
+ });
87
+ export { neonRegionOf, regionNamed, regionNotGiven, regionOffers, regionQuestion, settleRegion, vercelRegions };