@synopackageland/cli 0.48.6 → 0.48.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ - Reject daemon.nofile in check, build and inspect until package-safe activation is supported
6
+ - Stop daemons through the non-root SDK controller during migration and teardown; continue executor cleanup after a daemon stop failure
7
+
3
8
  ## 0.48.5
4
9
 
5
10
  - Require templates ~0.40.0: new scaffolds pin SDK/App 0.50.0 and UI 0.20.0, whose AppShell pages show no visible title and scroll only their content; the CLI controller SDK default stays 0.49.5
package/README.md CHANGED
@@ -92,6 +92,13 @@ checksum settings; a failed fetch reports `SDK_DOWNLOAD_FAILED`.
92
92
  The CLI pins an SDK release for its daemon controllers, Compose planning and installer
93
93
  context. Explicit App SDK declarations take precedence. Locally installed templates
94
94
  retain their own scaffold SDK pins; none declare daemon ingress.
95
+
96
+ `daemon.nofile` is currently unsupported. `check`, `build` and `inspect` report
97
+ `STANDALONE_DAEMON_NOFILE_UNSUPPORTED`: registering a system unit does not let
98
+ package-account hooks activate it. Remove this option to use the daemon's inherited
99
+ limits. This does not guarantee a higher file descriptor limit. See
100
+ [daemon file descriptor limits and migration](docs/daemon-nofile.md).
101
+
95
102
  Every App method is declared once in operations.json; ctl generate writes the
96
103
  permissions table and runtime bindings. Dynamic names and custom HTTP dispatchers
97
104
  are rejected. Use fixed
@@ -1,13 +1,13 @@
1
- import type { StandaloneError, StandaloneManifest } from './manifest.js';
1
+ import type { StandaloneError } from './manifest.js';
2
2
  export declare const DAEMON_NOFILE_MIN_SDK = "0.49.5";
3
3
  export declare const DAEMON_NOFILE_MIN_DSM = "7.0-40761";
4
+ export declare const DAEMON_NOFILE_UNSUPPORTED = "STANDALONE_DAEMON_NOFILE_UNSUPPORTED";
5
+ export declare const DAEMON_NOFILE_ACTIVATION_PROBLEM = "daemon.nofile is currently unsupported: DSM package hooks cannot activate the required system unit as the package account. Remove daemon.nofile to use inherited limits; higher limits require a verified native mechanism or an explicitly approved, package-scoped SDK service-control operation.";
6
+ /** Do not ship a registered unit that the package account cannot activate. */
7
+ export declare function requireDaemonNoFileActivation(nofile?: number): void;
4
8
  export declare function daemonNoFileSdkProblem(sdk: string): string | undefined;
5
9
  export declare function daemonNoFileIdentityProblem(pkg: string): string | undefined;
6
10
  export declare function readNoFile(value: unknown, fail: (e: StandaloneError) => void): number | undefined;
7
11
  export declare function daemonSystemUnitName(pkg: string): string;
12
+ /** Legacy archive shape, retained for inspection only. New builds reject NOFILE. */
8
13
  export declare function renderDaemonSystemUnit(pkg: string, nofile: number): string;
