Nuvaka › Developer docs › API reference

API reference

The app injects a global nuvaka object into every UI frame and background script (API v1). Every call returns a Promise; errors are Error objects with a code field.

Contents: basics · storage · shared · net · clipboard · files · notes · cloud · pool · friends · mail · connections · push · ui · events · errors · SDK package

Basics

MemberReturnsDescription
nuvaka.apiVersion1
nuvaka.backgroundbooleantrue in the background (QuickJS), false in the UI
nuvaka.readyPromise<ctx | null>in the UI resolves with { page, locale, theme } (plus handle, fileName when opened through a core contribution) once the shell connects; in the background resolves immediately with null
nuvaka.context()ctx | nulllatest context (updated when page, language or theme change)
nuvaka.info(){ id, version, trust, dev, grants, appVersion }trust: community, verified, or dev in developer mode (version is dev too); grants: granted scopes, e.g. { "files.read": true }
nuvaka.me(){ displayName, language, avatarUrl? }no email or user ID; server call
nuvaka.settings.get(){ [key]: value }values of the manifest settings (default when the user has not set one)
nuvaka.on(name, fn)unsubscribe functionsee events
nuvaka.off(name, fn)
nuvaka.call(method, arg)raw call; use the namespaces instead

nuvaka.storage

The extension's own key-value storage (server, cross-device). No permission needed. Keys are 1–200 characters, / allowed; values are JSON up to 1 MB. Every write carries the version it read (MVCC).

CallReturns
get(key){ value, version } or null if missing
set(key, value, { version }){ version } (the new version). Use version: 0 for a new key.
delete(key, { version })deleting also requires the version read
update(key, fn){ value, version }; fn(oldValue | undefined) returns the new value (or a Promise). Returning undefined writes nothing and returns what was read (or null). Up to 5 attempts on conflict.
list(prefix?, after?){ items: [{ key, version, size, updatedAt }], next } — no values; pass next as after to continue
onChanged(fn)unsubscribe function. fn(key, { value, version, deleted }); key === null means all of the extension's data was deleted. Only newer versions arrive; this context's own writes do not.

Errors: if_version_required (no version given), version_conflict (e.data = { current, value }), quota_exceeded.

// Paged listing
let after = ''
do {
  const page = await nuvaka.storage.list('summary/', after)
  for (const it of page.items) console.log(it.key, it.version, it.size)
  after = page.next
} while (after)

nuvaka.shared

Named values shared between extensions. Writable names must be in the manifest's shared.exports, readable ones in shared.imports.

CallReturns
set(name, value, { version }){ version }; version: 0 on first write, value ≤ 1 MB
getOwn(name)the value this extension shares: { value, version } or null
get(from, name)another extension's value (value only) or null. The user must grant shared and the source extension must be installed.

nuvaka.net

Needs the net permission. Requests go through the app's proxy: https only, and only to the hosts in the manifest. The browser's fetch is blocked in frames by the CSP.

const r = await nuvaka.net.fetch('https://api.github.com/repos/tauri-apps/tauri', {
  method: 'GET',                                   // default GET
  headers: { Accept: 'application/vnd.github+json' },
  // body: a string or Uint8Array/ArrayBuffer
})
r.status; r.ok; r.url; r.headers['content-type']   // header names are lower case
const data = await r.json()                         // or r.text(), r.arrayBuffer()
  • Request and response bodies up to 10 MB; connect timeout 10 s, total 30 s.
  • At most 5 redirects, only to allowed hosts; Authorization and Cookie headers are dropped on redirect.
  • These headers are not sent: host, content-length, connection, transfer-encoding, upgrade, proxy-authorization, te, trailer, keep-alive. set-cookie is not passed back. Default User-Agent: NuvakaApps/1.
  • Names resolving to private network, loopback or link-local addresses are rejected.
  • Errors: permission_required (no net permission), net_error (host not allowed, http, timeout, size…). HTTP 4xx/5xx is not an error; check r.ok.

