periderm-cli 0.1.71 → 0.1.73

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/index.js CHANGED
@@ -82,7 +82,10 @@ program
82
82
  if (v.plan !== "unlimited" &&
83
83
  (v.scans_remaining === undefined || v.scans_remaining <= 0)) {
84
84
  verifySpinner.fail(`No scans left on your ${v.plan} plan.`);
85
- console.info(chalk.yellow(`\nRenew or upgrade at ${cfg.apiUrl}/dashboard/billing\n`));
85
+ console.info(chalk.yellow(`\nRenew or upgrade at ${cfg.apiUrl}/dashboard/billing`));
86
+ console.info(chalk.dim("If you just subscribed, wait a moment then run ") +
87
+ chalk.bold.cyan("$ periderm whoami") +
88
+ chalk.dim(" to re-check your quota.\n"));
86
89
  process.exit(1);
87
90
  }
88
91
  verifySpinner.stop();
@@ -344,11 +347,19 @@ program
344
347
  </body>
345
348
  </html>`;
346
349
  res.end(html);
347
- const v = await verifyToken(token);
350
+ let v = await verifyToken(token);
348
351
  if (!v.valid) {
349
352
  console.info(chalk.red(`\nInvalid token: ${v.error}`));
350
353
  process.exit(1);
351
354
  }
355
+ // If quota shows 0 on a paid plan, the subscription webhook may not have
356
+ // propagated yet. Wait briefly and re-fetch once before displaying.
357
+ if (v.scans_remaining === 0 && v.plan !== "starter") {
358
+ await new Promise((r) => setTimeout(r, 2500));
359
+ const refreshed = await verifyToken(token);
360
+ if (refreshed.valid)
361
+ v = refreshed;
362
+ }
352
363
  writeConfig({ apiUrl, token });
353
364
  console.clear();
354
365
  const username = os.userInfo().username;
@@ -356,7 +367,8 @@ program
356
367
  const header = `${username}@${hostname}`;
357
368
  const formatEmail = v.email || v.user_id || "Unknown";
358
369
  const formatPlan = v.plan || "starter";
359
- const formatQuota = `${v.scans_remaining ?? "?"}`;
370
+ const scansLeft = v.scans_remaining ?? 0;
371
+ const formatQuota = v.plan === "unlimited" ? "Unlimited" : `${scansLeft} scan${scansLeft !== 1 ? "s" : ""}`;
360
372
  const actualLogoLines = PERIDERM_ASCII.split("\n");
361
373
  // Print logo
362
374
  console.info("");
@@ -371,8 +383,18 @@ program
371
383
  console.info("");
372
384
  console.info(chalk.bold.white("Account : ") + chalk.white(formatEmail));
373
385
  console.info(chalk.bold.white("Plan : ") + chalk.magenta(formatPlan));
374
- console.info(chalk.bold.white("Quota : ") + chalk.yellow(`${formatQuota} scans`));
386
+ console.info(chalk.bold.white("Quota : ") +
387
+ (scansLeft === 0 && v.plan !== "unlimited"
388
+ ? chalk.red(formatQuota)
389
+ : chalk.yellow(formatQuota)));
375
390
  console.info("");
391
+ // Hint when quota still shows 0 after a recent subscription — webhook
392
+ // delivery can lag by a few seconds. Running `whoami` re-fetches live.
393
+ if (scansLeft === 0 && v.plan !== "starter" && v.plan !== "unlimited") {
394
+ console.info(chalk.yellow("⚠ Quota shows 0. If you just subscribed, wait a moment then run:"));
395
+ console.info(chalk.bold.cyan(" $ periderm whoami") + chalk.dim(" (re-checks live)"));
396
+ console.info("");
397
+ }
376
398
  console.info(chalk.bold.white("[Next Steps]"));
377
399
  console.info(chalk.white(" 1. Scan + upload ") + chalk.hex("#FF4D00")("$ periderm scan"));
378
400
  console.info(chalk.white(" 2. Log out ") + chalk.hex("#FF4D00")("$ periderm logout"));
@@ -427,11 +449,23 @@ program
427
449
  console.info("");
428
450
  const formatEmail = r.email || r.user_id || "Unknown";
429
451
  const formatPlan = r.plan || "starter";
430
- const formatQuota = `${r.scans_remaining ?? "?"}`;
452
+ const scansLeft = r.scans_remaining ?? 0;
453
+ const formatQuota = r.plan === "unlimited" ? "Unlimited" : `${scansLeft} scan${scansLeft !== 1 ? "s" : ""}`;
431
454
  console.info(chalk.bold.white("Account : ") + chalk.white(formatEmail));
432
455
  console.info(chalk.bold.white("Plan : ") + chalk.magenta(formatPlan));
433
- console.info(chalk.bold.white("Quota : ") + chalk.yellow(`${formatQuota} scans`));
456
+ console.info(chalk.bold.white("Quota : ") +
457
+ (scansLeft === 0 && r.plan !== "unlimited"
458
+ ? chalk.red(formatQuota)
459
+ : chalk.yellow(formatQuota)));
434
460
  console.info(chalk.bold.white("API : ") + chalk.cyan(cfg.apiUrl));
461
+ if (scansLeft === 0 && r.plan !== "starter" && r.plan !== "unlimited") {
462
+ console.info("");
463
+ console.info(chalk.yellow("⚠ Quota shows 0. If you recently subscribed, the webhook may still be"));
464
+ console.info(chalk.yellow(" propagating. Run ") +
465
+ chalk.bold.cyan("$ periderm whoami") +
466
+ chalk.yellow(" again in a few seconds, or visit:"));
467
+ console.info(chalk.underline.cyan(` ${cfg.apiUrl}/dashboard/billing`));
468
+ }
435
469
  });
436
470
  program
437
471
  .command("logout")
@@ -10,6 +10,31 @@ import { reportCliError } from "../error-report.js";
10
10
  // @babel/traverse ships CJS; pick the default export defensively.
11
11
  const traverse = traverseDefault.default ??
12
12
  traverseDefault;
13
+ function isToolingPath(file) {
14
+ return (/(^|\/)(scripts|vite\.config|vitest\.config|eslint\.config)/.test(file) ||
15
+ /\.(?:test|spec)\./.test(file) ||
16
+ /(^|\/)(test\d*|test-server)\.js$/.test(file));
17
+ }
18
+ function isInsideCreateServerFn(p) {
19
+ let cur = p;
20
+ while (cur) {
21
+ if (cur.node?.type === "CallExpression") {
22
+ let n = cur.node.callee;
23
+ while (n) {
24
+ if (n.type === "Identifier" && n.name === "createServerFn")
25
+ return true;
26
+ if (n.type === "MemberExpression")
27
+ n = n.object;
28
+ else if (n.type === "CallExpression")
29
+ n = n.callee;
30
+ else
31
+ break;
32
+ }
33
+ }
34
+ cur = cur.parentPath;
35
+ }
36
+ return false;
37
+ }
13
38
  const lineOf = (source, idx) => source.slice(0, idx).split("\n").length;
14
39
  function stripStrings(source) {
15
40
  return source.replace(/`[^`]*`|"[^"\n]*"|'[^'\n]*'/g, "''");
