Bundle node dependencies and use them in Apigee Edge javascript policies. Built upon the excellent Browserify project.
npm install policify
In the example below we use the z-schema module in a new module 'policify'. The policify modules will be used in Apigee.
// validate-schema.js
var ZSchema = require('z-schema')
ZSchema = new ZSchema({
breakOnFirstError: true,
noExtraKeywords: true,
ignoreUnknownFormats: false,
reportPathAsArray: true
})
var policify = {
validateSchema: function (injected, schema) {
return ZSchema.validate(injected, schema)
}
}
module.exports = policify
npm install policify uglify-js
policify ./validate-schema.js | uglifyjs > bundle.js
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Javascript timeLimit="200" async="false" continueOnError="true" enabled="true" name="Add Output Validation">
<DisplayName>Add Output Validation</DisplayName>
<IncludeURL>jsc://bundle.js</IncludeURL>
<ResourceURL>jsc://schema-validation.js</ResourceURL>
</Javascript>
...
var bundle = context.getVariable('bundle')
bundle.policify.validateSchema(target, schema)
...