Sideshift: query both old and new affiliate accounts and merge completed orders#220
Sideshift: query both old and new affiliate accounts and merge completed orders#220j0ntz wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b21225d. Configure here.
…ed orders Loop the per-account completed-orders query over each configured affiliate account and merge the streams so a Sideshift affiliate-account rotation keeps reporting the old account's historical and in-flight shifts. Track latestIsoDate per account so neither account's cursor skips the other's orders, falling back to the legacy single cursor for backward compatibility. Single-account config is unchanged. Add a mocha test covering the dual-account merge and per-account cursor behavior. Claude-Session: https://claude.ai/code/session_01YNwNii1LxjqaeowP5d7dgJ
b21225d to
c439b81
Compare
Live dual-account smoke test (throwaway affiliate accounts)Verified the old + new merge end to end against the live Sideshift API, using two throwaway affiliate accounts created via
Fresh affiliate accounts have no order history, so (A)/(B)/(C) confirm the live query, signature, and cursor-map plumbing, while (D) feeds one realistic settled order per account into the live query loop so the real processing + merge path produces a combined non-empty stream. Combined with the deterministic unit tests in The throwaway accounts were used only for this read-only test and carry no funds. |

CHANGELOG
Does this branch warrant an entry to the CHANGELOG?
Dependencies
none
Description
Asana: https://app.asana.com/0/1215088146871429/1216057011453392
The Sideshift partner plugin queried a single affiliate account, so after the
Sideshift affiliate-account rotation it would drop the OLD account's historical
completed orders and miss in-flight shifts still routed under the OLD affiliateId
during the App Store update lag.
This changes
src/partners/sideshift.tsto query BOTH the old and new affiliateaccounts and merge their completed-order streams, per the rotation decision
(query both and merge to preserve complete history).
What changed:
sideshiftAffiliateIdOld/sideshiftAffiliateSecretOldalongside theexisting primary pair.
apiKeysreaching a plugin is a flat string map(
asPartnerInfointypes.ts), so a nested array is not possible; the oldpair is the explicit, backward-compatible form.
getSideshiftAccountsreturnsthe primary account plus the optional old account, deduped by affiliateId.
querySideshiftAccountand run once per configured account; the transactionstreams are merged into one result.
latestIsoDatecursor is tracked PER account in a newsettings.accountsmap so one account's cursor never skips the other'sorders. Legacy progress docs (single top-level
latestIsoDate, no map) fallback to that value on the first run after deploy, so migration is seamless. The
top-level
latestIsoDateis kept as the overall max for backward compatibility.Backward compatible: a single-account config (no old account) behaves exactly as
before. The new account's id/secret are config values ops adds later; the code
supports two accounts now.
Testing
test/sideshift.test.ts(mocha + chai, deterministic, no live network):single-account, dual-account merge with max overall cursor, legacy progress-doc
migration, and per-account cursor isolation. 7 passing.
tscandeslintclean on the changed files.edge-reports-serveris a backend server with no app/sim surface, so there is noin-app drive; the dual-account merge + cursor logic is covered by the unit tests
above. The live Sideshift API and CouchDB persistence paths are unchanged.
Note
Medium Risk
Changes partner reporting sync cursors and can emit duplicate or overlapping orders if both accounts return the same orderId; logic is well-tested but affects financial reporting completeness.
Overview
Sideshift affiliate reporting no longer relies on a single account during an affiliate ID rotation. Optional flat config fields
sideshiftAffiliateIdOld/sideshiftAffiliateSecretOldadd a legacy account alongside the primary pair;getSideshiftAccountsbuilds a deduped list (single-account configs behave as before).The completed-order fetch loop is extracted into
querySideshiftAccountand run once per account, with injectable fetch/process hooks for tests. Results are merged into one transaction list. Sync state addssettings.accounts(per-affiliateIdlatestIsoDate); the top-levellatestIsoDateremains the max across accounts. On first run after upgrade, the primary account inherits the legacy watermark while a newly added old account backfills from epoch so its history is not skipped.Adds
test/sideshift.test.tscovering account list building, dual-account merge, legacy progress docs, and per-account cursor isolation.Reviewed by Cursor Bugbot for commit c439b81. Bugbot is set up for automated code reviews on this repo. Configure here.