1
votes

I played around with UiPath Orchestrator package. And the connection worked out with the installed node.js package.

Anyway now I need to implement it in my website in a way where I get access it from a simple html site.

There I struggle a bit with getting it to run. This is how I would like to use it:

index.html:

<html>
  ...
  <button onclick="test()">Do something</button>  
  ...
  <script src="scripts.js"></script>
  ...
</html>

server.js: (I start with node server.js)

var http = require('http'),
    fs = require('fs');
const port = 6543;
const path = require('path');
const server = http.createServer((req, res) => {
  let filePath = path.join(
      __dirname,
      req.url === "/" ? "index.html" : req.url
  );
  let extName = path.extname(filePath);
  let contentType = 'text/html';
  switch (extName) {
      case '.js':
          contentType = 'text/javascript';
          break;
  }
  console.log(`File path: ${filePath}`);
  console.log(`Content-Type: ${contentType}`);
  res.writeHead(200, {'Content-Type': contentType});
  const readStream = fs.createReadStream(filePath);
  readStream.pipe(res);
});
server.listen(port, (err) => {
...
});

scripts.js:

function test() {
  ...
  // get the orch object here without defining it here as it contains credentials
  var orchestratorInstance = new Orchestrator({
    tenancyName: string (optional),
    usernameOrEmailAddress: string (required),
    password: string (required),
    hostname: string (required),
    isSecure: boolean (optional, default=true),
    port: integer (optional, [1..65535], default={443,80} depending on isSecure),
    invalidCertificate: boolean (optional, default=false),
    connectionPool: number (optional, 0=unlimited, default=1)
  });
}

This works. So the test function is fired.

But now I would like to get the Orchestrator object (like shown here https://www.npmjs.com/package/uipath-orchestrator).

How to do it in the best way?

Maybe just pass-through that object to the scripts.js file itself? But how to do that with window or global and would that be a proper solution?

I need the server-side generated object as it contains credentials that may not be delivered to client-side.

2
You could embed your node generated javascript into a script file of the html. - Steve Tomlin
And how to do that with the object? Some example code? - kwoxer

2 Answers

1
votes

A crude example, but to give an idea, of embedding a script file into html. Ideally you'd use express to load a webpage, but this is purely to describe usecase.

You could do the same with an end body tag, or end head tag.

const http = require('http'),
const fs = require('fs');

const html = fs.readFileSync('./file.html'); 
const obj = fs.readFileSync('./script.js'); 

const htmlWithScript = html.replace(/\<\/html\s*\>/,`<script>${obj}</script></html>`);
// const htmlWithScript = `<html><head><script>${obj}</script></head><body> my html stuff ...</body></html>`

http.createServer(function(request, response) {  
        response.writeHeader(200, {"Content-Type": "text/html"});  
        response.write(htmlWithScript);  
        response.end();  
    }).listen(8000);
0
votes

It works perfectly together with UiPath-Orchestrator nodejs.

So just use:

var util = require('util');
var Orchestrator = require('uipath-orchestrator');
var orchestrator = new Orchestrator({
     tenancyName: 'test',           // The Orchestrator Tenancy
     usernameOrEmailAddress: 'xxx',// The Orchestrator login
     password: 'yyy',               // The Orchestrator password
     hostname: 'host.company.com', // The instance hostname
     isSecure: true,                // optional (defaults to true)
     port: 443, // optional (defaults to 80 or 443 based on isSecure)
     invalidCertificate: false, // optional (defaults to false)
     connectionPool: 5 // options, 0=unlimited (defaults to 1)
});
var apiPath = '/odata/Users';
var apiQuery = {};
orchestrator.get(apiPath, apiQuery, function (err, data) {
    if (err) {
        console.error('Error: ' + err);
    }
    console.log('Data: ' + util.inspect(data));
});

and extract the orchestrator object to your node.js code.

It also works together with Orchestrator Cloud (if you don't have the on-prem), see here for more info.