@uipath/uipath-typescript 1.4.1 → 1.5.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.
Files changed (46) hide show
  1. package/dist/agent-memory/index.d.ts +4 -1
  2. package/dist/agents/index.cjs +341 -6
  3. package/dist/agents/index.d.ts +717 -16
  4. package/dist/agents/index.mjs +342 -7
  5. package/dist/assets/index.cjs +25 -9
  6. package/dist/assets/index.mjs +25 -9
  7. package/dist/attachments/index.cjs +25 -9
  8. package/dist/attachments/index.mjs +25 -9
  9. package/dist/buckets/index.cjs +25 -9
  10. package/dist/buckets/index.mjs +25 -9
  11. package/dist/cases/index.cjs +621 -524
  12. package/dist/cases/index.d.ts +186 -43
  13. package/dist/cases/index.mjs +621 -524
  14. package/dist/conversational-agent/index.cjs +25 -9
  15. package/dist/conversational-agent/index.mjs +25 -9
  16. package/dist/core/index.cjs +1 -1
  17. package/dist/core/index.mjs +1 -1
  18. package/dist/document-understanding/index.cjs +84 -84
  19. package/dist/document-understanding/index.d.ts +2 -1
  20. package/dist/document-understanding/index.mjs +1 -1
  21. package/dist/entities/index.cjs +25 -9
  22. package/dist/entities/index.mjs +25 -9
  23. package/dist/feedback/index.cjs +25 -9
  24. package/dist/feedback/index.mjs +25 -9
  25. package/dist/index.cjs +332 -62
  26. package/dist/index.d.ts +827 -89
  27. package/dist/index.mjs +333 -63
  28. package/dist/index.umd.js +332 -62
  29. package/dist/jobs/index.cjs +129 -14
  30. package/dist/jobs/index.d.ts +10 -5
  31. package/dist/jobs/index.mjs +129 -14
  32. package/dist/maestro-processes/index.cjs +198 -100
  33. package/dist/maestro-processes/index.d.ts +188 -43
  34. package/dist/maestro-processes/index.mjs +198 -100
  35. package/dist/processes/index.cjs +25 -9
  36. package/dist/processes/index.d.ts +6 -1
  37. package/dist/processes/index.mjs +25 -9
  38. package/dist/queues/index.cjs +25 -9
  39. package/dist/queues/index.mjs +25 -9
  40. package/dist/tasks/index.cjs +25 -9
  41. package/dist/tasks/index.d.ts +4 -1
  42. package/dist/tasks/index.mjs +25 -9
  43. package/dist/traces/index.cjs +2 -2
  44. package/dist/traces/index.d.ts +3 -3
  45. package/dist/traces/index.mjs +2 -2
  46. package/package.json +1 -1
@@ -1602,6 +1602,25 @@ class BaseService {
1602
1602
  }
1603
1603
  _BaseService_apiClient = new WeakMap();
1604
1604
 
1605
+ /**
1606
+ * Common enum for job state used across services
1607
+ */
1608
+ var JobState;
1609
+ (function (JobState) {
1610
+ JobState["Pending"] = "Pending";
1611
+ JobState["Running"] = "Running";
1612
+ JobState["Stopping"] = "Stopping";
1613
+ JobState["Terminating"] = "Terminating";
1614
+ JobState["Faulted"] = "Faulted";
1615
+ JobState["Successful"] = "Successful";
1616
+ JobState["Stopped"] = "Stopped";
1617
+ JobState["Suspended"] = "Suspended";
1618
+ JobState["Resumed"] = "Resumed";
1619
+ JobState["Cancelled"] = "Cancelled";
1620
+ /** Server-side fallback for an unrecognized or missing job state. */
1621
+ JobState["Unknown"] = "Unknown";
1622
+ })(JobState || (JobState = {}));
1623
+
1605
1624
  /**
1606
1625
  * Base path constants for different services
1607
1626
  */
