Cloudflare-only bridge between Flo POS desktop apps and outside clients, starting with live reports in RevFlo.
The design is in docs/design.md; the exact wire contract for implementing a POS or phone client is docs/protocol.md. This repo implements milestones M0 to M3: enrolment, the POS WebSocket, versioning and liveness, pairing (QR and manual code with numeric comparison), device auth and revocation, and the end-to-end encrypted report relay.
| Path | What |
|---|---|
src/worker.ts |
Edge Worker: routing, shape and MAC checks, rate-limit bindings, enrolment, admin block |
src/store-room.ts |
StoreRoom Durable Object (SQLite, hibernating WebSocket), one per store |
shared/protocol.ts |
Wire types and constants. Dependency-free: copy this one file into the POS and the app |
shared/transcript.ts, shared/test-vectors.json |
Crypto transcript bytes (commitment, SAS, wrap AADs, canonical query, key_id) and fixed vectors. Copy both into FloCafe and RevFlo and check the vectors in their tests. Regenerate with node scripts/gen-vectors.mjs |
shared/server-url.ts |
Server URL validation for the apps' Advanced setting |
test/ref/ |
Reference POS (Node crypto) and phone (WebCrypto) sides, and the test harness |
docs/protocol.md |
HTTP and WebSocket contract, crypto bytes |
migrations/ |
D1 directory schema |
public/ |
Static landing page (static asset requests are free) |
scripts/mock-pos.mjs |
Mock POS client for manual testing |
test/ |
Vitest with @cloudflare/vitest-pool-workers |
Needs Node 22.18 or newer.
npm ci
cp .dev.vars.example .dev.vars # then put random values in it
npx wrangler d1 migrations apply floconnect --local
npm run dev # http://localhost:8787, try /healthzTry the mock POS in a second terminal:
npm run mock-pos # enrols, connects, sends "ping" every 30 s
npm run mock-pos -- --ping-ms 5000 # faster ping
npm run mock-pos -- --silent # never pings: watch it go offline
npm run mock-pos -- --proto 0 # old protocol: gets 426 and stops retryingThe mock POS also takes commands on stdin (pair, approve, reject, devices, revoke <id>, revoke-all) and answers report.get encrypted. Pair a mock phone against it (use the same --url):
npm run mock-pos # type: pair (prints CODE and QR)
node scripts/mock-phone.mjs pair-qr "flo://pair?..." # or: pair-code <CODE>, which shows a number to compare
node scripts/mock-phone.mjs report sales --date 2026-12-04
node scripts/mock-phone.mjs summaryState is saved in .mock-pos.json and .mock-phone.json (gitignored). Block a store:
curl -X POST localhost:8787/v1/admin/block \
-H "Authorization: Bearer $ADMIN_TOKEN" \
-d '{"store_id":"<id>","blocked":true}'Checks: npm run typecheck and npm test. Tests run inside the Workers runtime and use short liveness windows set in vitest.config.ts.
Anyone can run their own FloConnect. You need a Cloudflare account on the Workers Paid plan (Durable Objects need it).
npx wrangler d1 create floconnect, then put the printeddatabase_idinwrangler.toml(the committed value is a placeholder).npx wrangler d1 migrations apply floconnect --remote- Set secrets:
npx wrangler secret put STORE_ID_SECRETandnpx wrangler secret put ADMIN_TOKEN(long random values). The MAC secret is yours alone; changing it invalidates every store id. - Add your domain under
routesinwrangler.toml, thennpx wrangler deploy. - Point the POS and the app at your origin (Server URL). A credential is bound to the origin that minted it.
Operator settings live in D1 and take effect without a deploy:
-- daily cap on new stores (default 500)
INSERT OR REPLACE INTO settings (k, v) VALUES ('enroll_daily_cap', '1000');Version gates are variables in wrangler.toml: MIN_POS_PROTO, MIN_APP_PROTO, MIN_POS_VERSION.
Keep the bill low: there are no alarms or timers, the POS sends one text ping every 30 s, and reconnects are throttled. Check the usage page weekly and set a spending limit and a billing alert.
Never commit .dev.vars, secrets or account ids. The database id in wrangler.toml is a placeholder.