JS SDK

@form-engine/sdk — framework-agnostic, ESM + UMD, under 3 KB gzipped.

npm install @form-engine/sdk

FormEngineClient

new FormEngineClient(slug: string, options?: { baseUrl?: string })
MethodDoes
.load()Fetches the published schema. Returns { slug, name, version, schema, maxUploadSizeBytes }.
.uploadFile(file, contentType)Authorizes an upload, then PUTs the file directly to storage. Returns { r2Key, contentType, expiresAt } — put r2Key in your submit data for that image field.
.submit(data, { draft?, turnstileToken })Submits the form. Returns { success, submission_id, edit_url, edit_expires_at }.

EditSession

For the link a respondent gets after submitting, so they can come back and change their answer.

const session = await EditSession.access(tokenFromUrl);
const current = await session.fetch();
await session.patch({ ...current.data, email: "new@email.com" });
MethodDoes
EditSession.access(token)Static. Exchanges an edit token for a session.
.fetch()Returns the submission's current { id, formId, formVersion, data, status, revision }.
.patch(data, { draft? })Updates the submission. Returns { id, data, status, revision }.

Errors

Every method throws a FormEngineError on failure, mirroring the API's error shape:

class FormEngineError extends Error { code: string; status: number }

Allowed image types

ALLOWED_UPLOAD_TYPES = ["image/jpeg", "image/png", "image/webp"], also exported from the package if you want to validate client-side before calling uploadFile.