Docs
JavaScript SDK
@northwork/sdk is a small, typed client with zero dependencies. It runs on Node 18+, Deno, Bun, browsers and Cloudflare Workers.
Install
npm install https://northwork.dev/sdk/northwork-sdk.tgz
The package is @northwork/sdk; import it by that name. It will also be published to the npm registry.
Usage
import { Northwork, NorthworkError } from "@northwork/sdk";
const nw = new Northwork({ apiKey: process.env.NORTHWORK_API_KEY });
const me = await nw.me.retrieve();
const { data: products } = await nw.products.list();
const pocket = await nw.products.retrieve("pocket");
const status = await nw.status.retrieve();
const posts = await nw.community.posts({ space: "pocket", limit: 10 });
try {
const entry = await nw.waitlists.join("pocket");
entry.status; // "joined" | "already_joined" | "simulated"
} catch (e) {
if (e instanceof NorthworkError) reportError(e.status, e.type, e.requestId);
}
// Every changelog entry, page by page
const titles: string[] = [];
for await (const u of nw.paginate((q) => nw.updates.list(q))) titles.push(u.date + " " + u.title);
nw.lastRateLimit; // { limit, remaining, reset }Options
apiKey: defaults toNORTHWORK_API_KEY.maxRetries(default 2): retries 429 and 5xx, honouringRetry-After.timeout(default 15000 ms),baseUrl, and a customfetch.
Webhooks
import { constructEvent } from "@northwork/sdk/webhooks";
export default {
async fetch(req: Request, env: { NORTHWORK_WEBHOOK_SECRET: string }) {
const body = await req.text();
try {
const event = await constructEvent(body, req.headers.get("Northwork-Signature"), env.NORTHWORK_WEBHOOK_SECRET);
// event.type: "update.published" | "status.changed" | "community.post.created" | "blog.published"
return new Response("ok");
} catch {
return new Response("bad signature", { status: 400 });
}
},
};