Sign In

@uipath/robot

Package Overview
Dependencies
Maintainers
23
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uipath/robot - npm Package Compare versions

Comparing version
1.2.5
to
1.2.6
+7
-0
dist/uipathRobot.d.ts

@@ -35,2 +35,9 @@ import { IRobotSDK } from './iRobotSDK';

/**
* Method to create a robot Job.
* @param processId Process Id of the robot process to run.
* @param argument Input parameters.
* @returns Deferred promise which is resolved with job result when robot process completes.
*/
const createJob: (processId: string, argument?: any) => Job;
/**
* Method to stop a robot process.

@@ -37,0 +44,0 @@ * @param process Robotprocess object containing all information about the robot process to cancel.

+4
-6
{
"name": "@uipath/robot",
"version": "1.2.5",
"version": "1.2.6",
"description": "UiPath Robot javascript SDK enabling web pages to interact with UiPath Robots",

@@ -9,5 +9,3 @@ "scripts": {

"clean": "tsc --build --clean",
"pack": "npm pack",
"publish:dev": "npm publish",
"publish:prod": "npm publish --access public"
"pack": "npm pack"
},

@@ -27,4 +25,4 @@ "devDependencies": {

"dependencies": {
"@microsoft/applicationinsights-web": "^2.4.4"
},
"@microsoft/applicationinsights-web": "^2.5.9"
},
"main": "dist/uipathRobot.js",

@@ -31,0 +29,0 @@ "repository": {

+6
-6

@@ -18,3 +18,3 @@ <img src="https://raw.githubusercontent.com/UiPath/angular-components/master/logo.png" width="135" />

<script src="//download.uipath.com/js/1.2.1/UiPathRobot.js"></script>
<script src="//download.uipath.com/js/1.2.6/UiPathRobot.js"></script>

@@ -45,11 +45,11 @@ ### In Node.js

To download our add-on separately visit [here](https://robotjs.uipath.com/download).
To download our add-on separately, visit [here](https://robotjs.uipath.com/download).
For a brief overview about how to use thr robot SDK visit [here] (https://robotjs.uipath.com/).
For a brief overview about how to use the robot SDK, visit [here](https://docs.uipath.com/robot/docs/about-the-robot-javascript-sdk).
[Troubleshooting] (https://robotjs.uipath.com/help).
For the SDK Specifications, visit [here](https://docs.uipath.com/robot/docs/sdk-specifications).
[Developers guide] (https://robotjs.uipath.com/guide).
Some samples can be found [here](https://robotjs.uipath.com/samples).
[Samples] (https://robotjs.uipath.com/samples).
For troubleshooting common problems, visit [here](https://robotjs.uipath.com/help).

@@ -56,0 +56,0 @@ ## License

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Job state enum
*/
var JobState;
(function (JobState) {
JobState[JobState["Executing"] = 0] = "Executing";
JobState[JobState["Closed"] = 1] = "Closed";
JobState[JobState["Canceled"] = 2] = "Canceled";
JobState[JobState["Faulted"] = 3] = "Faulted";
})(JobState = exports.JobState || (exports.JobState = {}));
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var TraceEvent;
(function (TraceEvent) {
TraceEvent["Invalid_Event"] = "InvalidEvent";
TraceEvent["Get_Port"] = "GetPort";
TraceEvent["Get_Processes"] = "GetProcesses";
TraceEvent["Init"] = "Init";
TraceEvent["Run_Robot"] = "RunRobot";
TraceEvent["Job_Status_Poll"] = "JobStatusPoll";
TraceEvent["User_Consent_Raised"] = "UserConsentRaised";
TraceEvent["SDK_Loaded"] = "SDKLoaded";
TraceEvent["Missing_Components"] = "MissingComponents";
TraceEvent["Consent_Timeout"] = "ConsentTimeout";
TraceEvent["Stop_Process"] = "StopProcess";
})(TraceEvent = exports.TraceEvent || (exports.TraceEvent = {}));
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var de_resource_json_1 = __importDefault(require("./resources/de_resource.json"));
var en_resource_json_1 = __importDefault(require("./resources/en_resource.json"));
var es_MX_resource_json_1 = __importDefault(require("./resources/es-MX_resource.json"));
var es_resource_json_1 = __importDefault(require("./resources/es_resource.json"));
var fr_resource_json_1 = __importDefault(require("./resources/fr_resource.json"));
var ja_resource_json_1 = __importDefault(require("./resources/ja_resource.json"));
var ko_resource_json_1 = __importDefault(require("./resources/ko_resource.json"));
var pt_BR_resource_json_1 = __importDefault(require("./resources/pt-BR_resource.json"));
var pt_resource_json_1 = __importDefault(require("./resources/pt_resource.json"));
var ru_resource_json_1 = __importDefault(require("./resources/ru_resource.json"));
var tr_resource_json_1 = __importDefault(require("./resources/tr_resource.json"));
var zh_CN_resource_json_1 = __importDefault(require("./resources/zh-CN_resource.json"));
var Language = /** @class */ (function () {
function Language() {
}
Language.GetResource = function () {
var language = window.navigator.language.slice(0, 2);
switch (language) {
case 'de': return de_resource_json_1.default;
case 'es-MX': return es_MX_resource_json_1.default;
case 'es': return es_resource_json_1.default;
case 'fr': return fr_resource_json_1.default;
case 'ja': return ja_resource_json_1.default;
case 'ko': return ko_resource_json_1.default;
case 'pt-BR': return pt_BR_resource_json_1.default;
case 'pt': return pt_resource_json_1.default;
case 'ru': return ru_resource_json_1.default;
case 'tr': return tr_resource_json_1.default;
case 'zh-CN': return zh_CN_resource_json_1.default;
case 'en':
default: return en_resource_json_1.default;
}
};
return Language;
}());
exports.Language = Language;
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var german = __importStar(require("./de_resource.json"));
var value = german;
module.exports = value;
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var english = __importStar(require("./en_resource.json"));
var value = english;
module.exports = value;
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var spanish = __importStar(require("./es_resource.json"));
var value = spanish;
module.exports = value;
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var spanish_mex = __importStar(require("./es-MX_resource.json"));
var value = spanish_mex;
module.exports = value;
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var french = __importStar(require("./fr_resource.json"));
var value = french;
module.exports = value;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var japanese = __importStar(require("./ja_resource.json"));
var value = japanese;
module.exports = value;
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var korean = __importStar(require("./ko_resource.json"));
var value = korean;
module.exports = value;
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var portuguese = __importStar(require("./pt_resource.json"));
var value = portuguese;
module.exports = value;
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var portuguese_br = __importStar(require("./pt-BR_resource.json"));
var value = portuguese_br;
module.exports = value;
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var russian = __importStar(require("./ru_resource.json"));
var value = russian;
module.exports = value;
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var turkish = __importStar(require("./tr_resource.json"));
var value = turkish;
module.exports = value;
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var chinese = __importStar(require("./zh-CN_resource.json"));
var value = chinese;
module.exports = value;
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./job"));
__export(require("./jobPromise"));
__export(require("./jobResult"));
__export(require("./jobStatus"));
__export(require("./response"));
__export(require("./robotProcess"));
__export(require("./settings"));
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var utils_1 = require("../utils");
var constants_1 = require("../utils/constants");
/**
* Job model used to identify a running/completed Robot process
*/
var Job = /** @class */ (function () {
/**
* Default constructor
* @param processId Unique GUID of the robot process to run.
* @param argument In arguments to be passed to the robot process on execution.
*/
function Job(processId, argument) {
var _this = this;
this.processId = processId;
this.argument = argument;
/**
* Dispatch method to trigger events.
* @param status argument to pass along while event is dispatched.
*/
this.dispatch = function (status) { return _this.eventHandlers.dispatch(constants_1.Constants.STATUS, status); };
this.jobId = '';
this.processId = processId;
this.argument = argument;
this.eventHandlers = new utils_1.Dispatcher();
}
/**
* Method to attach event handler on the job.
* @param eventName Available job events are 'status'.
* @param eventHanlder Event handler callback function called when event occurs.
*/
Job.prototype.on = function (eventName, eventHanlder) {
switch (eventName) {
case constants_1.Constants.STATUS: {
this.eventHandlers.on(constants_1.Constants.STATUS, eventHanlder);
break;
}
default: {
break;
}
}
};
return Job;
}());
exports.Job = Job;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var uipathRobot_1 = require("../uipathRobot");
var constants_1 = require("../utils/constants");
/**
* Job promise model used for resolution and/or rejection of Promise<JobResult>
*/
var JobPromise = /** @class */ (function () {
/**
* Default constructor
* @param job Job to be wrapped with promise
*/
function JobPromise(job) {
var _this = this;
this.job = job;
/**
* Method to attach job status event handlers.
* @param eventHanlder Attaches callback which is invoked on job status change.
*/
this.onStatus = function (eventHanlder) {
_this.job.on(constants_1.Constants.STATUS, eventHanlder);
return _this;
};
this.promise = uipathRobot_1.UiPathRobot.startJob(this.job);
}
JobPromise.prototype.then = function (onfulfilled, onrejected) {
return this.promise.then(onfulfilled, onrejected);
};
JobPromise.prototype.catch = function (onrejected) {
return this.promise.catch(onrejected);
};
JobPromise.prototype.finally = function (onfinally) {
return this.promise.finally(onfinally);
};
return JobPromise;
}());
exports.JobPromise = JobPromise;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Job result model containing all output arguments from the process.
* Empty if there are no out arguments.
*/
var JobResult = /** @class */ (function () {
function JobResult() {
}
return JobResult;
}());
exports.JobResult = JobResult;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Job status model containings details of the executing job.
*/
var JobStatus = /** @class */ (function () {
/**
*
* @param state Current state of the job
* @param status Current status of the job
* @param output Output of the job if any
* @param exception Exception from the job if any
*/
function JobStatus(state, status, output, exception) {
this.state = state;
this.status = status;
this.output = output;
this.exception = exception;
this.output = output || undefined;
this.exception = exception || undefined;
}
Object.defineProperty(JobStatus.prototype, "isExecuting", {
get: function () { return this.state === 'Executing'; },
enumerable: true,
configurable: true
});
Object.defineProperty(JobStatus.prototype, "isClosed", {
get: function () { return this.state === 'Closed'; },
enumerable: true,
configurable: true
});
Object.defineProperty(JobStatus.prototype, "errorResponse", {
get: function () {
if (this.exception) {
this.exception.state = this.state;
}
else {
this.exception = { 'state': this.state };
}
return this.exception;
},
enumerable: true,
configurable: true
});
return JobStatus;
}());
exports.JobStatus = JobStatus;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Generic response model
*/
var Response = /** @class */ (function () {
/**
*
* @param httpStatus Http status of the response
* @param statusText Http status text of the response
* @param data response data if any
* @param error Handled error response if any
*/
function Response(httpStatus, statusText, data, error) {
var _this = this;
this.httpStatus = httpStatus;
this.statusText = statusText;
this.data = data;
this.error = error;
/**
* Resolve promise if its a successful response. Throws error if response was unsuccessful.
* @param promise promise which will be resolved if response was successful.
*/
this.resolve = function (promise) {
if (_this.isSuccess) {
promise.resolve(_this.data);
}
else {
promise.reject(new Error(_this.httpStatus + " - " + _this.error));
}
};
this.data = data || undefined;
}
Object.defineProperty(Response.prototype, "isSuccess", {
get: function () { return this.httpStatus >= 200 && this.httpStatus < 300; },
enumerable: true,
configurable: true
});
Object.defineProperty(Response.prototype, "isUnauthorized", {
get: function () { return this.httpStatus === 401; },
enumerable: true,
configurable: true
});
Object.defineProperty(Response.prototype, "isForbidden", {
get: function () { return this.httpStatus === 403; },
enumerable: true,
configurable: true
});
Object.defineProperty(Response.prototype, "isEmpty", {
get: function () { return this.httpStatus === 0; },
enumerable: true,
configurable: true
});
Object.defineProperty(Response.prototype, "isNotFound", {
get: function () { return this.httpStatus === 404; },
enumerable: true,
configurable: true
});
return Response;
}());
exports.Response = Response;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var models_1 = require("../models");
/**
* Robot process model containing details of the robot process available in current system
*/
var RobotProcess = /** @class */ (function () {
/**
* Default constructor
* @param id Unique id of the robot process
* @param name Robot Process name
*/
function RobotProcess(id, name) {
var _this = this;
this.id = id;
this.name = name;
/**
* Start the robot process
* @param inArguments JSON object. In arguments to be passed to the robot if any.
*/
this.start = function (inArguments) { return new models_1.JobPromise(new models_1.Job(_this.id, inArguments)); };
}
return RobotProcess;
}());
exports.RobotProcess = RobotProcess;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Settings class used to change default settings of Js SDK
*/
var Settings = /** @class */ (function () {
/**
* Default constructor
* @param portNumber Port number of the Http listener
* @param pollTimeInterval Poll interval time.
*/
function Settings(portNumber, pollTimeInterval, disableTelemetry) {
this.portNumber = portNumber;
this.pollTimeInterval = pollTimeInterval;
this.disableTelemetry = disableTelemetry;
this.appOrigin = window.location.origin;
}
return Settings;
}());
exports.Settings = Settings;
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./invokeRobotRequest"));
__export(require("./jobStatusRequest"));
__export(require("./portRequest"));
__export(require("./robotProcessRequest"));
__export(require("./stopProcessRequest"));
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var index_1 = require("../../models/index");
var utils_1 = require("../../utils");
var constants_1 = require("../../utils/constants");
/**
* Request class to invoke any robot from local system.
*/
var InvokeRobotRequest = /** @class */ (function () {
/**
* Default constructor.
* @param robotProcessId PackageId of the robot to run.
* @param data Data to be passed as in arguments to robot process on start. Optional parameter.
*/
function InvokeRobotRequest(robotProcessId, data) {
var _this = this;
this.robotProcessId = robotProcessId;
this.data = data;
/**
* Method that sends the request to invoke a robot.
* @returns Promise of Response model type.
*/
this.send = function () { return utils_1.HttpUtil.post(_this.url, _this.convertToJob, _this.data); };
this.url = '';
}
/**
* Set the port to which the request should be sent along with the consent code.
* @param robotInvocationPort Port on which local listener is running.
* @param consentCode User consented code.
*/
InvokeRobotRequest.prototype.set = function (robotInvocationPort, consentCode) {
this.url = this.getURL(robotInvocationPort, consentCode);
return this;
};
/**
* Mapper method used to convert string response to desired Job model.
* @param data HttpResponse data sent from listener.
* @returns Job to uniquely identify this robot process execution.
*/
InvokeRobotRequest.prototype.convertToJob = function (data) {
var job = new index_1.Job('');
if (data) {
var jsonResponse = JSON.parse(data).response;
if (jsonResponse && jsonResponse.JobId) {
job.jobId = jsonResponse.JobId;
}
}
return job;
};
/**
* Method that returns the request endpoint to which request will be sent.
* @param robotInvocationPort Port of local listener to which request should be sent.
* @param consentCode User approved consent code if any.
*/
InvokeRobotRequest.prototype.getURL = function (robotInvocationPort, consentCode) {
var url = constants_1.Constants.DEFAULT_ROBOT_INVOKE_DOMAIN + ":" + robotInvocationPort + "/" + constants_1.Constants.INVOKE_ROBOT + "?robotProcessId=" + this.robotProcessId;
return utils_1.UrlUtil.appendConsentCode(url, consentCode);
};
return InvokeRobotRequest;
}());
exports.InvokeRobotRequest = InvokeRobotRequest;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var jobState_1 = require("../../enums/jobState");
var index_1 = require("../../models/index");
var constants_1 = require("../../utils/constants");
var httpUtil_1 = require("../../utils/httpUtil");
var urlUtil_1 = require("../../utils/urlUtil");
/**
* Request class to get status of any running/completed job.
*/
var JobStatusRequest = /** @class */ (function () {
/**
* Default constructor.
* @param job Job object whose status we want to request
*/
function JobStatusRequest(job) {
var _this = this;
this.job = job;
/**
* Method that sends the request to get status of running/completed job.
* @returns Promise of Response model type.
*/
this.send = function () { return httpUtil_1.HttpUtil.get(_this.url, _this.convertToJobStatus); };
/**
* Method that returns the request endpoint to which request will be sent.
* @param robotInvocationPort Port of local listener to which request should be sent.
* @param consentCode User approved consent code if any.
* @param job Job for which the result is to be found.
*/
this.getURL = function (robotInvocationPort, consentCode, job) {
var url = constants_1.Constants.DEFAULT_ROBOT_INVOKE_DOMAIN + ":" + robotInvocationPort + "/" + constants_1.Constants.GET_JOB_STATUS + "?jobId=" + job.jobId;
return urlUtil_1.UrlUtil.appendConsentCode(url, consentCode);
};
this.url = '';
}
/**
* Set the port to which the request should be sent along with the consent code.
* @param robotInvocationPort Port on which local listener is running.
* @param consentCode User consented code.
*/
JobStatusRequest.prototype.set = function (robotInvocationPort, consentCode) {
this.url = this.getURL(robotInvocationPort, consentCode, this.job);
return this;
};
/**
* Mapper method used to convert string response to desired Job status model.
* @param data HttpResponse sent from listener.
* @returns Job result of the completed/errored job.
*/
JobStatusRequest.prototype.convertToJobStatus = function (data) {
if (data) {
var jsonResponse = JSON.parse(data).response;
if (jsonResponse) {
return new index_1.JobStatus(jobState_1.JobState[jsonResponse.State], jsonResponse.Status, jsonResponse.Output, jsonResponse.Error);
}
}
return new index_1.JobStatus('', [], undefined, undefined);
};
return JobStatusRequest;
}());
exports.JobStatusRequest = JobStatusRequest;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var utils_1 = require("../../utils");
var constants_1 = require("../../utils/constants");
/**
* Request class to get port of listener running on local user session.
*/
var PortRequest = /** @class */ (function () {
/**
* Default constructor
* @param listenerPort Port of listener running on session 0.
* @param consentCode User approved consent code if any.
*/
function PortRequest(listenerPort, consentCode) {
var _this = this;
/**
* Method that sends the request to get port of listener running on local user session.
* @returns Promise of Response model type.
*/
this.getPort = function () { return utils_1.HttpUtil.get(_this.url, _this.convertToPort); };
/**
* Mapper method used to convert string response to number.
* @param response HttpResponse sent from listener.
* @returns Port number.
*/
this.convertToPort = function (response) {
if (response) {
var portResponse = JSON.parse(response);
return portResponse.Port;
}
return 0;
};
/**
* Method that sets the request endpoint to which request will be sent.
* @param listenerEndpoint Endpoint to which request will be sent
* @param consentCode randomly generated consent code.
*/
this.setURL = function (listenerEndpoint, consentCode) { return utils_1.UrlUtil.appendConsentCode(listenerEndpoint + "/" + constants_1.Constants.GET_PORT, consentCode); };
var listenerEndpoint = constants_1.Constants.DEFAULT_PORT_DISCOVERY_DOMAIN + ":" + listenerPort;
this.url = this.setURL(listenerEndpoint, consentCode);
}
return PortRequest;
}());
exports.PortRequest = PortRequest;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var models_1 = require("../../models");
var utils_1 = require("../../utils");
var constants_1 = require("../../utils/constants");
var RobotProcessRequest = /** @class */ (function () {
/**
* Default constructor
*/
function RobotProcessRequest() {
var _this = this;
/**
* Request method to get all published robots in local machine.
* @returns Promise of type Response.
*/
this.send = function () { return utils_1.HttpUtil.get(_this.url, _this.convertToRobotProcesses); };
/**
* Set the port to which the request should be sent along with the consent code.
* @param robotInvocationPort Port on which local listener is running.
* @param consentCode User consented code.
*/
this.set = function (robotInvocationPort, consentCode) {
_this.url = _this.getURL(robotInvocationPort, consentCode);
return _this;
};
this.convertToRobotProcesses = function (httpResponse) {
if (httpResponse) {
var jsonResponse = JSON.parse(httpResponse).response;
if (jsonResponse && jsonResponse.length) {
return jsonResponse.map(function (r) { return new models_1.RobotProcess(r.Key, r.Name); });
}
}
return [];
};
this.url = '';
}
/**
* Method that returns the request endpoint to which request will be sent.
* @param robotInvocationPort Port of local listener to which request should be sent.
* @param consentCode User approved consent code if any.
*/
RobotProcessRequest.prototype.getURL = function (robotInvocationPort, consentCode) {
var url = constants_1.Constants.DEFAULT_ROBOT_INVOKE_DOMAIN + ":" + robotInvocationPort + "/" + constants_1.Constants.GET_ROBOT_PROCESSES;
return utils_1.UrlUtil.appendConsentCode(url, consentCode);
};
return RobotProcessRequest;
}());
exports.RobotProcessRequest = RobotProcessRequest;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var constants_1 = require("../../utils/constants");
var httpUtil_1 = require("../../utils/httpUtil");
var urlUtil_1 = require("../../utils/urlUtil");
/**
* Request class to cancel a running job.
*/
var StopProcessRequest = /** @class */ (function () {
/**
* Default constructor.
* @param job Job object whose status we want to request
*/
function StopProcessRequest(process) {
var _this = this;
this.process = process;
/**
* Method that sends the request to cancel running job.
* @returns Promise of Response model type.
*/
this.send = function () { return httpUtil_1.HttpUtil.get(_this.url, _this.convert); };
this.convert = function (data) { return ''; };
/**
* Method that returns the request endpoint to which request will be sent.
* @param robotInvocationPort Port of local listener to which request should be sent.
* @param consentCode User approved consent code if any.
* @param process Robot Process to stop
*/
this.getURL = function (robotInvocationPort, consentCode, process) {
var url = constants_1.Constants.DEFAULT_ROBOT_INVOKE_DOMAIN + ":" + robotInvocationPort + "/" + constants_1.Constants.STOP_PROCESS + "?robotProcessId=" + process.id;
return urlUtil_1.UrlUtil.appendConsentCode(url, consentCode);
};
this.url = '';
}
/**
* Set the port to which the request should be sent along with the consent code.
* @param robotInvocationPort Port on which local listener is running.
* @param consentCode User consented code.
*/
StopProcessRequest.prototype.set = function (robotInvocationPort, consentCode) {
this.url = this.getURL(robotInvocationPort, consentCode, this.process);
return this;
};
return StopProcessRequest;
}());
exports.StopProcessRequest = StopProcessRequest;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var traceEvent_1 = require("../enums/traceEvent");
var language_1 = require("../locale/language");
var models_1 = require("../models");
var implementation_1 = require("../requests/implementation");
var utils_1 = require("../utils");
var constants_1 = require("../utils/constants");
var appinsightsLogger_1 = require("../utils/logger/appinsightsLogger");
/**
* Robot SDK class
*/
var RobotSDK = /** @class */ (function () {
function RobotSDK() {
var _this = this;
/**
* Method to attach event handlers on the SDK.
* @param eventName Available SDK events are 'consent-prompt', 'missing-components'.
* @param eventHanlder Event handler callback function called when event occurs.
*/
this.on = function (eventName, eventHanlder) {
switch (eventName) {
case constants_1.Constants.CONSENT_PROMPT: {
_this.eventHandlers.on(constants_1.Constants.CONSENT_PROMPT, eventHanlder);
break;
}
case constants_1.Constants.MISSING_COMPONENTS: {
_this.eventHandlers.on(constants_1.Constants.MISSING_COMPONENTS, eventHanlder);
break;
}
default: {
_this.trace(traceEvent_1.TraceEvent.Invalid_Event, {});
break;
}
}
};
/**
* Init method set custom consent code handling.
* @returns {IRobotSDK} implemented instance
*/
this.init = function () {
_this.trace(traceEvent_1.TraceEvent.Init, {});
return _this;
};
/**
* Method to retrieve all published robot processes on users local machine.
* @returns Deferred promise of type RobotProcess[] which will be resolved/rejected based on http response.
*/
this.getProcesses = function () {
_this.trace(traceEvent_1.TraceEvent.Get_Processes, {});
var deferredPromise = new utils_1.Deferred();
try {
_this.sendRequest(new implementation_1.RobotProcessRequest(), deferredPromise);
}
catch (error) {
deferredPromise.reject(error);
_this.traceError(traceEvent_1.TraceEvent.Get_Processes, error);
}
return deferredPromise.promise;
};
/**
* Method to invoke a robot process.
* @param job Job object containing all information about the robot process to run.
* @returns Deferred promise which is resolved with job result when robot process completes.
*/
this.startJob = function (job) { return __awaiter(_this, void 0, void 0, function () {
var deferredPromise, jobResponse;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.trace(traceEvent_1.TraceEvent.Run_Robot, {});
deferredPromise = new utils_1.Deferred();
return [4 /*yield*/, this.startRobot(job.processId, job.argument)];
case 1:
jobResponse = _a.sent();
job.jobId = jobResponse.jobId;
this.jobStatusPoll(job, deferredPromise);
return [2 /*return*/, deferredPromise.promise];
}
});
}); };
/**
* Method to stop a robot process job.
* @param job Job object containing all information about the robot process run to cancel.
* @returns Deferred promise which is resolved with job result when robot process is cancelled.
*/
this.stopProcess = function (process) { return __awaiter(_this, void 0, void 0, function () {
var deferredPromise, response, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.trace(traceEvent_1.TraceEvent.Stop_Process, {});
deferredPromise = new utils_1.Deferred();
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, new implementation_1.StopProcessRequest(process).set(this.robotInvocationPort, this.consentCode).send()];
case 2:
response = _a.sent();
if (response.isSuccess) {
deferredPromise.resolve();
}
else {
throw response.isEmpty ? "426 - " + language_1.Language.GetResource().api_not_found : response.error;
}
return [3 /*break*/, 4];
case 3:
error_1 = _a.sent();
deferredPromise.reject(error_1);
this.traceError(traceEvent_1.TraceEvent.Stop_Process, error_1);
return [3 /*break*/, 4];
case 4: return [2 /*return*/, deferredPromise.promise];
}
});
}); };
/**
* Method to invoke a robot on the local user machine.
* @param robotProcessId Robot package id to uniquely identify robots present on local user machine.
* @param data In arguments to be passed to the robot if any.
* @returns Deferred promise of type job which will be resolved/rejected based on http response.
*/
this.startRobot = function (robotProcessId, data) { return __awaiter(_this, void 0, void 0, function () {
var deferredPromise;
return __generator(this, function (_a) {
if (data) {
data = JSON.stringify(data);
}
deferredPromise = new utils_1.Deferred();
try {
this.sendRequest(new implementation_1.InvokeRobotRequest(robotProcessId, data), deferredPromise);
}
catch (error) {
deferredPromise.reject(error);
}
return [2 /*return*/, deferredPromise.promise];
});
}); };
/**
* Finds port of local listener and sends request. Requests user consent if required.
* @param request IRequest to send.
* @param deferredPromise Promise to resolve on completion of request.
*/
this.sendRequest = function (request, deferredPromise) { return __awaiter(_this, void 0, void 0, function () {
var response, error_2;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 6, , 7]);
return [4 /*yield*/, this.initializePort()];
case 1:
_a.sent();
return [4 /*yield*/, request.set(this.robotInvocationPort, this.consentCode).send()];
case 2:
response = _a.sent();
if (!response.isUnauthorized) return [3 /*break*/, 4];
return [4 /*yield*/, this.resendAfterConsent(request)];
case 3:
response = _a.sent();
return [3 /*break*/, 5];
case 4:
if (response.isEmpty) {
this.showMissingComponents();
}
_a.label = 5;
case 5:
response.resolve(deferredPromise);
return [3 /*break*/, 7];
case 6:
error_2 = _a.sent();
deferredPromise.reject(error_2);
return [3 /*break*/, 7];
case 7: return [2 /*return*/];
}
});
}); };
/**
* Initialize method that initializes listener port running on local session.
* @returns Promise.
*/
this.initializePort = function () { return __awaiter(_this, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
if (!(this.robotInvocationPort === 0)) return [3 /*break*/, 2];
this.consentCode = 0;
_a = this;
return [4 /*yield*/, this.getPort()];
case 1:
_a.robotInvocationPort = _b.sent();
_b.label = 2;
case 2: return [2 /*return*/];
}
});
}); };
/**
* Method to find the port on which local listener is running.
* @returns Deferred promise of type number which will be resolved/rejected based on http response.
*/
this.getPort = function () { return __awaiter(_this, void 0, void 0, function () {
var deferredPromise, request, response, result, error_3;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
deferredPromise = new utils_1.Deferred();
_a.label = 1;
case 1:
_a.trys.push([1, 6, , 7]);
request = new implementation_1.PortRequest(this.settings.portNumber, this.consentCode);
return [4 /*yield*/, request.getPort()];
case 2:
response = _a.sent();
if (!(response.isUnauthorized && this.consentCode === 0)) return [3 /*break*/, 4];
return [4 /*yield*/, this.askForConsent()];
case 3:
result = _a.sent();
deferredPromise.resolve(result);
return [3 /*break*/, 5];
case 4:
if (response.isEmpty) {
this.showMissingComponents();
deferredPromise.reject(new Error('500 - Robot Service down'));
}
else {
response.resolve(deferredPromise);
}
_a.label = 5;
case 5: return [3 /*break*/, 7];
case 6:
error_3 = _a.sent();
this.traceError(traceEvent_1.TraceEvent.Get_Port, error_3);
deferredPromise.reject(error_3);
return [3 /*break*/, 7];
case 7: return [2 /*return*/, deferredPromise.promise];
}
});
}); };
/**
* Generates a random number which will be passed to protocol handler and shown to user to approve as consent.
* Polls for 60 seconds to determine if user has consented.
*/
this.askForConsent = function () {
var deferredPromise = new utils_1.Deferred();
_this.consentCode = utils_1.RandomUtil.getRandomNumber();
utils_1.ProtocolUtil.openUiPathProtocol(_this.consentCode);
_this.showConsentCode(_this.consentCode);
_this.pollForApprovedConsent(_this.getPort)
.then(function (response) {
utils_1.HtmlUtil.hideConsentOverlay();
deferredPromise.resolve(response);
})
.catch(function (error) {
utils_1.HtmlUtil.hideConsentOverlay();
deferredPromise.reject(error);
_this.traceError(traceEvent_1.TraceEvent.Consent_Timeout, error);
});
_this.trace(traceEvent_1.TraceEvent.User_Consent_Raised, {});
return deferredPromise.promise;
};
/**
* Polls the given function for 1 min until success.
* @param fn Function to poll.
*/
this.pollForApprovedConsent = function (fn) { return utils_1.PollUtil.poll(fn, constants_1.Constants.POLL_TIMEOUT, constants_1.Constants.POLL_TIMEINTERVAL); };
/**
* Makes request after user consents access.
* @param request IRequest to send.
*/
this.resendAfterConsent = function (request) { return __awaiter(_this, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = this;
return [4 /*yield*/, this.askForConsent()];
case 1:
_a.robotInvocationPort = _b.sent();
return [2 /*return*/, request.set(this.robotInvocationPort, this.consentCode).send()];
}
});
}); };
/**
* Polls recursively until completion of currently running robot process job.
* @param job Job that is currently running.
* @param statusChangeCallback callback method to call if job status has changed
* @param deferredPromise Promise to resolve/reject once job completes.
*/
this.jobStatusPoll = function (job, deferredPromise) { return __awaiter(_this, void 0, void 0, function () {
var jobResponse, error_4;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, this.getJobStatus(job)];
case 1:
jobResponse = _a.sent();
jobResponse.status.forEach(function (value) { return job.dispatch(value); });
if (jobResponse.isExecuting) {
setTimeout(function () { return _this.jobStatusPoll(job, deferredPromise); }, this.settings.pollTimeInterval);
}
else if (jobResponse.isClosed) {
deferredPromise.resolve(jobResponse.output.Arguments);
}
else {
deferredPromise.reject(jobResponse.errorResponse);
}
return [3 /*break*/, 3];
case 2:
error_4 = _a.sent();
deferredPromise.reject(error_4);
this.traceError(traceEvent_1.TraceEvent.Job_Status_Poll, error_4);
return [3 /*break*/, 3];
case 3: return [2 /*return*/];
}
});
}); };
/**
* Method to get job status of any running/completed job.
* @param job Job object for which status needs to be found.
* @returns Deferred promise of type JobResult which will be resolved/rejected based on http response.
*/
this.getJobStatus = function (job) { return __awaiter(_this, void 0, void 0, function () {
var response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, new implementation_1.JobStatusRequest(job).set(this.robotInvocationPort, this.consentCode).send()];
case 1:
response = _a.sent();
if (response.isSuccess && response.data) {
return [2 /*return*/, response.data];
}
else {
throw new Error("500 - " + language_1.Language.GetResource().job_status_error);
}
return [2 /*return*/];
}
});
}); };
/**
* Calls consent-prompt event handler or shows SDK consent overlay
* @param consentCode Randomly generated consent code
*/
this.showConsentCode = function (consentCode) {
if (_this.eventHandlers.has(constants_1.Constants.CONSENT_PROMPT)) {
_this.eventHandlers.dispatch(constants_1.Constants.CONSENT_PROMPT, consentCode);
}
else {
utils_1.HtmlUtil.showConsentOverlay(consentCode, _this.settings.portNumber);
}
};
/**
* Calls 'missing-components' event handler or shows SDK error overlay
*/
this.showMissingComponents = function () {
if (_this.eventHandlers.has(constants_1.Constants.MISSING_COMPONENTS)) {
_this.eventHandlers.dispatch(constants_1.Constants.MISSING_COMPONENTS);
}
else {
utils_1.HtmlUtil.showErrorOverlay();
}
_this.trace(traceEvent_1.TraceEvent.Missing_Components, {});
};
this.trace = function (event, properties) {
if (!_this.settings.disableTelemetry) {
_this.logger.trace(event, properties, _this.settings.appOrigin);
}
};
this.traceError = function (event, properties) {
if (!_this.settings.disableTelemetry) {
_this.logger.traceError(event, properties, _this.settings.appOrigin);
}
};
this.robotInvocationPort = 0;
this.consentCode = 0;
this.settings = new models_1.Settings(constants_1.Constants.DEFAULT_PORT, constants_1.Constants.POLL_TIMEINTERVAL, false);
this.eventHandlers = new utils_1.Dispatcher();
this.logger = new appinsightsLogger_1.AppInsightsLogger();
}
return RobotSDK;
}());
var robotSDK = new RobotSDK();
/**
* Class to restrict exposing other private methods in RobotSDK object.
*/
var SDK = /** @class */ (function () {
function SDK() {
var _this = this;
/**
* Init method set custom consent code handling.
* @returns {IRobotSDK} instance
*/
this.init = function () { return _this; };
/**
* Method to retrieve all published robot processes on users local machine.
* @returns Deferred promise of type RobotProcess[] which will be resolved/rejected based on http response.
*/
this.getProcesses = function () { return robotSDK.getProcesses(); };
/**
* Method to attach event handlers on the SDK.
* @param eventName Available SDK events are 'consent-prompt', 'missing-components'.
* @param eventHanlder Event handler callback function called when event occurs.
*/
this.on = function (eventName, eventHanlder) { return robotSDK.on(eventName, eventHanlder); };
/**
* Method to invoke a robot process.
* @param job Job object containing all information about the robot process to run.
* @returns Deferred promise which is resolved with job result when robot process completes.
*/
this.startJob = function (job) { return robotSDK.startJob(job); };
/**
* Method to stop an executing/running robot process.
* @param process RobotProcess object containing all information about the robot process to stop.
* @returns Deferred promise which is resolved with job result when robot process is cancelled.
*/
this.stopProcess = function (process) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, robotSDK.stopProcess(process)];
}); }); };
}
Object.defineProperty(SDK.prototype, "settings", {
/**
* SDK settings
*/
get: function () {
return robotSDK.settings;
},
enumerable: true,
configurable: true
});
return SDK;
}());
exports.SDK = SDK;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var traceEvent_1 = require("./enums/traceEvent");
var robotSDK_1 = require("./sdk/robotSDK");
var appinsightsLogger_1 = require("./utils/logger/appinsightsLogger");
/**
* Browser invocation javascript SDK module. Accessible as UiPathRobot from browser console.
*/
var UiPathRobot;
(function (UiPathRobot) {
var robotSDK = new robotSDK_1.SDK();
/**
* Settings object to change default SDK settings
* @returns {Settings}
*/
UiPathRobot.settings = robotSDK.settings;
/**
* On page load analytics
*/
document.addEventListener('readystatechange', function () {
if (document.readyState === 'complete') {
var logger = new appinsightsLogger_1.AppInsightsLogger();
if (!UiPathRobot.settings.disableTelemetry) {
logger.tracePage();
logger.trace(traceEvent_1.TraceEvent.SDK_Loaded, {}, robotSDK.settings.appOrigin);
}
}
});
/**
* Init method set custom consent code handling.
* @returns {IRobotSDK} instance
*/
UiPathRobot.init = function () { return robotSDK.init(); };
/**
* Method to retrieve all published robot processes on users local machine.
* @returns Deferred promise of type RobotProcess[] which will be resolved/rejected based on http response.
*/
UiPathRobot.getProcesses = function () { return robotSDK.getProcesses(); };
/**
* Method to attach event handlers on the SDK.
* @param eventName Available SDK events are 'consent-prompt', 'missing-components'.
* @param eventHanlder Event handler callback function called when event occurs.
*/
UiPathRobot.on = function (eventName, eventHanlder) { return robotSDK.on(eventName, eventHanlder); };
/**
* Method to invoke a robot process.
* @param job Job object containing all information about the robot process to run.
* @returns Deferred promise which is resolved with job result when robot process completes.
*/
UiPathRobot.startJob = function (job) { return robotSDK.startJob(job); };
/**
* Method to stop a robot process.
* @param process Robotprocess object containing all information about the robot process to cancel.
* @returns Deferred promise which is resolved when robot process is cancelled.
*/
UiPathRobot.stopProcess = function (process) { return robotSDK.stopProcess(process); };
})(UiPathRobot = exports.UiPathRobot || (exports.UiPathRobot = {}));
window.UiPathRobot = UiPathRobot;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Constants = /** @class */ (function () {
function Constants() {
}
Constants.GET_PORT = 'GetPort';
Constants.GET_ROBOT_PROCESSES = 'RobotProcesses';
Constants.GET_JOB_STATUS = 'JobStatus';
Constants.INVOKE_ROBOT = 'InvokeRobot';
Constants.UIPATH_EDITION = 'UiPathEdition';
Constants.DEFAULT_ROBOT_INVOKE_DOMAIN = 'http://localhost';
Constants.DEFAULT_PORT_DISCOVERY_DOMAIN = 'http://localhost';
Constants.DEFAULT_PORT = 2323;
Constants.UIPATH_PROTOCOL = 'uipath-web';
Constants.POLL_TIMEOUT = 60000;
Constants.POLL_TIMEINTERVAL = 250;
Constants.HTTP_UNAUTHORIZED = 401;
Constants.UIPATH_CONSENTOVERLAY_ID = 'uipathConsentOverlay';
Constants.UIPATH_CONSENTDIALOG_ID = 'uipathConsentFrame';
Constants.CONSENT_PROMPT = 'consent-prompt';
Constants.MISSING_COMPONENTS = 'missing-components';
Constants.STATUS = 'status';
Constants.UIPATH_TOKEN = 'uipathToken';
Constants.STOP_PROCESS = 'StopProcess';
return Constants;
}());
exports.Constants = Constants;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Deferred promise class.
*/
var Deferred = /** @class */ (function () {
function Deferred() {
var _this = this;
this.resolve = function (value) { return _this._resolve(value); };
this.reject = function (reason) { return _this._reject(reason); };
this._promise = new Promise(function (resolve, reject) {
_this._resolve = resolve;
_this._reject = reject;
});
}
Object.defineProperty(Deferred.prototype, "promise", {
get: function () {
return this._promise;
},
enumerable: true,
configurable: true
});
return Deferred;
}());
exports.Deferred = Deferred;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Dispatcher class to allow event handling on custom classes.
*/
var Dispatcher = /** @class */ (function () {
function Dispatcher() {
var _this = this;
/**
* Method to determine if a certain event has been registered.
* @returns Boolean result
*/
this.has = function (eventName) { return _this.dispatchHandlers.has(eventName); };
this.dispatchHandlers = new Map();
}
/**
* Event registration method.
* @param eventName Name of the event to register.
* @param handler callback function to call when the event occurs.
*/
Dispatcher.prototype.on = function (eventName, handler) {
var allHandlers = this.dispatchHandlers.get(eventName);
if (allHandlers && this.dispatchHandlers.has(eventName)) {
allHandlers.push(handler);
}
else {
this.dispatchHandlers.set(eventName, [handler]);
}
};
/**
* Dispatch method to dispatch registered callbacks on the occuring event.
* @param eventName Name of the event that has occured.
* @param argument Arguments to pass to callback if any.
*/
Dispatcher.prototype.dispatch = function (eventName, argument) {
var _this = this;
var allHandlers = this.dispatchHandlers.get(eventName);
if (allHandlers && this.dispatchHandlers.has(eventName)) {
allHandlers.forEach(function (handler) {
handler.apply(_this, [argument]);
});
}
};
return Dispatcher;
}());
exports.Dispatcher = Dispatcher;

