@uipath/apms-tool 1.203.0-preview.235 → 1.203.0-preview.240

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-brtwkwnp.js";
6
+ } from "./tool-8qkqz0s2.js";
7
7
  import"./tool-1de529jm.js";
8
8
 
9
9
  // src/index.ts
@@ -2101,7 +2101,7 @@ var package_default = {
2101
2101
  name: "@uipath/apms-tool",
2102
2102
  author: "UiPath",
2103
2103
  license: "SEE LICENSE IN LICENSE.txt",
2104
- version: "1.203.0-preview.235",
2104
+ version: "1.203.0-preview.240",
2105
2105
  description: "CLI plugin for the UiPath Access Policy Management Service.",
2106
2106
  private: false,
2107
2107
  repository: {
@@ -7756,7 +7756,165 @@ class FilterImplicitLimitError extends Error {
7756
7756
  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).";
7757
7757
  }
7758
7758
  }
7759
- function applyFilter(data, filter) {
7759
+ function countRecords(data) {
7760
+ if (Array.isArray(data))
7761
+ return data.length;
7762
+ return data == null ? 0 : 1;
7763
+ }
7764
+ function availableFields(data) {
7765
+ const records = Array.isArray(data) ? data : [data];
7766
+ const keys = new Set;
7767
+ for (const record of records) {
7768
+ if (record && typeof record === "object" && !Array.isArray(record)) {
7769
+ for (const key of Object.keys(record))
7770
+ keys.add(key);
7771
+ }
7772
+ }
7773
+ return [...keys];
7774
+ }
7775
+ function decodeQuotedIdentifier(whole, inner) {
7776
+ const [error, decoded] = catchError2(() => JSON.parse(whole));
7777
+ if (!error && typeof decoded === "string")
7778
+ return decoded;
7779
+ return inner.replace(/\\(.)/g, "$1");
7780
+ }
7781
+ function referencedFields(filter) {
7782
+ const top = new Set;
7783
+ const nested = new Set;
7784
+ const withoutValueLiterals = filter.replace(/'(?:\\.|[^'\\])*'/g, " ").replace(/`(?:\\.|[^`\\])*`/g, " ");
7785
+ const isPathTail = (text, index) => text[index - 1] === "." && /[A-Za-z0-9_"]/.test(text[index - 2] ?? "");
7786
+ const quoted = [];
7787
+ const withoutLiterals = withoutValueLiterals.replace(/"((?:\\.|[^"\\])*)"/g, (whole, name, index) => {
7788
+ const isAlias = /^\s*:/.test(withoutValueLiterals.slice(index + whole.length));
7789
+ if (!isAlias) {
7790
+ quoted.push({
7791
+ name: decodeQuotedIdentifier(whole, name),
7792
+ index,
7793
+ tail: isPathTail(withoutValueLiterals, index)
7794
+ });
7795
+ }
7796
+ return `"${" ".repeat(whole.length - 2)}"`;
7797
+ });
7798
+ const descent = /[A-Za-z0-9_"]\s*[.[]/.exec(withoutLiterals);
7799
+ const rootEnd = descent ? descent.index + 1 : Number.POSITIVE_INFINITY;
7800
+ const place = (name, index, tail) => {
7801
+ if (tail || index >= rootEnd)
7802
+ nested.add(name);
7803
+ else
7804
+ top.add(name);
7805
+ };
7806
+ for (const entry of quoted)
7807
+ place(entry.name, entry.index, entry.tail);
7808
+ const identifiers = withoutLiterals.matchAll(/([A-Za-z_][A-Za-z0-9_]*)(\s*[:(])?/g);
7809
+ const reserved = new Set(["true", "false", "null", "and", "or", "not"]);
7810
+ for (const match of identifiers) {
7811
+ const [, name, trailing] = match;
7812
+ if (trailing || reserved.has(name))
7813
+ continue;
7814
+ place(name, match.index, isPathTail(withoutLiterals, match.index));
7815
+ }
7816
+ return {
7817
+ top: [...top],
7818
+ nested: [...nested].filter((name) => !top.has(name)),
7819
+ hasPredicate: /\[\s*\?/.test(withoutValueLiterals)
7820
+ };
7821
+ }
7822
+ function appearsBelowTopLevel(data, name) {
7823
+ let budget = 2000;
7824
+ const visit = (value, depth) => {
7825
+ if (budget-- <= 0 || depth > 4)
7826
+ return false;
7827
+ if (value === null || typeof value !== "object")
7828
+ return false;
7829
+ if (Array.isArray(value))
7830
+ return value.some((entry) => visit(entry, depth));
7831
+ const record = value;
7832
+ if (depth > 0 && Object.hasOwn(record, name))
7833
+ return true;
7834
+ return Object.values(record).some((entry) => visit(entry, depth + 1));
7835
+ };
7836
+ return visit(data, 0);
7837
+ }
7838
+ function alwaysNullKeys(records) {
7839
+ const objects = records.filter((r) => r != null && typeof r === "object" && !Array.isArray(r));
7840
+ if (objects.length === 0 || objects.length !== records.length)
7841
+ return [];
7842
+ const keys = [...new Set(objects.flatMap((o) => Object.keys(o)))];
7843
+ if (keys.length === 0)
7844
+ return [];
7845
+ const nullKeys = keys.filter((key) => objects.every((record) => record[key] === null));
7846
+ return nullKeys.length === keys.length ? nullKeys : [];
7847
+ }
7848
+ function carriesOnlyNulls(value) {
7849
+ if (value === null)
7850
+ return true;
7851
+ if (Array.isArray(value)) {
7852
+ return value.length > 0 && value.every(carriesOnlyNulls);
7853
+ }
7854
+ if (typeof value === "object" && value !== undefined) {
7855
+ const values = Object.values(value);
7856
+ return values.length > 0 && values.every(carriesOnlyNulls);
7857
+ }
7858
+ return false;
7859
+ }
7860
+ function nameList(names, cap2 = 12) {
7861
+ const shown = names.slice(0, cap2).map((n) => `\`${n}\``);
7862
+ const rest = names.length - shown.length;
7863
+ return shown.join(", ") + (rest > 0 ? `, and ${rest} more` : "");
7864
+ }
7865
+ function buildFilterWarning(filter, data, outcome) {
7866
+ const present = availableFields(data);
7867
+ const refs = referencedFields(filter);
7868
+ const unknown = refs.top.filter((name) => !present.includes(name) && !appearsBelowTopLevel(data, name));
7869
+ const unchecked = refs.nested.filter((name) => !present.includes(name));
7870
+ const count = countRecords(data);
7871
+ const scope = `${count} record(s)`;
7872
+ const isNotAField = (names) => `${nameList(names)} ${names.length === 1 ? "is not a field" : "are not fields"} on the ${scope} it read`;
7873
+ 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" : "";
7874
+ const withSoundness = (base) => soundness ? `${base}, and ${soundness}` : base;
7875
+ let detail;
7876
+ let lede;
7877
+ if (outcome.kind === "null-elements") {
7878
+ lede = "returned only null values";
7879
+ const projected = `all ${outcome.count} of the elements it projected are null`;
7880
+ if (unknown.length > 0) {
7881
+ detail = `${projected}, because ${isNotAField(unknown)}`;
7882
+ } else if (unchecked.length > 0) {
7883
+ detail = withSoundness(projected);
7884
+ } else {
7885
+ 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`;
7886
+ }
7887
+ } else if (outcome.kind === "null-rows") {
7888
+ lede = "returned only null values";
7889
+ const projected = `every value it projected is null on all ${outcome.count} row(s)`;
7890
+ detail = unknown.length > 0 ? `${projected}, because ${isNotAField(unknown)}` : withSoundness(projected);
7891
+ } else if (outcome.kind === "null-values") {
7892
+ lede = "returned only null values";
7893
+ const projected = `every key it projected (${nameList(outcome.keys)}) is null`;
7894
+ const sameSet = unknown.length === outcome.keys.length && outcome.keys.every((k) => unknown.includes(k));
7895
+ if (sameSet) {
7896
+ detail = `${isNotAField(outcome.keys)}, so every key it projected is null`;
7897
+ } else if (unknown.length > 0) {
7898
+ detail = `${projected}, because ${isNotAField(unknown)}`;
7899
+ } else {
7900
+ detail = withSoundness(`${projected} on all ${scope}`);
7901
+ }
7902
+ } else {
7903
+ lede = "returned nothing";
7904
+ if (unknown.length > 0) {
7905
+ detail = isNotAField(unknown);
7906
+ } else {
7907
+ const selection = refs.hasPredicate ? "no record matched" : "the expression resolved to no value";
7908
+ detail = withSoundness(`${selection} — it read ${scope}`);
7909
+ }
7910
+ }
7911
+ const fields = present.length > 0 ? ` Available fields: ${nameList(present)}.` : "";
7912
+ return `--output-filter ${JSON.stringify(filter)} ${lede}: ${detail}.${fields}`;
7913
+ }
7914
+ function appendWarning(existing, note) {
7915
+ return existing ? `${existing} ${note}` : note;
7916
+ }
7917
+ function applyFilter(data, filter, onWarning) {
7760
7918
  const codec = requireJmespath();
7761
7919
  let result;
7762
7920
  try {
@@ -7764,9 +7922,34 @@ function applyFilter(data, filter) {
7764
7922
  } catch (err) {
7765
7923
  throw new FilterEvaluationError(filter, err);
7766
7924
  }
7767
- if (result == null)
7925
+ const inputCount = countRecords(data);
7926
+ const warn = (outcome) => {
7927
+ if (inputCount === 0)
7928
+ return;
7929
+ const note = buildFilterWarning(filter, data, outcome);
7930
+ getOutputSink().writeErr(`[WARN] ${note}
7931
+ `);
7932
+ onWarning?.(note);
7933
+ };
7934
+ const warnIfAllNull = (records) => {
7935
+ const keys = alwaysNullKeys(records);
7936
+ if (keys.length > 0)
7937
+ warn({ kind: "null-values", keys });
7938
+ };
7939
+ if (result == null) {
7940
+ warn({ kind: "empty" });
7768
7941
  return [];
7942
+ }
7769
7943
  if (Array.isArray(result)) {
7944
+ if (result.length === 0) {
7945
+ warn({ kind: "empty" });
7946
+ } else if (result.every((entry) => entry === null)) {
7947
+ warn({ kind: "null-elements", count: result.length });
7948
+ } else if (result.every((entry) => Array.isArray(entry)) && carriesOnlyNulls(result)) {
7949
+ warn({ kind: "null-rows", count: result.length });
7950
+ } else {
7951
+ warnIfAllNull(result);
7952
+ }
7770
7953
  if (result.length > 0 && typeof result[0] !== "object") {
7771
7954
  const fieldMatch = filter.match(/\.(\w+)$/);
7772
7955
  const key = fieldMatch ? fieldMatch[1] : "Value";
@@ -7774,10 +7957,30 @@ function applyFilter(data, filter) {
7774
7957
  }
7775
7958
  return result;
7776
7959
  }
7777
- if (typeof result === "object")
7960
+ if (typeof result === "object") {
7961
+ warnIfAllNull([result]);
7778
7962
  return result;
7963
+ }
7779
7964
  return { Value: result };
7780
7965
  }
7966
+ function filterFailureData(envelope) {
7967
+ const filter = getOutputFilter();
7968
+ const data = envelope.Data;
7969
+ if (!filter || data == null)
7970
+ return;
7971
+ let note;
7972
+ const [filterError, filtered] = catchError2(() => applyFilter(data, filter, (n) => {
7973
+ note = n;
7974
+ }));
7975
+ if (filterError) {
7976
+ envelope.Warning = appendWarning(envelope.Warning, `--output-filter was not applied, so Data is shown in full: ${filterError.message}`);
7977
+ return;
7978
+ }
7979
+ envelope.Data = filtered;
7980
+ if (note) {
7981
+ envelope.Warning = appendWarning(envelope.Warning, note);
7982
+ }
7983
+ }
7781
7984
  function defaultErrorCodeForResult(result) {
7782
7985
  switch (result) {
7783
7986
  case RESULTS.AuthenticationError:
@@ -7860,8 +8063,14 @@ var OutputFormatter;
7860
8063
  }
7861
8064
  const filter = getOutputFilter();
7862
8065
  if (filter) {
7863
- const filtered = applyFilter(data.Data, filter);
8066
+ let note;
8067
+ const filtered = applyFilter(data.Data, filter, (n) => {
8068
+ note = n;
8069
+ });
7864
8070
  data.Data = normalize ? normalizeDataKeys(filtered, verbatim, subtrees && { refs: subtrees.refs, mode: "skip" }) : filtered;
8071
+ if (note) {
8072
+ data.Warning = appendWarning(data.Warning, note);
8073
+ }
7865
8074
  }
7866
8075
  logOutput(normalizeOutputKeys(data), getOutputFormat(), options?.tableRowStyle);
7867
8076
  }
@@ -7889,6 +8098,7 @@ var OutputFormatter;
7889
8098
  delete envelope.TelemetryErrorClass;
7890
8099
  delete envelope.TelemetryTerminalOutcome;
7891
8100
  delete envelope.TelemetryTerminalSignal;
8101
+ filterFailureData(envelope);
7892
8102
  if (!suppressTelemetry) {
7893
8103
  telemetry.trackEvent(CommonTelemetryEvents.Error, {
7894
8104
  result: data.Result,
@@ -7937,13 +8147,20 @@ var OutputFormatter;
7937
8147
  OutputFormatter.log = log;
7938
8148
  function formatToString(data) {
7939
8149
  const filter = getOutputFilter();
8150
+ const envelope = data;
7940
8151
  if ("Data" in data && data.Data != null) {
7941
8152
  data.Data = normalizeDataKeys(data.Data);
7942
8153
  if (filter) {
7943
- data.Data = normalizeDataKeys(applyFilter(data.Data, filter));
8154
+ let note;
8155
+ data.Data = normalizeDataKeys(applyFilter(data.Data, filter, (n) => {
8156
+ note = n;
8157
+ }));
8158
+ if (note) {
8159
+ envelope.Warning = appendWarning(envelope.Warning, note);
8160
+ }
7944
8161
  }
7945
8162
  }
7946
- const output = normalizeOutputKeys(data);
8163
+ const output = normalizeOutputKeys(envelope);
7947
8164
  const lines = [];
7948
8165
  const sink = getOutputSink();
7949
8166
  printOutput(output, getOutputFormat(), (msg) => {
@@ -9797,4 +10014,4 @@ var registerCommands = async (program2) => {
9797
10014
 
9798
10015
  export { Command, metadata, registerCommands };
9799
10016
 
9800
- //# debugId=6B3423DA67B2CC6B64756E2164756E21
10017
+ //# debugId=4F71147AC341EDF864756E2164756E21
package/dist/tool.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  metadata,
3
3
  registerCommands
4
- } from "./tool-brtwkwnp.js";
4
+ } from "./tool-8qkqz0s2.js";
5
5
  import"./tool-1de529jm.js";
6
6
  export {
7
7
  metadata,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@uipath/apms-tool",
3
3
  "author": "UiPath",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
- "version": "1.203.0-preview.235",
5
+ "version": "1.203.0-preview.240",
6
6
  "description": "CLI plugin for the UiPath Access Policy Management Service.",
7
7
  "private": false,
8
8
  "repository": {
@@ -27,5 +27,5 @@
27
27
  "files": [
28
28
  "dist"
29
29
  ],
30
- "gitHead": "4788b04c17a4429e5a994af2c3eba3898d1c4b13"
30
+ "gitHead": "95409ea61d359dff5465afaf59cb3a5efae542af"
31
31
  }