@pipelab/core-node 1.0.0-beta.22 → 1.0.0-beta.25

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.mjs CHANGED
@@ -10,6 +10,7 @@ import { WebSocket, WebSocketServer as WebSocketServer$1 } from "ws";
10
10
  import http from "node:http";
11
11
  import { nanoid } from "nanoid";
12
12
  import { SubscriptionRequiredError, WebSocketError, appSettingsMigrator, connectionsMigrator, fileRepoMigrations, isRequired, isSupabaseAvailable, isWebSocketRequestMessage, processGraph, savedFileMigrator, supabase, transformUrl, useLogger, usePlugins } from "@pipelab/shared";
13
+ import slash from "slash";
13
14
  import { execa } from "execa";
14
15
  import checkDiskSpace from "check-disk-space";
15
16
  import dns from "node:dns/promises";
@@ -129,7 +130,7 @@ var PipelabContext = class {
129
130
  async createTempFolder(prefix = "pipelab-") {
130
131
  const baseDir = this.getTempPath();
131
132
  await mkdir(baseDir, { recursive: true });
132
- return await mkdtemp(join(await realpath(baseDir), prefix));
133
+ return mkdtemp(join(await realpath(baseDir), prefix));
133
134
  }
134
135
  getCachePath(folder, ...subpaths) {
135
136
  const base = this.getSettings()?.cacheFolder || join(this.userDataPath, "cache");
@@ -461,6 +462,113 @@ const registerShellHandlers = (_context) => {
461
462
  });
462
463
  };
463
464
  //#endregion
465
+ //#region src/fs-utils.ts
466
+ function removeTrailingSlash(path) {
467
+ return path.replace(/[\\/]+$/, "");
468
+ }
469
+ function isWindowsDriveRoot(path) {
470
+ return /^[a-z]:$/.test(path);
471
+ }
472
+ const windowsSystemFolders = [
473
+ "windows",
474
+ "program files",
475
+ "program files (x86)",
476
+ "users",
477
+ "programdata",
478
+ "perflogs"
479
+ ];
480
+ function isWindowsSystemDirectory(path) {
481
+ if (!isWindowsDriveRoot(path.substring(0, 2)) || path.charAt(2) !== "/") return false;
482
+ const folder = path.substring(3);
483
+ return windowsSystemFolders.includes(folder);
484
+ }
485
+ const unixSystemDirectories = new Set([
486
+ "",
487
+ "/usr",
488
+ "/var",
489
+ "/opt",
490
+ "/etc",
491
+ "/bin",
492
+ "/sbin",
493
+ "/lib",
494
+ "/lib64",
495
+ "/boot",
496
+ "/sys",
497
+ "/proc",
498
+ "/dev",
499
+ "/run",
500
+ "/home",
501
+ "/root",
502
+ "/mnt",
503
+ "/media",
504
+ "/srv",
505
+ "/applications",
506
+ "/library",
507
+ "/system",
508
+ "/volumes",
509
+ "/snap"
510
+ ]);
511
+ const homeDirectory = removeTrailingSlash(slash(resolve(homedir()))).toLowerCase();
512
+ const additionalProtectedPaths = [
513
+ getDefaultUserDataPath("dev"),
514
+ getDefaultUserDataPath("beta"),
515
+ getDefaultUserDataPath("prod"),
516
+ projectRoot,
517
+ process.cwd(),
518
+ "/tmp",
519
+ "/var/tmp",
520
+ process.env.TEMP,
521
+ process.env.TMP,
522
+ join(homedir(), "AppData"),
523
+ join(homedir(), "AppData", "Local"),
524
+ join(homedir(), "AppData", "Roaming"),
525
+ join(homedir(), "Library"),
526
+ join(homedir(), "Library", "Application Support"),
527
+ join(homedir(), ".config"),
528
+ join(homedir(), ".local"),
529
+ join(homedir(), ".local", "share"),
530
+ join(homedir(), ".cache"),
531
+ join(homedir(), "OneDrive"),
532
+ join(homedir(), "Dropbox"),
533
+ join(homedir(), ".ssh"),
534
+ join(homedir(), ".gnupg"),
535
+ join(homedir(), ".aws"),
536
+ join(homedir(), ".docker"),
537
+ join(homedir(), ".kube"),
538
+ join(homedir(), ".vscode"),
539
+ join(homedir(), ".vscode-insiders"),
540
+ join(homedir(), ".cursor"),
541
+ join(homedir(), ".npm"),
542
+ join(homedir(), ".pnpm-state"),
543
+ join(homedir(), ".yarn"),
544
+ join(homedir(), ".cargo"),
545
+ join(homedir(), ".rustup"),
546
+ join(homedir(), ".m2"),
547
+ join(homedir(), ".gradle")
548
+ ].filter((p) => typeof p === "string" && p.length > 0);
549
+ const userSubdirectories = new Set([
550
+ join(homedir(), "Downloads"),
551
+ join(homedir(), "Documents"),
552
+ join(homedir(), "Desktop"),
553
+ join(homedir(), "Pictures"),
554
+ join(homedir(), "Music"),
555
+ join(homedir(), "Videos"),
556
+ join(homedir(), "Saved Games"),
557
+ join(homedir(), "Contacts"),
558
+ join(homedir(), "Searches"),
559
+ join(homedir(), "Links"),
560
+ join(homedir(), "3D Objects"),
561
+ ...additionalProtectedPaths
562
+ ].map((p) => removeTrailingSlash(slash(resolve(p))).toLowerCase()));
563
+ /**
564
+ * Checks if a path matches a critical user or system directory.
565
+ */
566
+ function isPathBlacklisted(pathToCheck) {
567
+ if (!pathToCheck) return false;
568
+ const normalized = removeTrailingSlash(slash(resolve(pathToCheck))).toLowerCase();
569
+ return normalized === homeDirectory || unixSystemDirectories.has(normalized) || userSubdirectories.has(normalized) || isWindowsDriveRoot(normalized) || isWindowsSystemDirectory(normalized);
570
+ }
571
+ //#endregion
464
572
  //#region src/handlers/fs.ts
