Skip to content

JavaScript SDK reference

Install: npm install @canvasmesh/sdk-js. Works in Node.js, browsers, and edge runtimes (Cloudflare Workers, Deno). Ships ESM and CJS.

import { CanvasClient } from '@canvasmesh/sdk-js';
const client = new CanvasClient({ apiKey, endpoint? });
OptionTypeRequiredDefault
apiKeystringyes
endpointstringnohttps://api.canvasmesh.app
client.create(options: CreateCanvasOptions): Promise<CanvasMesh & { view_url: string }>
OptionTypeRequired
titlestringyes
extstring (e.g. 'md')yes
contentstring | Blob | ArrayBufferyes
renderRenderTypeno
visibility'private' | 'public'no
client.update(canvasId: string, options: UpdateCanvasOptions): Promise<CanvasMesh>

All options optional. Only pass what you want to change.

OptionType
titlestring
contentstring | Blob | ArrayBuffer
visibilityCanvasVisibility
renderRenderType
client.get(canvasId: string): Promise<CanvasMesh>
client.list(options?: ListCanvasOptions): Promise<{ canvases: CanvasMesh[] }>
OptionTypeDefault
visibilityCanvasVisibility
limitnumber20 (max 100)
offsetnumber0
client.delete(canvasId: string): Promise<void>
client.share(canvasId: string, options?: ShareOptions): Promise<CanvasShare & { url: string }>
OptionTypeExample
expiresInstring'7d', '24h', '30m'
client.getContent(canvasId: string): Promise<string>

Fetches the raw file content as a string. For binary files use fetch(canvas.content_url) with appropriate parsing.

type RenderType =
| 'none' | 'html' | 'markdown' | 'react'
| 'svg' | 'json' | 'text' | 'image' | 'notebook';
type CanvasVisibility = 'private' | 'public';
interface CanvasMesh {
canvas_id: string;
owner_user_id: string;
title: string;
ext: string;
render: RenderType;
visibility: CanvasVisibility;
version: number;
created_at: string;
updated_at: string;
expires_at: string | null;
}
interface CanvasShare {
token: string;
expires_at: string | null;
view_count: number;
created_at: string;
}
interface ListCanvasOptions {
visibility?: CanvasVisibility;
limit?: number;
offset?: number;
}

All methods throw on non-2xx responses. The thrown Error has a status property (HTTP status code) and body property (parsed JSON or text).

try {
await client.get('cv_invalid');
} catch (err) {
if (err.status === 404) {
// not found
}
}