| 1 | // Stand-ins for identity, events, security and billing, so the repos |
| 2 | // service answers anonymous git requests with `wrangler dev` (repos.jsonc). |
| 3 | // |
| 4 | // - Identity knows one person, `dev` (secret `dev-push-secret`), the owner |
| 5 | // of the `acme` workspace, so pushes can be tried (push-check.mjs); any |
| 6 | // other credentials name no one, and no workspace was renamed or |
| 7 | // aliased. Public repositories can be cloned without signing in. |
| 8 | // - Events takes every event and audit entry and logs them. |
| 9 | // - Security has allowed no secrets; billing says every workspace is free. |
| 10 | |
| 11 | export default { |
| 12 | async fetch(request) { |
| 13 | const method = new URL(request.url).pathname.replace(/^\/rpc\//, ""); |
| 14 | const args = await request.json().catch(() => ({})); |
| 15 | const json = (value) => Response.json(value); |
| 16 | switch (method) { |
| 17 | case "user_for_git_credentials": |
| 18 | return json( |
| 19 | args.username === "dev" && args.secret === "dev-push-secret" |
| 20 | ? { id: "usr_dev", username: "dev", kind: "user", verified: true, workspaces: [{ slug: "acme", role: "owner" }] } |
| 21 | : null, |
| 22 | ); |
| 23 | case "resolve_slug": |
| 24 | case "resolve_alias": |
| 25 | return json(null); |
| 26 | case "is_free": |
| 27 | case "plan": |
| 28 | return json({ free: true }); |
| 29 | default: |
| 30 | console.log(`stub ${method}`, JSON.stringify(args).slice(0, 200)); |
| 31 | return json(null); |
| 32 | } |
| 33 | }, |
| 34 | }; |