@@ -1617,10 +1636,20 @@ const AGENTS_ENDPOINTS = {
1617
1636
  GET_INCIDENTS: `${INSIGHTS_RTM_BASE}/Agents/incidents`,
1618
1637
  /** Time-series of error counts grouped by agent over the requested window. */
1619
1638
  GET_ERRORS_TIMELINE: `${INSIGHTS_RTM_BASE}/Agents/errors`,
1620
- /** Time-series of AGU consumption over the requested window. */
1639
+ /** Time-series of Agent Units consumption over the requested window. */
1621
1640
  GET_CONSUMPTION_TIMELINE: `${INSIGHTS_RTM_BASE}/Agents/consumptionTimeline`,
1622
1641
  /** Time-series of agent latency (per-percentile) over the requested window. */
1623
1642
  GET_LATENCY_TIMELINE: `${INSIGHTS_RTM_BASE}/Agents/latencyTimeline`,
1643
+ /** Top-N agents by error count over the requested window. */
1644
+ GET_TOP_ERROR_COUNT: `${INSIGHTS_RTM_BASE}/Agents/topErroredAgents`,
1645
+ /** Top-N agents by unit consumption over the requested window. */
1646
+ GET_TOP_CONSUMPTION: `${INSIGHTS_RTM_BASE}/Agents/consumption`,
1647
+ /** Distribution of incidents across types (errors, escalations, policy). */
1648
+ GET_INCIDENT_DISTRIBUTION: `${INSIGHTS_RTM_BASE}/Agents/incidentDistribution`,
1649
+ /** Aggregate per-agent and overall job/success/duration summary over the requested window. */
1650
+ GET_SUMMARY: `${INSIGHTS_RTM_BASE}/Agents/summary`,
1651
+ /** Aggregate Agent Units and Platform Units consumption per agent over the requested window. */
1652
+ GET_UNIT_CONSUMPTION_SUMMARY: `${INSIGHTS_RTM_BASE}/Agents/summary/unit-consumption`,
1624
1653
  };
1625
1654
 
1626
1655
  /**
@@ -1652,6 +1681,33 @@ const sdkClient = getOrCreateClient(CLOUD_ROLE_NAME);
1652
1681
  const track = createTrack(sdkClient);
1653
1682
  createTrackEvent(sdkClient);
1654
1683
 
1684
+ const JOB_STATUS_ALIASES = {
1685
+ Success: JobState.Successful,
1686
+ };
1687
+ const VALID_JOB_STATES = new Set(Object.values(JobState));
1688
+ /**
1689
+ * Permissively maps a raw `lastJobStatus` string to a {@link JobState}. Known
1690
+ * aliases are translated first, canonical values pass through, and anything
1691
+ * unrecognized falls back to {@link JobState.Unknown} rather than throwing.
1692
+ */
1693
+ function toJobState(raw) {
1694
+ if (Object.prototype.hasOwnProperty.call(JOB_STATUS_ALIASES, raw))
1695
+ return JOB_STATUS_ALIASES[raw];
1696
+ if (VALID_JOB_STATES.has(raw))
1697
+ return raw;
1698
+ return JobState.Unknown;
1699
+ }
1700
+ /**
1701
+ * Transforms a raw summary period into the public shape, normalizing every
1702
+ * agent's raw `lastJobStatus` string to a {@link JobState}. Tolerates a missing
1703
+ * `agents` array (treated as empty).
1704
+ */
1705
+ function normalizeSummaryPeriod(period) {
1706
+ return {
1707
+ ...period,
1708
+ agents: (period.agents ?? []).map((agent) => ({ ...agent, lastJobStatus: toJobState(agent.lastJobStatus) })),
1709
+ };
1710
+ }
1655
1711
  /**
1656
1712
  * Service for interacting with the UiPath Agents API.
1657
1713
  */
@@ -1833,7 +1889,7 @@ class AgentService extends BaseService {
1833
1889
  return response.data.data;
1834
1890
  }
