@synopackageland/cli 0.49.1 → 0.50.0

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.
Files changed (75) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +10 -0
  3. package/dist/ctl/ai-tools.d.ts +9 -1
  4. package/dist/ctl/ai-tools.js +4 -4
  5. package/dist/ctl/cli.d.ts +8 -1
  6. package/dist/ctl/cli.js +40 -5
  7. package/dist/ctl/descriptor.d.ts +15 -2
  8. package/dist/ctl/descriptor.js +9 -4
  9. package/dist/ctl/flows.js +2 -0
  10. package/dist/ctl/input.d.ts +5 -3
  11. package/dist/ctl/input.js +3 -3
  12. package/dist/ctl/native-auth-command.d.ts +9 -0
  13. package/dist/ctl/native-auth-command.js +98 -0
  14. package/dist/ctl/native-executor.d.ts +16 -0
  15. package/dist/ctl/native-executor.js +187 -0
  16. package/dist/ctl/native-file-types.d.ts +16 -0
  17. package/dist/ctl/native-file-types.js +57 -0
  18. package/dist/ctl/native-files.d.ts +13 -0
  19. package/dist/ctl/native-files.js +115 -0
  20. package/dist/ctl/native-metadata.d.ts +10 -0
  21. package/dist/ctl/native-metadata.js +50 -0
  22. package/dist/ctl/native-paths.d.ts +4 -0
  23. package/dist/ctl/native-paths.js +54 -0
  24. package/dist/ctl/native-protocol.d.ts +21 -0
  25. package/dist/ctl/native-protocol.js +150 -0
  26. package/dist/ctl/native-registry.d.ts +8 -0
  27. package/dist/ctl/native-registry.js +182 -0
  28. package/dist/ctl/native-schemas.d.ts +7 -0
  29. package/dist/ctl/native-schemas.js +25 -0
  30. package/dist/ctl/native-store.d.ts +61 -0
  31. package/dist/ctl/native-store.js +348 -0
  32. package/dist/ctl/native-transfers.d.ts +13 -0
  33. package/dist/ctl/native-transfers.js +331 -0
  34. package/dist/ctl/native-transport.d.ts +30 -0
  35. package/dist/ctl/native-transport.js +148 -0
  36. package/dist/ctl/native-types.d.ts +15 -0
  37. package/dist/ctl/native-types.js +1 -0
  38. package/dist/ctl/registry.d.ts +5 -4
  39. package/dist/ctl/registry.js +12 -1
  40. package/dist/ctl/service.d.ts +32 -1
  41. package/dist/ctl/service.js +122 -1
  42. package/dist/error-registry.js +15 -0
  43. package/dist/generated/native-http.d.ts +189 -0
  44. package/dist/generated/native-http.js +1 -0
  45. package/dist/nas/store.d.ts +3 -1
  46. package/dist/nas/store.js +6 -3
  47. package/dist/nas/transport.d.ts +1 -0
  48. package/dist/native-http-schema/descriptor.schema.json +242 -0
  49. package/dist/native-http-schema/inventory.schema.json +121 -0
  50. package/dist/native-http-schema/registry.schema.json +872 -0
  51. package/dist/native-http-schema/source.json +1 -0
  52. package/dist/runtime/sdk-source.d.ts +1 -1
  53. package/dist/runtime/sdk-source.js +1 -1
  54. package/dist/standalone/api-description.d.ts +2 -5
  55. package/dist/standalone/build.js +5 -1
  56. package/dist/standalone/compose-errors.js +5 -0
  57. package/dist/standalone/inspect-spk.js +2 -17
  58. package/dist/standalone/lifecycle.js +9 -2
  59. package/dist/standalone/manifest.d.ts +1 -0
  60. package/dist/standalone/manifest.js +22 -5
  61. package/dist/standalone/native-http-inspect.d.ts +9 -0
  62. package/dist/standalone/native-http-inspect.js +43 -0
  63. package/dist/standalone/native-http.d.ts +31 -0
  64. package/dist/standalone/native-http.js +120 -0
  65. package/dist/standalone/operation-registry.d.ts +2 -7
  66. package/dist/standalone/operation-registry.js +3 -0
  67. package/dist/standalone/spk.d.ts +1 -0
  68. package/dist/standalone/spk.js +15 -1
  69. package/package.json +2 -2
  70. package/schema/dsm-api-contract.json +8 -7
  71. package/skills/SKILL.md +2 -2
  72. package/skills/reference/compose.md +21 -0
  73. package/skills/reference/ctl.md +198 -0
  74. package/skills/reference/daemon-mode.md +1 -1
  75. package/skills/reference/upstream-fork.md +5 -2
