@synopackageland/cli 0.48.11 → 0.48.13
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 +4 -0
- package/README.md +25 -5
- package/dist/bin.js +1 -1
- package/dist/host/catalog-install.d.ts +16 -4
- package/dist/host/catalog-install.js +113 -25
- package/dist/host/container-pull.d.ts +2 -0
- package/dist/host/container-pull.js +10 -4
- package/dist/host/install-control.d.ts +6 -0
- package/dist/host/install-control.js +39 -0
- package/dist/host/package-commands.d.ts +4 -1
- package/dist/host/package-commands.js +9 -3
- package/dist/host/package-operation.d.ts +15 -0
- package/dist/host/package-operation.js +52 -0
- package/dist/nas/timeouts.d.ts +1 -0
- package/dist/nas/timeouts.js +1 -0
- package/package.json +1 -1
- package/schema/package-state.schema.json +86 -0
- package/skills/SKILL.md +5 -0
- package/skills/reference/files.md +4 -0
- package/skills/reference/host-install.md +18 -0
- package/skills/reference/media.md +51 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
- Reject daemon.nofile in check, build and inspect until package-safe activation is supported
|
|
6
6
|
- Stop daemons through the non-root SDK controller during migration and teardown; continue executor cleanup after a daemon stop failure
|
|
7
7
|
|
|
8
|
+
## 0.48.13
|
|
9
|
+
|
|
10
|
+
- status and install report the upgrading state while DSM replaces an installed package instead of installed:false; waits use query limits and cancellation instead of short time budgets
|
|
11
|
+
|
|
8
12
|
## 0.48.5
|
|
9
13
|
|
|
10
14
|
- 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
|
@@ -494,18 +494,22 @@ are sent only over a connection whose certificate was inspected. Public package
|
|
|
494
494
|
feeds and SPK downloads retain normal HTTPS verification.
|
|
495
495
|
|
|
496
496
|
DSM API requests tolerate slow NAS storage and startup. These environment
|
|
497
|
-
variables also work in `.env`;
|
|
497
|
+
variables also work in `.env`; timeout/interval values accept integer seconds from 1 to 86400:
|
|
498
498
|
|
|
499
499
|
| Variable | Default | Budget |
|
|
500
500
|
| --- | ---: | --- |
|
|
501
501
|
| `DSM_REQUEST_TIMEOUT_SECONDS` | 180 | One DSM read, login or other API request |
|
|
502
502
|
| `DSM_OPERATION_TIMEOUT_SECONDS` | 600 | One SPK upload, install/upgrade compound, or package start/stop request |
|
|
503
|
-
| `
|
|
503
|
+
| `DSM_INSTALL_MAX_POLLS` | 10000 | Per-package polling attempts across initial checks, pre-pull and install/start verification |
|
|
504
504
|
| `DSM_UNINSTALL_TIMEOUT_SECONDS` | 1800 | State check, stop and uninstall together |
|
|
505
505
|
| `DSM_POLL_INTERVAL_SECONDS` | 5 | Package-state polling and progress interval |
|
|
506
506
|
| `DSM_IMAGE_PULL_STALL_TIMEOUT_SECONDS` | 1200 | No increase in NAS pull bytes; status heartbeats do not reset this budget |
|
|
507
507
|
|
|
508
|
-
|
|
508
|
+
Install/upgrade waiting has no default elapsed-time deadline. Slow successful work
|
|
509
|
+
continues until the polling limit (an integer from 1 to 1000000), cancellation or a DSM failure.
|
|
510
|
+
`DSM_INSTALL_TIMEOUT_SECONDS` no longer limits install/deploy waiting. Individual
|
|
511
|
+
requests retain their timeouts; timed-out status requests count toward the polling limit.
|
|
512
|
+
Press Ctrl-C to stop waiting; this does not cancel the NAS operation.
|
|
509
513
|
Container Apps pre-pull their inspected, locked image references on the NAS before
|
|
510
514
|
SPK upload. An exact local repository digest skips the registry pull; an image
|
|
511
515
|
configuration ID or a remote update digest is not sufficient proof. Progress includes bytes; failures name the image, requested registry
|
|
@@ -522,11 +526,27 @@ failure includes its source and timestamp; it is scoped to NAS origin and packag
|
|
|
522
526
|
and cleared after a successful pre-pull. An unavailable lower-level cause stays
|
|
523
527
|
unknown; a generic `install_corruption` does not prove a registry failure.
|
|
524
528
|
|
|
529
|
+
`status <package-id> --json` reports `state: "upgrading"`, `"installing"` or
|
|
530
|
+
`"starting"` during replacement/startup, with `fromVersion`/`toVersion` when known.
|
|
531
|
+
It never reports `installed:false` for those transitions: an upgrade retains
|
|
532
|
+
`installed:true`; a fresh install without a verified payload uses `installed:null`.
|
|
533
|
+
`status` carries the effective DSM/CLI status. The result contract is
|
|
534
|
+
[schema/package-state.schema.json](schema/package-state.schema.json).
|
|
535
|
+
|
|
536
|
+
The CLI checks DSM package list/status views and retains its own task identity
|
|
537
|
+
in a private cache scoped to the NAS origin and package. Concurrent CLI processes
|
|
538
|
+
under the same local user can therefore identify an upgrade even while DSM lists
|
|
539
|
+
omit the package. After interrupted work, DSM evidence is needed to keep claiming
|
|
540
|
+
an active transition; unresolved absence is `state:"unknown", installed:null`.
|
|
541
|
+
Other clients/machines rely on DSM's exposed transitions. Stable completion requires
|
|
542
|
+
the target version and running state; `install --json` returns that verified state.
|
|
543
|
+
|
|
525
544
|
An install/upgrade response timeout does not cancel DSM's work: the CLI keeps
|
|
526
545
|
checking for the requested version **and running state**, without replaying the
|
|
527
546
|
write. Progress continues on stderr, including with `--json`. A DSM failure
|
|
528
|
-
reports `DSM_INSTALL_FAILED` and its reported details
|
|
529
|
-
|
|
547
|
+
reports `DSM_INSTALL_FAILED` and its reported details. An exhausted polling limit
|
|
548
|
+
reports `DSM_INSTALL_LIMIT`; cancellation reports `DSM_INSTALL_CANCELED` (exit 130).
|
|
549
|
+
Both mean waiting stopped and DSM may still be working.
|
|
530
550
|
Uninstall also keeps checking after stop/uninstall response or status timeouts,
|
|
531
551
|
without replaying either write. Its exhausted budget reports `DSM_UNINSTALL_TIMEOUT`.
|
|
532
552
|
Check Package Center before retrying. A timed-out same-version reinstall also
|
package/dist/bin.js
CHANGED
|
@@ -7,5 +7,5 @@ loadDotEnv();
|
|
|
7
7
|
// Successful completion leaves Node's default 0 or the command's exitCode intact.
|
|
8
8
|
runCli(process.argv).catch((error) => {
|
|
9
9
|
console.error(terminalSafe(error instanceof Error ? error.message : String(error)));
|
|
10
|
-
process.exit(1);
|
|
10
|
+
process.exit(error?.code === 'DSM_INSTALL_CANCELED' ? 130 : 1);
|
|
11
11
|
});
|
|
@@ -11,7 +11,11 @@ interface CatalogPackageEntry {
|
|
|
11
11
|
replacepkgs?: unknown;
|
|
12
12
|
}
|
|
13
13
|
export interface InstalledPackageState {
|
|
14
|
-
installed
|
|
14
|
+
/** null means DSM cannot currently verify an installed payload. */
|
|
15
|
+
installed: boolean | null;
|
|
16
|
+
state?: 'installing' | 'upgrading' | 'starting' | 'unknown';
|
|
17
|
+
fromVersion?: string;
|
|
18
|
+
toVersion?: string;
|
|
15
19
|
version?: string;
|
|
16
20
|
status?: string;
|
|
17
21
|
error?: {
|
|
@@ -32,7 +36,10 @@ export interface UploadedCatalogPackage {
|
|
|
32
36
|
}
|
|
33
37
|
export declare function packageStateFromRecord(value: unknown): InstalledPackageState;
|
|
34
38
|
export declare function packageStateFromListPayload(payload: unknown, packageId: string): InstalledPackageState | undefined;
|
|
35
|
-
export declare function fetchInstalledPackageState(dsmOrigin: string, cookieHeader: string, packageId: string, timeoutMs?: number
|
|
39
|
+
export declare function fetchInstalledPackageState(dsmOrigin: string, cookieHeader: string, packageId: string, timeoutMs?: number, context?: {
|
|
40
|
+
signal?: AbortSignal;
|
|
41
|
+
ignoreOperation?: boolean;
|
|
42
|
+
}): Promise<InstalledPackageState | undefined>;
|
|
36
43
|
export interface InstallWaitOptions {
|
|
37
44
|
packageId: string;
|
|
38
45
|
expectedVersion?: string;
|
|
@@ -41,8 +48,11 @@ export interface InstallWaitOptions {
|
|
|
41
48
|
requireRunning?: boolean;
|
|
42
49
|
requireTransition?: boolean;
|
|
43
50
|
onProgress?: (message: string) => void;
|
|
51
|
+
maxPolls?: number;
|
|
52
|
+
consumePoll?: () => void;
|
|
53
|
+
signal?: AbortSignal;
|
|
44
54
|
}
|
|
45
|
-
export declare function waitForInstalledVersion(readState: (remainingMs: number) => InstalledPackageState | undefined | Promise<InstalledPackageState | undefined>, options: InstallWaitOptions): Promise<
|
|
55
|
+
export declare function waitForInstalledVersion(readState: (remainingMs: number) => InstalledPackageState | undefined | Promise<InstalledPackageState | undefined>, options: InstallWaitOptions): Promise<InstalledPackageState>;
|
|
46
56
|
export interface UninstallPackageOptions {
|
|
47
57
|
dsmOrigin: string;
|
|
48
58
|
cookieHeader: string;
|
|
@@ -73,6 +83,8 @@ export interface LocalSpkInstallOptions {
|
|
|
73
83
|
pollMs?: number;
|
|
74
84
|
onProgress?: (message: string) => void;
|
|
75
85
|
containerImages?: string[];
|
|
86
|
+
maxPolls?: number;
|
|
87
|
+
signal?: AbortSignal;
|
|
76
88
|
}
|
|
77
|
-
export declare function installPackageFromLocalSpk(options: LocalSpkInstallOptions): Promise<
|
|
89
|
+
export declare function installPackageFromLocalSpk(options: LocalSpkInstallOptions): Promise<InstalledPackageState>;
|
|
78
90
|
export {};
|
|
@@ -3,9 +3,11 @@ import { readFileSync } from "node:fs";
|
|
|
3
3
|
import { terminalSafe } from '../terminal-text.js';
|
|
4
4
|
import { pullContainerImages } from './container-pull.js';
|
|
5
5
|
import { savePullFailure } from './package-diagnostics.js';
|
|
6
|
+
import { readPackageOperation, operationOwnerAlive, savePackageOperation, clearPackageOperation, releasePackageOperation } from './package-operation.js';
|
|
7
|
+
import { cancelableInstall, installDelay, installWorkload, installCanceled } from './install-control.js';
|
|
6
8
|
import { dsmFetch } from "./dsm-http.js";
|
|
7
9
|
import { assertDsmCompoundResponse } from "./dsm-compound.js";
|
|
8
|
-
import { dsmRequestTimeoutMs, dsmOperationTimeoutMs,
|
|
10
|
+
import { dsmRequestTimeoutMs, dsmOperationTimeoutMs, dsmUninstallTimeoutMs, dsmPollIntervalMs, isHostTimeout } from '../nas/timeouts.js';
|
|
9
11
|
function normalizeDeppkgs(deppkgs) {
|
|
10
12
|
if (typeof deppkgs === "string") {
|
|
11
13
|
const match = /^([^><=]+)(>=|>|<=|<|==)(.+)$/.exec(deppkgs.trim());
|
|
@@ -29,6 +31,7 @@ async function dsmWebApi(dsmOrigin, cookieHeader, params, options = {}) {
|
|
|
29
31
|
const query = new URLSearchParams(params);
|
|
30
32
|
const response = await dsmFetch(`${dsmOrigin}/webapi/entry.cgi?${query.toString()}`, {
|
|
31
33
|
headers: { cookie: cookieHeader },
|
|
34
|
+
signal: options.signal,
|
|
32
35
|
}, options.timeoutMs);
|
|
33
36
|
const body = (await response.json());
|
|
34
37
|
const errorCode = body.error?.code;
|
|
@@ -79,6 +82,15 @@ export function packageStateFromRecord(value) {
|
|
|
79
82
|
const state = {
|
|
80
83
|
installed: Boolean(installedPath) || match.installed === true,
|
|
81
84
|
};
|
|
85
|
+
const transition = status?.toLowerCase();
|
|
86
|
+
if (transition === 'installing' || transition === 'upgrading' || transition === 'starting') {
|
|
87
|
+
state.state = transition;
|
|
88
|
+
// DSM can remove installed_info while replacing the payload.
|
|
89
|
+
state.installed = state.installed || transition === 'upgrading' ? true : null;
|
|
90
|
+
const target = stringValue(record(additional.installing_target).version);
|
|
91
|
+
if (target)
|
|
92
|
+
state.toVersion = target;
|
|
93
|
+
}
|
|
82
94
|
if (version !== undefined)
|
|
83
95
|
state.version = version;
|
|
84
96
|
if (status !== undefined)
|
|
@@ -115,16 +127,58 @@ export function packageStateFromListPayload(payload, packageId) {
|
|
|
115
127
|
}
|
|
116
128
|
return packageStateFromRecord(match);
|
|
117
129
|
}
|
|
118
|
-
export async function fetchInstalledPackageState(dsmOrigin, cookieHeader, packageId, timeoutMs) {
|
|
130
|
+
export async function fetchInstalledPackageState(dsmOrigin, cookieHeader, packageId, timeoutMs, context = {}) {
|
|
119
131
|
try {
|
|
120
132
|
const body = await dsmWebApi(dsmOrigin, cookieHeader, {
|
|
121
133
|
api: "SYNO.Core.Package",
|
|
122
134
|
version: "2",
|
|
123
135
|
method: "list",
|
|
124
|
-
additional: JSON.stringify(["status", "installed_info"]),
|
|
136
|
+
additional: JSON.stringify(["status", "installed_info", "installing_target"]),
|
|
125
137
|
ignore_hidden: "false",
|
|
126
|
-
}, { timeoutMs });
|
|
127
|
-
|
|
138
|
+
}, { timeoutMs, signal: context.signal });
|
|
139
|
+
if (!Array.isArray(record(body.data).packages))
|
|
140
|
+
return undefined;
|
|
141
|
+
let state = packageStateFromListPayload(body, packageId);
|
|
142
|
+
const operation = context.ignoreOperation ? undefined : readPackageOperation(dsmOrigin, packageId);
|
|
143
|
+
if (operation && state.installed && state.version === operation.toVersion && /^(run|running)$/i.test(state.status ?? '') &&
|
|
144
|
+
operation.fromVersion !== operation.toVersion)
|
|
145
|
+
return state;
|
|
146
|
+
if (!state.installed && !state.state) {
|
|
147
|
+
// An independent DSM view can retain a transition while list temporarily omits the package.
|
|
148
|
+
const statuses = await dsmWebApi(dsmOrigin, cookieHeader, {
|
|
149
|
+
api: 'SYNO.Core.Package', method: 'list_status', version: '1',
|
|
150
|
+
}, { timeoutMs, signal: context.signal });
|
|
151
|
+
if (!Array.isArray(record(statuses.data).packages))
|
|
152
|
+
return undefined;
|
|
153
|
+
const entry = record(statuses.data).packages.map(record).find(item => item.id === packageId);
|
|
154
|
+
if (entry) {
|
|
155
|
+
state = packageStateFromRecord(entry);
|
|
156
|
+
if (!state.state)
|
|
157
|
+
state.installed = true;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (operation && !state.state && !(state.installed && packageFailure(state))) {
|
|
161
|
+
const task = await dsmWebApi(dsmOrigin, cookieHeader, {
|
|
162
|
+
api: 'SYNO.Core.Package.Installation', method: 'status', version: '1', task_id: jsonApiParam(operation.taskId),
|
|
163
|
+
}, { timeoutMs, signal: context.signal, allowFailure: true });
|
|
164
|
+
const data = record(task.data);
|
|
165
|
+
const active = task.success === true && data.id === packageId &&
|
|
166
|
+
(/^(installing|upgrading|starting)$/i.test(String(data.status ?? '')) || data.installing === true);
|
|
167
|
+
if (active || operationOwnerAlive(operation))
|
|
168
|
+
return {
|
|
169
|
+
...state, installed: operation.operation === 'upgrading' ? true : null,
|
|
170
|
+
state: operation.operation, status: operation.operation,
|
|
171
|
+
fromVersion: operation.fromVersion, toVersion: operation.toVersion,
|
|
172
|
+
};
|
|
173
|
+
if (state.installed === false)
|
|
174
|
+
return { ...state, installed: null, state: 'unknown',
|
|
175
|
+
fromVersion: operation.fromVersion, toVersion: operation.toVersion };
|
|
176
|
+
}
|
|
177
|
+
if (operation && state.state)
|
|
178
|
+
return { ...state,
|
|
179
|
+
installed: operation.operation === 'upgrading' ? true : state.installed,
|
|
180
|
+
fromVersion: operation.fromVersion, toVersion: operation.toVersion };
|
|
181
|
+
return state;
|
|
128
182
|
}
|
|
129
183
|
catch (error) {
|
|
130
184
|
if (error instanceof CtlError)
|
|
@@ -155,13 +209,16 @@ function installBudgetExpired(options) {
|
|
|
155
209
|
return new CtlError('DSM_INSTALL_TIMEOUT', `Timed out waiting for ${options.packageId}${target}: overall install budget exhausted; DSM may still be installing/starting.`, 'Check Package Center state before retrying; the install was not replayed');
|
|
156
210
|
}
|
|
157
211
|
export async function waitForInstalledVersion(readState, options) {
|
|
158
|
-
|
|
212
|
+
// Only an explicitly supplied caller deadline constrains elapsed time.
|
|
213
|
+
const deadline = options.deadlineMs === undefined ? Infinity : Date.now() + options.deadlineMs;
|
|
214
|
+
const consumePoll = options.consumePoll ?? installWorkload(options.packageId, options.maxPolls);
|
|
159
215
|
const pollMs = options.pollMs ?? dsmPollIntervalMs();
|
|
160
216
|
let transitioned = !options.requireTransition;
|
|
161
217
|
while (Date.now() < deadline) {
|
|
218
|
+
consumePoll();
|
|
162
219
|
let state;
|
|
163
220
|
try {
|
|
164
|
-
state = await readState(Math.max(1, deadline - Date.now()));
|
|
221
|
+
state = await cancelableInstall(() => Promise.resolve(readState(Math.min(dsmRequestTimeoutMs(), Math.max(1, deadline - Date.now())))), options.signal);
|
|
165
222
|
}
|
|
166
223
|
catch (error) {
|
|
167
224
|
if (!isHostTimeout(error))
|
|
@@ -180,9 +237,9 @@ export async function waitForInstalledVersion(readState, options) {
|
|
|
180
237
|
if (state?.installed && !/installing|upgrading|starting/i.test(state.status ?? '') &&
|
|
181
238
|
(!options.expectedVersion || state.version === options.expectedVersion) &&
|
|
182
239
|
(!options.requireRunning || running) && transitioned)
|
|
183
|
-
return;
|
|
240
|
+
return state;
|
|
184
241
|
options.onProgress?.(`${options.packageId}: installing/starting… (DSM status ${state?.status ?? 'unavailable'})`);
|
|
185
|
-
await
|
|
242
|
+
await installDelay(Math.min(pollMs, Math.max(0, deadline - Date.now())), options.signal);
|
|
186
243
|
}
|
|
187
244
|
throw installBudgetExpired(options);
|
|
188
245
|
}
|
|
@@ -251,7 +308,9 @@ export async function uninstallPackageFromDsm(options) {
|
|
|
251
308
|
}
|
|
252
309
|
};
|
|
253
310
|
const before = await wait(() => true);
|
|
254
|
-
if (
|
|
311
|
+
if (before.state || before.installed === null)
|
|
312
|
+
throw new CtlError('PACKAGE_BUSY', `Package ${options.packageId} has an unresolved operation`, 'Wait for DSM to finish before uninstalling');
|
|
313
|
+
if (before.installed === false)
|
|
255
314
|
return;
|
|
256
315
|
const broken = packageFailure(before) && !installInProgress(before);
|
|
257
316
|
if (broken) {
|
|
@@ -261,13 +320,13 @@ export async function uninstallPackageFromDsm(options) {
|
|
|
261
320
|
if (!broken && !packageStatusIsStopped(before)) {
|
|
262
321
|
phase = 'stopping';
|
|
263
322
|
await dispatch('SYNO.Core.Package.Control', 'stop');
|
|
264
|
-
const stopped = await wait(state =>
|
|
265
|
-
if (
|
|
323
|
+
const stopped = await wait(state => state.installed === false || packageStatusIsStopped(state));
|
|
324
|
+
if (stopped.installed === false)
|
|
266
325
|
return;
|
|
267
326
|
}
|
|
268
327
|
phase = 'uninstalling';
|
|
269
328
|
await dispatch('SYNO.Core.Package.Uninstallation', 'uninstall');
|
|
270
|
-
await wait(state =>
|
|
329
|
+
await wait(state => state.installed === false);
|
|
271
330
|
}
|
|
272
331
|
catch (error) {
|
|
273
332
|
throw uninstallFailure(options.packageId, error);
|
|
@@ -368,6 +427,7 @@ async function uploadLocalSpk(options, sid, timeoutMs) {
|
|
|
368
427
|
method: "POST",
|
|
369
428
|
headers: { cookie: options.cookieHeader },
|
|
370
429
|
body: form,
|
|
430
|
+
signal: options.signal,
|
|
371
431
|
}, timeoutMs);
|
|
372
432
|
const body = (await uploadResponse.json());
|
|
373
433
|
if (!body.success || !body.data?.id || !body.data.task_id) {
|
|
@@ -376,24 +436,35 @@ async function uploadLocalSpk(options, sid, timeoutMs) {
|
|
|
376
436
|
return { id: body.data.id, taskId: body.data.task_id };
|
|
377
437
|
}
|
|
378
438
|
export async function installPackageFromLocalSpk(options) {
|
|
379
|
-
|
|
380
|
-
const
|
|
439
|
+
const deadline = options.deadlineMs === undefined ? Infinity : Date.now() + options.deadlineMs;
|
|
440
|
+
const consumePoll = installWorkload(options.packageId, options.maxPolls);
|
|
441
|
+
const controller = new AbortController();
|
|
442
|
+
const cancel = () => controller.abort();
|
|
443
|
+
const signal = options.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal;
|
|
444
|
+
options = { ...options, signal };
|
|
445
|
+
let operation;
|
|
446
|
+
let verified = false;
|
|
381
447
|
const requestMs = dsmRequestTimeoutMs(), operationMs = dsmOperationTimeoutMs();
|
|
382
448
|
const pollMs = options.pollMs ?? dsmPollIntervalMs();
|
|
383
449
|
const progress = options.onProgress ?? (message => process.stderr.write(`${terminalSafe(message)}\n`));
|
|
384
450
|
let phase = 'checking package state';
|
|
385
451
|
const remaining = (limit) => {
|
|
452
|
+
if (signal.aborted)
|
|
453
|
+
throw installCanceled();
|
|
386
454
|
if (Date.now() >= deadline)
|
|
387
455
|
throw installBudgetExpired(options);
|
|
388
456
|
return Math.min(limit, deadline - Date.now());
|
|
389
457
|
};
|
|
390
458
|
const heartbeat = setInterval(() => progress(`${options.packageId}: ${phase}…`), pollMs);
|
|
459
|
+
process.once('SIGINT', cancel);
|
|
460
|
+
process.once('SIGTERM', cancel);
|
|
391
461
|
try {
|
|
392
462
|
const sid = extractSid(options.cookieHeader);
|
|
393
463
|
let before;
|
|
394
464
|
while (!before) {
|
|
465
|
+
consumePoll();
|
|
395
466
|
try {
|
|
396
|
-
before = await fetchInstalledPackageState(options.dsmOrigin, options.cookieHeader, options.packageId, remaining(requestMs));
|
|
467
|
+
before = await cancelableInstall(() => fetchInstalledPackageState(options.dsmOrigin, options.cookieHeader, options.packageId, remaining(requestMs), { signal }), signal);
|
|
397
468
|
}
|
|
398
469
|
catch (error) {
|
|
399
470
|
if (!isHostTimeout(error))
|
|
@@ -401,14 +472,16 @@ export async function installPackageFromLocalSpk(options) {
|
|
|
401
472
|
}
|
|
402
473
|
if (!before) {
|
|
403
474
|
progress(`${options.packageId}: waiting for DSM package state…`);
|
|
404
|
-
await
|
|
475
|
+
await installDelay(Math.min(pollMs, remaining(requestMs)), signal);
|
|
405
476
|
}
|
|
406
477
|
}
|
|
478
|
+
if (before.state || before.installed === null)
|
|
479
|
+
throw new CtlError('PACKAGE_BUSY', `Package ${options.packageId} already has an unresolved operation`, 'Check package status before installing again');
|
|
407
480
|
if (options.containerImages?.length) {
|
|
408
481
|
phase = 'pulling container images';
|
|
409
482
|
try {
|
|
410
483
|
await pullContainerImages({ ...options, images: options.containerImages,
|
|
411
|
-
deadlineMs: remaining(Number.MAX_SAFE_INTEGER), pollMs, onProgress: progress });
|
|
484
|
+
deadlineMs: Number.isFinite(deadline) ? remaining(Number.MAX_SAFE_INTEGER) : undefined, consumePoll, signal, pollMs, onProgress: progress });
|
|
412
485
|
savePullFailure(options.dsmOrigin, options.packageId);
|
|
413
486
|
}
|
|
414
487
|
catch (error) {
|
|
@@ -418,16 +491,18 @@ export async function installPackageFromLocalSpk(options) {
|
|
|
418
491
|
}
|
|
419
492
|
phase = 'uploading';
|
|
420
493
|
progress(`${options.packageId}: uploading…`);
|
|
421
|
-
const uploaded = await uploadLocalSpk(options, sid, remaining(operationMs));
|
|
494
|
+
const uploaded = await cancelableInstall(() => uploadLocalSpk(options, sid, remaining(operationMs)), signal);
|
|
422
495
|
const compound = JSON.stringify(catalogCompoundSteps(uploaded, { version: options.version, size: readFileSync(options.spkPath).byteLength }, { blupgrade: before.installed, extraValues: options.extraValues }));
|
|
423
|
-
phase = 'installing
|
|
496
|
+
phase = before.installed ? 'upgrading' : 'installing';
|
|
497
|
+
operation = savePackageOperation(options.dsmOrigin, options.packageId, { taskId: uploaded.taskId,
|
|
498
|
+
operation: before.installed ? 'upgrading' : 'installing', fromVersion: before.installed ? before.version : undefined, toVersion: options.version });
|
|
424
499
|
progress(`${options.packageId}: ${phase}…`);
|
|
425
500
|
let timedOut = false;
|
|
426
501
|
try {
|
|
427
|
-
const response = await dsmWebApi(options.dsmOrigin, options.cookieHeader, {
|
|
502
|
+
const response = await cancelableInstall(() => dsmWebApi(options.dsmOrigin, options.cookieHeader, {
|
|
428
503
|
api: 'SYNO.Entry.Request', version: '1', method: 'request', stop_when_error: 'true',
|
|
429
504
|
mode: jsonApiParam('sequential'), compound, _sid: sid,
|
|
430
|
-
}, { allowFailure: true, timeoutMs: remaining(operationMs) });
|
|
505
|
+
}, { allowFailure: true, timeoutMs: remaining(operationMs), signal }), signal);
|
|
431
506
|
assertDsmCompoundResponse(response);
|
|
432
507
|
}
|
|
433
508
|
catch (error) {
|
|
@@ -436,13 +511,18 @@ export async function installPackageFromLocalSpk(options) {
|
|
|
436
511
|
timedOut = true;
|
|
437
512
|
progress(`${options.packageId}: install/upgrade request timed out; DSM may still be installing/starting; checking state…`);
|
|
438
513
|
}
|
|
439
|
-
await waitForInstalledVersion(budget => fetchInstalledPackageState(options.dsmOrigin, options.cookieHeader, options.packageId, Math.min(requestMs, budget)), { packageId: options.packageId, expectedVersion: options.version,
|
|
440
|
-
deadlineMs: remaining(Number.MAX_SAFE_INTEGER), pollMs, requireRunning: true,
|
|
514
|
+
const completed = await waitForInstalledVersion(budget => fetchInstalledPackageState(options.dsmOrigin, options.cookieHeader, options.packageId, Math.min(requestMs, budget), { signal, ignoreOperation: true }), { packageId: options.packageId, expectedVersion: options.version,
|
|
515
|
+
deadlineMs: Number.isFinite(deadline) ? remaining(Number.MAX_SAFE_INTEGER) : undefined, pollMs, requireRunning: true, consumePoll, signal,
|
|
441
516
|
// A lost same-version reinstall reply must not accept the old running instance.
|
|
442
|
-
requireTransition: timedOut && before.installed && before.version === options.version,
|
|
517
|
+
requireTransition: timedOut && before.installed === true && before.version === options.version,
|
|
443
518
|
onProgress: progress });
|
|
519
|
+
verified = true;
|
|
520
|
+
progress(`${options.packageId}: ${phase} complete (${completed.version}, DSM status ${completed.status})`);
|
|
521
|
+
return completed;
|
|
444
522
|
}
|
|
445
523
|
catch (error) {
|
|
524
|
+
if (signal.aborted)
|
|
525
|
+
throw installCanceled();
|
|
446
526
|
if (isHostTimeout(error)) {
|
|
447
527
|
if (Date.now() >= deadline)
|
|
448
528
|
throw installBudgetExpired(options);
|
|
@@ -452,5 +532,13 @@ export async function installPackageFromLocalSpk(options) {
|
|
|
452
532
|
}
|
|
453
533
|
finally {
|
|
454
534
|
clearInterval(heartbeat);
|
|
535
|
+
process.removeListener('SIGINT', cancel);
|
|
536
|
+
process.removeListener('SIGTERM', cancel);
|
|
537
|
+
if (operation) {
|
|
538
|
+
if (verified)
|
|
539
|
+
clearPackageOperation(options.dsmOrigin, options.packageId, operation);
|
|
540
|
+
else
|
|
541
|
+
releasePackageOperation(options.dsmOrigin, options.packageId, operation);
|
|
542
|
+
}
|
|
455
543
|
}
|
|
456
544
|
}
|
|
@@ -12,6 +12,8 @@ interface PullOptions {
|
|
|
12
12
|
stallMs?: number;
|
|
13
13
|
pollMs?: number;
|
|
14
14
|
onProgress?: (message: string) => void;
|
|
15
|
+
consumePoll?: () => void;
|
|
16
|
+
signal?: AbortSignal;
|
|
15
17
|
}
|
|
16
18
|
/** Pull on the NAS, before Package Center can turn a registry failure into broken/150. */
|
|
17
19
|
export declare function pullContainerImages(options: PullOptions): Promise<void>;
|
|
@@ -3,8 +3,9 @@ import { parseImageReference } from '../images/pin.js';
|
|
|
3
3
|
import { registryBaseUrl } from '../compose/registry-mirrors.js';
|
|
4
4
|
import { terminalSafe } from '../terminal-text.js';
|
|
5
5
|
import { maskDiagnostic } from './package-diagnostics.js';
|
|
6
|
+
import { installWorkload, installCanceled, installDelay } from './install-control.js';
|
|
6
7
|
import { dsmFetch } from './dsm-http.js';
|
|
7
|
-
import { dsmRequestTimeoutMs,
|
|
8
|
+
import { dsmRequestTimeoutMs, dsmPollIntervalMs, dsmPullStallTimeoutMs, isHostTimeout } from '../nas/timeouts.js';
|
|
8
9
|
/** Use inspected effective references: these include the lock's digest and mirror. */
|
|
9
10
|
export function containerImageReferences(report) {
|
|
10
11
|
return [...new Set((report.compose?.images ?? []).map(value => {
|
|
@@ -18,7 +19,8 @@ const hint = 'Configure a reachable registry mirror, trust the inspecting CA in
|
|
|
18
19
|
const causePattern = /error|fail|denied|forbidden|unauthorized|x509|certificate|tls|timeout|timed out|refused|no such host|not found|too many requests|429|403|unexpected.*status/i;
|
|
19
20
|
/** Pull on the NAS, before Package Center can turn a registry failure into broken/150. */
|
|
20
21
|
export async function pullContainerImages(options) {
|
|
21
|
-
const deadline = Date.now() +
|
|
22
|
+
const deadline = options.deadlineMs === undefined ? Infinity : Date.now() + options.deadlineMs;
|
|
23
|
+
const consumePoll = options.consumePoll ?? installWorkload('container image pull');
|
|
22
24
|
const stallMs = options.stallMs ?? dsmPullStallTimeoutMs();
|
|
23
25
|
const pollMs = options.pollMs ?? dsmPollIntervalMs();
|
|
24
26
|
const progress = options.onProgress ?? (line => process.stderr.write(`${terminalSafe(line)}\n`));
|
|
@@ -32,6 +34,8 @@ export async function pullContainerImages(options) {
|
|
|
32
34
|
const fail = (code, detail) => new CtlError(code, maskDiagnostic(`${context}: ${detail}`), hint);
|
|
33
35
|
let lastAdvance = Date.now(), downloaded = -1;
|
|
34
36
|
const remaining = () => {
|
|
37
|
+
if (options.signal?.aborted)
|
|
38
|
+
throw installCanceled();
|
|
35
39
|
if (Date.now() >= deadline)
|
|
36
40
|
throw fail('CONTAINER_PULL_TIMEOUT', 'overall install/pull budget exhausted; NAS pull outcome may still be pending');
|
|
37
41
|
if (Date.now() - lastAdvance >= stallMs)
|
|
@@ -41,6 +45,7 @@ export async function pullContainerImages(options) {
|
|
|
41
45
|
const call = async (method, params) => {
|
|
42
46
|
const response = await dsmFetch(`${options.dsmOrigin}/webapi/entry.cgi`, {
|
|
43
47
|
method: 'POST', headers: { cookie: options.cookieHeader, 'content-type': 'application/x-www-form-urlencoded' },
|
|
48
|
+
signal: options.signal,
|
|
44
49
|
body: new URLSearchParams({ api: 'SYNO.Docker.Image', version: '1', method, ...params }),
|
|
45
50
|
}, remaining());
|
|
46
51
|
const body = await response.json();
|
|
@@ -81,6 +86,7 @@ export async function pullContainerImages(options) {
|
|
|
81
86
|
lastAdvance = Date.now();
|
|
82
87
|
while (true) {
|
|
83
88
|
remaining();
|
|
89
|
+
consumePoll();
|
|
84
90
|
let state;
|
|
85
91
|
try {
|
|
86
92
|
state = await call('pull_status', { task_id: task.task_id });
|
|
@@ -105,11 +111,11 @@ export async function pullContainerImages(options) {
|
|
|
105
111
|
if (state.finished)
|
|
106
112
|
break;
|
|
107
113
|
}
|
|
108
|
-
await
|
|
114
|
+
await installDelay(Math.min(pollMs, remaining()), options.signal);
|
|
109
115
|
}
|
|
110
116
|
}
|
|
111
117
|
catch (error) {
|
|
112
|
-
if (error instanceof CtlError && error.code.startsWith('CONTAINER_PULL_'))
|
|
118
|
+
if (error instanceof CtlError && (error.code.startsWith('CONTAINER_PULL_') || error.code.startsWith('DSM_INSTALL_')))
|
|
113
119
|
throw error;
|
|
114
120
|
throw fail('CONTAINER_PULL_FAILED', `NAS image pull failed: ${error instanceof Error ? error.message : 'unknown transport error'}`);
|
|
115
121
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CtlError } from '../ctl/errors.js';
|
|
2
|
+
export declare function installCanceled(): CtlError;
|
|
3
|
+
export declare function cancelableInstall<T>(work: () => Promise<T>, signal?: AbortSignal): Promise<T>;
|
|
4
|
+
export declare function installDelay(ms: number, signal?: AbortSignal): Promise<void>;
|
|
5
|
+
export declare function installPollLimit(): number;
|
|
6
|
+
export declare function installWorkload(packageId: string, maximum?: number): () => void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
|
+
import { CtlError } from '../ctl/errors.js';
|
|
3
|
+
export function installCanceled() {
|
|
4
|
+
return new CtlError('DSM_INSTALL_CANCELED', 'Stopped waiting for DSM; the package operation may still be running.', 'Check package status before retrying; the write was not replayed', 130);
|
|
5
|
+
}
|
|
6
|
+
export async function cancelableInstall(work, signal) {
|
|
7
|
+
if (signal?.aborted)
|
|
8
|
+
throw installCanceled();
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
const abort = () => { signal?.removeEventListener('abort', abort); reject(installCanceled()); };
|
|
11
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
12
|
+
Promise.resolve().then(() => { if (signal?.aborted)
|
|
13
|
+
throw installCanceled(); return work(); }).then(value => { signal?.removeEventListener('abort', abort); resolve(value); }, error => { signal?.removeEventListener('abort', abort); reject(error); });
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export async function installDelay(ms, signal) {
|
|
17
|
+
try {
|
|
18
|
+
await delay(ms, undefined, { signal });
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
throw installCanceled();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function installPollLimit() {
|
|
25
|
+
const raw = process.env.DSM_INSTALL_MAX_POLLS ?? '10000';
|
|
26
|
+
const value = Number(raw);
|
|
27
|
+
if (!/^\d+$/.test(raw) || !Number.isSafeInteger(value) || value < 1 || value > 1000000)
|
|
28
|
+
throw new CtlError('DSM_INSTALL_LIMIT_INVALID', 'DSM_INSTALL_MAX_POLLS must be an integer from 1 to 1000000', 'Set a positive poll limit');
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
export function installWorkload(packageId, maximum = installPollLimit()) {
|
|
32
|
+
if (!Number.isSafeInteger(maximum) || maximum < 1)
|
|
33
|
+
throw new Error('Invalid install poll limit');
|
|
34
|
+
let polls = 0;
|
|
35
|
+
return () => {
|
|
36
|
+
if (++polls > maximum)
|
|
37
|
+
throw new CtlError('DSM_INSTALL_LIMIT', `Package ${packageId}: install status query limit reached; DSM may still be working.`, 'Check package status before retrying; no mutation was replayed');
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -71,7 +71,10 @@ export declare function uninstallPackage(id: string, options?: {
|
|
|
71
71
|
action?: undefined;
|
|
72
72
|
}>;
|
|
73
73
|
export declare function packageStatus(id: string, host?: string): Promise<{
|
|
74
|
-
installed: boolean;
|
|
74
|
+
installed: boolean | null;
|
|
75
|
+
state?: "installing" | "upgrading" | "starting" | "unknown";
|
|
76
|
+
fromVersion?: string;
|
|
77
|
+
toVersion?: string;
|
|
75
78
|
version?: string;
|
|
76
79
|
status?: string;
|
|
77
80
|
error?: {
|
|
@@ -174,8 +174,9 @@ export async function installPackage(spec, options = {}, connection) {
|
|
|
174
174
|
files.set(entry.package, file);
|
|
175
175
|
images.set(entry.package, containerImageReferences(checked));
|
|
176
176
|
}
|
|
177
|
-
|
|
178
|
-
|
|
177
|
+
let completed;
|
|
178
|
+
for (const entry of changes) {
|
|
179
|
+
const state = await installPackageFromLocalSpk({
|
|
179
180
|
dsmOrigin: nas.session.origin,
|
|
180
181
|
cookieHeader: nas.session.cookie,
|
|
181
182
|
packageId: entry.package,
|
|
@@ -184,9 +185,12 @@ export async function installPackage(spec, options = {}, connection) {
|
|
|
184
185
|
containerImages: images.get(entry.package),
|
|
185
186
|
extraValues: entry.package === root.package ? options.param : undefined,
|
|
186
187
|
});
|
|
188
|
+
if (entry.package === root.package)
|
|
189
|
+
completed = state;
|
|
190
|
+
}
|
|
187
191
|
return {
|
|
188
192
|
...publicPlan,
|
|
189
|
-
status: await fetchInstalledPackageState(nas.session.origin, nas.session.cookie, root.package),
|
|
193
|
+
status: completed ?? await fetchInstalledPackageState(nas.session.origin, nas.session.cookie, root.package),
|
|
190
194
|
};
|
|
191
195
|
}
|
|
192
196
|
finally {
|
|
@@ -197,6 +201,8 @@ export async function uninstallPackage(id, options = {}) {
|
|
|
197
201
|
packageId(id);
|
|
198
202
|
const nas = await connectNas(options.host);
|
|
199
203
|
const state = await fetchInstalledPackageState(nas.session.origin, nas.session.cookie, id);
|
|
204
|
+
if (state?.state || state?.installed === null)
|
|
205
|
+
throw fail('PACKAGE_BUSY', `Package ${id} has an unresolved operation`);
|
|
200
206
|
if (!state?.installed)
|
|
201
207
|
throw fail("PACKAGE_NOT_INSTALLED", `Package ${id} is not installed`);
|
|
202
208
|
if (options.dryRun)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Shared by concurrent CLI processes; never contains DSM credentials or wizard input. */
|
|
2
|
+
export interface PackageOperation {
|
|
3
|
+
token: string;
|
|
4
|
+
pid: number;
|
|
5
|
+
taskId: string;
|
|
6
|
+
operation: 'installing' | 'upgrading';
|
|
7
|
+
fromVersion?: string;
|
|
8
|
+
toVersion: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function readPackageOperation(origin: string, id: string): PackageOperation | undefined;
|
|
11
|
+
export declare function operationOwnerAlive(operation: PackageOperation): boolean;
|
|
12
|
+
/** Preserve uncertain work after cancellation/transport loss, without claiming a live waiter. */
|
|
13
|
+
export declare function releasePackageOperation(origin: string, id: string, operation: PackageOperation): void;
|
|
14
|
+
export declare function savePackageOperation(origin: string, id: string, input: Omit<PackageOperation, 'token' | 'pid'>): PackageOperation;
|
|
15
|
+
export declare function clearPackageOperation(origin: string, id: string, operation: PackageOperation): void;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdirSync, readFileSync, writeFileSync, renameSync, rmSync } from 'node:fs';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { join, dirname } from 'node:path';
|
|
5
|
+
function pathFor(origin, id) {
|
|
6
|
+
const key = createHash('sha256').update(new URL(origin).origin + '\0' + id).digest('hex');
|
|
7
|
+
return join(process.env.SYNOPKGLAND_OPERATIONS_DIR ?? join(homedir(), '.cache/synopkgland/operations'), key + '.json');
|
|
8
|
+
}
|
|
9
|
+
export function readPackageOperation(origin, id) {
|
|
10
|
+
try {
|
|
11
|
+
const value = JSON.parse(readFileSync(pathFor(origin, id), 'utf8'));
|
|
12
|
+
if (typeof value.token === 'string' && Number.isInteger(value.pid) && value.pid >= 0 &&
|
|
13
|
+
typeof value.taskId === 'string' && typeof value.toVersion === 'string' &&
|
|
14
|
+
['installing', 'upgrading'].includes(value.operation) &&
|
|
15
|
+
(value.fromVersion === undefined || typeof value.fromVersion === 'string'))
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
catch { /* No retained operation. */ }
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
export function operationOwnerAlive(operation) {
|
|
22
|
+
if (!operation.pid)
|
|
23
|
+
return false;
|
|
24
|
+
try {
|
|
25
|
+
process.kill(operation.pid, 0);
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Preserve uncertain work after cancellation/transport loss, without claiming a live waiter. */
|
|
33
|
+
export function releasePackageOperation(origin, id, operation) {
|
|
34
|
+
if (readPackageOperation(origin, id)?.token !== operation.token)
|
|
35
|
+
return;
|
|
36
|
+
const file = pathFor(origin, id), temporary = `${file}.${operation.token}.tmp`;
|
|
37
|
+
writeFileSync(temporary, JSON.stringify({ ...operation, pid: 0 }), { mode: 0o600 });
|
|
38
|
+
renameSync(temporary, file);
|
|
39
|
+
}
|
|
40
|
+
export function savePackageOperation(origin, id, input) {
|
|
41
|
+
const operation = { ...input, token: randomUUID(), pid: process.pid };
|
|
42
|
+
const file = pathFor(origin, id);
|
|
43
|
+
mkdirSync(dirname(file), { recursive: true, mode: 0o700 });
|
|
44
|
+
const temporary = `${file}.${operation.token}.tmp`;
|
|
45
|
+
writeFileSync(temporary, JSON.stringify(operation), { mode: 0o600 });
|
|
46
|
+
renameSync(temporary, file);
|
|
47
|
+
return operation;
|
|
48
|
+
}
|
|
49
|
+
export function clearPackageOperation(origin, id, operation) {
|
|
50
|
+
if (readPackageOperation(origin, id)?.token === operation.token)
|
|
51
|
+
rmSync(pathFor(origin, id), { force: true });
|
|
52
|
+
}
|
package/dist/nas/timeouts.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const dsmRequestTimeoutMs: () => number;
|
|
2
2
|
export declare const dsmOperationTimeoutMs: () => number;
|
|
3
3
|
export declare const dsmUninstallTimeoutMs: () => number;
|
|
4
|
+
/** @deprecated Install waiting now uses a workload limit and cancellation. */
|
|
4
5
|
export declare const dsmInstallTimeoutMs: () => number;
|
|
5
6
|
export declare const dsmPollIntervalMs: () => number;
|
|
6
7
|
export declare const dsmPullStallTimeoutMs: () => number;
|
package/dist/nas/timeouts.js
CHANGED
|
@@ -11,6 +11,7 @@ function seconds(name, fallback) {
|
|
|
11
11
|
export const dsmRequestTimeoutMs = () => seconds('DSM_REQUEST_TIMEOUT_SECONDS', 180);
|
|
12
12
|
export const dsmOperationTimeoutMs = () => seconds('DSM_OPERATION_TIMEOUT_SECONDS', 600);
|
|
13
13
|
export const dsmUninstallTimeoutMs = () => seconds('DSM_UNINSTALL_TIMEOUT_SECONDS', 1800);
|
|
14
|
+
/** @deprecated Install waiting now uses a workload limit and cancellation. */
|
|
14
15
|
export const dsmInstallTimeoutMs = () => seconds('DSM_INSTALL_TIMEOUT_SECONDS', 1800);
|
|
15
16
|
export const dsmPollIntervalMs = () => seconds('DSM_POLL_INTERVAL_SECONDS', 5);
|
|
16
17
|
export const dsmPullStallTimeoutMs = () => seconds('DSM_IMAGE_PULL_STALL_TIMEOUT_SECONDS', 1200);
|
package/package.json
CHANGED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://synopkgland.com/schema/package-state.schema.json",
|
|
4
|
+
"title": "DSM package state",
|
|
5
|
+
"description": "The data of status <package-id> --json, or the status field of install --json. installed:null means the installed payload cannot currently be verified.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": [
|
|
8
|
+
"installed"
|
|
9
|
+
],
|
|
10
|
+
"properties": {
|
|
11
|
+
"installed": {
|
|
12
|
+
"type": [
|
|
13
|
+
"boolean",
|
|
14
|
+
"null"
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"state": {
|
|
18
|
+
"enum": [
|
|
19
|
+
"installing",
|
|
20
|
+
"upgrading",
|
|
21
|
+
"starting",
|
|
22
|
+
"unknown"
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
"status": {
|
|
26
|
+
"type": "string",
|
|
27
|
+
"description": "Raw DSM status, or the retained CLI operation when DSM temporarily omits the package."
|
|
28
|
+
},
|
|
29
|
+
"version": {
|
|
30
|
+
"type": "string",
|
|
31
|
+
"description": "Version reported by DSM; may change during replacement."
|
|
32
|
+
},
|
|
33
|
+
"fromVersion": {
|
|
34
|
+
"type": "string",
|
|
35
|
+
"description": "Previously installed version, only when known."
|
|
36
|
+
},
|
|
37
|
+
"toVersion": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"description": "Requested target version, only when known."
|
|
40
|
+
},
|
|
41
|
+
"host": {
|
|
42
|
+
"type": "string"
|
|
43
|
+
},
|
|
44
|
+
"package": {
|
|
45
|
+
"type": "string"
|
|
46
|
+
},
|
|
47
|
+
"error": {
|
|
48
|
+
"type": "object"
|
|
49
|
+
},
|
|
50
|
+
"statusCode": {
|
|
51
|
+
"type": "number"
|
|
52
|
+
},
|
|
53
|
+
"statusDescription": {
|
|
54
|
+
"type": "string"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"allOf": [
|
|
58
|
+
{
|
|
59
|
+
"if": {
|
|
60
|
+
"required": [
|
|
61
|
+
"state"
|
|
62
|
+
],
|
|
63
|
+
"properties": {
|
|
64
|
+
"state": {
|
|
65
|
+
"enum": [
|
|
66
|
+
"installing",
|
|
67
|
+
"upgrading",
|
|
68
|
+
"starting"
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"then": {
|
|
74
|
+
"properties": {
|
|
75
|
+
"installed": {
|
|
76
|
+
"enum": [
|
|
77
|
+
true,
|
|
78
|
+
null
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
],
|
|
85
|
+
"additionalProperties": true
|
|
86
|
+
}
|
package/skills/SKILL.md
CHANGED
|
@@ -21,6 +21,11 @@ keep the installed dependency tree and generated pins consistent.
|
|
|
21
21
|
|
|
22
22
|
For Apps with data folders or gateway listeners, read [reference/install.md](reference/install.md). Default to an App-named dedicated DSM data share and installer-selected ports. Existing-folder access, port number format/range and required HTTPS origins use localized wizard validation before Next; detected port conflicts are nonblocking inline warnings, and an unavailable DSM port inventory does not block installation; upgrades retain port selections.
|
|
23
23
|
|
|
24
|
+
For private native `<audio>` / `<video>` playback and seeking, read
|
|
25
|
+
[reference/media.md](reference/media.md). Use SDK session-bound media grants,
|
|
26
|
+
owner hooks and a stable renewable URL; do not put DSM tokens in media URLs or
|
|
27
|
+
change DSM CSP for Blob playback.
|
|
28
|
+
|
|
24
29
|
All CLI NAS requests share one connection path. NAS certificates are accepted by default, including self-signed, wrong-name and expired certificates. A changed certificate warns once, updates its displayed SHA-256 and continues. `host add --strict-tls` stores strict verification; `--strict-tls` or `--ca <file>` on a command opts in for that command. Read [reference/host-install.md](reference/host-install.md) for host trust and error codes.
|
|
25
30
|
|
|
26
31
|
Before releasing an executor App, read [reference/approval-upgrades.md](reference/approval-upgrades.md). Run build/inspect with the previous released SPK as `--baseline` and include the approval difference in release notes. Without a comparable baseline, retention is unknown.
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# 檔案與背景工作
|
|
2
2
|
|
|
3
|
+
App 私人錄音/影片的原生 `<audio>`/`<video>` 播放與 seek,使用 SDK 的短效
|
|
4
|
+
media grant;先讀 [media.md](media.md)。File Station 下載與原生 media 是不同傳輸,
|
|
5
|
+
不能將下載表單的 token URL 模式套在 App 私人媒體。
|
|
6
|
+
|
|
3
7
|
Native-go 的 B 能力使用 `init --with files` 或 `add files`,對應 schema 2 `capabilities.files: session`。File tree 與共用 NasPicker 以 TreeView/DataGrid 顯示本人可見內容;一般選取不建立授權;delegate destination 選取例外,確認即授權。FilePicker 選瀏覽器本機檔案。上傳/下載使用 streaming transport,不把內容放進 JSON。每次以呼叫者有效 DSM session 由 File Station 判權,不需管理員進行能力設定。
|
|
4
8
|
|
|
5
9
|
SDK 的 delegated `files.write` 逐檔上限為 100 MiB;`files.read` 與
|
|
@@ -64,3 +64,21 @@ fingerprint after confirmation. `host add --fingerprint <sha256>` checks an
|
|
|
64
64
|
explicit expected leaf during registration; it does not turn on strict mode.
|
|
65
65
|
No global TLS override is used. Public package feeds and downloads keep normal
|
|
66
66
|
HTTPS verification. Network errors distinguish DNS, refusal and timeout.
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
During replacement, `status <package-id> --json` returns `state: "upgrading"`,
|
|
70
|
+
`"installing"` or `"starting"` and known `fromVersion`/`toVersion` values. These
|
|
71
|
+
states never use `installed:false`; `installed:null` means payload presence cannot
|
|
72
|
+
currently be verified. Treat `state:"unknown"` after interrupted work as unresolved,
|
|
73
|
+
not as removal. Concurrent CLI processes using the same local user share the
|
|
74
|
+
private origin/package task record; other clients rely on DSM status evidence.
|
|
75
|
+
See `schema/package-state.schema.json` for the result contract.
|
|
76
|
+
|
|
77
|
+
Install/upgrade verification waits for the target version and running state. It
|
|
78
|
+
has no default wall-clock deadline. `DSM_INSTALL_MAX_POLLS` limits polling attempts
|
|
79
|
+
(default 10000, integer 1–1000000), including timed-out reads and pre-pull checks.
|
|
80
|
+
`DSM_INSTALL_TIMEOUT_SECONDS` no longer limits install/deploy waiting. Ctrl-C stops
|
|
81
|
+
waiting with `DSM_INSTALL_CANCELED` (exit 130); `DSM_INSTALL_LIMIT` means the query
|
|
82
|
+
limit was reached. Neither proves DSM failed, cancels its work, or permits replaying
|
|
83
|
+
a write. Check status first. Progress stays on stderr with `--json`; the final
|
|
84
|
+
install result contains the verified completion state.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# 原生私人音訊與影片
|
|
2
|
+
|
|
3
|
+
私人錄音/影片要使用原生 `<audio>`/`<video>` 時,採用 SDK Go `media`
|
|
4
|
+
service 與前端 `mediaUrl(ctx, {asset})`。完整接線與安全契約見
|
|
5
|
+
[SDK media 文件](https://github.com/synopackageland/syno-pkg-land-sdk/blob/main/docs/media.md)。
|
|
6
|
+
先確認專案解析到的 SDK 確實匯出這些 API,再更新 matching Go/npm SDK pins 與
|
|
7
|
+
lockfiles;不要臆造版本或僅升級其中一端。此能力不新增 CLI flag 或 capability。
|
|
8
|
+
|
|
9
|
+
原生 media element 不能加 `X-SYNO-TOKEN` header;認證 fetch 成功不代表轉成
|
|
10
|
+
Blob URL 就能播放,DSM shell CSP 可能禁止 `blob:` media。不要修改 CSP、放
|
|
11
|
+
SynoToken 到 URL、開 public route、使用 Service Worker 或以 root App 解決。
|
|
12
|
+
|
|
13
|
+
後端以 `dsm.NewMediaAuthenticator(entryMode, packageID)` 配置不使用 cache 的
|
|
14
|
+
media admission,再用 `media.Service.Authenticator(existingAuthenticator)` 保留
|
|
15
|
+
其他 RPC 的既有身份檢查。issue/renew 仍需正常 cookie + header token + owner hook。
|
|
16
|
+
若既有 middleware 在 SDK Server 之前強制 header,只讓固定 media selector 進入
|
|
17
|
+
SDK 的完整 admission;不普遍略過認證。
|
|
18
|
+
|
|
19
|
+
App 自己的 operations.json 必須宣告 `media.issue`、`media.renew`、`media.revoke`
|
|
20
|
+
三個 write JSON RPC 與 `media.content` stream,全部至少 authenticated,然後
|
|
21
|
+
執行既有 `ctl generate` 產生 permissions/型別。自訂 prefix 必須在 Go、前端與
|
|
22
|
+
operation registry 一致。media issue/renew/revoke 不可標成 read recovery 或自動重送。
|
|
23
|
+
|
|
24
|
+
App 必須提供可信的 current install generation、每次重查 owner/read 權限的
|
|
25
|
+
Authorize hook,以及開啟同一已授權 immutable asset 的 Open hook。generation 必須
|
|
26
|
+
隨重新安裝/升級替換,不能只在 daemon 啟動時截取,也不能用版本字串或 browser params。
|
|
27
|
+
Open 回傳 seekable content、明確 audio/video Content-Type 與對應 bytes 的強 ETag。
|
|
28
|
+
不要讓 asset id 直接成為任意檔案路徑;admin 也不能略過 owner hook。
|
|
29
|
+
|
|
30
|
+
URL 只有固定 method selector 與高熵 `media_grant`。每次 GET/HEAD/Range 仍需原本
|
|
31
|
+
DSM id cookie 與 SDK 的加密 HttpOnly media cookie,並即時檢查 session、UID、App entry、
|
|
32
|
+
install generation、owner、撤銷。不同使用者或同使用者的不同 session 均不得互用。
|
|
33
|
+
SDK 只在 request memory 還原 token 給 DSM;磁碟保存 grant/session hashes、binding
|
|
34
|
+
metadata 與私有加密 key,不保存 DSM token/cookie。
|
|
35
|
+
|
|
36
|
+
預設 TTL 五分鐘,最高三十分鐘;是憑證有效期,不是播放或工作的失敗 timeout。
|
|
37
|
+
`mediaUrl` 在 TTL 一半時以已認證 RPC 續期相同 URL,GET/HEAD/Range 活動也延長
|
|
38
|
+
有效期;不替換 src 或改 currentTime。錯誤由 helper.error/onError 回報且停止自動
|
|
39
|
+
續期;讓 App 明確重試或登入後重新 issue,不隱藏重送。unmount 時 dispose,並由 App
|
|
40
|
+
pause、移除 src、load 釋放媒體。revoke 阻擋下一請求;已交付 bytes/已開啟 response
|
|
41
|
+
無法收回。native seek、Range 206、Content-Range、HEAD、If-Range/ETag 沿用 HTTP。
|
|
42
|
+
|
|
43
|
+
HTTP 依 SDK 政策允許並警告;建議 HTTPS 保護 session cookie。不要把 grant 轉送
|
|
44
|
+
其他 origin/CDN。回應 private,no-store/no-referrer/nosniff/same-origin CORP。
|
|
45
|
+
記錄診斷只用 SDK observer/redactor;精確欄位 `media_grant` 與 URL 中該 query
|
|
46
|
+
值應遮罩,client response 不遮。reverse proxy/DSM access log 必須省略 query、
|
|
47
|
+
Cookie/Set-Cookie;SDK 無法清洗程序外的 log。
|
|
48
|
+
|
|
49
|
+
開發驗證至少涵蓋簽發、cookie/subject/UID/entry/generation/asset 綁定、過期、
|
|
50
|
+
撤銷、權限撤回、Range/HEAD/ETag、非 GET/HEAD 拒絕、log 無 grant,以及前端穩定 URL
|
|
51
|
+
續期與 dispose。單元測試或本機瀏覽器不等於真機 DSM shell 播放+seek 驗收。
|