Workflow - Custom JavaScript Libraries

Currently trying to move some functionality from one of our Apps over to a Workflow but running into an issue with a JavaScript Library NodeForge (https://cdnjs.cloudflare.com/ajax/libs/forge/1.3.1/forge.min.js) not being available. I was able to link to the library in the app, but Workflows do not allow custom library declaration.

Would it be possible to get this added to the list for Workflows or is there an update on when custom declarations will be available?

Hi there @dohrann :wave: You should be able to add the node-forge npm package in Workflows using the the Libraries :package: panel on the left-hand side bar.

Here's a screenshot showing some sample code that uses node-forge:

And the code in the screenshot in case it's helpful for testing real quick:

const forge = require('node-forge');

// Function to encrypt data
function encryptData(plainText, secretKey) {
  const cipher = forge.cipher.createCipher('AES-CBC', secretKey);
  
  // Generate a random initialization vector (IV)
  const iv = forge.random.getBytesSync(16);

  // Encrypt
  cipher.start({ iv });
  cipher.update(forge.util.createBuffer(plainText, 'utf8'));
  cipher.finish();

  const encrypted = cipher.output.getBytes();
  return {
    encryptedData: forge.util.encode64(encrypted),
    iv: forge.util.encode64(iv)
  };
}

// Function to decrypt data
function decryptData(encryptedData, secretKey, iv) {
  const decipher = forge.cipher.createDecipher('AES-CBC', secretKey);

  // Decode the encrypted data and IV from base64
  const encryptedBytes = forge.util.decode64(encryptedData);
  const ivBytes = forge.util.decode64(iv);

  // Decrypt
  decipher.start({ iv: ivBytes });
  decipher.update(forge.util.createBuffer(encryptedBytes));
  const result = decipher.finish();

  if (result) {
    return decipher.output.toString('utf8');
  } else {
    throw new Error('Decryption failed');
  }
}

// Example usage:
const secretKey = forge.random.getBytesSync(16); // Generate a random 16-byte key
const plainText = 'Hello, this is a secret message!';

// Encrypt the data
const { encryptedData, iv } = encryptData(plainText, secretKey);
console.log('Encrypted:', encryptedData);

// Decrypt the data
const decryptedData = decryptData(encryptedData, secretKey, iv);
console.log('Decrypted:', decryptedData);

return {plainText, encryptedData, decryptedData}

Not seeing it listed. We are On Prem, retool version 3.75.8

was this added in a specific version of retool?

Screenshot 2024-10-25 090040

Hi @dohrann - Yes, Python code blocks and third-party libraries should be available on 3.75.8. Please make sure your deployment has at least one code-executor container running

I need a javascript library. But it seems thats still not supported?

Hi there - sorry for the mix up on Python versus JavaScript, I'll follow up soon

Hi @dohrann - sorry for the confusion I introduced by mentioning Python.

Workflows Custom JavaScript Libraries is available on 3.75 as a beta (community post about it is here) however as the (latest release) docs mention, you will need the code-executor container running for custom JavaScript libraries as well. The fact that you do not see Python as an option in your workflows UI means that it appears your self-hosted deployment does not have a code-executor container running.

The Workflows Custom JavaScript is already out of beta for cloud-hosted customers and will be out of beta for self-hosted deployments in the next Retool stable release.

If you get code-executor running and you'd like us to enable the beta for you, please DM me the email associated with your self-hosted license.