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

@hostsmith/sdk

v1.2.0

Published

Node.js SDK for the Hostsmith Public API

Readme

@hostsmith/sdk

CI Latest Release npm version Node Version License: MIT

Node.js SDK for the Hostsmith Public API. Manage sites and deploy files programmatically.

Installation

npm install @hostsmith/sdk

Requires Node.js 20 or later.

Quick Start

import { Hostsmith } from "@hostsmith/sdk";

const client = new Hostsmith({
  accessToken: "your-oauth-access-token",
  partition: "us", // "us" (United States) or "eu" (European Union)
});

// List all sites
const { sites } = await client.sites.list();

// Deploy a directory
await client.sites.deploy(sites[0].id, "./dist");

Authentication

The SDK requires an OAuth 2.0 access token. See the authentication guide for how to obtain one.

const client = new Hostsmith({
  accessToken: "your-access-token",
});

Usage

Sites

// List all sites
const { sites } = await client.sites.list();

// Get a site by ID
const site = await client.sites.get("site-id");

// Create a site
const { siteId } = await client.sites.create({
  subdomain: "my-portfolio",
  domain: "us.hostsmith.link",
});

// Delete a site
await client.sites.delete("site-id");

Domains

// List all domains (shared + custom)
const { domains } = await client.domains.list();

// List only shared hosting domains
const { domains: shared } = await client.domains.list({ shared: true });

// List only custom domains owned by your organization
const { domains: custom } = await client.domains.list({ shared: false });

// Each domain includes:
// - id, name, shared, partition, enableApexDomain, enableSubdomains, status
// - canonicalServedUrl: the URL where the site is actually served
//   (https://www.<apex> for apex-enabled domains, otherwise https://<name>)
// - bareApexCovered: whether the bare apex form (https://example.com) is reachable

Deploying Files

Deploy an entire directory:

const result = await client.sites.deploy("site-id", "./dist");
// { versionId: "...", status: "processing" }

Or deploy specific files:

import { Buffer } from "node:buffer";

const result = await client.sites.deploy("site-id", [
  { fileName: "index.html", content: Buffer.from("<h1>Hello</h1>") },
  { fileName: "style.css", content: Buffer.from("body { margin: 0 }") },
]);

The deploy method handles the full upload flow: requesting presigned URLs, uploading file parts to S3 (with concurrency), and finalizing the deployment.

Files larger than 5 MB are automatically split into multipart uploads.

Configuration

Partitions

Each Hostsmith data partition has its own API host. Pass partition to pick one:

| Partition | Label | Base URL | | --------- | -------------- | ------------------------------ | | us | United States | https://us.api.hostsmith.net | | eu | European Union | https://eu.api.hostsmith.net |

A discovery endpoint (GET /v1/partitions) returns the live list with labels.

Default partition from token

If partition is omitted, the SDK reads the access token's homePartition claim and uses it as the default. To call a partition other than the user's home partition, pass partition explicitly.

// Default to the user's home partition (from the token's `homePartition` claim).
const home = new Hostsmith({ accessToken: token });

// One token authorized for both partitions: target a specific one.
const us = new Hostsmith({ accessToken: token, partition: "us" });
const eu = new Hostsmith({ accessToken: token, partition: "eu" });

Custom partition URLs (dev / staging)

Override the default URL map (e.g. to point at hostsmith-dev.com):

const client = new Hostsmith({
  accessToken: "your-token",
  partition: "us",
  partitionUrls: {
    us: "https://us.api.hostsmith-dev.com",
    eu: "https://eu.api.hostsmith-dev.com",
  },
});

Token-based defaulting also uses the overridden URLs.

Custom Base URL

For local development:

const client = new Hostsmith({
  accessToken: "your-token",
  baseUrl: "http://localhost:3000",
});

Error Handling

The SDK throws typed errors for API failures:

import { ApiError, AuthError } from "@hostsmith/sdk";

try {
  await client.sites.get("nonexistent-id");
} catch (err) {
  if (err instanceof AuthError) {
    // 401 - token expired or invalid
    console.error("Auth failed:", err.message);
  } else if (err instanceof ApiError) {
    // Other API errors (403, 404, 409, 429)
    console.error(`API error ${err.status}:`, err.errorCode, err.message);
  }
}

Error Classes

  • HostsmithError - base class for all SDK errors
  • ApiError - API returned an error response (has status, errorCode, message)
  • AuthError - 401 Unauthorized (extends ApiError)

Contributing

See CONTRIBUTING.md. For security issues, see SECURITY.md.

License

MIT