@synopackageland/cli 0.52.3 → 0.52.5

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,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.52.5
4
+
5
+ - Fix first executor approval from mobile App entries by resuming DSM's native Noise session and signing protected requests
6
+ - Honor each DSM API's advertised request format, including JSON-encoded string parameters and password confirmation tokens
7
+ - Keep the desktop AppWindow transport and existing administrator, password confirmation and task verification checks
8
+
9
+ ## 0.52.4
10
+
11
+ - Wire executor approval into mobile App entries using the same tasks, digest pins and access runtime as DSM windows
12
+ - Share bounded startup retries and password confirmation across both entry hosts
13
+ - Include executor approval definitions in mobile cache identity
14
+ - Raise the templates dependency floor to 0.41.3 for SDK 0.53.2, UI ~0.23.3 and generated CLI ~0.52.3 pins
15
+ - Limit source UI scanning to shipped SDK windows so gateway-only scaffolds accept private project files
16
+
3
17
  ## 0.52.3
4
18
 
5
19
  - Minify all packaged public UI JS/CSS deterministically, preserving classic globals, module exports and LICENSES files
@@ -0,0 +1,4 @@
1
+ /** Starting refusals guarantee no dispatch; status panels own their polling.
2
+ * Wait up to 30 s for executor.control, 4 s for other calls, never APP_STOPPED.
3
+ * Each attempt retains the host transport's deadline and cancellation. */
4
+ export declare const CALL_RETRY_RUNTIME = "function createRetryCall(callOnce) {\n var retryCodes = [\"APP_STARTING\", \"EXECUTOR_STARTING\"];\n var statusReads = [\"delegate.status\", \"authorization.status\", \"executor.status\"];\n return function (method, params, options, requestTimeout) {\n var signal = options && options.signal;\n var left = statusReads.indexOf(method) >= 0 ? 0 : method === \"executor.control\" ? 30000 : 4000;\n var delay = 500;\n var attempt = function () {\n return callOnce(method, params, options, requestTimeout).catch(function (error) {\n if (left <= 0 || !error || retryCodes.indexOf(error.code) < 0) throw error;\n var wait = Math.min(delay, left);\n left -= wait;\n delay = Math.min(delay * 2, 8000);\n return new Promise(function (resolve, reject) {\n var leave = function () {\n clearTimeout(timer);\n reject({ code: \"request_canceled\", message: \"The request was canceled\" });\n };\n var timer = setTimeout(function () {\n if (signal) signal.removeEventListener(\"abort\", leave);\n resolve(attempt());\n }, wait);\n if (signal && signal.aborted) leave();\n else if (signal) signal.addEventListener(\"abort\", leave);\n });\n });\n };\n return attempt();\n };\n}";
@@ -0,0 +1,33 @@
1
+ /** Starting refusals guarantee no dispatch; status panels own their polling.
2
+ * Wait up to 30 s for executor.control, 4 s for other calls, never APP_STOPPED.
3
+ * Each attempt retains the host transport's deadline and cancellation. */
4
+ export const CALL_RETRY_RUNTIME = `function createRetryCall(callOnce) {
5
+ var retryCodes = ["APP_STARTING", "EXECUTOR_STARTING"];
6
+ var statusReads = ["delegate.status", "authorization.status", "executor.status"];
7
+ return function (method, params, options, requestTimeout) {
8
+ var signal = options && options.signal;
9
+ var left = statusReads.indexOf(method) >= 0 ? 0 : method === "executor.control" ? 30000 : 4000;
10
+ var delay = 500;
11
+ var attempt = function () {
12
+ return callOnce(method, params, options, requestTimeout).catch(function (error) {
13
+ if (left <= 0 || !error || retryCodes.indexOf(error.code) < 0) throw error;
14
+ var wait = Math.min(delay, left);
15
+ left -= wait;
16
+ delay = Math.min(delay * 2, 8000);
17
+ return new Promise(function (resolve, reject) {
18
+ var leave = function () {
19
+ clearTimeout(timer);
20
+ reject({ code: "request_canceled", message: "The request was canceled" });
21
+ };
22
+ var timer = setTimeout(function () {
23
+ if (signal) signal.removeEventListener("abort", leave);
24
+ resolve(attempt());
25
+ }, wait);
26
+ if (signal && signal.aborted) leave();
27
+ else if (signal) signal.addEventListener("abort", leave);
28
+ });
29
+ });
30
+ };
31
+ return attempt();
32
+ };
33
+ }`;
@@ -1,10 +1,12 @@
1
+ import { renderExecutorApproval } from './executor-approval.js';
2
+ import { CALL_RETRY_RUNTIME } from './call-retry.js';
1
3
  import { oidcResumeRuntime } from "./oidc-resume.js";
2
4
  import { gatewayEntryPath } from './native-gateway.js';
3
5
  import { resolvedSdkLaunch, dsmLauncherType } from "../contract/app-launch.js";
4
6
  import { REOPEN_EVENTS_RUNTIME } from "./reopen-events.js";
5
7
  import { LAUNCH_PARAMS_RUNTIME } from "./launch-params.js";
6
8
  import { DSM_LANGS } from "./i18n.js";
7
- import { PASSWORD_CONFIRM, ROOT_PANEL, ROOT_RUNTIME, rootPanelCatalogs, } from "./root-window.js";
9
+ import { ROOT_PANEL, rootPanelCatalogs, } from "./root-window.js";
8
10
  import { HOST_ADAPTER_RUNTIME } from "./host-adapter.js";
9
11
  import { permitsOrdinaryUsers } from "./api-permissions.js";
10
12
  import { portalRuntime } from "./portal-window.js";
@@ -334,45 +336,11 @@ ${batchRuntime}
334
336
  })();
335
337
  ` : ""}
336
338
 
337
- // APP_STOPPED, APP_STARTING and EXECUTOR_STARTING mean the executor op was not
338
- // sent. A stopped package waits for the user to start it in Package Center, so
339
- // APP_STOPPED rejects immediately. Starting states retry with bounded backoff:
340
- // half a second, then doubling, for 4 s of waiting in all, so a short start
341
- // shows the page nothing and the SDK's starting copy follows a long one within
342
- // its own 4 s recheck; executor.control, which the window's approval starts the
343
- // executor with, repeats up to 8 s apart for 30 s. Each attempt keeps its own
344
- // deadline; past the wait it rejects with the last refusal, and leaving the
345
- // page during a wait rejects request_canceled at once. The SDK's status reads
346
- // are not repeated: its panels show the stopped or starting package and check
347
- // again on their own.
348
- ${ns}.retryCodes = ["APP_STARTING", "EXECUTOR_STARTING"];
349
- ${ns}.statusReads = ["delegate.status", "authorization.status", "executor.status"];
350
- ${ns}.call = function (method, params, options, requestTimeout) {
351
- var signal = options && options.signal;
352
- var left = ${ns}.statusReads.indexOf(method) >= 0 ? 0 : method === "executor.control" ? 30000 : 4000;
353
- var delay = 500;
354
- var attempt = function () {
355
- return ${ns}.callOnce(method, params, options, requestTimeout).catch(function (error) {
356
- if (left <= 0 || !error || ${ns}.retryCodes.indexOf(error.code) < 0) throw error;
357
- var wait = Math.min(delay, left);
358
- left -= wait;
359
- delay = Math.min(delay * 2, 8000);
360
- return new Promise(function (resolve, reject) {
361
- var leave = function () {
362
- clearTimeout(timer);
363
- reject({ code: "request_canceled", message: "The request was canceled" });
364
- };
365
- var timer = setTimeout(function () {
366
- if (signal) signal.removeEventListener("abort", leave);
367
- resolve(attempt());
368
- }, wait);
369
- if (signal && signal.aborted) leave();
370
- else if (signal) signal.addEventListener("abort", leave);
371
- });
372
- });
373
- };
374
- return attempt();
375
- };
339
+ // Both entry hosts share bounded retries; status panels poll on their own.
340
+ ${ns}.call = (function () {
341
+ ${CALL_RETRY_RUNTIME}
342
+ return createRetryCall(${ns}.callOnce);
343
+ })();
376
344
 
377
345
  ${ns}.messages = ${JSON.stringify(manifest.i18n?.catalogs ?? { en: {} })};
378
346
  ${ns}.createI18n = (function () {
@@ -712,19 +680,10 @@ function settingsOnlyApproval(manifest) {
712
680
  */
713
681
  function renderRootParts(ns, manifest) {
714
682
  return {
715
- definitions: `${ns}.rootTasks = ${JSON.stringify(manifest.executor.tasks)};
716
- ${ns}.createRootAccess = (function () {
717
- ${ROOT_RUNTIME}
718
- return createRootAccess;
719
- })();
720
- ${ns}.mountRootPanel = (function () {
683
+ definitions: renderExecutorApproval(ns, manifest) + `${ns}.mountRootPanel = (function () {
721
684
  ${ROOT_PANEL}
722
685
  return mountRootPanel;
723
686
  })();
724
- ${ns}.createPasswordConfirm = (function () {
725
- ${PASSWORD_CONFIRM}
726
- return createPasswordConfirm;
727
- })();
728
687
 
729
688
  `,
730
689
  html: `autoScroll: true,
@@ -733,15 +692,11 @@ ${PASSWORD_CONFIRM}
733
692
  var current = SYNO.SDS.Session || {};
734
693
  return { name: current.user, admin: current.is_admin === true };
735
694
  };
736
- var access = ${ns}.createRootAccess({
737
- tasks: ${ns}.rootTasks,
738
- webapiProfiles: ${JSON.stringify(manifest.capabilities.webapi ?? {})},
739
- pins: ${JSON.stringify({ package: manifest.package, executorDigest: manifest.executor.executorDigest, policyDigest: manifest.executor.policyDigest })},
695
+ var access = ${ns}.createExecutorAccess({
740
696
  user: session,
741
697
  send: ${ns}.webApi(me),
742
698
  confirmPassword: ${ns}.createPasswordConfirm(me),
743
- call: call,
744
- wait: function (ms) { return new Promise(function (resolve) { setTimeout(resolve, ms); }); }
699
+ call: call
745
700
  });
746
701
  ${settingsOnlyApproval(manifest)
747
702
  ? ""
@@ -0,0 +1,3 @@
1
+ import type { StandaloneManifest } from './manifest.js';
2
+ /** Both entry hosts approve exactly the same tasks, profiles and digest pins. */
3
+ export declare function renderExecutorApproval(ns: string, manifest: StandaloneManifest): string;
@@ -0,0 +1,21 @@
1
+ import { PASSWORD_CONFIRM, ROOT_RUNTIME } from './root-window.js';
2
+ /** Both entry hosts approve exactly the same tasks, profiles and digest pins. */
3
+ export function renderExecutorApproval(ns, manifest) {
4
+ return `${ns}.rootTasks = ${JSON.stringify(manifest.executor.tasks)};
5
+ ${ns}.createRootAccess = (function () {
6
+ ${ROOT_RUNTIME}
7
+ return createRootAccess;
8
+ })();
9
+ ${ns}.createPasswordConfirm = (function () {
10
+ ${PASSWORD_CONFIRM}
11
+ return createPasswordConfirm;
12
+ })();
13
+ ${ns}.createExecutorAccess = function (options) {
14
+ options.tasks = ${ns}.rootTasks;
15
+ options.webapiProfiles = ${JSON.stringify(manifest.capabilities.webapi ?? {})};
16
+ options.pins = ${JSON.stringify({ package: manifest.package, executorDigest: manifest.executor.executorDigest, policyDigest: manifest.executor.policyDigest })};
17
+ options.wait = function (ms) { return new Promise(function (resolve) { setTimeout(resolve, ms); }); };
18
+ return ${ns}.createRootAccess(options);
19
+ };
20
+ `;
21
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Honor DSM API formats and resume Noise only when mobile approval needs it. Reuse
3
+ * the NAS libraries instead of shipping another implementation or login flow.
4
+ * The desktop keeps its injected AppWindow WebAPI channel.
5
+ */
6
+ export declare const MOBILE_APPROVAL_WEBAPI = "\nvar mobileApprovalCredential;\nfunction createMobileApprovalWebApi(ctx) {\n var formats = {};\n function url(path) {\n var base = new URL(ctx.files.endpoint);\n base.pathname = base.pathname.slice(0, base.pathname.indexOf(\"/webman/3rdparty/\") + 1);\n base.search = \"\"; base.hash = \"\";\n return new URL(path, base).href;\n }\n function failure() { return {code: \"dsm_119\"}; }\n function script(path) {\n return new Promise(function (resolve, reject) {\n var element = document.createElement(\"script\");\n var timer = setTimeout(function () { element.remove(); reject(failure()); }, ctx.requestTimeout || 300000);\n element.src = url(path);\n element.onload = function () { clearTimeout(timer); resolve(); };\n element.onerror = function () { clearTimeout(timer); element.remove(); reject(failure()); };\n document.head.appendChild(element);\n });\n }\n async function request(params, headers, json, path) {\n var body = new URLSearchParams();\n Object.keys(params).forEach(function (key) {\n var value = params[key];\n var routing = key === \"api\" || key === \"method\" || key === \"version\";\n body.set(key, (json && !routing) || typeof value !== \"string\" ? JSON.stringify(value) : value);\n });\n var response = await fetch(url(\"webapi/\" + (path || \"entry.cgi\")), {\n method: \"POST\", mode: \"same-origin\", credentials: \"same-origin\",\n redirect: \"error\", cache: \"no-store\", headers: headers, body: body,\n signal: AbortSignal.timeout(ctx.requestTimeout || 300000)\n });\n var reply = await response.json();\n if (response.ok && reply && reply.success === true) return reply.data;\n throw {code: \"dsm_\" + (reply && reply.error && reply.error.code || \"error\")};\n }\n async function credential() {\n var native = globalThis.SYNO && globalThis.SYNO.SDS && globalThis.SYNO.SDS.HandShake;\n if (native && native.cred) { await native.cred.WaitForReady(); return native.cred; }\n var stored;\n try { stored = JSON.parse(localStorage.getItem(\"lastHS\")); } catch (_) {}\n var remote = document.cookie.match(/(?:^|;\\s*)_SSID=([^;]+)/);\n // Older DSM and sessions without Noise retain their existing server checks.\n if (!remote || !stored || stored.account !== ctx.user.name || !stored.authtok) return;\n if (!mobileApprovalCredential) mobileApprovalCredential = (async function () {\n if (!globalThis.noise_c_wasm) {\n await script(\"scripts/noise/noise-c.js\");\n await script(\"scripts/noise/constants.js\");\n await script(\"scripts/noise/index.js\");\n }\n if (!globalThis.sodium) await script(\"scripts/noise/sodium.js\");\n if (!globalThis.synocredential) await script(\"scripts/synocredential.js/synocredential.min.js\");\n await globalThis.sodium.ready;\n var noise = await new Promise(function (resolve) { globalThis.noise_c_wasm(resolve); });\n var cred = new globalThis.synocredential(noise, {account: stored.account, authtok: stored.authtok});\n var params = cred.GetResumeParams({enable_syno_token: \"yes\"}, remote[1]);\n if (!params) throw failure();\n var resumed = await request(params, {\"X-SYNO-TOKEN\": ctx.files.token() || \"\"});\n if (!resumed || !resumed.kk_message) throw failure();\n // SetResumeResult's token updater belongs to the desktop's global session.\n // Keep this transport's token in its own credential headers instead.\n cred.SetResumeResult({kk_message: resumed.kk_message});\n cred.info.headers[\"X-SYNO-TOKEN\"] = resumed.synotoken\n ? encodeURIComponent(resumed.synotoken) : ctx.files.token() || \"\";\n return cred;\n })().catch(function (error) { mobileApprovalCredential = undefined; throw error; });\n return mobileApprovalCredential;\n }\n return async function (api, method, version, params) {\n if (!formats[api]) formats[api] = ctx.webApi(\"SYNO.API.Info\", \"query\", 1, {query: api}).then(function (info) {\n var entry = info && info[api];\n if (!entry || !/^[A-Za-z0-9_.-]+\\.cgi$/.test(entry.path)) throw {code: \"dsm_102\"};\n return entry;\n }).catch(function (error) { delete formats[api]; throw error; });\n var info = await formats[api];\n var protectedRequest = api === \"SYNO.Core.User.PasswordConfirm\" || api === \"SYNO.Core.EventScheduler.Root\" ||\n api === \"SYNO.Core.TaskScheduler.Root\";\n var cred = protectedRequest ? await credential() : undefined;\n // GetRequestHeaders generates a fresh hash/nonce for every request.\n return request(Object.assign({}, params, {api: api, method: method, version: version}),\n cred ? cred.GetRequestHeaders() : {\"X-SYNO-TOKEN\": ctx.files.token() || \"\"},\n info.requestFormat === \"JSON\", info.path);\n };\n}\n";
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Honor DSM API formats and resume Noise only when mobile approval needs it. Reuse
3
+ * the NAS libraries instead of shipping another implementation or login flow.
4
+ * The desktop keeps its injected AppWindow WebAPI channel.
5
+ */
6
+ export const MOBILE_APPROVAL_WEBAPI = `
7
+ var mobileApprovalCredential;
8
+ function createMobileApprovalWebApi(ctx) {
9
+ var formats = {};
10
+ function url(path) {
11
+ var base = new URL(ctx.files.endpoint);
12
+ base.pathname = base.pathname.slice(0, base.pathname.indexOf("/webman/3rdparty/") + 1);
13
+ base.search = ""; base.hash = "";
14
+ return new URL(path, base).href;
15
+ }
16
+ function failure() { return {code: "dsm_119"}; }
17
+ function script(path) {
18
+ return new Promise(function (resolve, reject) {
19
+ var element = document.createElement("script");
20
+ var timer = setTimeout(function () { element.remove(); reject(failure()); }, ctx.requestTimeout || 300000);
21
+ element.src = url(path);
22
+ element.onload = function () { clearTimeout(timer); resolve(); };
23
+ element.onerror = function () { clearTimeout(timer); element.remove(); reject(failure()); };
24
+ document.head.appendChild(element);
25
+ });
26
+ }
27
+ async function request(params, headers, json, path) {
28
+ var body = new URLSearchParams();
29
+ Object.keys(params).forEach(function (key) {
30
+ var value = params[key];
31
+ var routing = key === "api" || key === "method" || key === "version";
32
+ body.set(key, (json && !routing) || typeof value !== "string" ? JSON.stringify(value) : value);
33
+ });
34
+ var response = await fetch(url("webapi/" + (path || "entry.cgi")), {
35
+ method: "POST", mode: "same-origin", credentials: "same-origin",
36
+ redirect: "error", cache: "no-store", headers: headers, body: body,
37
+ signal: AbortSignal.timeout(ctx.requestTimeout || 300000)
38
+ });
39
+ var reply = await response.json();
40
+ if (response.ok && reply && reply.success === true) return reply.data;
41
+ throw {code: "dsm_" + (reply && reply.error && reply.error.code || "error")};
42
+ }
43
+ async function credential() {
44
+ var native = globalThis.SYNO && globalThis.SYNO.SDS && globalThis.SYNO.SDS.HandShake;
45
+ if (native && native.cred) { await native.cred.WaitForReady(); return native.cred; }
46
+ var stored;
47
+ try { stored = JSON.parse(localStorage.getItem("lastHS")); } catch (_) {}
48
+ var remote = document.cookie.match(/(?:^|;\\s*)_SSID=([^;]+)/);
49
+ // Older DSM and sessions without Noise retain their existing server checks.
50
+ if (!remote || !stored || stored.account !== ctx.user.name || !stored.authtok) return;
51
+ if (!mobileApprovalCredential) mobileApprovalCredential = (async function () {
52
+ if (!globalThis.noise_c_wasm) {
53
+ await script("scripts/noise/noise-c.js");
54
+ await script("scripts/noise/constants.js");
55
+ await script("scripts/noise/index.js");
56
+ }
57
+ if (!globalThis.sodium) await script("scripts/noise/sodium.js");
58
+ if (!globalThis.synocredential) await script("scripts/synocredential.js/synocredential.min.js");
59
+ await globalThis.sodium.ready;
60
+ var noise = await new Promise(function (resolve) { globalThis.noise_c_wasm(resolve); });
61
+ var cred = new globalThis.synocredential(noise, {account: stored.account, authtok: stored.authtok});
62
+ var params = cred.GetResumeParams({enable_syno_token: "yes"}, remote[1]);
63
+ if (!params) throw failure();
64
+ var resumed = await request(params, {"X-SYNO-TOKEN": ctx.files.token() || ""});
65
+ if (!resumed || !resumed.kk_message) throw failure();
66
+ // SetResumeResult's token updater belongs to the desktop's global session.
67
+ // Keep this transport's token in its own credential headers instead.
68
+ cred.SetResumeResult({kk_message: resumed.kk_message});
69
+ cred.info.headers["X-SYNO-TOKEN"] = resumed.synotoken
70
+ ? encodeURIComponent(resumed.synotoken) : ctx.files.token() || "";
71
+ return cred;
72
+ })().catch(function (error) { mobileApprovalCredential = undefined; throw error; });
73
+ return mobileApprovalCredential;
74
+ }
75
+ return async function (api, method, version, params) {
76
+ if (!formats[api]) formats[api] = ctx.webApi("SYNO.API.Info", "query", 1, {query: api}).then(function (info) {
77
+ var entry = info && info[api];
78
+ if (!entry || !/^[A-Za-z0-9_.-]+\\.cgi$/.test(entry.path)) throw {code: "dsm_102"};
79
+ return entry;
80
+ }).catch(function (error) { delete formats[api]; throw error; });
81
+ var info = await formats[api];
82
+ var protectedRequest = api === "SYNO.Core.User.PasswordConfirm" || api === "SYNO.Core.EventScheduler.Root" ||
83
+ api === "SYNO.Core.TaskScheduler.Root";
84
+ var cred = protectedRequest ? await credential() : undefined;
85
+ // GetRequestHeaders generates a fresh hash/nonce for every request.
86
+ return request(Object.assign({}, params, {api: api, method: method, version: version}),
87
+ cred ? cred.GetRequestHeaders() : {"X-SYNO-TOKEN": ctx.files.token() || ""},
88
+ info.requestFormat === "JSON", info.path);
89
+ };
90
+ }
91
+ `;
@@ -11,6 +11,9 @@ import { MODULE_UI_ENTRY } from './ui-assets.js';
11
11
  import { gatewayEntryPath } from './native-gateway.js';
12
12
  import { CLI_VERSION } from '../cli-version.js';
13
13
  import { isPortalAlias } from '../portal/alias.js';
14
+ import { renderExecutorApproval } from './executor-approval.js';
15
+ import { CALL_RETRY_RUNTIME } from './call-retry.js';
16
+ import { MOBILE_APPROVAL_WEBAPI } from './mobile-approval-webapi.js';
14
17
  const schema = JSON.parse(readFileSync(new URL('../../schema/mobile.v1.schema.json', import.meta.url), 'utf8'));
15
18
  const ajv = new Ajv({ allErrors: true });
16
19
  const validate = ajv.compile(schema);
@@ -77,6 +80,23 @@ export async function renderMobileAssets(manifest, uiDigest, moduleVersion) {
77
80
  for (const [size, png] of icons)
78
81
  files.set(`icons/mobile-${size}.png`, png);
79
82
  let runtime = '';
83
+ const approval = mobile.entry === 'app' && manifest.executor
84
+ ? `var executorApproval = {};
85
+ ${renderExecutorApproval('executorApproval', manifest)}
86
+ ${CALL_RETRY_RUNTIME}
87
+ ${MOBILE_APPROVAL_WEBAPI}
88
+ function attachExecutor(ctx, desktopWebApi) {
89
+ ctx.call = createRetryCall(ctx.call);
90
+ var send = desktopWebApi || createMobileApprovalWebApi(ctx);
91
+ ctx.executor = executorApproval.createExecutorAccess({
92
+ user: function () { return {name: ctx.user?.name, admin: ctx.user?.isAdmin === true}; },
93
+ send: send,
94
+ confirmPassword: executorApproval.createPasswordConfirm(send),
95
+ call: ctx.call
96
+ });
97
+ return ctx;
98
+ }
99
+ ` : '';
80
100
  const requestTimeout = requestTimeoutSeconds(manifest.backend) * 1000 + appSdkTimeouts(manifest.backend).browserMarginMs;
81
101
  if (mobile.entry === 'app') {
82
102
  const result = await build({ entryPoints: [entryModule(manifest)], bundle: true, write: false, format: 'esm', platform: 'browser', target: 'es2022', minify: true, keepNames: true, legalComments: 'none' });
@@ -85,6 +105,8 @@ export async function renderMobileAssets(manifest, uiDigest, moduleVersion) {
85
105
  // Hash both runtime and declaration, as well as the original UI and all icons.
86
106
  const hash = createHash('sha256').update(readFileSync(new URL(import.meta.url))).update(uiDigest).update(json(mobileRegistration(record))).update(runtime)
87
107
  .update(json({ generator: CLI_VERSION, requestTimeout, messages: manifest.i18n?.catalogs }));
108
+ if (approval)
109
+ hash.update(approval);
88
110
  for (const [path, bytes] of files)
89
111
  hash.update(path).update(bytes);
90
112
  const version = hash.digest('hex');
@@ -102,10 +124,13 @@ export async function renderMobileAssets(manifest, uiDigest, moduleVersion) {
102
124
  const loadApp = moduleVersion
103
125
  ? `import(${json(appBundle)})`
104
126
  : `new Promise((resolve,reject)=>{const script=document.createElement('script');script.src=new URL(${json(appBundle)},import.meta.url).href;script.dataset.package=${json(manifest.package)};script.onload=()=>resolve(window.DsmPackageApps?.[${json(manifest.package)}]);script.onerror=reject;document.head.appendChild(script)})`;
105
- const source = `import {bootEntryPage} from ${json(entryModule(manifest))};\nbootEntryPage({...${json(options)},root:document.querySelector('.dsmapp-root'),mount:async(root,ctx)=>{const app=await ${loadApp};if(typeof app?.mount!=='function')throw new Error('The UI must export mount(root, ctx)');return app.mount(root,ctx)}});`;
127
+ const source = `import {bootEntryPage} from ${json(entryModule(manifest))};\n${approval}bootEntryPage({...${json(options)},root:document.querySelector('.dsmapp-root'),mount:async(root,ctx)=>{${approval ? 'attachExecutor(ctx);' : ''}const app=await ${loadApp};if(typeof app?.mount!=='function')throw new Error('The UI must export mount(root, ctx)');return app.mount(root,ctx)}});`;
106
128
  const bundled = await build({ stdin: { contents: source, resolveDir: manifest.root, sourcefile: 'synopkgland-entry.generated.js' }, bundle: true, write: false, format: 'esm', platform: 'browser', target: 'es2022', minify: true, keepNames: true, plugins: [{ name: 'app-import', setup(api) { api.onResolve({ filter: /[?]v=/ }, args => ({ path: args.path, external: true })); } }], legalComments: 'none' });
107
129
  files.set('entry.js', Buffer.from(bundled.outputFiles[0].text));
108
- const context = await build({ stdin: { contents: `export {createAppContext} from ${json(entryModule(manifest))}`, resolveDir: manifest.root, sourcefile: 'synopkgland-context.generated.js' }, bundle: true, write: false, format: 'esm', platform: 'browser', target: 'es2022', minify: true, keepNames: true, legalComments: 'none' });
130
+ const contextSource = approval
131
+ ? `import {createAppContext as createContext} from ${json(entryModule(manifest))};\n${approval}export function createAppContext(options) { return attachExecutor(createContext(options), options.webApi); }`
132
+ : `export {createAppContext} from ${json(entryModule(manifest))}`;
133
+ const context = await build({ stdin: { contents: contextSource, resolveDir: manifest.root, sourcefile: 'synopkgland-context.generated.js' }, bundle: true, write: false, format: 'esm', platform: 'browser', target: 'es2022', minify: true, keepNames: true, legalComments: 'none' });
109
134
  files.set('entry-context.js', Buffer.from(context.outputFiles[0].text));
110
135
  const css = moduleVersion ? `./${moduleVersion}/app.css` : './app.css';
111
136
  files.set('entry.html', Buffer.from(`<!doctype html>\n<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"><meta name="synopkgland-build" content="${version}"><title>${html(name.en)}</title><link rel="icon" href="./icons/mobile-192.png?v=${version}"><link rel="stylesheet" href="${css}?v=${version}"><style>html,body,.dsmapp-root{margin:0;height:100%;min-height:100%}</style></head><body><div class="dsmapp-root"></div><script type="module" src="./entry.js?v=${version}"></script></body></html>\n`));
@@ -10,6 +10,6 @@ export declare function rootPanelCatalogs(): Record<string, Record<string, strin
10
10
  /** The plain-UI approval panel: it asks for the password itself and passes it
11
11
  * to `access.authorize`, the same PasswordConfirm path as ExecutorSettings. */
12
12
  export declare const ROOT_PANEL = "function mountRootPanel(host, access, t, admin) {\n if (!admin) return;\n function el(tag, className) { var e = document.createElement(tag); if (className) e.className = className; return e; }\n var panel = el(\"div\", \"dsmapp-rootpanel\"), title = el(\"h2\"), status = el(\"p\"), reason = el(\"p\", \"dsmapp-rootpanel-hint\");\n var form = el(\"form\"), label = el(\"label\"), password = el(\"input\"), actions = el(\"div\", \"dsmapp-rootpanel-actions\");\n var approve = el(\"button\", \"dsmapp-rootpanel-primary\"), check = el(\"button\");\n title.textContent = t(\"title\"); label.textContent = t(\"password\");\n password.type = \"password\"; password.autocomplete = \"current-password\";\n approve.type = \"submit\"; approve.textContent = t(\"approve\");\n check.type = \"button\"; check.textContent = t(\"check\");\n label.appendChild(password); actions.appendChild(approve); actions.appendChild(check);\n form.appendChild(label); form.appendChild(actions);\n panel.appendChild(title); panel.appendChild(status); panel.appendChild(reason); panel.appendChild(form);\n host.appendChild(panel);\n // The code and outcome in the DSM language, then the DSM code the English reason starts with.\n function explain(result) {\n if (!result.reason && !result.code) return \"\";\n var parts = [t(\"reason.\" + (result.code || \"failed\"))];\n if (result.outcome) parts.push(t(\"outcome.\" + result.outcome));\n var detail = /^([A-Za-z0-9_]+):/.exec(result.reason || \"\");\n if (detail) parts.push(\"(\" + detail[1] + \")\");\n return parts.reduce(function (text, part) { return text + (/[\u3000-\u30FF\u4E00-\u9FFF\uAC00-\uD7AF\uFF00-\uFFEF]$/.test(text) ? \"\" : \" \") + part; });\n }\n function show(result) {\n status.textContent = t(\"state.\" + result.state);\n reason.textContent = explain(result); reason.hidden = !reason.textContent;\n label.hidden = approve.hidden = result.state !== \"needs-admin-approval\" && result.retry !== true;\n }\n // A start step can hold the background service for up to a minute.\n function run(fn) { approve.disabled = check.disabled = true; reason.textContent = t(\"working\"); reason.hidden = false; return fn().then(show, function(e) { show({state: \"blocked\", reason: e && e.code ? e.code + \":\" : \"\", code: \"failed\"}); }).then(function() { approve.disabled = check.disabled = false; }); }\n access.subscribe(show);\n form.onsubmit = function(event) {\n if (event) event.preventDefault();\n var entered = password.value; password.value = \"\";\n if (!entered) return Promise.resolve();\n return run(function() { return access.authorize(entered); });\n };\n check.onclick = function() { return run(function() { return access.status(); }); };\n run(function() { return access.status().then(function(result) { return result.tasks && result.tasks.boot && result.tasks.control && result.tasks.boot.state === \"ready\" && result.tasks.control.state === \"ready\" ? access.control(\"start\") : result; }); });\n}";
13
- /** Administrator password confirmation in the window's own session, for the
14
- * password an approval panel collected. */
13
+ /** Administrator password confirmation through AppWindow or the SDK's
14
+ * same-origin WebAPI transport, for the password an approval panel collected. */
15
15
  export declare const PASSWORD_CONFIRM: string;
@@ -504,19 +504,24 @@ export const ROOT_PANEL = `function mountRootPanel(host, access, t, admin) {
504
504
  check.onclick = function() { return run(function() { return access.status(); }); };
505
505
  run(function() { return access.status().then(function(result) { return result.tasks && result.tasks.boot && result.tasks.control && result.tasks.boot.state === "ready" && result.tasks.control.state === "ready" ? access.control("start") : result; }); });
506
506
  }`;
507
- /** Administrator password confirmation in the window's own session, for the
508
- * password an approval panel collected. */
507
+ /** Administrator password confirmation through AppWindow or the SDK's
508
+ * same-origin WebAPI transport, for the password an approval panel collected. */
509
509
  export const PASSWORD_CONFIRM = `function createPasswordConfirm(win) {
510
510
  var versionUnsupported = ${versionUnsupported.toString()};
511
- function send(password, version) {
511
+ var webApi = typeof win === "function" ? win : function (api, method, version, params) {
512
512
  return new Promise(function (resolve, reject) {
513
- win.sendWebAPI({api: "SYNO.Core.User.PasswordConfirm", method: "auth", version: version, params: {password: password}, scope: win,
513
+ win.sendWebAPI({api: api, method: method, version: version, params: params, scope: win,
514
514
  callback: function (success, response) {
515
515
  if (!success) reject({code: "dsm_" + ((response && response.code) || "error")});
516
- else resolve({confirmed: true, token: response && response.SynoConfirmPWToken});
516
+ else resolve(response);
517
517
  }
518
518
  });
519
519
  });
520
+ };
521
+ function send(password, version) {
522
+ return webApi("SYNO.Core.User.PasswordConfirm", "auth", version, {password: password}).then(function (response) {
523
+ return {confirmed: true, token: response && response.SynoConfirmPWToken};
524
+ });
520
525
  }
521
526
  // DSM 7.1 has PasswordConfirm v1 only, which checks the password but issues no
522
527
  // token. Only an unsupported version is retried; a wrong password is not.
package/dist/validate.js CHANGED
@@ -5,6 +5,7 @@ import { join } from "node:path";
5
5
  import { getErrorCode } from "./error-registry.js";
6
6
  import { loadStandaloneManifest } from "./standalone/manifest.js";
7
7
  import { applyUiIgnores, scanUiTree } from "./standalone/public-ui.js";
8
+ import { hasSdkWindow } from "./standalone/dsm-window.js";
8
9
  import { isNativeLayout, loadNativeLayout, } from "./standalone/native-layout.js";
9
10
  import { manifestPolicyProblem } from "./runtime/executor-policy-check.js";
10
11
  /** All shipped Compose and native projects use the schema-2 build path. */
@@ -43,7 +44,7 @@ export function validateProject(project, _options = {}) {
43
44
  if (loaded.ok) {
44
45
  const manifest = loaded.manifest;
45
46
  const roots = "ui" in manifest
46
- ? [{ dir: manifest.ui.dir, prefix: "app/" }]
47
+ ? hasSdkWindow(manifest) ? [{ dir: manifest.ui.dir, prefix: "app/" }] : []
47
48
  : manifest.arches.map(arch => ({ dir: join(manifest.root, manifest.layout.payload.replaceAll("{arch}", arch), "ui"), prefix: "" }));
48
49
  for (const { dir, prefix } of roots) {
49
50
  if (!existsSync(dir))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synopackageland/cli",
3
- "version": "0.52.3",
3
+ "version": "0.52.5",
4
4
  "description": "Syno Package Land Developer Kit CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@napi-rs/keyring": "^2.1.1",
42
- "@synopackageland/templates": "~0.41.1",
42
+ "@synopackageland/templates": "~0.41.3",
43
43
  "ajv": "^8.17.1",
44
44
  "commander": "^13.1.0",
45
45
  "esbuild": "^0.28.2",
@@ -5,6 +5,7 @@ Files under ui/ (including mobile.json and entry.html) are public static files r
5
5
  Declare `mobile` in `dsm-package.yaml`. Both `admin-only` and `app-privilege`
6
6
  Apps may register. DSM entry and backend permissions still apply to every request.
7
7
  A portal is optional; without it the App stays on its entry URL.
8
+ Executor Apps also support first-time and upgrade approval by administrators on the phone.
8
9
 
9
10
  ```yaml
10
11
  mobile: