X Enterprises

fastify-xwhatconverts

WhatConverts lead tracking plugin for Fastify — lead CRUD, account management, profile management, and call recording retrieval.

fastify-xwhatconverts

WhatConverts lead tracking integration for Fastify v5. Decorates fastify.xwhatconverts with four service namespaces: leads (CRUD + constants), accounts (Agency Key required), profiles, and recordings. All methods validate inputs, attach the original WhatConverts error object on API failure, and expose structured error codes.

Installation

npm install @xenterprises/fastify-xwhatconverts

Quick Start

import Fastify from "fastify";
import xWhatConverts from "@xenterprises/fastify-xwhatconverts";

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

await fastify.register(xWhatConverts, {
  token: process.env.WHATCONVERTS_TOKEN,
  secret: process.env.WHATCONVERTS_SECRET,
});

// List recent phone call leads
const result = await fastify.xwhatconverts.leads.list({
  leadType: "phone_call",
  leadsPerPage: 50,
});

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

Options

NameTypeDefaultRequiredDescription
tokenstringYesWhatConverts API token.
secretstringYesWhatConverts API secret.
baseUrlstring"https://app.whatconverts.com/api/v1"NoAPI base URL override.
activebooleantrueNoSet false to skip plugin registration.

Methods

Leads (fastify.xwhatconverts.leads)

Accounts (fastify.xwhatconverts.accounts) — Agency Key required

Profiles (fastify.xwhatconverts.profiles)

Recordings (fastify.xwhatconverts.recordings)

Error Reference

ErrorCause
[xWhatConverts] options.token is required and must be a stringMissing or non-string token at registration
[xWhatConverts] options.secret is required and must be a stringMissing or non-string secret at registration
[xWhatConverts] options.baseUrl must be a stringNon-string baseUrl at registration
[xWhatConverts] leads.get: leadId is requiredleads.get() called without leadId
[xWhatConverts] leads.create: profileId is requiredleads.create() missing profileId
[xWhatConverts] leads.create: leadType is requiredleads.create() missing leadType
[xWhatConverts] leads.update: leadId is requiredleads.update() called without leadId
[xWhatConverts] leads.delete: leadId is requiredleads.delete() called without leadId
[xWhatConverts] accounts.get: accountId is requiredaccounts.get() called without accountId
[xWhatConverts] accounts.create: accountName is requiredaccounts.create() missing accountName
[xWhatConverts] accounts.update: accountId is requiredaccounts.update() called without accountId
[xWhatConverts] accounts.delete: accountId is requiredaccounts.delete() called without accountId
[xWhatConverts] profiles.get: profileId is requiredprofiles.get() called without profileId
[xWhatConverts] profiles.create: accountId is requiredprofiles.create() missing accountId
[xWhatConverts] profiles.create: profileName is requiredprofiles.create() missing profileName
[xWhatConverts] profiles.update: profileId is requiredprofiles.update() called without profileId
[xWhatConverts] profiles.delete: profileId is requiredprofiles.delete() called without profileId
[xWhatConverts] recordings.get: leadId is requiredrecordings.get() called without leadId
[xWhatConverts] recordings.getBuffer: leadId is requiredrecordings.getBuffer() called without leadId
[xWhatConverts] recordings.getUrl: leadId is requiredrecordings.getUrl() called without leadId
[xWhatConverts] Network error: <message>Network-level failure (DNS, timeout, connection refused)
[xWhatConverts] API error: <status>Non-2xx response from WhatConverts API

Environment Variables

VariableRequiredDescription
WHATCONVERTS_TOKENYesAPI token from the WhatConverts dashboard.
WHATCONVERTS_SECRETYesAPI secret from the WhatConverts dashboard.

How It Works

On registration the plugin validates token and secret, builds a Basic Auth header from them, then decorates fastify.xwhatconverts with four service namespaces (leads, accounts, profiles, recordings). All JSON service methods share a common apiRequest helper that sets Authorization and Content-Type, handles both JSON and empty responses, and wraps failures as structured errors with code, statusCode, and whatConvertsError. The recordings service uses apiBinaryRequest which returns the raw response body as an ArrayBuffer. API credentials are held in closure scope and are never exposed on the decorator.

AI Context

package: "@xenterprises/fastify-xwhatconverts"
type: fastify-plugin
use-when: WhatConverts lead tracking — lead CRUD, account management (Agency Key), profile management, call recording retrieval
decorator: fastify.xwhatconverts (leads, accounts, profiles, recordings)
env: WHATCONVERTS_TOKEN, WHATCONVERTS_SECRET
accounts: requires Agency Key (token/secret from agency account)
error-shape: { code, statusCode, whatConvertsError } on API failures
Copyright © 2026