Nuvaka › Developer docs › Core contributions
Core contributions
Your extension can add options to Nuvaka's own screens: an action like "Edit" in a file's menu in My Files, or a row in the "Open with" submenu. When the user picks it, your extension's page opens with a time-limited handle that can access only that one file.
Contribution points
| Point | Where | Default mode |
|---|---|---|
storage.fileAction | My Files › file menu (e.g. "Edit") | readwrite |
storage.openWith | My Files › file menu › Open with | read |
"entry": { "ui": "index.html" },
"pages": [{ "id": "main", "title": { "tr": "Düzenleyici", "en": "Editor" } }],
"contributes": {
"storage.fileAction": [
{ "id": "edit", "title": { "tr": "Düzenle", "en": "Edit" }, "icon": "pencil", "extensions": ["txt", "md"], "page": "main" }
],
"storage.openWith": [
{ "id": "view", "title": { "tr": "Görüntüle", "en": "View" }, "mimeTypes": ["text/*"], "page": "main", "mode": "read" }
]
}
Field rules: Manifest › contributes. An item appears when the file's extension (extensions) or MIME type (mimeTypes, wildcards like image/* included) matches.
Nuvaka draws the item
- The menu row is drawn by Nuvaka's UI: the
titlefrom the manifest, the icon and your extension's name. An extension cannot put HTML, styles or code on a Nuvaka screen; it sees nothing until the user picks the item. - Users can turn contributions off and on per extension (in the Apps screen, "Additions to Nuvaka screens"). A disabled contribution does not appear in the menu.
- If several extensions offer "Open with" for the same file type, the user can make one the default for that type.
- The Store card and detail page show that the extension adds to Nuvaka screens; it is also listed as a separate row at the top of the permission list.
- Every version with
contributesgoes through Nuvaka review. An update that changes or removes contributions is not installed automatically; the user is asked.
Single-file handle
When the user picks a contribution, the app obtains a handle for that file with the user's session and opens your extension's page. The handle:
- is valid only for this user and this extension; no other extension can use it;
- accesses only that one file; no
nuvaka.cloudpermission is needed; - has a mode:
readorreadwrite. The upper bound is the contribution'smode(default:storage.fileAction→readwrite,storage.openWith→read); a wider request is refused withread_only_contribution; - has a sliding lifetime: 15 minutes at open; every read, write or
meta()extends it by 15 minutes; at most 8 hours from opening. An editor that stays open for a long time can keep the handle alive by callingmeta()now and then. The current expiry ismeta().expiresAt; - is never written to the address bar or history; every use is recorded in the extension's activity log.
SDK: nuvaka.files.handle
If the page was opened through a contribution, the context carries handle and fileName. If the user picks the contribution on another file while the page is open, the file.open event fires and the context is updated.
const ctx = await nuvaka.ready
if (ctx.handle) await openFile(ctx.handle)
nuvaka.on('file.open', ({ handle }) => openFile(handle))
async function openFile(h) {
const file = nuvaka.files.handle(h)
const meta = await file.meta() // { fileId, name, size, contentType, folderId, version, encrypted, updatedAt, mode, contribution, expiresAt }
editor.value = await file.readText() // or read() → Uint8Array
saveButton.disabled = meta.mode !== 'readwrite'
saveButton.onclick = async () => {
try {
const r = await file.write(editor.value, { version: meta.version, contentType: 'text/plain' })
meta.version = r.versionNo // for the next save
showInline(`Saved (version ${r.versionNo})`)
} catch (e) {
if (e.code === 'version_conflict') showInline('The file changed elsewhere; reload it.') // e.data.current = current Meta
else throw e
}
}
}
| Call | Returns |
|---|---|
nuvaka.files.handle(h) | handle object (synchronous; no network call) |
.meta() | { fileId, name, size, contentType, folderId, version, encrypted, updatedAt, mode, contribution, expiresAt } |
.read() | Uint8Array |
.readText() | text (UTF-8) |
.write(data, { version, contentType?, encrypted? }) | { versionNo, plainVersions, file: Meta }; readwrite only; at most 100 MB |
.saveAs(name, data, { contentType?, encrypted? }) | { handle, handleId, expiresAt, file: Meta }: a new file in the same folder and its handle; readwrite only |
nuvaka.files.suggestPurgePlainHistory(h, message?) | { purged: n } or { purged: 0, kept: true }; UI only (see encrypted content) |
Writing: MVCC and versions
writeneeds theversionyou read (meta().version). If the file changed after you read it, the call fails withversion_conflictand the error carries the file's current state (e.data.current;VersionConflictError.filein the SDK). Without a version:if_version_required.- A write opens a new version of the same file:
fileIdnever changes, and share links and other handles always show the current version. The old content moves to the file's version history (30 days, at most 20 versions per file; it doesn't count toward the quota). Users see, download and restore old versions in My Files with right-click › View versions. Extensions can't delete old versions. meta().versionis the current version number; if another device or extension wrote the same file, your write getsversion_conflict.- For a format change or a copy use
saveAs(name, data): it creates a new file in the same folder (name up to 255 characters, no/or\→bad_name). No confirmation is asked because the user already opened the file with your extension; the quota applies.
Encrypted content
- If you encrypt the content on the client, write with
write(data, { version, encrypted: true }). The version is marked encrypted: Nuvaka produces no preview or thumbnail, the assistant doesn't read the content, and share dialogs warn that the recipient can't open it without the password. An unmarked new version removes the mark. plainVersionsin the response is the number of unencrypted older versions. If it's above zero Nuvaka follows the user's preference: "ask every time" (default) offers deletion in its own dialog, "always delete" deletes without asking, "always keep" leaves them.- To offer it with your own explanation, call
nuvaka.files.suggestPurgePlainHistory(h, 'Delete the unencrypted earlier states?')right after writing. The dialog and the deletion belong to Nuvaka; your note appears in a separate box labelled with your app's name. The extension can't delete anything itself.
Errors
| Code | Meaning |
|---|---|
bad_handle | the handle is invalid, expired or belongs to another extension |
read_only | a write was attempted with a read handle |
version_conflict | the file changed after you read it |
if_version_required | write was called without a version |
Cases that can happen while opening the handle (app side): the contribution does not match this file type (no_contribution), the user disabled it (contribution_disabled), a mode wider than the contribution's (read_only_contribution), the extension is stopped or blocked. Nuvaka shows these to the user.
NuvakaSync files
Users can also open files from NuvakaSync folders synced on their computer with "Edit / Open with" and files.pickFromMyFiles. The handle is then local (nvy_…) but the interface is the same: meta, read, write, saveAs, rename.
- The file is read into memory; at most 100 MB.
writecreates a new NuvakaSync version (based on the version you read). If the file changed on another device meanwhile, nothing is overwritten; a copy named "name (conflict …)" is saved in the same folder.renamemoves the file within its folder.- Read-only sync roots open in
readmode only (writing givesread_only). Secure roots aren't offered in the picker or menus. - If the extension has network, push or mail permissions, Nuvaka warns the user before opening.
Secure Space: secure session
Secure Space files are end-to-end encrypted; asking for a server handle always returns 403 secure_area. When the vault is unlocked and the user opens such a file in an extension with "Edit / Open with", the page runs in a secure session: nuvaka.context().secure === true.
- Nuvaka downloads the file into memory and decrypts it there; plain content is never written to disk. The extension gets a local
nvs_…handle (at most 200 MB). Only one secure session is open at a time. - When the window closes, the vault locks or the key changes, memory is zeroed and the session ends.
handle.writere-encrypts and saves a new version. If the file changed meanwhile, nothing is overwritten: a new secure file named "name (çakışma YYYY-MM-DD HH.MM)" is saved in the same folder, the response hasconflictCopy: { name }and the handle switches to the copy.saveAscreates a new secure file in the same folder.- The background script isn't started,
data.changedevents don't arrive; the frame doesn't count toward the open-app limit.
| State | Calls |
|---|---|
Closed (secure_session; even if permitted) | net.*, ui.openExternal, shared.*, me, deps.call, notes.*, cloud.*, pool.*, mail.*, connections.*, friends.*, server handles (nvh_…), push, ui.notify, files.* (e.g. pickFromMyFiles, suggestPurgePlainHistory) and any call not listed here |
| In memory only | storage.get/set/delete/list (value ≤ 1 MB); never sent to the server, deleted with the session |
| User confirms every time | ui.saveFile, ui.writeFile (with a "this copy is unencrypted" warning), clipboard.writeText. cancelled if declined. |
| Open (local) | info, settings.get, log, pdf.*, clipboard.readText, ui.openFile, ui.close, ui.setDirty, ui.presentation |
The frame runs in a stricter sandbox (scripts only; no forms, popups or top navigation; no network). window.open is disabled; if the frame navigates elsewhere the session closes. extends dependencies run in the same frame. Nothing extra is needed to support secure sessions, but when context().secure is set your page should hide network features and catch errors from closed calls.
const ctx = await nuvaka.ready
if (ctx.secure) hideShareAndSync()
const h = nuvaka.files.handle(ctx.handle)
const r = await h.write(text, { version: meta.version })
if (r.conflictCopy) toast(`Conflict: saved as "${r.conflictCopy.name}"`)
Testing
The SDK's mock nuvaka simulates handles: sliding lifetime, MVCC, the version counter, plainVersions, saveAs, read_only. The answer to the cleanup question comes from the onPurgeSuggest option, the user's preference from purgePref; suggestions are in log.purgeSuggestions.
import { installMockNuvaka } from '@nuvaka/extension-sdk/testing'
const m = installMockNuvaka({ file: { name: 'note.txt', content: 'hello', contentType: 'text/plain', contribution: 'edit' } })
const h = nuvaka.files.handle(nuvaka.context().handle)
m.remote.editFile(nuvaka.context().handle, 'changed by someone else') // next write conflicts
await m.openFile({ name: 'b.md', content: '# b' }) // file.open event
m.log.fileWrites // write records
Nuvaka Apps API v1 · last updated 2026-10-17