@trops/dash-core 0.1.743 → 0.1.744
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/electron/index.js +155 -0
- package/dist/electron/index.js.map +1 -1
- package/package.json +1 -1
package/dist/electron/index.js
CHANGED
|
@@ -11648,6 +11648,130 @@ function requireScanWidgetPackagePermissions () {
|
|
|
11648
11648
|
return scanWidgetPackagePermissions_1;
|
|
11649
11649
|
}
|
|
11650
11650
|
|
|
11651
|
+
/**
|
|
11652
|
+
* scanWidgetBotCalls.js — refuse widget packages that start the user's bots
|
|
11653
|
+
* directly (team-dashboards PRD TD-005 AC1, create-entry phase 4c).
|
|
11654
|
+
*
|
|
11655
|
+
* Widgets may only start a bot by publishing an event the user wired the
|
|
11656
|
+
* bot to ("Run on events"). A package whose code reaches `mainApi.bots`
|
|
11657
|
+
* (run, ask, pause… anything) is refused at install, before it's registered.
|
|
11658
|
+
* Dash's own bot widgets are built in, not packages, so this never sees them.
|
|
11659
|
+
*
|
|
11660
|
+
* What it catches: `mainApi.bots`, `mainApi?.bots`, `mainApi["bots"]`,
|
|
11661
|
+
* `mainApi['bots']`, and `{ bots } = …mainApi` destructuring. It reads every
|
|
11662
|
+
* .js/.jsx/.cjs/.mjs/.ts/.tsx file, `dist/` included (that's the code that
|
|
11663
|
+
* runs), skipping node_modules.
|
|
11664
|
+
*
|
|
11665
|
+
* Limitation (stated in the PRD): widgets share the app's window, so code
|
|
11666
|
+
* that builds the name at runtime could still reach it — the same is true
|
|
11667
|
+
* of every mainApi namespace. This blocks plain and AI-written use.
|
|
11668
|
+
*/
|
|
11669
|
+
|
|
11670
|
+
var scanWidgetBotCalls_1;
|
|
11671
|
+
var hasRequiredScanWidgetBotCalls;
|
|
11672
|
+
|
|
11673
|
+
function requireScanWidgetBotCalls () {
|
|
11674
|
+
if (hasRequiredScanWidgetBotCalls) return scanWidgetBotCalls_1;
|
|
11675
|
+
hasRequiredScanWidgetBotCalls = 1;
|
|
11676
|
+
|
|
11677
|
+
const fs = require$$0$3;
|
|
11678
|
+
const path = require$$1$2;
|
|
11679
|
+
|
|
11680
|
+
const CODE_EXT = new Set([".js", ".jsx", ".cjs", ".mjs", ".ts", ".tsx"]);
|
|
11681
|
+
const SKIP_DIRS = new Set(["node_modules", ".git"]);
|
|
11682
|
+
const MAX_FILE_BYTES = 5 * 1024 * 1024;
|
|
11683
|
+
|
|
11684
|
+
const PATTERNS = [
|
|
11685
|
+
/mainApi\s*(?:\?\.|\.)\s*bots\b/,
|
|
11686
|
+
/mainApi\s*(?:\?\.)?\s*\[\s*["'`]bots["'`]\s*\]/,
|
|
11687
|
+
/\{[^{}]*\bbots\b[^{}]*\}\s*=\s*[\w.?]*mainApi\b/,
|
|
11688
|
+
];
|
|
11689
|
+
|
|
11690
|
+
/** Whether a piece of code reaches mainApi.bots. */
|
|
11691
|
+
function callsBots(code) {
|
|
11692
|
+
const src = String(code || "");
|
|
11693
|
+
return PATTERNS.some((re) => re.test(src));
|
|
11694
|
+
}
|
|
11695
|
+
|
|
11696
|
+
function* walk(dir, root) {
|
|
11697
|
+
let entries = [];
|
|
11698
|
+
try {
|
|
11699
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
11700
|
+
} catch (_e) {
|
|
11701
|
+
return;
|
|
11702
|
+
}
|
|
11703
|
+
for (const e of entries) {
|
|
11704
|
+
if (e.isSymbolicLink()) continue;
|
|
11705
|
+
const full = path.join(dir, e.name);
|
|
11706
|
+
if (e.isDirectory()) {
|
|
11707
|
+
if (!SKIP_DIRS.has(e.name)) yield* walk(full);
|
|
11708
|
+
} else if (e.isFile() && CODE_EXT.has(path.extname(e.name))) {
|
|
11709
|
+
yield full;
|
|
11710
|
+
}
|
|
11711
|
+
}
|
|
11712
|
+
}
|
|
11713
|
+
|
|
11714
|
+
/**
|
|
11715
|
+
* @param {string} packageDir the installed (extracted / copied) package
|
|
11716
|
+
* @returns {{ ok: boolean, files: string[] }} files that reach mainApi.bots
|
|
11717
|
+
*/
|
|
11718
|
+
function scanWidgetBotCalls(packageDir) {
|
|
11719
|
+
const files = [];
|
|
11720
|
+
for (const file of walk(packageDir)) {
|
|
11721
|
+
let size = 0;
|
|
11722
|
+
try {
|
|
11723
|
+
size = fs.statSync(file).size;
|
|
11724
|
+
} catch (_e) {
|
|
11725
|
+
continue;
|
|
11726
|
+
}
|
|
11727
|
+
if (size > MAX_FILE_BYTES) continue;
|
|
11728
|
+
let code = "";
|
|
11729
|
+
try {
|
|
11730
|
+
code = fs.readFileSync(file, "utf8");
|
|
11731
|
+
} catch (_e) {
|
|
11732
|
+
continue;
|
|
11733
|
+
}
|
|
11734
|
+
if (callsBots(code)) files.push(path.relative(packageDir, file));
|
|
11735
|
+
}
|
|
11736
|
+
return { ok: files.length === 0, files };
|
|
11737
|
+
}
|
|
11738
|
+
|
|
11739
|
+
/** The refusal, in words. */
|
|
11740
|
+
function botCallsMessage(widgetName, files) {
|
|
11741
|
+
return `${widgetName} wasn't installed: it starts your bots directly (${files
|
|
11742
|
+
.slice(0, 3)
|
|
11743
|
+
.join(
|
|
11744
|
+
", ",
|
|
11745
|
+
)}). Widgets may only send events that you wire a bot to, under the bot's "Run on events".`;
|
|
11746
|
+
}
|
|
11747
|
+
|
|
11748
|
+
/**
|
|
11749
|
+
* Throw (after removing the package folder) when it calls bots.
|
|
11750
|
+
* @param {string} widgetName
|
|
11751
|
+
* @param {string} packageDir
|
|
11752
|
+
*/
|
|
11753
|
+
function assertNoBotCalls(widgetName, packageDir) {
|
|
11754
|
+
const res = scanWidgetBotCalls(packageDir);
|
|
11755
|
+
if (res.ok) return;
|
|
11756
|
+
try {
|
|
11757
|
+
fs.rmSync(packageDir, { recursive: true, force: true });
|
|
11758
|
+
} catch (_e) {
|
|
11759
|
+
// leave it; it isn't registered either way
|
|
11760
|
+
}
|
|
11761
|
+
const err = new Error(botCallsMessage(widgetName, res.files));
|
|
11762
|
+
err.code = "WIDGET_CALLS_BOTS";
|
|
11763
|
+
throw err;
|
|
11764
|
+
}
|
|
11765
|
+
|
|
11766
|
+
scanWidgetBotCalls_1 = {
|
|
11767
|
+
callsBots,
|
|
11768
|
+
scanWidgetBotCalls,
|
|
11769
|
+
assertNoBotCalls,
|
|
11770
|
+
botCallsMessage,
|
|
11771
|
+
};
|
|
11772
|
+
return scanWidgetBotCalls_1;
|
|
11773
|
+
}
|
|
11774
|
+
|
|
11651
11775
|
/*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
|
|
11652
11776
|
/**
|
|
11653
11777
|
* 5KB JS implementation of ed25519 EdDSA signatures.
|
|
@@ -15170,6 +15294,13 @@ var schedulerController_1 = schedulerController$2;
|
|
|
15170
15294
|
// Non-fatal — the gate's runtime JIT still backs us up.
|
|
15171
15295
|
}
|
|
15172
15296
|
|
|
15297
|
+
// Widgets may not start bots directly — only by events the user
|
|
15298
|
+
// wires a bot to (TD-005). Refused here, before it's registered.
|
|
15299
|
+
requireScanWidgetBotCalls().assertNoBotCalls(
|
|
15300
|
+
widgetName,
|
|
15301
|
+
widgetPath,
|
|
15302
|
+
);
|
|
15303
|
+
|
|
15173
15304
|
let config = await this.loadWidgetConfig(widgetName, widgetPath);
|
|
15174
15305
|
|
|
15175
15306
|
if (dashConfigPath) {
|
|
@@ -15264,6 +15395,7 @@ var schedulerController_1 = schedulerController$2;
|
|
|
15264
15395
|
});
|
|
15265
15396
|
const results = [];
|
|
15266
15397
|
let skipped = 0;
|
|
15398
|
+
const refused = [];
|
|
15267
15399
|
|
|
15268
15400
|
for (const entry of entries) {
|
|
15269
15401
|
if (!entry.isDirectory()) continue;
|
|
@@ -15281,6 +15413,21 @@ var schedulerController_1 = schedulerController$2;
|
|
|
15281
15413
|
continue;
|
|
15282
15414
|
}
|
|
15283
15415
|
|
|
15416
|
+
// Widgets that start bots directly aren't loaded (TD-005).
|
|
15417
|
+
const botScan =
|
|
15418
|
+
requireScanWidgetBotCalls().scanWidgetBotCalls(widgetPath);
|
|
15419
|
+
if (!botScan.ok) {
|
|
15420
|
+
console.warn(
|
|
15421
|
+
requireScanWidgetBotCalls().botCallsMessage(
|
|
15422
|
+
entry.name,
|
|
15423
|
+
botScan.files,
|
|
15424
|
+
),
|
|
15425
|
+
);
|
|
15426
|
+
refused.push(entry.name);
|
|
15427
|
+
skipped++;
|
|
15428
|
+
continue;
|
|
15429
|
+
}
|
|
15430
|
+
|
|
15284
15431
|
const config = await this.loadWidgetConfig(entry.name, widgetPath);
|
|
15285
15432
|
this.registerWidget(entry.name, config, widgetPath, false);
|
|
15286
15433
|
|
|
@@ -15297,6 +15444,7 @@ var schedulerController_1 = schedulerController$2;
|
|
|
15297
15444
|
|
|
15298
15445
|
// Attach skipped count as metadata on the array
|
|
15299
15446
|
results.skipped = skipped;
|
|
15447
|
+
results.refused = refused;
|
|
15300
15448
|
return results;
|
|
15301
15449
|
} catch (error) {
|
|
15302
15450
|
console.error(
|
|
@@ -15497,6 +15645,13 @@ var schedulerController_1 = schedulerController$2;
|
|
|
15497
15645
|
);
|
|
15498
15646
|
}
|
|
15499
15647
|
|
|
15648
|
+
// Widgets may not start bots directly — only by events the user
|
|
15649
|
+
// wires a bot to (TD-005). Refused here, before it's registered.
|
|
15650
|
+
requireScanWidgetBotCalls().assertNoBotCalls(
|
|
15651
|
+
widgetName,
|
|
15652
|
+
widgetPath,
|
|
15653
|
+
);
|
|
15654
|
+
|
|
15500
15655
|
let config = await this.loadWidgetConfig(widgetName, widgetPath);
|
|
15501
15656
|
|
|
15502
15657
|
if (dashConfigUrl) {
|