Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

About

Cloudflare bridge between Flo POS apps and outside clients

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

FloConnect

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.

Layout

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

Local development

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 /healthz

Try 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 retrying

The 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 summary

State 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.

Self-hosting

Anyone can run their own FloConnect. You need a Cloudflare account on the Workers Paid plan (Durable Objects need it).

  1. npx wrangler d1 create floconnect, then put the printed database_id in wrangler.toml (the committed value is a placeholder).
  2. npx wrangler d1 migrations apply floconnect --remote
  3. Set secrets: npx wrangler secret put STORE_ID_SECRET and npx wrangler secret put ADMIN_TOKEN (long random values). The MAC secret is yours alone; changing it invalidates every store id.
  4. Add your domain under routes in wrangler.toml, then npx wrangler deploy.
  5. 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.

Security notes

Never commit .dev.vars, secrets or account ids. The database id in wrangler.toml is a placeholder.

About

Cloudflare bridge between Flo POS apps and outside clients

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages