Add Connections-style word game with puzzle editor

Express + node:sqlite server, vanilla HTML/JS frontend. Daily puzzle by
assigned date, puzzle list, shuffle, one-away hint, shareable emoji
results, and a password-protected admin page to create and edit puzzles.
Answers are checked server-side and never sent before they are solved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aidan Dona 2026-10-08 16:56:34 -05:00
parent 0d3181ec99
commit 4a2309b589
18 changed files with 4286 additions and 0 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
node_modules/
data/

View file

@ -1,2 +1,62 @@
# NT-Connections
A NYT Connections style word game with an admin page for creating puzzles.
## Run locally
Needs Node 22.13+ (uses the built-in `node:sqlite`).
```sh
npm install
ADMIN_PASSWORD=choose-one npm start # PowerShell: $env:ADMIN_PASSWORD="choose-one"; npm start
npm test
```
Open http://localhost:3000. Create puzzles at `/admin`.
| Path | What |
|---|---|
| `/` | Today's puzzle (latest puzzle dated today or earlier) |
| `/puzzles` | Every puzzle whose date has arrived, plus undated ones |
| `/play/:id` | A specific puzzle |
| `/admin` | Log in, then create, edit and delete puzzles |
## Environment
| Var | Default | Notes |
|---|---|---|
| `ADMIN_PASSWORD` | required | Changing it logs out existing sessions |
| `PORT` | `3000` | Server listens on 127.0.0.1 only |
| `DB_PATH` | `./data/games.db` | Back this file up |
| `TZ` | system | Decides what "today" is for the daily puzzle |
## Deploy (VPS + nginx)
systemd unit, `/etc/systemd/system/nt-connections.service`:
```ini
[Service]
WorkingDirectory=/srv/nt-connections
ExecStart=/usr/bin/node server.js
Environment=ADMIN_PASSWORD=change-me
Environment=DB_PATH=/var/lib/nt-connections/games.db
Environment=TZ=America/New_York
Restart=always
User=www-data
[Install]
WantedBy=multi-user.target
```
nginx server block:
```nginx
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
```
Use HTTPS (e.g. certbot). The admin cookie is marked `Secure` behind HTTPS, and the "Share results" copy button needs HTTPS to reach the clipboard.

38
build.md Normal file
View file

@ -0,0 +1,38 @@
## Instructions
- Design: Use design-taste-frontend skill
## Build
- [x] Create a NYT Connections like game
- [x] Give me a page to create, store set games
## Decisions
- **Stack:** Node + Express + SQLite (one DB file), vanilla HTML/JS frontend. Runs with `npm start`.
- **Deploy:** own VPS, behind nginx (reverse proxy to the Node port). DB file lives outside the web root and must be backed up.
- **Storage:** server-side SQLite, shared for all players.
- **Editor access:** admin only. Single password from env var `ADMIN_PASSWORD`; login sets a signed session cookie. All write endpoints require it.
## Game rules (player page)
- 16 words, 4 hidden groups of 4. Groups have a difficulty color: yellow, green, blue, purple.
- Select up to 4 words, submit a guess. Correct group locks in at the top with its name.
- 4 mistakes allowed, then the game ends and reveals remaining groups.
- **Shuffle** button reorders the remaining words.
- **"One away..."** message when a guess has 3 of 4 from one group.
- Repeat guesses are not counted as mistakes.
- **Share results:** copy an emoji grid (🟨🟩🟦🟪 per guess) to clipboard.
## Pages
- `/` — Puzzle of the day: the game whose assigned date is today; if none, the most recent past-dated game.
- `/puzzles` — list of all published games (title, date) to pick and play.
- `/play/:id` — play a specific game.
- `/admin` — login, then create / edit / delete games.
## Editor (admin page)
- Fields: title, date (optional, unique), 4 groups × (name, color, 4 words).
- Validation: exactly 16 words, no duplicates (case-insensitive), every field filled, each color used once.
## Data model
- `games(id, title, date UNIQUE NULL, groups_json, created_at, updated_at)`
- Answers are never sent to the browser before solved: the client posts guesses to `/api/games/:id/guess` and the server returns correct / one-away / wrong.
## Out of scope (for now)
- User accounts, stats/streaks, multiple admins.

71
lib.js Normal file
View file

@ -0,0 +1,71 @@
const COLORS = ['yellow', 'green', 'blue', 'purple'];
const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
const norm = (w) => String(w).trim().toUpperCase();
function isRealDate(s) {
if (!DATE_RE.test(s)) return false;
const d = new Date(s + 'T00:00:00Z');
return !isNaN(d) && d.toISOString().slice(0, 10) === s;
}
// Returns { errors: [...] } or { game: { title, date, groups } } with cleaned values.
function validateGame(input) {
const errors = [];
const title = String(input?.title ?? '').trim();
if (!title) errors.push('Title is required.');
if (title.length > 100) errors.push('Title must be 100 characters or fewer.');
let date = input?.date ? String(input.date).trim() : null;
if (date && !isRealDate(date)) errors.push('Date must be a real date (YYYY-MM-DD).');
const rawGroups = Array.isArray(input?.groups) ? input.groups : [];
if (rawGroups.length !== 4) errors.push('A game needs exactly 4 groups.');
const seen = new Set();
const colors = new Set();
const groups = rawGroups.slice(0, 4).map((g, i) => {
const n = i + 1;
const name = String(g?.name ?? '').trim();
if (!name) errors.push(`Group ${n} needs a name.`);
if (name.length > 80) errors.push(`Group ${n} name must be 80 characters or fewer.`);
const color = g?.color;
if (!COLORS.includes(color)) errors.push(`Group ${n} needs a color.`);
else if (colors.has(color)) errors.push(`Color ${color} is used more than once.`);
colors.add(color);
const words = (Array.isArray(g?.words) ? g.words : []).map(norm);
if (words.length !== 4 || words.some((w) => !w)) errors.push(`Group ${n} needs 4 words.`);
for (const w of words) {
if (w.length > 30) errors.push(`"${w}" is longer than 30 characters.`);
if (w && seen.has(w)) errors.push(`"${w}" appears more than once.`);
seen.add(w);
}
return { name, color, words };
});
return errors.length ? { errors: [...new Set(errors)] } : { game: { title, date, groups } };
}
// Returns { result: 'correct', group } | { result: 'one-away' } | { result: 'wrong' } | { error }
function checkGuess(groups, guess) {
const words = Array.isArray(guess) ? [...new Set(guess.map(norm))] : [];
if (words.length !== 4) return { error: 'Pick 4 different words.' };
let best = 0;
for (const g of groups) {
const hits = words.filter((w) => g.words.includes(w)).length;
if (hits === 4) return { result: 'correct', group: g };
best = Math.max(best, hits);
}
return { result: best === 3 ? 'one-away' : 'wrong' };
}
function shuffle(arr) {
const a = [...arr];
for (let i = a.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[a[i], a[j]] = [a[j], a[i]];
}
return a;
}
module.exports = { COLORS, isRealDate, validateGame, checkGuess, shuffle };