465
573
  const registerFsHandlers = (_context) => {
466
574
  const { handle } = useAPI();
@@ -532,6 +640,26 @@ const registerFsHandlers = (_context) => {
532
640
  });
533
641
  }
534
642
  });
643
+ handle("fs:isPathBlacklisted", async (event, { value, send }) => {
644
+ try {
645
+ send({
646
+ type: "end",
647
+ data: {
648
+ type: "success",
649
+ result: { isBlacklisted: isPathBlacklisted(value.path) }
650
+ }
651
+ });
652
+ } catch (error) {
653
+ logger().error("Failed to check blacklist for path:", error);
654
+ send({
655
+ type: "end",
656
+ data: {
657
+ type: "error",
658
+ ipcError: error instanceof Error ? error.message : "Unable to check path blacklist"
659
+ }
660
+ });
661
+ }
662
+ });
535
663
  };
536
664
  //#endregion
537
665
  //#region src/handlers/config.ts
@@ -8914,8 +9042,9 @@ async function serveCommand(options, version, _dirname) {
8914
9042
  let rawAssetFolder;
8915
9043
  if (!isDev) rawAssetFolder = await fetchPipelabAsset("@pipelab/ui", releaseTag, { context });
8916
9044
  const server = http$1.createServer(async (request, response) => {
8917
- if (request.url?.startsWith("/media-file/")) {
8918
- const encodedPath = request.url.substring(12);
9045
+ const urlObj = request.url ? new URL(request.url, "http://localhost") : null;
9046
+ if (urlObj && urlObj.pathname.startsWith("/media-file/")) {
9047
+ const encodedPath = urlObj.pathname.substring(12);
8919
9048
  const filePath = decodeURIComponent(encodedPath);
8920
9049
  const normalizedPath = filePath.startsWith("/") && filePath.match(/^\/[a-zA-Z]:/) ? filePath.substring(1) : filePath;
8921
9050
  if (existsSync(normalizedPath)) try {
@@ -9485,14 +9614,23 @@ const handleActionExecute = async (nodeId, pluginId, params, mainWindow, send, a
9485
9614
  inputs: resolvedInputs,
9486
9615
  log: (...args) => {
9487
9616
  const decorator = `[${node.node.name}]`;
9488
- const logArgs = [decorator, ...args];
9617
+ const formattedArgs = args.map((arg) => {
9618
+ if (arg instanceof Error) return arg.stack || arg.message || String(arg);
9619
+ if (typeof arg === "object" && arg !== null) try {
9620
+ return JSON.stringify(arg, null, 2);
9621
+ } catch {
9622
+ return String(arg);
9623
+ }
9624
+ return arg;
9625
+ });
9626
+ const logArgs = [decorator, ...formattedArgs];
9489
9627
  logger().info(...logArgs);
9490
9628
  send({
9491
9629
  type: "log",
9492
9630
  data: {
9493
9631
  decorator,
9494
9632
  time: Date.now(),
9495
- message: args
9633
+ message: formattedArgs
9496
9634
  }
9497
9635
  });
9498
9636
  },
@@ -53810,6 +53948,6 @@ async function fetchLatestDesktopRelease(options = {}) {
53810
53948
  return latest;
53811
53949
  }
53812
53950
  //#endregion
53813
- export { BuildHistoryStorage, CacheFolder, PipelabContext, WebSocketServer, builtInPlugins, deletePipelineConfigFileByName, deletePipelineConfigFileByPath, downloadFile, ensure, ensureNodeJS, ensurePNPM, executeGraphWithHistory, extractTarGz, extractZip, fetchLatestDesktopRelease, fetchLatestPackageRelease, fetchPackage, fetchPackageReleases, fetchPipelabAsset, fetchPipelabCli, fetchPipelabPlugin, findInstalledPlugins, getDefaultUserDataPath, getFinalPlugins, getFolderSize, handleActionExecute, isDev, isOnline, loadCustomPlugin, loadPipelabPlugin, projectRoot, registerAgentsHandlers, registerAllHandlers, registerConfigHandlers, registerEngineHandlers, registerFsHandlers, registerHistoryHandlers, registerShellHandlers, runPipelineCommand, runPnpm, runWithLiveLogs, sendStartupProgress, sendStartupReady, serveCommand, setupConnectionsConfigFile, setupPipelineConfigFileByName, setupPipelineConfigFileByPath, setupProjectsConfigFile, setupSettingsConfigFile, useAPI, usePluginAPI, webSocketServer, zipFolder };
53951
+ export { BuildHistoryStorage, CacheFolder, PipelabContext, WebSocketServer, builtInPlugins, deletePipelineConfigFileByName, deletePipelineConfigFileByPath, downloadFile, ensure, ensureNodeJS, ensurePNPM, executeGraphWithHistory, extractTarGz, extractZip, fetchLatestDesktopRelease, fetchLatestPackageRelease, fetchPackage, fetchPackageReleases, fetchPipelabAsset, fetchPipelabCli, fetchPipelabPlugin, findInstalledPlugins, getDefaultUserDataPath, getFinalPlugins, getFolderSize, handleActionExecute, isDev, isOnline, isPathBlacklisted, loadCustomPlugin, loadPipelabPlugin, projectRoot, registerAgentsHandlers, registerAllHandlers, registerConfigHandlers, registerEngineHandlers, registerFsHandlers, registerHistoryHandlers, registerShellHandlers, runPipelineCommand, runPnpm, runWithLiveLogs, sendStartupProgress, sendStartupReady, serveCommand, setupConnectionsConfigFile, setupPipelineConfigFileByName, setupPipelineConfigFileByPath, setupProjectsConfigFile, setupSettingsConfigFile, useAPI, usePluginAPI, webSocketServer, zipFolder };
53814
53952
 
53815
53953
  //# sourceMappingURL=index.mjs.map