plaid / plaid-node

Node bindings for Plaid

Home Page:https://plaid.com/docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No support for edge runtime environment

codentacos opened this issue · comments

Unable to use Plaid Node in an API route using Vercel's edge runtime due to Axios dependency. Axios does not work in Edge runtimes from what I have found here.

My reason for needing the edge runtime is the longer time allowed for returning a response before timeout without paying for the Pro plan on Vercel. When connecting an item and the initial transaction request is done via transactions/sync is seems to take longer than the 10 seconds before the vercel serverless function times out.

 AxiosError: There is no suitable adapter to dispatch the request since :
- adapter xhr is not supported by the environment
- adapter http is not available in the build
    at (node_modules/axios/dist/browser/axios.cjs:2472:12)
    at (node_modules/axios/dist/browser/axios.cjs:2522:27)
    at (node_modules/axios/dist/browser/axios.cjs:2881:32)
    at (node_modules/axios/dist/browser/axios.cjs:6:14)
    at (node_modules/plaid/dist/common.js:149:21)
    at (node_modules/plaid/dist/api.js:19697:123)
    at (helpers/fetchTransactionUpdates.ts:46:25)
    at (app/api/webhooks/plaid/update/route.ts:22:36)
    at (node_modules/next/dist/esm/server/future/route-modules/app-route/module.js:187:36) {
  message: 'There is no suitable adapter to dispatch the request since :\n- adapter xhr is not supported by the environment\n- adapter http is not available in the build',
  name: 'AxiosError',
  code: 'ERR_NOT_SUPPORT'
}
commented

I took a look into this to see whether it might be simple to use fetch instead of axios but it appears that the node generators are tied to specific http libraries. Generating the library to use fetch instead of axios would require generating an entirely separate library, with a separate set of mustache/configuration files, that would have a different interface and possibly not even the same level of support for OpenAPI (see https://stackoverflow.com/questions/71213188/openapi-generator-typescript-fetch-vs-typescript-node-vs-typescript-axios). Given that, I think this is probably going to have to go in the "won't do" pile unless we see significant increased demand for it.

If you want to try generating your own fetch-supporting library, you can try using a generation tool such as https://github.com/jhannes/openapi-generator-typescript-fetch-api/tree/main or https://openapi-generator.tech/docs/generators/typescript-fetch/ in conjunction with the Plaid OpenAPI spec here: https://github.com/plaid/plaid-openapi

I put together a simple fetch-based wrapper in a new library called plaid-fetch (repo here). It's generated using the same OpenAPI generator library as the official plaid-node, and I tried to keep the config similar to Plaid's own config. Everything should work mostly similar to the official library (with a few differences I've noticed so far noted in the README). Feel free to test and contribute any issues or PRs. I've run some initial queries on the Vercel Edge runtime and things seem to work as expected.

Another approach that could be worth exploring is plugging a fetch adapter for Axios into plaid-node.

commented

@heysanil thanks, that's great! I'll add that later this month to the community libraries page at https://plaid.com/docs/api/libraries/#community-libraries