@@ -4,6 +4,11 @@ import { DESCRIPTION_METHOD, validateDescriptor, ajv } from './descriptor.js';
4
4
  import { runFlow } from './flows.js';
5
5
  import { localFile, transferRequest } from './transfers.js';
6
6
  import { selectApp, selectOperation, operationInput, requestPlan, confirmOperation } from './input.js';
7
+ import { nativeScope, nativeHostScope } from './native-store.js';
8
+ import { createNativeTransport } from './native-transport.js';
9
+ import { authorization, enrollNative } from './native-protocol.js';
10
+ import { executeNative } from './native-executor.js';
11
+ import { createNativeTransfer } from './native-transfers.js';
7
12
  export async function boundedMap(items, limit, fn) { const output = new Array(items.length); let next = 0; await Promise.all(Array.from({ length: Math.min(limit, items.length) }, async () => { while (next < items.length) {
8
13
  const index = next++;
9
14
  output[index] = await fn(items[index]);
@@ -11,12 +16,79 @@ export async function boundedMap(items, limit, fn) { const output = new Array(it
11
16
  export class CtlClient {
12
17
  store;
13
18
  host;
19
+ timeoutMs;
20
+ nativeOptions;
14
21
  request;
15
- constructor(store, host, request, timeoutMs = CTL_TIMEOUT_MS) {
22
+ constructor(store, host, request, timeoutMs = CTL_TIMEOUT_MS, nativeOptions = {}) {
16
23
  this.store = store;
17
24
  this.host = host;
25
+ this.timeoutMs = timeoutMs;
26
+ this.nativeOptions = nativeOptions;
18
27
  this.request = request ?? createRequest(host.origin, () => this.remaining(timeoutMs), undefined, store.trust(host));
19
28
  }
29
+ nativeApproved(app) {
30
+ const host = this.store.get(this.host.name), approval = host.approved[app.payload.package.id];
31
+ if (host.origin !== this.host.origin || host.username !== this.host.username || approval?.version !== app.payload.package.version || approval.hash !== app.sha256)
32
+ throw this.needsApproval(app.payload.package);
33
+ }
34
+ nativeTransport(app, auth) {
35
+ const execution = app.payload.execution;
36
+ if (!execution)
37
+ throw new CtlError('CTL_NATIVE_TRANSPORT_REQUIRED', 'App does not declare native HTTP.', 'Use ordinary ctl commands for this App.', 5);
38
+ const transport = this.nativeOptions.transportFor?.(app, auth) ?? createNativeTransport(this.host.origin, execution.basePath, this.nativePaths(app).map(path => path.split('/{')[0]), this.store.trust(this.host), auth === undefined ? undefined : () => auth, this.nativePaths(app));
39
+ return input => { this.nativeApproved(app); return transport({ ...input, timeoutMs: input.timeoutMs ?? this.timeoutMs }); };
40
+ }
41
+ nativePaths(app) {
42
+ const auth = app.payload.execution.auth;
43
+ return [...Object.values(app.payload.commands).map(op => op.http.path), ...(auth.type === 'header' ? [auth.verify.path] : [auth.exchangePath, auth.identityPath, auth.actionTokenPath])];
44
+ }
45
+ nativeGuidance(app) { const http = app.payload.execution; return { scheme: http.auth.type, credentialUrl: this.host.origin + http.basePath + http.auth.credentialPage, instructions: http.auth.instructions, command: `synopkgland ctl auth --host ${this.host.name} --app ${app.payload.package.id}` }; }
46
+ async nativeStoreKind(app) { return this.store.native.kind(nativeScope(this.host, app.payload.package.id, { authSha256: app.payload.authSha256 })); }
47
+ async nativeState(app) { return { ...this.nativeGuidance(app), state: await this.store.native.state(nativeScope(this.host, app.payload.package.id, { authSha256: app.payload.authSha256 })) }; }
48
+ nativeRequired(app) {
49
+ const guide = this.nativeGuidance(app);
50
+ return new CtlError('CTL_NATIVE_AUTH_REQUIRED', 'Native App credential is missing. Ask the user to run ctl auth in their own terminal; never request a token in chat.', `${guide.command}; credential location: ${guide.credentialUrl}; ${guide.instructions}`, 2);
51
+ }
52
+ async freshNative(app) {
53
+ const assertApproval = () => this.nativeApproved(app);
54
+ assertApproval();
55
+ const session = await this.store.session(this.host);
56
+ const pkg = (await this.inventory(session)).find(pkg => pkg.id === app.payload.package.id);
57
+ if (!pkg || pkg.version !== app.payload.package.version)
58
+ throw this.needsApproval(pkg ?? app.payload.package);
59
+ assertApproval();
60
+ const response = await this.request(app.payload.transport.path, { method: DESCRIPTION_METHOD, params: {} }, session);
61
+ if (response?.success !== true)
62
+ throw new CtlError('CTL_PERMISSION_DENIED', 'Native metadata admission was refused.', 'Restore DSM login and App entry permission.', 4);
63
+ const fresh = validateDescriptor(response.data, pkg.id, pkg.version);
64
+ if (fresh.sha256 !== app.sha256 || fresh.version !== 3)
65
+ throw this.needsApproval(fresh.payload.package);
66
+ assertApproval();
67
+ // A concurrent logout cannot be hidden by the already loaded DSM carriers.
68
+ if (!process.env.DSM_PASSWORD) {
69
+ const current = await this.store.credentials.get(this.store.key(this.host));
70
+ if (current?.cookie !== session.cookie || current?.token !== session.token)
71
+ throw new CtlError('CTL_NOT_AUTHENTICATED', 'DSM login changed during admission.', 'Run host login in your own terminal.', 2);
72
+ }
73
+ return fresh;
74
+ }
75
+ async authApp(name, options = {}) {
76
+ const app = this.selectApp(await this.discover({ ...options, app: name, refresh: true }), name);
77
+ if (app.version !== 3 || !app.payload.execution)
78
+ throw new CtlError('CTL_NATIVE_TRANSPORT_REQUIRED', 'App does not declare native credential authentication.', 'Use its declared transport.', 5);
79
+ return app;
80
+ }
81
+ async resetNative(app) { await this.store.native.delete(nativeScope(this.host, app.payload.package.id, { authSha256: app.payload.authSha256 })); }
82
+ async enroll(app, input, store = 'keychain', confirm) {
83
+ // Recheck admission before touching auth input or overwriting a local credential.
84
+ await this.freshNative(app);
85
+ const record = await enrollNative(app.payload.execution, input, auth => { const transport = this.nativeTransport(app, auth); return request => transport({ ...request, signal: AbortSignal.timeout(this.timeoutMs) }); });
86
+ if (confirm && !await confirm(record.identity ?? {}))
87
+ throw new CtlError('CTL_CONFIRM_REQUIRED', 'Native identity was not confirmed.', 'Run ctl auth again in your own terminal.', 7);
88
+ // Check local approval again after the human identity confirmation.
89
+ this.nativeApproved(app);
90
+ await this.store.native.set(nativeScope(this.host, app.payload.package.id, { authSha256: app.payload.authSha256 }), nativeHostScope(this.host), record, store);
91
+ }
20
92
  until;
21
93
  jobRequestBudget;
22
94
  remaining(fallback) { return this.jobRequestBudget ?? (this.until === undefined ? fallback : Math.max(0, this.until - performance.now())); }
@@ -51,6 +123,8 @@ export class CtlClient {
51
123
  return listing.apps.find(app => app.payload.package.id === pkg.id);
52
124
  }
53
125
  async discover(options = {}) {
126
+ if (!this.host.ephemeral)
127
+ this.host = this.store.get(this.host.name);
54
128
  const session = await this.store.session(this.host);
55
129
  let packages = (await this.inventory(session)).map(pkg => {
56
130
  const approved = this.host.approved[pkg.id];
@@ -67,9 +141,11 @@ export class CtlClient {
67
141
  this.host.approved[p.id] = { version: p.version };
68
142
  this.store.save(this.host);
69
143
  }
144
+ const approvalBaseline = structuredClone(this.host.approved);
70
145
  let cacheHits = 0;
71
146
  const results = await boundedMap(packages, 4, async (pkg) => {
72
147
  const approval = this.host.approved[pkg.id];
148
+ const approvalSnapshot = JSON.stringify(approval);
73
149
  if (approval?.version !== pkg.version) {
74
150
  pkg.error = this.needsApproval(pkg);
75
151
  return { error: { package: pkg.id, ...errorData(pkg.error) } };
@@ -92,6 +168,8 @@ export class CtlClient {
92
168
  throw new CtlError('CTL_DESCRIPTION_UNAVAILABLE', `Description refused (${String(response?.error?.code ?? 'invalid response')}).`, 'Use --refresh after updating the App.', 5);
93
169
  description = validateDescriptor(response.data, pkg.id, pkg.version);
94
170
  }
171
+ if (description.version === 3 && !this.host.ephemeral && JSON.stringify(this.store.get(this.host.name).approved[pkg.id]) !== approvalSnapshot)
172
+ throw this.needsApproval(pkg);
95
173
  if (approval.hash && approval.hash !== description.sha256 && !options.approve) {
96
174
  // Remember the observed change so a later cache hit cannot revive the old approval.
97
175
  this.store.putCache(this.host, pkg.id, pkg.version, description);
@@ -111,6 +189,20 @@ export class CtlClient {
111
189
  return { error: { package: pkg.id, ...failure } };
112
190
  }
113
191
  });
192
+ // Keep concurrent revocations and other profile changes; never restore a stale approval map.
193
+ if (!this.host.ephemeral) {
194
+ const current = this.store.get(this.host.name);
195
+ if (current.origin !== this.host.origin || current.username !== this.host.username)
196
+ throw new CtlError('CTL_CREDENTIAL_MISMATCH', 'Registered profile changed during discovery.', 'Repeat discovery with the current profile.', 2);
197
+ for (const pkg of packages)
198
+ if (JSON.stringify(current.approved[pkg.id]) === JSON.stringify(approvalBaseline[pkg.id])) {
199
+ if (this.host.approved[pkg.id])
200
+ current.approved[pkg.id] = this.host.approved[pkg.id];
201
+ else
202
+ delete current.approved[pkg.id];
203
+ }
204
+ this.host = current;
205
+ }
114
206
  this.host.lastUsed = new Date().toISOString();
115
207
  this.store.save(this.host);
116
208
  return { apps: results.flatMap(r => r.description ? [r.description] : []), installed: packages, diagnostics: results.flatMap(r => r.error ? [r.error] : []), cacheHits };
@@ -129,6 +221,8 @@ export class CtlClient {
129
221
  this.until = started + (options.timeoutMs ?? CTL_TIMEOUT_MS);
130
222
  const listing = await this.discover(options);
131
223
  const app = this.selectApp(listing, name);
224
+ if (app.version === 3)
225
+ await this.freshNative(app);
132
226
  const { id, operation } = selectOperation(app, path);
133
227
  const params = operationInput(operation, args, options.stdin, `run: synopkgland ctl ${name} ${operation.cli.join(' ')} --host ${this.host.name} --help`);
134
228
  if (operation.flow.type === 'job') {
@@ -141,6 +235,33 @@ export class CtlClient {
141
235
  confirmOperation(operation, !!options.yes, !!options.dryRun, plan);
142
236
  if (options.dryRun)
143
237
  return { dryRun: true, request: plan };
238
+ if (app.version === 3 && app.payload.execution) {
239
+ // Revocation is checked again before loading any App credential.
240
+ this.nativeApproved(app);
241
+ const key = nativeScope(this.host, app.payload.package.id, { authSha256: app.payload.authSha256 });
242
+ let record;
243
+ try {
244
+ record = await this.store.native.get(key);
245
+ }
246
+ catch (error) {
247
+ if (error instanceof CtlError && error.code === 'CTL_NATIVE_AUTH_INVALID')
248
+ throw new CtlError(error.code, error.message, `${this.nativeGuidance(app).command}; credential location: ${this.nativeGuidance(app).credentialUrl}; ${this.nativeGuidance(app).instructions}`, 2);
249
+ throw error;
250
+ }
251
+ if (!record)
252
+ throw this.nativeRequired(app);
253
+ try {
254
+ return await executeNative(operation, params, app.payload.execution, this.nativeTransport(app, authorization(app.payload.execution, record)), { signal: options.signal, transfer: this.nativeOptions.transfer ?? createNativeTransfer({ timeoutMs: options.timeoutMs ?? this.timeoutMs }), timeoutMs: options.timeoutMs ?? this.timeoutMs });
255
+ }
256
+ catch (error) {
257
+ if (error instanceof CtlError && error.code === 'CTL_NATIVE_AUTH_INVALID') {
258
+ await this.store.native.invalid(key);
259
+ const guide = this.nativeGuidance(app);
260
+ throw new CtlError(error.code, error.message, `${guide.command}; credential location: ${guide.credentialUrl}; ${guide.instructions}`, 2);
261
+ }
262
+ throw error;
263
+ }
264
+ }
144
265
  const session = await this.store.session(this.host);
145
266
  let appSession = session;
146
267
  if (app.payload.transport.auth === 'dsm-app-session') {
@@ -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 {};
@@ -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
- constructor(root?: string, credentials?: CredentialStore);
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
- constructor(root = process.env.SYNOPKGLAND_CTL_DIR ?? join(homedir(), '.synopkgland', 'ctl'), credentials = new OsCredentialStore()) {
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
  }
@@ -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>;