907
package-lock.json generated Normal file
View file

@ -0,0 +1,907 @@
{
"name": "nt-connections",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "nt-connections",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"@fontsource/outfit": "^5.3.0",
"@phosphor-icons/web": "^2.1.2",
"express": "^5.2.1"
}
},
"node_modules/@fontsource/outfit": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/@fontsource/outfit/-/outfit-5.3.0.tgz",
"integrity": "sha512-0AVHzTTVJSxWDOxPKSfMeHhZeBFDU3cmgrcOb76ZEyhGo0+xgyG3GsLF3h9+X8w0IX7G4jzjJgFQEBiWdX6VgA==",
"license": "OFL-1.1",
"funding": {
"url": "https://github.com/sponsors/ayuhito"
}
},
"node_modules/@phosphor-icons/web": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/@phosphor-icons/web/-/web-2.1.2.tgz",
"integrity": "sha512-rPAR9o/bEcp4Cw4DEeZHXf+nlGCMNGkNDRizYHM47NLxz9vvEHp/Tt6FMK1NcWadzw/pFDPnRBGi/ofRya958A==",
"license": "MIT"
},
"node_modules/accepts": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz",
"integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==",
"license": "MIT",
"dependencies": {
"mime-types": "^3.0.0",
"negotiator": "^1.0.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/body-parser": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.3.0.tgz",
"integrity": "sha512-2cGmJupaNgg+QUwVLAucDuWuoMZ6EX9iHDRswZ5lsNYEmwPaRknMPCLZz07yTzVq/83p4o/wzbDZbBrTvGGTIw==",
"license": "MIT",
"dependencies": {
"bytes": "^3.1.2",
"content-type": "^2.0.0",
"debug": "^4.4.3",
"http-errors": "^2.0.1",
"iconv-lite": "^0.7.2",
"on-finished": "^2.4.1",
"qs": "^6.15.2",
"raw-body": "^3.0.2",
"type-is": "^2.1.0"
},
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/body-parser/node_modules/content-type": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz",
"integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==",
"license": "MIT",
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/bytes": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
"integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/call-bind-apply-helpers": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/call-bound": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz",
"integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.2",
"get-intrinsic": "^1.3.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/content-disposition": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.1.0.tgz",
"integrity": "sha512-5jRCH9Z/+DRP7rkvY83B+yGIGX96OYdJmzngqnw2SBSxqCFPd0w2km3s5iawpGX8krnwSGmF0FW5Nhr0Hfai3g==",
"license": "MIT",
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/content-type": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
"integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/cookie": {
"version": "0.7.2",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
"integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/cookie-signature": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz",
"integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==",
"license": "MIT",
"engines": {
"node": ">=6.6.0"
}
},
"node_modules/debug": {
"version": "4.4.3",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
"integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
"license": "MIT",
"dependencies": {
"ms": "^2.1.3"
},
"engines": {
"node": ">=6.0"
},
"peerDependenciesMeta": {
"supports-color": {
"optional": true
}
}
},
"node_modules/depd": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
"integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.1",
"es-errors": "^1.3.0",
"gopd": "^1.2.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
"license": "MIT"
},
"node_modules/encodeurl": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz",
"integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/es-define-property": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-errors": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-object-atoms": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz",
"integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/escape-html": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
"license": "MIT"
},
"node_modules/etag": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
"integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/express": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/express/-/express-5.2.1.tgz",
"integrity": "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==",
"license": "MIT",
"dependencies": {
"accepts": "^2.0.0",
"body-parser": "^2.2.1",
"content-disposition": "^1.0.0",
"content-type": "^1.0.5",
"cookie": "^0.7.1",
"cookie-signature": "^1.2.1",
"debug": "^4.4.0",
"depd": "^2.0.0",
"encodeurl": "^2.0.0",
"escape-html": "^1.0.3",
"etag": "^1.8.1",
"finalhandler": "^2.1.0",
"fresh": "^2.0.0",
"http-errors": "^2.0.0",
"merge-descriptors": "^2.0.0",
"mime-types": "^3.0.0",
"on-finished": "^2.4.1",
"once": "^1.4.0",
"parseurl": "^1.3.3",
"proxy-addr": "^2.0.7",
"qs": "^6.14.0",
"range-parser": "^1.2.1",
"router": "^2.2.0",
"send": "^1.1.0",
"serve-static": "^2.2.0",
"statuses": "^2.0.1",
"type-is": "^2.0.1",
"vary": "^1.1.2"
},
"engines": {
"node": ">= 18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/finalhandler": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.1.tgz",
"integrity": "sha512-S8KoZgRZN+a5rNwqTxlZZePjT/4cnm0ROV70LedRHZ0p8u9fRID0hJUZQpkKLzro8LfmC8sx23bY6tVNxv8pQA==",
"license": "MIT",
"dependencies": {
"debug": "^4.4.0",
"encodeurl": "^2.0.0",
"escape-html": "^1.0.3",
"on-finished": "^2.4.1",
"parseurl": "^1.3.3",
"statuses": "^2.0.1"
},
"engines": {
"node": ">= 18.0.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/forwarded": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
"integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/fresh": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz",
"integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/function-bind": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-intrinsic": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.2",
"es-define-property": "^1.0.1",
"es-errors": "^1.3.0",
"es-object-atoms": "^1.1.1",
"function-bind": "^1.1.2",
"get-proto": "^1.0.1",
"gopd": "^1.2.0",
"has-symbols": "^1.1.0",
"hasown": "^2.0.2",
"math-intrinsics": "^1.1.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
"license": "MIT",
"dependencies": {
"dunder-proto": "^1.0.1",
"es-object-atoms": "^1.0.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/gopd": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/has-symbols": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/hasown": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz",
"integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==",
"license": "MIT",
"dependencies": {
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/http-errors": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz",
"integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==",
"license": "MIT",
"dependencies": {
"depd": "~2.0.0",
"inherits": "~2.0.4",
"setprototypeof": "~1.2.0",
"statuses": "~2.0.2",
"toidentifier": "~1.0.1"
},
"engines": {
"node": ">= 0.8"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/iconv-lite": {
"version": "0.7.3",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.3.tgz",
"integrity": "sha512-IKXpvIzjnC9XTAUbVBcMfGS0EPaIXtW6v+zr+RRp+hqULEpo0owZax6wyRwPOJbWbzjYspQwusTsfVr0ifh4uQ==",
"license": "MIT",
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3.0.0"
},
"engines": {
"node": ">=0.10.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
"license": "ISC"
},
"node_modules/ipaddr.js": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==",
"license": "MIT",
"engines": {
"node": ">= 0.10"
}
},
"node_modules/is-promise": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz",
"integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==",
"license": "MIT"
},
"node_modules/math-intrinsics": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/media-typer": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.1.tgz",
"integrity": "sha512-yz3xRaG20c6/BOzvYoDaGtPmGscs7YivItZEEqe6GbwNfHuxu9YNmvnEkMzKldAGY4/80pRcQRZSEnhquk9XuQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/merge-descriptors": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz",
"integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==",
"license": "MIT",
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/mime-db": {
"version": "1.54.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz",
"integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz",
"integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==",
"license": "MIT",
"dependencies": {
"mime-db": "^1.54.0"
},
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/ms": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
"license": "MIT"
},
"node_modules/negotiator": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.1.0.tgz",
"integrity": "sha512-NMPBRMJgiQHjbd8phG3Vebdx4kZ1H121rbl5IkMqeOsahptB9BKo/d7oJ3zTXqTgagn2bWlNSXkh0QUGM31RYg==",
"license": "MIT",
"dependencies": {
"content-type": "^2.1.0"
},
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/negotiator/node_modules/content-type": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz",
"integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==",
"license": "MIT",
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/object-inspect": {
"version": "1.13.4",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz",
"integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/on-finished": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
"integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
"license": "MIT",
"dependencies": {
"ee-first": "1.1.1"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
"license": "ISC",
"dependencies": {
"wrappy": "1"
}
},
"node_modules/parseurl": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/path-to-regexp": {
"version": "8.4.2",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.4.2.tgz",
"integrity": "sha512-qRcuIdP69NPm4qbACK+aDogI5CBDMi1jKe0ry5rSQJz8JVLsC7jV8XpiJjGRLLol3N+R5ihGYcrPLTno6pAdBA==",
"license": "MIT",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/proxy-addr": {
"version": "2.0.8",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.8.tgz",
"integrity": "sha512-5nnx0yGyVUcY6t9RnWcARWtwT9F1D8O9rt08htPvnd49W1IgZtmLkhu9WfMzQj1cFxjHIO6connUNVW5k7AVyQ==",
"license": "MIT",
"dependencies": {
"forwarded": "0.2.0",
"ipaddr.js": "1.9.1"
},
"engines": {
"node": ">= 0.10"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/qs": {
"version": "6.16.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.16.0.tgz",
"integrity": "sha512-h6fhOIaRrID2CbEY2fqs+7t+UXZo+MLAnU5gRIq85uFtdiUPCdsApMlHhXogKVM4HM2DVbIjGNTTYH2OcmP1vA==",
"license": "BSD-3-Clause",
"dependencies": {
"es-define-property": "^1.0.1",
"side-channel": "^1.1.1"
},
"engines": {
"node": ">=0.6"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/range-parser": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.3.0.tgz",
"integrity": "sha512-hek2mFQpPuI4E1BBKrSto+BU3e3x4xuarsbiwr3+lf7p44juvFMV0XFWQAP3xUyqXA4RrXLIoaSUGbSt056ZMw==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/raw-body": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz",
"integrity": "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA==",
"license": "MIT",
"dependencies": {
"bytes": "~3.1.2",
"http-errors": "~2.0.1",
"iconv-lite": "~0.7.0",
"unpipe": "~1.0.0"
},
"engines": {
"node": ">= 0.10"
}
},
"node_modules/router": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz",
"integrity": "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==",
"license": "MIT",
"dependencies": {
"debug": "^4.4.0",
"depd": "^2.0.0",
"is-promise": "^4.0.0",
"parseurl": "^1.3.3",
"path-to-regexp": "^8.0.0"
},
"engines": {
"node": ">= 18"
}
},
"node_modules/safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"license": "MIT"
},
"node_modules/send": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz",
"integrity": "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ==",
"license": "MIT",
"dependencies": {
"debug": "^4.4.3",
"encodeurl": "^2.0.0",
"escape-html": "^1.0.3",
"etag": "^1.8.1",
"fresh": "^2.0.0",
"http-errors": "^2.0.1",
"mime-types": "^3.0.2",
"ms": "^2.1.3",
"on-finished": "^2.4.1",
"range-parser": "^1.2.1",
"statuses": "^2.0.2"
},
"engines": {
"node": ">= 18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/serve-static": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.1.tgz",
"integrity": "sha512-xRXBn0pPqQTVQiC8wyQrKs2MOlX24zQ0POGaj0kultvoOCstBQM5yvOhAVSUwOMjQtTvsPWoNCHfPGwaaQJhTw==",
"license": "MIT",
"dependencies": {
"encodeurl": "^2.0.0",
"escape-html": "^1.0.3",
"parseurl": "^1.3.3",
"send": "^1.2.0"
},
"engines": {
"node": ">= 18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/setprototypeof": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
"license": "ISC"
},
"node_modules/side-channel": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.1.tgz",
"integrity": "sha512-6x6dK6zJdpTzF4sQeNYxwtvBzf6Eg4GtlesS94HOvTudUeyK2WXAaIfmDgsyslYrRBeFIlsi54AYsFGUuhmvrQ==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"object-inspect": "^1.13.4",
"side-channel-list": "^1.0.1",
"side-channel-map": "^1.0.1",
"side-channel-weakmap": "^1.0.2"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-list": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz",
"integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"object-inspect": "^1.13.4"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-map": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz",
"integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==",
"license": "MIT",
"dependencies": {
"call-bound": "^1.0.2",
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.5",
"object-inspect": "^1.13.3"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-weakmap": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz",
"integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==",
"license": "MIT",
"dependencies": {
"call-bound": "^1.0.2",
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.5",
"object-inspect": "^1.13.3",
"side-channel-map": "^1.0.1"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/statuses": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz",
"integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/toidentifier": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
"integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
"license": "MIT",
"engines": {
"node": ">=0.6"
}
},
"node_modules/type-is": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-2.1.0.tgz",
"integrity": "sha512-faYHw0anBbc/kWF3zFTEnxSFOAGUX9GFbOBthvDdLsIlEoWOFOtS0zgCiQYwIskL9iGXZL3kAXD8OoZ4GmMATA==",
"license": "MIT",
"dependencies": {
"content-type": "^2.0.0",
"media-typer": "^1.1.0",
"mime-types": "^3.0.0"
},
"engines": {
"node": ">= 18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/type-is/node_modules/content-type": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz",
"integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==",
"license": "MIT",
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
"integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
"integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
"license": "ISC"
}
}
}

