luxray-agent 0.1.0 → 0.1.1

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.
@@ -3,9 +3,9 @@
3
3
  // src/bin/luxray-agent.ts
4
4
  import * as os3 from "os";
5
5
  import * as readline from "readline/promises";
6
- import { existsSync, readFileSync } from "fs";
6
+ import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
7
7
  import { mkdir as mkdir3 } from "fs/promises";
8
- import { dirname as dirname2, join as join6 } from "path";
8
+ import { dirname as dirname2, join as join7 } from "path";
9
9
 
10
10
  // src/vault/credential-vault.ts
11
11
  import * as fs from "fs/promises";
@@ -443,6 +443,10 @@ var AgentClient = class {
443
443
  }
444
444
  };
445
445
 
446
+ // ../streaming/dist/config.js
447
+ import { existsSync, readFileSync, readdirSync } from "fs";
448
+ import { join as join2 } from "path";
449
+
446
450
  // ../streaming/dist/errors.js
447
451
  var StreamUnavailableError = class extends Error {
448
452
  brokers;
@@ -460,16 +464,68 @@ var StreamProtocolError = class extends Error {
460
464
 
461
465
  // ../streaming/dist/config.js
462
466
  var DEFAULT_BROKERS = "127.0.0.1:9092";
467
+ function findRootCert() {
468
+ try {
469
+ const cwd = process.cwd();
470
+ const commonNames = [
471
+ "cl.pem",
472
+ "cl.cert",
473
+ "cl.crt",
474
+ "ca.pem",
475
+ "ca.cert",
476
+ "ca.crt",
477
+ "certificate.pem",
478
+ "certificate.crt"
479
+ ];
480
+ for (const name of commonNames) {
481
+ const fullPath = join2(cwd, name);
482
+ if (existsSync(fullPath)) {
483
+ return readFileSync(fullPath, "utf-8");
484
+ }
485
+ }
486
+ const files = readdirSync(cwd);
487
+ for (const file of files) {
488
+ const lower = file.toLowerCase();
489
+ if ((lower.includes("cl") || lower.includes("ca") || lower.includes("cert")) && (lower.endsWith(".pem") || lower.endsWith(".crt") || lower.endsWith(".cert"))) {
490
+ return readFileSync(join2(cwd, file), "utf-8");
491
+ }
492
+ }
493
+ } catch {
494
+ }
495
+ return void 0;
496
+ }
497
+ function resolveSsl(env, brokers, hasSasl) {
498
+ if (env["KAFKA_SSL"]?.toLowerCase() === "false") {
499
+ return false;
500
+ }
501
+ const cert = findRootCert();
502
+ const explicitSsl = env["KAFKA_SSL"]?.toLowerCase() === "true";
503
+ const isRemote = brokers.some((b) => !b.startsWith("127.0.0.1") && !b.startsWith("localhost"));
504
+ const shouldEnable = explicitSsl || hasSasl || !!cert || isRemote;
505
+ if (!shouldEnable) {
506
+ return false;
507
+ }
508
+ if (cert) {
509
+ return {
510
+ ca: [cert],
511
+ rejectUnauthorized: true
512
+ };
513
+ }
514
+ return true;
515
+ }
463
516
  function streamConfigFromEnv(env = process.env, overrides = {}) {
464
- const brokers = (env["KAFKA_BROKERS"] ?? DEFAULT_BROKERS).split(",").map((broker) => broker.trim()).filter((broker) => broker.length > 0);
517
+ const rawBrokers = env["KAFKA_BROKERS"] ?? env["KAFKA_HOST"] ?? DEFAULT_BROKERS;
518
+ const brokers = rawBrokers.split(",").map((broker) => broker.trim()).filter((broker) => broker.length > 0);
465
519
  if (brokers.length === 0) {
466
520
  throw new Error("KAFKA_BROKERS is set but lists no broker address.");
467
521
  }
522
+ const sasl = saslFromEnv(env);
523
+ const ssl = overrides.ssl !== void 0 ? overrides.ssl : resolveSsl(env, brokers, sasl !== null);
468
524
  const merged = {
469
525
  brokers,
470
526
  clientId: env["KAFKA_CLIENT_ID"] ?? "luxray",
471
- ssl: (env["KAFKA_SSL"] ?? "").toLowerCase() === "true",
472
- sasl: saslFromEnv(env),
527
+ ssl,
528
+ sasl,
473
529
  connectionTimeoutMs: 5e3,
474
530
  retryCount: 2,
475
531
  topicPartitions: positiveInt(env["KAFKA_TOPIC_PARTITIONS"], 3, "KAFKA_TOPIC_PARTITIONS"),
@@ -479,11 +535,11 @@ function streamConfigFromEnv(env = process.env, overrides = {}) {
479
535
  return { ...merged, retryCount: Math.max(1, merged.retryCount) };
480
536
  }
481
537
  function saslFromEnv(env) {
482
- const username = env["KAFKA_SASL_USERNAME"];
483
- const password = env["KAFKA_SASL_PASSWORD"];
538
+ const username = env["KAFKA_SASL_USERNAME"] ?? env["KAFKA_USER"] ?? env["KAFKA_USERNAME"];
539
+ const password = env["KAFKA_SASL_PASSWORD"] ?? env["KAFKA_PASS"] ?? env["KAFKA_PASSWORD"];
484
540
  if (!username || !password)
485
541
  return null;
486
- const raw = (env["KAFKA_SASL_MECHANISM"] ?? "plain").toLowerCase();
542
+ const raw = (env["KAFKA_SASL_MECHANISM"] ?? "scram-sha-512").toLowerCase();
487
543
  if (raw !== "plain" && raw !== "scram-sha-256" && raw !== "scram-sha-512") {
488
544
  throw new Error(`KAFKA_SASL_MECHANISM must be plain, scram-sha-256 or scram-sha-512 (got ${raw}).`);
489
545
  }
@@ -1529,14 +1585,14 @@ function abortError() {
1529
1585
 
1530
1586
  // src/execution/exploration-job.ts
1531
1587
  import { createHash as createHash2 } from "crypto";
1532
- import { join as join5 } from "path";
1588
+ import { join as join6 } from "path";
1533
1589
 
1534
1590
  // ../../apps/exploration-worker/dist/exploration-worker.js
1535
- import { join as join3 } from "path";
1591
+ import { join as join4 } from "path";
1536
1592
 
1537
1593
  // ../../apps/exploration-worker/dist/artifacts/run-artifacts.js
1538
1594
  import { mkdir as mkdir2, writeFile as writeFile2 } from "fs/promises";
1539
- import { join as join2 } from "path";
1595
+ import { join as join3 } from "path";
1540
1596
  var SENSITIVE_HEADERS = /* @__PURE__ */ new Set([
1541
1597
  "authorization",
1542
1598
  "cookie",
@@ -1554,9 +1610,9 @@ async function writeRunArtifacts(dir, outcome, options) {
1554
1610
  await mkdir2(dir, { recursive: true });
1555
1611
  const paths = {
1556
1612
  dir,
1557
- runFile: join2(dir, "run.json"),
1558
- pagesFile: join2(dir, "pages.json"),
1559
- transactionsFile: join2(dir, "transactions.json")
1613
+ runFile: join3(dir, "run.json"),
1614
+ pagesFile: join3(dir, "pages.json"),
1615
+ transactionsFile: join3(dir, "transactions.json")
1560
1616
  };
1561
1617
  const transactions = redactTransactions(outcome.transactions, options);
1562
1618
  const secrets = usableSecrets(options?.secrets);
@@ -3321,7 +3377,7 @@ function authSecrets(auth) {
3321
3377
 
3322
3378
  // src/execution/openapi-spec.ts
3323
3379
  import { writeFile as writeFile3 } from "fs/promises";
3324
- import { join as join4 } from "path";
3380
+ import { join as join5 } from "path";
3325
3381
 
3326
3382
  // ../normalization/dist/url/url-parser.js
3327
3383
  var DUMMY_BASE = "http://localhost";
@@ -7966,8 +8022,8 @@ async function writeOpenApiArtifacts(directory, spec) {
7966
8022
  if (!spec.json || !spec.yaml) {
7967
8023
  throw new Error("OpenAPI artifact content was omitted before it could be written.");
7968
8024
  }
7969
- const jsonPath = join4(directory, "openapi.json");
7970
- const yamlPath = join4(directory, "openapi.yaml");
8025
+ const jsonPath = join5(directory, "openapi.json");
8026
+ const yamlPath = join5(directory, "openapi.yaml");
7971
8027
  await writeFile3(jsonPath, spec.json.content, "utf8");
7972
8028
  await writeFile3(yamlPath, spec.yaml.content, "utf8");
7973
8029
  return { jsonPath, yamlPath };
@@ -8024,7 +8080,7 @@ function createExplorationRunner(worker, options) {
8024
8080
  maxPages: scope.maxPages ?? DEFAULT_EXPLORATION_LIMITS.maxPages,
8025
8081
  maxDepth: scope.maxDepth ?? DEFAULT_EXPLORATION_LIMITS.maxDepth
8026
8082
  },
8027
- artifactDir: join5(options.artifactRoot, task.id),
8083
+ artifactDir: join6(options.artifactRoot, task.id),
8028
8084
  headless: options.headless ?? true,
8029
8085
  includeSecrets: options.includeSecrets,
8030
8086
  ...auth?.storageStatePath ? { storageStatePath: auth.storageStatePath } : {},
@@ -8508,8 +8564,8 @@ function parseAuthHeadersJson(raw) {
8508
8564
  let text = raw;
8509
8565
  if (raw.startsWith("@")) {
8510
8566
  const path2 = raw.slice(1);
8511
- if (!existsSync(path2)) throw new Error(`Auth headers file not found: ${path2}`);
8512
- text = readFileSync(path2, "utf8");
8567
+ if (!existsSync2(path2)) throw new Error(`Auth headers file not found: ${path2}`);
8568
+ text = readFileSync2(path2, "utf8");
8513
8569
  }
8514
8570
  let parsed;
8515
8571
  try {
@@ -8534,7 +8590,7 @@ async function resolveExploreAuth(flags, startUrl, options) {
8534
8590
  const saveStorageStatePath = flagValue(flags, "save-auth-state");
8535
8591
  const authStatePath = flagValue(flags, "auth-state");
8536
8592
  if (authStatePath) {
8537
- if (!existsSync(authStatePath)) {
8593
+ if (!existsSync2(authStatePath)) {
8538
8594
  throw new Error(`--auth-state file not found: ${authStatePath}`);
8539
8595
  }
8540
8596
  return {
@@ -8820,7 +8876,7 @@ Or configure environment variables (LUXRAY_AGENT_ID, LUXRAY_AGENT_TOKEN, LUXRAY_
8820
8876
  }
8821
8877
  const wsUrl = flags.ws || creds.wsUrl;
8822
8878
  const headless = flags.headed !== "true";
8823
- const artifactRoot = flags.out ? flags.out : join6(os3.homedir(), ".luxray", "runs");
8879
+ const artifactRoot = flags.out ? flags.out : join7(os3.homedir(), ".luxray", "runs");
8824
8880
  console.log(`
8825
8881
  Starting Luxray Agent:
8826
8882
  Agent ID: ${creds.agentId}
@@ -8981,7 +9037,7 @@ Register or import this agent first:
8981
9037
  const includeSubdomains = flags["include-subdomains"] === "true";
8982
9038
  const includeSecrets = flags["include-secrets"] === "true";
8983
9039
  const headless = flags.headed !== "true";
8984
- const artifactRoot = flags.out ? flags.out : join6(os3.homedir(), ".luxray", "runs");
9040
+ const artifactRoot = flags.out ? flags.out : join7(os3.homedir(), ".luxray", "runs");
8985
9041
  const apiUrl = (flags.api || flags.url || creds.apiUrl).replace(/\/$/, "");
8986
9042
  const wsUrl = flags.ws || creds.wsUrl;
8987
9043
  const streamConfig = streamConfigFromEnv(process.env, {