@north-light/cli 0.3.689 → 0.3.691
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/dist/api/client.d.ts +3 -1
- package/dist/api/client.js +2 -2
- package/dist/api/contract.d.ts +1 -1
- package/dist/api/contract.js +1 -1
- package/dist/api/dto/files.d.ts +17 -0
- package/dist/api/dto/reviews.d.ts +2 -0
- package/dist/api/routes.d.ts +2 -0
- package/dist/api/routes.js +1 -1
- package/dist/builtin-memory/crouter-sdk/release-notes.md +4 -0
- package/dist/clients/attach/viewer.js +498 -498
- package/dist/clients/inbox/review/review-client.js +1 -1
- package/dist/core/command-plugins/compose.js +1 -1
- package/dist/core/permissions/ceiling.js +8 -7
- package/dist/core/providers/files.d.ts +2 -0
- package/dist/core/providers/files.js +1 -1
- package/dist/core/review/stage.d.ts +6 -0
- package/dist/core/review/stage.js +1 -1
- package/dist/core/storage/node-transfer.d.ts +6 -0
- package/dist/core/storage/node-transfer.js +1 -0
- package/dist/daemon/api/handlers/node-files.js +1 -1
- package/dist/daemon/api/handlers/reviews.js +1 -1
- package/dist/daemon/api/operations.js +1 -1
- package/docs/sdk/release-notes.md +4 -0
- package/package.json +3 -3
- package/packages/crouter-api/dist/api/client.js +6 -0
- package/packages/crouter-api/dist/api/contract.js +1 -1
- package/packages/crouter-api/dist/api/routes.js +2 -0
- package/packages/crouter-api/dist/clients/inbox/review/review-client.js +3 -1
- package/packages/crouter-api/dist/core/command-plugins/compose.js +16 -3
- package/packages/crouter-api/dist/core/permissions/ceiling.js +10 -2
- package/packages/crouter-api/dist/core/providers/files.js +80 -9
- package/packages/crouter-api/dist/core/storage/node-transfer.js +100 -0
- package/packages/crouter-api/dist/daemon/api/operations.js +2 -0
- package/packages/crouter-api/package.json +1 -1
- package/packages/crouter-identity/package.json +1 -1
- package/packages/crouter-plugin/package.json +3 -3
- package/runtime.lock.json +14 -14
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// The node's CLI side of files crossing to the control plane by upload id (never by path). On a node whose crtr commands the shared control plane
|
|
2
|
+
// executes, the control plane cannot see this disk: the CLI uploads a file argument and sends its id, and downloads a file result by id into the node's
|
|
3
|
+
// attachments folder.
|
|
4
|
+
import { closeSync, constants, createReadStream, createWriteStream, fstatSync, mkdirSync, openSync } from 'node:fs';
|
|
5
|
+
import { basename, extname, join } from 'node:path';
|
|
6
|
+
import { Readable } from 'node:stream';
|
|
7
|
+
import { pipeline } from 'node:stream/promises';
|
|
8
|
+
import { createHash } from 'node:crypto';
|
|
9
|
+
import { cliClient } from '../../commands/api-client.js';
|
|
10
|
+
import { InputError } from '../io.js';
|
|
11
|
+
import { envNodeId, providerProjectionOverBrokerRelay } from '../../shared/env.js';
|
|
12
|
+
import { contentTypeFor } from './media-types.js';
|
|
13
|
+
import { appSpace } from '../layout.js';
|
|
14
|
+
import { envGrantee } from '../../shared/env.js';
|
|
15
|
+
const UPLOAD_MAX_BYTES = 100 * 1024 * 1024;
|
|
16
|
+
/** True when this CLI's commands run on the control plane, which cannot read this node's disk. */
|
|
17
|
+
export function filesCrossByUpload() {
|
|
18
|
+
return envNodeId() !== undefined && providerProjectionOverBrokerRelay();
|
|
19
|
+
}
|
|
20
|
+
function fail(error, message, next) {
|
|
21
|
+
throw new InputError({ error, message, next });
|
|
22
|
+
}
|
|
23
|
+
/** Upload one regular file the node can read; returns the upload id. */
|
|
24
|
+
export async function uploadNodeFile(path) {
|
|
25
|
+
const nodeId = envNodeId();
|
|
26
|
+
if (!nodeId)
|
|
27
|
+
fail('no_node', 'a file can be uploaded only from a node', 'Run this from a node.');
|
|
28
|
+
let fd;
|
|
29
|
+
try {
|
|
30
|
+
fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
return fail('not_found', `no such file: ${path} (${err.code ?? err.message})`, 'Pass the path of a regular file you can read.');
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const stat = fstatSync(fd);
|
|
37
|
+
if (!stat.isFile())
|
|
38
|
+
fail('not_found', `${path} is not a regular file`, 'Pass the path of a regular file.');
|
|
39
|
+
if (stat.size > UPLOAD_MAX_BYTES)
|
|
40
|
+
fail('invalid_request', `${path} exceeds 100 MiB`, 'Split or compress the file.');
|
|
41
|
+
const name = basename(path);
|
|
42
|
+
const mediaType = contentTypeFor(name);
|
|
43
|
+
const created = await cliClient().createNodeUpload(nodeId, { name, media_type: mediaType, size: stat.size });
|
|
44
|
+
const response = await fetch(created.upload_link, {
|
|
45
|
+
method: 'PUT', signal: AbortSignal.timeout(110_000),
|
|
46
|
+
headers: { 'Content-Type': mediaType, 'Content-Length': String(stat.size) },
|
|
47
|
+
body: (stat.size === 0 ? new Uint8Array(0) : Readable.toWeb(createReadStream('', { fd, autoClose: false, start: 0, end: stat.size - 1 }))), duplex: 'half',
|
|
48
|
+
});
|
|
49
|
+
await response.body?.cancel().catch(() => { });
|
|
50
|
+
if (!response.ok)
|
|
51
|
+
fail('upload_failed', `storage answered ${response.status} to the upload of ${path}`, 'Run the command again.');
|
|
52
|
+
return created.upload_id;
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
closeSync(fd);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function candidate(name, n) {
|
|
59
|
+
if (n === 1)
|
|
60
|
+
return name;
|
|
61
|
+
const ext = extname(name);
|
|
62
|
+
return ext && ext !== name ? `${name.slice(0, -ext.length)}-${n}${ext}` : `${name}-${n}`;
|
|
63
|
+
}
|
|
64
|
+
/** Download an upload the control plane holds for this node into its attachments folder, named after `field`; returns the local path. */
|
|
65
|
+
export async function downloadNodeUpload(uploadId, field, size, sha256) {
|
|
66
|
+
const nodeId = envNodeId();
|
|
67
|
+
if (!nodeId)
|
|
68
|
+
fail('no_node', 'a file result can be saved only on a node', 'Run this from a node.');
|
|
69
|
+
const link = await cliClient().nodeUploadLink(nodeId, uploadId);
|
|
70
|
+
const response = await fetch(link.url, { signal: AbortSignal.timeout(110_000) });
|
|
71
|
+
if (!response.ok || !response.body)
|
|
72
|
+
fail('download_failed', `storage answered ${response.status} to the download of ${field}`, 'Run the command again.');
|
|
73
|
+
const dir = join(appSpace(envGrantee() ?? fail('no_node', 'this node has no app assignment', 'Run this from a node.')).nodes, nodeId, 'attachments');
|
|
74
|
+
mkdirSync(dir, { recursive: true });
|
|
75
|
+
for (let n = 1;; n++) {
|
|
76
|
+
const path = join(dir, candidate(field, n));
|
|
77
|
+
let fd;
|
|
78
|
+
try {
|
|
79
|
+
fd = openSync(path, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL, 0o660);
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
if (err.code === 'EEXIST')
|
|
83
|
+
continue;
|
|
84
|
+
throw err;
|
|
85
|
+
}
|
|
86
|
+
const hash = createHash('sha256');
|
|
87
|
+
let bytes = 0;
|
|
88
|
+
try {
|
|
89
|
+
const source = Readable.fromWeb(response.body);
|
|
90
|
+
source.on('data', (chunk) => { hash.update(chunk); bytes += chunk.length; });
|
|
91
|
+
await pipeline(source, createWriteStream('', { fd, autoClose: true }));
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
fail('download_failed', `could not save ${field}: ${err instanceof Error ? err.message : String(err)}`, 'Run the command again.');
|
|
95
|
+
}
|
|
96
|
+
if (bytes !== size || hash.digest('hex') !== sha256.toLowerCase())
|
|
97
|
+
fail('download_failed', `the downloaded ${field} does not match the size and sha256 the server verified`, 'Run the command again.');
|
|
98
|
+
return path;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -91,6 +91,8 @@ export const OPERATIONS = [
|
|
|
91
91
|
{ name: 'bash-jobs.patch', method: 'PATCH', path: '/v1/nodes/:id/jobs/:jobId', classes: ['person', 'broker'], resource: 'node-write' },
|
|
92
92
|
{ name: 'files.create', method: 'POST', path: '/v1/nodes/:id/files', classes: ['broker'], resource: 'node-own', scope: 'crtr:act' },
|
|
93
93
|
{ name: 'files.complete', method: 'POST', path: '/v1/nodes/:id/files/:fileId/complete', classes: ['broker'], resource: 'node-own', scope: 'crtr:act' },
|
|
94
|
+
{ name: 'node-uploads.create', method: 'POST', path: '/v1/nodes/:id/uploads', classes: ['broker'], resource: 'node-own', scope: 'crtr:act' },
|
|
95
|
+
{ name: 'node-uploads.link', method: 'POST', path: '/v1/nodes/:id/uploads/:uploadId/link', classes: ['broker'], resource: 'node-own', scope: 'crtr:act' },
|
|
94
96
|
{ name: 'bash-jobs.start', method: 'POST', path: '/v1/nodes/:id/jobs/start', classes: ['broker'], resource: 'node-own', scope: 'crtr:act' },
|
|
95
97
|
{ name: 'hooks.plan', method: 'GET', path: '/v1/nodes/:id/hooks/plan', classes: ['broker'], resource: 'node-own' },
|
|
96
98
|
{ name: 'hooks.exec', method: 'POST', path: '/v1/nodes/:id/hooks/exec', classes: ['broker'], resource: 'node-own' },
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/api",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.691",
|
|
4
4
|
"description": "Typed crtrd /v1 API contract — DTOs, route builders, the error contract, the CrtrClient, and the command-plugin manifest format. Zero runtime dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/api/index.js",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/plugin",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.691",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"postpack": "node ../../scripts/pack-minify.mjs postpack packages/crouter-plugin"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@north-light/api": "0.3.
|
|
31
|
-
"@north-light/identity": "0.3.
|
|
30
|
+
"@north-light/api": "0.3.691",
|
|
31
|
+
"@north-light/identity": "0.3.691"
|
|
32
32
|
},
|
|
33
33
|
"license": "UNLICENSED",
|
|
34
34
|
"publishConfig": {
|
package/runtime.lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.691",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@north-light/cli",
|
|
9
|
-
"version": "0.3.
|
|
9
|
+
"version": "0.3.691",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "UNLICENSED",
|
|
12
12
|
"workspaces": [
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"@milkdown/preset-gfm": "^7.22.3",
|
|
29
29
|
"@milkdown/prose": "^7.22.3",
|
|
30
30
|
"@milkdown/utils": "^7.22.3",
|
|
31
|
-
"@north-light/identity": "0.3.
|
|
32
|
-
"@north-light/plugin": "0.3.
|
|
31
|
+
"@north-light/identity": "0.3.691",
|
|
32
|
+
"@north-light/plugin": "0.3.691",
|
|
33
33
|
"cron-parser": "^5.6.0",
|
|
34
34
|
"esbuild": "0.28.2",
|
|
35
35
|
"jose": "^6.2.12",
|
|
@@ -10667,17 +10667,17 @@
|
|
|
10667
10667
|
},
|
|
10668
10668
|
"packages/crouter-api": {
|
|
10669
10669
|
"name": "@north-light/api",
|
|
10670
|
-
"version": "0.3.
|
|
10670
|
+
"version": "0.3.691",
|
|
10671
10671
|
"license": "UNLICENSED"
|
|
10672
10672
|
},
|
|
10673
10673
|
"packages/crouter-env-docker": {
|
|
10674
10674
|
"name": "@north-light/env-docker",
|
|
10675
|
-
"version": "0.3.
|
|
10675
|
+
"version": "0.3.691",
|
|
10676
10676
|
"license": "UNLICENSED"
|
|
10677
10677
|
},
|
|
10678
10678
|
"packages/crouter-identity": {
|
|
10679
10679
|
"name": "@north-light/identity",
|
|
10680
|
-
"version": "0.3.
|
|
10680
|
+
"version": "0.3.691",
|
|
10681
10681
|
"license": "UNLICENSED",
|
|
10682
10682
|
"dependencies": {
|
|
10683
10683
|
"jose": "^6.2.1"
|
|
@@ -10685,21 +10685,21 @@
|
|
|
10685
10685
|
},
|
|
10686
10686
|
"packages/crouter-plugin": {
|
|
10687
10687
|
"name": "@north-light/plugin",
|
|
10688
|
-
"version": "0.3.
|
|
10688
|
+
"version": "0.3.691",
|
|
10689
10689
|
"license": "UNLICENSED",
|
|
10690
10690
|
"dependencies": {
|
|
10691
|
-
"@north-light/api": "0.3.
|
|
10692
|
-
"@north-light/identity": "0.3.
|
|
10691
|
+
"@north-light/api": "0.3.691",
|
|
10692
|
+
"@north-light/identity": "0.3.691"
|
|
10693
10693
|
}
|
|
10694
10694
|
},
|
|
10695
10695
|
"packages/crouter-sdk": {
|
|
10696
10696
|
"name": "@north-light/sdk",
|
|
10697
|
-
"version": "0.3.
|
|
10697
|
+
"version": "0.3.691",
|
|
10698
10698
|
"license": "UNLICENSED",
|
|
10699
10699
|
"dependencies": {
|
|
10700
|
-
"@north-light/api": "0.3.
|
|
10701
|
-
"@north-light/identity": "0.3.
|
|
10702
|
-
"@north-light/plugin": "0.3.
|
|
10700
|
+
"@north-light/api": "0.3.691",
|
|
10701
|
+
"@north-light/identity": "0.3.691",
|
|
10702
|
+
"@north-light/plugin": "0.3.691",
|
|
10703
10703
|
"jose": "^6.2.1"
|
|
10704
10704
|
},
|
|
10705
10705
|
"bin": {
|