X Enterprises

fastify-xplaid

Plaid financial data integration for Fastify — bank account linking, transactions, balances, identity, auth, investments, liabilities, and webhooks.

fastify-xplaid

Plaid integration for Fastify v5. Covers the full Plaid data access surface — Link token creation, public token exchange, accounts, transaction sync, balances, identity, ACH auth, investments, liabilities, webhooks, institution search, and sandbox helpers. Every method validates inputs and attaches the original Plaid error object on failure.

Installation

npm install @xenterprises/fastify-xplaid plaid

Quick Start

import Fastify from "fastify";
import xPlaid from "@xenterprises/fastify-xplaid";

const fastify = Fastify({ logger: true });

await fastify.register(xPlaid, {
  clientId: process.env.PLAID_CLIENT_ID,
  secret: process.env.PLAID_SECRET,
  environment: "sandbox",
});

// 1. Create a Link token for the frontend
const { linkToken } = await fastify.xplaid.link.createToken({
  userId: "user_123",
  clientName: "My App",
  products: ["transactions"],
  countryCodes: ["US"],
});

// 2. After the user completes Plaid Link, exchange the public token
const { accessToken } = await fastify.xplaid.link.exchangePublicToken(publicToken);

// 3. Sync transactions incrementally
const { added, nextCursor } = await fastify.xplaid.transactions.sync(accessToken);

await fastify.listen({ port: 3000 });

Options

NameTypeDefaultRequiredDescription
clientIdstringYesPlaid client ID.
secretstringYesPlaid secret (environment-specific).
environmentstring"sandbox"No"sandbox", "development", or "production".
versionstring"2020-09-14"NoPlaid API version header.
activebooleantrueNoSet false to disable the plugin entirely.

Methods

  • createToken — Create a Link token to initialize Plaid Link in the browser.
  • exchangePublicToken — Exchange a temporary public token for a permanent access token.
  • getToken — Get metadata for an existing Link token.

fastify.xplaid.accounts

  • get — Get all accounts for an Item.
  • getBalance — Get real-time account balances (fresh call, not cached).

fastify.xplaid.transactions

  • sync — Incremental transaction sync with cursor (recommended).
  • get — Fetch transactions by date range.
  • refresh — Force-refresh transaction data for an Item.
  • getRecurring — Get recurring transaction streams (inflow and outflow).

fastify.xplaid.identity

  • get — Get identity data (names, emails, phone numbers, addresses).

fastify.xplaid.auth

  • get — Get ACH routing and account numbers.

fastify.xplaid.investments

fastify.xplaid.liabilities

  • get — Get credit card, mortgage, and student loan liabilities.

fastify.xplaid.items

fastify.xplaid.webhooks

  • update — Update the webhook URL for an Item.
  • getVerificationKey — Get the webhook verification key for signature validation.

fastify.xplaid.sandbox

  • createPublicToken — Create a sandbox public token without the Link UI.
  • resetItem — Reset an Item's login state (forces re-authentication).

Other properties

PropertyTypeDescription
fastify.xplaid.configobject{ environment, clientId } — resolved config with masked client ID.
fastify.xplaid.constantsobject{ ENVIRONMENTS, PRODUCTS, COUNTRY_CODES } — enum-like string constants.
fastify.xplaid.rawPlaidApiDirect access to the underlying PlaidApi client for unwrapped endpoints.

Error Reference

On Plaid API failure every method throws with:

{
  message: "Human-readable error",
  statusCode: 400,          // HTTP status from Plaid
  plaidError: {
    error_type: "INVALID_REQUEST",
    error_code: "INVALID_ACCESS_TOKEN",
    error_message: "...",
    display_message: "...",
    request_id: "..."
  }
}

Startup Errors

ErrorCause
[xPlaid] clientId is required and must be a stringMissing or non-string clientId.
[xPlaid] secret is required and must be a stringMissing or non-string secret.
[xPlaid] environment must be one of: sandbox, development, productionInvalid environment value.
[xPlaid] version must be a stringNon-string version.

Common Plaid API Error Types

TypeDescription
INVALID_REQUESTInvalid parameters sent in the request.
INVALID_INPUTInvalid input data (e.g. bad access token format).
INSTITUTION_ERRORBank is temporarily unavailable.
RATE_LIMIT_EXCEEDEDToo many requests — implement exponential backoff.
API_ERRORPlaid internal error — safe to retry.
ITEM_ERRORItem needs re-authentication via Plaid Link update mode.

Environment Variables

VariableRequiredDescription
PLAID_CLIENT_IDYesPlaid client ID from the dashboard.
PLAID_SECRETYesPlaid secret (environment-specific).
PLAID_ENVNoPlaid environment (sandbox, development, production).

How It Works

On registration the plugin validates clientId, secret, and environment, creates a PlaidApi client with the appropriate base URL and authentication headers, then decorates fastify.xplaid with namespaced service objects. Every method validates required parameters before making an API call and wraps failures in a try/catch that attaches the original Plaid error object as .plaidError and the HTTP status as .statusCode. The sandbox namespace provides helpers for automated testing without the Link UI. The raw property exposes the full PlaidApi client for endpoints not yet wrapped by the plugin.

AI Context

package: "@xenterprises/fastify-xplaid"
type: fastify-plugin
use-when: Plaid financial data — bank account linking, transactions, balances, identity, ACH auth, investments, liabilities, webhooks
decorator: fastify.xplaid (link, accounts, transactions, identity, auth, investments, liabilities, items, webhooks, sandbox, config, constants, raw)
env: PLAID_CLIENT_ID, PLAID_SECRET, PLAID_ENV (optional)
peer-deps: plaid
error-shape: { message, statusCode, plaidError } on API failures
flow: createToken → [user completes Plaid Link] → exchangePublicToken → store accessToken → sync/get data
Copyright © 2026