npm i @gork/sdk
Client
import { Gork, GorkError, verifyGorkWebhook } from "@gork/sdk";
const gork = new Gork({
apiKey: process.env.GORK_API_KEY, // falls back to GORK_KEY, then GORK_API_KEY
baseUrl: process.env.GORK_BASE_URL, // default https://api.gork.email
});
Inboxes
const inbox = await gork.inboxes.create({ username: "sdr-alex", name: "SDR Agent" });
const inboxes = await gork.inboxes.list();
const one = await gork.inboxes.get("inb_123");
await gork.inboxes.delete("inb_123");
Messages & search
const msg = await gork.messages.send({
inboxId: "inb_123",
to: ["prospect@example.com"],
subject: "Quick question",
text: "Hi — got 10 minutes Thursday?",
});
// Idempotent send (safe retries)
await gork.messages.send(
{ inboxId: "inb_123", to: ["a@example.com"], subject: "Hi", text: "Hello" },
{ idempotencyKey: "campaign-1-user-42" }
);
const recent = await gork.messages.list({ inboxId: "inb_123", limit: 20 });
const hits = await gork.messages.search("invoice", { direction: "inbound" });
const full = await gork.messages.get("msg_123");
await gork.messages.cancelScheduled("msg_123"); // scheduled sends only
inReplyTo with the original message ID:
await gork.messages.send({
inboxId: "inb_123",
to: ["prospect@example.com"],
subject: "Re: Quick question",
text: "Bumping this up.",
inReplyTo: "msg_original",
});
Threads
const threads = await gork.threads.list({ inboxId: "inb_123" });
const thread = await gork.threads.get("thd_123");
Drafts
const draft = await gork.drafts.create({ inboxId: "inb_123", to: ["a@example.com"], subject: "Hi" });
await gork.drafts.update(draft.id, { text: "Hello — final copy." });
await gork.drafts.send(draft.id); // idempotent per draft
const open = await gork.drafts.list({ status: "draft" });
await gork.drafts.discard(draft.id);
Attachments
const bytes = await gork.attachments.download("att_123"); // ArrayBuffer
const csv = await gork.attachments.downloadText("att_123"); // decoded text
content is base64 — max 10 files, 10MB each, 15MB total):
await gork.messages.send({
inboxId: "inb_123",
to: ["a@example.com"],
subject: "Invoice attached",
text: "See attached.",
attachments: [{ filename: "invoice.pdf", contentType: "application/pdf", content: "<base64>" }],
});
Domains
const domain = await gork.domains.create({ domain: "mail.example.com" });
await gork.domains.verify(domain.id);
await gork.domains.list();
await gork.domains.delete(domain.id);
Suppressions
await gork.suppressions.create({ email: "bad@example.com", reason: "manual" });
await gork.suppressions.list({ reason: "hard_bounce" });
await gork.suppressions.delete("sup_123");
API keys
const key = await gork.keys.create({ name: "agent-01", scopes: ["*"] });
await gork.keys.list();
await gork.keys.revoke("key_123");
Webhooks
const hook = await gork.webhooks.create({
url: "https://example.com/hooks/gork",
subscribedEvents: ["email.received", "email.sent"],
});
await gork.webhooks.list();
await gork.webhooks.rotateSecret(hook.id);
await gork.webhooks.delete(hook.id);
// Verify X-Gork-Signature: t=<unix>,v1=<hex> (also exported standalone)
const ok = await gork.webhooks.verifySignature(rawBody, signatureHeader, secret);
const ok2 = await verifyGorkWebhook({ payload: rawBody, signature: signatureHeader, secret });
Errors
try {
await gork.messages.send({ inboxId: "inb_123", to: ["a@example.com"], subject: "Hi", text: "Hello" });
} catch (err) {
if (err instanceof GorkError) {
console.error(err.code, err.status, err.message); // err.details for field errors
}
throw err;
}