@uipath/apms-tool 1.202.1-preview.220 → 1.202.1-preview.239

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
@@ -3,7 +3,7 @@ import {
3
3
  Command,
4
4
  metadata,
5
5
  registerCommands
6
- } from "./tool-6fsxmqrs.js";
6
+ } from "./tool-t7mr9yxe.js";
7
7
  import"./tool-1de529jm.js";
8
8
 
9
9
  // src/index.ts
@@ -2100,7 +2100,7 @@ var require_commander = __commonJS(function(exports) {
2100
2100
  var package_default = {
2101
2101
  name: "@uipath/apms-tool",
2102
2102
  license: "SEE LICENSE IN LICENSE.txt",
2103
- version: "1.202.1-preview.220",
2103
+ version: "1.202.1-preview.239",
2104
2104
  description: "CLI plugin for the UiPath Access Policy Management Service.",
2105
2105
  private: false,
2106
2106
  repository: {
@@ -7505,7 +7505,165 @@ class FilterImplicitLimitError extends Error {
7505
7505
  this.instructions = "Pass --limit <n> to choose how many records the filter applies to. " + "To filter over all records, pass the command's maximum accepted --limit (see the option's description in --help).";
7506
7506
  }
7507
7507
  }
7508
- function applyFilter(data, filter) {
7508
+ function countRecords(data) {
7509
+ if (Array.isArray(data))
7510
+ return data.length;
7511
+ return data == null ? 0 : 1;
7512
+ }
7513
+ function availableFields(data) {
7514
+ const records = Array.isArray(data) ? data : [data];
7515
+ const keys = new Set;
7516
+ for (const record of records) {
7517
+ if (record && typeof record === "object" && !Array.isArray(record)) {
7518
+ for (const key of Object.keys(record))
7519
+ keys.add(key);
7520
+ }
7521
+ }
7522
+ return [...keys];
7523
+ }
7524
+ function decodeQuotedIdentifier(whole, inner) {
7525
+ const [error, decoded] = catchError2(() => JSON.parse(whole));
7526
+ if (!error && typeof decoded === "string")
7527
+ return decoded;
7528
+ return inner.replace(/\\(.)/g, "$1");
7529
+ }
7530
+ function referencedFields(filter) {
7531
+ const top = new Set;
7532
+ const nested = new Set;
7533
+ const withoutValueLiterals = filter.replace(/'(?:\\.|[^'\\])*'/g, " ").replace(/`(?:\\.|[^`\\])*`/g, " ");
7534
+ const isPathTail = (text, index) => text[index - 1] === "." && /[A-Za-z0-9_"]/.test(text[index - 2] ?? "");
7535
+ const quoted = [];
7536
+ const withoutLiterals = withoutValueLiterals.replace(/"((?:\\.|[^"\\])*)"/g, (whole, name, index) => {
7537
+ const isAlias = /^\s*:/.test(withoutValueLiterals.slice(index + whole.length));
7538
+ if (!isAlias) {
7539
+ quoted.push({
7540
+ name: decodeQuotedIdentifier(whole, name),
7541
+ index,
7542
+ tail: isPathTail(withoutValueLiterals, index)
7543
+ });
7544
+ }
7545
+ return `"${" ".repeat(whole.length - 2)}"`;
7546
+ });
7547
+ const descent = /[A-Za-z0-9_"]\s*[.[]/.exec(withoutLiterals);
7548
+ const rootEnd = descent ? descent.index + 1 : Number.POSITIVE_INFINITY;
7549
+ const place = (name, index, tail) => {
7550
+ if (tail || index >= rootEnd)
7551
+ nested.add(name);
7552
+ else
7553
+ top.add(name);
7554
+ };
7555
+ for (const entry of quoted)
7556
+ place(entry.name, entry.index, entry.tail);
7557
+ const identifiers = withoutLiterals.matchAll(/([A-Za-z_][A-Za-z0-9_]*)(\s*[:(])?/g);
7558
+ const reserved = new Set(["true", "false", "null", "and", "or", "not"]);
7559
+ for (const match of identifiers) {
7560
+ const [, name, trailing] = match;
7561
+ if (trailing || reserved.has(name))
7562
+ continue;
7563
+ place(name, match.index, isPathTail(withoutLiterals, match.index));
7564
+ }
7565
+ return {
7566
+ top: [...top],
7567
+ nested: [...nested].filter((name) => !top.has(name)),
7568
+ hasPredicate: /\[\s*\?/.test(withoutValueLiterals)
7569
+ };
7570
+ }
7571
+ function appearsBelowTopLevel(data, name) {
7572
+ let budget = 2000;
7573
+ const visit = (value, depth) => {
7574
+ if (budget-- <= 0 || depth > 4)
7575
+ return false;
7576
+ if (value === null || typeof value !== "object")
7577
+ return false;
7578
+ if (Array.isArray(value))
7579
+ return value.some((entry) => visit(entry, depth));
7580
+ const record = value;
7581
+ if (depth > 0 && Object.hasOwn(record, name))
7582
+ return true;
7583
+ return Object.values(record).some((entry) => visit(entry, depth + 1));
7584
+ };
7585
+ return visit(data, 0);
7586
+ }
7587
+ function alwaysNullKeys(records) {
7588
+ const objects = records.filter((r) => r != null && typeof r === "object" && !Array.isArray(r));
7589
+ if (objects.length === 0 || objects.length !== records.length)
7590
+ return [];
7591
+ const keys = [...new Set(objects.flatMap((o) => Object.keys(o)))];
7592
+ if (keys.length === 0)
7593
+ return [];
7594
+ const nullKeys = keys.filter((key) => objects.every((record) => record[key] === null));
7595
+ return nullKeys.length === keys.length ? nullKeys : [];
7596
+ }
7597
+ function carriesOnlyNulls(value) {
7598
+ if (value === null)
7599
+ return true;
7600
+ if (Array.isArray(value)) {
7601
+ return value.length > 0 && value.every(carriesOnlyNulls);
7602
+ }
7603
+ if (typeof value === "object" && value !== undefined) {
7604
+ const values = Object.values(value);
7605
+ return values.length > 0 && values.every(carriesOnlyNulls);
7606
+ }
7607
+ return false;
7608
+ }
7609
+ function nameList(names, cap2 = 12) {
7610
+ const shown = names.slice(0, cap2).map((n) => `\`${n}\``);
7611
+ const rest = names.length - shown.length;
7612
+ return shown.join(", ") + (rest > 0 ? `, and ${rest} more` : "");
7613
+ }
7614
+ function buildFilterWarning(filter, data, outcome) {
7615
+ const present = availableFields(data);
7616
+ const refs = referencedFields(filter);
7617
+ const unknown = refs.top.filter((name) => !present.includes(name) && !appearsBelowTopLevel(data, name));
7618
+ const unchecked = refs.nested.filter((name) => !present.includes(name));
7619
+ const count = countRecords(data);
7620
+ const scope = `${count} record(s)`;
7621
+ const isNotAField = (names) => `${nameList(names)} ${names.length === 1 ? "is not a field" : "are not fields"} on the ${scope} it read`;
7622
+ const soundness = unchecked.length > 0 ? `${nameList(unchecked)} ${unchecked.length === 1 ? "reads" : "read"} below the top level, so ${unchecked.length === 1 ? "it was" : "they were"} not checked against the record keys` : refs.top.length > 0 ? "every field it names exists" : "";
7623
+ const withSoundness = (base) => soundness ? `${base}, and ${soundness}` : base;
7624
+ let detail;
7625
+ let lede;
7626
+ if (outcome.kind === "null-elements") {
7627
+ lede = "returned only null values";
7628
+ const projected = `all ${outcome.count} of the elements it projected are null`;
7629
+ if (unknown.length > 0) {
7630
+ detail = `${projected}, because ${isNotAField(unknown)}`;
7631
+ } else if (unchecked.length > 0) {
7632
+ detail = withSoundness(projected);
7633
+ } else {
7634
+ detail = `${projected}, and every field it names exists — a multi-select list ` + `(\`[A, B]\`) reads each entry against \`Data\` itself, so on a list ` + `result use \`[].[A, B]\` or \`[].{a: A, b: B}\` to read the records`;
7635
+ }
7636
+ } else if (outcome.kind === "null-rows") {
7637
+ lede = "returned only null values";
7638
+ const projected = `every value it projected is null on all ${outcome.count} row(s)`;
7639
+ detail = unknown.length > 0 ? `${projected}, because ${isNotAField(unknown)}` : withSoundness(projected);
7640
+ } else if (outcome.kind === "null-values") {
7641
+ lede = "returned only null values";
7642
+ const projected = `every key it projected (${nameList(outcome.keys)}) is null`;
7643
+ const sameSet = unknown.length === outcome.keys.length && outcome.keys.every((k) => unknown.includes(k));
7644
+ if (sameSet) {
7645
+ detail = `${isNotAField(outcome.keys)}, so every key it projected is null`;
7646
+ } else if (unknown.length > 0) {
7647
+ detail = `${projected}, because ${isNotAField(unknown)}`;
7648
+ } else {
7649
+ detail = withSoundness(`${projected} on all ${scope}`);
7650
+ }
7651
+ } else {
7652
+ lede = "returned nothing";
7653
+ if (unknown.length > 0) {
7654
+ detail = isNotAField(unknown);
7655
+ } else {
7656
+ const selection = refs.hasPredicate ? "no record matched" : "the expression resolved to no value";
7657
+ detail = withSoundness(`${selection} — it read ${scope}`);
7658
+ }
7659
+ }
7660
+ const fields = present.length > 0 ? ` Available fields: ${nameList(present)}.` : "";
7661
+ return `--output-filter ${JSON.stringify(filter)} ${lede}: ${detail}.${fields}`;
7662
+ }
7663
+ function appendWarning(existing, note) {
7664
+ return existing ? `${existing} ${note}` : note;
7665
+ }
7666
+ function applyFilter(data, filter, onWarning) {
7509
7667
  const codec = requireJmespath();
7510
7668
  let result;
7511
7669
  try {
@@ -7513,9 +7671,34 @@ function applyFilter(data, filter) {
7513
7671
  } catch (err) {
7514
7672
  throw new FilterEvaluationError(filter, err);
7515
7673
  }
7516
- if (result == null)
7674
+ const inputCount = countRecords(data);
7675
+ const warn = (outcome) => {
7676
+ if (inputCount === 0)
7677
+ return;
7678
+ const note = buildFilterWarning(filter, data, outcome);
7679
+ getOutputSink().writeErr(`[WARN] ${note}
7680
+ `);
7681
+ onWarning?.(note);
7682
+ };
7683
+ const warnIfAllNull = (records) => {
7684
+ const keys = alwaysNullKeys(records);
7685
+ if (keys.length > 0)
7686
+ warn({ kind: "null-values", keys });
7687
+ };
7688
+ if (result == null) {
7689
+ warn({ kind: "empty" });
7517
7690
  return [];
7691
+ }
7518
7692
  if (Array.isArray(result)) {
7693
+ if (result.length === 0) {
7694
+ warn({ kind: "empty" });
7695
+ } else if (result.every((entry) => entry === null)) {
7696
+ warn({ kind: "null-elements", count: result.length });
7697
+ } else if (result.every((entry) => Array.isArray(entry)) && carriesOnlyNulls(result)) {
7698
+ warn({ kind: "null-rows", count: result.length });
7699
+ } else {
7700
+ warnIfAllNull(result);
7701
+ }
7519
7702
  if (result.length > 0 && typeof result[0] !== "object") {
7520
7703
  const fieldMatch = filter.match(/\.(\w+)$/);
7521
7704
  const key = fieldMatch ? fieldMatch[1] : "Value";
@@ -7523,10 +7706,30 @@ function applyFilter(data, filter) {
7523
7706
  }
7524
7707
  return result;
7525
7708
  }
7526
- if (typeof result === "object")
7709
+ if (typeof result === "object") {
7710
+ warnIfAllNull([result]);
7527
7711
  return result;
7712
+ }
7528
7713
  return { Value: result };
7529
7714
  }
7715
+ function filterFailureData(envelope) {
7716
+ const filter = getOutputFilter();
7717
+ const data = envelope.Data;
7718
+ if (!filter || data == null)
7719
+ return;
7720
+ let note;
7721
+ const [filterError, filtered] = catchError2(() => applyFilter(data, filter, (n) => {
7722
+ note = n;
7723
+ }));
7724
+ if (filterError) {
7725
+ envelope.Warning = appendWarning(envelope.Warning, `--output-filter was not applied, so Data is shown in full: ${filterError.message}`);
7726
+ return;
7727
+ }
7728
+ envelope.Data = filtered;
7729
+ if (note) {
7730
+ envelope.Warning = appendWarning(envelope.Warning, note);
7731
+ }
7732
+ }
7530
7733
  function defaultErrorCodeForResult(result) {
7531
7734
  switch (result) {
7532
7735
  case RESULTS.AuthenticationError:
@@ -7609,8 +7812,14 @@ var OutputFormatter;
7609
7812
  }
7610
7813
  const filter = getOutputFilter();
7611
7814
  if (filter) {
7612
- const filtered = applyFilter(data.Data, filter);
7815
+ let note;
7816
+ const filtered = applyFilter(data.Data, filter, (n) => {
7817
+ note = n;
7818
+ });
7613
7819
  data.Data = normalize ? normalizeDataKeys(filtered, verbatim, subtrees && { refs: subtrees.refs, mode: "skip" }) : filtered;
7820
+ if (note) {
7821
+ data.Warning = appendWarning(data.Warning, note);
7822
+ }
7614
7823
  }
7615
7824
  logOutput(normalizeOutputKeys(data), getOutputFormat(), options?.tableRowStyle);
7616
7825
  }
@@ -7638,6 +7847,7 @@ var OutputFormatter;
7638
7847
  delete envelope.TelemetryErrorClass;
7639
7848
  delete envelope.TelemetryTerminalOutcome;
7640
7849
  delete envelope.TelemetryTerminalSignal;
7850
+ filterFailureData(envelope);
7641
7851
  if (!suppressTelemetry) {
7642
7852
  telemetry.trackEvent(CommonTelemetryEvents.Error, {
7643
7853
  result: data.Result,
@@ -7686,13 +7896,20 @@ var OutputFormatter;
7686
7896
  OutputFormatter.log = log;
7687
7897
  function formatToString(data) {
7688
7898
  const filter = getOutputFilter();
7899
+ const envelope = data;
7689
7900
  if ("Data" in data && data.Data != null) {
7690
7901
  data.Data = normalizeDataKeys(data.Data);
7691
7902
  if (filter) {
7692
- data.Data = normalizeDataKeys(applyFilter(data.Data, filter));
7903
+ let note;
7904
+ data.Data = normalizeDataKeys(applyFilter(data.Data, filter, (n) => {
7905
+ note = n;
7906
+ }));
7907
+ if (note) {
7908
+ envelope.Warning = appendWarning(envelope.Warning, note);
7909
+ }
7693
7910
  }
7694
7911
  }
7695
- const output = normalizeOutputKeys(data);
7912
+ const output = normalizeOutputKeys(envelope);
7696
7913
  const lines = [];
7697
7914
  const sink = getOutputSink();
7698
7915
  printOutput(output, getOutputFormat(), (msg) => {
@@ -9546,4 +9763,4 @@ var registerCommands = async (program2) => {
9546
9763
 
9547
9764
  export { Command, metadata, registerCommands };
9548
9765
 
9549
- //# debugId=6EEE592684BAF4B864756E2164756E21
9766
+ //# debugId=CE7C95975FA72C1664756E2164756E21
package/dist/tool.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  metadata,
3
3
  registerCommands
4
- } from "./tool-6fsxmqrs.js";
4
+ } from "./tool-t7mr9yxe.js";
5
5
  import"./tool-1de529jm.js";
6
6
  export {
7
7
  metadata,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@uipath/apms-tool",
3
3
  "license": "SEE LICENSE IN LICENSE.txt",
4
- "version": "1.202.1-preview.220",
4
+ "version": "1.202.1-preview.239",
5
5
  "description": "CLI plugin for the UiPath Access Policy Management Service.",
6
6
  "private": false,
7
7
  "repository": {
@@ -26,5 +26,5 @@
26
26
  "files": [
27
27
  "dist"
28
28
  ],
29
- "gitHead": "a09041733b628c3f6b658a1f58349ea0f40bb492"
29
+ "gitHead": "97545a7857bdff7e6db62bbe13c6097607cf38f1"
30
30
  }