-
Notifications
You must be signed in to change notification settings - Fork 929
"Add support for transactions fetching from Plaid" #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
"Add support for transactions fetching from Plaid" #106
Conversation
|
@ArshadMasood is attempting to deploy a commit to the JS Mastery Pro Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThis change refactors the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
Note 🔌 MCP (Model Context Protocol) integration is now available in Early Access!Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
lib/actions/user.actions.ts (1)
174-182: Avoid storing Plaid access_token in plaintextStoring access tokens directly in the database is a high-value target if compromised. Prefer field-level encryption (e.g., AES-256-GCM with per-record IV) before persistence, or a KMS/HSM solution. Also ensure the value is never logged.
If you want, I can provide a small utils encrypt/decrypt helper (Node crypto) and the minimal changes here to encrypt before write and decrypt on read.
🧹 Nitpick comments (7)
lib/actions/user.actions.ts (7)
7-12: Type the Link Token request to avoid casts and tighten compile-time checksImport LinkTokenCreateRequest and annotate tokenParams. This removes ambiguity and prevents accidental shape drift.
import { CountryCode, + LinkTokenCreateRequest, ProcessorTokenCreateRequest, ProcessorTokenCreateRequestProcessorEnum, Products, } from "plaid";- const tokenParams = { + const tokenParams: LinkTokenCreateRequest = { user: { client_user_id: user.$id, }, client_name: `${user.firstName} ${user.lastName}`, - products: ["auth", "transactions"] as Products[], + products: ["auth", "transactions"] as Products[], language: "en", - country_codes: ["US"] as CountryCode[], + country_codes: ["US"] as CountryCode[], };
31-37: Harden getUserInfo and standardize error logging
- Use console.error for errors.
- Optional: Guard against empty result set to prevent user.documents[0] from being undefined.
- const user = await database.listDocuments( + const user = await database.listDocuments( DATABASE_ID!, USER_COLLECTION_ID!, [Query.equal("userId", [userId])] ); - return parseStringify(user.documents[0]); + // Optionally guard against no matches + // if (!user.total) return null; + return parseStringify(user.documents[0]); } catch (error) { - console.log(error); + console.error(error); }
118-123: Use console.error for error pathsFor consistency with other catch blocks and better log semantics, use console.error here.
- } catch (error) { - console.log(error); + } catch (error) { + console.error(error); return null; }
250-250: Nit: clarify error messageMinor grammar improvement for clearer logs.
- console.error("An error occurred while creating exchanging token:", error); + console.error("An error occurred while exchanging the public token:", error);
274-281: Prefer getDocument for direct ID lookupsSince you’re fetching by document ID, getDocument is simpler and more efficient than listDocuments + Query.equal on $id.
- const bank = await database.listDocuments( - DATABASE_ID!, - BANK_COLLECTION_ID!, - [Query.equal("$id", [documentId])] - ); - - return parseStringify(bank.documents[0]); + const bank = await database.getDocument( + DATABASE_ID!, + BANK_COLLECTION_ID!, + documentId + ); + return parseStringify(bank);
266-266: Standardize error logging to console.errorUse console.error for error paths throughout for consistency and log tooling.
Also applies to: 283-283, 36-36, 122-122
286-299: Ensure uniqueness of accountId (ideally scoped by userId) at the DB levelThis function assumes a 1:1 mapping. Enforce a unique index in Appwrite on either:
- accountId (global unique), or
- composite (userId + accountId) if the same accountId could appear under different users.
If you’d like, I can draft an Appwrite migration script to declare the attributes and create the index. Do you want me to open an issue for this?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
lib/actions/user.actions.ts(12 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
lib/actions/user.actions.ts (4)
lib/utils.ts (1)
parseStringify(79-79)lib/appwrite.ts (6)
user(39-41)createAdminClient(26-43)account(20-22)account(33-35)createSessionClient(6-24)database(36-38)lib/actions/dwolla.actions.ts (2)
createDwollaCustomer(54-64)addFundingSource(94-114)lib/plaid.ts (1)
plaidClient(13-13)
🔇 Additional comments (4)
lib/actions/user.actions.ts (4)
52-52: LGTM: Using getUserInfo after sign-inRetrieving and returning the normalized user is correct.
131-134: LGTM: Logout clears cookie and invalidates sessionDeleting the session cookie and calling account.deleteSession("current") is correct.
217-219: LGTM: Processor token creation requestTyping and request fields look correct for Dwolla processor token creation.
141-154: All Plaid linkTokenCreate calls include “transactions”Verified that in lib/actions/user.actions.ts (line 141–154) the
productsarray is defined as["auth", "transactions"]. A repository-wide search forlinkTokenCreateshows no other production code calls that would need the same update.
| const fundingSourceUrl = await addFundingSource({ | ||
| dwollaCustomerId: user.dwollaCustomerId, | ||
| processorToken, | ||
| bankName: accountData.name, | ||
| }); | ||
|
|
||
| // If the funding source URL is not created, throw an error | ||
| if (!fundingSourceUrl) throw Error; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix: throw an Error instance instead of the constructor
throw Error throws the function object, not an Error instance.
- if (!fundingSourceUrl) throw Error;
+ if (!fundingSourceUrl) throw new Error("Failed to create funding source URL");📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const fundingSourceUrl = await addFundingSource({ | |
| dwollaCustomerId: user.dwollaCustomerId, | |
| processorToken, | |
| bankName: accountData.name, | |
| }); | |
| // If the funding source URL is not created, throw an error | |
| if (!fundingSourceUrl) throw Error; | |
| const fundingSourceUrl = await addFundingSource({ | |
| dwollaCustomerId: user.dwollaCustomerId, | |
| processorToken, | |
| bankName: accountData.name, | |
| }); | |
| // If the funding source URL is not created, throw an error | |
| if (!fundingSourceUrl) throw new Error("Failed to create funding source URL"); |
🤖 Prompt for AI Agents
In lib/actions/user.actions.ts around lines 223 to 231, the code throws the
Error constructor instead of an Error instance. Replace "throw Error" with
"throw new Error()" or "throw new Error('Descriptive message')" to correctly
throw an Error object.
Fixed the 400 error by adding "transactions" product support in the user actions when creating the Plaid link token.
Before fix — error received
The error occurred because the
"transactions"product was missing in the Plaid link token creation.After fix — added "transactions" product
Fixed the error by including
"transactions"in the products array during token creation.products: ["auth", "transactions"] as Products[], // Added "transactions" here
Summary by CodeRabbit
Style
New Features