Repository navigation
fix(bring): sync the Bring! list into the shopping list, and renew the token (#407) - #408
Merged
Merged
Conversation
…e token (#407) Bring! sync only ever pushed. Items added in the Bring! app never reached shopping_items and items bought there stayed open in Kinboard. - lib/bring-sync.ts: a pure planner plus apply step that reconciles the selected Bring! list with shopping_items. bring_item_id links an item to its Bring! key (the German catalogue name); the new bring_checked column records the ticked state last agreed with Bring!, so a tick from shop mode, an assistant or the offline queue is pushed instead of undone. - migration_bring_pull_sync.sql: bring_checked, plus a server-only bring_removals table filled by a trigger, so an open item deleted from any path is taken off Bring! rather than read back in. - /api/cron/sync-bring every 2 minutes (families with Auto sync on), /api/bring/sync for "Sync now" and the shopping page on open. - Access token renewal via bringauth/token on a 401, for every Bring! call. - Pulled items show in the family's language; ticks and deletes on the shopping page use the Bring! key.
…the URL The session routes take listId from the request and it becomes part of the Bring! URL path (CodeQL: server-side request forgery).
svenger87
force-pushed
the
fix/bring-pull-sync-407
branch
from
October 16, 2026 15:31
566abbd to
65d3a77
Compare
svenger87
marked this pull request as ready for review
October 16, 2026 15:31
… read Review of the pull sync found two ways it could go wrong for a family. Picking another Bring! list (or signing in to another account) left every open item linked to the old list. None of them is on the new one, so the next sync took them as bought there and ticked the whole open list off. Links now record their list (shopping_items.bring_list_id, and bring_removals too); a link to another list counts as no link, so the item is pushed (two-way) or left alone (one-way), and a deletion recorded against the old list is not taken off the new one. The sync read the oldest 1000 rows. Ticked items are never cleared, so a household past 1000 rows had its new items fall outside that window: every item open on Bring! looked new and was inserted again on every run, every two minutes. It now reads every open item (refusing, rather than planning from part of the list, past 1000) plus the newest 1000 ticked ones. Verification: bring-sync.spec 3 new cases, 81/81 with rls-coverage across desktop, mobile and webkit; with the list check switched off the list-switch case fails in all three. Migration applied twice on a local stack without error; the trigger records the list; both PostgREST queries answer 200. tsc and eslint clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #407. Bring! sync only went one way, Kinboard → Bring!. Nothing ever read the Bring! list back into
shopping_items, so items added in the Bring! app never showed up and items bought there stayed open. The access token also ran out after about a week, and pushes then failed silently.lib/bring-sync.ts):planBringSyncis a pure planner, andsyncBringFamilyapplies its plan. The network and the database are injected so the logic can be tested without either. Two pieces of per-item state make the reconcile unambiguous:bring_item_idlinks an item to its Bring! key, which is the German catalogue name, e.g.Milch. Ticks and deletes on the shopping page now send that key, which fixes theMilkvsMilchgap from the issue.bring_checkedis a new column holding the ticked state last agreed with Bring!. Ifcheckeddiffers from it, Kinboard changed the item since, so Kinboard's change is pushed. This covers ticks from shop mode, assistants and the offline queue, which never told Bring! and would otherwise be undone. If the two match, any difference comes from Bring!, and Bring! wins.bring_removalsis a server-only table that a trigger fills. It records open, linked items deleted in Kinboard, so the next sync takes them off Bring! instead of reading them back in. The trigger skips the family-delete cascade; I tested that against Postgres 16./api/cron/sync-bringruns every 2 minutes via ofelia, for families with Auto sync on./api/bring/syncruns for Sync now and when the shopping page opens. A per-family queue stops the two from inserting the same item twice.withBringAccess. On a 401 it callsbringauth/tokenwith the stored refresh token, saves the new token inintegration_secrets, and retries once.catalog.<bcp47>.json.Found in review, fixed here
shopping_items.bring_list_id, also onbring_removals). A link to another list counts as no link: the item is pushed (two-way) or left alone (one-way), and a deletion recorded against the old list is not taken off the new one.Verification: three new cases. bring-sync + rls-coverage 81/81 on desktop, mobile and webkit. With the list check switched off, the list-switch case fails in all three. The migration applies twice on a local stack, the trigger records the list, and both PostgREST reads answer 200.
Type of change
Test plan
e2e/bring-sync.spec.ts, 22 cases: added, bought and re-added in the app; translations; a tick from another screen is pushed, not undone; untick; delete; one-way mode; a failed push leaves the rows alone; two syncs of one family don't overlap; wiringrls-coveragelearned aboutbring_removalsanon, a delete records only open, linked rows, andanoncannot readbring_removals. Deleting a family still cascades.npm run lint,npx tsc --noEmit/shoppingwithin 2 minutes, buy it in the app and see it ticked off, wait past token expiry and see a push still go through.Screenshots
No UI changes beyond the Sync now spinner covering the sync.
Checklist
npm run lintpassesmessages/en.jsonandmessages/de.json(no new strings)webapp/docker/migration*.sqlfile (idempotent —IF NOT EXISTS)CHANGELOG.mdupdated under[Unreleased](Fixed)