@uipath/uipath-typescript 1.2.2 → 1.3.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.
@@ -1642,6 +1642,36 @@ class FolderScopedService extends BaseService {
1642
1642
  }
1643
1643
  }
1644
1644
 
1645
+ /**
1646
+ * Creates methods for a job response object.
1647
+ *
1648
+ * @param jobData - The raw job data from API
1649
+ * @param service - The job service instance
1650
+ * @returns Object containing job methods
1651
+ */
1652
+ function createJobMethods(jobData, service) {
1653
+ return {
1654
+ async getOutput() {
1655
+ if (!jobData.key)
1656
+ throw new Error('Job key is undefined');
1657
+ if (!jobData.folderId)
1658
+ throw new Error('Job folderId is undefined');
1659
+ return service.getOutput(jobData.key, jobData.folderId);
1660
+ },
1661
+ };
1662
+ }
1663
+ /**
1664
+ * Creates a job response with bound methods.
1665
+ *
1666
+ * @param jobData - The raw job data from API
1667
+ * @param service - The job service instance
1668
+ * @returns A job object with added methods
1669
+ */
1670
+ function createJobWithMethods(jobData, service) {
1671
+ const methods = createJobMethods(jobData, service);
1672
+ return Object.assign({}, jobData, methods);
1673
+ }
1674
+
1645
1675
  /**
1646
1676
  * Base path constants for different services
1647
1677
  */
@@ -1655,6 +1685,13 @@ const ORCHESTRATOR_BASE = 'orchestrator_';
1655
1685
  */
1656
1686
  const JOB_ENDPOINTS = {
1657
1687
  GET_ALL: `${ORCHESTRATOR_BASE}/odata/Jobs`,
1688
+ GET_BY_KEY: (identifier) => `${ORCHESTRATOR_BASE}/odata/Jobs/UiPath.Server.Configuration.OData.GetByKey(identifier=${identifier})`,
1689
+ };
1690
+ /**
1691
+ * Orchestrator Attachment Service Endpoints
1692
+ */
1693
+ const ORCHESTRATOR_ATTACHMENT_ENDPOINTS = {
1694
+ GET_BY_ID: (id) => `${ORCHESTRATOR_BASE}/odata/Attachments(${id})`,
1658
1695
  };
1659
1696
 
1660
1697
  /**
@@ -1678,7 +1715,7 @@ const JobMap = {
1678
1715
  // Connection string placeholder that will be replaced during build
1679
1716
  const CONNECTION_STRING = "InstrumentationKey=a6efa11d-1feb-4508-9738-e13e12dcae5e;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;ApplicationId=7c58eb1c-9581-4ba6-839e-11725848a037";
1680
1717
  // SDK Version placeholder
1681
- const SDK_VERSION = "1.2.2";
1718
+ const SDK_VERSION = "1.3.0";
1682
1719
  const VERSION = "Version";
1683
1720
  const SERVICE = "Service";
1684
1721
  const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
@@ -1904,8 +1941,9 @@ function createTrackedFunction(originalFunction, nameOrOptions, fallbackName, op
1904
1941
  // Track the event if enabled
1905
1942
  if (shouldTrack) {
1906
1943
  // Use the full name provided in the decorator (e.g., "Queue.GetAll")
1907
- const serviceMethod = nameOrOptions
1908
- ;
1944
+ const serviceMethod = typeof nameOrOptions === 'string'
1945
+ ? nameOrOptions
1946
+ : fallbackName;
1909
1947
  // Use 'Sdk.Run' as the name and serviceMethod as the service
1910
1948
  telemetryClient.track(serviceMethod, SDK_RUN_EVENT, opts.attributes);
1911
1949
  }
@@ -1934,7 +1972,7 @@ function createTrackedFunction(originalFunction, nameOrOptions, fallbackName, op
1934
1972
  */
