@zenera/browser 1.3.45 → 1.3.47

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/apis.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import type { Problem } from './session.ts';
2
+ /** The audit of every `*.api.py` under `folder`; nothing when it has none. */
3
+ export declare function auditApis(folder: string): Problem[];
4
+ //# sourceMappingURL=apis.d.ts.map
package/dist/apis.js ADDED
@@ -0,0 +1,65 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { readdirSync } from 'node:fs';
3
+ import { join, relative } from 'node:path';
4
+ import { APP_API_SUFFIX, RUNTIME_PYTHON } from '@zenera/engine';
5
+ import { pythonPath } from "./target.js";
6
+ // ---------------------------------------------------------------------------
7
+ // What a page's functions let the page do: `python3 -m zenera.api --audit`
8
+ //
9
+ // A page's `*.api.py` functions are an API: whoever can open the page - every visitor of an app
10
+ // shared with others too - can call any of them with any arguments. The audit (zenera.api's
11
+ // own, which reads the files and never runs them) flags public functions that let the page
12
+ // choose a command, the text of SQL or a file, or that return the environment.
13
+ //
14
+ // Main: auditApis - the findings for the `*.api.py` files under a page's folder, as Problems.
15
+ // Used by: @zenera/cli `zen page check` (commands/page.ts), beside checkPage's own report.
16
+ // ---------------------------------------------------------------------------
17
+ /** Folders never looked in: a page's data, its build's packages. */
18
+ const SKIP = /^(\.|node_modules$)/;
19
+ function apiFiles(dir, depth = 0) {
20
+ if (depth > 4)
21
+ return [];
22
+ const out = [];
23
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
24
+ if (SKIP.test(entry.name))
25
+ continue;
26
+ const at = join(dir, entry.name);
27
+ if (entry.isDirectory())
28
+ out.push(...apiFiles(at, depth + 1));
29
+ else if (entry.isFile() && entry.name.endsWith(APP_API_SUFFIX))
30
+ out.push(at);
31
+ }
32
+ return out.sort();
33
+ }
34
+ /** The audit of every `*.api.py` under `folder`; nothing when it has none. */
35
+ export function auditApis(folder) {
36
+ const files = apiFiles(folder);
37
+ if (!files.length)
38
+ return [];
39
+ const paths = [...pythonPath(), ...(process.env.PYTHONPATH ? [process.env.PYTHONPATH] : [])];
40
+ const run = spawnSync('python3', ['-m', 'zenera.api', '--audit', ...files], {
41
+ encoding: 'utf8',
42
+ env: { ...process.env, PYTHONPATH: paths.join(':') || RUNTIME_PYTHON },
43
+ timeout: 30_000,
44
+ });
45
+ let findings;
46
+ try {
47
+ if (run.error)
48
+ throw run.error;
49
+ findings = JSON.parse(run.stdout);
50
+ }
51
+ catch (err) {
52
+ const why = (run.stderr || (err instanceof Error ? err.message : String(err))).trim();
53
+ return [
54
+ {
55
+ level: 'warning',
56
+ text: `could not check the page's functions (python3 -m zenera.api --audit): ${why.slice(-300)}`,
57
+ },
58
+ ];
59
+ }
60
+ return findings.map((f) => ({
61
+ level: f.level,
62
+ text: `${relative(folder, f.file)}:${f.line}${f.function ? ` ${f.function}()` : ''}: ${f.text}`,
63
+ }));
64
+ }
65
+ //# sourceMappingURL=apis.js.map
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './apis.ts';
1
2
  export * from './host.ts';
2
3
  export * from './install.ts';
3
4
  export * from './report.ts';
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // The public API of @zenera/browser: an html page in a real browser, served as the chat serves
2
2
  // it, for `zen page` (the html-page skill's check) and, later, agents' browser tools.
3
3
  // Import from '@zenera/browser', not a file.
4
+ export * from "./apis.js";
4
5
  export * from "./host.js";
5
6
  export * from "./install.js";
6
7
  export * from "./report.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenera/browser",
3
- "version": "1.3.45",
3
+ "version": "1.3.47",
4
4
  "description": "An html page in a real browser, served as a zen chat serves it: checked for errors, driven, photographed.",
5
5
  "keywords": [
6
6
  "playwright",
@@ -41,8 +41,8 @@
41
41
  "prepack": "tsc -b"
42
42
  },
43
43
  "dependencies": {
44
- "@zenera/engine": "^1.3.45",
45
- "@zenera/sandbox": "^1.3.45",
44
+ "@zenera/engine": "^1.3.47",
45
+ "@zenera/sandbox": "^1.3.47",
46
46
  "playwright-core": "1.65.1"
47
47
  }
48
48
  }