brakit 0.7.4 → 0.7.6
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 +78 -50
- package/dist/api.d.ts +116 -3
- package/dist/api.js +615 -353
- package/dist/bin/brakit.js +38 -31
- package/dist/runtime/index.js +1150 -510
- package/package.json +1 -1
package/dist/bin/brakit.js
CHANGED
|
@@ -5,7 +5,7 @@ import { runMain } from "citty";
|
|
|
5
5
|
// src/cli/commands/install.ts
|
|
6
6
|
import { defineCommand } from "citty";
|
|
7
7
|
import { resolve as resolve3, join as join2 } from "path";
|
|
8
|
-
import { readFile as readFile3, writeFile as
|
|
8
|
+
import { readFile as readFile3, writeFile as writeFile3 } from "fs/promises";
|
|
9
9
|
import { execSync } from "child_process";
|
|
10
10
|
import pc from "picocolors";
|
|
11
11
|
|
|
@@ -386,6 +386,33 @@ var corsCredentialsRule = {
|
|
|
386
386
|
}
|
|
387
387
|
};
|
|
388
388
|
|
|
389
|
+
// src/constants/thresholds.ts
|
|
390
|
+
var OVERFETCH_UNWRAP_MIN_SIZE = 3;
|
|
391
|
+
|
|
392
|
+
// src/utils/response.ts
|
|
393
|
+
function unwrapResponse(parsed) {
|
|
394
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return parsed;
|
|
395
|
+
const obj = parsed;
|
|
396
|
+
const keys = Object.keys(obj);
|
|
397
|
+
if (keys.length > 3) return parsed;
|
|
398
|
+
let best = null;
|
|
399
|
+
let bestSize = 0;
|
|
400
|
+
for (const key of keys) {
|
|
401
|
+
const val = obj[key];
|
|
402
|
+
if (Array.isArray(val) && val.length > bestSize) {
|
|
403
|
+
best = val;
|
|
404
|
+
bestSize = val.length;
|
|
405
|
+
} else if (val && typeof val === "object" && !Array.isArray(val)) {
|
|
406
|
+
const size = Object.keys(val).length;
|
|
407
|
+
if (size > bestSize) {
|
|
408
|
+
best = val;
|
|
409
|
+
bestSize = size;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return best && bestSize >= OVERFETCH_UNWRAP_MIN_SIZE ? best : parsed;
|
|
414
|
+
}
|
|
415
|
+
|
|
389
416
|
// src/analysis/rules/response-pii-leak.ts
|
|
390
417
|
var WRITE_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH"]);
|
|
391
418
|
var FULL_RECORD_MIN_FIELDS = 5;
|
|
@@ -430,28 +457,6 @@ function hasInternalIds(obj) {
|
|
|
430
457
|
}
|
|
431
458
|
return false;
|
|
432
459
|
}
|
|
433
|
-
function unwrapResponse(parsed) {
|
|
434
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return parsed;
|
|
435
|
-
const obj = parsed;
|
|
436
|
-
const keys = Object.keys(obj);
|
|
437
|
-
if (keys.length > 3) return parsed;
|
|
438
|
-
let best = null;
|
|
439
|
-
let bestSize = 0;
|
|
440
|
-
for (const key of keys) {
|
|
441
|
-
const val = obj[key];
|
|
442
|
-
if (Array.isArray(val) && val.length > bestSize) {
|
|
443
|
-
best = val;
|
|
444
|
-
bestSize = val.length;
|
|
445
|
-
} else if (val && typeof val === "object" && !Array.isArray(val)) {
|
|
446
|
-
const size = Object.keys(val).length;
|
|
447
|
-
if (size > bestSize) {
|
|
448
|
-
best = val;
|
|
449
|
-
bestSize = size;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
return best && bestSize >= 3 ? best : parsed;
|
|
454
|
-
}
|
|
455
460
|
function detectPII(method, reqBody, resBody) {
|
|
456
461
|
const target = unwrapResponse(resBody);
|
|
457
462
|
if (WRITE_METHODS.has(method) && reqBody && typeof reqBody === "object") {
|
|
@@ -592,7 +597,7 @@ var RequestStore = class {
|
|
|
592
597
|
responseHeaders: flattenHeaders(input.responseHeaders),
|
|
593
598
|
responseBody: responseBodyStr,
|
|
594
599
|
startedAt: input.startTime,
|
|
595
|
-
durationMs: Math.round(performance.now() - input.startTime),
|
|
600
|
+
durationMs: Math.round((input.endTime ?? performance.now()) - input.startTime),
|
|
596
601
|
responseSize: input.responseBody?.length ?? 0,
|
|
597
602
|
isStatic: isStaticPath(path)
|
|
598
603
|
};
|
|
@@ -685,15 +690,17 @@ import {
|
|
|
685
690
|
writeFileSync as writeFileSync2,
|
|
686
691
|
mkdirSync as mkdirSync2,
|
|
687
692
|
existsSync as existsSync2,
|
|
688
|
-
unlinkSync
|
|
693
|
+
unlinkSync,
|
|
694
|
+
renameSync
|
|
689
695
|
} from "fs";
|
|
696
|
+
import { writeFile as writeFile2, mkdir, rename } from "fs/promises";
|
|
690
697
|
import { resolve as resolve2 } from "path";
|
|
691
698
|
|
|
692
699
|
// src/analysis/group.ts
|
|
693
700
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
694
701
|
|
|
695
702
|
// src/index.ts
|
|
696
|
-
var VERSION = "0.7.
|
|
703
|
+
var VERSION = "0.7.6";
|
|
697
704
|
|
|
698
705
|
// src/cli/commands/install.ts
|
|
699
706
|
var IMPORT_LINE = `import "brakit";`;
|
|
@@ -807,7 +814,7 @@ async function setupNextjs(rootDir) {
|
|
|
807
814
|
`}`,
|
|
808
815
|
``
|
|
809
816
|
].join("\n");
|
|
810
|
-
await
|
|
817
|
+
await writeFile3(absPath, content);
|
|
811
818
|
return { action: "created", file: relPath, content };
|
|
812
819
|
}
|
|
813
820
|
async function setupNuxt(rootDir) {
|
|
@@ -825,7 +832,7 @@ async function setupNuxt(rootDir) {
|
|
|
825
832
|
const dir = join2(rootDir, "server/plugins");
|
|
826
833
|
const { mkdirSync: mkdirSync3 } = await import("fs");
|
|
827
834
|
mkdirSync3(dir, { recursive: true });
|
|
828
|
-
await
|
|
835
|
+
await writeFile3(absPath, content);
|
|
829
836
|
return { action: "created", file: relPath, content };
|
|
830
837
|
}
|
|
831
838
|
async function setupPrepend(rootDir, ...candidates) {
|
|
@@ -836,7 +843,7 @@ async function setupPrepend(rootDir, ...candidates) {
|
|
|
836
843
|
if (content.includes(IMPORT_MARKER)) {
|
|
837
844
|
return { action: "exists", file: relPath };
|
|
838
845
|
}
|
|
839
|
-
await
|
|
846
|
+
await writeFile3(absPath, `${IMPORT_LINE}
|
|
840
847
|
${content}`);
|
|
841
848
|
return { action: "prepended", file: relPath };
|
|
842
849
|
}
|
|
@@ -890,7 +897,7 @@ function printManualInstructions(framework) {
|
|
|
890
897
|
// src/cli/commands/uninstall.ts
|
|
891
898
|
import { defineCommand as defineCommand2 } from "citty";
|
|
892
899
|
import { resolve as resolve4, join as join3 } from "path";
|
|
893
|
-
import { readFile as readFile4, writeFile as
|
|
900
|
+
import { readFile as readFile4, writeFile as writeFile4, unlink } from "fs/promises";
|
|
894
901
|
import { execSync as execSync2 } from "child_process";
|
|
895
902
|
import pc2 from "picocolors";
|
|
896
903
|
var IMPORT_LINE2 = `import "brakit";`;
|
|
@@ -968,7 +975,7 @@ var uninstall_default = defineCommand2({
|
|
|
968
975
|
const content = await readFile4(absPath, "utf-8");
|
|
969
976
|
if (!content.includes(IMPORT_LINE2)) continue;
|
|
970
977
|
const updated = content.split("\n").filter((line) => line.trim() !== IMPORT_LINE2.trim()).join("\n");
|
|
971
|
-
await
|
|
978
|
+
await writeFile4(absPath, updated);
|
|
972
979
|
console.log(pc2.green(` \u2713 Removed brakit import from ${relPath}`));
|
|
973
980
|
removed = true;
|
|
974
981
|
break;
|