1935
1973
  function track(nameOrOptions, options) {
1936
1974
  return function decorator(_target, propertyKey, descriptor) {
1937
- const opts = {};
1975
+ const opts = typeof nameOrOptions === 'object' ? nameOrOptions : {};
1938
1976
  if (descriptor && typeof descriptor.value === 'function') {
1939
1977
  // Method decorator
1940
1978
  descriptor.value = createTrackedFunction(descriptor.value, nameOrOptions, propertyKey || 'unknown_method', opts);
@@ -1945,27 +1983,90 @@ function track(nameOrOptions, options) {
1945
1983
  };
1946
1984
  }
1947
1985
 
1986
+ /**
1987
+ * Maps fields for Attachment entities to ensure consistent naming
1988
+ */
1989
+ const AttachmentsMap = {
1990
+ creationTime: 'createdTime',
1991
+ lastModificationTime: 'lastModifiedTime'
1992
+ };
1993
+
1994
+ /**
1995
+ * Maps fields for Bucket entities to ensure consistent naming
1996
+ */
1997
+ const BucketMap = {
1998
+ fullPath: 'path',
1999
+ items: 'blobItems',
2000
+ verb: 'httpMethod'
2001
+ };
2002
+
2003
+ class AttachmentService extends BaseService {
2004
+ /**
2005
+ * Gets an attachment by ID
2006
+ * @param id - The UUID of the attachment to retrieve
2007
+ * @param options - Optional query parameters (expand, select)
2008
+ * @returns Promise resolving to the attachment
2009
+ *
2010
+ * @example
2011
+ * ```typescript
2012
+ * import { Attachments } from '@uipath/uipath-typescript/attachments';
2013
+ *
2014
+ * const attachments = new Attachments(sdk);
2015
+ * const attachment = await attachments.getById('12345678-1234-1234-1234-123456789abc');
2016
+ * ```
2017
+ */
2018
+ async getById(id, options = {}) {
2019
+ if (!id) {
2020
+ throw new ValidationError({ message: 'id is required for getById' });
2021
+ }
2022
+ // Prefix all keys in options with $ for OData
2023
+ const keysToPrefix = Object.keys(options);
2024
+ const apiOptions = addPrefixToKeys(options, ODATA_PREFIX, keysToPrefix);
2025
+ const response = await this.get(ORCHESTRATOR_ATTACHMENT_ENDPOINTS.GET_BY_ID(id), {
2026
+ params: apiOptions,
2027
+ });
2028
+ // Transform response from PascalCase to camelCase, then apply field maps
2029
+ const camelCased = pascalToCamelCaseKeys(response.data);
2030
+ camelCased.blobFileAccess = transformData(camelCased.blobFileAccess, BucketMap);
2031
+ return transformData(camelCased, AttachmentsMap);
2032
+ }
2033
+ }
2034
+ __decorate([
2035
+ track('Attachments.GetById')
2036
+ ], AttachmentService.prototype, "getById", null);
2037
+
1948
2038
  /**
1949
2039
  * Service for interacting with UiPath Orchestrator Jobs API
1950
2040
  */
1951
2041
  class JobService extends FolderScopedService {
1952
2042
  /**
1953
- * Gets all jobs across folders with optional filtering
2043
+ * Creates an instance of the Jobs service.
2044
+ *
2045
+ * @param instance - UiPath SDK instance providing authentication and configuration
2046
+ */
2047
+ constructor(instance) {
2048
+ super(instance);
2049
+ this.attachmentService = new AttachmentService(instance);
2050
+ }
2051
+ /**
2052
+ * Gets all jobs across folders with optional filtering and pagination.
2053
+ *
2054
+ * Returns jobs with full details including state, timing, and input/output arguments.
2055
+ * Pass `folderId` to scope the query to a specific folder.
1954
2056
  *
1955
- * @param options - Query options including optional folderId and pagination options
1956
- * @returns Promise resolving to array of jobs or paginated response
2057
+ * !!! info "Input and output fields are not included in `getAll` responses"
2058
+ * The `inputArguments`, `inputFile`, `outputArguments`, and `outputFile` fields will always be `null` in the `getAll` response. To retrieve a job's output, use the {@link getOutput} method with the job's `key` and `folderId`.
1957
2059
  *
2060
+ * @param options - Query options including optional folderId, filtering, and pagination options
2061
+ * @returns Promise resolving to either an array of jobs {@link NonPaginatedResponse}<{@link JobGetResponse}> or a {@link PaginatedResponse}<{@link JobGetResponse}> when pagination options are used.
2062
+ * {@link JobGetResponse}
1958
2063
  * @example
1959
2064
  * ```typescript
1960
- * import { Jobs } from '@uipath/uipath-typescript/jobs';
1961
- *
1962
- * const jobs = new Jobs(sdk);
1963
- *
1964
2065
  * // Get all jobs
1965
2066
  * const allJobs = await jobs.getAll();
1966
2067
  *
1967
2068
  * // Get all jobs in a specific folder
1968
- * const folderJobs = await jobs.getAll({ folderId: 123 });
2069
+ * const folderJobs = await jobs.getAll({ folderId: <folderId> });
1969
2070
  *
1970
2071
  * // With filtering
1971
2072
  * const runningJobs = await jobs.getAll({
@@ -1979,10 +2080,19 @@ class JobService extends FolderScopedService {
1979
2080
  * if (page1.hasNextPage) {
1980
2081
  * const page2 = await jobs.getAll({ cursor: page1.nextCursor });
1981
2082
  * }
2083
+ *
2084
+ * // Jump to specific page
2085
+ * const page5 = await jobs.getAll({
2086
+ * jumpToPage: 5,
2087
+ * pageSize: 10
2088
+ * });
1982
2089
  * ```
1983
2090
  */
1984
2091
  async getAll(options) {
1985
- const transformJobResponse = (job) => transformData(pascalToCamelCaseKeys(job), JobMap);
2092
+ const transformJobResponse = (job) => {
2093
+ const rawJob = transformData(pascalToCamelCaseKeys(job), JobMap);
2094
+ return createJobWithMethods(rawJob, this);
2095
+ };
1986
2096
  return PaginationHelpers.getAll({
1987
2097
  serviceAccess: this.createPaginationServiceAccess(),
1988
2098
  getEndpoint: () => JOB_ENDPOINTS.GET_ALL,
@@ -2000,10 +2110,111 @@ class JobService extends FolderScopedService {
2000
2110
  },
2001
2111
  }, options);
2002
2112
  }
2113
+ /**
2114
+ * Gets the output of a completed job.
2115
+ *
2116
+ * Retrieves the job's output arguments, handling both inline output (stored directly on the job
2117
+ * as a JSON string in `outputArguments`) and file-based output (stored as a blob attachment for
2118
+ * large outputs). Returns the parsed JSON output or `null` if the job has no output.
2119
+ *
2120
+ * @param jobKey - The unique key (GUID) of the job to retrieve output from
2121
+ * @param folderId - The folder ID where the job resides
2122
+ * @returns Promise resolving to the parsed output as `Record<string, unknown>`, or `null` if no output exists
2123
+ *
2124
+ * @example
2125
+ * ```typescript
2126
+ * // Get output from a completed job
2127
+ * const output = await jobs.getOutput(<jobKey>, <folderId>);
2128
+ *
2129
+ * if (output) {
2130
+ * console.log('Job output:', output);
2131
+ * }
2132
+ * ```
2133
+ *
2134
+ * @example
2135
+ * ```typescript
2136
+ * // Get output using bound method (jobKey and folderId are taken from the job object)
2137
+ * const allJobs = await jobs.getAll();
2138
+ * const completedJob = allJobs.items.find(j => j.state === JobState.Successful);
2139
+ *
2140
+ * if (completedJob) {
2141
+ * const output = await completedJob.getOutput();
2142
+ * }
2143
+ * ```
2144
+ */
2145
+ async getOutput(jobKey, folderId) {
2146
+ if (!jobKey) {
2147
+ throw new ValidationError({ message: 'jobKey is required for getOutput' });
2148
+ }
2149
+ const job = await this.fetchJobByKey(jobKey, folderId);
2150
+ if (job.OutputArguments) {
2151
+ try {
2152
+ return JSON.parse(job.OutputArguments);
2153
+ }
2154
+ catch {
2155
+ throw new ServerError({ message: 'Failed to parse job output arguments as JSON' });
2156
+ }
2157
+ }
2158
+ if (job.OutputFile) {
2159
+ return this.downloadOutputFile(job.OutputFile);
2160
+ }
2161
+ return null;
2162
+ }
2163
+ /**
2164
+ * Fetches a job by its Key (GUID) using the GetByKey endpoint.
2165
+ * Only selects fields needed for output extraction.
2166
+ */
2167
+ async fetchJobByKey(jobKey, folderId) {
2168
+ const headers = createHeaders({ [FOLDER_ID]: folderId });
2169
+ const response = await this.get(JOB_ENDPOINTS.GET_BY_KEY(jobKey), {
2170
+ params: {
2171
+ $select: 'OutputArguments,OutputFile',
2172
+ },
2173
+ headers,
2174
+ });
2175
+ return response.data;
2176
+ }
2177
+ /**
2178
+ * Downloads the output file content via the Attachments API.
2179
+ * 1. Fetches blob access info from the attachment using AttachmentService
2180
+ * 2. Downloads content from the presigned blob URI
2181
+ * 3. Parses and returns the JSON content
2182
+ */
2183
+ async downloadOutputFile(outputFileKey) {
2184
+ const attachment = await this.attachmentService.getById(outputFileKey);
2185
+ const blobAccess = attachment.blobFileAccess;
2186
+ if (!blobAccess?.uri) {
2187
+ return null;
2188
+ }
2189
+ const blobHeaders = { ...blobAccess.headers };
2190
+ // Add auth header if the blob URI requires authenticated access
2191
+ if (blobAccess.requiresAuth) {
2192
+ const token = await this.getValidAuthToken();
2193
+ blobHeaders['Authorization'] = `Bearer ${token}`;
2194
+ }
2195
+ const blobResponse = await fetch(blobAccess.uri, {
2196
+ method: 'GET',
2197
+ headers: blobHeaders,
2198
+ });
2199
+ if (!blobResponse.ok) {
2200
+ const errorInfo = await errorResponseParser.parse(blobResponse);
2201
+ throw ErrorFactory.createFromHttpStatus(blobResponse.status, errorInfo);
2202
+ }
2203
+ const content = await blobResponse.text();
2204
+ try {
2205
+ return JSON.parse(content);
2206
+ }
2207
+ catch {
2208
+ throw new ServerError({ message: 'Failed to parse job output file as JSON' });
2209
+ }
2210
+ }
2003
2211
  }
2004
2212
  __decorate([
2005
2213
  track('Jobs.GetAll')
2006
2214
  ], JobService.prototype, "getAll", null);
2215
+ __decorate([
2216
+ track('Jobs.GetOutput')
2217
+ ], JobService.prototype, "getOutput", null);
2007
2218
 
2008
2219
  /**
2009
2220
  * Enum for job sub-state
@@ -2030,4 +2241,20 @@ var ServerlessJobType;
2030
2241
  ServerlessJobType["PythonAgent"] = "PythonAgent";
2031
2242
  })(ServerlessJobType || (ServerlessJobType = {}));
2032
2243
 
2033
- export { JobService, JobSubState, JobService as Jobs, ServerlessJobType };
2244
+ /**
2245
+ * Common enum for job state used across services
2246
+ */
2247
+ var JobState;
2248
+ (function (JobState) {
2249
+ JobState["Pending"] = "Pending";
2250
+ JobState["Running"] = "Running";
2251
+ JobState["Stopping"] = "Stopping";
2252
+ JobState["Terminating"] = "Terminating";
2253
+ JobState["Faulted"] = "Faulted";
2254
+ JobState["Successful"] = "Successful";
2255
+ JobState["Stopped"] = "Stopped";
2256
+ JobState["Suspended"] = "Suspended";
2257
+ JobState["Resumed"] = "Resumed";
2258
+ })(JobState || (JobState = {}));
2259
+
2260
+ export { JobService, JobState, JobSubState, JobService as Jobs, ServerlessJobType, createJobWithMethods };
@@ -1732,7 +1732,7 @@ class BpmnHelpers {
1732
1732
  // Connection string placeholder that will be replaced during build
1733
1733
  const CONNECTION_STRING = "InstrumentationKey=a6efa11d-1feb-4508-9738-e13e12dcae5e;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;ApplicationId=7c58eb1c-9581-4ba6-839e-11725848a037";
1734
1734
  // SDK Version placeholder
1735
- const SDK_VERSION = "1.2.2";
1735
+ const SDK_VERSION = "1.3.0";
1736
1736
  const VERSION = "Version";
1737
1737
  const SERVICE = "Service";
1738
1738
  const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
@@ -1730,7 +1730,7 @@ class BpmnHelpers {
1730
1730
  // Connection string placeholder that will be replaced during build
1731
1731
  const CONNECTION_STRING = "InstrumentationKey=a6efa11d-1feb-4508-9738-e13e12dcae5e;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;ApplicationId=7c58eb1c-9581-4ba6-839e-11725848a037";
1732
1732
  // SDK Version placeholder
1733
- const SDK_VERSION = "1.2.2";
1733
+ const SDK_VERSION = "1.3.0";
1734
1734
  const VERSION = "Version";
1735
1735
  const SERVICE = "Service";
1736
1736
  const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
@@ -1712,7 +1712,7 @@ const PROCESS_ENDPOINTS = {
1712
1712
  // Connection string placeholder that will be replaced during build
1713
1713
  const CONNECTION_STRING = "InstrumentationKey=a6efa11d-1feb-4508-9738-e13e12dcae5e;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;ApplicationId=7c58eb1c-9581-4ba6-839e-11725848a037";
1714
1714
  // SDK Version placeholder
1715
- const SDK_VERSION = "1.2.2";
1715
+ const SDK_VERSION = "1.3.0";
1716
1716
  const VERSION = "Version";
1717
1717
  const SERVICE = "Service";
1718
1718
  const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
@@ -1710,7 +1710,7 @@ const PROCESS_ENDPOINTS = {
1710
1710
  // Connection string placeholder that will be replaced during build
1711
1711
  const CONNECTION_STRING = "InstrumentationKey=a6efa11d-1feb-4508-9738-e13e12dcae5e;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;ApplicationId=7c58eb1c-9581-4ba6-839e-11725848a037";
1712
1712
  // SDK Version placeholder
1713
- const SDK_VERSION = "1.2.2";
1713
+ const SDK_VERSION = "1.3.0";
1714
1714
  const VERSION = "Version";
1715
1715
  const SERVICE = "Service";
1716
1716
  const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
@@ -1676,7 +1676,7 @@ const QueueMap = {
1676
1676
  // Connection string placeholder that will be replaced during build
1677
1677
  const CONNECTION_STRING = "InstrumentationKey=a6efa11d-1feb-4508-9738-e13e12dcae5e;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;ApplicationId=7c58eb1c-9581-4ba6-839e-11725848a037";
1678
1678
  // SDK Version placeholder
1679
- const SDK_VERSION = "1.2.2";
1679
+ const SDK_VERSION = "1.3.0";
1680
1680
  const VERSION = "Version";
1681
1681
  const SERVICE = "Service";
1682
1682
  const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
@@ -1674,7 +1674,7 @@ const QueueMap = {
1674
1674
  // Connection string placeholder that will be replaced during build
1675
1675
  const CONNECTION_STRING = "InstrumentationKey=a6efa11d-1feb-4508-9738-e13e12dcae5e;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;ApplicationId=7c58eb1c-9581-4ba6-839e-11725848a037";
1676
1676
  // SDK Version placeholder
1677
- const SDK_VERSION = "1.2.2";
1677
+ const SDK_VERSION = "1.3.0";
1678
1678
  const VERSION = "Version";
1679
1679
  const SERVICE = "Service";
1680
1680
  const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
@@ -278,7 +278,7 @@ class NetworkError extends UiPathError {
278
278
  // Connection string placeholder that will be replaced during build
279
279
  const CONNECTION_STRING = "InstrumentationKey=a6efa11d-1feb-4508-9738-e13e12dcae5e;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;ApplicationId=7c58eb1c-9581-4ba6-839e-11725848a037";
280
280
  // SDK Version placeholder
281
- const SDK_VERSION = "1.2.2";
281
+ const SDK_VERSION = "1.3.0";
282
282
  const VERSION = "Version";
283
283
  const SERVICE = "Service";
284
284
  const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
@@ -276,7 +276,7 @@ class NetworkError extends UiPathError {
276
276
  // Connection string placeholder that will be replaced during build
277
277
  const CONNECTION_STRING = "InstrumentationKey=a6efa11d-1feb-4508-9738-e13e12dcae5e;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/;ApplicationId=7c58eb1c-9581-4ba6-839e-11725848a037";
278
278
  // SDK Version placeholder
279
- const SDK_VERSION = "1.2.2";
279
+ const SDK_VERSION = "1.3.0";
280
280
  const VERSION = "Version";
281
281
  const SERVICE = "Service";
282
282
  const CLOUD_ORGANIZATION_NAME = "CloudOrganizationName";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/uipath-typescript",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
4
4
  "description": "UiPath TypeScript SDK",
5
5
  "license": "MIT",
6
6
  "keywords": [