@@ -40,7 +65,7 @@ const silentCatch = (source, file, ast) => {
40
65
  CatchClause(p) {
41
66
  const body = p.node.body.body;
42
67
  const catchSrc = source.slice(p.node.start ?? 0, p.node.end ?? 0);
43
- if (/periderm-ignore/.test(catchSrc))
68
+ if (/periderm-ignore|keep original|ignore auth|unauthenticated|fallback/i.test(catchSrc))
44
69
  return;
45
70
  if (body.length === 0) {
46
71
  out.push(mkFinding({
@@ -66,6 +91,8 @@ const silentCatch = (source, file, ast) => {
66
91
  e.callee.object.name === "console");
67
92
  });
68
93
  if (onlyConsole) {
94
+ if (isToolingPath(file) || isInsideCreateServerFn(p))
95
+ return;
69
96
  out.push(mkFinding({
70
97
  id: "silent-catch-console",
71
98
  category: "Runtime Stability",
@@ -87,6 +114,8 @@ const silentCatch = (source, file, ast) => {
87
114
  // ───────────────────────────────────────────────────────────────────────
88
115
  const envLeak = (source, file) => {
89
116
  const out = [];
117
+ if (isToolingPath(file) || /(^|\/)scripts\//.test(file))
118
+ return out;
90
119
  const isServer = /\.server\.|\/api\/|\.functions\.|server-fn|createServerFn/.test(file + source);
91
120
  if (isServer)
92
121
  return out;
@@ -96,6 +125,9 @@ const envLeak = (source, file) => {
96
125
  const name = m[1];
97
126
  if (/^(NODE_ENV|VITE_)/.test(name))
98
127
  continue;
128
+ // Public-by-design names (Supabase anon / publishable keys, etc.)
129
+ if (/(PUBLISHABLE|ANON|PUBLIC)/.test(name))
130
+ continue;
99
131
  if (/(SECRET|KEY|TOKEN|PASSWORD|PRIVATE)/.test(name)) {
100
132
  out.push(mkFinding({
101
133
  id: "env-leak",
@@ -386,7 +418,7 @@ const consoleLog = (source, file) => {
386
418
  const out = [];
387
419
  if (!/\.(tsx|jsx|ts|js)$/.test(file))
388
420
  return out;
389
- if (/\.test\.|\.spec\.|\/scripts\//.test(file))
421
+ if (/\.test\.|\.spec\.|\/scripts\//.test(file) || isToolingPath(file))
390
422
  return out;
391
423
  const matches = source.match(/console\.log\s*\(/g);
392
424
  if (matches && matches.length >= 1) {
@@ -461,31 +493,60 @@ const placeholderContent = (source, file) => {
461
493
  // ───────────────────────────────────────────────────────────────────────
462
494
  // 15. fetch call without .catch / try/catch nearby
463
495
  // ───────────────────────────────────────────────────────────────────────
464
- const unhandledFetch = (source, file) => {
496
+ const unhandledFetch = (source, file, ast) => {
465
497
  const out = [];
466
498
  if (!/\.(tsx|jsx|ts|js)$/.test(file))
467
499
  return out;
500
+ if (isToolingPath(file) || /(^|\/)scripts\//.test(file))
501
+ return out;
502
+ const push = (line) => {
503
+ if (out.length)
504
+ return;
505
+ out.push(mkFinding({
506
+ id: "unhandled-fetch",
507
+ category: "Runtime Stability",
508
+ severity: "high",
509
+ file,
510
+ line,
511
+ message: "fetch call has no visible .catch or try/catch.",
512
+ why: "Network requests fail. Without a catch, the UI silently breaks and the user has no idea why.",
513
+ fix: "Wrap in try/catch (for await) or chain .catch — set an error state and surface a retry path.",
514
+ aiPrompt: `In ${file} near line ${line}, wrap the fetch call in try/catch (or chain .catch), set an error UI state on failure, and offer the user a retry button.`,
515
+ }));
516
+ };
517
+ if (ast) {
518
+ traverse(ast, {
519
+ CallExpression(p) {
520
+ const callee = p.node.callee;
521
+ if (callee.type !== "Identifier" || callee.name !== "fetch")
522
+ return;
523
+ let cur = p;
524
+ while (cur) {
525
+ if (cur.node?.type === "TryStatement")
526
+ return;
527
+ if (cur.node?.type === "CallExpression") {
528
+ const c = cur.node.callee;
529
+ if (c?.type === "MemberExpression" &&
530
+ c.property?.type === "Identifier" &&
531
+ c.property.name === "catch")
532
+ return;
533
+ }
534
+ cur = cur.parentPath;
535
+ }
536
+ push(p.node.loc?.start.line ?? 1);
537
+ },
538
+ });
539
+ return out;
540
+ }
468
541
  const re = /\bfetch\s*\(/g;
469
542
  let m;
470
543
  while ((m = re.exec(source))) {
471
- // Look 200 chars in either direction for .catch or try
472
- const window = source.slice(Math.max(0, m.index - 80), m.index + 400);
473
- const handled = /\.catch\s*\(|try\s*\{[\s\S]*?await\s+[\s\S]{0,40}fetch/.test(window) ||
474
- /try\s*\{/.test(source.slice(Math.max(0, m.index - 200), m.index));
475
- if (!handled) {
476
- out.push(mkFinding({
477
- id: "unhandled-fetch",
478
- category: "Runtime Stability",
479
- severity: "high",
480
- file,
481
- line: lineOf(source, m.index),
482
- message: "fetch call has no visible .catch or try/catch.",
483
- why: "Network requests fail. Without a catch, the UI silently breaks and the user has no idea why.",
484
- fix: "Wrap in try/catch (for await) or chain .catch — set an error state and surface a retry path.",
485
- aiPrompt: `In ${file} near line ${lineOf(source, m.index)}, wrap the fetch call in try/catch (or chain .catch), set an error UI state on failure, and offer the user a retry button.`,
486
- }));
487
- return out; // one per file is enough signal
488
- }
544
+ const before = source.slice(Math.max(0, m.index - 2500), m.index);
545
+ const after = source.slice(m.index, m.index + 400);
546
+ const handled = /\.catch\s*\(/.test(before + after) ||
547
+ /try\s*\{/.test(before);
548
+ if (!handled)
549
+ push(lineOf(source, m.index));
489
550
  }
490
551
  return out;
491
552
  };
@@ -602,7 +663,9 @@ const idorDataFetch = (source, file) => {
602
663
  let m;
603
664
  while ((m = re.exec(source))) {
604
665
  const window = source.slice(Math.max(0, m.index - 50), m.index + 200);
605
- if (!window.includes(".eq('user_id'") && !window.includes('.eq("user_id"')) {
666
+ if (!window.includes(".eq('user_id'") &&
667
+ !window.includes('.eq("user_id"') &&
668
+ !/\.eq\(\s*['"]id['"]\s*,\s*(currentUserId|userId|context\.userId|user\.id|data\.userId)/.test(window)) {
606
669
  out.push(mkFinding({
607
670
  id: "idor-data-fetch",
608
671
  category: "Security",
@@ -629,6 +692,9 @@ const deadEndPage = (source, file) => {
629
692
  return out; // Only check route pages
630
693
  if (/__root|_layout|\.server/.test(file))
631
694
  return out; // Ignore layouts
695
+ // Nested dashboard / admin / auth / device-login routes inherit chrome or are transient.
696
+ if (/\/dashboard\/|_authenticated[/\\]|cli-login|auth\.callback|\/auth\./.test(file))
697
+ return out;
632
698
  const isRoute = /createFileRoute|export default function/i.test(source);
633
699
  if (!isRoute)
634
700
  return out;
@@ -1057,8 +1123,12 @@ const missingErrorTyping = (source, file, ast) => {
1057
1123
  const hasGuard = new RegExp(`instanceof\\s+Error|typeof\\s+${errorName}\\s*===?\\s*['"]object['"]|${errorName}\\s+is\\s+|as\\s+Error`).test(catchBodySrc) ||
1058
1124
  new RegExp(`\\b${errorName}\\s+instanceof\\b`).test(catchBodySrc) ||
1059
1125
  /Error\s*\(/.test(catchBodySrc) ||
1060
- new RegExp(`isError\\s*\\(\\s*${errorName}\\s*\\)`).test(catchBodySrc);
1061
- if (!hasGuard) {
1126
+ new RegExp(`isError\\s*\\(\\s*${errorName}\\s*\\)`).test(catchBodySrc) ||
1127
+ new RegExp(`\\b${errorName}\\?\\.(message|code|name|stack)\\b`).test(catchBodySrc) ||
1128
+ new RegExp(`String\\s*\\(\\s*${errorName}\\s*\\)`).test(catchBodySrc);
1129
+ const param = p.node.param;
1130
+ const isExplicitAny = param.typeAnnotation?.typeAnnotation?.type === "TSAnyKeyword";
1131
+ if (!hasGuard && !isExplicitAny) {
1062
1132
  out.push(mkFinding({
1063
1133
  id: "missing-error-typing",
1064
1134
  category: "Data Integrity",
@@ -1083,7 +1153,7 @@ const unusedVariablesImports = (source, file, ast) => {
1083
1153
  const out = [];
1084
1154
  if (!ast || !/\.(tsx|jsx|ts|js|mjs|cjs)$/.test(file))
1085
1155
  return out;
1086
- if (/\.d\.ts$/.test(file))
1156
+ if (/\.d\.ts$/.test(file) || isToolingPath(file))
1087
1157
  return out;
1088
1158
  traverse(ast, {
1089
1159
  Program(p) {
@@ -1167,6 +1237,9 @@ const emptyLinkText = (source, file, ast) => {
1167
1237
  (a.name.name === "aria-label" || a.name.name === "aria-labelledby"));
1168
1238
  if (hasAriaLabel)
1169
1239
  return;
1240
+ const hasSpread = p.node.attributes.some((a) => a.type === "JSXSpreadAttribute");
1241
+ if (hasSpread)
1242
+ return;
1170
1243
  const parent = p.parentPath.node;
1171
1244
  if (parent.type !== "JSXElement")
1172
1245
  return;
@@ -24,8 +24,8 @@ export async function initPredictor() {
24
24
  if (session)
25
25
  return;
26
26
  try {
27
- ort = await import("onnxruntime-web");
28
- debugMl("runtime: onnxruntime-web");
27
+ ort = await import("onnxruntime-node");
28
+ debugMl("runtime: onnxruntime-node");
29
29
  }
30
30
  catch {
31
31
  debugMl("no ONNX runtime available");
@@ -23,11 +23,10 @@ async function readMaybe(p) {
23
23
  function isMarketingRoute(rel) {
24
24
  if (!/routes\//.test(rel))
25
25
  return false;
26
- if (/_authenticated|admin|dashboard|api\//.test(rel))
26
+ if (/_authenticated|admin|dashboard|api\/|auth\.|cli-login|callback/.test(rel))
27
27
  return false;
28
- return (/(?:^|\/)index\.(tsx|jsx)$/.test(rel) ||
29
- /routes\/(?:index|__root)\.(tsx|jsx)$/.test(rel) ||
30
- !/_authenticated|admin/.test(rel));
28
+ return (/(?:^|\/)(?:index|about|docs|privacy|terms|reddit)(?:-reddit)?\.(tsx|jsx)$/.test(rel) ||
29
+ /routes\/(?:index|__root|about|docs|privacy|terms|reddit)\.(tsx|jsx)$/.test(rel));
31
30
  }
32
31
  export const SEO_CHECK_COUNT = 5;
33
32
  export async function runSeoChecks(root, files) {
@@ -11,6 +11,12 @@ export async function walk(root, extraIgnores = []) {
11
11
  "!**/*.d.ts",
12
12
  "!**/routeTree.gen.*",
13
13
  "!**/packages/cli/**", // never scan the scanner itself
14
+ "!**/scripts/**",
15
+ "!**/test.js",
16
+ "!**/test2.js",
17
+ "!**/test-server.js",
18
+ "!**/fix-*.mjs",
19
+ "!**/*.{test,spec}.{ts,tsx,js,jsx,mjs,cjs}",
14
20
  ];
15
21
  // Cloud policy ignores: normalize to negated globs
16
22
  const cloudIgnoreGlobs = extraIgnores.map((ig) => (ig.startsWith("!") ? ig : `!${ig}`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "periderm-cli",
3
- "version": "0.1.71",
3
+ "version": "0.1.73",
4
4
  "description": "Periderm CLI: A pre-launch checklist to catch user-losing bugs, legal liabilities, revenue leaks, runaway cloud bills and so many more before you ship.",
5
5
  "type": "module",
6
6
  "preferGlobal": true,
@@ -54,7 +54,7 @@
54
54
  "chalk": "^5.3.0",
55
55
  "commander": "^12.1.0",
56
56
  "fast-glob": "^3.3.2",
57
- "onnxruntime-web": "^1.29.0",
57
+ "onnxruntime-node": "^1.29.0",
58
58
  "open": "^10.1.0",
59
59
  "ora": "^9.4.1"
60
60
  },