9
- /** One fixed dispatch layer covers every native lifecycle composition, including
10
- * delegated jobs and rootOps. The unit itself calls the SDK directly. */
11
- export declare function renderNoFileLifecycle(manifest: StandaloneManifest, script: string): string;
12
- /** Refuse old pins or mismatched local SDK overrides before producing an SPK. */
13
- export declare function requireDaemonNoFileSource(dir: string, sdk: string, nofile?: number): void;
@@ -1,8 +1,13 @@
1
- import { readFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
1
  import { StandaloneBuildError } from './spk.js';
4
2
  export const DAEMON_NOFILE_MIN_SDK = '0.49.5';
5
3
  export const DAEMON_NOFILE_MIN_DSM = '7.0-40761';
4
+ export const DAEMON_NOFILE_UNSUPPORTED = 'STANDALONE_DAEMON_NOFILE_UNSUPPORTED';
5
+ export const DAEMON_NOFILE_ACTIVATION_PROBLEM = 'daemon.nofile is currently unsupported: DSM package hooks cannot activate the required system unit as the package account. Remove daemon.nofile to use inherited limits; higher limits require a verified native mechanism or an explicitly approved, package-scoped SDK service-control operation.';
6
+ /** Do not ship a registered unit that the package account cannot activate. */
7
+ export function requireDaemonNoFileActivation(nofile) {
8
+ if (nofile !== undefined)
9
+ throw new StandaloneBuildError(DAEMON_NOFILE_UNSUPPORTED, DAEMON_NOFILE_ACTIVATION_PROBLEM);
10
+ }
6
11
  export function daemonNoFileSdkProblem(sdk) {
7
12
  const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(sdk);
8
13
  if (match) {
@@ -24,6 +29,7 @@ export function readNoFile(value, fail) {
24
29
  fail({ code: 'STANDALONE_DAEMON_NOFILE_INVALID', message: 'daemon.nofile must be an integer from 1024 to 1048576; the daemon always runs as the package account' });
25
30
  }
26
31
  export function daemonSystemUnitName(pkg) { return `pkg-${pkg}-daemon.service`; }
32
+ /** Legacy archive shape, retained for inspection only. New builds reject NOFILE. */
27
33
  export function renderDaemonSystemUnit(pkg, nofile) {
28
34
  const problem = daemonNoFileIdentityProblem(pkg);
29
35
  if (problem)
@@ -48,49 +54,3 @@ TimeoutStartSec=0
48
54
  TimeoutStopSec=0
49
55
  `;
50
56
  }
51
- /** One fixed dispatch layer covers every native lifecycle composition, including
52
- * delegated jobs and rootOps. The unit itself calls the SDK directly. */
53
- export function renderNoFileLifecycle(manifest, script) {
54
- if (manifest.daemon?.nofile === undefined)
55
- return script;
56
- const pkg = manifest.package, unit = daemonSystemUnitName(pkg);
57
- const controls = [`"/var/packages/${pkg}/target/daemon/control"`, `"\${SYNOPKG_PKGDEST:-/var/packages/${pkg}/target}/daemon/control"`];
58
- if (!controls.some(c => script.includes(c)))
59
- return script;
60
- for (const control of controls)
61
- script = script.replaceAll(`exec ${control}`, 'synopkgland_daemon_control').replaceAll(control, 'synopkgland_daemon_control');
62
- const dispatch = `synopkgland_daemon_control() {
63
- synopkgland_daemon_action="$1"
64
- shift
65
- case "$synopkgland_daemon_action" in
66
- start|restart) /usr/syno/bin/synosystemctl "$synopkgland_daemon_action" ${unit} ;;
67
- stop)
68
- if [ -f /usr/local/lib/systemd/system/${unit} ]; then
69
- /usr/syno/bin/synosystemctl stop ${unit} || return $?
70
- fi
71
- "\${SYNOPKG_PKGDEST:-/var/packages/${pkg}/target}/daemon/control" stop "$@" ;;
72
- uninstall)
73
- if [ -f /usr/local/lib/systemd/system/${unit} ]; then
74
- /usr/syno/bin/synosystemctl stop ${unit} || return $?
75
- fi
76
- "\${SYNOPKG_PKGDEST:-/var/packages/${pkg}/target}/daemon/control" uninstall "$@" ;;
77
- *) "\${SYNOPKG_PKGDEST:-/var/packages/${pkg}/target}/daemon/control" "$synopkgland_daemon_action" "$@" ;;
78
- esac
79
- }
80
- `;
81
- return script.replace('#!/bin/sh\n', () => `#!/bin/sh\n${dispatch}`);
82
- }
83
- /** Refuse old pins or mismatched local SDK overrides before producing an SPK. */
84
- export function requireDaemonNoFileSource(dir, sdk, nofile) {
85
- if (nofile === undefined)
86
- return;
87
- let main = '', linux = '';
88
- try {
89
- main = readFileSync(join(dir, 'daemonctl/main.go'), 'utf8');
90
- linux = readFileSync(join(dir, 'daemonctl/nofile_linux.go'), 'utf8');
91
- }
92
- catch { /* Fail closed below. */ }
93
- const problem = daemonNoFileSdkProblem(sdk);
94
- if (problem || !/\bNoFile\s+int\s+`json:"nofile,omitempty"`/.test(main) || !main.includes('validateNoFile(cfg.NoFile)') || !main.includes('applyNoFile(c.NoFile)') || !linux.includes('func applyNoFile('))
95
- throw new StandaloneBuildError('STANDALONE_DAEMON_NOFILE_SDK_REQUIRED', problem ?? `daemon.nofile requires matching SDK ${DAEMON_NOFILE_MIN_SDK} source with validated non-root NOFILE inheritance; update the SDK pin or development override before building`);
96
- }
@@ -5,7 +5,7 @@ import { type DaemonRestart } from "./daemon-restart.js";
5
5
  import type { CommandRunner } from "./build.js";
