b4n1-audit 0.0.0-stage → 0.1.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.
package/README.md CHANGED
@@ -1,3 +1,16 @@
1
- # Temporary Holding Version
1
+ # b4n1-audit — JavaScript SDK (provisional, fase privada)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Wrapper JavaScript del binario `b4n1-audit` (patrón one-binary-N-wrappers).
4
+ Binario empaquetado en `bin/`, o resuelto con `B4N1_AUDIT_BIN` / `PATH`.
5
+
6
+ ```javascript
7
+ const { run, binaryPath, AuditError } = require("b4n1-audit");
8
+
9
+ console.log(binaryPath()); // fail loud si no hay binario
10
+ const report = run("json", "."); // objeto (JSON) o string
11
+ // también: run(["json", "."], { timeout: 60000 })
12
+ ```
13
+
14
+ - `run()` lanza `AuditError` con stderr si el binario sale con exit ≠ 0.
15
+ - Sin paso de build: `main` apunta a `src/` (tipos en `src/index.d.ts`).
16
+ - No publicar en npm hasta la decisión de publicación (task `952f7022`).
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,32 @@
1
1
  {
2
2
  "name": "b4n1-audit",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "B4N1 Audit SDK for JavaScript — security & code quality scanner with bundled binary",
5
+ "main": "src/index.js",
6
+ "types": "src/index.d.ts",
7
+ "license": "SEE LICENSE IN LICENSE.md",
8
+ "files": [
9
+ "src",
10
+ "bin",
11
+ "README.md",
12
+ "EULA.txt"
13
+ ],
14
+ "scripts": {
15
+ "test": "node test/smoke.js"
16
+ },
17
+ "keywords": [
18
+ "security",
19
+ "audit",
20
+ "scanner",
21
+ "sarif",
22
+ "static-analysis"
23
+ ],
24
+ "engines": {
25
+ "node": ">=16"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/B4N1-com/b4n1-audit"
30
+ },
31
+ "homepage": "https://b4n1.com"
32
+ }
package/src/binary.js ADDED
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ /**
3
+ * Resolución del binario b4n1-audit (patrón one-binary-N-wrappers).
4
+ * Orden: B4N1_AUDIT_BIN > binario empaquetado > PATH > fail loud (§5).
5
+ */
6
+ const fs = require("fs");
7
+ const os = require("os");
8
+ const path = require("path");
9
+ const { execFileSync } = require("child_process");
10
+
11
+ const BIN_ENV = "B4N1_AUDIT_BIN";
12
+
13
+ /** (so, arquitectura) → nombre empaquetado; null si la plataforma es desconocida. */
14
+ function platformBinaryName() {
15
+ const archMap = {
16
+ x64: "amd64",
17
+ arm64: "arm64",
18
+ ia32: "ia32",
19
+ x86: "ia32",
20
+ };
21
+ const arch = archMap[os.arch()] || null;
22
+ if (!arch) return null;
23
+ if (process.platform === "linux") return `b4n1-audit-linux-${arch}`;
24
+ if (process.platform === "darwin")
25
+ return `b4n1-audit-macos-${arch === "arm64" ? "arm64" : "x64"}`;
26
+ if (process.platform === "win32")
27
+ return `b4n1-audit-windows-${arch}.exe`;
28
+ return null;
29
+ }
30
+
31
+ /** Resuelve el binario o lanza con la lista completa de sitios probados. */
32
+ function binaryPath() {
33
+ const searched = [];
34
+
35
+ const envBin = (process.env[BIN_ENV] || "").trim();
36
+ if (envBin) {
37
+ if (fs.existsSync(envBin)) return envBin;
38
+ searched.push(`${BIN_ENV}=${envBin} (no existe)`);
39
+ }
40
+
41
+ const name = platformBinaryName();
42
+ if (name) {
43
+ const bundled = path.join(__dirname, "..", "bin", name);
44
+ searched.push(bundled);
45
+ if (fs.existsSync(bundled)) return bundled;
46
+ }
47
+
48
+ // PATH: búsqueda manual (sin dependencias)
49
+ const exe = process.platform === "win32" ? ".exe" : "";
50
+ for (const dir of (process.env.PATH || "").split(path.delimiter)) {
51
+ if (!dir) continue;
52
+ const candidate = path.join(dir, `b4n1-audit${exe}`);
53
+ searched.push(candidate);
54
+ if (fs.existsSync(candidate)) return candidate;
55
+ }
56
+
57
+ throw new Error(
58
+ "b4n1-audit binario no resuelto — probado: " + searched.join(" | ")
59
+ );
60
+ }
61
+
62
+ module.exports = { binaryPath, platformBinaryName, BIN_ENV };
package/src/index.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ /** Tipos del SDK b4n1-audit (JavaScript) — sin paso de build. */
2
+
3
+ export type RunOptions = {
4
+ /** Timeout en ms; sin él no hay límite. */
5
+ timeout?: number;
6
+ };
7
+
8
+ export declare class AuditError extends Error {
9
+ name: "AuditError";
10
+ }
11
+
12
+ /** Binario resuelto (B4N1_AUDIT_BIN > empaquetado > PATH > lanza AuditError). */
13
+ export declare function binaryPath(): string;
14
+
15
+ /**
16
+ * Invoca el binario; stdout crudo. Exit ≠ 0 → AuditError.
17
+ * Acepta variadic ("json", ".") o array (["json", "."], {timeout}).
18
+ */
19
+ export declare function runRaw(
20
+ ...rest: (string | string[] | RunOptions)[]
21
+ ): string;
22
+
23
+ /** Como runRaw pero parsea JSON (objeto/array) cuando la salida lo es. */
24
+ export declare function run(
25
+ ...rest: (string | string[] | RunOptions)[]
26
+ ): unknown | string;
package/src/index.js ADDED
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ /**
3
+ * b4n1-audit SDK (JavaScript) — wrapper del binario precompilado.
4
+ *
5
+ * const { run, binaryPath, AuditError } = require("b4n1-audit");
6
+ * const report = run("json", "."); // objeto si la salida es JSON, si no string
7
+ */
8
+ const { execFileSync } = require("child_process");
9
+ const { binaryPath } = require("./binary");
10
+
11
+ class AuditError extends Error {
12
+ /** Fallo tipado del binario o del entorno (§5: loud, nunca silencioso). */
13
+ constructor(message) {
14
+ super(message);
15
+ this.name = "AuditError";
16
+ }
17
+ }
18
+
19
+ /** Normaliza llamadas: run("json", "."), run(["json", "."], {timeout}) y
20
+ * run(["json", "."], options) — strings → args, array → se concatena,
21
+ * objeto → options. Devuelve {args, options} siempre válido. */
22
+ function normalize(all) {
23
+ const args = [];
24
+ let options = {};
25
+ for (const item of all) {
26
+ if (Array.isArray(item)) args.push(...item);
27
+ else if (item && typeof item === "object") options = item;
28
+ else if (typeof item === "string") args.push(item);
29
+ else throw new AuditError(`argumento no soportado: ${typeof item}`);
30
+ }
31
+ return { args, options };
32
+ }
33
+
34
+ /** Invoca el binario con *args* y devuelve stdout crudo. Exit ≠ 0 → AuditError. */
35
+ function runRaw(...rest) {
36
+ const { args, options } = normalize(rest);
37
+ const bin = binaryPath();
38
+ const argv = Array.isArray(args) ? args : [String(args)];
39
+ try {
40
+ return execFileSync(bin, argv, {
41
+ encoding: "utf8",
42
+ maxBuffer: 64 * 1024 * 1024,
43
+ timeout: options.timeout,
44
+ stdio: ["ignore", "pipe", "pipe"],
45
+ });
46
+ } catch (e) {
47
+ if (e instanceof AuditError) throw e;
48
+ const stderr = e.stderr ? String(e.stderr).slice(0, 2000) : "";
49
+ throw new AuditError(
50
+ `b4n1-audit exit=${e.status ?? "killed"}: ${argv.join(" ")}\nstderr: ${stderr}`
51
+ );
52
+ }
53
+ }
54
+
55
+ /** Como runRaw pero parsea el stdout como JSON si lo es (objeto/array). */
56
+ function run(...rest) {
57
+ const out = runRaw(...rest);
58
+ try {
59
+ const parsed = JSON.parse(out);
60
+ if (parsed && typeof parsed === "object") return parsed;
61
+ } catch (_) {
62
+ /* salida no-JSON: se entrega como string */
63
+ }
64
+ return out;
65
+ }
66
+
67
+ module.exports = { run, runRaw, binaryPath, AuditError };