Skip to content

About

Official Runearc SDK for Node.js: send and schedule email, read agent inboxes, manage domains, verify webhooks.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Runearc for Node.js. Install with the command shown, then send email and give agents inboxes.

version 0.1.0 MIT licence requires node 18+ tested against the real API

Website · Docs · Node.js guide · MCP · Status · Changelog

runearc

The official Node.js SDK for Runearc, email infrastructure for apps and AI agents. Send email and give your agents an inbox, from Node.js.

npm install runearc
import { Runearc } from "runearc";

const runearc = new Runearc(process.env.RUNEARC_API_KEY);
const { id } = await runearc.emails.send({ from: "Acme <noreply@acme.com>", to: "bob@example.com", subject: "Welcome to Acme", html: "<p>Thanks for signing up.</p>" });

See runearc.com/integrations/node for the guide and more examples.

The official TypeScript SDK for Runearc: send, batch and schedule email, create inboxes your agents can read, manage domains and verify webhooks.

Zero runtime dependencies. It uses the global fetch and Web Crypto only, so it runs on Node 18+, Bun, Deno, Cloudflare Workers, Vercel Edge and other edge runtimes. ESM and CommonJS builds with types.

Install

npm install runearc
# or: pnpm add runearc, yarn add runearc, bun add runearc

Quick start

import { Runearc } from "runearc";

const runearc = new Runearc(process.env.RUNEARC_API_KEY);

const { id } = await runearc.emails.send({
  from: "Acme <noreply@acme.com>",
  to: "bob@example.com",
  subject: "Welcome to Acme",
  html: "<p>Thanks for signing up.</p>",
});

new Runearc() with no key reads RUNEARC_API_KEY. Options:

Option Default
baseUrl RUNEARC_BASE_URL, else https://api.runearc.com A trailing /v1 is fine.
maxRetries 2 Retries after the first attempt (see Retries).
timeoutMs 60000 Per attempt.
fetch global fetch Bring your own.
headers none Sent with every request.

Field names are the API's JSON, in snake case (reply_to, scheduled_at, next_cursor), so the API reference and this SDK read the same. Every method also takes a last options argument: { idempotencyKey, signal, timeoutMs }.

To try things without sending real mail, send to delivered@test.runearc.com. bounced@ and complained@ at the same domain simulate those outcomes.

How results and errors work

Methods return the parsed response and throw a RunearcError when something fails. There is no { data, error } wrapper.

import { Runearc, RunearcError } from "runearc";

try {
  await runearc.emails.send({ from: "noreply@acme.com", to: "bob@example.com", subject: "Hi", text: "Hi" });
} catch (e) {
  if (e instanceof RunearcError) {
    console.log(e.status); // 403
    console.log(e.code);   // "sender_not_verified", a stable string to branch on
    console.log(e.message);
    console.log(e.fix);    // what to do about it, when there is something to do
  }
  throw e;
}

RunearcError has status (the HTTP status, or 0 when no response came back), kind (one of invalid, unauthorized, limit_reached, forbidden, not_found, conflict, rate_limited, unavailable, internal, or client when no response arrived), code, message, fix, retryAfter (seconds, when the API sent Retry-After) and, for a refused batch, errors. Failures before a response use the codes network_error, timeout, aborted and missing_api_key.

Lists come back as the API sends them: { data }, plus next_cursor on paginated lists.

Emails

// Send
const { id } = await runearc.emails.send({
  from: "Acme <noreply@acme.com>",
  to: ["bob@example.com"],
  cc: "carol@example.com",
  reply_to: "support@acme.com",
  subject: "Your receipt",
  html: "<p>Thanks for your order.</p>",
  text: "Thanks for your order.",
  attachments: [{ filename: "receipt.pdf", content: base64Pdf }],
  tags: [{ name: "kind", value: "receipt" }],
});

// Read
const email = await runearc.emails.get(id); // status, last_event, recipients[], html, text
const page = await runearc.emails.list({ limit: 50 });
const next = await runearc.emails.list({ cursor: page.next_cursor! });

Scheduled send

Pass scheduled_at (or scheduledAt) as a Date, an ISO 8601 time with an offset, or the relative form in <n> <unit>. Up to 30 days ahead.

