@synopackageland/cli 0.47.4 → 0.48.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 +13 -0
- package/README.md +20 -20
- package/assets/go/route-audit/main.go +1 -1
- package/assets/init-compose.md +1 -1
- package/dist/add.js +10 -0
- package/dist/cli.js +9 -1
- package/dist/ctl/ai-tools.d.ts +29 -0
- package/dist/ctl/ai-tools.js +28 -0
- package/dist/ctl/cli.d.ts +5 -2
- package/dist/ctl/cli.js +34 -1
- package/dist/ctl/descriptor.d.ts +7 -3
- package/dist/ctl/descriptor.js +24 -4
- package/dist/ctl/generate.d.ts +1 -0
- package/dist/ctl/generate.js +16 -0
- package/dist/ctl/import-openapi.d.ts +8 -0
- package/dist/ctl/import-openapi.js +149 -0
- package/dist/ctl/registry.d.ts +47 -0
- package/dist/ctl/registry.js +119 -0
- package/dist/error-registry.js +8 -5
- package/dist/init-upstream.js +3 -2
- package/dist/init.js +22 -4
- package/dist/runtime/sdk-source.d.ts +1 -1
- package/dist/runtime/sdk-source.js +1 -1
- package/dist/standalone/api-description-inspect.js +3 -0
- package/dist/standalone/api-description.d.ts +6 -1
- package/dist/standalone/api-description.js +35 -57
- package/dist/standalone/api-permissions.d.ts +3 -1
- package/dist/standalone/api-permissions.js +14 -6
- package/dist/standalone/bridge-build.js +8 -2
- package/dist/standalone/bridge-runtime.d.ts +1 -0
- package/dist/standalone/bridge-runtime.js +1 -0
- package/dist/standalone/build.js +2 -1
- package/dist/standalone/manifest.d.ts +1 -0
- package/dist/standalone/manifest.js +17 -3
- package/dist/standalone/operation-registry.d.ts +13 -0
- package/dist/standalone/operation-registry.js +83 -0
- package/docs/ctl-external.md +5 -2
- package/package.json +2 -2
- package/schema/synopkgland-api-v2.schema.json +504 -0
- package/skills/SKILL.md +11 -10
- package/skills/reference/compose.md +3 -3
- package/skills/reference/create.md +8 -8
- package/skills/reference/ctl.md +81 -40
- package/skills/reference/files.md +1 -1
- package/skills/reference/identity-gateway.md +13 -19
- package/skills/reference/identity.md +3 -4
- package/skills/reference/install.md +2 -2
- package/skills/reference/portal.md +1 -1
- package/skills/reference/upstream-fork.md +11 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.48.1
|
|
4
|
+
|
|
5
|
+
- Align Go requirement messages, native build guidance and fixtures with Go 1.26.10 (#130)
|
|
6
|
+
- Pin the runtime SDK default to 0.47.1 and require templates ~0.39.2 with UI 0.19.5
|
|
7
|
+
|
|
8
|
+
## 0.48.0
|
|
9
|
+
|
|
10
|
+
- Generate permissions, runtime bindings, ctl commands, AI/MCP tools and App references from one synopkgland.api v2 operation registry
|
|
11
|
+
- Require explicit AI exposure classes and exact handler/spec equality; reject generated drift during check and build
|
|
12
|
+
- Import OpenAPI inventories hidden by default, with per-API opt-in and fork-owned output under synology/
|
|
13
|
+
- Run complete fixed flows for AI tools and return preview-only write drafts for human confirmation
|
|
14
|
+
- Use SDK/App 0.47.0 and templates 0.39.1; keep the skill and command guidance aligned with the current registry workflow
|
|
15
|
+
|
|
3
16
|
## 0.47.4
|
|
4
17
|
|
|
5
18
|
- Expose ctx.webApi in every generated DSM window, across all backend runtimes and desktop or full-page launches, using the existing session channel and DSM error codes
|
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Full documentation: <https://www.varvis.me/docs/> ([繁體中文](https://www.va
|
|
|
11
11
|
npm install -g @synopackageland/cli --registry=https://registry.npmjs.org
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
Native Go apps need Go 1.
|
|
14
|
+
Native Go apps need Go 1.26.10 and npm. The CLI is tested on Node.js 22.19.
|
|
15
15
|
|
|
16
16
|
## Quick start
|
|
17
17
|
|
|
@@ -89,11 +89,12 @@ alongside npm lockfiles. Do not disable checksum verification for public SDK
|
|
|
89
89
|
packages. Private mirrors can use explicitly configured Go authentication and
|
|
90
90
|
checksum settings; a failed fetch reports `SDK_DOWNLOAD_FAILED`.
|
|
91
91
|
|
|
92
|
-
The CLI pins SDK 0.
|
|
93
|
-
context. Explicit App SDK declarations take precedence. Templates use ~0.
|
|
92
|
+
The CLI pins SDK 0.47.1 for its daemon controllers, Compose planning and installer
|
|
93
|
+
context. Explicit App SDK declarations take precedence. Templates use ~0.39.2
|
|
94
94
|
and retain their own scaffold SDK pins; none declare daemon ingress.
|
|
95
|
-
Every App method
|
|
96
|
-
|
|
95
|
+
Every App method is declared once in operations.json; ctl generate writes the
|
|
96
|
+
permissions table and runtime bindings. Dynamic names and custom HTTP dispatchers
|
|
97
|
+
are rejected. Use fixed
|
|
97
98
|
`api.HandleHTTP` prefixes for authorized raw HTTP and `ipc.ServeUnix` for private
|
|
98
99
|
package Unix sockets. The audit follows each shipped Linux binary's import graph;
|
|
99
100
|
unimported development commands are excluded. Use
|
|
@@ -101,8 +102,8 @@ unimported development commands are excluded. Use
|
|
|
101
102
|
authentication. See [App entry and registration](docs/app-entry.md).
|
|
102
103
|
|
|
103
104
|
`init` and `add` read their templates from the locally installed
|
|
104
|
-
`@synopackageland/templates`. CLI 0.
|
|
105
|
-
update can select the latest templates patch in the 0.
|
|
105
|
+
`@synopackageland/templates`. CLI 0.48.1 depends on `~0.39.2`: npm installation or
|
|
106
|
+
update can select the latest templates patch in the 0.39 minor line. Templates
|
|
106
107
|
patches need only a templates release; update the npm installation to receive them.
|
|
107
108
|
The CLI never fetches templates at runtime, so offline use works after installation;
|
|
108
109
|
commit a lockfile and use `npm ci` to reproduce a chosen dependency tree.
|
|
@@ -110,8 +111,7 @@ The CLI accepts SDK executor manifest format 1 across SDK minor versions. The
|
|
|
110
111
|
exact SDK Go module sum anchors the build manifest; npm integrity anchors the
|
|
111
112
|
identical manifest in `@synopackageland/sdk/executor-manifest.json`. No manifest
|
|
112
113
|
is fetched at NAS runtime. Missing, malformed or unsupported new manifests fail
|
|
113
|
-
closed.
|
|
114
|
-
CLI runtime defaults use its pinned SDK independently of the templates. An SDK minor
|
|
114
|
+
closed. CLI runtime defaults use its pinned SDK independently of the templates. An SDK minor
|
|
115
115
|
release does not require a templates release; new CLI capabilities or a new manifest
|
|
116
116
|
format can still require one.
|
|
117
117
|
|
|
@@ -330,7 +330,7 @@ Third-party components keep their own terms.
|
|
|
330
330
|
- Keep `backend/THIRD_PARTY_NOTICES.txt` current when you change Go modules. Your own binaries,
|
|
331
331
|
added modules, container images and upstream apps need their own notices.
|
|
332
332
|
|
|
333
|
-
|
|
333
|
+
Declare delegated JSON WebAPI profiles:
|
|
334
334
|
|
|
335
335
|
```yaml
|
|
336
336
|
capabilities:
|
|
@@ -364,7 +364,7 @@ contract for the complete transport and CGI validation rules.
|
|
|
364
364
|
|
|
365
365
|
`webapi.call` request parameters are JSON-only; it has no request upload field.
|
|
366
366
|
Use streaming `files.write` for uploads, up to 100 MiB per file. Reads and URL
|
|
367
|
-
downloads retain their separate 64 MiB limit. Rebuild with SDK 0.
|
|
367
|
+
downloads retain their separate 64 MiB limit. Rebuild with SDK 0.47.1 and approve
|
|
368
368
|
the refreshed executor payload.
|
|
369
369
|
|
|
370
370
|
## App launch mode
|
|
@@ -423,14 +423,13 @@ or `portal`, or with `capabilities.rootOps`, `delegate`, `webapi` or
|
|
|
423
423
|
`identity`, whose approval or sign-in is shown in the SDK window
|
|
424
424
|
(`STANDALONE_UI_NO_WINDOW_INVALID`). A missing `ui` is still an error.
|
|
425
425
|
|
|
426
|
-
Gateway Apps
|
|
426
|
+
Gateway Apps include DSM-origin `sso/settings.cgi`
|
|
427
427
|
and default to `external_access: {connect: optional, origin_change: none}`.
|
|
428
428
|
Declare `identity_gateway.external_access.connect: none` to ignore Connect's
|
|
429
429
|
public URL projection; manual URLs remain available without Connect. Use
|
|
430
430
|
`origin_change: confirm` for Apps that need confirmation when their public
|
|
431
|
-
origin changes, and `single_origin: true`
|
|
432
|
-
works on one URL only. `connect: required` is rejected
|
|
433
|
-
with SDK older than 0.29.0 is rejected. Compose and gateway SDK pins must match.
|
|
431
|
+
origin changes, and `single_origin: true` for an upstream that
|
|
432
|
+
works on one URL only. `connect: required` is rejected. Compose and gateway SDK pins must match.
|
|
434
433
|
See [external access configuration](skills/reference/identity-gateway.md#external-access)
|
|
435
434
|
for the manifest, settings entry, URL rules and cold-login handoff.
|
|
436
435
|
|
|
@@ -578,7 +577,10 @@ override is supplied. After a network or job timeout, query the App's state befo
|
|
|
578
577
|
retrying a write.
|
|
579
578
|
|
|
580
579
|
Read `synopkgland skill show ctl` for the AI workflow, batch discovery approval,
|
|
581
|
-
cache refresh, host removal/revocation and
|
|
580
|
+
cache refresh, host removal/revocation and `ctl.registry` authoring with `synopkgland.api` v2. Run `ctl generate`,
|
|
581
|
+
`ctl generate --check` and `check`; generated tool lists and operation references
|
|
582
|
+
share the registry summaries. Import upstream OpenAPI with `ctl import-openapi`;
|
|
583
|
+
new entries stay hidden until the user opts in per API.
|
|
582
584
|
API descriptions are private SPK files named `synopkgland-api.json`, served
|
|
583
585
|
only by the authenticated fixed `synopkgland.describe` CGI operation.
|
|
584
586
|
|
|
@@ -608,7 +610,7 @@ single-call client. Rebuild the window with the current CLI/SDK to adopt it.
|
|
|
608
610
|
|
|
609
611
|
### DSM-managed gateway HTTPS
|
|
610
612
|
|
|
611
|
-
With
|
|
613
|
+
With a package target of DSM 7.2-64570 or later,
|
|
612
614
|
the build uses DSM's native web-config worker for a separate HTTPS App origin.
|
|
613
615
|
No Web Station dependency or executor capability is added. nginx inherits DSM's
|
|
614
616
|
system default certificate, which must be trusted by the browser and cover the
|
|
@@ -624,9 +626,7 @@ package start activates nginx.
|
|
|
624
626
|
|
|
625
627
|
Older SDK/DSM targets retain the direct listener and explain its certificate or
|
|
626
628
|
unencrypted-HTTP limitations before opening it. Native resource/startup failures
|
|
627
|
-
fail closed; they do not silently expose a direct listener. The native runtime
|
|
628
|
-
requires the corresponding SDK release; this CLI change does not publish that
|
|
629
|
-
release or change existing manifest version pins.
|
|
629
|
+
fail closed; they do not silently expose a direct listener. The native runtime uses the resolved SDK release; new scaffolds pin SDK 0.47.1.
|
|
630
630
|
|
|
631
631
|
Compose Apps may opt in to Intel render devices with
|
|
632
632
|
`compose.devices.gpu.services: [media]`. The matching SDK discovers exact devices
|
|
@@ -258,7 +258,7 @@ func reusesBoundary(expr ast.Node, owner source, sources []source, safe map[ast.
|
|
|
258
258
|
if sel, ok := call.Fun.(*ast.SelectorExpr); ok {
|
|
259
259
|
if id, ok := sel.X.(*ast.Ident); ok && imports[id.Name] == sdkModule+"/api" {
|
|
260
260
|
switch sel.Sel.Name {
|
|
261
|
-
case "NewServerWithPermissions":
|
|
261
|
+
case "NewServerWithPermissions", "NewServerWithOperations":
|
|
262
262
|
return false
|
|
263
263
|
case "WithRequestDeadline", "WithDescription", "WithObserver":
|
|
264
264
|
// WithObserver's callback runs after the SDK answered; only its
|
package/assets/init-compose.md
CHANGED
|
@@ -22,7 +22,7 @@ Application Portal. Headless Apps omit compose.web and have no launcher.
|
|
|
22
22
|
Compose ctl is unsupported.
|
|
23
23
|
|
|
24
24
|
Use supported upstream config files, environment, argv or reverse proxy for
|
|
25
|
-
login/settings. For integrated upstream Apps, select supported trusted-header authentication or disable upstream login behind the DSM admin gate; or use the existing SDK
|
|
25
|
+
login/settings. For integrated upstream Apps, select supported trusted-header authentication or disable upstream login behind the DSM admin gate; or use the existing SDK token adapter: OpenList uses mode: token, access: dsm-admins and entry: admin-only. Its unmodified admin token CLI supplies a package-private 0600 credential; the gateway injects Authorization server-side after DSM admission, without delivering it to the browser. All DSM admins share one upstream admin; token reset requires package restart; WebDAV keeps its own credentials. Verify each App adapter and DSM admission separately.
|
|
26
26
|
Containers use the package account and a dedicated bridge; they do not inherit
|
|
27
27
|
an interactive user's NAS ACL. Do not use root/chown during any App lifecycle
|
|
28
28
|
phase. Preserve licenses and dependency/source provenance. Read the CLI skill
|
package/dist/add.js
CHANGED
|
@@ -126,6 +126,8 @@ export function addCapabilities(root, requested) {
|
|
|
126
126
|
const permissions = `backend/${API_PERMISSIONS_FILE[m.backend.kind]}`;
|
|
127
127
|
if (added.includes('delegate') && !safePath(root, permissions))
|
|
128
128
|
conflicts.push(permissions);
|
|
129
|
+
if (m.ctl?.registry && !safePath(root, m.ctl.registry))
|
|
130
|
+
conflicts.push(m.ctl.registry);
|
|
129
131
|
if (!safePath(root, 'dsm-package.yaml'))
|
|
130
132
|
conflicts.push('dsm-package.yaml');
|
|
131
133
|
if (conflicts.length)
|
|
@@ -142,6 +144,14 @@ export function addCapabilities(root, requested) {
|
|
|
142
144
|
for (const file of deletions)
|
|
143
145
|
rmSync(join(root, file), { force: true });
|
|
144
146
|
writeFileSync(manifestPath, setTopLevel(text, { ...values, capabilities }));
|
|
147
|
+
if (m.ctl?.registry) {
|
|
148
|
+
const path = join(root, m.ctl.registry), registry = JSON.parse(readFileSync(path, 'utf8'));
|
|
149
|
+
const generatedRegistry = JSON.parse(readFileSync(join(generated, 'operations.json'), 'utf8'));
|
|
150
|
+
for (const [name, op] of Object.entries(generatedRegistry.operations))
|
|
151
|
+
if (!registry.operations[name])
|
|
152
|
+
registry.operations[name] = op;
|
|
153
|
+
writeFileSync(path, JSON.stringify(registry, null, 2) + '\n');
|
|
154
|
+
}
|
|
145
155
|
return withNotes({ added, unchanged }, notes);
|
|
146
156
|
}
|
|
147
157
|
finally {
|
package/dist/cli.js
CHANGED
|
@@ -376,7 +376,7 @@ async function runCliWithin(argv) {
|
|
|
376
376
|
.command("check")
|
|
377
377
|
.description("Validate the manifest, capability combination and Compose")
|
|
378
378
|
.option("--json", "Print a single JSON object")
|
|
379
|
-
.action((_options, command) => {
|
|
379
|
+
.action(async (_options, command) => {
|
|
380
380
|
const validation = validateProject(requireProject(rootOf(command)), {
|
|
381
381
|
profile: "personal",
|
|
382
382
|
});
|
|
@@ -391,6 +391,14 @@ async function runCliWithin(argv) {
|
|
|
391
391
|
: loadStandaloneManifest(standalone);
|
|
392
392
|
if (!loaded.ok)
|
|
393
393
|
throw failure(loaded.errors[0].code, loaded.errors.map((e) => `[${e.code}] ${e.message}`).join("\n"), "Update dsm-package.yaml to schema: 2, fix the declaration and retry.");
|
|
394
|
+
if ('ctl' in loaded.manifest && (loaded.manifest.ctl?.enabled || loaded.manifest.ctl?.registry)) {
|
|
395
|
+
const { generateOperations } = await import('./standalone/operation-registry.js');
|
|
396
|
+
const { spawnSync } = await import('node:child_process');
|
|
397
|
+
await generateOperations(loaded.manifest, (command, args, options) => {
|
|
398
|
+
const result = spawnSync(command, args, { cwd: options.cwd, env: options.env, encoding: 'utf8' });
|
|
399
|
+
return { status: result.status, stdout: result.stdout, stderr: result.stderr };
|
|
400
|
+
}, true);
|
|
401
|
+
}
|
|
394
402
|
const declared = "icon" in loaded.manifest && loaded.manifest.icon
|
|
395
403
|
? resolve(standalone, loaded.manifest.icon)
|
|
396
404
|
: undefined;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CtlClient, DiscoverOptions } from './service.js';
|
|
2
|
+
export declare function listAiTools(client: CtlClient, appName: string, options?: DiscoverOptions): Promise<{
|
|
3
|
+
package: {
|
|
4
|
+
id: string;
|
|
5
|
+
version: string;
|
|
6
|
+
displayName: string;
|
|
7
|
+
};
|
|
8
|
+
sha256: string;
|
|
9
|
+
tools: {
|
|
10
|
+
execution: string;
|
|
11
|
+
preview?: string | undefined;
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
inputSchema: Record<string, any>;
|
|
15
|
+
outputSchema: Record<string, any>;
|
|
16
|
+
annotations: {
|
|
17
|
+
readOnlyHint: boolean;
|
|
18
|
+
destructiveHint: boolean;
|
|
19
|
+
openWorldHint: boolean;
|
|
20
|
+
};
|
|
21
|
+
ai: "read" | "preview" | "draft" | "human-only" | "hidden";
|
|
22
|
+
flow: import("./descriptor.js").Flow;
|
|
23
|
+
}[];
|
|
24
|
+
}>;
|
|
25
|
+
/** A draft is always a preview and plan. This API has no write-confirmation input.
|
|
26
|
+
* Humans can execute the reviewed ctl plan separately with the normal --yes guard.
|
|
27
|
+
* Read tools run a complete fixed flow, including job polling or pagination.
|
|
28
|
+
*/
|
|
29
|
+
export declare function runAiTool(client: CtlClient, appName: string, method: string, params: Record<string, unknown>, options?: DiscoverOptions): Promise<any>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CtlError } from './errors.js';
|
|
2
|
+
import { registryTools } from './registry.js';
|
|
3
|
+
export async function listAiTools(client, appName, options = {}) {
|
|
4
|
+
const app = client.selectApp(await client.discover(options), appName);
|
|
5
|
+
if (app.version !== 2 || !app.payload.operations)
|
|
6
|
+
throw new CtlError('CTL_AI_REGISTRY_REQUIRED', 'AI tools require a v2 registry.', 'Migrate the App operation registry.', 5);
|
|
7
|
+
return { package: app.payload.package, sha256: app.sha256, tools: registryTools({ format: 'synopkgland.api', version: 2, operations: app.payload.operations }) };
|
|
8
|
+
}
|
|
9
|
+
/** A draft is always a preview and plan. This API has no write-confirmation input.
|
|
10
|
+
* Humans can execute the reviewed ctl plan separately with the normal --yes guard.
|
|
11
|
+
* Read tools run a complete fixed flow, including job polling or pagination.
|
|
12
|
+
*/
|
|
13
|
+
export async function runAiTool(client, appName, method, params, options = {}) {
|
|
14
|
+
const app = client.selectApp(await client.discover(options), appName);
|
|
15
|
+
const op = app.version === 2 ? app.payload.commands[method] : undefined;
|
|
16
|
+
if (!op || !['read', 'preview', 'draft'].includes(op.ai ?? ''))
|
|
17
|
+
throw new CtlError('CTL_AI_NOT_EXPOSED', 'Operation is not an AI tool.', 'Use the generated tool list.', 4);
|
|
18
|
+
const args = ['--input', '-'], stdin = JSON.stringify(params);
|
|
19
|
+
if (op.ai === 'draft') {
|
|
20
|
+
const preview = app.payload.commands[op.preview];
|
|
21
|
+
if (!preview || preview.ai !== 'preview' || preview.effect !== 'read')
|
|
22
|
+
throw new CtlError('CTL_AI_PREVIEW_REQUIRED', 'Draft requires a read-only preview.', 'Repair the operation registry.', 5);
|
|
23
|
+
const result = await client.execute(appName, preview.cli, args, { ...options, stdin });
|
|
24
|
+
const draft = await client.execute(appName, op.cli, args, { ...options, stdin, dryRun: true });
|
|
25
|
+
return { confirmationRequired: true, preview: result, draft };
|
|
26
|
+
}
|
|
27
|
+
return client.execute(appName, op.cli, args, { ...options, stdin });
|
|
28
|
+
}
|
package/dist/ctl/cli.d.ts
CHANGED
|
@@ -19,9 +19,12 @@ export declare function listView(host: string, apps: Descriptor[]): {
|
|
|
19
19
|
}[];
|
|
20
20
|
examples: string[];
|
|
21
21
|
summary: string;
|
|
22
|
+
ai?: import("./registry.js").AIClass;
|
|
23
|
+
preview?: string;
|
|
24
|
+
longRunning?: boolean;
|
|
22
25
|
cli: string[];
|
|
23
26
|
effect: "read" | "write" | "destructive";
|
|
24
|
-
permission: "public" | "authenticated" | "administrators";
|
|
27
|
+
permission: "public" | "authenticated" | "administrators" | "integration";
|
|
25
28
|
paramsSchema?: Record<string, any>;
|
|
26
29
|
resultSchema?: Record<string, any>;
|
|
27
30
|
flow: import("./descriptor.js").Flow;
|
|
@@ -37,7 +40,7 @@ export declare function listView(host: string, apps: Descriptor[]): {
|
|
|
37
40
|
displayName: string;
|
|
38
41
|
};
|
|
39
42
|
aliases: string[];
|
|
40
|
-
protocolVersion: 1;
|
|
43
|
+
protocolVersion: 2 | 1;
|
|
41
44
|
developedBy: string;
|
|
42
45
|
provenance: string;
|
|
43
46
|
hash: string;
|
package/dist/ctl/cli.js
CHANGED
|
@@ -11,7 +11,7 @@ import { canonicalOrigin, CTL_TIMEOUT_MS, createRequest } from './transport.js';
|
|
|
11
11
|
import { loginDsm, logoutDsm } from './dsm-auth.js';
|
|
12
12
|
import { publicOperation } from './redaction.js';
|
|
13
13
|
import { runExternal } from './external.js';
|
|
14
|
-
const USAGE = 'synopkgland host add|list|show|login|logout|remove|revoke|default|trust; ctl list [--host a,b|--all-hosts] [--app pkg] [--refresh]; ctl <alias|package> <command...> [typed flags|--input file|-] [--dry-run] [--yes]; NAS HTTPS accepts any certificate by default; --strict-tls or --ca <file> opts into verification';
|
|
14
|
+
const USAGE = 'synopkgland host add|list|show|login|logout|remove|revoke|default|trust; ctl generate [--check]; ctl import-openapi <file|https-url>; ctl tools <app>; ctl tool <app> <method> --input <file|->; ctl list [--host a,b|--all-hosts] [--app pkg] [--refresh]; ctl <alias|package> <command...> [typed flags|--input file|-] [--dry-run] [--yes]; NAS HTTPS accepts any certificate by default; --strict-tls or --ca <file> opts into verification';
|
|
15
15
|
async function prompt(message, secret = false) {
|
|
16
16
|
if (!process.stdin.isTTY)
|
|
17
17
|
throw new CtlError('CTL_INTERACTION_REQUIRED', 'Interactive input required.', 'Use --username and --password-stdin for host authentication.', 2);
|
|
@@ -69,6 +69,17 @@ function example(host, app, op) {
|
|
|
69
69
|
}
|
|
70
70
|
export function listView(host, apps) { return apps.map(app => ({ host, package: app.payload.package, aliases: app.payload.aliases, protocolVersion: app.version, developedBy: app.payload.provenance.developedBy, provenance: 'self-declared', hash: app.sha256, ...(app.payload.external ? { external: app.payload.external } : {}), commands: Object.entries(app.payload.commands).map(([id, original]) => { const op = publicOperation(original); return { id, ...op, parameters: op.paramsSchema ?? 'Undescribed parameters; use --input', flags: typedFlags(op), examples: example(host, app, op) }; }) })); }
|
|
71
71
|
export async function runCtl(argv, io = {}) {
|
|
72
|
+
if (argv[0] === 'generate' || argv[0] === 'import-openapi') {
|
|
73
|
+
try {
|
|
74
|
+
const data = argv[0] === 'generate' ? await (await import('./generate.js')).generateCommand(argv.slice(1)) : await (await import('./import-openapi.js')).importOpenApiCommand(argv.slice(1));
|
|
75
|
+
(io.out ?? console.log)(JSON.stringify({ ok: true, data }));
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
(io.out ?? console.log)(JSON.stringify({ ok: false, error: { code: /^(CTL_[A-Z_]+):/.exec(error.message)?.[1] ?? 'CTL_REGISTRY_ERROR', message: error.message } }));
|
|
79
|
+
process.exitCode = 5;
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
72
83
|
if (argv[0] === 'external')
|
|
73
84
|
return runExternal(argv.slice(1), io);
|
|
74
85
|
try {
|
|
@@ -97,6 +108,28 @@ async function runCtlWithin(argv, io = {}) {
|
|
|
97
108
|
const timeoutMs = timeout ? Number(timeout) * 1000 : CTL_TIMEOUT_MS;
|
|
98
109
|
const client = (host) => new CtlClient(store, host, io.requestFor?.(host), timeoutMs);
|
|
99
110
|
const discoverOptions = { refresh, app: appFilter, approve, confirm: tty ? async (packages) => /^y(es)?$/i.test(await ask('Allow DSM session to fixed description endpoints for ' + packages.map(p => p.id + '@' + p.version).join(', ') + '? [y/N] ')) : undefined };
|
|
111
|
+
if (args[0] === 'tools' || args[0] === 'tool') {
|
|
112
|
+
if (yes || dryRun || allHosts || approve || refresh)
|
|
113
|
+
throw new CtlError('CTL_ARGUMENT_INVALID', 'Tool commands do not accept mutation, approval or multi-host flags.', 'Use ctl tools <app> or ctl tool <app> <method> --input -.', 3);
|
|
114
|
+
const hosts = selectHosts(store.list().map(h => h.name), hostOption ?? store.defaultName(), false);
|
|
115
|
+
if (hosts.length !== 1 || !args[1])
|
|
116
|
+
throw new CtlError('CTL_ARGUMENT_INVALID', 'Select one host and App.', 'Use --host <profile>.', 3);
|
|
117
|
+
const { listAiTools, runAiTool } = await import('./ai-tools.js');
|
|
118
|
+
if (args[0] === 'tools') {
|
|
119
|
+
if (args.length !== 2)
|
|
120
|
+
throw new CtlError('CTL_ARGUMENT_INVALID', 'Unexpected tool-list arguments.', 'Use ctl tools <app>.', 3);
|
|
121
|
+
emit({ ok: true, data: await listAiTools(client(store.get(hosts[0])), args[1]) });
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (args.length !== 5 || args[3] !== '--input' || !args[4])
|
|
125
|
+
throw new CtlError('CTL_ARGUMENT_INVALID', 'Tool calls require a method and JSON input.', 'Use ctl tool <app> <method> --input <file|->.', 3);
|
|
126
|
+
const { strictJson } = await import('./json.js');
|
|
127
|
+
const params = strictJson(readBounded(args[4] === '-' ? 0 : args[4]));
|
|
128
|
+
if (!params || typeof params !== 'object' || Array.isArray(params))
|
|
129
|
+
throw new CtlError('CTL_PARAMS_INVALID', 'Tool input must be an object.', 'Use a JSON object.', 3);
|
|
130
|
+
emit({ ok: true, data: await runAiTool(client(store.get(hosts[0])), args[1], args[2], params) });
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
100
133
|
if (args[0] === 'host') {
|
|
101
134
|
const action = args[1], name = args[2];
|
|
102
135
|
if (help || !action) {
|
package/dist/ctl/descriptor.d.ts
CHANGED
|
@@ -3,9 +3,12 @@ export declare const DESCRIPTION_METHOD = "synopkgland.describe";
|
|
|
3
3
|
export declare const DESCRIPTION_FILE = "synopkgland-api.json";
|
|
4
4
|
export type Operation = {
|
|
5
5
|
summary: string;
|
|
6
|
+
ai?: import('./registry.js').AIClass;
|
|
7
|
+
preview?: string;
|
|
8
|
+
longRunning?: boolean;
|
|
6
9
|
cli: string[];
|
|
7
10
|
effect: 'read' | 'write' | 'destructive';
|
|
8
|
-
permission: 'public' | 'authenticated' | 'administrators';
|
|
11
|
+
permission: 'public' | 'authenticated' | 'administrators' | 'integration';
|
|
9
12
|
paramsSchema?: Record<string, any>;
|
|
10
13
|
resultSchema?: Record<string, any>;
|
|
11
14
|
examples?: Record<string, unknown>[];
|
|
@@ -46,7 +49,7 @@ export type Flow = {
|
|
|
46
49
|
};
|
|
47
50
|
export interface Binding {
|
|
48
51
|
effect: 'read' | 'write' | 'destructive';
|
|
49
|
-
permission: 'public' | 'authenticated' | 'administrators';
|
|
52
|
+
permission: 'public' | 'authenticated' | 'administrators' | 'integration';
|
|
50
53
|
}
|
|
51
54
|
export interface ApiPayload {
|
|
52
55
|
package: {
|
|
@@ -64,6 +67,7 @@ export interface ApiPayload {
|
|
|
64
67
|
path: string;
|
|
65
68
|
auth: string;
|
|
66
69
|
};
|
|
70
|
+
operations?: Record<string, import('./registry.js').RegisteredOperation>;
|
|
67
71
|
commands: Record<string, Operation>;
|
|
68
72
|
bindings: Record<string, Binding>;
|
|
69
73
|
external?: Record<string, {
|
|
@@ -72,7 +76,7 @@ export interface ApiPayload {
|
|
|
72
76
|
}
|
|
73
77
|
export interface Descriptor {
|
|
74
78
|
format: 'synopkgland.api';
|
|
75
|
-
version: 1;
|
|
79
|
+
version: 1 | 2;
|
|
76
80
|
payload: ApiPayload;
|
|
77
81
|
sha256: string;
|
|
78
82
|
}
|
package/dist/ctl/descriptor.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { validateRegistry, INFRASTRUCTURE_METHODS } from './registry.js';
|
|
1
2
|
import { readFileSync } from 'node:fs';
|
|
2
3
|
import { createHash } from 'node:crypto';
|
|
3
4
|
import { canonicalize } from 'json-canonicalize';
|
|
@@ -7,13 +8,14 @@ import { schemaRegExp } from './pattern.js';
|
|
|
7
8
|
export const DESCRIPTION_METHOD = 'synopkgland.describe';
|
|
8
9
|
export const DESCRIPTION_FILE = 'synopkgland-api.json';
|
|
9
10
|
export const ajv = new Ajv2020.default({ allErrors: true, strict: false, validateFormats: false, addUsedSchema: false, code: { regExp: schemaRegExp } });
|
|
11
|
+
const descriptorSchemaV2 = ajv.compile(JSON.parse(readFileSync(new URL('../../schema/synopkgland-api-v2.schema.json', import.meta.url), 'utf8')));
|
|
10
12
|
const descriptorSchema = ajv.compile(JSON.parse(readFileSync(new URL('../../schema/synopkgland-api-v1.schema.json', import.meta.url), 'utf8')));
|
|
11
|
-
export function makeDescriptor(payload) { const value = { format: 'synopkgland.api', version: 1, payload }; return { ...value, sha256: createHash('sha256').update(canonicalize(value)).digest('hex') }; }
|
|
13
|
+
export function makeDescriptor(payload) { const value = { format: 'synopkgland.api', version: (payload.operations ? 2 : 1), payload }; return { ...value, sha256: createHash('sha256').update(canonicalize(value)).digest('hex') }; }
|
|
12
14
|
export function validateDescriptor(value, id, version) {
|
|
13
15
|
const fail = (message) => { throw new CtlError('CTL_DESCRIPTOR_INVALID', message, 'run: synopkgland ctl list --refresh', 5); };
|
|
14
|
-
if (!value || value.format !== 'synopkgland.api' || value.version
|
|
16
|
+
if (!value || value.format !== 'synopkgland.api' || ![1, 2].includes(value.version) || !value.payload || !/^([0-9a-f]{64})$/.test(value.sha256))
|
|
15
17
|
return fail('Unsupported API description format.');
|
|
16
|
-
if (!descriptorSchema(value))
|
|
18
|
+
if (!(value.version === 2 ? descriptorSchemaV2 : descriptorSchema)(value))
|
|
17
19
|
return fail('API description schema validation failed.');
|
|
18
20
|
const p = value.payload;
|
|
19
21
|
if (p.package?.id !== id || p.package?.version !== version)
|
|
@@ -24,10 +26,28 @@ export function validateDescriptor(value, id, version) {
|
|
|
24
26
|
return fail('API endpoint must be the fixed CGI of its own package.');
|
|
25
27
|
if (!['admin-only', 'app-privilege', 'policy'].includes(p.entry) || !['synopkgland', 'third-party', 'unknown'].includes(p.provenance?.developedBy) || typeof p.provenance?.generator !== 'string')
|
|
26
28
|
return fail('Invalid API metadata.');
|
|
27
|
-
if (!p.commands || Array.isArray(p.commands) || typeof p.commands !== 'object' || Object.keys(p.commands).length < 1 || Object.keys(p.commands).length > 1024)
|
|
29
|
+
if (!p.commands || Array.isArray(p.commands) || typeof p.commands !== 'object' || (value.version === 1 && Object.keys(p.commands).length < 1) || Object.keys(p.commands).length > 1024)
|
|
28
30
|
return fail('Invalid command allowlist.');
|
|
29
31
|
if (!p.bindings || typeof p.bindings !== 'object')
|
|
30
32
|
return fail('Missing internal method bindings.');
|
|
33
|
+
if (value.version === 2) {
|
|
34
|
+
try {
|
|
35
|
+
validateRegistry({ format: 'synopkgland.api', version: 2, operations: p.operations });
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return fail('Invalid operation registry.');
|
|
39
|
+
}
|
|
40
|
+
const expected = Object.fromEntries(Object.entries(p.operations).filter(([, op]) => op.ai !== 'hidden'));
|
|
41
|
+
if (canonicalize(expected) !== canonicalize(p.commands))
|
|
42
|
+
return fail('Commands differ from the operation registry.');
|
|
43
|
+
for (const [name, op] of Object.entries(p.operations)) {
|
|
44
|
+
const b = p.bindings[name];
|
|
45
|
+
if (!b || b.effect !== op.effect || b.permission !== op.permission)
|
|
46
|
+
return fail('Operation binding mismatch.');
|
|
47
|
+
}
|
|
48
|
+
if (Object.keys(p.bindings).some(name => !Object.hasOwn(p.operations, name) && !INFRASTRUCTURE_METHODS.has(name)))
|
|
49
|
+
return fail('Binding has no operation spec.');
|
|
50
|
+
}
|
|
31
51
|
const externalMethods = new Set();
|
|
32
52
|
for (const entry of Object.values(p.external ?? {})) {
|
|
33
53
|
const binding = p.bindings[entry.method];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function generateCommand(args: string[]): Promise<unknown>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { loadStandaloneManifest } from '../standalone/manifest.js';
|
|
2
|
+
import { generateOperations } from '../standalone/operation-registry.js';
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
export async function generateCommand(args) {
|
|
5
|
+
const check = args.includes('--check'), rest = args.filter(a => a !== '--check' && a !== '--json');
|
|
6
|
+
if (rest.length)
|
|
7
|
+
throw Error('Usage: synopkgland ctl generate [--check] [--json]');
|
|
8
|
+
const loaded = loadStandaloneManifest(process.cwd());
|
|
9
|
+
if (!loaded.ok)
|
|
10
|
+
throw Error(loaded.errors.map(e => e.message).join('\n'));
|
|
11
|
+
const result = await generateOperations(loaded.manifest, async (command, argv, options) => {
|
|
12
|
+
const result = spawnSync(command, argv, { cwd: options?.cwd, env: options?.env, encoding: 'utf8' });
|
|
13
|
+
return { status: result.status ?? 1, stdout: result.stdout ?? '', stderr: result.stderr ?? '' };
|
|
14
|
+
}, check);
|
|
15
|
+
return { checked: check, sha256: result.description.sha256 };
|
|
16
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type OperationRegistry } from './registry.js';
|
|
2
|
+
/** Import is an inventory, never an authorization or a transport adapter. */
|
|
3
|
+
export declare function importOpenApi(document: any): OperationRegistry;
|
|
4
|
+
export declare function importOpenApiCommand(args: string[]): Promise<{
|
|
5
|
+
imported: number;
|
|
6
|
+
ai: string;
|
|
7
|
+
next: string;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { readFileSync, existsSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
2
|
+
import { dirname, resolve } from 'node:path';
|
|
3
|
+
import { parseDocument } from 'yaml';
|
|
4
|
+
import { readRegistry, validateRegistry, registryFile } from './registry.js';
|
|
5
|
+
const MAX_BYTES = 1048576;
|
|
6
|
+
function objectSchema() { return { type: 'object', additionalProperties: false, properties: {} }; }
|
|
7
|
+
/** Import is an inventory, never an authorization or a transport adapter. */
|
|
8
|
+
export function importOpenApi(document) {
|
|
9
|
+
if (document?.format === 'synopkgland.api') {
|
|
10
|
+
const copy = structuredClone(document);
|
|
11
|
+
for (const op of Object.values(copy.operations ?? {}))
|
|
12
|
+
op.ai = 'hidden';
|
|
13
|
+
validateRegistry(copy);
|
|
14
|
+
return copy;
|
|
15
|
+
}
|
|
16
|
+
if (!/^3\.[01]\./.test(document?.openapi) || !document.paths || typeof document.paths !== 'object')
|
|
17
|
+
throw Error('CTL_IMPORT_INVALID: supply OpenAPI 3.0/3.1 or a handwritten synopkgland.api v2 registry.');
|
|
18
|
+
const operations = {};
|
|
19
|
+
const expand = (schema, seen = new Set()) => {
|
|
20
|
+
if (!schema || typeof schema !== 'object')
|
|
21
|
+
return schema;
|
|
22
|
+
if (schema.$ref) {
|
|
23
|
+
const ref = schema.$ref;
|
|
24
|
+
if (typeof ref !== 'string' || !ref.startsWith('#/') || seen.has(ref))
|
|
25
|
+
throw Error('CTL_IMPORT_UNSUPPORTED: external or recursive references require manual schemas.');
|
|
26
|
+
let target = document;
|
|
27
|
+
for (const key of ref.slice(2).split('/'))
|
|
28
|
+
target = target?.[key.replaceAll('~1', '/').replaceAll('~0', '~')];
|
|
29
|
+
if (!target)
|
|
30
|
+
throw Error('CTL_IMPORT_INVALID: unresolved local reference.');
|
|
31
|
+
return expand({ ...target, ...Object.fromEntries(Object.entries(schema).filter(([k]) => k !== '$ref')) }, new Set([...seen, ref]));
|
|
32
|
+
}
|
|
33
|
+
if (Array.isArray(schema))
|
|
34
|
+
return schema.map(s => expand(s, seen));
|
|
35
|
+
const out = Object.fromEntries(Object.entries(schema).map(([k, v]) => [k, expand(v, seen)]));
|
|
36
|
+
if (out.nullable === true) {
|
|
37
|
+
delete out.nullable;
|
|
38
|
+
if (typeof out.type === 'string')
|
|
39
|
+
out.type = [out.type, 'null'];
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
};
|
|
43
|
+
for (const [path, item] of Object.entries(document.paths)) {
|
|
44
|
+
if (!path.startsWith('/') || path.includes('?') || path.includes('#'))
|
|
45
|
+
throw Error('CTL_IMPORT_INVALID: invalid upstream path.');
|
|
46
|
+
if (item.$ref)
|
|
47
|
+
throw Error('CTL_IMPORT_UNSUPPORTED: expand path references before importing.');
|
|
48
|
+
for (const verb of ['get', 'post', 'put', 'patch', 'delete', 'head', 'options']) {
|
|
49
|
+
const raw = item[verb];
|
|
50
|
+
if (!raw)
|
|
51
|
+
continue;
|
|
52
|
+
const slug = String(raw.operationId ?? `${verb}_${path}`).replace(/([a-z0-9])([A-Z])/g, '$1_$2').replace(/[^a-zA-Z0-9_]+/g, '_').replace(/^_+|_+$/g, '').toLowerCase();
|
|
53
|
+
const name = `upstream.${/^[a-z]/.test(slug) ? slug : 'operation_' + slug}`;
|
|
54
|
+
if (Object.hasOwn(operations, name))
|
|
55
|
+
throw Error('CTL_IMPORT_INVALID: duplicate imported method.');
|
|
56
|
+
const params = objectSchema(), required = [];
|
|
57
|
+
const parameters = new Map();
|
|
58
|
+
for (const p of [...(item.parameters ?? []), ...(raw.parameters ?? [])]) {
|
|
59
|
+
const param = expand(p);
|
|
60
|
+
parameters.set(`${param.in}:${param.name}`, param);
|
|
61
|
+
}
|
|
62
|
+
for (const p of parameters.values()) {
|
|
63
|
+
if (!['path', 'query', 'header', 'cookie'].includes(p.in) || !p.name || !p.schema)
|
|
64
|
+
throw Error('CTL_IMPORT_UNSUPPORTED: parameters require a location, name and schema.');
|
|
65
|
+
// Retain locations as objects, so same-name path/query arguments cannot collide.
|
|
66
|
+
const group = params.properties[p.in] ??= objectSchema();
|
|
67
|
+
group.properties[p.name] = expand(p.schema);
|
|
68
|
+
if (p.required) {
|
|
69
|
+
(group.required ??= []).push(p.name);
|
|
70
|
+
if (!required.includes(p.in))
|
|
71
|
+
required.push(p.in);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (raw.requestBody) {
|
|
75
|
+
const body = expand(raw.requestBody), schema = body.content?.['application/json']?.schema;
|
|
76
|
+
if (!schema)
|
|
77
|
+
throw Error('CTL_IMPORT_UNSUPPORTED: non-JSON bodies require a hand-written upload spec.');
|
|
78
|
+
params.properties.body = expand(schema);
|
|
79
|
+
if (body.required)
|
|
80
|
+
required.push('body');
|
|
81
|
+
}
|
|
82
|
+
if (required.length)
|
|
83
|
+
params.required = required;
|
|
84
|
+
const response = Object.entries(raw.responses ?? {}).find(([status]) => /^2\d\d$/.test(status))?.[1];
|
|
85
|
+
const resolved = response ? expand(response) : undefined;
|
|
86
|
+
const result = resolved?.content?.['application/json']?.schema ?? {};
|
|
87
|
+
operations[name] = { summary: raw.summary ?? raw.description ?? `${verb.toUpperCase()} ${path}`, cli: ['upstream', slug.replaceAll('_', '-')], ai: 'hidden', effect: ['get', 'head', 'options'].includes(verb) ? 'read' : 'destructive', permission: 'administrators', paramsSchema: params, resultSchema: expand(result), flow: { type: 'invoke', method: name }, upstream: { method: verb.toUpperCase(), path } };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const registry = { format: 'synopkgland.api', version: 2, operations };
|
|
91
|
+
validateRegistry(registry);
|
|
92
|
+
return registry;
|
|
93
|
+
}
|
|
94
|
+
export async function importOpenApiCommand(args) {
|
|
95
|
+
const rest = args.filter(a => a !== '--json'), input = rest.shift();
|
|
96
|
+
const fork = existsSync('synology/dsm-package.yaml') && !existsSync('dsm-package.yaml');
|
|
97
|
+
let output = fork ? 'synology/operations.json' : 'operations.json';
|
|
98
|
+
if (rest[0] === '--output' && rest[1]) {
|
|
99
|
+
output = rest[1];
|
|
100
|
+
rest.splice(0, 2);
|
|
101
|
+
}
|
|
102
|
+
if (!input || rest.length)
|
|
103
|
+
throw Error('Usage: synopkgland ctl import-openapi <file|https-url> [--output operations.json]');
|
|
104
|
+
let raw;
|
|
105
|
+
if (/^https?:/.test(input)) {
|
|
106
|
+
const url = new URL(input);
|
|
107
|
+
if (url.protocol !== 'https:' || url.username || url.password)
|
|
108
|
+
throw Error('CTL_IMPORT_URL: use HTTPS without credentials.');
|
|
109
|
+
const response = await fetch(url, { redirect: 'error', signal: AbortSignal.timeout(30000) });
|
|
110
|
+
if (!response.ok || Number(response.headers.get('content-length')) > MAX_BYTES)
|
|
111
|
+
throw Error('CTL_IMPORT_FAILED: upstream document unavailable or too large.');
|
|
112
|
+
const reader = response.body.getReader(), chunks = [];
|
|
113
|
+
let size = 0;
|
|
114
|
+
try {
|
|
115
|
+
while (true) {
|
|
116
|
+
const part = await reader.read();
|
|
117
|
+
if (part.done)
|
|
118
|
+
break;
|
|
119
|
+
size += part.value.length;
|
|
120
|
+
if (size > MAX_BYTES)
|
|
121
|
+
throw Error('CTL_IMPORT_INVALID: document exceeds 1 MiB.');
|
|
122
|
+
chunks.push(part.value);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
await reader.cancel();
|
|
127
|
+
}
|
|
128
|
+
raw = Buffer.concat(chunks).toString('utf8');
|
|
129
|
+
}
|
|
130
|
+
else
|
|
131
|
+
raw = readFileSync(input, 'utf8');
|
|
132
|
+
if (Buffer.byteLength(raw) > MAX_BYTES)
|
|
133
|
+
throw Error('CTL_IMPORT_INVALID: document exceeds 1 MiB.');
|
|
134
|
+
const parsed = parseDocument(raw, { uniqueKeys: true });
|
|
135
|
+
if (parsed.errors.length)
|
|
136
|
+
throw Error('CTL_IMPORT_INVALID: invalid document or duplicate keys.');
|
|
137
|
+
const imported = importOpenApi(parsed.toJS({ maxAliasCount: 0 })), path = resolve(output);
|
|
138
|
+
if (fork)
|
|
139
|
+
registryFile(resolve('synology'), path);
|
|
140
|
+
const registry = existsSync(path) ? readRegistry(path) : { format: 'synopkgland.api', version: 2, operations: {} };
|
|
141
|
+
// Never reset an explicitly reviewed operation, or overwrite its description/schema.
|
|
142
|
+
for (const [name, op] of Object.entries(imported.operations))
|
|
143
|
+
if (!Object.hasOwn(registry.operations, name))
|
|
144
|
+
registry.operations[name] = op;
|
|
145
|
+
validateRegistry(registry);
|
|
146
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
147
|
+
writeFileSync(path, JSON.stringify(registry, null, 2) + '\n');
|
|
148
|
+
return { imported: Object.keys(imported.operations).length, ai: 'hidden', next: 'Review each API by area before opting in; implement adapters through the existing ingress transport.' };
|
|
149
|
+
}
|