Repository navigation
Picnic as second supermarket (search + mapping, no checkout) - #452
Merged
Merged
Conversation
Each ingredient gets an optional picnic_product_id plus a raw cache of the product behind it, stored next to the AH mapping it already has. The migration only adds columns and an index, so existing rows and AH mappings stay exactly as they are. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
HTTP client for Picnic's api/15, modelled on the Picnic client the app carried before it moved to AH. It covers search, reading the cart and adding or removing products in it. There is no checkout, payment or delivery-slot call on purpose: orders finish in the Picnic app. The auth key comes from PICNIC_AUTH_KEY through runtime config, the same way the supermarket's secrets are handled. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
set_mode now accepts picnic next to ah and checklist. In picnic mode the plan syncs into the Picnic cart for every mapped ingredient and the unmapped rest shows up as checklist items that check_item can tick. A dead Picnic falls back to the checklist the same way a dead supermarket does in ah mode. Order items carry which store they come from. The AH code path is unchanged: picnic sync only writes to the Picnic cart and never touches the basket, the AH mappings or an order snapshot. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The fake answers the api/15 routes picnic mode uses: reading the cart, adding and removing products, search and login. It keeps a cart the same way it keeps the AH basket so tests can assert on what sync pushed. The fixtures are hand-written with fake ids and fake image hashes. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Two new tools: search_picnic finds products in the Picnic catalogue, map_ingredient_picnic sets or clears the Picnic product behind an ingredient and caches the name, unit, image and price of a search result. get_shopping_list reports store per item and the ingredient lookup resolves both key spaces, so a picnic cart row and a checklist fallback row both find their ingredient. The order item type gains store, the ingredient type gains picnic_product_id, and set_mode and check_item describe the new mode. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The client tests run against the supermarket fake: search, reading and mutating the cart, and the delta math apply_changes turns a target-quantity diff into. The mode tests cover switching between ah, picnic and checklist, the checklist fallback for unmapped ingredients, ticking, removing with quantity 0, and that a picnic sync leaves the AH basket and the AH mappings untouched. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The MCP README names the two new tools, explains store per item and says Picape never checks out at Picnic. The credentials line in AGENTS.md names the PICNIC_* env vars without their values. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
A non-2xx answer or an error body from Picnic was cached as the cart, so a rejected auth key looked like an empty reachable cart. Responses now raise the shared supermarket error instead, and the client refuses to call out at all while PICNIC_AUTH_KEY is unset. Unplanned recipes now count at quantity 0, like the supermarket path, so unplanning removes products from the Picnic cart. Sync also drops the five-hour cart cache before it computes deltas, so it diffs against the cart Picnic actually has. The search URL encoded the term with Plug.Conn.Query, which produces "=term" rather than "search_term=term"; the fake now requires the parameter so that shape cannot come back. The fake also logs every request for header assertions and can answer 401 AUTH_ERROR on the api/15 routes. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
login/2 now reads the second_factor_authentication_required flag in the body instead of guessing from a missing header, and returns the provisional key so generate_2fa/1 and verify_2fa/2 can finish the login against /user/2fa/generate and /user/2fa/verify. mix picnic.login runs the whole flow and stores the key in config/dev.secret.exs, printing only "ok" so the key never lands in terminal output. Headers Picnic expects got non-empty defaults matching python-picnic-api2, including x-picnic-country: NL, and empty configured values now count as unset. picnic_quantities sums rows per selling unit because the cart can list one on two ORDER_LINE groups. item_ingredient_ids maps the checklist rows picnic mode falls back to by their supermarket product id, the way the rest of the app reads them. add_ingredient accepts a Picnic product without a supermarket product, skipping the product fetch there is none of. README and the MCP descriptions say "Bestelling ontvangen" closes a Picnic order after checkout in the Picnic app. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Searches, pickers and the list all read the order's store now: - search_supermarket on MCP follows the mode, so it hits Picnic in picnic mode; search_picnic stays the explicit variant. GraphQL gets a searchPicnic query for the same catalogue. - The cart screen switches between AH, Picnic and the checklist and shows which store is active. Picnic-mode items that stayed on the checklist get tick boxes there too. - Ingredient screens pick or clear the Picnic product without touching the AH id, and adding an ingredient accepts a Picnic selling unit id on its own. A remap takes the old product out of the Picnic cart, since Picnic keys its cart by selling unit. - Picnic product ids must look like s123; search results fall back to price_ranges when a tile carries no display_price. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Adrian authenticates Picape with the x-picnic-auth value his own Picnic app session sends, not with a username, password or SMS code. The capture of that session shows no login or refresh call: the storefront api carries one long-lived x-picnic-auth on every request. So PICNIC_AUTH_KEY stays a direct access token, and login/2, the 2FA calls, the mix picnic.login task and the fake endpoints go away. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Prod carries a leftover index named recipe_ingredient_picnic_product_id_index on supermarket_product_id from a column rename. That is also the default name Ecto picks for a unique index on picnic_product_id, so the migration would fail on release with a name collision. Give it an explicit name and point the changeset constraints at it. A regression test recreates the leftover index on a scratch test database and runs the real migration over it. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.
Adds Picnic as a second supermarket next to Albert Heijn: AH ordering is down after the cyber incident, so the plan can now sync into the Picnic cart instead. @adri
What changed
Picape.Picnicclient for Picnic's api/15: search, reading the cart, adding and removing products. Modelled on the Picnic client this app carried before it moved to AH.ahandchecklist:picnic.set_modeaccepts it; in picnic mode the plan syncs into the Picnic cart for every mapped ingredient. Unplanned products come out, a remap takes the old product out, and the cart is re-read before each sync.check_itemticks them, in picnic mode too.supermarket_reachablefalse.search_supermarkethits Picnic in picnic mode, GraphQL hassearchPicnic, the cart screen switches between AH, Picnic and checklist, and the ingredient screens pick or clear the Picnic product without touching the AH id. Adding an ingredient accepts a Picnic selling unit id on its own.get_shopping_listreportstoreper item (ah,picnic,checklist).order_item.product_idis numeric and Picnic selling unit ids are strings, so a closed picnic order keeps its plan rows like pre-snapshot orders did.Migrations
One additive migration:
20261018120000_add_ingredient_picnic_productaddspicnic_product_id(string, unique index) andpicnic_product_raw(jsonb) torecipe_ingredient. No drops, no renames, no data rewrites.MCP tools
search_supermarket— searches the active store: Picnic in picnic mode, the supermarket otherwise.search_picnic— search the Picnic catalogue explicitly, returns selling unit ids likes1016186with name, price in cents, unit quantity and image id.map_ingredient_picnic— set or clear an ingredient's Picnic product and cache name/unit/image/price.get_shopping_list— reportsmodeandstoreper item.set_mode— acceptsah,picnicandchecklist.check_item— works in checklist and picnic mode.Auth
PICNIC_AUTH_KEYcarries thex-picnic-authvalue the Picnic app itself sends on every request, taken from an app session.x-picnic-authon every request and never rotates it. Picape therefore uses the configured key directly and has no refresh-token code. When Picnic rejects the key the calls fail and the list falls back to the checklist until a fresh key is configured.Environment
PICNIC_AUTH_KEY— required for picnic mode; thex-picnic-authvalue every call sends.PICNIC_BASE_URL,PICNIC_AGENT,PICNIC_DID,PICNIC_USER_AGENT— optional, defaulted (PICNIC_DIDgets a generated id per boot).No checkout
There is no checkout, order placement, payment, confirmation or delivery-slot code anywhere in this change, and none is planned here. Ordering finishes in the Picnic app; Picape only keeps the cart in step with the plan. After checking out in the Picnic app, tap "Bestelling ontvangen" in Picape to close the order; Picape cannot see a Picnic checkout by itself.
Tests
mix check: green — format, credo --strict, compile --warnings-as-errors, 173 tests, sobelow.cd frontend && npm run check: green (ESLint, Prettier, GraphQL schema check, Jest).bin/e2e: 95 passed, 10 pre-existing platform skips. The shop baseline changed on purpose: the store switch shows where it used to link to the checklist.Not verified without live Picnic credentials: whether the api/15 endpoints and the
x-picnic-authflow still answer exactly the way the client and the fake assume.Follow-ups (pre-existing on master, not fixed here)
&1 + 2inordered_item_quantitiesdouble-counts a planned recipe's ingredients.Plug.Conn.Query.encodeuse builds a wrong request query.Screenshots