const { id } = await runearc.emails.send({
  from: "Acme <noreply@acme.com>",
  to: "bob@example.com",
  subject: "Your trial ends tomorrow",
  text: "Here is what happens next.",
  scheduledAt: new Date(Date.now() + 24 * 60 * 60 * 1000), // or "2026-10-20T09:00:00Z", or "in 1 day"
});

await runearc.emails.get(id);                    // status: "scheduled", scheduled_at: "..."
await runearc.emails.reschedule(id, "in 2 days"); // same as emails.update(id, { scheduled_at })
await runearc.emails.cancel(id);                 // status: "canceled"

Rescheduling or canceling an email that is no longer scheduled throws email_not_scheduled (409).

Batch send

Up to 100 emails in one request. Each item is the same shape as emails.send, scheduled_at included.

const { data } = await runearc.emails.batch([
  { from: "Acme <noreply@acme.com>", to: "bob@example.com", subject: "Hi Bob", text: "..." },
  { from: "Acme <noreply@acme.com>", to: "carol@example.com", subject: "Hi Carol", text: "..." },
]);
// data: [{ id }, { id }] in request order

By default validation is strict: if any item is invalid nothing is sent, and the error lists every bad item.

try {
  await runearc.emails.batch(emails);
} catch (e) {
  if (e instanceof RunearcError && e.code === "invalid_batch") {
    for (const item of e.errors ?? []) console.log(item.index, item.code, item.message, item.fix);
  }
}

With batchValidation: "permissive" the valid items are sent and the invalid ones are reported:

const { data, errors } = await runearc.emails.batch(emails, { batchValidation: "permissive" });

Senders

const { data } = await runearc.senders.list(); // addresses you can use as `from`

Inboxes and messages

Inboxes receive mail. Give one to an agent, wait for a message, read the code in it, reply.

const inbox = await runearc.inboxes.create({ local_part: "signup-bot", display_name: "Signup bot" });
await runearc.inboxes.list();
await runearc.inboxes.get(inbox.id);

// Wait up to 120 seconds for a matching message. Resolves null when none arrived.
const got = await runearc.messages.wait(inbox.id, { from: "github.com", subject: "verify", timeout: 60 });
if (got) console.log(got.codes, got.links, got.message.subject);

const { data, next_cursor } = await runearc.messages.list(inbox.id, { limit: 20 });
const message = await runearc.messages.get(data[0]!.id);
const rfc822 = await runearc.messages.raw(message.id);

// Send from the inbox, and reply in a thread
await runearc.messages.send(inbox.id, { to: "bob@example.com", subject: "Hello", text: "Hi Bob" });
await runearc.messages.reply(message.id, { text: "Thanks, on it", reply_all: false });

// Threads
await runearc.threads.list(inbox.id);
const thread = await runearc.threads.get(message.thread_id); // with messages[]

await runearc.inboxes.delete(inbox.id);

Conversations

The shared support inbox view across every inbox you can read.

const { data } = await runearc.conversations.list({ status: "open", assignee: "none", q: "refund" });
await runearc.conversations.counts();
await runearc.conversations.update(data[0]!.id, { status: "closed" });
await runearc.conversations.update(data[0]!.id, { snoozed_until: new Date(Date.now() + 3600_000) });
await runearc.conversations.read(data[0]!.id);
await runearc.conversations.unread(data[0]!.id);

Domains

const domain = await runearc.domains.create({ name: "acme.com" });
console.log(domain.records);   // the DNS records to publish
console.log(domain.next_step);

await runearc.domains.verify(domain.id); // checks DNS now
await runearc.domains.list();
await runearc.domains.get("acme.com");   // id or name
await runearc.domains.delete(domain.id);

Webhooks

const hook = await runearc.webhooks.create({
  url: "https://acme.com/api/runearc",
  event_types: ["message.received", "message.delivered", "message.bounced"],
});
// hook.secret ("whsec_...") is shown once: store it, you need it to verify deliveries.

await runearc.webhooks.list();
const { data } = await runearc.webhooks.deliveries(hook.id, { limit: 20 });
await runearc.webhooks.replay(hook.id, data[0]!.id);
await runearc.webhooks.delete(hook.id);

Verifying webhooks

