Skip to content

Repository files navigation

@draftmark-app/client

Isomorphic TypeScript client for the Draftmark v1 API. Zero runtime dependencies; runs anywhere fetch is available (Node 18+, VS Code extension host, browsers). Shared by the dm CLI and the Draftmark VS Code extension.

Install

npm install @draftmark-app/client

Usage

import{DraftmarkClient}from"@draftmark-app/client";// An account API key (acct_...) covers the full owner lifecycle for docs it// creates: create, update, delete, comment, resolve.constdm=newDraftmarkClient({apiKey: process.env.DM_API_KEY});// Create (the doc is owned by the account behind the acct_ key)constcreated=awaitdm.createDoc({content: "# Draft\n\nReview me.",visibility: "public",});// Readconstdoc=awaitdm.getDoc(created.slug);constmarkdown=awaitdm.getDocRaw(created.slug);// Commentsconstcomments=awaitdm.listComments(created.slug,{status: "open"});awaitdm.createComment(created.slug,{body: "Nit: tighten this line.",anchor_type: "line",anchor_ref: 3,anchor_text: "Review me.",// populate so the comment survives edits (re-anchoring)});awaitdm.setCommentStatus(created.slug,comments[0].id,"resolved");// Update (new version) — no per-doc magic token needed for account-owned docsawaitdm.updateDoc(created.slug,{content: "# Draft\n\nReviewed.",version_note: "addressed feedback"});// Reviews & reactions (dedup identity is derived server-side)awaitdm.createReview(created.slug,{reviewer_type: "agent"});awaitdm.addReaction(created.slug,"thumbs_up");

Auth

Pass default auth to the constructor, or override per call:

constdm=newDraftmarkClient({baseUrl: "https://draftmark.app/api/v1"});awaitdm.getDoc("abc123",{apiKey: "key_..."});// doc api_keyawaitdm.updateDoc("abc123",{title: "New"},{magicToken: "..."});// per-doc magic token
  • apiKeyAuthorization: Bearer (a doc api_keyor an account acct_ key).
  • magicTokenX-Magic-Token (per-doc owner token; only needed for docs not owned by an account).

Errors

Typed methods throw DraftmarkApiError (.status, .code, .message, .details). For result-style handling, use the low-level raw() / request(), which return { ok, status, data }.

import{DraftmarkApiError}from"@draftmark-app/client";try{awaitdm.createComment(slug,{body: "hi"});}catch(e){if(einstanceofDraftmarkApiError&&e.status===409){// review closed / deadline passed}}

Custom fetch

newDraftmarkClient({fetch: myFetch});// e.g. tests, or a runtime without global fetch

Build

npm install
npm run build # tsc → dist/ (ESM + .d.ts)

License

MIT © Rumbo Labs

About

Isomorphic TypeScript client for the Draftmark v1 API (shared by the dm CLI and VS Code extension)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages