@synopackageland/cli 0.49.1 → 0.50.1
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 +11 -0
- package/README.md +10 -0
- package/dist/build-spk/generator.js +3 -3
- package/dist/build-spk/reproducible-archive.js +3 -1
- package/dist/ctl/ai-tools.d.ts +11 -1
- package/dist/ctl/ai-tools.js +4 -4
- package/dist/ctl/cli.d.ts +8 -1
- package/dist/ctl/cli.js +54 -5
- package/dist/ctl/descriptor.d.ts +15 -2
- package/dist/ctl/descriptor.js +9 -4
- package/dist/ctl/diagnostics.d.ts +16 -0
- package/dist/ctl/diagnostics.js +11 -0
- package/dist/ctl/flows.js +2 -0
- package/dist/ctl/input.d.ts +5 -3
- package/dist/ctl/input.js +3 -3
- package/dist/ctl/native-auth-command.d.ts +9 -0
- package/dist/ctl/native-auth-command.js +103 -0
- package/dist/ctl/native-executor.d.ts +16 -0
- package/dist/ctl/native-executor.js +187 -0
- package/dist/ctl/native-file-types.d.ts +16 -0
- package/dist/ctl/native-file-types.js +57 -0
- package/dist/ctl/native-files.d.ts +13 -0
- package/dist/ctl/native-files.js +115 -0
- package/dist/ctl/native-metadata.d.ts +10 -0
- package/dist/ctl/native-metadata.js +50 -0
- package/dist/ctl/native-paths.d.ts +4 -0
- package/dist/ctl/native-paths.js +65 -0
- package/dist/ctl/native-protocol.d.ts +21 -0
- package/dist/ctl/native-protocol.js +150 -0
- package/dist/ctl/native-registry.d.ts +8 -0
- package/dist/ctl/native-registry.js +182 -0
- package/dist/ctl/native-schemas.d.ts +7 -0
- package/dist/ctl/native-schemas.js +25 -0
- package/dist/ctl/native-store.d.ts +67 -0
- package/dist/ctl/native-store.js +342 -0
- package/dist/ctl/native-transfers.d.ts +13 -0
- package/dist/ctl/native-transfers.js +331 -0
- package/dist/ctl/native-transport.d.ts +30 -0
- package/dist/ctl/native-transport.js +148 -0
- package/dist/ctl/native-types.d.ts +15 -0
- package/dist/ctl/native-types.js +1 -0
- package/dist/ctl/registry.d.ts +5 -4
- package/dist/ctl/registry.js +12 -1
- package/dist/ctl/service.d.ts +34 -1
- package/dist/ctl/service.js +122 -1
- package/dist/ctl/windows-acl.d.ts +39 -0
- package/dist/ctl/windows-acl.js +80 -0
- package/dist/ctl/windows-prompt.d.ts +5 -0
- package/dist/ctl/windows-prompt.js +119 -0
- package/dist/ctl/windows-sddl.d.ts +20 -0
- package/dist/ctl/windows-sddl.js +162 -0
- package/dist/ctl/windows-security-helper.d.ts +7 -0
- package/dist/ctl/windows-security-helper.js +88 -0
- package/dist/ctl/windows-security.d.ts +10 -0
- package/dist/ctl/windows-security.js +95 -0
- package/dist/ctl/windows-tools.d.ts +11 -0
- package/dist/ctl/windows-tools.js +23 -0
- package/dist/error-registry.js +15 -0
- package/dist/generated/native-http.d.ts +189 -0
- package/dist/generated/native-http.js +1 -0
- package/dist/nas/store.d.ts +3 -1
- package/dist/nas/store.js +6 -3
- package/dist/nas/transport.d.ts +1 -0
- package/dist/native-http-schema/descriptor.schema.json +242 -0
- package/dist/native-http-schema/inventory.schema.json +121 -0
- package/dist/native-http-schema/registry.schema.json +872 -0
- package/dist/native-http-schema/source.json +1 -0
- package/dist/runtime/sdk-source.d.ts +1 -1
- package/dist/runtime/sdk-source.js +1 -1
- package/dist/spk/extract.d.ts +6 -0
- package/dist/spk/extract.js +39 -0
- package/dist/standalone/api-description.d.ts +2 -5
- package/dist/standalone/build.js +5 -1
- package/dist/standalone/compose-errors.js +5 -0
- package/dist/standalone/daemon.js +1 -0
- package/dist/standalone/inspect-spk.js +23 -37
- package/dist/standalone/install-ports.js +2 -1
- package/dist/standalone/lifecycle.js +9 -2
- package/dist/standalone/manifest.d.ts +1 -0
- package/dist/standalone/manifest.js +22 -5
- package/dist/standalone/native-http-inspect.d.ts +9 -0
- package/dist/standalone/native-http-inspect.js +43 -0
- package/dist/standalone/native-http.d.ts +31 -0
- package/dist/standalone/native-http.js +120 -0
- package/dist/standalone/native-layout.js +2 -0
- package/dist/standalone/operation-registry.d.ts +2 -7
- package/dist/standalone/operation-registry.js +3 -0
- package/dist/standalone/spk.d.ts +1 -0
- package/dist/standalone/spk.js +15 -1
- package/package.json +3 -2
- package/schema/dsm-api-contract.json +8 -7
- package/skills/SKILL.md +2 -2
- package/skills/reference/compose.md +21 -0
- package/skills/reference/ctl.md +229 -0
- package/skills/reference/daemon-mode.md +1 -1
- package/skills/reference/upstream-fork.md +5 -2
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Isolated native ACL readback. No PowerShell, WMI or account-name parsing.
|
|
2
|
+
import koffi from 'koffi';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import { readBounded, strictJson } from './json.js';
|
|
5
|
+
import { windowsSystemTool } from './windows-tools.js';
|
|
6
|
+
export function readWindowsDescriptor(path) {
|
|
7
|
+
if (process.platform !== 'win32')
|
|
8
|
+
throw new Error('Windows only');
|
|
9
|
+
const advapi = koffi.load(windowsSystemTool('advapi32.dll')), kernel = koffi.load(windowsSystemTool('kernel32.dll'));
|
|
10
|
+
const attributes = kernel.func('uint32_t __stdcall GetFileAttributesW(const char16_t *path)');
|
|
11
|
+
const lastError = kernel.func('uint32_t __stdcall GetLastError()');
|
|
12
|
+
const release = kernel.func('void * __stdcall LocalFree(void *memory)');
|
|
13
|
+
const read = advapi.func('uint32_t __stdcall GetNamedSecurityInfoW(const char16_t *name, int type, uint32_t info, void *owner, void *group, void *dacl, void *sacl, _Out_ void **descriptor)');
|
|
14
|
+
const convert = advapi.func('int __stdcall ConvertSecurityDescriptorToStringSecurityDescriptorW(void *descriptor, uint32_t revision, uint32_t info, _Out_ void **text, _Out_ uint32_t *length)');
|
|
15
|
+
const value = attributes(path);
|
|
16
|
+
if (value === 0xffffffff)
|
|
17
|
+
throw Object.assign(new Error('Native inspection failed'), { win32Code: lastError() });
|
|
18
|
+
if (value & 0x400)
|
|
19
|
+
throw new Error('Reparse point refused');
|
|
20
|
+
const descriptor = [null], text = [null], length = [0];
|
|
21
|
+
try {
|
|
22
|
+
const result = read(path, 1, 5, null, null, null, null, descriptor);
|
|
23
|
+
if (result) {
|
|
24
|
+
descriptor[0] = null;
|
|
25
|
+
throw Object.assign(new Error('Native inspection failed'), { win32Code: result });
|
|
26
|
+
}
|
|
27
|
+
if (!convert(descriptor[0], 1, 5, text, length)) {
|
|
28
|
+
text[0] = null;
|
|
29
|
+
throw Object.assign(new Error('Native conversion failed'), { win32Code: lastError() });
|
|
30
|
+
}
|
|
31
|
+
if (!length[0] || length[0] > 1024 * 1024 || !text[0])
|
|
32
|
+
throw new Error('Native descriptor bound exceeded');
|
|
33
|
+
// The API reports buffer capacity, not string length. Decode only inside that
|
|
34
|
+
// bound, then stop at NUL; unused buffer space must never reach the parser.
|
|
35
|
+
const buffer = koffi.decode.string16(text[0], length[0]), end = buffer.indexOf('\0');
|
|
36
|
+
if (end < 0)
|
|
37
|
+
throw new Error('Native descriptor is not terminated');
|
|
38
|
+
const sddl = buffer.slice(0, end), aliasSids = {};
|
|
39
|
+
const relative = [...new Set([...sddl.matchAll(/(?<=[:;])(LA|LG)(?=[OGDS]:|\)|$)/g)].map(match => match[1]))];
|
|
40
|
+
if (relative.length) {
|
|
41
|
+
const toSid = advapi.func('int __stdcall ConvertStringSidToSidW(const char16_t *alias, _Out_ void **sid)');
|
|
42
|
+
const toString = advapi.func('int __stdcall ConvertSidToStringSidW(void *sid, _Out_ void **text)');
|
|
43
|
+
for (const alias of relative) {
|
|
44
|
+
const binary = [null], string = [null];
|
|
45
|
+
try {
|
|
46
|
+
if (!toSid(alias, binary)) {
|
|
47
|
+
binary[0] = null;
|
|
48
|
+
throw Object.assign(new Error('Native SID conversion failed'), { win32Code: lastError() });
|
|
49
|
+
}
|
|
50
|
+
if (!toString(binary[0], string)) {
|
|
51
|
+
string[0] = null;
|
|
52
|
+
throw Object.assign(new Error('Native SID conversion failed'), { win32Code: lastError() });
|
|
53
|
+
}
|
|
54
|
+
// This API returns an OS-allocated NUL-terminated SID string.
|
|
55
|
+
const sid = koffi.decode.string16(string[0]);
|
|
56
|
+
if (!new RegExp('^S-1-5-21-(?:[0-9]+-){3}' + (alias === 'LA' ? '500' : '501') + '$').test(sid))
|
|
57
|
+
throw new Error('Invalid local SID');
|
|
58
|
+
aliasSids[alias] = sid;
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
if (string[0])
|
|
62
|
+
release(string[0]);
|
|
63
|
+
if (binary[0])
|
|
64
|
+
release(binary[0]);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return { sddl, reparsePoint: false, directory: !!(value & 0x10), ...(relative.length ? { aliasSids } : {}) };
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
if (text[0])
|
|
72
|
+
release(text[0]);
|
|
73
|
+
if (descriptor[0])
|
|
74
|
+
release(descriptor[0]);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
78
|
+
try {
|
|
79
|
+
const value = strictJson(readBounded(0, 256 * 1024));
|
|
80
|
+
if (typeof value?.path !== 'string' || value.path.includes('\0'))
|
|
81
|
+
throw new Error('Invalid request');
|
|
82
|
+
process.stdout.write(JSON.stringify(readWindowsDescriptor(value.path)) + '\n');
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
const code = error.win32Code;
|
|
86
|
+
process.stdout.write(JSON.stringify({ errorCode: Number.isInteger(code) && code >= 0 ? code : 0 }) + '\n');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import type { WindowsAclSnapshot } from './windows-acl.js';
|
|
3
|
+
export declare function parseWhoamiUser(text: string): string;
|
|
4
|
+
export declare function createWindowsSecurityTools(execute?: typeof execFileSync): {
|
|
5
|
+
inspect: (path: string) => WindowsAclSnapshot & {
|
|
6
|
+
directory: boolean;
|
|
7
|
+
};
|
|
8
|
+
privatize: (path: string) => WindowsAclSnapshot;
|
|
9
|
+
currentUser: () => string;
|
|
10
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { parseWindowsSddl, SddlError } from './windows-sddl.js';
|
|
4
|
+
import { windowsSystemTool, WindowsToolFailure, windowsChildDiagnostic } from './windows-tools.js';
|
|
5
|
+
export function parseWhoamiUser(text) {
|
|
6
|
+
const cells = [];
|
|
7
|
+
let cell = '', quoted = false;
|
|
8
|
+
for (let index = 0; index < text.length; index++) {
|
|
9
|
+
const character = text[index];
|
|
10
|
+
if (character === '"') {
|
|
11
|
+
if (quoted && text[index + 1] === '"') {
|
|
12
|
+
cell += '"';
|
|
13
|
+
index++;
|
|
14
|
+
}
|
|
15
|
+
else
|
|
16
|
+
quoted = !quoted;
|
|
17
|
+
}
|
|
18
|
+
else if (character === ',' && !quoted) {
|
|
19
|
+
cells.push(cell);
|
|
20
|
+
cell = '';
|
|
21
|
+
}
|
|
22
|
+
else
|
|
23
|
+
cell += character;
|
|
24
|
+
}
|
|
25
|
+
cells.push(cell.trim());
|
|
26
|
+
if (quoted || cells.length !== 2 || !/^S-1-(?:\d+-)+\d+$/.test(cells[1]))
|
|
27
|
+
throw new SddlError('native-output');
|
|
28
|
+
return cells[1];
|
|
29
|
+
}
|
|
30
|
+
export function createWindowsSecurityTools(execute) {
|
|
31
|
+
let identity;
|
|
32
|
+
function run(file, args, input) {
|
|
33
|
+
try {
|
|
34
|
+
return (execute ?? execFileSync)(file, args, { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true, maxBuffer: 1024 * 1024, ...(input === undefined ? {} : { input }) });
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
throw new WindowsToolFailure(windowsChildDiagnostic(error));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function currentUser() {
|
|
41
|
+
if (!identity) {
|
|
42
|
+
try {
|
|
43
|
+
identity = { sid: parseWhoamiUser(run(windowsSystemTool('whoami.exe'), ['/user', '/fo', 'csv', '/nh'])) };
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
identity = { error: new WindowsToolFailure(windowsChildDiagnostic(error)) };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if ('error' in identity)
|
|
50
|
+
throw identity.error;
|
|
51
|
+
return identity.sid;
|
|
52
|
+
}
|
|
53
|
+
function inspect(path) {
|
|
54
|
+
const current = currentUser();
|
|
55
|
+
let result;
|
|
56
|
+
try {
|
|
57
|
+
result = JSON.parse(run(process.execPath, [fileURLToPath(new URL('./windows-security-helper.js', import.meta.url))], JSON.stringify({ path })));
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (error instanceof WindowsToolFailure)
|
|
61
|
+
throw error;
|
|
62
|
+
throw new SddlError('native-output');
|
|
63
|
+
}
|
|
64
|
+
if (Number.isInteger(result?.errorCode))
|
|
65
|
+
throw new WindowsToolFailure({ category: result.errorCode === 5 ? 'access-denied' : 'native-error', win32Code: result.errorCode });
|
|
66
|
+
if (typeof result?.sddl !== 'string' || typeof result.reparsePoint !== 'boolean' || typeof result.directory !== 'boolean')
|
|
67
|
+
throw new SddlError('native-output');
|
|
68
|
+
const parsed = parseWindowsSddl(result.sddl, current, result.reparsePoint, result.aliasSids ?? {});
|
|
69
|
+
if (parsed.owner === 'LA' || parsed.owner === 'LG' || parsed.rules.some(rule => rule.sid === 'LA' || rule.sid === 'LG'))
|
|
70
|
+
throw new SddlError('native-output');
|
|
71
|
+
return { ...parsed, directory: result.directory };
|
|
72
|
+
}
|
|
73
|
+
function privatize(path) {
|
|
74
|
+
const before = inspect(path), sid = currentUser();
|
|
75
|
+
if (before.reparsePoint || ![sid, 'S-1-5-18', 'S-1-5-32-544', ...(before.aliasSids?.LA ? [before.aliasSids.LA] : [])].includes(before.owner))
|
|
76
|
+
throw new SddlError('private-readback');
|
|
77
|
+
const others = [...new Set(before.rules.map(rule => rule.sid).filter(value => value !== sid))];
|
|
78
|
+
if (others.length > 32)
|
|
79
|
+
throw new SddlError('private-readback');
|
|
80
|
+
const tool = windowsSystemTool('icacls.exe');
|
|
81
|
+
run(tool, [path, '/inheritance:r', '/grant:r', `*${sid}:${before.directory ? '(OI)(CI)' : ''}F`, '/Q', '/L']);
|
|
82
|
+
// /grant:r replaces only this user's grants; remove other explicit ACEs too.
|
|
83
|
+
if (others.length)
|
|
84
|
+
run(tool, [path, '/remove', ...others.map(value => '*' + value), '/Q', '/L']);
|
|
85
|
+
if (before.rules.some(rule => rule.sid === sid && rule.type === 'Deny'))
|
|
86
|
+
run(tool, [path, '/remove:d', '*' + sid, '/Q', '/L']);
|
|
87
|
+
if (before.owner !== sid)
|
|
88
|
+
run(tool, [path, '/setowner', '*' + sid, '/Q', '/L']);
|
|
89
|
+
const after = inspect(path);
|
|
90
|
+
if (after.owner !== sid || !after.protected || after.rules.some(rule => rule.type === 'Allow' && rule.sid !== sid && rule.rights !== 0))
|
|
91
|
+
throw new SddlError('private-readback');
|
|
92
|
+
return after;
|
|
93
|
+
}
|
|
94
|
+
return { inspect, privatize, currentUser };
|
|
95
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface WindowsChildDiagnostic {
|
|
2
|
+
category: 'access-denied' | 'spawn-failed' | 'native-error' | 'other';
|
|
3
|
+
exitCode?: number;
|
|
4
|
+
win32Code?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function windowsSystemTool(name: 'whoami.exe' | 'icacls.exe' | 'advapi32.dll' | 'kernel32.dll', env?: NodeJS.ProcessEnv): string;
|
|
7
|
+
export declare class WindowsToolFailure extends Error {
|
|
8
|
+
detail: WindowsChildDiagnostic;
|
|
9
|
+
constructor(detail: WindowsChildDiagnostic);
|
|
10
|
+
}
|
|
11
|
+
export declare function windowsChildDiagnostic(error: unknown): WindowsChildDiagnostic;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { win32 } from 'node:path';
|
|
2
|
+
export function windowsSystemTool(name, env = process.env) {
|
|
3
|
+
const get = (key) => Object.entries(env).find(([name]) => name.toLowerCase() === key.toLowerCase())?.[1];
|
|
4
|
+
const root = get('SystemRoot') ?? get('WINDIR') ?? 'C:\\Windows';
|
|
5
|
+
if (!win32.isAbsolute(root) || root.includes('\0'))
|
|
6
|
+
throw new Error('Invalid Windows system root');
|
|
7
|
+
return win32.join(root, 'System32', name);
|
|
8
|
+
}
|
|
9
|
+
export class WindowsToolFailure extends Error {
|
|
10
|
+
detail;
|
|
11
|
+
constructor(detail) {
|
|
12
|
+
super('Windows security inspection failed.');
|
|
13
|
+
this.detail = detail;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function windowsChildDiagnostic(error) {
|
|
17
|
+
if (error instanceof WindowsToolFailure)
|
|
18
|
+
return error.detail;
|
|
19
|
+
const value = error;
|
|
20
|
+
const stderr = typeof value?.stderr === 'string' ? value.stderr : Buffer.isBuffer(value?.stderr) ? value.stderr.toString('utf8') : '';
|
|
21
|
+
const category = value?.code === 'ENOENT' ? 'spawn-failed' : /access.*denied|permissiondenied/i.test(stderr) ? 'access-denied' : 'other';
|
|
22
|
+
return { category, ...(Number.isInteger(value?.status) && Number(value.status) >= 0 ? { exitCode: Number(value.status) } : {}) };
|
|
23
|
+
}
|
package/dist/error-registry.js
CHANGED
|
@@ -27,6 +27,21 @@ export const ERROR_REGISTRY = {
|
|
|
27
27
|
HOST_TIMEOUT: { "code": "HOST_TIMEOUT", "description": "The NAS request timed out", "suggestion": "Check connection and firewall; inspect state before retrying writes" },
|
|
28
28
|
CTL_HOST_REQUIRED: { "code": "CTL_HOST_REQUIRED", "description": "Select a registered NAS host", "suggestion": "Run synopkgland host add, select --host, or set host default" },
|
|
29
29
|
CTL_NOT_AUTHENTICATED: { "code": "CTL_NOT_AUTHENTICATED", "description": "The DSM session is absent or expired", "suggestion": "Run synopkgland host login <name>" },
|
|
30
|
+
CTL_NATIVE_AUTH_REQUIRED: { code: 'CTL_NATIVE_AUTH_REQUIRED', description: 'This profile/App needs a native credential', suggestion: 'Ask the human to run ctl auth --host <profile> --app <package> in their own terminal; never request a token in chat' },
|
|
31
|
+
CTL_NATIVE_AUTH_INVALID: { code: 'CTL_NATIVE_AUTH_INVALID', description: 'The App rejected its native credential', suggestion: 'Run ctl auth --app <package> --reset in your own terminal; no automatic retry occurs' },
|
|
32
|
+
CTL_NATIVE_ACCESS_DENIED: { code: 'CTL_NATIVE_ACCESS_DENIED', description: 'Native App role or resource access was denied', suggestion: 'Check native App permissions; resetting a token does not grant additional access' },
|
|
33
|
+
CTL_NATIVE_UNAVAILABLE: { code: 'CTL_NATIVE_UNAVAILABLE', description: 'Native API is unavailable or disabled', suggestion: 'Check the App configuration and native API enablement' },
|
|
34
|
+
CTL_NATIVE_REDIRECT: { code: 'CTL_NATIVE_REDIRECT', description: 'Native API returned a redirect', suggestion: 'Correct the declared ingress or native endpoint; redirects are never followed' },
|
|
35
|
+
CTL_NATIVE_OUTCOME_UNKNOWN: { code: 'CTL_NATIVE_OUTCOME_UNKNOWN', description: 'A native mutation or receipt was interrupted', suggestion: 'Inspect the original resource or task before retrying; no automatic replay occurs' },
|
|
36
|
+
CTL_NATIVE_VAULT_LOCKED: { code: 'CTL_NATIVE_VAULT_LOCKED', description: 'The encrypted native credential vault is locked', suggestion: 'Unlock interactively in your own terminal; headless execution requires an OS secret service' },
|
|
37
|
+
CTL_NATIVE_VAULT_INVALID: { code: 'CTL_NATIVE_VAULT_INVALID', description: 'The vault did not authenticate or has unsafe metadata', suggestion: 'Use the correct passphrase; corrupted ciphertext is never overwritten implicitly' },
|
|
38
|
+
CTL_NATIVE_STORE_BUSY: { code: 'CTL_NATIVE_STORE_BUSY', description: 'Another native credential store operation holds the lock', suggestion: 'Allow that operation to finish; never remove a live lock' },
|
|
39
|
+
CTL_NATIVE_STORE_UNAVAILABLE: { code: 'CTL_NATIVE_STORE_UNAVAILABLE', description: 'Native OS credential storage is unavailable or unsafe', suggestion: 'Unlock the keychain, or explicitly enroll with ctl auth --store encrypted-file' },
|
|
40
|
+
CTL_NATIVE_SDK_REQUIRED: { code: 'CTL_NATIVE_SDK_REQUIRED', description: 'The selected SDK lacks a matching native HTTP v3 contract', suggestion: 'Use a matching SDK with native HTTP v3 metadata; do not downgrade to Compose RPC' },
|
|
41
|
+
CTL_NATIVE_REGISTRY_INVALID: { code: 'CTL_NATIVE_REGISTRY_INVALID', description: 'The native HTTP registry conflicts with its App manifest or gateway policy', suggestion: 'Check the v3 registry, protected ingress, declared upstream auth paths and backend capabilities; run ctl generate and check' },
|
|
42
|
+
CTL_NATIVE_METADATA_REQUIRED: { code: 'CTL_NATIVE_METADATA_REQUIRED', description: 'Native HTTP packaging lacks its private descriptor, inventory or CGI', suggestion: 'Run ctl generate and rebuild with a matching SDK' },
|
|
43
|
+
CTL_NATIVE_METADATA_MISMATCH: { code: 'CTL_NATIVE_METADATA_MISMATCH', description: 'Native descriptor, HTTP inventory, gateway policy, CGI pin or final package identity drifted', suggestion: 'Regenerate metadata, rebuild and inspect the exact SPK before installing' },
|
|
44
|
+
CTL_NATIVE_BACKEND_CONFLICT: { code: 'CTL_NATIVE_BACKEND_CONFLICT', description: 'A metadata-only CGI would replace required SDK business behavior', suggestion: 'Keep RPC for SDK business capabilities or use an independent native daemon and metadata-only CGI' },
|
|
30
45
|
NAS_ADMIN_REQUIRED: { "code": "NAS_ADMIN_REQUIRED", "description": "Package installation and removal require an administrator", "suggestion": "Register and log in with a DSM administrator account" },
|
|
31
46
|
INIT_UPSTREAM_INVALID: { code: "INIT_UPSTREAM_INVALID", description: "The upstream repository URL is invalid.", suggestion: "Supply --upstream with an HTTPS repository URL without credentials." },
|
|
32
47
|
INIT_PUBLISHER_INVALID: { code: "INIT_PUBLISHER_INVALID", description: "The attribution name or publisher URL is invalid.", suggestion: "Use plain single-line project/publisher names and an http(s) publisher URL without credentials." },
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/** Pure metadata contracts. Native requests and credentials belong to the CLI. */
|
|
2
|
+
export type NativeScalar = string | number | boolean | null;
|
|
3
|
+
export type NativeSchema = Record<string, unknown>;
|
|
4
|
+
export type NativeBinding = {
|
|
5
|
+
param: string;
|
|
6
|
+
} | {
|
|
7
|
+
literal: NativeScalar;
|
|
8
|
+
} | {
|
|
9
|
+
actionToken: true;
|
|
10
|
+
};
|
|
11
|
+
export type NativeProjection = {
|
|
12
|
+
pointer: string;
|
|
13
|
+
} | {
|
|
14
|
+
fields: Record<string, string>;
|
|
15
|
+
};
|
|
16
|
+
export interface NativeResponse {
|
|
17
|
+
statuses: number[];
|
|
18
|
+
decode: 'json' | 'text' | 'binary';
|
|
19
|
+
maxBytes: number;
|
|
20
|
+
contentTypes: string[];
|
|
21
|
+
project?: NativeProjection;
|
|
22
|
+
}
|
|
23
|
+
export type NativeAuth = {
|
|
24
|
+
type: 'header';
|
|
25
|
+
header: 'Authorization';
|
|
26
|
+
prefix: 'Token ' | 'Bearer ';
|
|
27
|
+
credentialPage: string;
|
|
28
|
+
instructions: string;
|
|
29
|
+
verify: {
|
|
30
|
+
method: 'GET';
|
|
31
|
+
path: string;
|
|
32
|
+
response: Omit<NativeResponse, 'decode'> & {
|
|
33
|
+
decode: 'json' | 'text';
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
} | {
|
|
37
|
+
type: 'greader-client-login';
|
|
38
|
+
credentialPage: string;
|
|
39
|
+
instructions: string;
|
|
40
|
+
exchangePath: string;
|
|
41
|
+
identityPath: string;
|
|
42
|
+
actionTokenPath: string;
|
|
43
|
+
};
|
|
44
|
+
export interface NativeHttp {
|
|
45
|
+
basePath: string;
|
|
46
|
+
auth: NativeAuth;
|
|
47
|
+
limits: {
|
|
48
|
+
maxResponseBytes: number;
|
|
49
|
+
maxTransferBytes: number;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export type NativePagination = {
|
|
53
|
+
mode: 'page';
|
|
54
|
+
pageParam: string;
|
|
55
|
+
sizeParam: string;
|
|
56
|
+
items: string;
|
|
57
|
+
next: string;
|
|
58
|
+
pageSize: number;
|
|
59
|
+
maxPages: number;
|
|
60
|
+
maxItems: number;
|
|
61
|
+
maxBytes: number;
|
|
62
|
+
} | {
|
|
63
|
+
mode: 'cursor';
|
|
64
|
+
cursorParam: string;
|
|
65
|
+
sizeParam: string;
|
|
66
|
+
items: string;
|
|
67
|
+
next: string;
|
|
68
|
+
pageSize: number;
|
|
69
|
+
maxPages: number;
|
|
70
|
+
maxItems: number;
|
|
71
|
+
maxBytes: number;
|
|
72
|
+
};
|
|
73
|
+
export type NativeFlow = {
|
|
74
|
+
type: 'invoke';
|
|
75
|
+
method: string;
|
|
76
|
+
} | {
|
|
77
|
+
type: 'paginate-http';
|
|
78
|
+
method: string;
|
|
79
|
+
pagination: NativePagination;
|
|
80
|
+
} | {
|
|
81
|
+
type: 'ndjson';
|
|
82
|
+
method: string;
|
|
83
|
+
maxLines: number;
|
|
84
|
+
maxLineBytes: number;
|
|
85
|
+
maxBytes: number;
|
|
86
|
+
} | {
|
|
87
|
+
type: 'upload-http';
|
|
88
|
+
method: string;
|
|
89
|
+
fileParam: string;
|
|
90
|
+
maxBytes: number;
|
|
91
|
+
contentTypes: string[];
|
|
92
|
+
encoding: 'multipart';
|
|
93
|
+
part: string;
|
|
94
|
+
} | {
|
|
95
|
+
type: 'upload-http';
|
|
96
|
+
method: string;
|
|
97
|
+
fileParam: string;
|
|
98
|
+
maxBytes: number;
|
|
99
|
+
contentTypes: string[];
|
|
100
|
+
encoding: 'raw';
|
|
101
|
+
} | {
|
|
102
|
+
type: 'download-file';
|
|
103
|
+
method: string;
|
|
104
|
+
outputParam: string;
|
|
105
|
+
maxBytes: number;
|
|
106
|
+
contentTypes: string[];
|
|
107
|
+
};
|
|
108
|
+
export interface NativeHttpBinding {
|
|
109
|
+
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
110
|
+
path: string;
|
|
111
|
+
query?: Record<string, NativeBinding>;
|
|
112
|
+
headers?: {
|
|
113
|
+
'Accept'?: string;
|
|
114
|
+
'Content-Type'?: string;
|
|
115
|
+
};
|
|
116
|
+
body?: {
|
|
117
|
+
encoding: 'json' | 'form';
|
|
118
|
+
fields: Record<string, NativeBinding>;
|
|
119
|
+
};
|
|
120
|
+
response: NativeResponse;
|
|
121
|
+
}
|
|
122
|
+
export interface NativeInventoryBinding {
|
|
123
|
+
effect: 'read' | 'write' | 'destructive';
|
|
124
|
+
permission: 'authenticated' | 'administrators';
|
|
125
|
+
kind: 'rpc' | 'stream';
|
|
126
|
+
flow: NativeFlow;
|
|
127
|
+
http: NativeHttpBinding;
|
|
128
|
+
}
|
|
129
|
+
export interface NativeOperation extends NativeInventoryBinding {
|
|
130
|
+
summary: string;
|
|
131
|
+
cli: string[];
|
|
132
|
+
ai: 'read' | 'preview' | 'draft' | 'human-only' | 'hidden';
|
|
133
|
+
preview?: string;
|
|
134
|
+
paramsSchema: NativeSchema;
|
|
135
|
+
resultSchema: NativeSchema;
|
|
136
|
+
}
|
|
137
|
+
export interface NativeRegistry {
|
|
138
|
+
format: 'synopkgland.api';
|
|
139
|
+
version: 3;
|
|
140
|
+
nativeHttp: NativeHttp;
|
|
141
|
+
operations: Record<string, NativeOperation>;
|
|
142
|
+
}
|
|
143
|
+
export interface NativePackage {
|
|
144
|
+
id: string;
|
|
145
|
+
version: string;
|
|
146
|
+
displayName: string;
|
|
147
|
+
}
|
|
148
|
+
export type NativeEntry = 'policy' | 'admin-only' | 'app-privilege';
|
|
149
|
+
export type NativeFeature = 'native-http-v1' | 'auth-header-v1' | 'auth-greader-client-login-v1' | 'paginate-http-v1' | 'ndjson-http-v1' | 'upload-http-v1' | 'download-file-v1';
|
|
150
|
+
export interface NativeInventory {
|
|
151
|
+
upstreamAuthPaths: string[];
|
|
152
|
+
format: 'synopkgland.http-inventory';
|
|
153
|
+
version: 1;
|
|
154
|
+
package: NativePackage;
|
|
155
|
+
entry: NativeEntry;
|
|
156
|
+
entryPolicyDigest: string;
|
|
157
|
+
basePath: string;
|
|
158
|
+
registrySha256: string;
|
|
159
|
+
authSha256: string;
|
|
160
|
+
bindings: Record<string, NativeInventoryBinding>;
|
|
161
|
+
}
|
|
162
|
+
export interface NativeDescriptor {
|
|
163
|
+
format: 'synopkgland.api';
|
|
164
|
+
version: 3;
|
|
165
|
+
payload: {
|
|
166
|
+
package: NativePackage;
|
|
167
|
+
aliases: string[];
|
|
168
|
+
provenance: {
|
|
169
|
+
developedBy: 'synopkgland' | 'third-party' | 'unknown';
|
|
170
|
+
generator: string;
|
|
171
|
+
};
|
|
172
|
+
entry: NativeEntry;
|
|
173
|
+
transport: {
|
|
174
|
+
path: string;
|
|
175
|
+
auth: 'dsm-session';
|
|
176
|
+
};
|
|
177
|
+
execution: NativeHttp & {
|
|
178
|
+
type: 'native-http';
|
|
179
|
+
};
|
|
180
|
+
features: NativeFeature[];
|
|
181
|
+
entryPolicyDigest: string;
|
|
182
|
+
registrySha256: string;
|
|
183
|
+
inventorySha256: string;
|
|
184
|
+
authSha256: string;
|
|
185
|
+
bindings: Record<string, NativeInventoryBinding>;
|
|
186
|
+
commands: Record<string, NativeOperation>;
|
|
187
|
+
};
|
|
188
|
+
sha256: string;
|
|
189
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/nas/store.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DsmSession } from './transport.js';
|
|
2
2
|
import type { HostTls } from './tls.js';
|
|
3
|
+
import { NativeCredentialStore } from '../ctl/native-store.js';
|
|
3
4
|
export interface Approval {
|
|
4
5
|
version: string;
|
|
5
6
|
hash?: string;
|
|
@@ -30,7 +31,8 @@ export declare class OsCredentialStore implements CredentialStore {
|
|
|
30
31
|
export declare class CtlStore {
|
|
31
32
|
root: string;
|
|
32
33
|
credentials: CredentialStore;
|
|
33
|
-
|
|
34
|
+
native: NativeCredentialStore;
|
|
35
|
+
constructor(root?: string, credentials?: CredentialStore, native?: NativeCredentialStore);
|
|
34
36
|
private safe;
|
|
35
37
|
private file;
|
|
36
38
|
key(host: Host): string;
|
package/dist/nas/store.js
CHANGED
|
@@ -7,6 +7,7 @@ import { loginDsm } from './auth.js';
|
|
|
7
7
|
import { createRequest, canonicalOrigin } from './transport.js';
|
|
8
8
|
import { nasOptions } from './options.js';
|
|
9
9
|
import { publicDescriptor } from '../ctl/redaction.js';
|
|
10
|
+
import { NativeCredentialStore, nativeHostScope } from '../ctl/native-store.js';
|
|
10
11
|
export class OsCredentialStore {
|
|
11
12
|
async entry(key) { try {
|
|
12
13
|
const { AsyncEntry } = await import('@napi-rs/keyring');
|
|
@@ -40,9 +41,11 @@ export class OsCredentialStore {
|
|
|
40
41
|
export class CtlStore {
|
|
41
42
|
root;
|
|
42
43
|
credentials;
|
|
43
|
-
|
|
44
|
+
native;
|
|
45
|
+
constructor(root = process.env.SYNOPKGLAND_CTL_DIR ?? join(homedir(), '.synopkgland', 'ctl'), credentials = new OsCredentialStore(), native) {
|
|
44
46
|
this.root = root;
|
|
45
47
|
this.credentials = credentials;
|
|
48
|
+
this.native = native ?? new NativeCredentialStore(root);
|
|
46
49
|
}
|
|
47
50
|
safe(name) { if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$/.test(name))
|
|
48
51
|
throw new CtlError('CTL_HOST_INVALID', 'Invalid host name.', 'Use letters, digits, dots, dashes or underscores.'); return name; }
|
|
@@ -139,6 +142,6 @@ export class CtlStore {
|
|
|
139
142
|
}
|
|
140
143
|
putFailure(host, pkg, version, failure) { mkdirSync(this.cacheRoot(host), { recursive: true, mode: 0o700 }); const file = this.cacheFile(host, pkg, version), tmp = file + '.' + randomUUID(); writeFileSync(tmp, JSON.stringify({ failure }), { mode: 0o600 }); renameSync(tmp, file); }
|
|
141
144
|
revoke(name, pkg) { const host = this.get(name); delete host.approved[pkg]; this.save(host); rmSync(this.cacheRoot(host), { recursive: true, force: true }); return { revoked: pkg, cacheCleared: true }; }
|
|
142
|
-
async remove(name) { const host = this.get(name); await this.credentials.delete(this.key(host)); rmSync(this.cacheRoot(host), { recursive: true, force: true }); rmSync(this.file(name)); if (this.defaultName() === name)
|
|
143
|
-
rmSync(join(this.root, 'default.json'), { force: true }); return { removed: name, deleted: ['session', 'SynoToken', 'device token', 'App approvals', 'hash pins', 'list cache', 'host registration'] }; }
|
|
145
|
+
async remove(name) { const host = this.get(name); await this.native.removeHost(nativeHostScope(host)); await this.credentials.delete(this.key(host)); rmSync(this.cacheRoot(host), { recursive: true, force: true }); rmSync(this.file(name)); if (this.defaultName() === name)
|
|
146
|
+
rmSync(join(this.root, 'default.json'), { force: true }); return { removed: name, deleted: ['session', 'SynoToken', 'device token', 'App approvals', 'hash pins', 'list cache', 'host registration', 'native credentials'] }; }
|
|
144
147
|
}
|
package/dist/nas/transport.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export interface DsmSession {
|
|
|
10
10
|
deviceId?: string;
|
|
11
11
|
}
|
|
12
12
|
export type JsonRequest = (path: string, body: URLSearchParams | Record<string, unknown>, session?: DsmSession, signal?: AbortSignal) => Promise<any>;
|
|
13
|
+
export type NasHttpResponseHeaders = http.IncomingHttpHeaders;
|
|
13
14
|
export declare function canonicalOrigin(input: string, tunnel?: boolean): string;
|
|
14
15
|
export declare function createRequest(origin: string, timeoutMs?: number | (() => number) | undefined, ca?: string, trust?: HostTls): JsonRequest;
|
|
15
16
|
export declare function sessionFetch(url: string, init: RequestInit, session: DsmSession | undefined, ca?: string, trust?: HostTls, timeoutMs?: number): Promise<Response>;
|