Use node modules or npm packages in Custom Enrichment

Is it possible to use any npm packages in custom JS enrichment?

My use case is for decrypting a field so maybe there’s a way to do this with bringing in npm packages or node modules (crypto module)?

Technically yes, but not in the traditional sense of npm install.

You can include any JavaScript you need but it needs to be merged into a single script and then Base64 encoded for the enrichment.

To include an NPM Package, you would need to either copy the functions from the package into your script manually, or create a build process that constructs a single JS script that contains the code from the NPM package.

In regards to your example, crypto is a part of NodeJS which isn’t what the JS Enrichment uses under the hood so isn’t automatically available. There is crypto-js which might work, using the technique described above, but I can’t make any guarentees as I haven’t tested it.

Additionally, the JS Enrichment execution engine might not support all the features you need for libraries like crypto-js. If you are using Enrich pre-1.3.0 then you will be using the RhinoJS engine, from 1.3.0 onwards it is the Nashorn engine.

1 Like