Repository navigation
Upgrade pluggy-sdk and migrate away from deprecated page-size transactions to cursor-based transactions - #8103
Conversation
✅ Deploy Preview for actualbudget ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
👋 Hello contributor! We would love to review your PR! Before we can do that, please make sure:
We do this to reduce the TOIL the core contributor team has to go through for each PR and to allow for speedy reviews and merges. For more information, please see our Contributing Guide. |
✅ Deploy Preview for actualbudget-website ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
📝 WalkthroughWalkthroughBumps pluggy-sdk to ^0.85.3, replaces paginated transaction fetching with SDK cursor-based fetchAllTransactions, simplifies service method signature and normalizes returned transactions, updates the /transactions handler to the new service shape, and adds an upcoming release note. ChangesPluggy SDK and Transaction Endpoint Migration
Sequence DiagramsequenceDiagram
participant AppEndpoint
participant PluggyAIService
participant PluggySDKClient
participant PluggyAPI
AppEndpoint->>PluggyAIService: getTransactionsByAccountId(accountId, startDate)
PluggyAIService->>PluggySDKClient: fetchAllTransactions({ dateFrom: startDate })
PluggySDKClient->>PluggyAPI: GET /v2/transactions (cursor-based)
PluggyAPI-->>PluggySDKClient: transactions (cursor pages)
PluggySDKClient-->>PluggyAIService: aggregated transactions
PluggyAIService-->>AppEndpoint: normalized, (sandbox-tagged) transactions
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/sync-server/src/app-pluggyai/pluggyai-service.js (1)
75-90:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winFix return-shape regression in Pluggy AI transactions (array vs paged object)
client.fetchAllTransactions(...)returnsPromise<Transaction[]>, butgetTransactionsByAccountIdstill treats the result like a paged object (transactions.results...) and returns an object (return { ...transactions, ... }). This will break/transactionssinceapp-pluggyai.jsiterates withfor (const trans of transactions)(runtime error), and will also throw in sandbox mode whentransactions.resultsis missing.💡 Proposed fix
- const transactions = await client.fetchAllTransactions(accountId, { + let transactions = await client.fetchAllTransactions(accountId, { dateFrom: startDate, }); if (sandboxAccount) { - transactions.results = transactions.results.map(t => ({ + transactions = transactions.map(t => ({ ...t, sandbox: true, })); } - return { - ...transactions, - hasError: false, - errors: {}, - }; + return transactions;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/sync-server/src/app-pluggyai/pluggyai-service.js` around lines 75 - 90, client.fetchAllTransactions returns Promise<Transaction[]>, but getTransactionsByAccountId currently treats the result as a paged object (uses transactions.results and returns an object with hasError/errors), causing iteration and sandbox mapping to fail; update getTransactionsByAccountId to treat transactions as an array: assign the await client.fetchAllTransactions(...) result to a transactions array, if sandboxAccount map over that array to set sandbox: true on each transaction (replace use of transactions.results), and return the array itself (not an object with hasError/errors) so callers like app-pluggyai.js can iterate with for (const trans of transactions); adjust any surrounding code in getTransactionsByAccountId that relied on the previous paged shape.
🧹 Nitpick comments (2)
packages/sync-server/src/app-pluggyai/pluggyai-service.js (1)
61-96: 🏗️ Heavy liftMigrate this touched Pluggy service module to TypeScript.
This change adds/updates behavior in a
.jsmodule, but the repo guideline requires TypeScript for code in JS/TS paths.As per coding guidelines,
**/*.{js,jsx,ts,tsx}: Use TypeScript for all code.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/sync-server/src/app-pluggyai/pluggyai-service.js` around lines 61 - 96, The file is JavaScript but must be migrated to TypeScript: rename the module to .ts and convert the default export object to typed functions (annotate getTransactionsByAccountId with proper parameter types like accountId: string, startDate: string | undefined and a Promise return type), import or declare types for the Pluggy client, transaction list and error shape, and update references to getPluggyClient and pluggyaiService to typed imports; ensure fetchAllTransactions call is typed and that transactions.results mapping preserves the transaction type while adding sandbox?: boolean; update the catch block to accept unknown and narrow it before accessing message (or use String(error)) and export the service with an explicit type (e.g., PluggyService) so TypeScript compilation and linting pass.packages/sync-server/src/app-pluggyai/app-pluggyai.js (1)
67-75: 🏗️ Heavy liftConvert this touched
/transactionshandler module to TypeScript.The updated route logic is in a
.jsfile, but this path falls under the TypeScript-only guideline.As per coding guidelines,
**/*.{js,jsx,ts,tsx}: Use TypeScript for all code.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/sync-server/src/app-pluggyai/app-pluggyai.js` around lines 67 - 75, This endpoint file is in JavaScript but must be TypeScript; rename app-pluggyai.js to app-pluggyai.ts and update the /transactions route handler to use typed Express Request/Response types (import { Request, Response } from 'express'), type the req.body shape (accountId?: string, startDate?: string) and the pluggyaiService.getTransactionsByAccountId call (ensure pluggyaiService has proper TypeScript signatures or import its types), and update handleError usage to a typed wrapper (e.g., handleError(async (req: Request, res: Response) => { ... })). Also fix any default/commonjs imports to ES module style if needed so the file compiles under the repo TS config.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@packages/sync-server/src/app-pluggyai/pluggyai-service.js`:
- Around line 75-90: client.fetchAllTransactions returns Promise<Transaction[]>,
but getTransactionsByAccountId currently treats the result as a paged object
(uses transactions.results and returns an object with hasError/errors), causing
iteration and sandbox mapping to fail; update getTransactionsByAccountId to
treat transactions as an array: assign the await
client.fetchAllTransactions(...) result to a transactions array, if
sandboxAccount map over that array to set sandbox: true on each transaction
(replace use of transactions.results), and return the array itself (not an
object with hasError/errors) so callers like app-pluggyai.js can iterate with
for (const trans of transactions); adjust any surrounding code in
getTransactionsByAccountId that relied on the previous paged shape.
---
Nitpick comments:
In `@packages/sync-server/src/app-pluggyai/app-pluggyai.js`:
- Around line 67-75: This endpoint file is in JavaScript but must be TypeScript;
rename app-pluggyai.js to app-pluggyai.ts and update the /transactions route
handler to use typed Express Request/Response types (import { Request, Response
} from 'express'), type the req.body shape (accountId?: string, startDate?:
string) and the pluggyaiService.getTransactionsByAccountId call (ensure
pluggyaiService has proper TypeScript signatures or import its types), and
update handleError usage to a typed wrapper (e.g., handleError(async (req:
Request, res: Response) => { ... })). Also fix any default/commonjs imports to
ES module style if needed so the file compiles under the repo TS config.
In `@packages/sync-server/src/app-pluggyai/pluggyai-service.js`:
- Around line 61-96: The file is JavaScript but must be migrated to TypeScript:
rename the module to .ts and convert the default export object to typed
functions (annotate getTransactionsByAccountId with proper parameter types like
accountId: string, startDate: string | undefined and a Promise return type),
import or declare types for the Pluggy client, transaction list and error shape,
and update references to getPluggyClient and pluggyaiService to typed imports;
ensure fetchAllTransactions call is typed and that transactions.results mapping
preserves the transaction type while adding sandbox?: boolean; update the catch
block to accept unknown and narrow it before accessing message (or use
String(error)) and export the service with an explicit type (e.g.,
PluggyService) so TypeScript compilation and linting pass.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 8a632db0-4f39-474a-b9df-520fa628b852
⛔ Files ignored due to path filters (1)
yarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (4)
packages/sync-server/package.jsonpackages/sync-server/src/app-pluggyai/app-pluggyai.jspackages/sync-server/src/app-pluggyai/pluggyai-service.jsupcoming-release-notes/8103.md
|
I'm receiving notifications about this PR, but I don't see any tags on my username |
|
I can't see why it's subscribed you, but giving it a test with prod pluggy would be good if you're able! |
sure, will do |
I got too excited and had a comment with you tagged before the PR was ready and deleted the comment. Sorry! |
|
It didn't work, here some changes I needed to do to make it work on my accounts: diff --git a/packages/sync-server/src/app-pluggyai/app-pluggyai.js b/packages/sync-server/src/app-pluggyai/app-pluggyai.js
index 1e69c878d..bb55c2e49 100644
--- a/packages/sync-server/src/app-pluggyai/app-pluggyai.js
+++ b/packages/sync-server/src/app-pluggyai/app-pluggyai.js
@@ -82,7 +82,7 @@ app.post(
if (account.type === 'CREDIT') {
startingBalance = -startingBalance;
}
- const date = getDate(new Date(account.updatedAt));
+ const date = getDate(account.updatedAt);
const balances = [
{
@@ -99,12 +99,17 @@ app.post(
const booked = [];
const pending = [];
- for (const trans of transactions) {
+ for (const trans of Object.values(transactions)) {
+
+ if(typeof trans !== 'object' || Object.keys(trans).length === 0) {
+ continue;
+ }
+
const newTrans = {};
newTrans.booked = !(trans.status === 'PENDING');
- const transactionDate = new Date(trans.date);
+ const transactionDate = trans.date;
if (transactionDate < startDate && !trans.sandbox) {
continue; |
|
after this changes it synced |
✅ Deploy Preview for actualbudget-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| @@ -0,0 +1,6 @@ | |||
| --- | |||
| category: Maintenance | |||
| authors: [KevinIsMyName. lelemm] | |||
There was a problem hiding this comment.
This needs to be a comma
| authors: [KevinIsMyName. lelemm] | |
| authors: [KevinIsMyName, lelemm] |
There was a problem hiding this comment.
Hey, thanks for catching this one. Fixed!
|
It looks like you may need to update yarn.lock locally with "yarn install". I think something in the dependency update changed the tree. |
Oh interesting, are the current yarn.lock changes outdated? I think pulling master might have caused the current yarn.lock to become stale. |
I'm not sure how it happened in all honesty, but it looks right now! |
|
Thank you all for working on this so quickly, I really appreciate it! If anyone knows, how are releases typically handled for fixes like this? Should I expect this to be included in a patch release, or will it likely ship with the next regular release (which I assume would be sometime in July)? Either way, thank you again for the quick turnaround! |
yes, this will be cited on the release notes all PR's from last release until the merge freeze are included (plus some during merge freeze to improve the new version stability) |
…tions to cursor-based transactions (actualbudget#8103) * Bump pluggy-sdk to include new fetchTransactionsCursor GET /v2/transactions * Use fetchAllTransactions, which uses cursor-based /v2/transactions * Remove weak helper function * Add release note * Fix unused result mapping * Add lelemm's changes Co-authored by: lelemm * Fix lint * Add lelemm as co-author on release note * Update message * Fix comma typo * Update yarn.lock --------- Co-authored-by: Matt Fiddaman <[email protected]>
Description
Use Pluggy.ai's new cursor-based
GET /v2/transactionsinstead of deprecated page-size-basedGET /v1/transactions.Related issue(s)
Fixes #8087
Testing
I was unable to reproduce the bug. I do not use Pluggy.ai because I am not in LATAM. I experienced an unrelated currency conversion bug instead; that bugfix is scoped to me and is not included in this PR.
Tested with Pluggy.ai's sandbox account. See link here to set up sandbox account to get client id and client secret.
Checklist
Bundle Stats
View detailed bundle stats
desktop-client
Total
View detailed bundle breakdown
Added
No assets were added
Removed
No assets were removed
Bigger
No assets were bigger
Smaller
No assets were smaller
Unchanged
loot-core
Total
View detailed bundle breakdown
Added
No assets were added
Removed
No assets were removed
Bigger
No assets were bigger
Smaller
No assets were smaller
Unchanged
api
Total
View detailed bundle breakdown
Added
No assets were added
Removed
No assets were removed
Bigger
No assets were bigger
Smaller
No assets were smaller
Unchanged
cli
Total
View detailed bundle breakdown
Added
No assets were added
Removed
No assets were removed
Bigger
No assets were bigger
Smaller
No assets were smaller
Unchanged
crdt
Total
View detailed bundle breakdown
Added
No assets were added
Removed
No assets were removed
Bigger
No assets were bigger
Smaller
No assets were smaller
Unchanged