6
6
  import type { StandaloneError, StandaloneManifest } from "./manifest.js";
7
7
  export interface Daemon {
8
- /** Acquired system-unit file descriptor limit; all processes stay non-root. */
8
+ /** Legacy inventory only; new builds reject this until activation is package-safe. */
9
9
  nofile?: number;
10
10
  /** Optional bounded recovery; omission uses the SDK controller default. SDK 0.26.0 or later. */
11
11
  restart?: DaemonRestart;
@@ -1,4 +1,4 @@
1
- import { readNoFile, requireDaemonNoFileSource } from "./daemon-nofile.js";
1
+ import { readNoFile, requireDaemonNoFileActivation } from "./daemon-nofile.js";
2
2
  import { portDefaults } from "./install-ports.js";
3
3
  import { operationBudgetSeconds, runtimeBudgetSdkSupported } from "../runtime/runtime-budgets.js";
4
4
  import { goChildEnv } from "../runtime/go-env.js";
@@ -234,11 +234,11 @@ export function requireBackendDaemonSource(source, daemon) {
234
234
  export async function buildDaemonControl(manifest, arch, work, run) {
235
235
  if (!manifest.daemon && !(manifest.compose && manifest.identityGateway))
236
236
  return undefined;
237
+ requireDaemonNoFileActivation(manifest.daemon?.nofile);
237
238
  const out = join(work, `daemon-control-${arch}`);
238
239
  const sdk = daemonSdkVersion(manifest);
239
240
  const source = runtimeBudgetSource(sdkSource(sdk).goDir, manifest);
240
241
  requireDaemonRestartSource(source, sdk, manifest.daemon?.restart);
241
- requireDaemonNoFileSource(source, sdk, manifest.daemon?.nofile);
242
242
  requireBackendDaemonSource(source, manifest.daemon);
243
243
  const result = await run("go", [
244
244
  "build",
@@ -1,4 +1,4 @@
1
- import { readNoFile, daemonSystemUnitName, renderDaemonSystemUnit, daemonNoFileSdkProblem, daemonNoFileIdentityProblem, DAEMON_NOFILE_MIN_DSM } from "./daemon-nofile.js";
1
+ import { DAEMON_NOFILE_UNSUPPORTED, DAEMON_NOFILE_ACTIVATION_PROBLEM, readNoFile, daemonSystemUnitName, renderDaemonSystemUnit, daemonNoFileSdkProblem, daemonNoFileIdentityProblem, DAEMON_NOFILE_MIN_DSM } from "./daemon-nofile.js";
2
2
  import { gatewayIngressPathProblem, gatewayIngressOwnershipSupported } from './gateway-ingress.js';
3
3
  import { renderGatewayIngressCheck } from './native-gateway.js';
4
4
  import { portDefaults, portInstallSteps } from "./install-ports.js";
@@ -155,6 +155,8 @@ export async function inspectSpk(spkPath, expectedKind) {
155
155
  }
156
156
  const dependencies = inspectPackageDependencies(metadata.dependencies, findings);
157
157
  const daemonNoFile = readNoFile(metadata.daemon_nofile, e => findings.push(e.message));
158
+ if (metadata.daemon_nofile !== undefined)
159
+ findings.push(`[${DAEMON_NOFILE_UNSUPPORTED}] ${DAEMON_NOFILE_ACTIVATION_PROBLEM}`);
158
160
  if (daemonNoFile !== undefined) {
159
161
  const problem = daemonNoFileSdkProblem(typeof metadata.daemon_sdk === 'string' ? metadata.daemon_sdk : 'unknown');
160
162
  if (problem)
@@ -1,4 +1,3 @@
1
- import { renderNoFileLifecycle } from "./daemon-nofile.js";
2
1
  import { renderGatewayIngressCheck } from './native-gateway.js';
3
2
  import { renderSettingsHook } from './install-settings.js';
4
3
  import { renderComposeRetainedData } from "../build-spk/compose-retained-data.js";
@@ -16,7 +15,7 @@ import { composeAppScript } from "./app-scripts.js";
16
15
  const UNINSTALL_ONLY = '[ "${SYNOPKG_PKG_STATUS:-}" = UPGRADE ] || synopkgland_uninstall_hook\n';
17
16
  /** Package-account lifecycle hooks for CGI, daemon and background packages. */
18
17
  export function renderStandaloneScript(name, manifest) {
19
- const script = renderNoFileLifecycle(manifest, renderStandaloneScriptInternal(name, manifest));
18
+ const script = renderStandaloneScriptInternal(name, manifest);
20
19
  const prefix = renderStandaloneScriptPrefix(name, manifest);
21
20
  const sdk = prefix ? script.replace('#!/bin/sh\n', () => '#!/bin/sh\n' + prefix) : script;
22
21
  return manifest.appScripts?.some((app) => app === name)
@@ -161,9 +160,9 @@ function renderStandaloneScriptBody(name, manifest) {
161
160
  },
162
161
  });
163
162
  const stopDaemon = manifest.daemon
164
- ? `"/var/packages/${manifest.package}/target/daemon/control" stop "\${SYNOPKG_PKGDEST:-/var/packages/${manifest.package}/target}" "\${SYNOPKG_PKGVAR:-/var/packages/${manifest.package}/var}" || exit $?\n`
163
+ ? `"/var/packages/${manifest.package}/target/daemon/control" stop "\${SYNOPKG_PKGDEST:-/var/packages/${manifest.package}/target}" "\${SYNOPKG_PKGVAR:-/var/packages/${manifest.package}/var}" || daemon_result=$?\n`
165
164
  : "";
166
- return normal.replace("#!/bin/sh\n", `#!/bin/sh\n${workerStop}if [ "$1" = start ]; then\n${request("start")}fi\nif [ "$1" = stop ]; then\n${stopWorker}${stopDaemon}${request("stop")}${workerResult}fi\n`);
165
+ return normal.replace("#!/bin/sh\n", `#!/bin/sh\n${workerStop}if [ "$1" = start ]; then\n${request("start")}fi\nif [ "$1" = stop ]; then\n${stopWorker}daemon_result=0\n${stopDaemon}${request("stop")}[ "$daemon_result" = 0 ] || exit "$daemon_result"\n${workerResult}fi\n`);
167
166
  }
168
167
  if (name === "preuninst")
169
168
  return renderExecutorPreuninst(manifest, workerStop, stopWorker, workerResult, request);
@@ -1,4 +1,4 @@
1
- import { daemonNoFileSdkProblem, daemonNoFileIdentityProblem, DAEMON_NOFILE_MIN_DSM } from './daemon-nofile.js';
1
+ import { daemonNoFileSdkProblem, daemonNoFileIdentityProblem, DAEMON_NOFILE_MIN_DSM, DAEMON_NOFILE_UNSUPPORTED, DAEMON_NOFILE_ACTIVATION_PROBLEM } from './daemon-nofile.js';
2
2
  import { readRegistry, registryFile } from '../ctl/registry.js';
3
3
  import { gatewayIngressPathProblem, gatewayIngressOwnershipSupported } from './gateway-ingress.js';
4
4
  import { nativeGatewaySdk } from "./native-gateway.js";
@@ -348,6 +348,8 @@ function readManifest(raw, c) {
348
348
  if (problem)
349
349
  c.fail("STANDALONE_DAEMON_INGRESS_MIN_DSM", problem);
350
350
  }
351
+ if (daemon?.nofile !== undefined)
352
+ c.fail(DAEMON_NOFILE_UNSUPPORTED, DAEMON_NOFILE_ACTIVATION_PROBLEM);
351
353
  if (daemon?.nofile !== undefined && backend) {
352
354
  if (osMinVer && !isDsmAtLeast(osMinVer, DAEMON_NOFILE_MIN_DSM))
353
355
  c.fail('STANDALONE_DAEMON_NOFILE_DSM_REQUIRED', `daemon.nofile requires DSM ${DAEMON_NOFILE_MIN_DSM} or later; the target is never raised automatically`);
@@ -1,4 +1,4 @@
1
- import { daemonSystemUnitName, renderDaemonSystemUnit } from "./daemon-nofile.js";
1
+ import { requireDaemonNoFileActivation } from "./daemon-nofile.js";
2
2
  import { gatewayIngressOwnershipSupported } from './gateway-ingress.js';
3
3
  import { portDefaults, portInstallSteps, writePortPayload } from "./install-ports.js";
4
4
  import { packageDependencies, dependencyInfo } from "./package-dependencies.js";
@@ -73,6 +73,7 @@ export class StandaloneBuildError extends Error {
73
73
  */
74
74
  export async function assembleStandaloneSpk(options) {
75
75
  const { manifest } = options;
76
+ requireDaemonNoFileActivation(manifest.daemon?.nofile);
76
77
  const staging = mkdtempSync(join(tmpdir(), "syno-standalone-spk-"));
77
78
  try {
78
79
  if ((manifest.capabilities.rootOps ||
@@ -302,10 +303,6 @@ export async function assembleStandaloneSpk(options) {
302
303
  const resource = renderStandaloneResource(manifest, portal);
303
304
  if (resource)
304
305
  writeFile(join(staging, "conf", "resource"), resource);
305
- if (manifest.daemon?.nofile !== undefined) {
306
- mkdirSync(join(staging, "conf/systemd"), { recursive: true });
307
- writeFile(join(staging, "conf/systemd", daemonSystemUnitName(manifest.package)), renderDaemonSystemUnit(manifest.package, manifest.daemon.nofile));
308
- }
309
306
  if (manifest.capabilities.jobs) {
310
307
  mkdirSync(join(staging, BACKGROUND_UNIT_DIR), { recursive: true });
311
308
  writeFile(join(staging, BACKGROUND_UNIT_DIR, backgroundUnitName(manifest.package)), renderBackgroundUnit(manifest.package, isBridgeBackend(manifest.backend) ? BRIDGE_WORKER_ARGS : [], manifest.daemon?.timeouts.stop ?? manifest.lifecycleTimeouts?.stop ?? 30));
@@ -0,0 +1,81 @@
1
+ # Daemon file descriptor limits
2
+
3
+ `daemon.nofile` is currently unsupported. Manifest validation, SPK building
4
+ (including direct assembly) and inspection report
5
+ `STANDALONE_DAEMON_NOFILE_UNSUPPORTED`. No system unit is generated for new
6
+ packages. Removing the option preserves ordinary non-root SDK startup with the
7
+ limits inherited from DSM; it does not establish any minimum above those limits.
8
+
9
+ The numeric declaration and legacy archive unit shape remain readable so an old
10
+ SPK produces an actionable diagnostic instead of silently passing inspection.
11
+
12
+ ## DSM activation boundary
13
+
14
+ DSM's [systemd resource documentation](https://help.synology.com/developer-guide/resource_acquisition/systemd_user_unit.html)
15
+ distinguishes user units from system units. The framework registers and removes
16
+ `conf/systemd/pkg-*` units. This does not authorize a package-account lifecycle
17
+ hook to start or stop those system units.
18
+
19
+ A controlled DSM 7.3.2 fixture established these limits:
20
+
21
+ - The generated package service and its package-account hooks inherit a hard
22
+ NOFILE limit of 4096. The shell hook's soft limit is 1024.
23
+ - `conf/systemd/override/pkg-service` applies `TimeoutStartSec`, but does not
24
+ propagate `LimitNOFILE` into the generated service.
25
+ - An INFO `start_dep_services` declaration naming the custom package system unit
26
+ does not activate it. An `[Install]` dependency alone does not enable it.
27
+ - Package-account `synosystemctl` and `systemctl` requests are denied. A user
28
+ manager cannot raise its inherited hard limit; see
29
+ [systemd's resource limit rules](https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html).
30
+
31
+ These observations qualify the current refusal. They do not prove that every DSM
32
+ release lacks another native mechanism. Support requires a verified activation
33
+ and teardown mechanism, not just a syntactically valid unit file.
34
+
35
+ ## Migration and cleanup
36
+
37
+ Regenerate a package after removing `daemon.nofile`. Its lifecycle hooks call the
38
+ SDK daemon controller directly for stop, upgrade and uninstall, including when
39
+ the outgoing payload has a legacy NOFILE unit. They do not attempt unprivileged
40
+ system-manager control first. Executor stop still runs after a daemon stop
41
+ failure and the hook preserves failure status.
42
+
43
+ DSM owns removal of the old registered unit during resource release on upgrade
44
+ or uninstall. Hooks do not unlink system files or invoke `daemon-reload` as the
45
+ package account.
46
+
47
+ An already installed legacy hook can prevent DSM from reaching that release:
48
+ DSM uses the incoming `preupgrade` but still runs the outgoing `preuninst`.
49
+ The old hook tries to stop the system unit and returns on access denial even
50
+ when SDK stop already succeeded. Upgrading the CLI cannot rewrite that installed
51
+ hook. Such an installation requires administrator recovery of its exact legacy
52
+ unit before retrying an upgrade or uninstall. The CLI does not perform that
53
+ privileged recovery automatically. Automatic migration of these broken outgoing
54
+ hooks remains unsupported until the approved service-control contract exists.
55
+
56
+ A failed SDK teardown remains a failure requiring recovery. Removing the manifest
57
+ option does not make an application that needs a higher limit ready for release.
58
+
59
+ ## Required contract for a privileged SDK alternative
60
+
61
+ If no native mechanism meets the lifecycle requirements, a future SDK operation
62
+ would need administrator-approved root executor authority. It is not implemented
63
+ or implicitly authorized by `daemon.nofile`.
64
+
65
+ - Derive exactly one unit name, `pkg-<validated-package>-daemon.service`, from the
66
+ executor's trusted package identity. Accept only a fixed action enum such as
67
+ start, stop and restart; accept no caller-supplied unit name, command or path.
68
+ - Anchor the installed unit bytes to the approved package payload. Verify the
69
+ fixed SDK executable, package User/Group, package slice, NOFILE value and
70
+ lifecycle arguments before every privileged control operation. Reject replaced,
71
+ symlinked, foreign or mismatched units.
72
+ - Require a distinct, digest-bound service-control approval. Ordinary daemon
73
+ startup, App code, the daemon controller and every worker remain non-root;
74
+ `conf/privilege` retains `defaults.run-as: package`.
75
+ - Bound operations, verify readiness and report the actual manager failure.
76
+ During stop, upgrade and uninstall, attempt SDK cleanup even if service control
77
+ fails. Preserve failed/cleanup-required outcomes and support recovery after a
78
+ partially completed operation.
79
+ - Verify old-unit release, rollback and uninstall with an active legacy unit.
80
+ Never use App-side sudo, a broad root lifecycle hook or arbitrary systemctl
81
+ access as a substitute for this operation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synopackageland/cli",
3
- "version": "0.48.6",
3
+ "version": "0.48.8",
4
4
  "description": "Syno Package Land Developer Kit CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -16,7 +16,8 @@
16
16
  "schema",
17
17
  "docs/ctl-external.md",
18
18
  "skills",
19
- "docs/shared-folders.md"
19
+ "docs/shared-folders.md",
20
+ "docs/daemon-nofile.md"
20
21
  ],
21
22
  "scripts": {
22
23
  "check:docs": "node --test scripts/check-doc-versions.test.mjs && node scripts/check-doc-versions.mjs",
package/skills/SKILL.md CHANGED
@@ -360,6 +360,37 @@ upstreams with a hardcoded base path. Read [reference/identity-gateway.md](refer
360
360
  for reserved paths, install-time ownership checks and unchanged auth policy.
361
361
  Apps requiring `/` cannot use ingress.
362
362
 
363
+ ## HTTPS 與舊 DSM token
364
+
365
+ 不是每個 App 都需要 HTTPS,很多 App 用 HTTP 就夠。一般 CRUD、設定或檔案類
366
+ App 不要預設強制 HTTPS。只有使用 secure context 能力(`getUserMedia`、
367
+ 剪貼簿讀寫、Service Worker、WebCrypto `subtle` 等)、瀏覽器 Extension 或外部
368
+ 裝置配對,或 App 的嚴格 Origin 驗證確實要求 HTTPS 時,才明確啟用限制。
369
+
370
+ 要求 HTTPS 的 App 應回專屬碼 `https_required`,不可混成 `NOT_AUTHENTICATED`
371
+ 或 `session_required`,否則重新登入也無法解決。可選用 Go
372
+ `api.RequireSecureOrigin(request)`;它不取代 session、同源或權限檢查。
373
+ 前端以 `identityCopy(locale).httpsTitle` 和 `errors.https_required` 顯示
374
+ 「需要 HTTPS/請改用 HTTPS」頁,提供重新開啟 App 的說明。
375
+ 只有 `ctx.user?.isAdmin === true` 才呼叫 `readDsmPorts(ctx)`,從 `dms_https`
376
+ 取得實際 HTTPS 埠並提供 DSM 連結;也可用 SDK `readDsmHttpsURL(ctx, location.href)`
377
+ 處理此限制。PortInfo 限管理員,一般使用者呼叫可能被拒或關閉 DSM 視窗;
378
+ 一般使用者只顯示說明文字。查不到埠時不猜測、不阻擋說明頁。
379
+
380
+ 舊 DSM 分頁可能在其他分頁重新登入後繼續帶舊 `X-SYNO-TOKEN`。對明確宣告
381
+ `effect: read` 的一般 JSON RPC,可用 `createClient({sessionRetry: ...})`
382
+ 搭配 `createDsmSession` 的 `refresh(rejectedToken)` 更新 token 後重試一次。
383
+ `sessionRetry.operations` 必須來自 App 可信的 effect 資料並明確標示 `kind`;
384
+ 只有 `kind: rpc` 可重試。寫入、AI、串流、batch 和不明方法均不自動重試,
385
+ 失敗後保留原錯誤。既有 `ctx.call` 不會因 SDK 更新而自動啟用此功能。
386
+ 完整 API 與 opt-in 理由見 SDK 的
387
+ [HTTPS 與 session 恢復指南](https://github.com/synopackageland/syno-pkg-land-sdk/blob/main/docs/https-and-session-recovery.md)。
388
+
389
+ 驗收時分別從 `http://<host>:5000` 與 `https://<host>:5001` 開啟 App(DSM
390
+ 自訂埠改用實際值),各驗管理員與一般使用者;HTTP 應能正常使用,或明確顯示
391
+ HTTPS 要求,不能陷入重登入循環。另驗跨分頁重新登入後的讀取恢復,並確認
392
+ 寫入、AI、串流不重送。
393
+
363
394
  ## Maintaining this CLI
364
395
 
365
396
  For CLI releases, `npm run gates` runs basic build/typecheck, core unit checks,
@@ -15,6 +15,28 @@ I capability: init --with login or add login enables Go-native standalone identi
15
15
 
16
16
  B files needs the current user's DSM session. A jobs processes owner-bound private copies as the package account without administrator setup. Neither App identity nor login alone grants offline File Station access.
17
17
 
18
+ ## HTTPS and stale DSM tokens
19
+
20
+ HTTP is sufficient for many CRUD, settings and file Apps. Require HTTPS only
21
+ when the App needs secure context browser features, pairing or a strict secure
22
+ Origin policy. Return `https_required`, separate from authentication failures,
23
+ and render `identityCopy(locale).httpsTitle` / `errors.https_required` with a
24
+ way to reopen through HTTPS. Go `api.RequireSecureOrigin(request)` is opt-in
25
+ and supplements the existing origin/session/permission checks.
26
+
27
+ Only administrators may call `readDsmPorts(ctx)` to find `dms_https`;
28
+ `readDsmHttpsURL(ctx, location.href)` provides this guard and a DSM link.
29
+ Ordinary users receive instructions only: PortInfo can refuse their session
30
+ or close their DSM window. Never guess a configured port.
31
+
32
+ After another tab signs in, an old page can retain a stale `X-SYNO-TOKEN`.
33
+ `createClient` offers opt-in `sessionRetry` using `createDsmSession.refresh`:
34
+ only trusted `effect: read`, `kind: rpc` entries retry once on `session_required`.
35
+ Writes, AI, streams, batches, unknown methods and other failures never replay.
36
+ This does not automatically wrap the generated `ctx.call`. Read the SDK's
37
+ [API and policy guide](https://github.com/synopackageland/syno-pkg-land-sdk/blob/main/docs/https-and-session-recovery.md)
38
+ and the [main skill's validation guidance](../SKILL.md#https-與舊-dsm-token).
39
+
18
40
 
19
41
  ## Permanent destination integration
20
42