1835
1891
  /**
1836
- * Retrieves a time-series of AGU (Agent Units) consumption over the requested window.
1892
+ * Retrieves a time-series of Agent Units consumption over the requested window.
1837
1893
  *
1838
1894
  * @param startTime - Inclusive lower bound for the query window
1839
1895
  * @param endTime - Exclusive upper bound for the query window
@@ -1845,13 +1901,13 @@ class AgentService extends BaseService {
1845
1901
  *
1846
1902
  * const agents = new Agents(sdk);
1847
1903
  *
1848
- * // AGU consumption timeline in May 2025
1904
+ * // Agent Units consumption timeline in May 2025
1849
1905
  * const result = await agents.getConsumptionTimeline(
1850
1906
  * new Date('2025-05-01T00:00:00Z'),
1851
1907
  * new Date('2025-06-01T00:00:00Z'),
1852
1908
  * );
1853
1909
  * result.forEach((point) => {
1854
- * console.log(`${point.timeSlice}: ${point.aguConsumption} AGU`);
1910
+ * console.log(`${point.timeSlice}: ${point.aguConsumption} Agent Units`);
1855
1911
  * });
1856
1912
  * ```
1857
1913
  * @example
@@ -1913,6 +1969,246 @@ class AgentService extends BaseService {
1913
1969
  const response = await this.post(AGENTS_ENDPOINTS.GET_LATENCY_TIMELINE, body);
1914
1970
  return response.data.data;
1915
1971
  }
1972
+ /**
1973
+ * Retrieves the top-N agents ranked by error count over the requested window.
1974
+ *
1975
+ * @param startTime - Inclusive lower bound for the query window
1976
+ * @param endTime - Exclusive upper bound for the query window
1977
+ * @param options - Optional filters
1978
+ * @returns Promise resolving to {@link AgentGetTopErrorCountResponse}
1979
+ * @example
1980
+ * ```typescript
1981
+ * import { Agents } from '@uipath/uipath-typescript/agents';
1982
+ *
1983
+ * const agents = new Agents(sdk);
1984
+ *
1985
+ * // Top agents by error count in May 2025
1986
+ * const result = await agents.getTopErrorCount(
1987
+ * new Date('2025-05-01T00:00:00Z'),
1988
+ * new Date('2025-06-01T00:00:00Z'),
1989
+ * );
1990
+ * result.data.forEach((agent) => {
1991
+ * console.log(`${agent.name}: ${agent.count} errors`);
1992
+ * });
1993
+ * ```
1994
+ * @example
1995
+ * ```typescript
1996
+ * // Scope to specific folders and top 5 agents
1997
+ * const result = await agents.getTopErrorCount(
1998
+ * new Date('2025-05-01T00:00:00Z'),
1999
+ * new Date('2025-06-01T00:00:00Z'),
2000
+ * {
2001
+ * folderKeys: ['<folderKey1>'],
2002
+ * limit: 5,
2003
+ * },
2004
+ * );
2005
+ * ```
2006
+ */
2007
+ async getTopErrorCount(startTime, endTime, options) {
2008
+ const body = this.buildAgentFilterBody(startTime, endTime, options);
2009
+ const response = await this.post(AGENTS_ENDPOINTS.GET_TOP_ERROR_COUNT, body);
2010
+ return response.data;
2011
+ }
2012
+ /**
2013
+ * Retrieves the top-N agents ranked by unit consumption over the requested window.
2014
+ *
2015
+ * @param startTime - Inclusive lower bound for the query window
2016
+ * @param endTime - Exclusive upper bound for the query window
2017
+ * @param options - Optional filters
2018
+ * @returns Promise resolving to {@link AgentGetTopConsumptionResponse}
2019
+ * @example
2020
+ * ```typescript
2021
+ * import { Agents } from '@uipath/uipath-typescript/agents';
2022
+ *
2023
+ * const agents = new Agents(sdk);
2024
+ *
2025
+ * // Top agents by consumption in May 2025
2026
+ * const result = await agents.getTopConsumption(
2027
+ * new Date('2025-05-01T00:00:00Z'),
2028
+ * new Date('2025-06-01T00:00:00Z'),
2029
+ * );
2030
+ * console.log(`Total consumed: ${result.totalConsumed}`);
2031
+ * result.agents.forEach((agent) => {
2032
+ * console.log(`${agent.agentName}: ${agent.consumedQuantity}`);
2033
+ * });
2034
+ * ```
2035
+ * @example
2036
+ * ```typescript
2037
+ * import { Agents, AgentType } from '@uipath/uipath-typescript/agents';
2038
+ *
2039
+ * const agents = new Agents(sdk);
2040
+ *
2041
+ * // Top 5 healthy autonomous agents by consumption
2042
+ * const result = await agents.getTopConsumption(
2043
+ * new Date('2025-05-01T00:00:00Z'),
2044
+ * new Date('2025-06-01T00:00:00Z'),
2045
+ * {
2046
+ * limit: 5,
2047
+ * healthy: true,
2048
+ * agentTypes: [AgentType.Autonomous],
2049
+ * },
2050
+ * );
2051
+ * ```
2052
+ */
2053
+ async getTopConsumption(startTime, endTime, options) {
2054
+ const body = this.buildAgentFilterBody(startTime, endTime, options);
2055
+ if (options?.healthy !== undefined)
2056
+ body.healthy = options.healthy;
2057
+ if (options?.healthThreshold !== undefined)
2058
+ body.healthThreshold = options.healthThreshold;
2059
+ if (options?.agentTypes?.length)
2060
+ body.agentTypes = options.agentTypes.join(',');
2061
+ const response = await this.post(AGENTS_ENDPOINTS.GET_TOP_CONSUMPTION, body);
2062
+ return response.data.data;
2063
+ }
2064
+ /**
2065
+ * Retrieves breakdown of agent incidents count — errors, escalations,
2066
+ * and policy violations over a requested window.
2067
+ *
2068
+ * @param startTime - Inclusive lower bound for the query window
2069
+ * @param endTime - Exclusive upper bound for the query window
2070
+ * @param options - Optional filters
2071
+ * @returns Promise resolving to {@link AgentGetIncidentDistributionResponse}
2072
+ * @example
2073
+ * ```typescript
2074
+ * import { Agents } from '@uipath/uipath-typescript/agents';
2075
+ *
2076
+ * const agents = new Agents(sdk);
2077
+ *
2078
+ * // Incident distribution in May 2025
2079
+ * const result = await agents.getIncidentDistribution(
2080
+ * new Date('2025-05-01T00:00:00Z'),
2081
+ * new Date('2025-06-01T00:00:00Z'),
2082
+ * );
2083
+ * console.log(`Errors: ${result.errorCount}, Escalations: ${result.escalationCount}, Policy: ${result.policyCount}`);
2084
+ * ```
2085
+ * @example
2086
+ * ```typescript
2087
+ * // Scope to specific folders
2088
+ * const result = await agents.getIncidentDistribution(
2089
+ * new Date('2025-05-01T00:00:00Z'),
2090
+ * new Date('2025-06-01T00:00:00Z'),
2091
+ * {
2092
+ * folderKeys: ['<folderKey1>'],
2093
+ * },
2094
+ * );
2095
+ * ```
2096
+ */
2097
+ async getIncidentDistribution(startTime, endTime, options) {
2098
+ const body = this.buildAgentFilterBody(startTime, endTime, options);
2099
+ const response = await this.post(AGENTS_ENDPOINTS.GET_INCIDENT_DISTRIBUTION, body);
2100
+ return response.data.data;
2101
+ }
2102
+ /**
2103
+ * Retrieves a job-execution summary for the requested window: overall totals
2104
+ * (total jobs, successful jobs, success rate, average duration) alongside a
2105
+ * per-agent breakdown. When `lookbackPeriodAnalysis` is enabled, a comparable
2106
+ * summary for the preceding window of equal length is included too.
2107
+ *
2108
+ * @param startTime - Inclusive lower bound for the query window
2109
+ * @param endTime - Exclusive upper bound for the query window
2110
+ * @param options - Optional filters
2111
+ * @returns Promise resolving to {@link AgentGetSummaryResponse}
2112
+ * @example
2113
+ * ```typescript
2114
+ * import { Agents } from '@uipath/uipath-typescript/agents';
2115
+ *
2116
+ * const agents = new Agents(sdk);
2117
+ *
2118
+ * // Summary for May 2025
2119
+ * const result = await agents.getSummary(
2120
+ * new Date('2025-05-01T00:00:00Z'),
2121
+ * new Date('2025-06-01T00:00:00Z'),
2122
+ * );
2123
+ * console.log(`Success rate: ${result.currentPeriodSummary.successRate}%`);
2124
+ * ```
2125
+ * @example
2126
+ * ```typescript
2127
+ * import { Agents, AgentExecutionType } from '@uipath/uipath-typescript/agents';
2128
+ *
2129
+ * const agents = new Agents(sdk);
2130
+ *
2131
+ * // Runtime-only summary with lookback comparison
2132
+ * const result = await agents.getSummary(
2133
+ * new Date('2025-05-01T00:00:00Z'),
2134
+ * new Date('2025-06-01T00:00:00Z'),
2135
+ * {
2136
+ * lookbackPeriodAnalysis: true,
2137
+ * executionType: AgentExecutionType.Runtime,
2138
+ * },
2139
+ * );
2140
+ * ```
2141
+ */
2142
+ async getSummary(startTime, endTime, options) {
2143
+ const body = this.buildAgentFilterBody(startTime, endTime, options);
2144
+ if (options?.lookbackPeriodAnalysis !== undefined)
2145
+ body.lookbackPeriodAnalysis = options.lookbackPeriodAnalysis;
2146
+ if (options?.processKey !== undefined)
2147
+ body.processKey = options.processKey;
2148
+ if (options?.folderKey !== undefined)
2149
+ body.folderKey = options.folderKey;
2150
+ if (options?.executionType !== undefined)
2151
+ body.executionType = options.executionType;
2152
+ const response = await this.post(AGENTS_ENDPOINTS.GET_SUMMARY, body);
2153
+ const summary = response.data.data;
2154
+ return {
2155
+ currentPeriodSummary: normalizeSummaryPeriod(summary.currentPeriodSummary),
2156
+ lookbackPeriodSummary: summary.lookbackPeriodSummary
2157
+ ? normalizeSummaryPeriod(summary.lookbackPeriodSummary)
2158
+ : undefined,
2159
+ };
2160
+ }
2161
+ /**
2162
+ * Retrieves an aggregate Agent Units and Platform Units consumption summary per agent over the
2163
+ * requested window.
2164
+ *
2165
+ * @param startTime - Inclusive lower bound for the query window
2166
+ * @param endTime - Exclusive upper bound for the query window
2167
+ * @param options - Optional filters
2168
+ * @returns Promise resolving to {@link AgentGetUnitConsumptionSummaryResponse}
2169
+ * @example
2170
+ * ```typescript
2171
+ * import { Agents } from '@uipath/uipath-typescript/agents';
2172
+ *
2173
+ * const agents = new Agents(sdk);
2174
+ *
2175
+ * // Unit consumption summary for May 2025
2176
+ * const result = await agents.getUnitConsumptionSummary(
2177
+ * new Date('2025-05-01T00:00:00Z'),
2178
+ * new Date('2025-06-01T00:00:00Z'),
2179
+ * );
2180
+ * console.log(`Agent Units complete jobs: ${result.currentPeriodSummary.totalAgentUnitConsumption.completeJobs}`);
2181
+ * ```
2182
+ * @example
2183
+ * ```typescript
2184
+ * import { Agents, AgentExecutionType } from '@uipath/uipath-typescript/agents';
2185
+ *
2186
+ * const agents = new Agents(sdk);
2187
+ *
2188
+ * // Runtime-only summary with lookback comparison
2189
+ * const result = await agents.getUnitConsumptionSummary(
2190
+ * new Date('2025-05-01T00:00:00Z'),
2191
+ * new Date('2025-06-01T00:00:00Z'),
2192
+ * {
2193
+ * lookbackPeriodAnalysis: true,
2194
+ * executionType: AgentExecutionType.Runtime,
2195
+ * },
2196
+ * );
2197
+ * ```
2198
+ */
2199
+ async getUnitConsumptionSummary(startTime, endTime, options) {
2200
+ const body = this.buildAgentFilterBody(startTime, endTime, options);
2201
+ if (options?.lookbackPeriodAnalysis !== undefined)
2202
+ body.lookbackPeriodAnalysis = options.lookbackPeriodAnalysis;
2203
+ if (options?.processKey !== undefined)
2204
+ body.processKey = options.processKey;
2205
+ if (options?.folderKey !== undefined)
2206
+ body.folderKey = options.folderKey;
2207
+ if (options?.executionType !== undefined)
2208
+ body.executionType = options.executionType;
2209
+ const response = await this.post(AGENTS_ENDPOINTS.GET_UNIT_CONSUMPTION_SUMMARY, body);
2210
+ return response.data.data;
2211
+ }
1916
2212
  /**
1917
2213
  * Builds the common POST request body shared by the agent filter endpoints —
1918
2214
  * the required time window plus any optional folder/agent/project/process
@@ -1953,6 +2249,21 @@ __decorate([
1953
2249
  __decorate([
1954
2250
  track('Agents.GetLatencyTimeline')
1955
2251
  ], AgentService.prototype, "getLatencyTimeline", null);
2252
+ __decorate([
2253
+ track('Agents.GetTopErrorCount')
2254
+ ], AgentService.prototype, "getTopErrorCount", null);
2255
+ __decorate([
2256
+ track('Agents.GetTopConsumption')
2257
+ ], AgentService.prototype, "getTopConsumption", null);
2258
+ __decorate([
2259
+ track('Agents.GetIncidentDistribution')
2260
+ ], AgentService.prototype, "getIncidentDistribution", null);
2261
+ __decorate([
2262
+ track('Agents.GetSummary')
2263
+ ], AgentService.prototype, "getSummary", null);
2264
+ __decorate([
2265
+ track('Agents.GetUnitConsumptionSummary')
2266
+ ], AgentService.prototype, "getUnitConsumptionSummary", null);
1956
2267
 
1957
2268
  /**
1958
2269
  * Columns available for ordering results.
@@ -1965,9 +2276,9 @@ var AgentListSortColumn;
1965
2276
  AgentListSortColumn["HealthScore"] = "HealthScore";
1966
2277
  AgentListSortColumn["LastIncident"] = "LastIncident";
1967
2278
  AgentListSortColumn["FolderName"] = "FolderName";
1968
- /** Quantity of AGU (Agent Units) consumed */
2279
+ /** Quantity of Agent Units consumed */
1969
2280
  AgentListSortColumn["QuantityAGU"] = "QuantityAGU";
