toc

Cagify

An inline function for converting any existing function into a Cage.

Overview

evervault.cagify() is an inline function that lets you instantly convert any existing function into a Cage. It is only available in our Node.js SDK.

Simply wrap an existing function in cagify() along with a name for the Cage, and our SDK will automatically deploy your source code to a Cage.

cagify() requires the CLI to be installed in your local development environment. It uses our CLI to automatically deploy Cages under the hood.

It will also generate a cage-lock.json file in the root of your project which must be committed to source control and included in your production codebase. The cage-lock.json file keeps track of any source code changes, prevents code tampering, and ensures your app is always calling the correct version of the Cage.

All updates to a Cage deployed via cagify() will be tracked and logged to an individual user within your team.

It is important to note that cagify() functions will not have access to any resources outside of the function scope itself, with two exceptions:

  1. Environment Variables
  2. NPM Packages

Environment variables

Environment variables will automatically be encrypted in your server and injected to the Cage at runtime. They will be available in the process.env object, as normal.

NPM Packages

npm packages must be required within the function itself. cagify() will automatically detect any packages included in your function and install them during the deployment flow.

Note: if your function is synchronous, cagify() will automatically convert it to an asynchronous function as it requires an external network call.

For more information, see the Node.js SDK reference.

Example App

Here is an example of a typical cagify() app:

javascript
const Evervault = require('@evervault/sdk');
const evervault = new Evervault('<YOUR_API_KEY>');
// `from` and `to` will be exposed as standard objects,
// even if encrypted data is passed in.
const calculateDistance = (from, to) => {
// You can include any `npm` packages you like!
const geolib = require('geolib');
// Your environment will be transmitted to the Cage automatically.
console.log(process.env.API_SECRET);
return geolib.getDistance(from, to);
};
// Wrap the function in `cagify()` and give it a Cage name.
const calculateDistanceCage = evervault.cagify(
'distance-calculator',
calculateDistance
);
(async () => {
// calculateDistanceCage will now accept encrypted parameters.
const from = await evervault.encrypt({
latitude: 37.445103,
longitude: -122.160363,
});
// The function will accept both encrypted and decrypted values.
const to = {
latitude: 37.794046,
longitude: -122.395366,
};
// calculateDistanceCage becomes an async function.
const distance = await calculateDistanceCage(from, to);
console.log(distance);
})();