- js/sync.js: email/password sign-in (☁ Sync in the menu), a status pill in
the header, and a sync engine that fingerprints each saved game and uploads
the changed ones a few seconds after scoring pauses (right away when a game
ends or the app is hidden), uploads deletions as { deleted: true }, and
applies other devices' changes from a live Firestore listener (including
the game open on screen). Newer version wins; the losing older version is
kept in My Games as a copy and left out of season stats.
- firestore.rules: owner-only access; updates must be newer than stored.
- Firebase compat SDK 12.19.0 bundled in js/vendor/firebase (Apache 2.0,
license included); loaded only on signed-in devices and cached on first use.
- js/firebase-config.js is null until the Firebase project exists, so sync
stays hidden and nothing extra loads.
- Tests: two simulated devices on an in-memory Firebase (7 cases incl.
offline queue and conflict copy); 50 passing. README updated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
1.1 KiB
Plaintext
33 lines
1.1 KiB
Plaintext
rules_version = '2';
|
|
|
|
// Baseball Scorecard sync: each signed-in user reads and writes only their own games.
|
|
// An update is accepted only if it's newer than what's stored, so an older offline
|
|
// edit can't overwrite a newer one (the app then keeps the older version as a copy).
|
|
// Games are never hard-deleted from the app; deletions are stored as { deleted: true }.
|
|
service cloud.firestore {
|
|
match /databases/{database}/documents {
|
|
match /users/{uid}/games/{gameId} {
|
|
function isOwner() {
|
|
return request.auth != null && request.auth.uid == uid;
|
|
}
|
|
function validGame() {
|
|
let d = request.resource.data;
|
|
return d.updatedAt is number
|
|
&& d.deleted is bool
|
|
&& (d.payload == null || (d.payload is string && d.payload.size() < 900000));
|
|
}
|
|
|
|
allow read: if isOwner();
|
|
allow create: if isOwner() && validGame();
|
|
allow update: if isOwner() && validGame()
|
|
&& request.resource.data.updatedAt > resource.data.updatedAt;
|
|
allow delete: if false;
|
|
}
|
|
|
|
// Nothing else is readable or writable
|
|
match /{document=**} {
|
|
allow read, write: if false;
|
|
}
|
|
}
|
|
}
|