1970
- /** Quantity of PLTU (Platform Units) consumed */
2281
+ /** Quantity of Platform Units consumed */
1971
2282
  AgentListSortColumn["QuantityPLTU"] = "QuantityPLTU";
1972
2283
  AgentListSortColumn["FolderPath"] = "FolderPath";
1973
2284
  })(AgentListSortColumn || (AgentListSortColumn = {}));
@@ -1989,5 +2300,29 @@ var AgentErrorSortColumn;
1989
2300
  AgentErrorSortColumn["LastSeenFolderName"] = "LastSeenFolderName";
1990
2301
  AgentErrorSortColumn["LastSeenFolderPath"] = "LastSeenFolderPath";
1991
2302
  })(AgentErrorSortColumn || (AgentErrorSortColumn = {}));
2303
+ /**
2304
+ * Agent type, used to filter consumption results.
2305
+ *
2306
+ * Wire format is the string name, per the API's `StringEnumConverter` serialization.
2307
+ */
2308
+ var AgentType;
2309
+ (function (AgentType) {
2310
+ AgentType["Autonomous"] = "Autonomous";
2311
+ AgentType["Conversational"] = "Conversational";
2312
+ AgentType["Coded"] = "Coded";
2313
+ })(AgentType || (AgentType = {}));
2314
+ /**
2315
+ * Job execution mode filter accepted by the summary endpoints.
2316
+ *
2317
+ * Wire format is the string name (`"Debug"` / `"Runtime"`), per the API's
2318
+ * `StringEnumConverter` serialization.
2319
+ */
2320
+ var AgentExecutionType;
2321
+ (function (AgentExecutionType) {
2322
+ /** Test runs */
2323
+ AgentExecutionType["Debug"] = "Debug";
2324
+ /** Production runs */
2325
+ AgentExecutionType["Runtime"] = "Runtime";
2326
+ })(AgentExecutionType || (AgentExecutionType = {}));
1992
2327
 
