Email JavaScript SDK

Send transactional email over the HTTPS API from Node and TypeScript with the hepgg package, including queued (over-cap) handling.

Email SDK

The hepgg package wraps the transactional Email HTTPS API in a typed client. One send() call, sensible client-side guards, and the over-cap queued case surfaced as result.status so you are never surprised by a 202.

Install

flag
npm install hepgg --registry https://npm.hep.gg

Send An Email

Construct Email with your key, then call send(). Provide at least one of html or text.

esm
import { Email } from "hepgg/email";
 
const email = new Email({ token: process.env.HYD_MAIL_KEY });
 
const res = await email.send({
  to: "user@example.com",
  subject: "Welcome to the thing",
  html: "<h1>Hello!</h1>",
  fromName: "Acme",
});
 
console.log(res.messageId, res.status); // "...", "sent"

to, cc, and bcc each accept a string or an array. Billing is one credit per distinct recipient.

Over-Cap Sends Are Queued

When a sender hits its rolling 24-hour cap the API returns 202 and queues the message. The SDK treats that as success and reports it on status, so you can branch instead of catching.

const res = await email.send({ to: list, subject: "Digest", html });
if (res.status === "queued") {
  console.log("over cap, it will drain within 24h");
}

Guards, Options, Errors

The client checks the obvious mistakes before spending a request: at least one of html/text, and no more than 100 distinct recipients. Those throw TypeError/RangeError. API failures (credits, rate limit) throw a typed HepError.

email.send(message)
to
string | string[]required
Primary recipients.
cc
string | string[]optional
Carbon copy.
bcc
string | string[]optional
Blind carbon copy.
subject
stringoptional
Subject line.
html
stringoptional
HTML body. One of html/text is required.
text
stringoptional
Plain-text body.
from
stringoptional
A sender address you own.
fromName
stringoptional
Display name (max 100 chars).
replyTo
stringoptional
Reply-To address.
import { HepError } from "hepgg";
 
try {
  await email.send({ to: "user@example.com", html: "<p>hi</p>" });
} catch (err) {
  if (err instanceof HepError && err.status === 402) console.error("out of credits");
}

The Email constructor also takes baseURL, timeoutMs, retries, and fetch.

Full Reference

HTTPS API, Senders, billing, limits, and Errors.