npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@xenterprises/fastify-xhubspot

v1.3.0

Published

Fastify plugin for HubSpot CRM integration with contact management, engagement tracking, and custom objects support. Ideal for third-party portals managing contacts, companies, deals, and engagement notes.

Readme

@xenterprises/fastify-xhubspot

Fastify plugin for HubSpot CRM integration — contacts, companies, deals, engagements, and custom objects — for third-party portals and SaaS backends that manage CRM data from their own API. It wraps the official @hubspot/api-client with input validation, consistent error propagation, and optional debug request logging.

Install

npm install @xenterprises/fastify-xhubspot fastify@5

Minimal example

import Fastify from "fastify";
import xHubspot from "@xenterprises/fastify-xhubspot";

const fastify = Fastify();

await fastify.register(xHubspot, {
  apiKey: process.env.HUBSPOT_ACCESS_TOKEN, // consumer owns env access
});

const contact = await fastify.xHubspot.contacts.create({
  email: "[email protected]",
  firstname: "John",
  lastname: "Doe",
});

await fastify.xHubspot.engagement.createNote(contact.id, "Initial onboarding call completed");

Options

| Name | Type | Default | Required | Description | |------|------|---------|----------|-------------| | apiKey | string | — | Yes* | HubSpot Private App access token (pat-na1-...) | | logRequests | boolean | false | No | Log each HubSpot API call at debug level | | client | Client | — | No | Pre-built @hubspot/api-client Client instance (advanced/testing). When provided, apiKey is not required and no client is constructed |

* Required unless client is provided. The plugin never reads process.env; pass configuration in explicitly.

Decorators

fastify.xHubspot

Single namespace exposing:

| Member | Type | Description | |--------|------|-------------| | client | Client | The raw @hubspot/api-client Client instance for direct API access | | contacts | ContactsService | Contact operations | | companies | CompaniesService | Company operations | | deals | DealsService | Deal operations | | engagement | EngagementsService | Notes, tasks, calls, emails | | customObjects | CustomObjectsService | Custom object operations |

fastify.xHubspot.contacts

| Method | Arguments | Returns | Description | |--------|-----------|---------|-------------| | create(data) | CrmProperties | CrmObject | Create a contact | | getById(id, props?) | string, string[] | CrmObject | Get contact by ID | | getByEmail(email, props?) | string, string[] | CrmObject & { email } | Get contact by email | | update(id, props) | string, CrmProperties | CrmObject | Update contact | | delete(id) | string | true | Archive contact | | list(opts?) | { limit?, after?, sort? } | { contacts, paging } | List contacts with pagination | | search(prop, value) | string, string | CrmObject[] | Search by property value | | batchCreate(contacts) | CrmProperties[] | CrmObject[] | Create up to 100 contacts | | batchUpdate(contacts) | { id, properties }[] | CrmObject[] | Update up to 100 contacts | | getAssociations(id, type) | string, string | Association[] | Get associated objects | | associate(id, objectId, type) | string, string, string | true | Create association |

fastify.xHubspot.companies

| Method | Arguments | Returns | Description | |--------|-----------|---------|-------------| | create(data) | CrmProperties | CrmObject | Create a company | | getById(id, props?) | string, string[] | CrmObject | Get company by ID | | getByDomain(domain, props?) | string, string[] | CrmObject | Find company by domain | | update(id, props) | string, CrmProperties | CrmObject | Update company | | delete(id) | string | true | Archive company | | list(opts?) | { limit?, after? } | { companies, paging } | List companies | | search(prop, value) | string, string | CrmObject[] | Search by property | | batchCreate(companies) | CrmProperties[] | CrmObject[] | Create up to 100 | | batchUpdate(companies) | { id, properties }[] | CrmObject[] | Update up to 100 | | getAssociations(id, type) | string, string | Association[] | Get associations |

fastify.xHubspot.deals

| Method | Arguments | Returns | Description | |--------|-----------|---------|-------------| | create(data) | CrmProperties | CrmObject | Create a deal | | getById(id, props?) | string, string[] | CrmObject | Get deal by ID | | update(id, props) | string, CrmProperties | CrmObject | Update deal | | delete(id) | string | true | Archive deal | | list(opts?) | { limit?, after? } | { deals, paging } | List deals | | search(prop, value) | string, string | CrmObject[] | Search by property | | batchCreate(deals) | CrmProperties[] | CrmObject[] | Create up to 100 | | getAssociations(id, type) | string, string | Association[] | Get associations |

fastify.xHubspot.engagement

| Method | Arguments | Returns | Description | |--------|-----------|---------|-------------| | createNote(contactId, body, ownerId?) | string, string, string? | EngagementResult | Create a note | | createTask(contactId, taskData) | string, TaskData | EngagementResult | Create a task | | createCall(contactId, callData) | string, CallData | EngagementResult | Log a call | | createEmail(contactId, emailData) | string, EmailData | EngagementResult | Log an email | | getEngagements(contactId) | string | { engagements, total } | All engagements for contact | | getNotes(contactId, limit?) | string, number? | CrmObject[] | List notes | | getTasks(contactId, limit?) | string, number? | CrmObject[] | List tasks | | getCalls(contactId, limit?) | string, number? | CrmObject[] | List calls | | getEmails(contactId, limit?) | string, number? | CrmObject[] | List emails |

fastify.xHubspot.customObjects

| Method | Arguments | Returns | Description | |--------|-----------|---------|-------------| | create(type, data) | string, CrmProperties | CrmObject | Create custom object | | getById(type, id, props?) | string, string, string[] | CrmObject | Get by ID | | update(type, id, props) | string, string, CrmProperties | CrmObject | Update | | delete(type, id) | string, string | true | Archive | | list(type, opts?) | string, { limit?, after? } | { objects, paging } | List | | search(type, prop, value) | string, string, string | CrmObject[] | Search | | batchCreate(type, objects) | string, CrmProperties[] | CrmObject[] | Batch create | | associate(type, id, toType, toId, assocTypeId?) | string, string, string, string, number? | true | Create association | | getAssociations(type, id, assocType) | string, string, string | Association[] | Get associations |

Routes

None. The plugin adds no routes.

Error behavior

  • Registration fails fast on missing/invalid options. Messages name the plugin, the option, and an example:
    • xhubspot: missing required option `apiKey` (string), e.g. `app.register(xHubspot, { apiKey: 'pat-na1-...' })`
    • xhubspot: option `logRequests` must be a boolean, e.g. ...
  • Method argument validation throws Errors with an [xHubspot] prefix (e.g. [xHubspot] contacts.getById requires a contactId) before any API call is made.
  • HubSpot API errors are re-thrown unchanged after being logged at error level via fastify.log (message only — no tokens or raw SDK error dumps). companies.getByDomain() throws an error with .status = 404 when no company matches.

Requirements

  • Node.js >= 20
  • Fastify ^5.0.0 (peer dependency)

License

Proprietary — All Rights Reserved X Enterprises. See LICENSE.