Runearc signs every delivery with Standard Webhooks: headers webhook-id, webhook-timestamp and webhook-signature (v1,<base64 HMAC SHA256>). verifyWebhook checks the signature with Web Crypto, refuses timestamps more than 5 minutes off, and returns the parsed event. It throws WebhookVerificationError (a RunearcError) otherwise. Always pass the raw body, not JSON you parsed and serialized again.

Next.js route handler (app/api/runearc/route.ts):

import { verifyWebhook, WebhookVerificationError } from "runearc";

export async function POST(req: Request) {
  const payload = await req.text();
  try {
    const event = await verifyWebhook({ payload, headers: req.headers, secret: process.env.RUNEARC_WEBHOOK_SECRET! });
    if (event.type === "message.received") {
      // event.data.message_id, event.data.inbox_id, ...
    }
    return new Response(null, { status: 204 });
  } catch (e) {
    if (e instanceof WebhookVerificationError) return new Response(e.message, { status: 400 });
    throw e;
  }
}

Cloudflare Worker:

import { verifyWebhook } from "runearc";

export default {
  async fetch(req: Request, env: { RUNEARC_WEBHOOK_SECRET: string }): Promise<Response> {
    const payload = await req.text();
    try {
      const event = await verifyWebhook({ payload, headers: req.headers, secret: env.RUNEARC_WEBHOOK_SECRET });
      console.log(event.type, event.id); // event.id is the webhook-id: use it to drop duplicates
      return new Response(null, { status: 204 });
    } catch {
      return new Response("invalid signature", { status: 400 });
    }
  },
};

Express or any Node server works the same way as long as you read the raw body (express.raw({ type: "application/json" })) and pass req.headers.

API keys, suppressions and events

const { key, secret } = await runearc.keys.create({ name: "app", permissions: "sending", domain_id: "acme.com" });
// secret is shown once
await runearc.keys.list();
await runearc.keys.delete(key.id); // revokes at once

await runearc.suppressions.list();
await runearc.suppressions.delete("bob@example.com"); // lets mail go to bob again

let page = await runearc.events.list({ limit: 100 }); // oldest first
page = await runearc.events.list({ after: page.next_after! });

Retries and idempotency

The SDK retries a request up to maxRetries times (default 2) with exponential backoff and jitter, and waits as long as the API's Retry-After header asks. It retries:

  • 429 (rate limited), always;
  • 5xx, network errors and timeouts, when the request is safe to repeat: GET, PATCH and DELETE, and any POST that carries an Idempotency-Key.

It never retries other 4xx errors. A POST that could create something twice (such as creating an inbox) is not repeated after a 5xx or a network error; the error is thrown instead.

Every call that sends mail (emails.send, emails.batch, messages.send, messages.reply) gets an Idempotency-Key automatically when you do not give one, and every retry reuses it, so a retry never sends twice. Runearc remembers keys for 24 hours. To make your own retries safe too, for example from a job queue, pass a key that is stable for that piece of work:

await runearc.emails.send(email, { idempotencyKey: `welcome/${user.id}` });

Repeating a key with the same body returns the first result. The same key with a different body throws idempotency_conflict (409).

Already using Resend?

Runearc's /v1/emails speaks Resend's format, so the official resend package works against Runearc unchanged. Set two environment variables and keep your code:

RESEND_BASE_URL=https://api.runearc.com/v1
RESEND_API_KEY=mb_live_xxxxxxxxx   # a Runearc API key, ideally a sending key

resend reads RESEND_BASE_URL when it loads, so set it in the environment rather than in code after the import. Send to delivered@test.runearc.com first. When you want batch, scheduled send, inboxes or webhook verification with typed errors, switch to this package; the field names are the same.

Runtime support

Runtime Status
Node 20+ Supported.
Node 18 Supported. verifyWebhook needs Web Crypto, which Node 18 does not expose globally in ES modules: pass crypto: (await import("node:crypto")).webcrypto.
Bun, Deno Supported.
Cloudflare Workers, Vercel Edge, Netlify Edge Supported. No node: imports, no Buffer.
Browsers Works, but do not ship an API key to a browser.

License

MIT. Copyright Runearc. See LICENSE.

About

Official Runearc SDK for Node.js: send and schedule email, read agent inboxes, manage domains, verify webhooks.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages