|
| 1 | +# Ourmoji — Home-Server Agent Setup |
| 2 | + |
| 3 | +How to configure an external agent (running on your home server) to post the |
| 4 | +daily Ourmoji oracle on behalf of multiple users. |
| 5 | + |
| 6 | +The agent authenticates as the project owner using a single long-lived API key |
| 7 | +with admin scope, and posts to an admin-only endpoint that accepts a target |
| 8 | +`userId`. No per-user session cookies or per-user keys are needed. |
| 9 | + |
| 10 | +Production base URL: `https://tada.living` |
| 11 | + |
| 12 | +Replace `https://tada.living` below if running against a different deployment |
| 13 | +(e.g. `http://localhost:3000` for local dev). |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 17 | +## Prerequisites |
| 18 | + |
| 19 | +1. **You are an admin.** Your user id must be listed in the server-side |
| 20 | + `ADMIN_USER_IDS` env var (comma-separated). |
| 21 | +2. **You know both user ids** — Caspar's (yours) and Marian's. |
| 22 | + You can find user ids via `GET https://tada.living/api/v1/admin/users` once |
| 23 | + you have a session, or in the database directly. |
| 24 | +3. **You are logged in to tada in a browser** on the same origin (for the key |
| 25 | + minting step, which requires session auth). |
| 26 | + |
| 27 | +--- |
| 28 | + |
| 29 | +## Step 1 — Mint the API key (browser) |
| 30 | + |
| 31 | +Open the devtools console on any `https://tada.living/*` page while signed in, |
| 32 | +and run: |
| 33 | + |
| 34 | +```js |
| 35 | +await fetch("https://tada.living/api/v1/auth/keys", { |
| 36 | + method: "POST", |
| 37 | + credentials: "include", |
| 38 | + headers: { "Content-Type": "application/json" }, |
| 39 | + body: JSON.stringify({ |
| 40 | + name: "home-server ourmoji agent", |
| 41 | + permissions: ["admin:users:write"], |
| 42 | + }), |
| 43 | +}).then((r) => r.json()); |
| 44 | +``` |
| 45 | + |
| 46 | +The response includes a `key` field of the form `tada_key_…`. **This is the |
| 47 | +only time the plaintext key is ever shown.** Copy it to the home-server agent's |
| 48 | +secret store immediately. If you lose it, revoke and mint a new one. |
| 49 | + |
| 50 | +> `admin:users:write` is the same permission used by the existing admin |
| 51 | +> module-toggle and user-update endpoints. A single key with this scope can |
| 52 | +> post daily Ourmoji for any user, toggle feature flags, update users, reset |
| 53 | +> passwords, clear sessions, etc. Treat it like a root credential — do not |
| 54 | +> share it outside the home-server agent. |
| 55 | +
|
| 56 | +--- |
| 57 | + |
| 58 | +## Step 2 — Enable Ourmoji for each user (one-shot) |
| 59 | + |
| 60 | +The agent can only post for users who have the `ourmoji` module flag turned |
| 61 | +on. Do this once per user from the home server (or anywhere with curl): |
| 62 | + |
| 63 | +**For Caspar (you):** |
| 64 | + |
| 65 | +```bash |
| 66 | +curl -X PATCH https://tada.living/api/v1/admin/users/<CASPAR_USER_ID>/modules \ |
| 67 | + -H "Authorization: Bearer tada_key_…" \ |
| 68 | + -H "Content-Type: application/json" \ |
| 69 | + -d '{"ourmoji": true}' |
| 70 | +``` |
| 71 | + |
| 72 | +**For Marian:** |
| 73 | + |
| 74 | +```bash |
| 75 | +curl -X PATCH https://tada.living/api/v1/admin/users/<MARIAN_USER_ID>/modules \ |
| 76 | + -H "Authorization: Bearer tada_key_…" \ |
| 77 | + -H "Content-Type: application/json" \ |
| 78 | + -d '{"ourmoji": true}' |
| 79 | +``` |
| 80 | + |
| 81 | +A 200 with `{"data": {"enabledModules": {"ourmoji": true, …}}}` confirms the |
| 82 | +flag is set. |
| 83 | + |
| 84 | +--- |
| 85 | + |
| 86 | +## Step 3 — Verify the key (optional) |
| 87 | + |
| 88 | +Quick sanity check from the home server: |
| 89 | + |
| 90 | +```bash |
| 91 | +curl https://tada.living/api/v1/admin/health \ |
| 92 | + -H "Authorization: Bearer tada_key_…" |
| 93 | +``` |
| 94 | + |
| 95 | +Expect a 200. If you get 401, the key is wrong or revoked. If you get 403, |
| 96 | +your user is not in `ADMIN_USER_IDS` on the server. |
| 97 | + |
| 98 | +--- |
| 99 | + |
| 100 | +## Step 4 — Daily posting (what the agent does each morning) |
| 101 | + |
| 102 | +Once per user per day, POST to `/api/v1/admin/ourmoji/daily`: |
| 103 | + |
| 104 | +```bash |
| 105 | +curl -X POST https://tada.living/api/v1/admin/ourmoji/daily \ |
| 106 | + -H "Authorization: Bearer tada_key_…" \ |
| 107 | + -H "Content-Type: application/json" \ |
| 108 | + -d '{ |
| 109 | + "userId": "<CASPAR_USER_ID>", |
| 110 | + "date": "2026-04-21", |
| 111 | + "emoji": "🌙", |
| 112 | + "reflection": "The waning gibbous whispers of release.", |
| 113 | + "moonPhase": "Waning Gibbous", |
| 114 | + "moonIllumination": 75, |
| 115 | + "wheelOfYear": "Beltane", |
| 116 | + "wheelCategory": "fire", |
| 117 | + "timezone": "Europe/London" |
| 118 | + }' |
| 119 | +``` |
| 120 | + |
| 121 | +### Field reference |
| 122 | + |
| 123 | +| Field | Type | Required | Notes | |
| 124 | +|-------|------|----------|-------| |
| 125 | +| `userId` | string | yes | Target user (Caspar or Marian) | |
| 126 | +| `date` | string `YYYY-MM-DD` | yes | Local date the entry belongs to | |
| 127 | +| `emoji` | string (1–16 chars) | yes | Drawn from the 23-emoji Sacred Set | |
| 128 | +| `reflection` | string (≤ 5000 chars) | yes | Poetic reflection text | |
| 129 | +| `moonPhase` | string | yes | e.g. "Waning Gibbous" | |
| 130 | +| `moonIllumination` | number 0–100 | no | Percent illuminated | |
| 131 | +| `wheelOfYear` | string | no | e.g. "Beltane", "Samhain" | |
| 132 | +| `wheelCategory` | string | no | e.g. "fire", "water" | |
| 133 | +| `timezone` | string | yes | IANA zone, e.g. "Europe/London" | |
| 134 | + |
| 135 | +### Idempotency |
| 136 | + |
| 137 | +The endpoint is idempotent per `(userId, date)` — re-posting for the same date |
| 138 | +updates the existing entry rather than creating a duplicate. Safe to retry on |
| 139 | +network failure. |
| 140 | + |
| 141 | +### Response |
| 142 | + |
| 143 | +```json |
| 144 | +{ |
| 145 | + "data": { |
| 146 | + "entry": { |
| 147 | + "id": "…", |
| 148 | + "date": "2026-04-21", |
| 149 | + "emoji": "🌙", |
| 150 | + "reflection": "…", |
| 151 | + "moonPhase": "Waning Gibbous", |
| 152 | + "moonIllumination": 75, |
| 153 | + "wheelOfYear": "Beltane", |
| 154 | + "wheelCategory": "fire", |
| 155 | + "timestamp": "2026-04-21T00:00:00Z", |
| 156 | + "timezone": "Europe/London" |
| 157 | + } |
| 158 | + } |
| 159 | +} |
| 160 | +``` |
| 161 | + |
| 162 | +### Error cases |
| 163 | + |
| 164 | +| Status | Meaning | Fix | |
| 165 | +|--------|---------|-----| |
| 166 | +| 400 | "Target user does not have the ourmoji module enabled" | Run Step 2 for that user | |
| 167 | +| 401 | Missing/invalid Bearer token | Check the key | |
| 168 | +| 403 | Admin check failed | Ensure your user id is in `ADMIN_USER_IDS` | |
| 169 | +| 404 | Target user does not exist | Check the `userId` value | |
| 170 | +| 422 | Validation error | Check the payload shape against the table above | |
| 171 | + |
| 172 | +--- |
| 173 | + |
| 174 | +## Rotating / revoking the key |
| 175 | + |
| 176 | +List your keys (browser console, logged in): |
| 177 | + |
| 178 | +```js |
| 179 | +await fetch("https://tada.living/api/v1/auth/keys", { |
| 180 | + credentials: "include", |
| 181 | +}).then((r) => r.json()); |
| 182 | +``` |
| 183 | + |
| 184 | +Revoke by id: |
| 185 | + |
| 186 | +```js |
| 187 | +await fetch("https://tada.living/api/v1/auth/keys/<KEY_ID>", { |
| 188 | + method: "DELETE", |
| 189 | + credentials: "include", |
| 190 | +}); |
| 191 | +``` |
| 192 | + |
| 193 | +Then redo Step 1 to mint a replacement and swap it into the agent's secret |
| 194 | +store. |
| 195 | + |
| 196 | +--- |
| 197 | + |
| 198 | +## What the agent needs to hold |
| 199 | + |
| 200 | +- Base URL (`https://tada.living`) |
| 201 | +- One Bearer token (`tada_key_…`) |
| 202 | +- Caspar's user id |
| 203 | +- Marian's user id |
| 204 | +- Whatever it uses to compute each day's emoji / moon / Wheel of Year / reflection |
| 205 | + |
| 206 | +That's it — no session cookies, no per-user credentials, no rotation |
| 207 | +co-ordination across users. |
| 208 | + |
| 209 | +--- |
| 210 | + |
| 211 | +[Back to Ourmoji](./ourmoji.md) |
0 commit comments