opencode-skills-collection 1.0.186 → 1.0.187
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundled-skills/.antigravity-install-manifest.json +5 -1
- package/bundled-skills/3d-web-experience/SKILL.md +152 -37
- package/bundled-skills/agent-evaluation/SKILL.md +1088 -26
- package/bundled-skills/agent-memory-systems/SKILL.md +1037 -25
- package/bundled-skills/agent-tool-builder/SKILL.md +668 -16
- package/bundled-skills/ai-agents-architect/SKILL.md +271 -31
- package/bundled-skills/ai-product/SKILL.md +716 -26
- package/bundled-skills/ai-wrapper-product/SKILL.md +450 -44
- package/bundled-skills/algolia-search/SKILL.md +867 -15
- package/bundled-skills/autonomous-agents/SKILL.md +1033 -26
- package/bundled-skills/aws-serverless/SKILL.md +1046 -35
- package/bundled-skills/azure-functions/SKILL.md +1318 -19
- package/bundled-skills/browser-automation/SKILL.md +1065 -28
- package/bundled-skills/browser-extension-builder/SKILL.md +159 -32
- package/bundled-skills/bullmq-specialist/SKILL.md +347 -16
- package/bundled-skills/clerk-auth/SKILL.md +796 -15
- package/bundled-skills/computer-use-agents/SKILL.md +1870 -28
- package/bundled-skills/context-window-management/SKILL.md +271 -18
- package/bundled-skills/conversation-memory/SKILL.md +453 -24
- package/bundled-skills/crewai/SKILL.md +252 -46
- package/bundled-skills/discord-bot-architect/SKILL.md +1207 -34
- package/bundled-skills/docs/integrations/jetski-cortex.md +3 -3
- package/bundled-skills/docs/integrations/jetski-gemini-loader/README.md +1 -1
- package/bundled-skills/docs/maintainers/repo-growth-seo.md +3 -3
- package/bundled-skills/docs/maintainers/skills-update-guide.md +1 -1
- package/bundled-skills/docs/users/bundles.md +1 -1
- package/bundled-skills/docs/users/claude-code-skills.md +1 -1
- package/bundled-skills/docs/users/gemini-cli-skills.md +1 -1
- package/bundled-skills/docs/users/getting-started.md +1 -1
- package/bundled-skills/docs/users/kiro-integration.md +1 -1
- package/bundled-skills/docs/users/usage.md +4 -4
- package/bundled-skills/docs/users/visual-guide.md +4 -4
- package/bundled-skills/email-systems/SKILL.md +646 -26
- package/bundled-skills/faf-expert/SKILL.md +221 -0
- package/bundled-skills/faf-wizard/SKILL.md +252 -0
- package/bundled-skills/file-uploads/SKILL.md +212 -11
- package/bundled-skills/firebase/SKILL.md +646 -16
- package/bundled-skills/gcp-cloud-run/SKILL.md +1117 -32
- package/bundled-skills/graphql/SKILL.md +1026 -27
- package/bundled-skills/hubspot-integration/SKILL.md +804 -19
- package/bundled-skills/idea-darwin/SKILL.md +120 -0
- package/bundled-skills/inngest/SKILL.md +431 -16
- package/bundled-skills/interactive-portfolio/SKILL.md +342 -44
- package/bundled-skills/langfuse/SKILL.md +296 -41
- package/bundled-skills/langgraph/SKILL.md +259 -50
- package/bundled-skills/micro-saas-launcher/SKILL.md +343 -44
- package/bundled-skills/neon-postgres/SKILL.md +572 -15
- package/bundled-skills/nextjs-supabase-auth/SKILL.md +269 -21
- package/bundled-skills/notion-template-business/SKILL.md +371 -44
- package/bundled-skills/personal-tool-builder/SKILL.md +537 -44
- package/bundled-skills/plaid-fintech/SKILL.md +825 -19
- package/bundled-skills/prompt-caching/SKILL.md +438 -25
- package/bundled-skills/rag-engineer/SKILL.md +271 -29
- package/bundled-skills/salesforce-development/SKILL.md +912 -19
- package/bundled-skills/satori/SKILL.md +54 -0
- package/bundled-skills/scroll-experience/SKILL.md +381 -44
- package/bundled-skills/segment-cdp/SKILL.md +817 -19
- package/bundled-skills/shopify-apps/SKILL.md +1475 -19
- package/bundled-skills/slack-bot-builder/SKILL.md +1162 -28
- package/bundled-skills/telegram-bot-builder/SKILL.md +152 -37
- package/bundled-skills/telegram-mini-app/SKILL.md +445 -44
- package/bundled-skills/trigger-dev/SKILL.md +916 -27
- package/bundled-skills/twilio-communications/SKILL.md +1310 -28
- package/bundled-skills/upstash-qstash/SKILL.md +898 -27
- package/bundled-skills/vercel-deployment/SKILL.md +637 -39
- package/bundled-skills/viral-generator-builder/SKILL.md +132 -37
- package/bundled-skills/voice-agents/SKILL.md +937 -27
- package/bundled-skills/voice-ai-development/SKILL.md +375 -46
- package/bundled-skills/workflow-automation/SKILL.md +982 -29
- package/bundled-skills/zapier-make-patterns/SKILL.md +772 -27
- package/package.json +1 -1
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: plaid-fintech
|
|
3
|
-
description:
|
|
3
|
+
description: Expert patterns for Plaid API integration including Link token
|
|
4
|
+
flows, transactions sync, identity verification, Auth for ACH, balance checks,
|
|
5
|
+
webhook handling, and fintech compliance best practices.
|
|
4
6
|
risk: unknown
|
|
5
|
-
source:
|
|
6
|
-
date_added:
|
|
7
|
+
source: vibeship-spawner-skills (Apache 2.0)
|
|
8
|
+
date_added: 2026-02-27
|
|
7
9
|
---
|
|
8
10
|
|
|
9
11
|
# Plaid Fintech
|
|
10
12
|
|
|
13
|
+
Expert patterns for Plaid API integration including Link token flows,
|
|
14
|
+
transactions sync, identity verification, Auth for ACH, balance checks,
|
|
15
|
+
webhook handling, and fintech compliance best practices.
|
|
16
|
+
|
|
11
17
|
## Patterns
|
|
12
18
|
|
|
13
19
|
### Link Token Creation and Exchange
|
|
@@ -16,37 +22,837 @@ Create a link_token for Plaid Link, exchange public_token for access_token.
|
|
|
16
22
|
Link tokens are short-lived, one-time use. Access tokens don't expire but
|
|
17
23
|
may need updating when users change passwords.
|
|
18
24
|
|
|
25
|
+
// server.ts - Link token creation endpoint
|
|
26
|
+
import { Configuration, PlaidApi, PlaidEnvironments, Products, CountryCode } from 'plaid';
|
|
27
|
+
|
|
28
|
+
const configuration = new Configuration({
|
|
29
|
+
basePath: PlaidEnvironments[process.env.PLAID_ENV || 'sandbox'],
|
|
30
|
+
baseOptions: {
|
|
31
|
+
headers: {
|
|
32
|
+
'PLAID-CLIENT-ID': process.env.PLAID_CLIENT_ID,
|
|
33
|
+
'PLAID-SECRET': process.env.PLAID_SECRET,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const plaidClient = new PlaidApi(configuration);
|
|
39
|
+
|
|
40
|
+
// Create link token for new user
|
|
41
|
+
app.post('/api/plaid/create-link-token', async (req, res) => {
|
|
42
|
+
const { userId } = req.body;
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
const response = await plaidClient.linkTokenCreate({
|
|
46
|
+
user: {
|
|
47
|
+
client_user_id: userId, // Your internal user ID
|
|
48
|
+
},
|
|
49
|
+
client_name: 'My Finance App',
|
|
50
|
+
products: [Products.Transactions],
|
|
51
|
+
country_codes: [CountryCode.Us],
|
|
52
|
+
language: 'en',
|
|
53
|
+
webhook: 'https://yourapp.com/api/plaid/webhooks',
|
|
54
|
+
// Request 180 days for recurring transactions
|
|
55
|
+
transactions: {
|
|
56
|
+
days_requested: 180,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
res.json({ link_token: response.data.link_token });
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error('Link token creation failed:', error);
|
|
63
|
+
res.status(500).json({ error: 'Failed to create link token' });
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Exchange public token for access token
|
|
68
|
+
app.post('/api/plaid/exchange-token', async (req, res) => {
|
|
69
|
+
const { publicToken, userId } = req.body;
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
// Exchange for permanent access token
|
|
73
|
+
const exchangeResponse = await plaidClient.itemPublicTokenExchange({
|
|
74
|
+
public_token: publicToken,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const { access_token, item_id } = exchangeResponse.data;
|
|
78
|
+
|
|
79
|
+
// Store securely - access_token doesn't expire!
|
|
80
|
+
await db.plaidItem.create({
|
|
81
|
+
data: {
|
|
82
|
+
userId,
|
|
83
|
+
itemId: item_id,
|
|
84
|
+
accessToken: await encrypt(access_token), // Encrypt at rest
|
|
85
|
+
status: 'ACTIVE',
|
|
86
|
+
products: ['transactions'],
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Trigger initial transaction sync
|
|
91
|
+
await initiateTransactionSync(item_id, access_token);
|
|
92
|
+
|
|
93
|
+
res.json({ success: true, itemId: item_id });
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.error('Token exchange failed:', error);
|
|
96
|
+
res.status(500).json({ error: 'Failed to exchange token' });
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Frontend - React component
|
|
101
|
+
import { usePlaidLink } from 'react-plaid-link';
|
|
102
|
+
|
|
103
|
+
function BankLinkButton({ userId }: { userId: string }) {
|
|
104
|
+
const [linkToken, setLinkToken] = useState<string | null>(null);
|
|
105
|
+
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
async function createLinkToken() {
|
|
108
|
+
const response = await fetch('/api/plaid/create-link-token', {
|
|
109
|
+
method: 'POST',
|
|
110
|
+
headers: { 'Content-Type': 'application/json' },
|
|
111
|
+
body: JSON.stringify({ userId }),
|
|
112
|
+
});
|
|
113
|
+
const { link_token } = await response.json();
|
|
114
|
+
setLinkToken(link_token);
|
|
115
|
+
}
|
|
116
|
+
createLinkToken();
|
|
117
|
+
}, [userId]);
|
|
118
|
+
|
|
119
|
+
const { open, ready } = usePlaidLink({
|
|
120
|
+
token: linkToken,
|
|
121
|
+
onSuccess: async (publicToken, metadata) => {
|
|
122
|
+
// Exchange public token for access token
|
|
123
|
+
await fetch('/api/plaid/exchange-token', {
|
|
124
|
+
method: 'POST',
|
|
125
|
+
headers: { 'Content-Type': 'application/json' },
|
|
126
|
+
body: JSON.stringify({ publicToken, userId }),
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
onExit: (error, metadata) => {
|
|
130
|
+
if (error) {
|
|
131
|
+
console.error('Link exit error:', error);
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<button onClick={() => open()} disabled={!ready}>
|
|
138
|
+
Connect Bank Account
|
|
139
|
+
</button>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
### Context
|
|
144
|
+
|
|
145
|
+
- initial bank linking
|
|
146
|
+
- user onboarding
|
|
147
|
+
- connecting accounts
|
|
148
|
+
|
|
19
149
|
### Transactions Sync
|
|
20
150
|
|
|
21
151
|
Use /transactions/sync for incremental transaction updates. More efficient
|
|
22
152
|
than /transactions/get. Handle webhooks for real-time updates instead of
|
|
23
153
|
polling.
|
|
24
154
|
|
|
155
|
+
// Transactions sync service
|
|
156
|
+
interface TransactionSyncState {
|
|
157
|
+
cursor: string | null;
|
|
158
|
+
hasMore: boolean;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async function syncTransactions(
|
|
162
|
+
accessToken: string,
|
|
163
|
+
itemId: string
|
|
164
|
+
): Promise<void> {
|
|
165
|
+
// Get last cursor from database
|
|
166
|
+
const item = await db.plaidItem.findUnique({
|
|
167
|
+
where: { itemId },
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
let cursor = item?.transactionsCursor || null;
|
|
171
|
+
let hasMore = true;
|
|
172
|
+
let addedCount = 0;
|
|
173
|
+
let modifiedCount = 0;
|
|
174
|
+
let removedCount = 0;
|
|
175
|
+
|
|
176
|
+
while (hasMore) {
|
|
177
|
+
try {
|
|
178
|
+
const response = await plaidClient.transactionsSync({
|
|
179
|
+
access_token: accessToken,
|
|
180
|
+
cursor: cursor || undefined,
|
|
181
|
+
count: 500, // Max per request
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const { added, modified, removed, next_cursor, has_more } = response.data;
|
|
185
|
+
|
|
186
|
+
// Process added transactions
|
|
187
|
+
if (added.length > 0) {
|
|
188
|
+
await db.transaction.createMany({
|
|
189
|
+
data: added.map(txn => ({
|
|
190
|
+
plaidTransactionId: txn.transaction_id,
|
|
191
|
+
itemId,
|
|
192
|
+
accountId: txn.account_id,
|
|
193
|
+
amount: txn.amount,
|
|
194
|
+
date: new Date(txn.date),
|
|
195
|
+
name: txn.name,
|
|
196
|
+
merchantName: txn.merchant_name,
|
|
197
|
+
category: txn.personal_finance_category?.primary,
|
|
198
|
+
subcategory: txn.personal_finance_category?.detailed,
|
|
199
|
+
pending: txn.pending,
|
|
200
|
+
paymentChannel: txn.payment_channel,
|
|
201
|
+
location: txn.location ? JSON.stringify(txn.location) : null,
|
|
202
|
+
})),
|
|
203
|
+
skipDuplicates: true,
|
|
204
|
+
});
|
|
205
|
+
addedCount += added.length;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Process modified transactions
|
|
209
|
+
for (const txn of modified) {
|
|
210
|
+
await db.transaction.updateMany({
|
|
211
|
+
where: { plaidTransactionId: txn.transaction_id },
|
|
212
|
+
data: {
|
|
213
|
+
amount: txn.amount,
|
|
214
|
+
name: txn.name,
|
|
215
|
+
merchantName: txn.merchant_name,
|
|
216
|
+
pending: txn.pending,
|
|
217
|
+
updatedAt: new Date(),
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
modifiedCount++;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Process removed transactions
|
|
224
|
+
if (removed.length > 0) {
|
|
225
|
+
await db.transaction.deleteMany({
|
|
226
|
+
where: {
|
|
227
|
+
plaidTransactionId: {
|
|
228
|
+
in: removed.map(r => r.transaction_id),
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
removedCount += removed.length;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
cursor = next_cursor;
|
|
236
|
+
hasMore = has_more;
|
|
237
|
+
|
|
238
|
+
} catch (error: any) {
|
|
239
|
+
if (error.response?.data?.error_code === 'TRANSACTIONS_SYNC_MUTATION_DURING_PAGINATION') {
|
|
240
|
+
// Data changed during pagination, restart from null
|
|
241
|
+
cursor = null;
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
throw error;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Save cursor for next sync
|
|
249
|
+
await db.plaidItem.update({
|
|
250
|
+
where: { itemId },
|
|
251
|
+
data: { transactionsCursor: cursor },
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
console.log(`Sync complete: +${addedCount} ~${modifiedCount} -${removedCount}`);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Webhook handler for real-time updates
|
|
258
|
+
app.post('/api/plaid/webhooks', async (req, res) => {
|
|
259
|
+
const { webhook_type, webhook_code, item_id } = req.body;
|
|
260
|
+
|
|
261
|
+
// Verify webhook (see webhook verification pattern)
|
|
262
|
+
if (!verifyPlaidWebhook(req)) {
|
|
263
|
+
return res.status(401).send('Invalid webhook');
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (webhook_type === 'TRANSACTIONS') {
|
|
267
|
+
switch (webhook_code) {
|
|
268
|
+
case 'SYNC_UPDATES_AVAILABLE':
|
|
269
|
+
// New transactions available, trigger sync
|
|
270
|
+
await queueTransactionSync(item_id);
|
|
271
|
+
break;
|
|
272
|
+
case 'INITIAL_UPDATE':
|
|
273
|
+
// Initial batch of transactions ready
|
|
274
|
+
await queueTransactionSync(item_id);
|
|
275
|
+
break;
|
|
276
|
+
case 'HISTORICAL_UPDATE':
|
|
277
|
+
// Historical transactions ready
|
|
278
|
+
await queueTransactionSync(item_id);
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
res.sendStatus(200);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
### Context
|
|
287
|
+
|
|
288
|
+
- fetching transactions
|
|
289
|
+
- transaction history
|
|
290
|
+
- account activity
|
|
291
|
+
|
|
25
292
|
### Item Error Handling and Update Mode
|
|
26
293
|
|
|
27
294
|
Handle ITEM_LOGIN_REQUIRED errors by putting users through Link update mode.
|
|
28
295
|
Listen for PENDING_DISCONNECT webhook to proactively prompt users.
|
|
29
296
|
|
|
30
|
-
|
|
297
|
+
// Create link token for update mode
|
|
298
|
+
app.post('/api/plaid/create-update-token', async (req, res) => {
|
|
299
|
+
const { itemId } = req.body;
|
|
300
|
+
|
|
301
|
+
const item = await db.plaidItem.findUnique({
|
|
302
|
+
where: { itemId },
|
|
303
|
+
include: { user: true },
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
if (!item) {
|
|
307
|
+
return res.status(404).json({ error: 'Item not found' });
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
try {
|
|
311
|
+
const response = await plaidClient.linkTokenCreate({
|
|
312
|
+
user: {
|
|
313
|
+
client_user_id: item.userId,
|
|
314
|
+
},
|
|
315
|
+
client_name: 'My Finance App',
|
|
316
|
+
country_codes: [CountryCode.Us],
|
|
317
|
+
language: 'en',
|
|
318
|
+
webhook: 'https://yourapp.com/api/plaid/webhooks',
|
|
319
|
+
// Update mode: provide access_token instead of products
|
|
320
|
+
access_token: await decrypt(item.accessToken),
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
res.json({ link_token: response.data.link_token });
|
|
324
|
+
} catch (error) {
|
|
325
|
+
console.error('Update token creation failed:', error);
|
|
326
|
+
res.status(500).json({ error: 'Failed to create update token' });
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
// Handle item errors from webhooks
|
|
331
|
+
app.post('/api/plaid/webhooks', async (req, res) => {
|
|
332
|
+
const { webhook_type, webhook_code, item_id, error } = req.body;
|
|
333
|
+
|
|
334
|
+
if (webhook_type === 'ITEM') {
|
|
335
|
+
switch (webhook_code) {
|
|
336
|
+
case 'ERROR':
|
|
337
|
+
// Item has entered an error state
|
|
338
|
+
await db.plaidItem.update({
|
|
339
|
+
where: { itemId: item_id },
|
|
340
|
+
data: {
|
|
341
|
+
status: 'ERROR',
|
|
342
|
+
errorCode: error?.error_code,
|
|
343
|
+
errorMessage: error?.error_message,
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
// Notify user to reconnect
|
|
348
|
+
if (error?.error_code === 'ITEM_LOGIN_REQUIRED') {
|
|
349
|
+
await notifyUserReconnect(item_id, 'Please reconnect your bank account');
|
|
350
|
+
}
|
|
351
|
+
break;
|
|
352
|
+
|
|
353
|
+
case 'PENDING_DISCONNECT':
|
|
354
|
+
// User needs to reauthorize soon
|
|
355
|
+
await db.plaidItem.update({
|
|
356
|
+
where: { itemId: item_id },
|
|
357
|
+
data: { status: 'PENDING_DISCONNECT' },
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
// Proactive notification
|
|
361
|
+
await notifyUserReconnect(item_id, 'Your bank connection will expire soon');
|
|
362
|
+
break;
|
|
363
|
+
|
|
364
|
+
case 'USER_PERMISSION_REVOKED':
|
|
365
|
+
// User revoked access at their bank
|
|
366
|
+
await db.plaidItem.update({
|
|
367
|
+
where: { itemId: item_id },
|
|
368
|
+
data: { status: 'REVOKED' },
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
// Clean up stored data
|
|
372
|
+
await db.transaction.deleteMany({
|
|
373
|
+
where: { itemId: item_id },
|
|
374
|
+
});
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
res.sendStatus(200);
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
// Check item status before API calls
|
|
383
|
+
async function getItemWithValidation(itemId: string) {
|
|
384
|
+
const item = await db.plaidItem.findUnique({
|
|
385
|
+
where: { itemId },
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
if (!item) {
|
|
389
|
+
throw new Error('Item not found');
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if (item.status === 'ERROR') {
|
|
393
|
+
throw new ItemNeedsUpdateError(item.errorCode, item.errorMessage);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return item;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
### Context
|
|
400
|
+
|
|
401
|
+
- error recovery
|
|
402
|
+
- reauthorization
|
|
403
|
+
- credential updates
|
|
404
|
+
|
|
405
|
+
### Auth for ACH Transfers
|
|
406
|
+
|
|
407
|
+
Use Auth product to get account and routing numbers for ACH transfers.
|
|
408
|
+
Combine with Identity to verify account ownership before initiating
|
|
409
|
+
transfers.
|
|
410
|
+
|
|
411
|
+
// Get account and routing numbers
|
|
412
|
+
async function getACHNumbers(accessToken: string): Promise<ACHInfo[]> {
|
|
413
|
+
const response = await plaidClient.authGet({
|
|
414
|
+
access_token: accessToken,
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
const { accounts, numbers } = response.data;
|
|
418
|
+
|
|
419
|
+
// Map ACH numbers to accounts
|
|
420
|
+
return accounts.map(account => {
|
|
421
|
+
const achNumber = numbers.ach.find(
|
|
422
|
+
n => n.account_id === account.account_id
|
|
423
|
+
);
|
|
424
|
+
|
|
425
|
+
return {
|
|
426
|
+
accountId: account.account_id,
|
|
427
|
+
name: account.name,
|
|
428
|
+
mask: account.mask,
|
|
429
|
+
type: account.type,
|
|
430
|
+
subtype: account.subtype,
|
|
431
|
+
routing: achNumber?.routing,
|
|
432
|
+
account: achNumber?.account,
|
|
433
|
+
wireRouting: achNumber?.wire_routing,
|
|
434
|
+
};
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// Verify identity before ACH transfer
|
|
439
|
+
async function verifyAndInitiateTransfer(
|
|
440
|
+
accessToken: string,
|
|
441
|
+
userId: string,
|
|
442
|
+
amount: number
|
|
443
|
+
): Promise<TransferResult> {
|
|
444
|
+
// Get identity from linked account
|
|
445
|
+
const identityResponse = await plaidClient.identityGet({
|
|
446
|
+
access_token: accessToken,
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
const accountOwners = identityResponse.data.accounts[0]?.owners || [];
|
|
450
|
+
|
|
451
|
+
// Get user's stored identity
|
|
452
|
+
const user = await db.user.findUnique({
|
|
453
|
+
where: { id: userId },
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
// Match identity
|
|
457
|
+
const matchResponse = await plaidClient.identityMatch({
|
|
458
|
+
access_token: accessToken,
|
|
459
|
+
user: {
|
|
460
|
+
legal_name: user.legalName,
|
|
461
|
+
phone_number: user.phoneNumber,
|
|
462
|
+
email_address: user.email,
|
|
463
|
+
address: {
|
|
464
|
+
street: user.street,
|
|
465
|
+
city: user.city,
|
|
466
|
+
region: user.state,
|
|
467
|
+
postal_code: user.postalCode,
|
|
468
|
+
country: 'US',
|
|
469
|
+
},
|
|
470
|
+
},
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
const matchScores = matchResponse.data.accounts[0]?.legal_name;
|
|
474
|
+
|
|
475
|
+
// Require high confidence for transfers
|
|
476
|
+
if ((matchScores?.score || 0) < 70) {
|
|
477
|
+
throw new Error('Identity verification failed');
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// Get real-time balance for the transfer
|
|
481
|
+
const balanceResponse = await plaidClient.accountsBalanceGet({
|
|
482
|
+
access_token: accessToken,
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
const account = balanceResponse.data.accounts[0];
|
|
486
|
+
|
|
487
|
+
// Check sufficient funds (consider pending)
|
|
488
|
+
const availableBalance = account.balances.available ?? account.balances.current;
|
|
489
|
+
if (availableBalance < amount) {
|
|
490
|
+
throw new Error('Insufficient funds');
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// Get ACH numbers and initiate transfer
|
|
494
|
+
const authResponse = await plaidClient.authGet({
|
|
495
|
+
access_token: accessToken,
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
const achNumbers = authResponse.data.numbers.ach.find(
|
|
499
|
+
n => n.account_id === account.account_id
|
|
500
|
+
);
|
|
501
|
+
|
|
502
|
+
// Initiate ACH transfer with your payment processor
|
|
503
|
+
return await initiateACHTransfer({
|
|
504
|
+
routingNumber: achNumbers.routing,
|
|
505
|
+
accountNumber: achNumbers.account,
|
|
506
|
+
amount,
|
|
507
|
+
accountType: account.subtype,
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
### Context
|
|
512
|
+
|
|
513
|
+
- ach transfers
|
|
514
|
+
- money movement
|
|
515
|
+
- account funding
|
|
516
|
+
|
|
517
|
+
### Real-Time Balance Check
|
|
518
|
+
|
|
519
|
+
Use /accounts/balance/get for real-time balance (paid endpoint).
|
|
520
|
+
/accounts/get returns cached data suitable for display but not
|
|
521
|
+
real-time decisions.
|
|
522
|
+
|
|
523
|
+
interface BalanceInfo {
|
|
524
|
+
accountId: string;
|
|
525
|
+
available: number | null;
|
|
526
|
+
current: number;
|
|
527
|
+
limit: number | null;
|
|
528
|
+
isoCurrencyCode: string;
|
|
529
|
+
lastUpdated: Date;
|
|
530
|
+
isRealtime: boolean;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// Get cached balance (free, suitable for display)
|
|
534
|
+
async function getCachedBalances(accessToken: string): Promise<BalanceInfo[]> {
|
|
535
|
+
const response = await plaidClient.accountsGet({
|
|
536
|
+
access_token: accessToken,
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
return response.data.accounts.map(account => ({
|
|
540
|
+
accountId: account.account_id,
|
|
541
|
+
available: account.balances.available,
|
|
542
|
+
current: account.balances.current,
|
|
543
|
+
limit: account.balances.limit,
|
|
544
|
+
isoCurrencyCode: account.balances.iso_currency_code || 'USD',
|
|
545
|
+
lastUpdated: new Date(account.balances.last_updated_datetime || Date.now()),
|
|
546
|
+
isRealtime: false,
|
|
547
|
+
}));
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// Get real-time balance (paid, for payment validation)
|
|
551
|
+
async function getRealTimeBalance(
|
|
552
|
+
accessToken: string,
|
|
553
|
+
accountIds?: string[]
|
|
554
|
+
): Promise<BalanceInfo[]> {
|
|
555
|
+
const response = await plaidClient.accountsBalanceGet({
|
|
556
|
+
access_token: accessToken,
|
|
557
|
+
options: accountIds ? { account_ids: accountIds } : undefined,
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
return response.data.accounts.map(account => ({
|
|
561
|
+
accountId: account.account_id,
|
|
562
|
+
available: account.balances.available,
|
|
563
|
+
current: account.balances.current,
|
|
564
|
+
limit: account.balances.limit,
|
|
565
|
+
isoCurrencyCode: account.balances.iso_currency_code || 'USD',
|
|
566
|
+
lastUpdated: new Date(),
|
|
567
|
+
isRealtime: true,
|
|
568
|
+
}));
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// Payment validation with balance check
|
|
572
|
+
async function validatePayment(
|
|
573
|
+
accessToken: string,
|
|
574
|
+
accountId: string,
|
|
575
|
+
amount: number
|
|
576
|
+
): Promise<PaymentValidation> {
|
|
577
|
+
const balances = await getRealTimeBalance(accessToken, [accountId]);
|
|
578
|
+
const account = balances.find(b => b.accountId === accountId);
|
|
579
|
+
|
|
580
|
+
if (!account) {
|
|
581
|
+
return { valid: false, reason: 'Account not found' };
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
const available = account.available ?? account.current;
|
|
31
585
|
|
|
32
|
-
|
|
586
|
+
if (available < amount) {
|
|
587
|
+
return {
|
|
588
|
+
valid: false,
|
|
589
|
+
reason: 'Insufficient funds',
|
|
590
|
+
available,
|
|
591
|
+
requested: amount,
|
|
592
|
+
};
|
|
593
|
+
}
|
|
33
594
|
|
|
34
|
-
|
|
595
|
+
return {
|
|
596
|
+
valid: true,
|
|
597
|
+
available,
|
|
598
|
+
requested: amount,
|
|
599
|
+
};
|
|
600
|
+
}
|
|
35
601
|
|
|
36
|
-
###
|
|
602
|
+
### Context
|
|
37
603
|
|
|
38
|
-
|
|
604
|
+
- balance checking
|
|
605
|
+
- fund availability
|
|
606
|
+
- payment validation
|
|
39
607
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
608
|
+
### Webhook Verification
|
|
609
|
+
|
|
610
|
+
Verify Plaid webhooks using the verification key endpoint.
|
|
611
|
+
Handle duplicate webhooks idempotently and design for out-of-order
|
|
612
|
+
delivery.
|
|
613
|
+
|
|
614
|
+
import jwt from 'jsonwebtoken';
|
|
615
|
+
import jwksClient from 'jwks-rsa';
|
|
616
|
+
|
|
617
|
+
// Cache JWKS client
|
|
618
|
+
const client = jwksClient({
|
|
619
|
+
jwksUri: 'https://production.plaid.com/.well-known/jwks.json',
|
|
620
|
+
cache: true,
|
|
621
|
+
cacheMaxAge: 86400000, // 24 hours
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
async function getSigningKey(kid: string): Promise<string> {
|
|
625
|
+
const key = await client.getSigningKey(kid);
|
|
626
|
+
return key.getPublicKey();
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
async function verifyPlaidWebhook(req: Request): Promise<boolean> {
|
|
630
|
+
const signedJwt = req.headers['plaid-verification'];
|
|
631
|
+
|
|
632
|
+
if (!signedJwt) {
|
|
633
|
+
return false;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
try {
|
|
637
|
+
// Decode to get kid
|
|
638
|
+
const decoded = jwt.decode(signedJwt, { complete: true });
|
|
639
|
+
if (!decoded?.header?.kid) {
|
|
640
|
+
return false;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// Get signing key
|
|
644
|
+
const key = await getSigningKey(decoded.header.kid);
|
|
645
|
+
|
|
646
|
+
// Verify JWT
|
|
647
|
+
const claims = jwt.verify(signedJwt, key, {
|
|
648
|
+
algorithms: ['ES256'],
|
|
649
|
+
}) as any;
|
|
650
|
+
|
|
651
|
+
// Verify body hash
|
|
652
|
+
const bodyHash = crypto
|
|
653
|
+
.createHash('sha256')
|
|
654
|
+
.update(JSON.stringify(req.body))
|
|
655
|
+
.digest('hex');
|
|
656
|
+
|
|
657
|
+
if (claims.request_body_sha256 !== bodyHash) {
|
|
658
|
+
return false;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// Check timestamp (within 5 minutes)
|
|
662
|
+
const issuedAt = new Date(claims.iat * 1000);
|
|
663
|
+
const fiveMinutesAgo = new Date(Date.now() - 5 * 60 * 1000);
|
|
664
|
+
if (issuedAt < fiveMinutesAgo) {
|
|
665
|
+
return false;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
return true;
|
|
669
|
+
} catch (error) {
|
|
670
|
+
console.error('Webhook verification failed:', error);
|
|
671
|
+
return false;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// Idempotent webhook handler
|
|
676
|
+
app.post('/api/plaid/webhooks', async (req, res) => {
|
|
677
|
+
// Verify webhook signature
|
|
678
|
+
if (!await verifyPlaidWebhook(req)) {
|
|
679
|
+
return res.status(401).send('Invalid signature');
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
const { webhook_type, webhook_code, item_id } = req.body;
|
|
683
|
+
|
|
684
|
+
// Create idempotency key
|
|
685
|
+
const idempotencyKey = `${webhook_type}:${webhook_code}:${item_id}:${JSON.stringify(req.body)}`;
|
|
686
|
+
const idempotencyHash = crypto.createHash('sha256').update(idempotencyKey).digest('hex');
|
|
687
|
+
|
|
688
|
+
// Check if already processed
|
|
689
|
+
const existing = await db.webhookLog.findUnique({
|
|
690
|
+
where: { idempotencyHash },
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
if (existing) {
|
|
694
|
+
console.log('Duplicate webhook, skipping:', idempotencyHash);
|
|
695
|
+
return res.sendStatus(200);
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
// Record webhook before processing
|
|
699
|
+
await db.webhookLog.create({
|
|
700
|
+
data: {
|
|
701
|
+
idempotencyHash,
|
|
702
|
+
webhookType: webhook_type,
|
|
703
|
+
webhookCode: webhook_code,
|
|
704
|
+
itemId: item_id,
|
|
705
|
+
payload: req.body,
|
|
706
|
+
processedAt: new Date(),
|
|
707
|
+
},
|
|
708
|
+
});
|
|
709
|
+
|
|
710
|
+
// Process webhook (async for quick response)
|
|
711
|
+
processWebhookAsync(req.body).catch(console.error);
|
|
712
|
+
|
|
713
|
+
res.sendStatus(200);
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
### Context
|
|
717
|
+
|
|
718
|
+
- webhook security
|
|
719
|
+
- event processing
|
|
720
|
+
- production deployment
|
|
721
|
+
|
|
722
|
+
## Sharp Edges
|
|
723
|
+
|
|
724
|
+
### Access Tokens Never Expire But Are Highly Sensitive
|
|
725
|
+
|
|
726
|
+
Severity: CRITICAL
|
|
727
|
+
|
|
728
|
+
### accounts/get Returns Cached Balances, Not Real-Time
|
|
729
|
+
|
|
730
|
+
Severity: HIGH
|
|
731
|
+
|
|
732
|
+
### Webhooks May Arrive Out of Order or Duplicated
|
|
733
|
+
|
|
734
|
+
Severity: HIGH
|
|
735
|
+
|
|
736
|
+
### Items Enter Error States That Require User Action
|
|
737
|
+
|
|
738
|
+
Severity: HIGH
|
|
739
|
+
|
|
740
|
+
### Sandbox Does Not Reflect Production Complexity
|
|
741
|
+
|
|
742
|
+
Severity: MEDIUM
|
|
743
|
+
|
|
744
|
+
### TRANSACTIONS_SYNC_MUTATION_DURING_PAGINATION Requires Restart
|
|
745
|
+
|
|
746
|
+
Severity: MEDIUM
|
|
747
|
+
|
|
748
|
+
### Link Tokens Are Short-Lived and Single-Use
|
|
749
|
+
|
|
750
|
+
Severity: MEDIUM
|
|
751
|
+
|
|
752
|
+
### Recurring Transactions Need 180+ Days of History
|
|
753
|
+
|
|
754
|
+
Severity: MEDIUM
|
|
755
|
+
|
|
756
|
+
## Validation Checks
|
|
757
|
+
|
|
758
|
+
### Access Token Stored in Plain Text
|
|
759
|
+
|
|
760
|
+
Severity: ERROR
|
|
761
|
+
|
|
762
|
+
Plaid access tokens must be encrypted at rest
|
|
763
|
+
|
|
764
|
+
Message: Plaid access token appears to be stored unencrypted. Encrypt at rest.
|
|
765
|
+
|
|
766
|
+
### Plaid Secret in Client Code
|
|
767
|
+
|
|
768
|
+
Severity: ERROR
|
|
769
|
+
|
|
770
|
+
Plaid secret must never be exposed to clients
|
|
771
|
+
|
|
772
|
+
Message: Plaid secret may be exposed. Keep server-side only.
|
|
773
|
+
|
|
774
|
+
### Hardcoded Plaid Credentials
|
|
775
|
+
|
|
776
|
+
Severity: ERROR
|
|
777
|
+
|
|
778
|
+
Credentials must use environment variables
|
|
779
|
+
|
|
780
|
+
Message: Hardcoded Plaid credentials. Use environment variables.
|
|
781
|
+
|
|
782
|
+
### Missing Webhook Signature Verification
|
|
783
|
+
|
|
784
|
+
Severity: ERROR
|
|
785
|
+
|
|
786
|
+
Plaid webhooks must verify JWT signature
|
|
787
|
+
|
|
788
|
+
Message: Webhook handler without signature verification. Verify Plaid-Verification header.
|
|
789
|
+
|
|
790
|
+
### Using Cached Balance for Payment Decision
|
|
791
|
+
|
|
792
|
+
Severity: ERROR
|
|
793
|
+
|
|
794
|
+
Use real-time balance for payment validation
|
|
795
|
+
|
|
796
|
+
Message: Using accountsGet (cached) for payment. Use accountsBalanceGet for real-time balance.
|
|
797
|
+
|
|
798
|
+
### Missing Item Error State Handling
|
|
799
|
+
|
|
800
|
+
Severity: WARNING
|
|
801
|
+
|
|
802
|
+
API calls should handle ITEM_LOGIN_REQUIRED
|
|
803
|
+
|
|
804
|
+
Message: API call without ITEM_LOGIN_REQUIRED handling. Handle item error states.
|
|
805
|
+
|
|
806
|
+
### Polling for Transactions Instead of Webhooks
|
|
807
|
+
|
|
808
|
+
Severity: WARNING
|
|
809
|
+
|
|
810
|
+
Use webhooks for transaction updates
|
|
811
|
+
|
|
812
|
+
Message: Polling for transactions. Configure webhooks for SYNC_UPDATES_AVAILABLE.
|
|
813
|
+
|
|
814
|
+
### Link Token Cached or Reused
|
|
815
|
+
|
|
816
|
+
Severity: WARNING
|
|
817
|
+
|
|
818
|
+
Link tokens are single-use and expire in 4 hours
|
|
819
|
+
|
|
820
|
+
Message: Link tokens should not be cached. Create fresh token for each session.
|
|
821
|
+
|
|
822
|
+
### Using Deprecated Public Key
|
|
823
|
+
|
|
824
|
+
Severity: ERROR
|
|
825
|
+
|
|
826
|
+
Public key integration ended January 2025
|
|
827
|
+
|
|
828
|
+
Message: Public key is deprecated. Use Link tokens instead.
|
|
829
|
+
|
|
830
|
+
### Transaction Sync Without Cursor Storage
|
|
831
|
+
|
|
832
|
+
Severity: WARNING
|
|
833
|
+
|
|
834
|
+
Store cursor for incremental syncs
|
|
835
|
+
|
|
836
|
+
Message: Transaction sync without cursor persistence. Store cursor for incremental sync.
|
|
837
|
+
|
|
838
|
+
## Collaboration
|
|
839
|
+
|
|
840
|
+
### Delegation Triggers
|
|
841
|
+
|
|
842
|
+
- user needs payment processing -> stripe-integration (Stripe for actual payment, Plaid for account linking)
|
|
843
|
+
- user needs budgeting features -> analytics-specialist (Transaction categorization and analysis)
|
|
844
|
+
- user needs investment tracking -> data-engineer (Portfolio analysis and reporting)
|
|
845
|
+
- user needs compliance/audit -> security-specialist (SOC 2, PCI compliance)
|
|
846
|
+
- user needs mobile app -> mobile-developer (React Native Plaid SDK)
|
|
50
847
|
|
|
51
848
|
## When to Use
|
|
52
|
-
|
|
849
|
+
|
|
850
|
+
- User mentions or implies: plaid
|
|
851
|
+
- User mentions or implies: bank account linking
|
|
852
|
+
- User mentions or implies: bank connection
|
|
853
|
+
- User mentions or implies: ach
|
|
854
|
+
- User mentions or implies: account aggregation
|
|
855
|
+
- User mentions or implies: bank transactions
|
|
856
|
+
- User mentions or implies: open banking
|
|
857
|
+
- User mentions or implies: fintech
|
|
858
|
+
- User mentions or implies: identity verification banking
|