Cotton code
204 lines · 16.7 KB · JSONRaw
{  "$schema": "node_modules/wrangler/config-schema.json",  // The business Worker (coordinator, 24 Oct 2026, from the review session's  // decisions in Cotton memory [business-apps-run-on-cloudflare-…]): one  // Worker for every business, one Durable Object with its own SQLite per  // business, R2 for photos. The hostname's first label names the business  // (sharmila.<domain> → the object "sharmila"); in development the path  // prefix /b/<slug> does the same. No D1: two businesses need no registry.  "name": "cottondb",  "main": "src/index.ts",  "compatibility_date": "2026-08-01",  "compatibility_flags": ["nodejs_compat"],  "workers_dev": true,  // Hosts: a business answers on <slug>.cottondb.com, named by its first  // label, and gets its route here when it goes live; Cloudflare makes the  // record and the certificate. workers.dev stays for the /b/<slug> prefix.  // The open host (owner, 26 Oct 2026): cottondb.com is every person's one  // address, where the sign-in and the bearer name the object (src/open.ts).  "routes": [    { "pattern": "cottondb.com", "custom_domain": true }  ],  // The version answering (storage_summary's `worker`): which deploy a reply came from.  "version_metadata": { "binding": "CF_VERSION_METADATA" },  // The site (owner, 27 Oct 2026): cottondb.com is the public site's address  // too, and a hostname has one Worker, so this one holds it and hands the  // site Worker every request that is not the open door's own (src/open.ts  // `forSite`), over this binding, no DNS. cotton-site keeps www.cottondb.com  // and cotton.tinmen.ai, which it 308s here. Locally both run in one session:  // `wrangler dev -c wrangler.jsonc -c ../cotton-site/wrangler.jsonc  // --local-upstream cottondb.com` after the site's `pnpm build`. The dev  // Worker (`env.dev`) binds no SITE (a binding is not inherited), so its  // site paths answer 503.  "services": [{ "binding": "SITE", "service": "cotton-site" }],  "observability": { "enabled": true },  "vars": {    "ENV_LABEL": "production",    // ADMIN KEYS 3 (src/env.ts keyDefault): a new key or connection gets no allow list, as before allows. The owner    // flips this to "narrow" once the phones have the Assistants screen.    "KEY_DEFAULT": "today",    // Your Claude's standing grant (src/agent.ts): on for live at the owner's word, 21 Nov 2026.    "AGENT_GRANT": "on",    "OPEN_HOST": "cottondb.com",    // Written by `pnpm -s passkey:associations` from apps/registry.json; never by hand.    "APPLE_APP_SITE_ASSOCIATION": "{\"webcredentials\":{\"apps\":[\"M7V3QVXZQH.com.cottondb.books\",\"M7V3QVXZQH.com.cottondb.cinemas\",\"M7V3QVXZQH.com.cottondb.downloads\",\"M7V3QVXZQH.com.cottondb.keys\",\"M7V3QVXZQH.com.cottondb.notes\",\"M7V3QVXZQH.com.cottondb.messages\",\"M7V3QVXZQH.com.cottondb.health\",\"M7V3QVXZQH.com.cottondb.story\",\"M7V3QVXZQH.com.cottondb.calendar\",\"M7V3QVXZQH.com.cottondb.meetings\",\"M7V3QVXZQH.com.cottondb.data\",\"M7V3QVXZQH.com.cottondb.sites\",\"M7V3QVXZQH.com.cottondb.mail\",\"M7V3QVXZQH.com.cottondb.albums\",\"M7V3QVXZQH.com.cottondb.contacts\"]},\"applinks\":{\"details\":[{\"appIDs\":[\"M7V3QVXZQH.com.cottondb.messages\",\"M7V3QVXZQH.com.cottondb.contacts\"],\"components\":[{\"/\":\"/c/*\"}]}]}}",    "ANDROID_ASSET_LINKS": "[{\"relation\":[\"delegate_permission/common.get_login_creds\"],\"target\":{\"namespace\":\"android_app\",\"package_name\":\"com.cottondb.books\",\"sha256_cert_fingerprints\":[\"39:0A:E4:85:7F:60:CE:BD:83:47:CB:F6:18:4D:E9:B8:B4:00:45:2C:3F:51:66:C0:70:66:52:5F:73:1E:16:31\"]}},{\"relation\":[\"delegate_permission/common.get_login_creds\"],\"target\":{\"namespace\":\"android_app\",\"package_name\":\"com.cottondb.cinemas\",\"sha256_cert_fingerprints\":[\"65:86:53:F5:65:0A:6C:C1:2D:5F:0A:42:7B:F7:43:ED:6E:FA:57:45:8D:AE:43:97:A6:28:53:A4:AC:FE:F8:FD\"]}},{\"relation\":[\"delegate_permission/common.get_login_creds\"],\"target\":{\"namespace\":\"android_app\",\"package_name\":\"com.cottondb.downloads\",\"sha256_cert_fingerprints\":[\"EA:F0:77:79:F2:E1:29:55:28:70:C7:09:73:E8:B2:E3:B1:88:D7:70:D4:6F:FB:9A:11:BE:E9:B9:55:88:38:4E\"]}},{\"relation\":[\"delegate_permission/common.get_login_creds\"],\"target\":{\"namespace\":\"android_app\",\"package_name\":\"com.cottondb.keys\",\"sha256_cert_fingerprints\":[\"06:69:52:0F:F4:D4:B0:DA:9A:23:75:8F:14:B7:69:C5:4A:4C:3B:6F:E5:5D:73:12:B2:BF:B7:11:C3:35:F9:A5\"]}},{\"relation\":[\"delegate_permission/common.get_login_creds\"],\"target\":{\"namespace\":\"android_app\",\"package_name\":\"com.cottondb.notes\",\"sha256_cert_fingerprints\":[\"9C:3E:A5:67:32:3B:5C:92:61:B2:3D:AE:12:C4:93:16:19:94:B0:EE:3E:8D:93:20:7E:FD:70:CD:F2:1E:45:5F\"]}},{\"relation\":[\"delegate_permission/common.get_login_creds\",\"delegate_permission/common.handle_all_urls\"],\"target\":{\"namespace\":\"android_app\",\"package_name\":\"com.cottondb.messages\",\"sha256_cert_fingerprints\":[\"18:F8:05:3D:9F:92:2F:26:D2:A1:BB:A2:50:57:BC:13:2D:90:92:9D:0C:25:83:23:20:E5:C1:08:FE:76:F7:B9\"]}},{\"relation\":[\"delegate_permission/common.get_login_creds\"],\"target\":{\"namespace\":\"android_app\",\"package_name\":\"com.cottondb.story\",\"sha256_cert_fingerprints\":[\"A2:AB:8C:D3:CC:00:D8:5B:1C:48:01:2D:47:A7:80:D3:9B:46:75:91:7A:D9:C6:05:69:DF:19:B0:6C:2E:FC:FE\"]}},{\"relation\":[\"delegate_permission/common.get_login_creds\"],\"target\":{\"namespace\":\"android_app\",\"package_name\":\"com.cottondb.meetings\",\"sha256_cert_fingerprints\":[\"2B:AE:FD:70:E6:64:34:76:FC:B6:79:88:9B:4E:52:7C:23:E7:EE:25:09:F2:25:BB:1D:9B:BA:7E:4F:03:AB:AC\"]}}]",    "PASSKEY_ANDROID_ORIGINS": "android:apk-key-hash:OQrkhX9gzr2DR8v2GE3puLQARSw_UWbAcGZSX3MeFjE,android:apk-key-hash:ZYZT9WUKbMEtXwpCe_dD7W76V0WNrkOXpihTpKz--P0,android:apk-key-hash:6vB3efLhKVUocMcJc-iy47GI13DUb_uaEb7puVWIOE4,android:apk-key-hash:BmlSD_TUsNqaI3WPFLdpxUpMO2_lXXMSsr-3EcM1-aU,android:apk-key-hash:nD6lZzI7XJJhsj2uEsSTFhmUsO4-jZMgfv1wzfIeRV8,android:apk-key-hash:GPgFPZ-SLybSobuiUFe8Ey2Qkp0MJYMjIOXBCP5297k,android:apk-key-hash:oquM08wA2FscSAEtR6eA05tGdZF62cYFad8ZsGwu_P4,android:apk-key-hash:K679cOZkNHb8tnmIm05SfCPn7iUJ8iW7HZu6fk8Dq6w",    // Phone-and-OTP sign-in (owner, 13 Nov 2026): live sends every code    // through Twilio Verify, secrets TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN and    // TWILIO_VERIFY_SID. The numbers the secret OTP_TEST_CODES names (a JSON    // object, E.164 number → six-digit code) prove their own code and never    // reach Twilio. `fixed` (every code the secret OTP_FIXED_CODE) runs on the    // dev Worker alone; src/auth.ts refuses it wherever ENV_LABEL is not dev.    // Guard: scripts/__tests__/wrangler-envs.test.ts.    "OTP_MODE": "twilio",    // Deleting an account (src/account_delete.ts `switchedOn`): ON on live (owner, 25 Nov 2026: every app has a way to    // ask, and we delete in 30 days), after the thirty days were proven at head (assets/design/shared/DELETE-GO-LIVE.md).    // Only `on` switches it on; `off` stops new deletions and leaves those asked to erase on their date.    "ACCOUNT_DELETE": "on",    // Space for photos and files (src/space.ts, assets/design/shared/SPACE.md): off on live until the coordinator    // throws it; `count` starts counting days and friends, `on` holds the rules. Only those two words do anything.    "SPACE_RULES": "off"    // No `define` of __SHARED_SPACES__ here, on purpose: the shared spaces are shut on live, and only a build of the    // dev Worker (its own `define` below) opens them; no var or secret can (src/space/switch.ts). Guard:    // scripts/__tests__/wrangler-envs.test.ts.  },  "durable_objects": {    "bindings": [      { "name": "BUSINESS", "class_name": "Business" },      { "name": "DIRECTORY", "class_name": "Directory" },      { "name": "CALLROOM", "class_name": "CallRoom" },      { "name": "PUBLISHED", "class_name": "Published" },      // A shared space (src/space/space.ts): one object per space, on nobody's own object.      { "name": "SPACES", "class_name": "Space" }    ]  },  // v2: the directory, which number owns which database (src/directory.ts).  "migrations": [    { "tag": "v1", "new_sqlite_classes": ["Business"] },    { "tag": "v2", "new_sqlite_classes": ["Directory"] },    { "tag": "v3", "new_sqlite_classes": ["CallRoom"] },    { "tag": "v4", "new_sqlite_classes": ["Published"] },    { "tag": "v5", "new_sqlite_classes": ["Space"] }  ],  // JOBS OUT 1 (src/jobs/run.ts, assets/design/shared/JOBS-OUT.md): the background jobs' queue, one run of one job a  // message, each with the consumer's 15 minutes to itself. The account object alone puts a run on it (with the run's  // credential, signed by the secret JOB_TOKEN_KEY); the watchdog on its alarm asks again for a run the queue lost.  // Made by the coordinator before the first deploy that carries it: `wrangler queues create cotton-jobs` and  // `cotton-jobs-dead`.  // JOBS OUT 4, the dead-man check (src/alarm_watch.ts): every 5 minutes each account's alarm is looked at from outside  // its object, and one standing more than 10 minutes in the past is set again.  "triggers": { "crons": ["*/5 * * * *"] },  "queues": {    "producers": [{ "binding": "JOBS", "queue": "cotton-jobs" }],    "consumers": [{ "queue": "cotton-jobs", "max_batch_size": 1, "max_batch_timeout": 1, "max_retries": 5, "retry_delay": 60, "max_concurrency": 50, "dead_letter_queue": "cotton-jobs-dead" }]  },  // Reads of the published databases (src/published.ts): each signed-in  // database may make `limit` a minute, counted by Cloudflare and kept nowhere.  "ratelimits": [    { "name": "PUBLISHED_READS", "namespace_id": "1401", "simple": { "limit": 600, "period": 60 } }  ],  // PHOTOS: the businesses' public photos. MEDIA: the personal database's  // media, the owner's alone (src/media.ts) — made in APAC by the coordinator  // before the first deploy that carries it. IMAGES draws an image at a size.  "r2_buckets": [    { "binding": "PHOTOS", "bucket_name": "cotton-business-photos-apac" },    { "binding": "MEDIA", "bucket_name": "cotton-personal-media-apac" }  ],  "images": { "binding": "IMAGES" },  // ASSETS: the kits' fan tile pictures, `/kit-pictures/<sha256>.png`, served  // by the object as `photo:<sha256>` (src/media.ts `kitPicture`) and never  // from the bundle. The folder is generated and gitignored: `pnpm -s kit`  // writes it, and `pnpm worker:deploy` runs that before wrangler. The Worker  // runs first on every request, so no path of the host is an asset's: the  // binding is the only way in.  "assets": { "directory": "./assets", "binding": "ASSETS", "run_worker_first": true },  // Workers AI (owner, 29 Oct 2026): the calendar engine embeds an event's  // words to judge its kind (src/calendar_engine.ts). Under `wrangler dev` it  // runs remotely, on the account; a development object may name  // KIND_EMBEDDINGS_URL in its place, the same model served locally.  "ai": { "binding": "AI" },  // THE DEV WORKER (owner, 29 Oct 2026): `pnpm run deploy:dev` deploys this  // env as its own Worker, cottondb-dev, which every session deploys  // freely and Cotton Dev signs in to; the live Worker above is deployed only  // together with a phone build. An env's Worker is another script, so it has  // its own Durable Object namespaces, the migrations above inherited and run  // there from v1; its own buckets; no custom domain (`routes` IS inherited,  // so it is emptied here). Its one host, its workers.dev address, is its  // open host: the sign-in and the bearer name the object there as on  // cottondb.com, and `/b/<slug>` still names a business (`pnpm onboard`). No  // SITE. Secrets by the live Worker's names, each a value  // of its own (`wrangler secret put <NAME> --env dev`): OTP_FIXED_CODE (the  // vault's cotton/dev-otp; OTP_MODE stays `fixed` here alone), OTP_TEST_CODES if any, ADMIN_TOKEN (cloudflare/business-dev-admin-token),  // VAULT_KEY (cloudflare/dev-vault-key), SERVICE_TOKEN_KEY (the Google  // and Spotify refresh tokens, src/vault.ts t1; cloudflare/dev-service-token-key),  // WINDOW_KEY (an unlock window's keys at rest, src/window.ts), STREAM_SIGNING_KEY (a film's stream  // URL, src/media.ts); no Google client, whose one redirect  // is cottondb.com's. Spotify (src/spotify.ts) on either Worker:  // SPOTIFY_CLIENT_ID and SPOTIFY_CLIENT_SECRET, both put as secrets so a  // deploy keeps them; the Spotify app registers each Worker's  // https://<OPEN_HOST>/v1/spotify/callback. Guard: scripts/__tests__/wrangler-envs.test.ts.  "env": {    "dev": {      "routes": [],      "workers_dev": true,      "version_metadata": { "binding": "CF_VERSION_METADATA" },      "vars": {        "ENV_LABEL": "dev",        // ADMIN KEYS 3 (src/env.ts keyDefault): a new key or connection gets key_allow's DEFAULT_ALLOW.        "KEY_DEFAULT": "narrow",        // OPEN_HOST (its workers.dev host) and GOOGLE_BASE are not written here: the dev deploy        // (`pnpm run deploy:dev`, scripts/deploy.ts) passes them from config/dev-server.json.        // Written by `pnpm -s passkey:associations` from apps/registry.json; never by hand.        "APPLE_APP_SITE_ASSOCIATION": "{\"webcredentials\":{\"apps\":[\"M7V3QVXZQH.com.cottondb.books.dev\",\"M7V3QVXZQH.com.cottondb.cinemas.dev\",\"M7V3QVXZQH.com.cottondb.downloads.dev\",\"M7V3QVXZQH.com.cottondb.keys.dev\",\"M7V3QVXZQH.com.cottondb.notes.dev\",\"M7V3QVXZQH.com.cottondb.messages.dev\",\"M7V3QVXZQH.com.cottondb.health.dev\",\"M7V3QVXZQH.com.cottondb.story.dev\",\"M7V3QVXZQH.com.cottondb.calendar.dev\",\"M7V3QVXZQH.com.cottondb.meetings.dev\",\"M7V3QVXZQH.com.cottondb.data.dev\",\"M7V3QVXZQH.com.cottondb.sites.dev\",\"M7V3QVXZQH.com.cottondb.mail.dev\",\"M7V3QVXZQH.com.cottondb.albums.dev\",\"M7V3QVXZQH.com.cottondb.contacts.dev\"]},\"applinks\":{\"details\":[{\"appIDs\":[\"M7V3QVXZQH.com.cottondb.messages.dev\",\"M7V3QVXZQH.com.cottondb.contacts.dev\"],\"components\":[{\"/\":\"/c/*\"}]}]}}",        // GOOGLE_BASE, the fake Google (src/fake_google, wrangler.fake-google.jsonc) until the real OAuth client exists        // (GCAL READY, 24 Nov 2026; assets/design/days/GCAL-GO-LIVE.md), comes from config/dev-server.json's fakeGoogleHost        // at the dev deploy. Honoured on dev and test alone; take it out of that file for the real Google.        // Your Claude's standing grant (src/agent.ts), on the dev Worker only until it is proven there; the live Worker keeps the windows as they were.        "AGENT_GRANT": "on",        // New personal databases born with both locks on (src/business.ts provision). Live waits for the phone builds whose        // top_up hands every sealed table (HANDING STUCK, 25 Nov 2026): a new account's Connect Claude must hand the session keys.        "LOCKS_AT_BIRTH": "on",        "OTP_MODE": "fixed",        // Deleting an account, on for dev alone (src/account_delete.ts `switchedOn`).        "ACCOUNT_DELETE": "on",        // Space for photos and files: off on dev too; an invented account is tried by its own mode (POST /v1/admin/space/mode)."SPACE_RULES": "off",        // Every walk on every Mac signs in from one office IP (src/directory.ts `limitsFor`).        "SIGN_IN_ATTEMPTS_PER_HOUR": "500",        "SIGN_UPS_PER_HOUR": "100",        // A walk erases and signs in the same number several times an hour (src/auth.ts `codesPerHour`).        "CODES_PER_HOUR": "100"      },      // The shared spaces, built on for the dev Worker alone (src/space/switch.ts).      "define": { "__SHARED_SPACES__": "\"on\"" },      "durable_objects": {        "bindings": [          { "name": "BUSINESS", "class_name": "Business" },          { "name": "DIRECTORY", "class_name": "Directory" },          { "name": "CALLROOM", "class_name": "CallRoom" },          { "name": "PUBLISHED", "class_name": "Published" },          { "name": "SPACES", "class_name": "Space" }        ]      },      // JOBS OUT 1: the dev Worker's own jobs queue (a binding is not inherited). `wrangler queues create cotton-dev-jobs`      // and `cotton-dev-jobs-dead`; its secret JOB_TOKEN_KEY by `wrangler secret put JOB_TOKEN_KEY --env dev`.      // JOBS OUT 4: triggers are not inherited either.      "triggers": { "crons": ["*/5 * * * *"] },      "queues": {        "producers": [{ "binding": "JOBS", "queue": "cotton-dev-jobs" }],        "consumers": [{ "queue": "cotton-dev-jobs", "max_batch_size": 1, "max_batch_timeout": 1, "max_retries": 5, "retry_delay": 60, "max_concurrency": 50, "dead_letter_queue": "cotton-dev-jobs-dead" }]      },      "ratelimits": [        { "name": "PUBLISHED_READS", "namespace_id": "1402", "simple": { "limit": 600, "period": 60 } }      ],      "r2_buckets": [        { "binding": "PHOTOS", "bucket_name": "cotton-dev-photos-apac" },        { "binding": "MEDIA", "bucket_name": "cotton-dev-media-apac" }      ],      "images": { "binding": "IMAGES" },      "assets": { "directory": "./assets", "binding": "ASSETS", "run_worker_first": true },      "ai": { "binding": "AI" }    }  }}