1993
- export { AgentErrorSortColumn, AgentListSortColumn, AgentService as Agents };
2328
+ export { AgentErrorSortColumn, AgentExecutionType, AgentListSortColumn, AgentType, AgentService as Agents };
@@ -956,7 +956,16 @@ const BUCKET_TOKEN_PARAMS = {
956
956
  * Returns the original value if parsing fails.
957
957
  */
958
958
  /**
959
- * Transforms data by mapping fields according to the provided field mapping
959
+ * Transforms data by renaming each key in `data` exactly once, using the
960
+ * mapping (`sourceField → targetField`). Keys not present in the mapping
961
+ * pass through unchanged. The original (pre-rename) key is dropped — the
962
+ * result contains only the renamed key.
963
+ *
964
+ * Each rename is independent. If the mapping happens to contain chained
965
+ * entries (`a → b` and `b → c`), they do NOT compose: a field named `a`
966
+ * in `data` becomes `b` (not `c`), because the renames are applied based
967
+ * on the original data's keys, not the running result.
968
+ *
960
969
  * @param data The source data to transform
961
970
  * @param fieldMapping Object mapping source field names to target field names
962
971
  * @returns Transformed data with mapped field names
@@ -979,21 +988,28 @@ const BUCKET_TOKEN_PARAMS = {
979
988
  * // { userId: '123', name: 'john' },
980
989
  * // { userId: '456', name: 'jane' }
981
990
  * // ]
991
+ *
992
+ * // No chaining — `a → b` does not become `a → c` even if the map has `b → c`.
993
+ * transformData({ a: 1 }, { a: 'b', b: 'c' });
994
+ * // result = { b: 1 }
982
995
  * ```
983
996
  */
984
997
  function transformData(data, fieldMapping) {
998
+ // Pass null/undefined through unchanged — callers (e.g. AttachmentService.getById)
999
+ // may invoke this on optional fields that an OData `select` excluded.
1000
+ if (data == null) {
1001
+ return data;
1002
+ }
985
1003
  // Handle array of objects
986
1004
  if (Array.isArray(data)) {
987
1005
  return data.map(item => transformData(item, fieldMapping));
988
1006
  }
989
- // Handle single object
990
- const result = { ...data };
991
- for (const [sourceField, targetField] of Object.entries(fieldMapping)) {
992
- if (sourceField in result) {
993
- const value = result[sourceField];
994
- delete result[sourceField];
995
- result[targetField] = value;
996
- }
1007
+ // Walk the ORIGINAL data's keys, look up each in the mapping. One rename
1008
+ // per data key — no mutation of an in-progress result, so chains can't form.
1009
+ const result = {};
1010
+ for (const [key, value] of Object.entries(data)) {
1011
+ const renamedKey = fieldMapping[key] ?? key;
1012
+ result[renamedKey] = value;
997
1013
  }
998
1014
  return result;
999
1015
  }
@@ -954,7 +954,16 @@ const BUCKET_TOKEN_PARAMS = {
954
954
  * Returns the original value if parsing fails.
955
955
  */
956
956
  /**
957
- * Transforms data by mapping fields according to the provided field mapping
957
+ * Transforms data by renaming each key in `data` exactly once, using the
958
+ * mapping (`sourceField → targetField`). Keys not present in the mapping
959
+ * pass through unchanged. The original (pre-rename) key is dropped — the
960
+ * result contains only the renamed key.
961
+ *
962
+ * Each rename is independent. If the mapping happens to contain chained
963
+ * entries (`a → b` and `b → c`), they do NOT compose: a field named `a`
964
+ * in `data` becomes `b` (not `c`), because the renames are applied based
965
+ * on the original data's keys, not the running result.
966
+ *
958
967
  * @param data The source data to transform
959
968
  * @param fieldMapping Object mapping source field names to target field names
960
969
  * @returns Transformed data with mapped field names
@@ -977,21 +986,28 @@ const BUCKET_TOKEN_PARAMS = {
977
986
  * // { userId: '123', name: 'john' },
978
987
  * // { userId: '456', name: 'jane' }
979
988
  * // ]
989
+ *
990
+ * // No chaining — `a → b` does not become `a → c` even if the map has `b → c`.
991
+ * transformData({ a: 1 }, { a: 'b', b: 'c' });
992
+ * // result = { b: 1 }
980
993
  * ```
981
994
  */
982
995
  function transformData(data, fieldMapping) {
996
+ // Pass null/undefined through unchanged — callers (e.g. AttachmentService.getById)
997
+ // may invoke this on optional fields that an OData `select` excluded.
998
+ if (data == null) {
999
+ return data;
1000
+ }
983
1001
  // Handle array of objects
984
1002
  if (Array.isArray(data)) {
985
1003
  return data.map(item => transformData(item, fieldMapping));
986
1004
  }
987
- // Handle single object
988
- const result = { ...data };
989
- for (const [sourceField, targetField] of Object.entries(fieldMapping)) {
990
- if (sourceField in result) {
991
- const value = result[sourceField];
992
- delete result[sourceField];
993
- result[targetField] = value;
994
- }
1005
+ // Walk the ORIGINAL data's keys, look up each in the mapping. One rename
1006
+ // per data key — no mutation of an in-progress result, so chains can't form.
1007
+ const result = {};
1008
+ for (const [key, value] of Object.entries(data)) {
1009
+ const renamedKey = fieldMapping[key] ?? key;
1010
+ result[renamedKey] = value;
995
1011
  }
996
1012
  return result;
997
1013
  }
@@ -277,7 +277,16 @@ class NetworkError extends UiPathError {
277
277
  * Returns the original value if parsing fails.
278
278
  */
279
279
  /**
280
- * Transforms data by mapping fields according to the provided field mapping
280
+ * Transforms data by renaming each key in `data` exactly once, using the
281
+ * mapping (`sourceField → targetField`). Keys not present in the mapping
282
+ * pass through unchanged. The original (pre-rename) key is dropped — the
283
+ * result contains only the renamed key.
284
+ *
285
+ * Each rename is independent. If the mapping happens to contain chained
286
+ * entries (`a → b` and `b → c`), they do NOT compose: a field named `a`
287
+ * in `data` becomes `b` (not `c`), because the renames are applied based
288
+ * on the original data's keys, not the running result.
289
+ *
281
290
  * @param data The source data to transform
282
291
  * @param fieldMapping Object mapping source field names to target field names
283
292
  * @returns Transformed data with mapped field names
@@ -300,21 +309,28 @@ class NetworkError extends UiPathError {
300
309
  * // { userId: '123', name: 'john' },
301
310
  * // { userId: '456', name: 'jane' }
302
311
  * // ]
312
+ *
313
+ * // No chaining — `a → b` does not become `a → c` even if the map has `b → c`.
314
+ * transformData({ a: 1 }, { a: 'b', b: 'c' });
315
+ * // result = { b: 1 }
303
316
  * ```
304
317
  */
305
318
  function transformData(data, fieldMapping) {
319
+ // Pass null/undefined through unchanged — callers (e.g. AttachmentService.getById)
320
+ // may invoke this on optional fields that an OData `select` excluded.
321
+ if (data == null) {
322
+ return data;
323
+ }
306
324
  // Handle array of objects
307
325
  if (Array.isArray(data)) {
308
326
  return data.map(item => transformData(item, fieldMapping));
309
327
  }
310
- // Handle single object
311
- const result = { ...data };
312
- for (const [sourceField, targetField] of Object.entries(fieldMapping)) {
313
- if (sourceField in result) {
314
- const value = result[sourceField];
315
- delete result[sourceField];
316
- result[targetField] = value;
317
- }
328
+ // Walk the ORIGINAL data's keys, look up each in the mapping. One rename
329
+ // per data key — no mutation of an in-progress result, so chains can't form.
330
+ const result = {};
331
+ for (const [key, value] of Object.entries(data)) {
332
+ const renamedKey = fieldMapping[key] ?? key;
333
+ result[renamedKey] = value;
318
334
  }
319
335
  return result;
320
336
  }
@@ -275,7 +275,16 @@ class NetworkError extends UiPathError {
275
275
  * Returns the original value if parsing fails.
276
276
  */
277
277
  /**
278
- * Transforms data by mapping fields according to the provided field mapping
278
+ * Transforms data by renaming each key in `data` exactly once, using the
279
+ * mapping (`sourceField → targetField`). Keys not present in the mapping
280
+ * pass through unchanged. The original (pre-rename) key is dropped — the
281
+ * result contains only the renamed key.
282
+ *
283
+ * Each rename is independent. If the mapping happens to contain chained
284
+ * entries (`a → b` and `b → c`), they do NOT compose: a field named `a`
285
+ * in `data` becomes `b` (not `c`), because the renames are applied based
286
+ * on the original data's keys, not the running result.
287
+ *
279
288
  * @param data The source data to transform
280
289
  * @param fieldMapping Object mapping source field names to target field names
281
290
  * @returns Transformed data with mapped field names
@@ -298,21 +307,28 @@ class NetworkError extends UiPathError {
298
307
  * // { userId: '123', name: 'john' },
299
308
  * // { userId: '456', name: 'jane' }
300
309
  * // ]
310
+ *
311
+ * // No chaining — `a → b` does not become `a → c` even if the map has `b → c`.
312
+ * transformData({ a: 1 }, { a: 'b', b: 'c' });
313
+ * // result = { b: 1 }
301
314
  * ```
302
315
  */
303
316
  function transformData(data, fieldMapping) {
317
+ // Pass null/undefined through unchanged — callers (e.g. AttachmentService.getById)
318
+ // may invoke this on optional fields that an OData `select` excluded.
319
+ if (data == null) {
320
+ return data;
321
+ }
304
322
  // Handle array of objects
305
323
  if (Array.isArray(data)) {
306
324
  return data.map(item => transformData(item, fieldMapping));
307
325
  }
308
- // Handle single object
309
- const result = { ...data };
310
- for (const [sourceField, targetField] of Object.entries(fieldMapping)) {
311
- if (sourceField in result) {
312
- const value = result[sourceField];
313
- delete result[sourceField];
314
- result[targetField] = value;
315
- }
326
+ // Walk the ORIGINAL data's keys, look up each in the mapping. One rename
327
+ // per data key — no mutation of an in-progress result, so chains can't form.
328
+ const result = {};
329
+ for (const [key, value] of Object.entries(data)) {
330
+ const renamedKey = fieldMapping[key] ?? key;
331
+ result[renamedKey] = value;
316
332
  }
317
333
  return result;
318
334
  }