nuvaka.net.requestHost(host) → boolean. Needs the net.user permission. Asks the user for permission to connect to one host name (UI only; ui_only in the background). An already approved host returns true without asking. See Permissions › net.user.

if (await nuvaka.net.requestHost(new URL(address).hostname)) {
  const r = await nuvaka.net.fetch(address)
}

nuvaka.clipboard

This device's system clipboard. For the cross-device clipboard pool see nuvaka.pool.

CallPermissionReturns
readText()clipboard: readtext or null
writeText(text)clipboard: writenull; text ≤ 1 MB

nuvaka.files

Folders the user opened to the extension on this device. root is the absolute path returned by pick() or folders(); path is relative to it ("notes/a.txt"). .., absolute paths and escaping the root through symbolic links are rejected.

CallPermissionReturns
folders()readstring[] — folders opened on this device
pick()readopens a folder picker; the chosen absolute path, or null if cancelled
list(root, path?)read[{ name, dir, size, mtime }] (mtime in ms or null; symbolic links are skipped; at most 5000 entries)
readText(root, path)readtext (UTF-8; invalid bytes become U+FFFD)
readBytes(root, path)readUint8Array
writeText(root, path, text)writenull; missing parent folders are created
writeBytes(root, path, bytes)writenull
mkdir(root, path)writenull
remove(root, path)writenull; a folder is removed only if empty

The largest readable file is 50 MB. The picked folder itself cannot be modified or removed. Errors: forbidden (folder not opened, or path outside the root), bad_request (invalid path), io (file system error), permission_required.

nuvaka.files.handle(h) — single-file handle

When the user picks one of your extension's core contributions in My Files, the page opens with a handle scoped to that Nuvaka file (nuvaka.context().handle). No files or nuvaka.cloud permission is needed.

CallReturns
files.handle(h)handle object (synchronous)
.meta(){ fileId, name, size, contentType, folderId, version, encrypted, updatedAt, mode, contribution, expiresAt }
.read() / .readText()Uint8Array / text
.write(data, { version, contentType?, encrypted? }){ versionNo, plainVersions, file: Meta } — readwrite only; ≤ 100 MB; a new version of the same file (the old content stays in the version history)
.saveAs(name, data, { contentType?, encrypted? }){ handle, handleId, expiresAt, file: Meta } — a new file in the same folder; no confirmation
.rename(name){ success: true, file: Meta } — readwrite only; renames the file in place, the extension may change (a.txt → a.md). fileId, version history and the handle stay the same; the content type is updated from the new extension. Errors: bad_name, name_exists (same folder, case-insensitive), read_only, secure_area, bad_handle.
files.pickFromMyFiles({ accept?, multiple?, mode? })[{ handle, handleId, meta }] — UI only; no permission. Opens Nuvaka's My files / NuvakaSync picker; the user's pick is the consent. Returns a ready handle for each file. mode: 'read' (default) or 'readwrite'; falls back to read in read-only locations. Secure Space isn't shown in the picker. [] if cancelled; secure_session in a secure session.
files.suggestPurgePlainHistory(h, message?){ purged } / { purged: 0, kept: true } — UI only; Nuvaka offers the user to delete unencrypted older versions (encrypted content)

Handles come from three places: a core contribution (context().handle), files.pickFromMyFiles and the cloud.upload response. NuvakaSync file handles are local (nvy_…) and use the same interface; see NuvakaSync files.

The handle has a sliding lifetime: each use extends it by 15 minutes, at most 8 hours from opening. Errors: bad_handle, read_only, version_conflict (e.data.current = current Meta), if_version_required, bad_name (saveAs), upload_in_progress (the previous version is still being saved; retry in a few seconds).

nuvaka.notes

CallPermissionReturns
list({ q?, folder? })readarray [{ id, title, content, color, isPinned, createdAt, updatedAt, reminderCount }]; with folder only that folder's notes, and items include folderId. q searches title/content and is filtered on the client (in the SDK).
get(id)read{ note: { id, title, content, color, isPinned, folderId, createdAt, updatedAt }, images: [{ id, fileName, fileSize }], reminders: [{ id, reminderType, reminderMessage, remindAt, intervalMinutes, maxReminders, sentCount, isActive }] }
create({ title, content, color? })writethe created note
update(id, { title?, content?, color?, isPinned? })writethe updated note
delete(id)write{ success: true }