Sorry, the diff of this file is too big to display

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* XMLHttpRequest module used to send Http requests to listeners.
*/
var models_1 = require("../models");
var constants_1 = require("../utils/constants");
var HttpUtil = /** @class */ (function () {
function HttpUtil() {
}
/**
* HttpGet method.
* @param url Endpoint to hit.
* @param transform Method to transform http response string to desired object.
*/
HttpUtil.get = function (url, transform) {
return HttpUtil.httpRequest(url, transform, 'GET');
};
/**
* HttpPost method.
* @param url Endpoint to hit.
* @param transform Method to transform http response string to desired object.
* @param data Data to post.
*/
HttpUtil.post = function (url, transform, data) {
return HttpUtil.httpRequest(url, transform, 'POST', data);
};
HttpUtil.httpRequest = function (url, transform, method, data) {
var _this = this;
var request = new XMLHttpRequest();
return new Promise(function (resolve, reject) {
request.onreadystatechange = function () {
if (request.readyState !== 4) {
return;
}
resolve(new models_1.Response(request.status, request.statusText, transform(this.response), HttpUtil.errorResponse(this.response)));
HttpUtil.persistTokentoLocalStorage(request);
};
request.onerror = function () {
reject(new models_1.Response(request.status, request.statusText));
HttpUtil.persistTokentoLocalStorage(request);
};
request.open(method, url, true);
request.withCredentials = true;
_this.addTokenToHeader(request);
if (data) {
request.send(data);
}
else {
request.send();
}
});
};
/**
* Converts response data into error model if the call failed safely.
* @param httpResponse response data
*/
HttpUtil.errorResponse = function (httpResponse) {
if (httpResponse) {
var jsonResponse = JSON.parse(httpResponse).response;
if (jsonResponse && jsonResponse.Error) {
return jsonResponse.Error;
}
}
return '';
};
/**
* Checks for existing token in local storage and adds it to outgoing request headers.
* @param request The request to which the token will be added as header.
*/
HttpUtil.addTokenToHeader = function (request) {
var token = window.localStorage.getItem(constants_1.Constants.UIPATH_TOKEN);
if (token) {
request.setRequestHeader(constants_1.Constants.UIPATH_TOKEN, token);
}
};
/**
* Reads all response headers if token is present, sets token to local storage.
* @param request request containing the response headers.
*/
HttpUtil.persistTokentoLocalStorage = function (request) {
var allHeaders = request.getAllResponseHeaders();
if (allHeaders.indexOf(constants_1.Constants.UIPATH_TOKEN)) {
var token = request.getResponseHeader(constants_1.Constants.UIPATH_TOKEN);
if (token) {
window.localStorage.removeItem(constants_1.Constants.UIPATH_TOKEN);
window.localStorage.setItem(constants_1.Constants.UIPATH_TOKEN, token);
}
}
};
return HttpUtil;
}());
exports.HttpUtil = HttpUtil;
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./deferred"));
__export(require("./dispatcher"));
__export(require("./htmlUtil"));
__export(require("./httpUtil"));
__export(require("./pollUtil"));
__export(require("./protocolUtil"));
__export(require("./randomUtil"));
__export(require("./urlUtil"));
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var applicationinsights_web_1 = require("@microsoft/applicationinsights-web");
/**
* Appinsights logger. Stops logging for locally hosted files as file path might contain user info.
*/
var AppInsightsLogger = /** @class */ (function () {
function AppInsightsLogger() {
var _this = this;
this.appInsights = new applicationinsights_web_1.ApplicationInsights({
config: {
instrumentationKey: process.env.NODE_ENV === 'production' ? '025bfd02-04e8-4969-8293-94a1ec738e4e' : '45d1ba3e-f027-4fb0-a1cc-d6874a40ec00',
},
});
/**
* Trace event method
* @param event event name
* @param properties properties to log along with the event.
*/
this.trace = function (event, properties, appName) {
if (window.location.protocol !== 'file:') {
_this.appInsights.trackEvent({ name: event.toString(), properties: { application: appName } }, properties);
}
};
/**
* Tracing error
* @param event event name
* @param error Error to trace.
*/
this.traceError = function (event, error, appName) {
if (window.location.protocol !== 'file:') {
_this.appInsights.trackException({
properties: { method: event.toString(), application: appName },
exception: new Error(error),
});
}
};
/**
* Tracing page
*/
this.tracePage = function () {
if (window.location.protocol !== 'file:') {
_this.appInsights.trackPageView();
}
};
if (window.location.protocol !== 'file:') {
this.appInsights.loadAppInsights();
}
}
return AppInsightsLogger;
}());
exports.AppInsightsLogger = AppInsightsLogger;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var language_1 = require("../locale/language");
/**
* Poll a particular function until a specified interval/timeout.
*/
var PollUtil = /** @class */ (function () {
function PollUtil() {
}
/**
* Method used for polling.
* @param fn Function that needs to be polled.
* @param timeout Time after which the polling will stop.
* @param interval Time difference between calls while polling.
*/
PollUtil.poll = function (fn, timeout, interval) {
var endTime = Number(new Date()) + (timeout || 2000);
interval = interval || 1000;
var checkCondition = function (resolve, reject) {
fn()
.then(function (response) {
resolve(response);
})
.catch(function (error) {
var message = error.message;
if (message && message.indexOf('403') > -1) {
reject(new Error("403 - " + language_1.Language.GetResource().consent_rejected));
}
else if (Number(new Date()) < endTime) {
setTimeout(checkCondition, interval, resolve, reject);
}
else {
reject(new Error("408 - " + language_1.Language.GetResource().timed_out));
}
});
};
return new Promise(checkCondition);
};
return PollUtil;
}());
exports.PollUtil = PollUtil;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var constants_1 = require("./constants");
/**
* Protocol util to open consent window application
*/
var ProtocolUtil = /** @class */ (function () {
function ProtocolUtil() {
}
ProtocolUtil.openUiPathProtocol = function (consentCode) {
var url = constants_1.Constants.UIPATH_PROTOCOL + "://consentCode=" + consentCode + "&Origin=" + window.location.origin;
window.location.href = url;
};
return ProtocolUtil;
}());
exports.ProtocolUtil = ProtocolUtil;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Module to generate a random number.
*/
var RandomUtil = /** @class */ (function () {
function RandomUtil() {
}
/**
* Function to generate a random number. Range if not specified is capped between 100001-999999.
* @param min Min value (included) which the random number can take.
* @param max Max value (included) which the random number can take.
*/
RandomUtil.getRandomNumber = function (min, max) {
min = min || 100001;
max = max || 999999;
return Math.floor(Math.random() * (max - min + 1)) + min;
};
return RandomUtil;
}());
exports.RandomUtil = RandomUtil;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Url utility that adds consent code to url as query parameter.
*/
var UrlUtil = /** @class */ (function () {
function UrlUtil() {
}
/**
* Method that adds consent code to url as query parameter if needed.
* @param url URL to which the consent code query parameter needs to be appended.
* @param consentCode consent code that was randomly generated.
*/
UrlUtil.appendConsentCode = function (url, consentCode) {
return consentCode !== 0 ?
url.indexOf('?') > 0 ? url + "&consentCode=" + consentCode : url + "?consentCode=" + consentCode :
url;
};
return UrlUtil;
}());
exports.UrlUtil = UrlUtil;

Sorry, the diff of this file is too big to display