@rulecad/cad 0.7.31 → 0.7.33
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/README.md +2 -1
- package/lib/links.mjs +1 -1
- package/lib/sandbox-run.mjs +1 -1
- package/lib/sandbox.mjs +13 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -265,7 +265,8 @@ other items' variables, so a keycap can sit exactly where its slot meets the swi
|
|
|
265
265
|
watertight; `npm install manifold-3d`) with `"engine": "manifold"` in the object's JSON or `CAD_ENGINE=manifold`.
|
|
266
266
|
- **Sandbox:** a JSCAD design runs in a separate Node process under Node's permission model. Whatever it does, it
|
|
267
267
|
can't write or delete files, start programs or workers, or load addons, and it reads only the workspace and the
|
|
268
|
-
packages designs use
|
|
268
|
+
packages designs use, by their real paths (a `node_modules` link spelled through another link, as macOS spells its
|
|
269
|
+
temporary folders through `/tmp` and `/var`, is refused by name: make the link with the real path). To keep it to making shapes it may import only `@jscad/modeling`, `@rulecad/shapes`,
|
|
269
270
|
`@rulecad/flexures` and files in its own project (no `node:` modules), `fetch` and its kin are gone, and it is
|
|
270
271
|
started with none of your environment (no tokens). Those shut the ordinary roads to the network, not every one:
|
|
271
272
|
before Node 25 the permission model doesn't cover the network, so a design written to get round them might still
|
package/lib/links.mjs
CHANGED
|
@@ -18,7 +18,7 @@ export const VIEW = process.env.CAD_VIEW_URL || config.viewUrl;
|
|
|
18
18
|
/** A link to the model page; one the page would turn away is an error here, not when someone opens it. */
|
|
19
19
|
export async function linkTo(model) {
|
|
20
20
|
const errors = checkLink(model.shapes ? expand(model) : model);
|
|
21
|
-
if (errors.length) throw new Error(`no link: ${errors[0]}`);
|
|
21
|
+
if (errors.length) throw new Error(`no link: ${errors[0].text}`);
|
|
22
22
|
return `${VIEW}#m=${await encode(model)}`;
|
|
23
23
|
}
|
|
24
24
|
|
package/lib/sandbox-run.mjs
CHANGED
|
@@ -33,5 +33,5 @@ try {
|
|
|
33
33
|
done({ parts, read: [...read], ...(mechanism ? { mechanism } : {}), ...(Object.keys(kept).length ? { stages: kept } : {}) });
|
|
34
34
|
} catch (e) {
|
|
35
35
|
const line = lineOf(e, js);
|
|
36
|
-
done({ error: { message: e?.message || String(e), ...(line ? { line } : {}), ...(e?.name === 'SyntaxError' ? { syntax: true } : {}), code: e?.code && typeof e.code === 'string' && !/^ERR_/.test(e.code) ? e.code : e?.code === 'ERR_ACCESS_DENIED' ? 'design.sandbox' : 'design.run' } });
|
|
36
|
+
done({ error: { message: e?.message || String(e), ...(line ? { line } : {}), ...(e?.name === 'SyntaxError' ? { syntax: true } : {}), code: e?.code && typeof e.code === 'string' && !/^ERR_/.test(e.code) ? e.code : e?.code === 'ERR_ACCESS_DENIED' ? 'design.sandbox' : 'design.run', ...(e?.code === 'ERR_ACCESS_DENIED' && e.resource ? { resource: e.resource } : {}) } });
|
|
37
37
|
}
|
package/lib/sandbox.mjs
CHANGED
|
@@ -44,6 +44,18 @@ function readable() {
|
|
|
44
44
|
return [...new Set(dirs.filter(Boolean).flatMap((d) => [d, real(d)]).filter(Boolean))];
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
// A read the permission model refused, said with what to do. Node names the first path it may not read; when that is
|
|
48
|
+
// a link (macOS spells its temporary folders through /tmp and /var, both links into /private), the design's packages
|
|
49
|
+
// are reached through a node_modules link spelled through it, which the sandbox follows by its real path and may not.
|
|
50
|
+
function refused(e) {
|
|
51
|
+
if (e.code !== 'design.sandbox' || !e.resource) return e.message;
|
|
52
|
+
const res = e.resource, to = (() => { try { return fs.lstatSync(res).isSymbolicLink() ? fs.realpathSync(res) : null; } catch { return null; } })();
|
|
53
|
+
const trust = 'or trust the workspace ("sandbox": false in cad.config.json, then cad trust)';
|
|
54
|
+
return to
|
|
55
|
+
? `the design's sandbox was refused ${res}, a link to ${to}: something the design loads is reached through it (a node_modules link spelled through ${res}, most likely). Make that link with its real path (ln -s "$(pwd -P)/node_modules"), ${trust}`
|
|
56
|
+
: `the design's sandbox was refused ${res}: a design may read only its workspace and the packages it uses. Keep what it needs inside the workspace, ${trust}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
47
59
|
/**
|
|
48
60
|
* Run a design's main(values) in the sandbox: { parts, read } as the build makes them.
|
|
49
61
|
* @param {{ js: string }} d the design @param {object} values @param {object} meta the .json's parts @param {'jscad' | 'manifold'} [engine] v.ops's booleans
|
|
@@ -69,7 +81,7 @@ export function runSandboxed(d, values, meta, engine = 'jscad', optional = [], s
|
|
|
69
81
|
return reject(located(new Error(`the design's sandbox stopped: ${Buffer.concat(err).toString('utf8').trim().split('\n').slice(-3).join(' ') || 'no output'}`), d.js, 'design.sandbox'));
|
|
70
82
|
}
|
|
71
83
|
if (err.length) process.stderr.write(Buffer.concat(err)); // what the design printed
|
|
72
|
-
if (r.error) return reject(located(Object.assign(new Error(r.error
|
|
84
|
+
if (r.error) return reject(located(Object.assign(new Error(refused(r.error)), { code: r.error.code, ...(r.error.line ? { line: r.error.line } : {}), ...(r.error.syntax ? { name: 'SyntaxError' } : {}) }), d.js, r.error.code || 'design.run'));
|
|
73
85
|
if (stages) for (const [k, text] of Object.entries(r.stages || {})) stages.put(k, text);
|
|
74
86
|
resolve({ parts: r.parts.map(({ solid, ...p }) => ({ ...p, geometry: fromFaces(solid) })), read: new Set(r.read), mechanism: r.mechanism || null });
|
|
75
87
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/cad",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.33",
|
|
4
4
|
"description": "The cad command: JSCAD designs from traceable rules, checked for printing and fit, versioned by what fits, shared as links and exported as Bambu 3MF.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@rulecad/variables": "^0.3.0",
|
|
61
61
|
"@rulecad/keyboard-layout": "^0.1.2",
|
|
62
|
-
"@rulecad/printcheck": "^0.
|
|
63
|
-
"@rulecad/fit": "^0.
|
|
64
|
-
"@rulecad/model-link": "^0.
|
|
62
|
+
"@rulecad/printcheck": "^0.3.0",
|
|
63
|
+
"@rulecad/fit": "^0.4.0",
|
|
64
|
+
"@rulecad/model-link": "^0.3.0",
|
|
65
65
|
"@rulecad/versions": "^0.1.0",
|
|
66
66
|
"@rulecad/shapes": "^0.4.1",
|
|
67
67
|
"@rulecad/rules": "^0.3.0",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"three": "^0.186.1",
|
|
70
70
|
"@rulecad/fea": "^0.2.1",
|
|
71
71
|
"@rulecad/topopt": "^0.3.0",
|
|
72
|
-
"@rulecad/flexures": "^0.
|
|
72
|
+
"@rulecad/flexures": "^0.5.0"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"@rulecad/pcb": "^0.1.0 || ^0.2.0 || ^0.3.0 || ^0.4.0 || ^0.5.0"
|