Dates are ISO 8601 strings. Note content may be HTML; use textContent when rendering it.

nuvaka.cloud

The user's Nuvaka cloud files; only the folders (or all) the user opened to the extension at install.

CallPermissionReturns
roots()read{ roots: "all" | [{ id, name }] }
list(folderId?)read{ items: [{ type: "folder"|"file", id, name, size, contentType, fileId, createdAt, currentVersion, encrypted, isFrozen, frozenReason, frozenUntil }], breadcrumb: [folders], currentFolderId }. Without folderId, the root (only when roots: "all").
read(fileId)readUint8Array (the file item's fileId)
upload(folderId, name, bytes, contentType?, { encrypted? })write critical{ success, file: { id, fileId, fileName, fileSize, contentType, createdAt } }; up to 100 MB
delete(fileId)write critical{ success: true }
versions(fileId)read{ fileId, current, items: [{ versionNo, size, contentType, encrypted, createdAt, supersededAt, createdBy, note, expiresAt }], total, plainVersions, keepDays: 30, keepMax: 20, countsTowardQuota: false }
restoreVersion(fileId, versionNo)write critical{ success, versionNo, restoredFrom, plainVersions }

Folders or files outside the scope are rejected with out_of_scope. Writing and deleting are confirmed by the user every time.

Saving to an uploaded file later: for an unencrypted upload outside Secure Space, the upload response also returns handle, handleId, expiresAt and meta. With this readwrite handle later saves are new versions of the same file via handle.write; the critical confirmation is asked only on the first upload. handle.rename works too. If the response has no handle, each save is a new upload.

const r = await nuvaka.cloud.upload(folderId, 'report.md', text, 'text/markdown')
let meta = r.meta
// later, Ctrl+S:
const w = await r.handle.write(newText, { version: meta.version })
meta = w.file

nuvaka.pool

The account's cross-device clipboard pool (nuvaka.clipboard permission).

CallPermissionReturns
list({ before?, limit? })read{ items: [{ id, deviceId, deviceName, kind, mime, fileName, size, hash, createdAt, text, textTruncated, blocks }] } — newest first; limit 1–200 (default 50); before returns items older than this ID
add(text)writethe added item (same shape; text up to 4096 characters, longer text is cut and textTruncated: true)

Adding to the pool is done on behalf of this device; it fails if the device is not registered and active in sync.

nuvaka.friends

list() → { items: [{ username, since }] }. Permission: nuvaka.friends: read.

nuvaka.mail

Account based: call accounts() first. nuvaka.mail.read and .send are critical and confirmed on every use.

CallPermissionReturns
accounts()read or send{ items: [{ id, email, type, isNuvaka }] } (no passwords)
folders(accountId)readarray [{ name, fullName, unreadCount, totalCount, isInbox, isSent, isDrafts, isTrash, isSpam, children: [same shape] }]
messages(accountId, { folder?, page?, pageSize? })read{ messages: [{ id, uniqueId, from: { name, email }, to: [{ name, email }], subject, date, isRead, hasAttachments, preview, messageId }], totalCount, page, pageSize, unreadCount }; folder defaults to INBOX, pageSize 1–100
get(accountId, folder, uniqueId)read{ id, uniqueId, from, to, cc, bcc, subject, date, isRead, hasAttachments, textBody, htmlBody, attachments: [{ id, fileName, size, contentType }] }
send(accountId, { to, cc?, bcc?, subject, body, isHtml?, replyToMessageId? })send{ success: true }. to/cc/bcc as a comma-separated string or an array. 30 per hour per extension; every mail sent lands in the user's notifications.

nuvaka.connections

CallPermissionReturns
list()list or secrets{ items: [{ id, type, name, details: { host, port, username, database … }, createdAt }] } — password/key fields stripped
secret(id)secrets critical{ id, type, name, data: { … raw fields including password / privateKey } }; confirmed on every call and added to the user's notification feed

nuvaka.push

nuvaka.push(title, body?) → { success: true }. A notification to all of the user's devices; nuvaka.push permission. title is required. Subject to the notification limit; notify_limit if the user does not raise it.

nuvaka.deps and nuvaka.expose

For private-copy dependencies (kind: "uses"). The owner calls nuvaka.deps.call(id, name, arg?), which runs a function the copy opened in its background with nuvaka.expose(name, fn). The result comes back as JSON, and the call waits at most 60 s. No permission is needed; the copy runs with its own permissions. See Dependencies.

nuvaka.pdf

Renders PDF pages to images and returns text positions, for PDF viewers and editors. No permission needed (no network, no disk); works in the UI and the background. src is a docId from open or the PDF bytes (Uint8Array/ArrayBuffer).

CallReturns
open(bytes, { password? })docId. Keeps the document in memory so you don't resend the bytes for every page. Up to 4 documents / 200 MB per extension; the oldest is dropped.
info(src){ pages, encrypted, title, pageSizes: [{ w, h }] } (pt, 1/72 inch)
render(src, { page?, scale?, maxWidth?, format? })PNG or WebP bytes (Uint8Array) on a white background. page is 0-based; scale 1 = 72 dpi; maxWidth in pixels. At most 40 MP; larger requests are scaled down automatically.
text(src, page?)[{ str, x, y, w, h, fontSize, baseline }]: text pieces on the page with their boxes (pt, origin top-left). For text selection and editing UIs.
close(docId)null

Limits and errors: input up to 200 MB (too_large), 10 s per job (timeout), broken file pdf_invalid, encrypted PDF without/with a wrong password pdf_encrypted, closed or dropped session not_found. To modify PDFs (add pages, place text/images, create documents) bundle a library that doesn't use eval, such as pdf-lib; nuvaka.pdf only reads and renders.

nuvaka.addons

Only for hosts that accept addons: list installed addons, read files from data addons, call code addons, show the in-app store. Full reference on the In-app store page (0.3.1).

nuvaka.realtime

Live rooms between users: create, join(code), get, invite, setState/update (shared state, MVCC with ifVersion), leave; UI only: connect, send, sendTo. Requires the nuvaka.realtime permission. Full reference: Realtime rooms (0.3.1, SDK 1.2.0).

nuvaka.servers

Joining extension servers: list, create, delete, invite; UI only: join(id, password?), send, leave. Requires the nuvaka.realtime permission. Server code, nuvaka.db and management: Extension servers (0.3.1, SDK 1.3.0).

nuvaka.ui

CallReturns
notify(title, body?)null. A local notification on this device; notifications permission; notification limit (notify_limit). Works in the background too.
openExternal(url)boolean. Opens the link in the system browser. No permission needed; UI only (ui_only in the background), https only, without user name/password or port. The shell shows the full address with the host emphasized and asks; the user can pick "don't ask again for this domain" (that device only, revocable in settings). true if opened, false if cancelled.
presentation()'modal' | 'page' | 'pip' | 'widget'. pip: you're in the picture-in-picture window (ui.pip). widget: on the home page as a widget (Home page widgets; 0.3.1). modal: you run in a window on top of My files, opened from a right-click action or "Open with" (no switch to the app page). page: on your own page from Apps. Also delivered at start as nuvaka.context().presentation; tighten your layout for it (hide your own side menu in the modal, show a clear "Save" button).
close()Closes the window (modal). In page mode, goes back if the page was opened through a contribution; otherwise does nothing. Call it after saving: My files refreshes its list when the window closes.
setDirty(dirty)Whether there are unsaved changes. While true, closing the window with X/Esc makes the shell ask "Close without saving?". Set it to false after saving.
saveFile(name, data, { contentType? }){ saved, name?, ref? }. The system "Save as" dialog; the user picks the place, no permission needed. Up to 500 MB; UI only. Returns { saved: false } if cancelled. For standalone tools (opened from Apps) that save to the computer. With the returned ref, later saves go to the same file through writeFile without asking.
openFile({ accept?, multiple? })[{ name, contentType, size, bytes, ref }]. The system "Open" dialog (accept like ['.pdf'], ['image/*']); no permission needed. Up to 100 MB per file, 200 MB in total. Empty array if cancelled. <input type=file> inside the frame may not work on every platform; prefer this.
writeFile(ref, data, { contentType? }){ saved: true, size }. Writes back to the same local file using the ref from openFile/saveFile (Ctrl+S): the user already picked the file, so there is no second prompt and no permission. A ref is valid only for this app session and only for the extension that got it (bad_ref). The write is atomic (temp file in the same folder, then rename). Up to 500 MB (too_large); UI only.
theme(){ dark, vars } — in the UI. dark is false only when the manifest says themes: ["light"]; vars are the app's --nv-* values (see themes)
page()the open page's id
locale()the app language, e.g. en
onTheme(fn)when the theme changes; unsubscribe function
onPage(fn)when the user switches to another page from the menu; unsubscribe function

nuvaka.ui.pip — picture-in-picture

Opens one of your extension's pages in a separate, borderless, small window that can stay on top of everything: a player, a timer, a chat. No permission needed. Desktop only and UI only (ui_only in the background, unsupported on Android).

CallReturns
open({ page?, width?, height?, alwaysOnTop?, title? }){ opened: true }. Opens the window or brings it to front. One window per extension; size and position are remembered on the device. page is a page id from the manifest (default: the first page); alwaysOnTop defaults to true. Can't be called from inside the PiP window.
close()null
setAlwaysOnTop(on)null
setSize(width, height)null
post(msg)null. JSON message to the other side (main page ↔ PiP), at most 1 MB (too_large). pip_closed if the window is closed.

In the PiP window the page runs like a normal page; presentation() returns 'pip'. Both sides receive messages with nuvaka.on('pip.message', fn); the main page gets pip.closed when the window closes. If the OS doesn't support "always on top" (some Linux desktops), Nuvaka shows the window as a floating layer inside the app.

// main page
await nuvaka.ui.pip.open({ page: 'mini', width: 360, height: 200 })
nuvaka.on('pip.message', (m) => { if (m.type === 'pause') player.pause() })
nuvaka.on('pip.closed', () => showInlinePlayer())
// mini page
if (nuvaka.ui.presentation() === 'pip') nuvaka.ui.pip.post({ type: 'ready' })

Events

Listen with nuvaka.on(name, fn). The background receives the events listed in the manifest's triggers; server-originated events are not delivered without the matching read permission.

EventWherePayload
schedulebackground{ schedule, at } — at in unix seconds
app.started, app.focused, network.onlinebackgroundnull
notes.changed, cloud.fileAdded, mail.received, clipboard.addedbackgrounda change notice (scope, method, path …); no data, read again through the API
data.changedboth{ kind, name, version, deleted } — raw event; prefer storage.onChanged
theme, page, localeUInew theme / page ID / language
pip.messageUIa message from the other side via ui.pip.post
pip.closedUInull — the PiP window closed (to the main page)
file.openUI{ handle, fileName, file } — a new file was picked through a core contribution while the page is open
realtime.message, realtime.member, realtime.state, realtime.closed, realtime.status, realtime.inviteUIrealtime rooms (payloads)
server.message, server.kicked, server.closed, server.inviteUIextension servers (payloads)
// background.js
nuvaka.on('schedule', async ({ schedule, at }) => {
  console.log('fired', schedule, new Date(at * 1000).toISOString())
})
nuvaka.on('notes.changed', () => refreshIndex())   // manifest: { "event": "notes.changed" } + nuvaka.notes: read

A Promise returned by a handler is awaited; an error thrown in a handler is written to the app log and does not stop the other handlers.

Errors

Every error is an Error: name: "NuvakaError", code, message (Turkish), and when relevant permission (the missing scope) and data.

CodeMeaning
permission_requiredno permission, or it was revoked; e.permission is the missing scope
permission_deniedcritical confirmation denied or timed out
confirmation_required_backgroundno valid timed approval for a critical permission in the background; nothing is asked (details)
version_conflictthe version read is stale; e.data = { current, value } (for a file handle, current is the current Meta)
bad_handle, read_onlyfile handle invalid or expired / write with a read handle
if_version_requiredset/delete called without a version
quota_exceededstorage quota full
notify_limitnotification limit reached and the user did not raise it
rate_limitedrate limit (300 calls per minute, 30 mails per hour)
confirmation_floodmore than 3 pending confirmations
out_of_scopecloud folder not opened to the extension
not_foundrecord not found
forbidden, bad_request, iolocal file errors
net_error, networknet.fetch proxy error / server unreachable
not_installed, disabled, blockedextension not installed, stopped or blocked
session_revokedthe user's session was revoked
ui_onlythe call is UI only (not in the background)
unsupportednot available on this platform (e.g. ui.pip on Android)
too_largedata exceeds the size limit
bad_refui.writeFile got an invalid ref or another extension's
pip_closedpip.post while the PiP window is closed
name_existsrename: the name exists in that folder
secure_areaa Secure Space file can't be opened / changed through a server handle
secure_sessioncall closed in a secure session (list)
confirmation_required, cancelleduser confirmation was needed / the user cancelled
host_requiredinstall the host app before an addon (addons)
unknown_methodunknown call

Codes not listed here can also appear; show unknown codes as a generic error.

SDK package (@nuvaka/extension-sdk)

Optional. It contains no transport code: it types the global nuvaka, turns errors into classes and gives you a mock nuvaka for tests.

It is not published on npm; it ships in the extension-sdk/ folder of the developer kit. A project created with nuvaka-ext init already lists it as a file: dependency in package.json, so npm install is enough (details).

import { nuvaka, PermissionError, VersionConflictError, NotifyLimitError } from '@nuvaka/extension-sdk'
import type { Manifest } from '@nuvaka/extension-sdk'

try {
  await nuvaka.push('Hello')
} catch (e) {
  if (e instanceof NotifyLimitError) { /* try again later */ }
}
ClassCode
NuvakaErrorbase class (any code)
PermissionErrorpermission_required
ConfirmationDeniedErrorpermission_denied (subclass of PermissionError)
BackgroundConfirmationErrorconfirmation_required_background (subclass of PermissionError; permission = scope)
VersionConflictErrorversion_conflict (current, value; for a file handle file = current Meta)
QuotaErrorquota_exceeded
NotifyLimitErrornotify_limit
RateLimitErrorrate_limited, confirmation_flood

The package's nuvaka throws no_runtime when called outside the app (plain browser, Node). Code that uses the global without importing can get types only with import type {} from '@nuvaka/extension-sdk/global'.

Testing: mock nuvaka

import { installMockNuvaka, uninstallMockNuvaka } from '@nuvaka/extension-sdk/testing'

const m = installMockNuvaka({
  grants: ['notifications', 'net'],             // flat scope names
  storage: { count: 1 },
  settings: { greeting: 'Hello' },
  notifyPerMinute: 3,
  fetch: (req) => ({ status: 200, body: { ok: true } }),
})
await nuvaka.storage.update('count', (n) => n + 1)
await m.emit('schedule', { schedule: 'every 15m', at: 1790000000 })
m.advance(60_000)                               // fake clock (notification window)
uninstallMockNuvaka()

The mock emulates permission checks, critical confirmation (confirm), MVCC, storage.onChanged, the notification limit and the quota. With background: true it behaves like the background: without a valid timed approval a critical call fails with BackgroundConfirmationError; m.grantConfirmation('nuvaka.mail.read', '7d') simulates an approval given in settings. For file handles there are the file: { name, content } option, m.openFile(), m.remote.editFile() and m.log.fileWrites (example). nuvaka-ext test runs vitest in the extension folder.

Nuvaka Apps API v1 · last updated 2026-10-17