@uipath/rpa-tool 1.202.1 → 1.203.0

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
@@ -11300,6 +11300,16 @@ function getOutputFormat() {
11300
11300
  function getOutputFilter() {
11301
11301
  return filterSlot.get();
11302
11302
  }
11303
+ var OUTPUT_FORMATS = [
11304
+ "table",
11305
+ "json",
11306
+ "yaml",
11307
+ "plain",
11308
+ "markdown"
11309
+ ];
11310
+ function isOutputFormat(value) {
11311
+ return OUTPUT_FORMATS.includes(value);
11312
+ }
11303
11313
  var recordedFailureSlot = singleton("CommandTelemetryFailure");
11304
11314
  var AUTH_ERROR_CODES = new Set([
11305
11315
  "authentication_required",
@@ -12575,18 +12585,56 @@ function isSyncFlushForced() {
12575
12585
  function isDrainableTelemetryProvider(provider) {
12576
12586
  return "drainPendingEnvelopes" in provider && typeof provider.drainPendingEnvelopes === "function";
12577
12587
  }
12578
- function spawnTelemetrySidecar(entryPath) {
12579
- const child = spawn(process.execPath, [entryPath, TELEMETRY_DRAIN_ARGV], {
12580
- cwd: getFileSystem().env.tmpdir(),
12581
- detached: true,
12588
+ async function spawnTelemetrySidecar(entryPath) {
12589
+ const cwd = getFileSystem().env.tmpdir();
12590
+ const isWindows = process.platform === "win32";
12591
+ const child = isWindows ? spawn(windowsShell(), windowsLauncherArgs(entryPath), {
12592
+ cwd,
12582
12593
  stdio: "ignore",
12583
- windowsHide: true
12594
+ windowsHide: true,
12595
+ windowsVerbatimArguments: true
12596
+ }) : spawn(process.execPath, [entryPath, TELEMETRY_DRAIN_ARGV], {
12597
+ cwd,
12598
+ detached: true,
12599
+ stdio: "ignore"
12584
12600
  });
12585
12601
  child.on("error", (error) => {
12586
12602
  logger.debug(`[Telemetry] sidecar spawn failed (spool kept for a later run): ${error.message}`);
12587
12603
  });
12604
+ if (isWindows) {
12605
+ await waitForWindowsLauncher(child);
12606
+ }
12588
12607
  child.unref();
12589
12608
  }
12609
+ var WINDOWS_LAUNCHER_TIMEOUT_MS = 3000;
12610
+ function waitForWindowsLauncher(child) {
12611
+ return new Promise((resolve2) => {
12612
+ const timer = setTimeout(resolve2, WINDOWS_LAUNCHER_TIMEOUT_MS);
12613
+ timer.unref();
12614
+ const settle = () => {
12615
+ clearTimeout(timer);
12616
+ resolve2();
12617
+ };
12618
+ child.on("exit", settle);
12619
+ child.on("error", settle);
12620
+ });
12621
+ }
12622
+ function windowsShell() {
12623
+ return process.env.ComSpec ?? "cmd.exe";
12624
+ }
12625
+ function windowsLauncherArgs(entryPath) {
12626
+ return [
12627
+ "/d",
12628
+ "/s",
12629
+ "/c",
12630
+ "start",
12631
+ '""',
12632
+ "/b",
12633
+ `"${process.execPath}"`,
12634
+ `"${entryPath}"`,
12635
+ TELEMETRY_DRAIN_ARGV
12636
+ ];
12637
+ }
12590
12638
  async function trySidecarHandoff(provider) {
12591
12639
  const entryPath = getTelemetrySidecarEntry();
12592
12640
  if (entryPath === undefined || isSyncFlushForced() || !isDrainableTelemetryProvider(provider)) {
@@ -12601,7 +12649,7 @@ async function trySidecarHandoff(provider) {
12601
12649
  if (spoolError) {
12602
12650
  logger.debug(`[Telemetry] spool write failed; dropping ${pending.envelopes.length} pending envelope(s): ${spoolError.message}`);
12603
12651
  } else {
12604
- const [spawnError] = catchError(() => spawnTelemetrySidecar(entryPath));
12652
+ const [spawnError] = await catchError(spawnTelemetrySidecar(entryPath));
12605
12653
  if (spawnError) {
12606
12654
  logger.debug(`[Telemetry] sidecar spawn failed; spool will be sent by a future run: ${spawnError.message}`);
12607
12655
  }
@@ -12716,28 +12764,32 @@ function isPlainRecord(value) {
12716
12764
  const prototype = Object.getPrototypeOf(value);
12717
12765
  return prototype === Object.prototype || prototype === null;
12718
12766
  }
12719
- function extractPagedRows(value) {
12767
+ function splitPagedEnvelope(value) {
12720
12768
  if (Array.isArray(value) || !isPlainRecord(value))
12721
12769
  return null;
12722
- const entries = Object.values(value);
12770
+ const entries = Object.entries(value);
12723
12771
  if (entries.length === 0)
12724
12772
  return null;
12725
- let rows = null;
12726
- let hasScalarSibling = false;
12727
- for (const entry of entries) {
12773
+ let found = null;
12774
+ const meta = Object.create(null);
12775
+ for (const [key, entry] of entries) {
12728
12776
  if (Array.isArray(entry)) {
12729
- if (rows !== null)
12777
+ if (found !== null)
12730
12778
  return null;
12731
- rows = entry;
12779
+ found = { key, rows: entry };
12732
12780
  } else if (entry !== null && typeof entry === "object") {
12733
12781
  return null;
12734
12782
  } else {
12735
- hasScalarSibling = true;
12783
+ meta[key] = entry;
12736
12784
  }
12737
12785
  }
12738
- if (rows === null || !hasScalarSibling)
12786
+ if (found === null || Object.keys(meta).length === 0)
12739
12787
  return null;
12740
- return rows;
12788
+ return { ...found, meta };
12789
+ }
12790
+ function extractPagedRows(value) {
12791
+ const paged = splitPagedEnvelope(value);
12792
+ return paged === null ? null : paged.rows;
12741
12793
  }
12742
12794
  function toLowerCamelCaseKey(key) {
12743
12795
  if (!key)
@@ -12841,6 +12893,9 @@ function printOutput(data, format = "json", logFn, asciiSafe = false, tableRowSt
12841
12893
  }
12842
12894
  break;
12843
12895
  }
12896
+ case "markdown":
12897
+ logFn(renderMarkdown(data));
12898
+ break;
12844
12899
  default: {
12845
12900
  const hasData = "Data" in data && data.Data != null;
12846
12901
  const pagedRows = hasData ? extractPagedRows(data.Data) : null;
@@ -12865,6 +12920,10 @@ function logOutput(data, format = "json", tableRowStyle) {
12865
12920
  printOutput(data, format, (msg) => sink.writeOut(`${msg}
12866
12921
  `), needsAsciiSafeJson(sink), styleFn);
12867
12922
  }
12923
+ var PLUMBING_KEYS = new Set(["code", "log"]);
12924
+ function isPlumbingKey(key) {
12925
+ return PLUMBING_KEYS.has(key.toLowerCase());
12926
+ }
12868
12927
  function cellToString(val) {
12869
12928
  return val != null && typeof val === "object" ? JSON.stringify(val) : String(val ?? "");
12870
12929
  }
@@ -12880,7 +12939,7 @@ function wrapText(text, width) {
12880
12939
  function printTable(data, logFn, externalLogValue, tableRowStyle) {
12881
12940
  if (data.length === 0)
12882
12941
  return;
12883
- const keys = Object.keys(data[0]).filter((key) => !["code", "log"].includes(key.toLowerCase()));
12942
+ const keys = Object.keys(data[0]).filter((key) => !isPlumbingKey(key));
12884
12943
  const maxWidths = keys.map((key) => Math.max(key.length, ...data.map((item) => cellToString(item[key]).length)));
12885
12944
  const header = keys.map((key, i) => key.padEnd(maxWidths[i])).join(" | ");
12886
12945
  logFn(header);
@@ -12902,7 +12961,7 @@ function isNonEmptyPlainObject(value) {
12902
12961
  }
12903
12962
  var NESTED_INDENT = " ";
12904
12963
  function printVerticalTable(data, logFn = console.log, externalLogValue) {
12905
- const keys = Object.keys(data).filter((key) => !["code", "log"].includes(key.toLowerCase()));
12964
+ const keys = Object.keys(data).filter((key) => !isPlumbingKey(key));
12906
12965
  if (keys.length === 0)
12907
12966
  return;
12908
12967
  const isBlockValue = (value) => isPlainObjectArray(value) || isNonEmptyPlainObject(value);
@@ -12933,7 +12992,7 @@ function printVerticalTable(data, logFn = console.log, externalLogValue) {
12933
12992
  function printResizableTable(data, logFn = console.log, externalLogValue, availableWidth, tableRowStyle) {
12934
12993
  if (data.length === 0)
12935
12994
  return;
12936
- const keys = Object.keys(data[0]).filter((key) => !["code", "log"].includes(key.toLowerCase()));
12995
+ const keys = Object.keys(data[0]).filter((key) => !isPlumbingKey(key));
12937
12996
  if (keys.length === 0)
12938
12997
  return;
12939
12998
  if (!process.stdout.isTTY) {
@@ -13007,6 +13066,216 @@ function printResizableTable(data, logFn = console.log, externalLogValue, availa
13007
13066
  logFn(`Log: ${externalLogValue}`);
13008
13067
  }
13009
13068
  }
13069
+ var MARKDOWN_MAX_CELL = 200;
13070
+ var MARKDOWN_MAX_DEPTH = 3;
13071
+ function markdownHeading(depth) {
13072
+ return "#".repeat(Math.min(3 + depth, 6));
13073
+ }
13074
+ var BACKTICK_RUN = /`+/g;
13075
+ function fencedBlock(text) {
13076
+ const first = text.trimStart()[0];
13077
+ const language = first === "<" ? "xml" : first === "{" || first === "[" ? "json" : "";
13078
+ const longestRun = Math.max(0, ...Array.from(text.matchAll(BACKTICK_RUN), (match) => match[0].length));
13079
+ const fence = "`".repeat(Math.max(3, longestRun + 1));
13080
+ return `${fence}${language}
13081
+ ${text}
13082
+ ${fence}`;
13083
+ }
13084
+ function markdownCell(value) {
13085
+ const text = value instanceof Date ? value.toISOString() : cellToString(value);
13086
+ return text.replace(/\s*\n\s*/g, " ").replace(/\|/g, "\\|");
13087
+ }
13088
+ function markdownLabel(key) {
13089
+ return key.replace(/\s*\n\s*/g, " ").replace(/[\\`*|]/g, "\\$&");
13090
+ }
13091
+ function withoutPlumbing(record) {
13092
+ const kept = Object.create(null);
13093
+ for (const [key, value] of Object.entries(record)) {
13094
+ if (!isPlumbingKey(key))
13095
+ kept[key] = value;
13096
+ }
13097
+ return kept;
13098
+ }
13099
+ function rowsWithoutPlumbing(rows) {
13100
+ return rows.map((row) => isPlainRecord(row) ? withoutPlumbing(row) : row);
13101
+ }
13102
+ function markdownTable(rows) {
13103
+ const columns = [];
13104
+ const seen = new Set;
13105
+ for (const row of rows) {
13106
+ for (const key of Object.keys(row)) {
13107
+ if (!seen.has(key)) {
13108
+ seen.add(key);
13109
+ columns.push(key);
13110
+ }
13111
+ }
13112
+ }
13113
+ if (columns.length === 0)
13114
+ return null;
13115
+ const cells = rows.map((row) => columns.map((key) => markdownCell(row[key])));
13116
+ if (cells.some((row) => row.some((c) => c.length > MARKDOWN_MAX_CELL))) {
13117
+ return null;
13118
+ }
13119
+ return [
13120
+ `| ${columns.map(markdownLabel).join(" | ")} |`,
13121
+ `| ${columns.map(() => "---").join(" | ")} |`,
13122
+ ...cells.map((row) => `| ${row.join(" | ")} |`)
13123
+ ].join(`
13124
+ `);
13125
+ }
13126
+ function extractMessageSequence(rows) {
13127
+ const messages = [];
13128
+ for (const row of rows) {
13129
+ const message = extractSingleMessage(row);
13130
+ if (message === null)
13131
+ return null;
13132
+ messages.push(message);
13133
+ }
13134
+ return messages.join(`
13135
+
13136
+ `);
13137
+ }
13138
+ function markdownRows(rows, depth) {
13139
+ if (rows.length === 0)
13140
+ return "(none)";
13141
+ if (!isPlainObjectArray(rows)) {
13142
+ return rows.map((item) => `- ${markdownCell(item)}`).join(`
13143
+ `);
13144
+ }
13145
+ const prose = extractMessageSequence(rows);
13146
+ if (prose !== null)
13147
+ return prose;
13148
+ const table = markdownTable(rows);
13149
+ if (table !== null)
13150
+ return table;
13151
+ if (depth >= MARKDOWN_MAX_DEPTH) {
13152
+ return fencedBlock(JSON.stringify(rows, null, 2));
13153
+ }
13154
+ return rows.map((row, index) => [
13155
+ `${markdownHeading(depth)} ${index + 1}`,
13156
+ markdownObject(row, depth + 1)
13157
+ ].join(`
13158
+
13159
+ `)).join(`
13160
+
13161
+ `);
13162
+ }
13163
+ function markdownObject(obj, depth) {
13164
+ const scalars = [];
13165
+ const blocks = [];
13166
+ for (const [key, value] of Object.entries(obj)) {
13167
+ if (value === undefined)
13168
+ continue;
13169
+ const label = markdownLabel(key);
13170
+ if (Array.isArray(value)) {
13171
+ blocks.push(`${markdownHeading(depth)} ${label}
13172
+
13173
+ ${markdownRows(value, depth + 1)}`);
13174
+ } else if (isNonEmptyPlainObject(value)) {
13175
+ const nested = depth < MARKDOWN_MAX_DEPTH ? markdownObject(value, depth + 1) : fencedBlock(JSON.stringify(value, null, 2));
13176
+ if (nested !== "") {
13177
+ blocks.push(`${markdownHeading(depth)} ${label}
13178
+
13179
+ ${nested}`);
13180
+ }
13181
+ } else if (typeof value === "string" && value.includes(`
13182
+ `)) {
13183
+ blocks.push(`**${label}:**
13184
+
13185
+ ${fencedBlock(value)}`);
13186
+ } else {
13187
+ scalars.push(`**${label}:** ${markdownCell(value)}`);
13188
+ }
13189
+ }
13190
+ const sections = scalars.length > 0 ? [scalars.join(`
13191
+ `)] : [];
13192
+ sections.push(...blocks);
13193
+ return sections.join(`
13194
+
13195
+ `);
13196
+ }
13197
+ function extractSingleMessage(payload) {
13198
+ if (!isPlainRecord(payload))
13199
+ return null;
13200
+ const keys = Object.keys(payload);
13201
+ if (keys.length !== 1 || keys[0].toLowerCase() !== "message")
13202
+ return null;
13203
+ const value = payload[keys[0]];
13204
+ return typeof value === "string" ? value : null;
13205
+ }
13206
+ function markdownPayload(payload) {
13207
+ const message = extractSingleMessage(payload);
13208
+ if (message !== null)
13209
+ return message;
13210
+ if (Array.isArray(payload)) {
13211
+ return markdownRows(rowsWithoutPlumbing(payload), 0);
13212
+ }
13213
+ const visible = withoutPlumbing(payload);
13214
+ const paged = splitPagedEnvelope(visible);
13215
+ if (paged !== null) {
13216
+ const meta = markdownObject(paged.meta, 0);
13217
+ const rows = `${markdownHeading(0)} ${markdownLabel(paged.key)}
13218
+
13219
+ ${markdownRows(rowsWithoutPlumbing(paged.rows), 1)}`;
13220
+ return meta === "" ? rows : `${meta}
13221
+
13222
+ ${rows}`;
13223
+ }
13224
+ return markdownObject(visible, 0);
13225
+ }
13226
+ function isPaginationWorthShowing(value) {
13227
+ if (typeof value !== "object" || value === null)
13228
+ return false;
13229
+ const page = value;
13230
+ return page.HasMore === true || typeof page.Offset === "number" && page.Offset > 0;
13231
+ }
13232
+ function markdownEnvelopeNotes(data) {
13233
+ const envelope = data;
13234
+ const notes = [];
13235
+ const warning = envelope.Warning;
13236
+ if (typeof warning === "string" && warning !== "") {
13237
+ notes.push(`> **Warning:** ${warning}`);
13238
+ }
13239
+ const instructions = envelope.Instructions;
13240
+ if (typeof instructions === "string" && instructions !== "") {
13241
+ notes.push(`> ${instructions}`);
13242
+ }
13243
+ const pagination = envelope.Pagination;
13244
+ if (isPaginationWorthShowing(pagination)) {
13245
+ const body = markdownObject(pagination, 1);
13246
+ if (body !== "") {
13247
+ notes.push(`${markdownHeading(0)} Pagination
13248
+
13249
+ ${body}`);
13250
+ }
13251
+ }
13252
+ const log = envelope.Log;
13253
+ if (typeof log === "string" && log !== "") {
13254
+ notes.push(`**Log:** ${log}`);
13255
+ }
13256
+ return notes;
13257
+ }
13258
+ function renderMarkdown(data) {
13259
+ if (data.Result !== RESULTS.Success) {
13260
+ const failure = data;
13261
+ const sections = [`**Failed:** ${failure.Message}`];
13262
+ if (failure.Data != null) {
13263
+ sections.push(markdownPayload(failure.Data));
13264
+ }
13265
+ if (failure.Instructions) {
13266
+ sections.push(`> ${failure.Instructions}`);
13267
+ }
13268
+ return sections.filter((section) => section !== "").join(`
13269
+
13270
+ `);
13271
+ }
13272
+ if (!("Data" in data) || data.Data == null) {
13273
+ return markdownObject(withoutPlumbing(data), 0);
13274
+ }
13275
+ return [markdownPayload(data.Data), ...markdownEnvelopeNotes(data)].filter((section) => section !== "").join(`
13276
+
13277
+ `);
13278
+ }
13010
13279
  function toYaml(data) {
13011
13280
  const codec = getYamlCodec();
13012
13281
  if (!codec) {
@@ -13980,6 +14249,14 @@ ${descIndent}${indentedDesc}`;
13980
14249
  });
13981
14250
  }
13982
14251
 
14252
+ // src/cli/wrapper-options.ts
14253
+ var FORMAT_OPTION_DESCRIPTION = `Output format (${OUTPUT_FORMATS.join(", ")})`;
14254
+ function createFormatOption() {
14255
+ return new Option("--format <format>", FORMAT_OPTION_DESCRIPTION).choices([
14256
+ ...OUTPUT_FORMATS
14257
+ ]);
14258
+ }
14259
+
13983
14260
  // src/index.ts
13984
14261
  import { metadata, registerCommands } from "./tool.js";
13985
14262
  if (process.platform !== "win32") {
@@ -13997,12 +14274,12 @@ var format = extractArg(process.argv, "format");
13997
14274
  if (hasFlag(process.argv, "use-studio") && hostStudioPid) {
13998
14275
  console.error("[rpa-tool] --use-studio is deprecated and has no effect. " + "Studio routing is automatic when UIPATH_STUDIO_PID is set.");
13999
14276
  }
14000
- if (format) {
14277
+ if (format && isOutputFormat(format)) {
14001
14278
  setOutputFormat(format);
14002
14279
  }
14003
14280
  var program3 = new Command;
14004
14281
  configureHelpFormat(program3);
14005
- program3.name(metadata.name).version(metadata.version).description(metadata.description).option("--project-dir <path>", "Project directory to match against running Studio instances", process.cwd()).option("--studio-dir <path>", "Path to Studio installation directory (for starting a new instance)").option("--robot-dir <path>", "Path to Robot installation directory (bypasses registry/bundle discovery)").option("--timeout <seconds>", "Timeout in seconds", "300").option("--verbose", "Enable verbose logging (debug level)").option("--format <format>", "Output format (table, json, yaml, plain)");
14282
+ program3.name(metadata.name).version(metadata.version).description(metadata.description).option("--project-dir <path>", "Project directory to match against running Studio instances", process.cwd()).option("--studio-dir <path>", "Path to Studio installation directory (for starting a new instance)").option("--robot-dir <path>", "Path to Robot installation directory (bypasses registry/bundle discovery)").option("--timeout <seconds>", "Timeout in seconds", "300").option("--verbose", "Enable verbose logging (debug level)").addOption(createFormatOption());
14006
14283
  if (verbose) {
14007
14284
  console.error(`rpa-tool v${metadata.version}`);
14008
14285
  }