Native apps
A native app is a Go backend that DSM runs as a CGI, plus a UI in a DSM window. It installs as an unsigned SPK and runs as its own package account, without containers or root access.
Set it up
Section titled “Set it up”synopkgland init -t native-go my-appThe default UI is Vue; --ui plain writes ui/app.js (UI components), and --with adds capabilities (Capabilities). init never overwrites a file (INIT_TARGET_NOT_EMPTY).
| Path | What it is |
|---|---|
dsm-package.yaml | Identity, version, build number, architectures, backend and UI location |
backend/internal/app/ | Routes and handlers |
backend/internal/api/permissions.json | Who may call each method |
frontend/src/ | Vue UI shell; on-screen text in frontend/src/i18n/<locale>.json |
i18n/messages/<locale>.json | Package text in nine languages |
i18n/glossary.json | DSM’s own words and the messages that must use them |
AGENTS.md, CLAUDE.md | Instructions for an AI assistant |
backend/internal/api/permissions.go, backend/cmd/ | Permission loading and CGI/jobs wiring; rarely edited |
Request guards, sign-in, File Station, jobs and delegate come from the SDK: the Go module github.com/synopackageland/syno-pkg-land-sdk and @synopackageland/sdk. backend/go.mod and frontend/package.json must name the same SDK version (SDK_VERSION_MISMATCH).
Add a backend route
Section titled “Add a backend route”A route is a Go handler in backend/internal/app/routes.go plus an entry in backend/internal/api/permissions.json.
func Routes(cfg Config) []api.Route { routes := cfg.delegateRoutes() routes = append(routes, []api.Route{ api.Handle("app.status", cfg.status), api.Handle("greeting.get", cfg.getGreeting), api.Handle("greeting.set", cfg.setGreeting), api.Handle("notes.list", cfg.listNotes), }...) // ...the rest of the function stays as generated}
func (cfg Config) listNotes(_ context.Context, caller api.Caller, params json.RawMessage) (any, error) { var in struct { Limit int `json:"limit"` } if err := decodeParams(params, &in); err != nil { return nil, err } return map[string]any{"owner": caller.User(), "notes": []string{}}, nil}{ "schema": 1, "default": "administrators", "methods": { "notes.list": "authenticated" }}Add valid parameters to sampleParams in backend/internal/app/routes_test.go, such as "notes.list": with {"limit":20}; the generated tests fail until you do. Run (cd backend && go test ./...).
- A handler is
func(ctx, caller, params) (any, error).decodeParamsrejects unknown fields; returnapi.BadRequest(message)or&api.Error{Code, Message}, or the UI seesinternal. - Use
api.HandleRequestfor the request,api.HandleResponsefor cookies or a written response, andapi.HandleStreamfor a transfer. caller.User()andcaller.Admin()come from DSM, never the request;api.RequireAdmin(caller)reserves one action and returnsadmin_required.- Method names are dot-joined lowercase words such as
notes.list; every name inpermissions.jsonmust be registered. Changing the file needs a rebuild.
Level in permissions.json | Without a session | Ordinary user | Administrator |
|---|---|---|---|
administrators, and any unlisted method | session_required | admin_required | runs |
authenticated | session_required | runs | runs |
public | runs | runs | runs |
default must stay administrators; public is only for routes that work without signing in (API reference). An authenticated or public route also lets ordinary users open the window; entry and ui.launch change that (see entry and launch mode).
Call it from the UI
Section titled “Call it from the UI”ctx.call(method, params) posts to your backend with the DSM session and resolves with the result; errors reject with { code, message }.
const { notes } = await ctx.call<{ notes: string[] }>('notes.list', { limit: 20 })Hide administrator-only controls with ctx.user?.isAdmin; the backend still decides. ctx.reopen(fn), ctx.locale, ctx.launchParams and ctx.onLaunch(fn) are described in the API reference.
Replies use HTTP 200; a failure is {"success": false, "error": {"code", "message"}}, as in DSM’s own web API. Codes are in Errors.
Link to a page
Section titled “Link to a page”Put a page’s route in the route launch parameter:
https://<nas>:5001/?launchApp=SYNO.SDS.<package>.Instance&launchParam=route%3D%252Fa%252Fnotes%252F42launchParam is encoded twice, for the URL and each value, because DSM decodes it into pairs and then each value. followLaunchRoute follows the opening launch and each later one:
import { followLaunchRoute } from '@synopackageland/sdk'
// Vue Router with createWebHashHistory: #/a/notes/42 in a portal link, route=/a/notes/42 from DSM.const stop = followLaunchRoute(ctx, (route) => { void router.replace(route) })The route is a path from the app root: one leading /, no backslash or control character, at most 2048 characters. Launch values are untrusted: pick a page or record with them, never HTML, a URL or a permission.
Translate the app
Section titled “Translate the app”The app ships in nine languages: en, zh-TW, zh-CN, ja, ko, de, fr, es and it; other DSM languages show English.
i18n/messages/<locale>.jsonholds flat"dotted.key": "text"pairs;en.jsonis required, and every file needs exactly its keys and{placeholder}names. Add anerror.<code>message for every backend error.i18n/glossary.jsonlists DSM’s words, such as “Save” and “Cancel”, and which messages must contain them; add your key to a term’skeysto use it.i18n.infosets Package Center text per language. In a plain UI,ctx.t("greeting.setBy", { text, user })reads these files; the Vue UI keeps its text infrontend/src/i18n/<locale>.json.
check and build fail on a missing or extra key, a dropped placeholder, an unsupported language or a glossary mismatch.
Run it as a daemon
Section titled “Run it as a daemon”A daemon keeps the App running as a supervised foreground process, as the package account, for work that must outlive one request.
- Resident children and the daemon restart after every unrequested exit, including exit zero and a signal, with jittered exponential backoff. After repeated failures in the retry window the daemon shows
failedand the App offers Retry. - A requested stop stays stopped: turning the integration off, stopping the package, an upgrade and uninstall never restart it.
- An explicit start or restart re-arms recovery with the same bounds.
Serve the web UI under the package path
Section titled “Serve the web UI under the package path”daemon.ingress serves the daemon’s web UI at /synopkgland/<package>/ on DSM’s own address, so the browser sends its DSM cookie and the page stays same-origin:
daemon: backend: true ingress: path: /synopkgland/MyApp/- The path is exactly
/synopkgland/<package>/, with the manifest’s package ID; every other top-level path is refused at build and byinspect. os_min_vermust be 7.2-64570 or later: DSM 7.1 refusesweb-configin an unsigned package.- The daemon listens on the socket in
SYNOPKGLAND_INGRESS_SOCKETand mounts its routes belowSYNOPKGLAND_INGRESS_PATH; nginx only proxies, so the daemon checks DSM sign-in itself. - A Go backend serves it with
api.ServeIngress, which checks the package ID in the socket. The fixed location block turns buffering off, so server-sent events arrive as they are written. - A stopped App’s path returns 404.
daemon.restart is optional and takes off or on-failure with bounded delays, attempts and window; without it the supervisor uses always. The manifest reference lists every field.
Develop, deploy, check
Section titled “Develop, deploy, check”synopkgland checksynopkgland buildsynopkgland deploy --host my-nassynopkgland status --host my-nassynopkgland logs --host my-nas| Command | What it does |
|---|---|
check | Validates the manifest, capabilities, permissions.json and translations |
build | Writes dist/<package>-<version>-<build>-<arch>.spk per architecture; run pnpm install in frontend/ first |
deploy | Builds and installs one architecture; the version-build must exceed the installed one (DEPLOY_VERSION_INVALID) |
status | Package state, the Open URL, and capability readiness |
logs | Status lines and identity, not an application log |
--host is required for deploy, status and logs (HOST_REQUIRED). Bump build for every SPK; --json prints one object. See Ship.
Troubleshooting
Section titled “Troubleshooting”| Symptom or code | Cause | Fix |
|---|---|---|
admin_required for an ordinary user | The route is administrators or unlisted | Set "authenticated" for it and rebuild |
unknown_method | The method is not registered in routes.go | Register it with api.Handle |
bad_request | decodeParams rejected a field, or the handler rejected a value | Send exactly the fields the handler reads |
INIT_TARGET_NOT_EMPTY | init found an existing file | Use an empty directory |
Limits
Section titled “Limits”| Item | Limit |
|---|---|
| Package name | 2 to 64 letters and digits, starting with a letter |
build | Integer from 1 to 9999 |
| Architectures | x86_64, aarch64, armv7; armv7 is built but not verified for jobs, delegate, root operations and daemon |
| Minimum DSM | os_min_ver defaults to 7.1-42661 |
Body size and timeout limits are in the API reference.