26
package.json Normal file
View file

@ -0,0 +1,26 @@
{
"name": "nt-connections",
"version": "1.0.0",
"description": "NYT Connections style word game with a puzzle editor",
"main": "server.js",
"scripts": {
"test": "node --test test.js",
"start": "node server.js"
},
"repository": {
"type": "git",
"url": "https://git.nextgenerationofunity.org/ngu-git-admin/NT-Connections.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "commonjs",
"dependencies": {
"@fontsource/outfit": "^5.3.0",
"@phosphor-icons/web": "^2.1.2",
"express": "^5.2.1"
},
"engines": {
"node": ">=22.13"
}
}

19
public/admin.html Normal file
View file

@ -0,0 +1,19 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex">
<title>Admin | NT Connections</title>
<link rel="stylesheet" href="/style.css">
</head>
<body>
<header class="topbar">
<a class="brand" href="/">NT Connections</a>
<nav><a href="/puzzles">Puzzles</a><a href="/admin" aria-current="page">Admin</a></nav>
</header>
<main id="app"><div class="skeleton"></div></main>
<script src="/common.js"></script>
<script src="/admin.js"></script>
</body>
</html>

109
public/admin.js Normal file
View file

@ -0,0 +1,109 @@
const COLORS = ['yellow', 'green', 'blue', 'purple'];
const $app = document.getElementById('app');
let games = [];
const icon = (name) => el('i', { class: `ph-bold ph-${name}`, 'aria-hidden': 'true' });
const errorList = (errors) => el('ul', { class: 'errors', role: 'alert' }, errors.map((e) => el('li', {}, e)));
async function showList() {
const { ok, status, data } = await api('/api/admin/games');
if (status === 401) return showLogin();
if (!ok) return $app.replaceChildren(el('div', { class: 'empty' }, 'Could not load puzzles. Try refreshing.'));
games = data;
const items = games.length
? games.map((g) => el('li', {}, el('div', { class: 'item' },
el('div', {}, el('strong', {}, g.title), el('div', { class: 'meta' }, g.date ? fmtDate(g.date) : 'No date (list only)')),
el('div', { class: 'row-actions' },
el('a', { class: 'btn icon-btn', href: `/play/${g.id}`, 'aria-label': `Play ${g.title}` }, icon('arrow-right')),
el('button', { class: 'btn icon-btn', 'aria-label': `Edit ${g.title}`, onclick: () => showEditor(g) }, icon('pencil-simple')),
el('button', { class: 'btn icon-btn danger', 'aria-label': `Delete ${g.title}`, onclick: () => remove(g) }, icon('trash'))))))
: [el('li', { class: 'empty' }, 'No puzzles yet. Create your first one.')];
$app.replaceChildren(
el('h1', {}, 'Your puzzles'),
el('p', { class: 'sub' }, 'Dated puzzles appear on their day. Future ones stay hidden until then.'),
el('div', { class: 'actions', style: 'justify-content:flex-start;margin-bottom:20px' },
el('button', { class: 'btn primary', onclick: () => showEditor() }, icon('plus'), 'New puzzle'),
el('button', { class: 'btn', onclick: logout }, icon('sign-out'), 'Log out')),
el('ul', { class: 'list' }, items),
);
}
function showLogin(error) {
const input = el('input', { id: 'pw', type: 'password', autocomplete: 'current-password', required: true });
$app.replaceChildren(
el('h1', {}, 'Admin login'),
el('p', { class: 'sub' }, 'Only the puzzle editor needs this.'),
el('form', { onsubmit: async (e) => {
e.preventDefault();
const btn = e.submitter; btn.disabled = true;
const { ok, data } = await api('/api/login', { method: 'POST', body: { password: input.value } });
ok ? showList() : showLogin(data.error || 'Login failed.');
} },
el('div', { class: 'field' }, el('label', { for: 'pw' }, 'Password'), input,
error ? el('p', { class: 'help', style: 'color:var(--error)', role: 'alert' }, error) : null),
el('button', { class: 'btn primary', type: 'submit' }, 'Log in')),
);
input.focus();
}
function showEditor(game) {
const g = game || { title: '', date: '', groups: COLORS.map((color) => ({ name: '', color, words: ['', '', '', ''] })) };
const field = (id, label, input, help) =>
el('div', { class: 'field' }, el('label', { for: id }, label), input, help ? el('p', { class: 'help' }, help) : null);
const title = el('input', { id: 'title', value: g.title, maxlength: 100, required: true });
const date = el('input', { id: 'date', type: 'date', value: g.date || '' });
const errBox = el('div');
const groupEls = g.groups.map((grp, i) => {
const n = i + 1;
const name = el('input', { id: `g${n}-name`, value: grp.name, maxlength: 80, required: true });
const color = el('select', { id: `g${n}-color` }, COLORS.map((c) => el('option', { value: c, selected: c === grp.color }, c[0].toUpperCase() + c.slice(1))));
const words = grp.words.map((w, j) => el('input', { value: w, maxlength: 30, required: true, 'aria-label': `Group ${n} word ${j + 1}` }));
const box = el('fieldset', { class: 'group-edit' },
el('legend', { class: 'sr' }, `Group ${n}`),
el('div', { class: 'head' },
field(`g${n}-name`, el('span', {}, el('span', { class: `swatch ${grp.color}` }), `Group ${n} name`), name),
field(`g${n}-color`, 'Color', color)),
el('label', {}, 'Words'), el('div', { class: 'words' }, words));
color.addEventListener('change', () => { box.querySelector('.swatch').className = `swatch ${color.value}`; });
return { box, read: () => ({ name: name.value, color: color.value, words: words.map((w) => w.value) }) };
});
$app.replaceChildren(
el('a', { href: '/admin', class: 'btn', style: 'margin-bottom:20px', onclick: (e) => { e.preventDefault(); showList(); } }, icon('arrow-left'), 'Back'),
el('h1', {}, game ? 'Edit puzzle' : 'New puzzle'),
el('p', { class: 'sub' }, 'Yellow is the easiest group, purple the trickiest.'),
el('form', { novalidate: true, onsubmit: async (e) => {
e.preventDefault();
const btn = e.submitter; btn.disabled = true;
const body = { title: title.value, date: date.value || null, groups: groupEls.map((x) => x.read()) };
const { ok, data } = await api(game ? `/api/admin/games/${game.id}` : '/api/admin/games', { method: game ? 'PUT' : 'POST', body });
btn.disabled = false;
if (ok) { toast('Saved'); return showList(); }
if (data.error) return showLogin(data.error);
errBox.replaceChildren(errorList(data.errors || ['Could not save.']));
errBox.scrollIntoView({ block: 'center' });
} },
errBox,
field('title', 'Title', title),
field('date', 'Date', date, 'Optional. The puzzle becomes the daily puzzle on this date.'),
groupEls.map((x) => x.box),
el('div', { class: 'actions', style: 'justify-content:flex-start' }, el('button', { class: 'btn primary', type: 'submit' }, icon('check'), 'Save puzzle'))),
);
}
async function remove(g) {
if (!confirm(`Delete "${g.title}"? This cannot be undone.`)) return;
const { ok } = await api(`/api/admin/games/${g.id}`, { method: 'DELETE' });
toast(ok ? 'Deleted' : 'Delete failed');
showList();
}
async function logout() {
await api('/api/logout', { method: 'POST' });
showLogin();
}
showList();

31
public/common.js Normal file
View file

@ -0,0 +1,31 @@
// Small helpers shared by every page.
function el(tag, attrs = {}, ...kids) {
const n = document.createElement(tag);
for (const [k, v] of Object.entries(attrs)) {
if (k === 'class') n.className = v;
else if (k.startsWith('on')) n.addEventListener(k.slice(2), v);
else if (v !== false && v != null) n.setAttribute(k, v === true ? '' : v);
}
n.append(...kids.flat().filter((k) => k != null));
return n;
}
async function api(url, opts = {}) {
const res = await fetch(url, {
...opts,
headers: { 'Content-Type': 'application/json' },
body: opts.body ? JSON.stringify(opts.body) : undefined,
});
const data = await res.json().catch(() => ({}));
return { ok: res.ok, status: res.status, data };
}
function toast(msg) {
document.querySelector('.toast')?.remove();
const t = el('div', { class: 'toast', role: 'status' }, msg);
document.body.append(t);
setTimeout(() => t.remove(), 1800);
}
const fmtDate = (d) =>
d ? new Date(d + 'T00:00:00Z').toLocaleDateString(undefined, { timeZone: 'UTC', year: 'numeric', month: 'long', day: 'numeric' }) : '';

24
public/play.html Normal file
View file

@ -0,0 +1,24 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>NT Connections</title>
<link rel="stylesheet" href="/style.css">
</head>
<body>
<header class="topbar">
<a class="brand" href="/">NT Connections</a>
<nav><a href="/" id="nav-today">Today</a><a href="/puzzles">Puzzles</a></nav>
</header>
<main>
<h1 id="title">Loading puzzle</h1>
<p class="sub" id="sub">Create four groups of four.</p>
<div id="game" aria-live="polite">
<div class="board"><div class="skeleton"></div><div class="skeleton"></div><div class="skeleton"></div><div class="skeleton"></div></div>
</div>
</main>
<script src="/common.js"></script>
<script src="/play.js"></script>
</body>
</html>

139
public/play.js Normal file
View file

@ -0,0 +1,139 @@
const ORDER = ['yellow', 'green', 'blue', 'purple'];
const EMOJI = { yellow: '🟨', green: '🟩', blue: '🟦', purple: '🟪' };
const MAX_MISTAKES = 4;
const $game = document.getElementById('game');
const idMatch = location.pathname.match(/^\/play\/(\d+)/);
if (!idMatch) document.getElementById('nav-today').setAttribute('aria-current', 'page');
const state = { game: null, words: [], selected: new Set(), solved: [], mistakes: 0, guesses: [], tried: new Set(), done: false, won: false };
async function load() {
const { ok, data } = await api(idMatch ? `/api/games/${idMatch[1]}` : '/api/daily');
if (!ok) {
document.getElementById('title').textContent = idMatch ? 'Puzzle not found' : 'No puzzle today';
document.getElementById('sub').textContent = data.error || 'Something went wrong.';
$game.replaceChildren(el('div', { class: 'empty' }, 'Pick one from the ', el('a', { href: '/puzzles' }, 'puzzle list'), ' instead.'));
return;
}
state.game = data;
state.words = data.words;
document.getElementById('title').textContent = data.title;
document.title = `${data.title} | NT Connections`;
if (data.date) document.getElementById('sub').textContent = `${fmtDate(data.date)}. Create four groups of four.`;
render();
}
function render() {
const board = el('div', { class: 'board' },
state.solved.map((g) => el('div', { class: `solved ${g.color}` }, el('strong', {}, g.name), el('span', {}, g.words.join(', ')))),
state.words.length ? el('div', { class: 'row4' }, state.words.map((w) =>
el('button', { class: 'tile', 'aria-pressed': String(state.selected.has(w)), disabled: state.done, onclick: () => toggle(w) }, w))) : null,
);
const kids = [board];
if (state.done) {
kids.push(resultPanel());
} else {
kids.push(
el('div', { class: 'mistakes', 'aria-label': `${MAX_MISTAKES - state.mistakes} mistakes remaining` },
'Mistakes remaining:', [...Array(MAX_MISTAKES)].map((_, i) => el('i', { class: i < state.mistakes ? 'used' : '' }))),
el('div', { class: 'actions' },
el('button', { class: 'btn', onclick: shuffleWords }, el('i', { class: 'ph-bold ph-shuffle', 'aria-hidden': 'true' }), 'Shuffle'),
el('button', { class: 'btn', disabled: !state.selected.size, onclick: () => { state.selected.clear(); render(); } }, 'Deselect all'),
el('button', { class: 'btn primary', disabled: state.selected.size !== 4, onclick: submit }, 'Submit')),
);
}
// Re-rendering replaces the buttons, so put keyboard focus back on the same one.
const focused = $game.contains(document.activeElement) ? document.activeElement.textContent : null;
$game.replaceChildren(...kids);
if (focused) [...$game.querySelectorAll('button')].find((b) => b.textContent === focused && !b.disabled)?.focus();
}
function toggle(w) {
if (state.selected.has(w)) state.selected.delete(w);
else if (state.selected.size < 4) state.selected.add(w);
render();
}
function shuffleWords() {
const a = state.words;
for (let i = a.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[a[i], a[j]] = [a[j], a[i]];
}
render();
}
let busy = false;
async function submit() {
if (busy) return;
const words = [...state.selected];
const key = [...words].sort().join('|');
if (state.tried.has(key)) return toast('Already guessed!');
busy = true;
const { ok, data } = await api(`/api/games/${state.game.id}/guess`, { method: 'POST', body: { words } });
busy = false;
if (!ok) return toast(data.error || 'Could not check that guess.');
state.tried.add(key);
state.guesses.push(words);
if (data.result === 'correct') {
state.solved.push(data.group);
state.words = state.words.filter((w) => !data.group.words.includes(w));
state.selected.clear();
if (state.solved.length === 4) return finish(true);
return render();
}
state.mistakes++;
if (data.result === 'one-away') toast('One away...');
if (state.mistakes >= MAX_MISTAKES) return finish(false);
render();
const grid = $game.querySelector('.row4');
grid?.classList.add('shake');
}
async function finish(won) {
const { ok, data } = await api(`/api/games/${state.game.id}/reveal`, { method: 'POST' });
state.answers = ok ? data.groups : state.solved;
if (!won) {
const have = new Set(state.solved.map((g) => g.name));
state.solved.push(...state.answers.filter((g) => !have.has(g.name)).sort((a, b) => ORDER.indexOf(a.color) - ORDER.indexOf(b.color)));
state.words = [];
}
state.done = true;
state.won = won;
state.selected.clear();
render();
}
function shareGrid() {
const colorOf = (w) => state.answers.find((g) => g.words.includes(w))?.color;
return state.guesses.map((guess) => guess.map((w) => EMOJI[colorOf(w)] || '⬜').join('')).join('\n');
}
function resultPanel() {
const heading = !state.won ? 'Next time' : state.mistakes === 0 ? 'Perfect!' : 'Solved';
const grid = shareGrid();
const text = `NT Connections\n${state.game.title}\n${grid}\n${location.origin}/play/${state.game.id}`;
return el('div', { class: 'result' },
el('h2', {}, heading),
el('p', { class: 'sub' }, state.won ? `Finished with ${state.mistakes} mistake${state.mistakes === 1 ? '' : 's'}.` : 'Here are the groups.'),
el('pre', { 'aria-label': 'Your guesses' }, grid),
el('div', { class: 'actions' },
el('button', { class: 'btn primary', onclick: () => share(text) }, el('i', { class: 'ph-bold ph-copy', 'aria-hidden': 'true' }), 'Share results'),
el('a', { class: 'btn', href: '/puzzles' }, 'More puzzles')));
}
async function share(text) {
try {
await navigator.clipboard.writeText(text);
toast('Copied to clipboard');
} catch {
// Clipboard API needs HTTPS; the grid above is still selectable by hand.
toast('Copy failed. Select the grid to copy it.');
}
}
load();

33
public/puzzles.html Normal file
View file

@ -0,0 +1,33 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Puzzles | NT Connections</title>
<link rel="stylesheet" href="/style.css">
</head>
<body>
<header class="topbar">
<a class="brand" href="/">NT Connections</a>
<nav><a href="/">Today</a><a href="/puzzles" aria-current="page">Puzzles</a></nav>
</header>
<main>
<h1>All puzzles</h1>
<p class="sub">Play today's, or catch up on ones you missed.</p>
<ul class="list" id="list">
<li class="skeleton"></li><li class="skeleton"></li><li class="skeleton"></li>
</ul>
</main>
<script src="/common.js"></script>
<script>
(async () => {
const $list = document.getElementById('list');
const { ok, data } = await api('/api/games');
if (!ok) return $list.replaceChildren(el('li', { class: 'empty' }, 'Could not load puzzles. Try refreshing.'));
if (!data.length) return $list.replaceChildren(el('li', { class: 'empty' }, 'No puzzles yet. Check back soon.'));
$list.replaceChildren(...data.map((g) =>
el('li', {}, el('a', { href: `/play/${g.id}` }, el('strong', {}, g.title), el('span', { class: 'meta' }, fmtDate(g.date))))));
})();
</script>
</body>
</html>

220
public/style.css Normal file
View file

@ -0,0 +1,220 @@
@import url('/vendor/font/400.css');
@import url('/vendor/font/600.css');
@import url('/vendor/font/700.css');
@import url('/vendor/icons/style.css');
/* Shape rule: buttons are full pill; tiles, panels and inputs are 10px. */
:root {
--bg: #f4f4f5;
--surface: #ffffff;
--tile: #e4e4e7;
--tile-hover: #d4d4d8;
--ink: #18181b;
--muted: #52525b;
--line: #d4d4d8;
--selected: #3f3f46;
--selected-ink: #fafafa;
--error: #b42318;
--yellow: #f0d36b;
--green: #a3c96f;
--blue: #a9c1ea;
--purple: #bd9ddb;
--on-group: #18181b;
--radius: 10px;
--ease: cubic-bezier(0.16, 1, 0.3, 1);
color-scheme: light;
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #111113;
--surface: #1c1c1f;
--tile: #2a2a2e;
--tile-hover: #35353a;
--ink: #f4f4f5;
--muted: #a1a1aa;
--line: #3f3f46;
--selected: #e4e4e7;
--selected-ink: #18181b;
--error: #f97066;
--yellow: #e2c25a;
--green: #93ba60;
--blue: #93acd8;
--purple: #a988c9;
color-scheme: dark;
}
}
* { box-sizing: border-box; }
body {
margin: 0;
min-height: 100dvh;
background: var(--bg);
color: var(--ink);
font-family: 'Outfit', system-ui, sans-serif;
line-height: 1.5;
-webkit-font-smoothing: antialiased;
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.topbar {
height: 64px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 20px;
border-bottom: 1px solid var(--line);
background: var(--surface);
}
.brand { font-weight: 700; font-size: 1.15rem; letter-spacing: -0.02em; text-decoration: none; }
.topbar nav { display: flex; gap: 20px; }
.topbar nav a { text-decoration: none; color: var(--muted); font-weight: 600; }
.topbar nav a:hover, .topbar nav a[aria-current='page'] { color: var(--ink); }
main { max-width: 640px; margin: 0 auto; padding: 32px 16px 64px; }
h1 { font-size: clamp(1.6rem, 4vw, 2.1rem); letter-spacing: -0.03em; line-height: 1.1; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 24px; }
/* Buttons */
.btn {
font: inherit;
font-weight: 600;
display: inline-flex;
align-items: center;
gap: 8px;
white-space: nowrap;
padding: 10px 20px;
border-radius: 999px;
border: 1.5px solid var(--ink);
background: transparent;
color: var(--ink);
cursor: pointer;
text-decoration: none;
transition: transform 0.15s var(--ease), background 0.2s;
}
.btn:hover { background: var(--tile); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--ink); color: var(--bg); }
.btn.primary:hover { opacity: 0.88; }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn.danger { border-color: var(--error); color: var(--error); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
/* Board */
.board { display: grid; gap: 8px; margin-bottom: 20px; }
.row4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tile {
font: inherit;
font-weight: 700;
font-size: clamp(0.7rem, 2.6vw, 1rem);
text-transform: uppercase;
min-height: 76px;
padding: 6px;
border: 0;
border-radius: var(--radius);
background: var(--tile);
color: var(--ink);
cursor: pointer;
overflow-wrap: anywhere;
line-height: 1.15;
transition: transform 0.15s var(--ease), background 0.15s, color 0.15s;
}
.tile:hover { background: var(--tile-hover); }
.tile:active { transform: scale(0.96); }
.tile[aria-pressed='true'] { background: var(--selected); color: var(--selected-ink); }
.tile:disabled { cursor: default; }
.solved {
border-radius: var(--radius);
min-height: 76px;
padding: 12px;
display: grid;
place-content: center;
text-align: center;
color: var(--on-group);
animation: pop 0.4s var(--ease);
}
.solved strong { text-transform: uppercase; letter-spacing: 0.02em; }
.solved span { text-transform: uppercase; font-size: 0.9rem; }
.yellow { background: var(--yellow); }
.green { background: var(--green); }
.blue { background: var(--blue); }
.purple { background: var(--purple); }
.mistakes { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0 0 20px; color: var(--muted); }
.mistakes i { width: 12px; height: 12px; border-radius: 50%; background: var(--selected); transition: transform 0.3s var(--ease), opacity 0.3s; }
.mistakes i.used { transform: scale(0); opacity: 0; }
.shake { animation: shake 0.35s; }
.toast {
position: fixed;
left: 50%;
top: 84px;
transform: translateX(-50%);
background: var(--ink);
color: var(--bg);
padding: 8px 16px;
border-radius: var(--radius);
font-weight: 600;
animation: fade 1.8s forwards;
z-index: 10; /* only overlay on the page */
}
.result { text-align: center; margin-top: 8px; animation: pop 0.4s var(--ease); }
.result h2 { margin: 0 0 4px; letter-spacing: -0.02em; }
.result pre { font-family: inherit; font-size: 1.4rem; line-height: 1.25; margin: 12px 0 20px; }
/* Lists and forms */
.list { display: grid; gap: 10px; padding: 0; margin: 0; list-style: none; }
.list a, .list .item {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 14px 16px;
background: var(--surface);
border: 1px solid var(--line);
border-radius: var(--radius);
text-decoration: none;
transition: transform 0.15s var(--ease), border-color 0.2s;
}
.list a:hover { border-color: var(--ink); transform: translateY(-1px); }
.list .meta { color: var(--muted); font-size: 0.9rem; }
.empty, .skeleton { color: var(--muted); padding: 32px 16px; text-align: center; border: 1.5px dashed var(--line); border-radius: var(--radius); }
.skeleton { border-style: solid; background: var(--tile); color: transparent; min-height: 52px; padding: 0; animation: pulse 1.2s infinite alternate; }
.field { display: grid; gap: 6px; margin-bottom: 16px; }
label { font-weight: 600; font-size: 0.95rem; }
.help { color: var(--muted); font-size: 0.85rem; margin: 0; }
input, select {
font: inherit;
padding: 10px 12px;
border: 1.5px solid var(--line);
border-radius: var(--radius);
background: var(--surface);
color: var(--ink);
width: 100%;
}
input:focus, select:focus { border-color: var(--ink); outline: none; }
.group-edit { min-width: 0; padding: 16px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid var(--line); background: var(--surface); }
.group-edit .head { display: grid; grid-template-columns: 1fr 140px; gap: 10px; margin-bottom: 10px; }
.group-edit .words { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.group-edit .swatch { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.errors { color: var(--error); margin: 0 0 16px; padding-left: 20px; }
.row-actions { display: flex; gap: 8px; }
.icon-btn { padding: 8px 12px; }
@media (max-width: 767px) {
.group-edit .head, .group-edit .words { grid-template-columns: 1fr 1fr; }
.topbar nav { gap: 14px; }
}
@keyframes pop { from { transform: scale(0.94); opacity: 0; } }
@keyframes shake { 25% { transform: translateX(-6px); } 50% { transform: translateX(6px); } 75% { transform: translateX(-3px); } }
@keyframes fade { 0%, 75% { opacity: 1; } 100% { opacity: 0; } }
@keyframes pulse { to { opacity: 0.5; } }
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { animation: none !important; transition: none !important; }
}

137
server.js Normal file
View file

@ -0,0 +1,137 @@
const path = require('node:path');
const fs = require('node:fs');
const crypto = require('node:crypto');
const { DatabaseSync } = require('node:sqlite');
const express = require('express');
const { validateGame, checkGuess, shuffle } = require('./lib');
const PORT = process.env.PORT || 3000;
const ADMIN_PASSWORD = process.env.ADMIN_PASSWORD;
const DB_PATH = process.env.DB_PATH || path.join(__dirname, 'data', 'games.db');
if (!ADMIN_PASSWORD) {
console.error('Set ADMIN_PASSWORD before starting the server.');
process.exit(1);
}
fs.mkdirSync(path.dirname(DB_PATH), { recursive: true });
const db = new DatabaseSync(DB_PATH);
db.exec(`CREATE TABLE IF NOT EXISTS games (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
date TEXT UNIQUE,
groups_json TEXT NOT NULL,
created_at TEXT NOT NULL DEFAULT (datetime('now')),
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
)`);
// Server's local date decides "today"; set TZ on the VPS to the timezone you want.
const today = () => new Date().toLocaleDateString('en-CA');
const toGame = (row) => row && { id: row.id, title: row.title, date: row.date, groups: JSON.parse(row.groups_json) };
// A game is public once its date has arrived (undated games are always public).
const getPublic = (id) =>
toGame(db.prepare('SELECT * FROM games WHERE id = ? AND (date IS NULL OR date <= ?)').get(Number(id), today()));
// Stateless session: the cookie is an HMAC of the password, so changing the password logs everyone out.
const SESSION = crypto.createHmac('sha256', ADMIN_PASSWORD).update('nt-admin-session').digest('hex');
const safeEqual = (a, b) => {
const x = crypto.createHash('sha256').update(String(a)).digest();
const y = crypto.createHash('sha256').update(String(b)).digest();
return crypto.timingSafeEqual(x, y);
};
const cookie = (req, name) =>
(req.headers.cookie || '').split(';').map((c) => c.trim().split('=')).find(([k]) => k === name)?.[1];
const isAdmin = (req) => safeEqual(cookie(req, 'nt_admin') || '', SESSION);
const requireAdmin = (req, res, next) => (isAdmin(req) ? next() : res.status(401).json({ error: 'Log in first.' }));
const app = express();
app.set('trust proxy', 'loopback'); // nginx on the same box
app.use(express.json());
app.use('/vendor/font', express.static(path.join(__dirname, 'node_modules/@fontsource/outfit')));
app.use('/vendor/icons', express.static(path.join(__dirname, 'node_modules/@phosphor-icons/web/src/bold')));
app.use(express.static(path.join(__dirname, 'public'), { index: false }));
const page = (file) => (req, res) => res.sendFile(path.join(__dirname, 'public', file));
app.get('/', page('play.html'));
app.get('/play/:id', page('play.html'));
app.get('/puzzles', page('puzzles.html'));
app.get('/admin', page('admin.html'));
// ---- Player API (never sends group membership until solved or revealed) ----
const publicView = (g) => ({ id: g.id, title: g.title, date: g.date, words: shuffle(g.groups.flatMap((x) => x.words)) });
app.get('/api/games', (req, res) => {
const rows = db
.prepare('SELECT id, title, date FROM games WHERE date IS NULL OR date <= ? ORDER BY date IS NULL, date DESC, id DESC')
.all(today());
res.json(rows);
});
app.get('/api/daily', (req, res) => {
const row = db.prepare('SELECT * FROM games WHERE date <= ? ORDER BY date DESC LIMIT 1').get(today());
if (!row) return res.status(404).json({ error: 'No puzzle scheduled yet.' });
res.json(publicView(toGame(row)));
});
app.get('/api/games/:id', (req, res) => {
const g = getPublic(req.params.id);
if (!g) return res.status(404).json({ error: 'Puzzle not found.' });
res.json(publicView(g));
});
app.post('/api/games/:id/guess', (req, res) => {
const g = getPublic(req.params.id);
if (!g) return res.status(404).json({ error: 'Puzzle not found.' });
const out = checkGuess(g.groups, req.body?.words);
res.status(out.error ? 400 : 200).json(out);
});
app.post('/api/games/:id/reveal', (req, res) => {
const g = getPublic(req.params.id);
if (!g) return res.status(404).json({ error: 'Puzzle not found.' });
res.json({ groups: g.groups });
});
// ---- Admin ----
app.post('/api/login', async (req, res) => {
if (!safeEqual(req.body?.password ?? '', ADMIN_PASSWORD)) {
await new Promise((r) => setTimeout(r, 1000)); // slow down guessing
return res.status(401).json({ error: 'Wrong password.' });
}
const secure = req.secure ? '; Secure' : '';
res.setHeader('Set-Cookie', `nt_admin=${SESSION}; HttpOnly; SameSite=Strict; Path=/; Max-Age=2592000${secure}`);
res.json({ ok: true });
});
app.post('/api/logout', (req, res) => {
res.setHeader('Set-Cookie', 'nt_admin=; HttpOnly; SameSite=Strict; Path=/; Max-Age=0');
res.json({ ok: true });
});
app.get('/api/admin/games', requireAdmin, (req, res) => {
res.json(db.prepare('SELECT * FROM games ORDER BY date IS NULL, date DESC, id DESC').all().map(toGame));
});
function save(req, res, id) {
const { errors, game } = validateGame(req.body);
if (errors) return res.status(400).json({ errors });
try {
const args = [game.title, game.date, JSON.stringify(game.groups)];
const r = id
? db.prepare("UPDATE games SET title = ?, date = ?, groups_json = ?, updated_at = datetime('now') WHERE id = ?").run(...args, id)
: db.prepare('INSERT INTO games (title, date, groups_json) VALUES (?, ?, ?)').run(...args);
if (id && r.changes === 0) return res.status(404).json({ errors: ['Puzzle not found.'] });
res.json({ id: id || Number(r.lastInsertRowid) });
} catch (e) {
if (String(e.message).includes('UNIQUE')) return res.status(409).json({ errors: [`Another puzzle already uses ${game.date}.`] });
throw e;
}
}
app.post('/api/admin/games', requireAdmin, (req, res) => save(req, res, null));
app.put('/api/admin/games/:id', requireAdmin, (req, res) => save(req, res, Number(req.params.id)));
app.delete('/api/admin/games/:id', requireAdmin, (req, res) => {
db.prepare('DELETE FROM games WHERE id = ?').run(Number(req.params.id));
res.json({ ok: true });
});
app.listen(PORT, '127.0.0.1', () => console.log(`NT Connections on http://localhost:${PORT}`));

11
skills-lock.json Normal file
View file

@ -0,0 +1,11 @@
{
"version": 1,
"skills": {
"design-taste-frontend": {
"source": "Leonxlnx/taste-skill",
"sourceType": "github",
"skillPath": "skills/taste-skill/SKILL.md",
"computedHash": "899b84384f74f540ea5284d9b2e9234e050998b42eacc805410b518d4226c0b3"
}
}
}

47
test.js Normal file
View file

@ -0,0 +1,47 @@
const test = require('node:test');
const assert = require('node:assert');
const { validateGame, checkGuess } = require('./lib');
const good = () => ({
title: 'Sample',
date: '2026-10-08',
groups: [
{ name: 'Fish', color: 'yellow', words: ['bass', 'pike', 'carp', 'sole'] },
{ name: 'Planets', color: 'green', words: ['mars', 'venus', 'earth', 'saturn'] },
{ name: 'Keys', color: 'blue', words: ['shift', 'tab', 'enter', 'escape'] },
{ name: 'Tools', color: 'purple', words: ['saw', 'drill', 'level', 'file'] },
],
});
test('valid game is cleaned and uppercased', () => {
const { game, errors } = validateGame(good());
assert.equal(errors, undefined);
assert.deepEqual(game.groups[0].words, ['BASS', 'PIKE', 'CARP', 'SOLE']);
});
test('rejects duplicates, bad dates, repeated colors, missing words', () => {
const g = good();
g.groups[1].words[0] = ' Bass ';
g.groups[2].color = 'yellow';
g.groups[3].words = ['a', 'b', 'c'];
g.date = '2026-02-30';
const { errors } = validateGame(g);
assert.ok(errors.some((e) => e.includes('appears more than once')));
assert.ok(errors.some((e) => e.includes('used more than once')));
assert.ok(errors.some((e) => e.includes('needs 4 words')));
assert.ok(errors.some((e) => e.includes('real date')));
assert.ok(validateGame({}).errors.length);
});
test('undated game is allowed', () => {
assert.equal(validateGame({ ...good(), date: '' }).game.date, null);
});
test('checkGuess: correct, one away, wrong, invalid', () => {
const { groups } = validateGame(good()).game;
assert.equal(checkGuess(groups, ['sole', 'carp', 'PIKE', 'bass']).group.name, 'Fish');
assert.equal(checkGuess(groups, ['bass', 'pike', 'carp', 'mars']).result, 'one-away');
assert.equal(checkGuess(groups, ['bass', 'pike', 'mars', 'venus']).result, 'wrong');
assert.ok(checkGuess(groups, ['bass', 'bass', 'pike', 'carp']).error);
assert.ok(checkGuess(groups, 'nope').error);
});