Skip to content

Instantly share code, notes, and snippets.

@tjanczuk
Last active Apr 2, 2018
Embed
What would you like to do?
Best effort migration of Node 4 webtask to Node 8
'use strict';
const Async = require('async');
const Acorn = require('acorn');
const AcornWalk = require('acorn/dist/walk');
const Astring = require('astring');
const Superagent = require('superagent');
module.exports = migrate;
/**
* Migrates a webtask from https://webtask.it.auth0.com to https://sandbox.auth0-extend.com:
* - analyzes code to uncover module dependencies ("require" only, no built-ins)
* - merges the implicit module dependencies with explicit module dependencies
* - ensures modules are built on Node 8
* - re-creates the Node 4 webtask in Node 8 with secrets, code, and meta
*
* options.container
* options.name
* options.token
*/
function migrate(options, cb) {
const TYPE_GLOBAL = 'global';
const TYPE_REQUIRE = 'require';
const TYPE_REQUIRE_DYNAMIC = 'require_dynamic';
var moduleTypes = {
TYPE_GLOBAL,
TYPE_REQUIRE,
TYPE_REQUIRE_DYNAMIC,
};
const node4ModuleList = {
nativeModuleNames: Object.keys(process.binding('natives')),
verquireModules: {"hashmap":["2.1.0"],"auth0-extension-s3-tools":["1.1.1"],"sanitize-html":["1.14.1"],"box-node-sdk":["1.3.0"],"exif":["0.6.0"],"mercadopago":["0.5.0"],"vso-client":["0.2.5"],"node-jose":["0.9.2"],"node-google-dfp":["0.2.2"],"web-push":["3.2.2"],"node-firebird":["0.8.1"],"osom":["2.2.0"],"firebase-queue":["1.6.1"],"google-translate":["1.0.9"],"chartmogul-node":["1.0.0"],"project-name-generator":["2.1.3"],"latest-github-tag":["1.0.0"],"exif-js":["2.1.1"],"3scale":["0.7.2"],"firebase-token-generator":["2.0.0"],"facebook-ads-sdk":["2.7.2"],"mailparser":["0.6.1"],"aws-kinesis-writable":["2.0.0"],"hapi-swagger":["7.4.0"],"auth0-extension-hapi-tools":["1.0.0","1.1.0","1.2.0","1.2.1"],"auth0-extension-express-tools":["1.0.2","1.1.5"],"lru-memoizer":["1.10.0"],"html-entities":["1.2.0"],"auth0-horn-middlewares":["0.0.4"],"client-sessions":["0.7.0"],"blipp":["2.3.0"],"relish":["0.2.4"],"rollbar":["0.6.2"],"mssql":["3.3.0"],"@guggy/guggy-js-sdk":["1.4.2"],"react":["15.3.2","15.4.1"],"axios":["0.15.2"],"urllib":["2.17.0"],"pug":["2.0.0-beta6"],"fable-core":["0.6.10"],"cors":["2.8.1"],"dovehash":["0.0.5"],"x-ray":["2.3.1"],"sinch-ticketgen":["0.0.6"],"joi":["9.0.4"],"nano":["6.2.0"],"splunk-bunyan-logger":["0.9.1"],"@horizon/client":["2.0.0"],"web3":["0.16.0"],"keen-js":["3.4.1"],"fraction.js":["3.3.1"],"authorize-net":["1.0.6"],"node-shipstation":["0.1.1"],"firebase-auth":["0.1.2"],"tropo-webapi":["1.2.0"],"node-bigcommerce":["2.0.1"],"chrono-node":["1.2.4"],"@kikinteractive/kik":["2.0.8"],"getstream":["3.4.1"],"watson-developer-cloud":["2.0.1","2.27.1"],"mixpanel":["0.4.0"],"helmet":["2.1.2"],"immutable":["3.8.1"],"ibm_db":["1.0.0"],"liquid-node":["2.6.1"],"dropbox":["2.0.0"],"vso-node-api":["3.1.1"],"gitlab":["1.7.0"],"aimlinterpreter":["0.1.7"],"feed-read":["0.0.1"],"openpgp":["2.3.2"],"nodemailer":["2.5.0"],"jwks-rsa":["1.0.0","1.1.1"],"inert":["4.0.1"],"hapi-auth-jwt2":["7.0.1"],"hapi":["13.5.0"],"good":["7.0.1"],"good-console":["6.1.2"],"scrypt":["6.0.3"],"apn":["1.7.6"],"discourse-sso":["1.0.3"],"ably":["0.8.29"],"mcrypt":["0.1.11"],"airbrake":["1.0.2","1.2.0"],"gcloud":["0.36.0"],"mailchimp":["1.2.0"],"mailchimp-api":["2.0.7"],"opentok":["2.3.2"],"particle-api-js":["5.2.7"],"shortid":["2.2.6"],"mollie-api-node":["1.2.1"],"oracledb":["1.9.3"],"diffbot-api-client":["1.0.0"],"ahrefs":["0.1.0"],"pdffiller":["0.3.0"],"fanoutpub":["1.0.3"],"quagga":["0.11.1"],"samlp":["1.0.0"],"nlp_compromise":["4.10.6"],"nsp":["2.4.0"],"fibers":["1.0.10"],"deasync":["0.1.6"],"medium-sdk":["0.0.3"],"paypal-rest-sdk":["1.6.8"],"yelp":["1.0.1"],"node-telegram-bot-api":["0.21.1"],"lodash":["3.10.1","3.9.3","2.4.1","4.8.2"],"jsforce":["1.6.0"],"pusher":["1.2.1"],"ldapjs":["1.0.0"],"validatejs":["0.0.2"],"nconf":["0.8.4"],"aiml":["0.0.2"],"letsencrypt":["1.4.3"],"algorithmia":["0.3.3"],"geolib":["2.0.18"],"analytics-node":["2.0.1"],"google-search":["0.0.3"],"auth0-oauth2-express":["0.0.3","1.1.5","1.2.0"],"stamplay":["1.0.6","1.0.5","1.0.3","1.0.8"],"algoliasearch":["3.10.2"],"ssh2":["0.4.13"],"adal-node":["0.1.17"],"azure":["0.10.6","1.2.0-preview"],"azure-arm-apiapp":["0.1.3"],"azure-arm-authorization":["2.0.0"],"azure-arm-commerce":["0.1.1"],"azure-arm-compute":["0.13.0"],"azure-arm-datalake-analytics":["0.1.6"],"azure-arm-datalake-store":["0.1.4"],"azure-arm-dns":["0.10.1"],"azure-arm-hdinsight":["0.1.0"],"azure-arm-hdinsight-jobs":["0.1.0"],"azure-arm-insights":["0.10.2"],"azure-arm-intune":["0.1.3"],"azure-arm-keyvault":["0.10.1"],"azure-arm-network":["0.11.0"],"azure-arm-rediscache":["0.1.0"],"azure-arm-resource":["0.10.7"],"azure-arm-storage":["0.11.0"],"azure-arm-trafficmanager":["0.10.4"],"azure-arm-website":["0.10.1"],"azure-asm-compute":["0.11.0"],"azure-asm-hdinsight":["0.10.2"],"azure-asm-scheduler":["0.10.1"],"azure-asm-mgmt":["0.10.1"],"azure-asm-network":["0.10.2"],"azure-asm-sb":["0.10.1"],"azure-asm-sql":["0.10.1"],"azure-asm-storage":["0.10.1"],"azure-asm-store":["0.10.1"],"azure-asm-subscription":["0.10.1"],"azure-asm-trafficmanager":["0.10.3"],"azure-asm-website":["0.10.1"],"azure-cli":["0.9.13"],"azure-common":["0.9.16"],"azure-extra":["0.2.12"],"azure-gallery":["2.0.0-pre.18"],"azure-insights":["0.7.7-pre"],"azure-iot-build":["1.0.0-preview.4"],"azure-iot-common":["1.0.0-preview.9"],"azure-iot-device":["1.0.0-preview.9"],"azure-iothub":["1.0.0-preview.9"],"azure-keyvault":["0.10.1"],"azure-mgmt":["0.9.16"],"azure-mgmt-authorization":["0.9.0-pre.6"],"azure-mgmt-compute":["0.9.16"],"azure-mgmt-hdinsight":["0.9.16"],"azure-mgmt-resource":["2.0.0-pre.17"],"azure-mgmt-sb":["0.9.16"],"azure-mgmt-scheduler":["0.9.1-pre.16"],"azure-mgmt-sql":["0.9.17"],"azure-mgmt-storage":["0.9.16"],"azure-mgmt-store":["0.9.16"],"azure-mgmt-subscription":["0.9.16"],"azure-mgmt-vnet":["0.9.17"],"azure-mgmt-website":["0.9.16"],"azure-mobile-apps":["2.0.0-beta3"],"azure-monitoring":["0.10.2"],"azure-rm-website":["0.9.0-pre.10"],"azure-sb":["0.10.2"],"azure-scheduler":["0.10.1"],"documentdb":["1.5.1"],"documentdb-q-promises":["1.5.0"],"reindex-js":["0.3.1"],"cassandra-driver":["3.0.0"],"shopify-node-api":["1.5.1"],"babel-runtime":["6.3.19","6.3.13"],"fbemitter":["2.0.0"],"fbjs":["0.5.0"],"invariant":["2.2.0"],"isomorphic-fetch":["2.2.0"],"html-to-text":["1.5.0"],"applicationinsights":["0.15.8","0.18.0"],"request-promise":["1.0.2"],"googleapis":["2.1.6"],"nforce":["1.2.3"],"braintree":["1.30.0"],"parse":["1.6.8"],"ramda":["0.18.0","0.23.0"],"plaid":["1.0.7"],"s3-blob-store":["0.1.0"],"s3-lister":["0.1.0"],"express-jwt":["3.1.0","5.1.0"],"elasticsearch":["8.2.0"],"stream-to-promise":["1.0.4"],"temp":["0.8.3"],"archiver":["0.15.0"],"mongoose":["4.1.6"],"slack-notify":["0.1.4"],"le_node":["1.0.8"],"node-zendesk":["1.1.4"],"json-bigint":["0.1.4"],"verquire":["0.2.5"],"async":["1.0.0","0.9.0","2.1.2"],"auth0":["2.0.0-alpha.5","2.4.0","2.1.0","2.0.0","0.8.2","2.6.0","2.7.0","2.8.0","2.9.1"],"aws-sdk":["2.2.30","2.1.31","2.1.13","2.4.13","2.5.3","2.197.0"],"azure-storage":["0.4.4","0.4.1","0.9.0"],"babel":["5.4.7","5.1.9"],"bcrypt":["0.8.5"],"couchbase":["2.1.3"],"dockerode":["2.2.3","2.1.4","2.0.3"],"easy-pbkdf2":["0.1.1","0.0.2"],"ejs":["2.3.1"],"firebase":["2.4.0","2.2.5","2.2.4","3.0.4","3.1.0","3.6.9"],"ip":["0.3.2","0.0.1"],"jsonwebtoken":["5.7.0","5.0.1","5.0.0","7.1.9"],"knex":["0.8.6"],"mongo-getdb":["1.4.0"],"mongodb":["2.0.48","2.0.33","2.0.27","2.2.11"],"mysql":["2.7.0","2.6.2","2.0.0-alpha8","2.15.0"],"node-cassandra-cql":["0.4.4"],"oauth":["0.9.13","0.9.12"],"pg":["4.3.0","4.1.1","6.1.2"],"posix":["4.0.0"],"pubnub":["3.7.11","3.7.0"],"q":["1.4.1","1.0.1"],"range_check":["0.0.5","0.0.1"],"request":["2.56.0","2.55.0","2.27.0","2.67.0","2.81.0"],"rethinkdb":["2.1.1","2.0.0-1","2.0.0"],"tedious":["1.11.0","0.1.4"],"tripwire":["4.1.0"],"winston":["1.0.0","0.8.1"],"wordpress-hash-node":["1.0.0"],"xml2js":["0.4.8","0.2.8"],"xmldom":["0.1.19","0.1.13"],"xpath":["0.0.9","0.0.5"],"xtend":["4.0.0","1.0.3"],"node-uuid":["1.4.3"],"node-php-password":["0.1.2"],"optimist":["0.6.1"],"validator":["3.40.0"],"cheerio":["0.19.0"],"knox":["0.9.2"],"consolidate":["0.13.1"],"less":["2.5.1"],"sendgrid":["1.8.0","3.0.7","4.7.0"],"handlebars":["3.0.3"],"csv":["0.4.2"],"ws":["0.7.2"],"sequelize":["3.1.1","3.28.0"],"underscore.string":["3.0.3"],"marked":["0.3.3"],"twilio":["2.2.1"],"mime":["1.3.4"],"swig":["1.4.2"],"hiredis":["0.4.1"],"mongojs":["0.18.2"],"jsdom":["3.1.2"],"twit":["1.1.20","2.2.3"],"debug":["2.2.0"],"cloudinary":["1.2.1"],"mandrill-api":["1.0.45"],"stripe":["3.3.4","4.14.0","4.24.0"],"redis-url":["1.2.0"],"superagent":["1.2.0"],"minimatch":["2.0.8"],"glob":["5.0.10"],"minimist":["1.1.1"],"qs":["3.1.0"],"inherits":["2.0.1"],"commander":["2.8.1"],"readable-stream":["1.0.33"],"mkdirp":["0.5.1"],"lru-cache":["2.6.4"],"graceful-fs":["3.0.7"],"source-map":["0.4.2"],"isarray":["0.0.1"],"ms":["0.7.1"],"chalk":["1.0.0"],"rimraf":["2.3.4"],"ansi-styles":["2.0.1"],"string_decoder":["0.10.31"],"strip-ansi":["2.0.1"],"core-util-is":["1.0.1"],"supports-color":["1.3.1"],"mime-types":["2.0.12"],"esprima":["2.2.0"],"once":["1.3.2"],"underscore":["1.8.3"],"oauth-sign":["0.8.0"],"semver":["4.3.4"],"hawk":["2.3.1"],"uglify-js":["2.4.23"],"ansi-regex":["1.1.1"],"hoek":["2.14.0","4.1.0"],"nopt":["3.0.2"],"has-ansi":["1.0.3"],"wordwrap":["1.0.0"],"boom":["2.7.2","3.2.2"],"form-data":["0.2.0"],"cryptiles":["2.0.4"],"sntp":["1.0.9"],"sigmund":["1.0.1"],"nan":["1.8.4"],"through2":["0.6.5"],"tough-cookie":["1.2.0","2.2.2"],"escape-string-regexp":["1.0.3"],"forever-agent":["0.6.1"],"wrappy":["1.0.1"],"caseless":["0.10.0"],"get-stdin":["4.0.1"],"delayed-stream":["1.0.0"],"amdefine":["0.1.0"],"mime-db":["1.10.0"],"json-stringify-safe":["5.0.1"],"colors":["1.1.0"],"concat-map":["0.0.1"],"tunnel-agent":["0.4.0"],"iconv-lite":["0.4.10"],"balanced-match":["0.2.0"],"brace-expansion":["1.1.0"],"ctype":["0.5.4"],"inflight":["1.0.4"],"object-assign":["2.0.0"],"js-yaml":["3.3.1"],"asn1":["0.2.2"],"resolve":["1.1.6"],"combined-stream":["1.0.3"],"send":["0.12.3"],"npm":["2.10.1"],"http-signature":["0.11.0"],"assert-plus":["0.1.5"],"through":["2.3.7"],"domelementtype":["1.3.0"],"methods":["1.1.1"],"cookie-signature":["1.0.6"],"end-of-stream":["1.1.0"],"cookie":["0.1.3"],"osenv":["0.1.1"],"bl":["0.9.4"],"entities":["1.1.1"],"aws-sign2":["0.5.0"],"estraverse":["4.1.0"],"negotiator":["0.5.3"],"strip-json-comments":["1.0.2"],"argparse":["1.0.2"],"which":["1.1.1"],"bytes":["2.1.0"],"stringstream":["0.0.4"],"bluebird":["2.9.26","3.4.6","3.5.0"],"fresh":["0.3.0"],"abbrev":["1.0.6"],"camelcase":["1.1.0"],"ee-first":["1.1.1"],"clone":["1.0.2"],"on-finished":["2.3.0"],"crc":["3.2.1"],"coffee-script":["1.9.3"],"meow":["3.1.0"],"finalhandler":["0.3.6"],"etag":["1.6.0"],"punycode":["1.3.2"],"type-is":["1.6.2"],"dateformat":["1.0.11"],"range-parser":["1.0.2"],"isstream":["0.1.2"],"ini":["1.3.3"],"esprima-fb":["15001.1.0-dev-harmony-fb"],"depd":["1.0.1"],"serve-static":["1.9.3"],"accepts":["1.2.7"],"connect":["3.3.5"],"lodash.keys":["3.1.1"],"shelljs":["0.5.0"],"deep-equal":["1.0.0"],"domutils":["1.5.1"],"yargs":["3.9.1"],"mute-stream":["0.0.5"],"raw-body":["2.1.0"],"escape-html":["1.0.1"],"map-obj":["1.0.1"],"fstream":["1.0.6"],"express":["4.12.4","4.14.0"],"parseurl":["1.3.0"],"ncp":["2.0.0"],"is-finite":["1.0.1"],"graceful-readlink":["1.0.1"],"findup-sync":["0.2.1"],"repeating":["1.1.3"],"inquirer":["0.8.5"],"utils-merge":["1.0.0"],"is-my-json-valid":["2.12.0"],"indent-string":["1.2.1"],"har-validator":["1.7.1"],"camelcase-keys":["1.0.0"],"vinyl":["0.4.6"],"sax":["1.1.1"],"diff":["1.4.0"],"pkginfo":["0.3.0"],"jade":["1.10.0"],"xmlbuilder":["2.6.4"],"generate-object-property":["1.2.0"],"rc":["1.0.3"],"esutils":["2.0.2"],"request-progress":["0.3.1"],"escodegen":["1.6.1"],"mout":["0.11.0"],"tar-stream":["1.1.5"],"es6-symbol":["2.0.1"],"duplexer2":["0.0.2"],"media-typer":["0.3.0"],"htmlparser2":["3.8.2"],"gaze":["0.5.1"],"body-parser":["1.12.4"],"domhandler":["2.3.0"],"vary":["1.0.0"],"console-browserify":["1.1.0"],"destroy":["1.0.3"],"tmp":["0.0.26"],"generate-function":["2.0.0"],"jsonpointer":["2.0.0"],"is-property":["1.0.2"],"mocha":["2.2.5"],"lodash.template":["3.6.1"],"acorn":["1.2.2"],"es5-ext":["0.10.7"],"archy":["1.0.0"],"globule":["0.2.0"],"traverse":["0.6.6"],"exit":["0.1.2"],"convert-source-map":["1.1.1"],"user-home":["1.1.1"],"isobject":["1.0.0"],"sprintf-js":["1.0.2"],"extend":["2.0.1"],"is-primitive":["2.0.0"],"uid-safe":["2.0.0"],"fs-extra":["0.18.4"],"read":["1.0.6"],"jshint":["2.7.0"],"npmconf":["2.1.2"],"clone-stats":["0.0.1"],"concat-stream":["1.4.8"],"dom-serializer":["0.1.0"],"event-stream":["3.3.1"],"deep-extend":["0.4.0"],"cli":["0.7.0"],"lodash._reinterpolate":["3.0.0"],"object-keys":["1.0.4"],"lodash.templatesettings":["3.1.0"],"lodash.escape":["3.0.0"],"shell-quote":["1.4.3"],"process":["0.11.1"],"got":["3.2.0"],"statuses":["1.2.1"],"batch":["0.5.2"],"date-now":["1.0.1"],"uglify-to-browserify":["1.0.2"],"update-notifier":["0.5.0"],"merge-descriptors":["1.0.0"],"uuid":["2.0.1","3.1.0"],"window-size":["0.1.0"],"array-uniq":["1.0.2"],"growl":["1.8.1"],"chokidar":["1.0.1"],"lodash.isarguments":["3.0.3"],"lodash.isarray":["3.0.3"],"native-or-bluebird":["1.2.0"],"decamelize":["1.0.0"],"lodash._isiterateecall":["3.0.9"],"es6-iterator":["0.1.3"],"retry":["0.6.1"],"lodash.isnative":["3.0.3"],"gulp-util":["3.0.4"],"multiparty":["4.1.2"],"typedarray":["0.0.6"],"browserify":["10.2.1"],"path-to-regexp":["1.2.0"],"proto-list":["1.2.4"],"morgan":["1.5.3"],"pause":["0.0.1"],"event-emitter":["0.3.3"],"adm-zip":["0.4.7"],"defined":["1.0.0"],"es6-weak-map":["1.0.2"],"jsonify":["0.0.0"],"socket.io":["1.3.5"],"clean-css":["3.2.10"],"uid-number":["0.0.6"],"eventemitter2":["0.4.14"],"glob-watcher":["2.0.0"],"vinyl-fs":["1.0.0"],"cardinal":["0.5.0"],"jsonfile":["2.0.1"],"touch":["0.0.3"],"moment":["2.10.3","2.11.2"],"string-length":["1.0.0"],"lodash._basecopy":["3.0.1"],"deep-is":["0.1.3"],"socket.io-client":["1.3.5"],"throttleit":["1.0.0"],"glob-stream":["5.0.0"],"bower":["1.4.1"],"progress":["1.1.8"],"config-chain":["1.1.8"],"options":["0.0.6"],"array-differ":["1.0.0"],"utile":["0.3.0"],"d":["0.1.1"],"ipaddr.js":["1.0.1"],"next-tick":["0.2.2"],"duplexify":["3.4.1"],"express-session":["1.11.2"],"cli-color":["1.0.0"],"unique-stream":["2.0.2"],"cookie-parser":["1.3.5"],"prelude-ls":["1.1.2"],"registry-url":["3.0.3"],"proxy-addr":["1.0.8"],"basic-auth":["1.0.1"],"redis":["2.4.2","0.12.1"],"i":["0.3.4"],"compression":["1.4.4"],"read-all-stream":["2.1.2"],"readdirp":["1.3.0"],"package-json":["1.1.0"],"lodash.restparam":["3.6.1"],"serve-favicon":["2.2.1"],"bower-config":["0.6.1"],"indexof":["0.0.1"],"semver-diff":["2.0.0"],"optionator":["0.6.0"],"decompress-zip":["0.2.0"],"latest-version":["1.0.0"],"formidable":["1.0.17"],"serve-index":["1.6.4"],"lodash._basetostring":["3.0.0"],"lodash._objecttypes":["2.4.1"],"tar":["2.1.1"],"multipipe":["0.1.2"],"path-is-absolute":["1.0.0"],"opn":["1.0.2"],"type-check":["0.3.1"],"levn":["0.2.5"],"fast-levenshtein":["1.0.6"],"insight":["0.6.0"],"tar-fs":["1.5.1"],"method-override":["2.3.3"],"sha.js":["2.4.1"],"lodash.debounce":["3.1.0"],"figures":["1.3.5"],"base64id":["0.1.0"],"stream-combiner":["0.2.1"],"p-throttler":["0.1.1"],"memoizee":["0.3.8"],"buffer-crc32":["0.2.5"],"bower-registry-client":["0.3.0"],"promise":["7.0.1"],"stack-trace":["0.0.9"],"grunt":["0.4.5"],"strip-bom":["1.0.0"],"promptly":["0.2.1"],"compressible":["2.0.2"],"rx":["2.5.2"],"first-chunk-stream":["1.0.0"],"is-utf8":["0.2.0"],"infinity-agent":["2.0.3"],"tinycolor":["0.0.1"],"replace-ext":["0.0.1"],"errorhandler":["1.3.6"],"fstream-ignore":["1.0.2"],"on-headers":["1.0.0"],"configstore":["1.0.0"],"ast-types":["0.7.6"],"socket.io-parser":["2.2.4"],"stream-counter":["1.0.0"],"http-proxy":["1.11.1"],"base64-js":["0.0.8"],"content-type":["1.0.1"],"pump":["1.0.0"],"lodash._isnative":["2.4.1"],"repeat-string":["1.5.2"],"buffers":["0.1.1"],"is-absolute":["0.1.7"],"bindings":["1.2.1"],"xdg-basedir":["1.0.1"],"nested-error-stacks":["1.0.0"],"glob2base":["0.0.12"],"chainsaw":["0.1.0"],"jsonparse":["1.0.0"],"faye-websocket":["0.9.4"],"parseuri":["0.0.4"],"duplexer":["0.1.1"],"readline2":["0.1.1"],"binary":["0.3.0"],"ordered-read-streams":["0.2.0"],"content-disposition":["0.5.0"],"recast":["0.10.12"],"find-index":["1.1.0"],"is-relative":["0.1.3"],"prepend-http":["1.0.1"],"is-stream":["1.0.1"],"util":["0.10.3"],"lowercase-keys":["1.0.0"],"has-binary":["0.1.6"],"timed-out":["2.0.0"],"component-emitter":["1.2.0"],"csurf":["1.8.2"],"lodash.isobject":["3.0.2"],"async-each":["0.1.6"],"response-time":["2.3.1"],"has-color":["0.1.7"],"forwarded":["0.1.0"],"connect-timeout":["1.6.2"],"chmodr":["0.1.1"],"http-errors":["1.3.1"],"kew":["0.6.0"],"eyes":["0.1.8"],"base64-url":["1.2.1"],"lru-queue":["0.1.0"],"timers-ext":["0.1.0"],"pako":["0.2.6"],"xmlhttprequest":["1.7.0"],"liftoff":["2.1.0"],"is-number":["2.0.2"],"is-npm":["1.0.0"],"cycle":["1.0.3"],"redeyed":["0.5.0"],"braces":["1.8.0"],"expand-range":["1.8.1"],"prompt":["0.2.14"],"lodash._basevalues":["3.0.0"],"lockfile":["1.0.1"],"lodash._reescape":["3.0.0"],"beeper":["1.0.0"],"lodash._reevaluate":["3.0.0"],"basic-auth-connect":["1.0.0"],"stringify-object":["2.0.0"],"kind-of":["1.1.0"],"split":["1.0.0"],"scmp":["1.0.0"],"array-filter":["1.0.0"],"callsite":["1.0.0"],"array-map":["0.0.0"],"array-reduce":["0.0.0"],"junk":["1.0.1"],"anymatch":["1.3.0"],"gulp":["3.8.11"],"ansicolors":["0.3.2"],"defaults":["1.0.2"],"browserify-zlib":["0.1.4"],"block-stream":["0.0.8"],"hooker":["0.2.3"],"interpret":["0.6.2"],"parents":["1.0.1"],"mkpath":["0.1.0"],"binary-extensions":["1.3.1"],"parse-glob":["3.0.2"],"vhost":["3.0.0"],"repeat-element":["1.1.2"],"github":["0.2.4"],"is-root":["1.0.0"],"map-stream":["0.0.5"],"log4js":["0.6.25"],"os-name":["1.0.3"],"is-binary-path":["1.0.1"],"bower-endpoint-parser":["0.2.2"],"bower-json":["0.5.0"],"intersect":["1.0.1"],"bower-logger":["0.2.2"],"getobject":["0.1.0"],"request-replay":["0.3.0"],"array-slice":["0.2.3"],"micromatch":["2.1.6"],"object.omit":["1.1.0"],"for-own":["0.1.3"],"for-in":["0.1.4"],"is-dotfile":["1.0.1"],"is-glob":["2.0.0"],"each-async":["1.1.1"],"glob-parent":["1.2.0"],"arrify":["1.0.0"],"grunt-legacy-log":["0.1.2"],"osx-release":["1.0.0"],"win-release":["1.0.0"],"regex-cache":["0.4.2"],"glob-base":["0.2.0"],"fileset":["0.1.5"],"grunt-legacy-util":["0.2.0"],"fill-range":["2.2.2"],"detective":["4.1.0"],"lodash._shimkeys":["2.4.1"],"preserve":["0.2.0"],"filename-regex":["2.0.0"],"expand-brackets":["0.1.1"],"is-equal-shallow":["0.1.2"],"arr-diff":["1.0.1"],"randomatic":["1.1.0"],"is-extglob":["1.0.0"],"tildify":["1.0.0"],"csrf":["3.0.0"],"path-platform":["0.11.15"],"lodash.defaults":["3.1.1"],"buffer":["3.2.2"],"pretty-hrtime":["1.0.0"],"source-map-support":["0.2.10"],"rndm":["1.1.0"],"noptify":["0.0.3"],"istanbul":["0.3.14"],"orchestrator":["0.3.7"],"chai":["2.3.0"],"querystring":["0.2.0"],"browser-pack":["5.0.1"],"deprecated":["0.0.1"],"crypto-browserify":["3.9.14"],"stream-consume":["0.1.0"],"sequencify":["0.0.7"],"pretty-bytes":["2.0.1"],"asap":["2.0.3"],"after":["0.8.1"],"ultron":["1.0.1"],"sinon":["1.14.1"],"timers-browserify":["1.4.1"],"url":["0.10.3"],"assert":["1.3.0"],"ieee754":["1.1.5"],"module-deps":["3.8.0"],"cli-table":["0.3.1"],"array-union":["1.0.1"],"text-table":["0.2.0"],"mz":["2.0.0"],"strip-dirs":["1.1.1"],"npmlog":["1.2.1"],"useragent":["2.1.6"],"inline-source-map":["0.5.0"],"ripemd160":["1.0.1"],"v8flags":["2.0.5"],"stream-browserify":["1.0.0"],"brorand":["1.0.5"],"bn.js":["2.0.5"],"insert-module-globals":["6.5.0"],"uid2":["0.0.3"],"benchmark":["1.0.0"],"querystring-es3":["0.2.1"],"thenify":["3.1.0"],"umd":["3.0.1"],"onetime":["1.0.0"],"deps-sort":["1.3.9"],"thenify-all":["1.6.0"],"private":["0.1.6"],"stable":["0.1.5"],"css-parse":["2.0.0"],"path-browserify":["0.0.0"],"browser-resolve":["1.9.0"],"subarg":["1.0.0"],"vm-browserify":["0.0.4"],"events":["1.0.2"],"assertion-error":["1.0.1"],"eventemitter3":["1.1.0"],"domain-browser":["1.1.4"],"flagged-respawn":["0.3.1"],"set-immediate-shim":["1.0.1"],"syntax-error":["1.1.4"],"constants-browserify":["0.0.1"],"type-detect":["1.0.0"],"https-browserify":["0.0.0"],"utf8":["2.1.0"],"is-integer":["1.0.4"],"os-browserify":["0.1.2"],"tty-browserify":["0.0.0"],"stream-combiner2":["1.0.2"],"cookie-jar":["0.3.0"],"deep-eql":["0.1.3"],"aws-sign":["0.1.1"],"stringmap":["0.2.2"],"policyfile":["0.0.5"],"ansi":["0.3.0"],"core-js":["0.9.13"],"zeparser":["0.0.7"],"simple-fmt":["0.1.0"],"simple-is":["0.2.0"],"is-nan":["1.0.1"],"engine.io":["1.5.1"],"commondir":["1.0.1"],"active-x-obfuscator":["0.0.2"],"tryor":["0.1.2"],"alter":["0.2.0"],"download":["4.1.2"],"gulp-rename":["1.2.2"],"stringset":["0.2.1"],"install":["0.1.8"],"builtins":["1.0.1"],"keypress":["0.2.1"],"postcss":["4.1.11"],"lexical-scope":["1.1.1"],"revalidator":["0.3.1"],"engine.io-parser":["1.2.1"],"astw":["2.0.0"],"bson":["0.3.2"],"json3":["3.3.2"],"has-cors":["1.1.0"],"gzip-size":["1.0.0"],"commoner":["0.10.1"],"combine-source-map":["0.6.1"],"gauge":["1.2.0"],"is-array":["1.0.1"],"blob":["0.0.4"],"base64-arraybuffer":["0.1.2"],"arraybuffer.slice":["0.0.6"],"open":["0.0.5"],"pause-stream":["0.0.11"],"di":["0.0.1"],"component-bind":["1.0.0"],"asn1.js":["2.0.3"],"when":["3.7.3"],"hash.js":["1.0.3"],"lodash-node":["3.9.3"],"better-assert":["1.0.2"],"delegates":["0.1.0"],"tiny-lr-fork":["0.0.5"],"karma-jasmine":["0.3.5"],"shallow-copy":["0.0.1"],"engine.io-client":["1.5.1"],"co":["4.5.4"],"cron-parser":["0.6.4"],"numeraljs":["1.5.3"],"unirest":["0.4.2"],"mock":["0.1.1"],"stats-analysis":["2.0.0"],"xero":["0.0.8"],"easyxml":["2.0.1"],"restify":["4.0.3"],"botbuilder":["3.4.4","0.9.0"],"cloudant":["1.4.1"],"ms-rest":["1.12.0"],"pdfkit":["0.7.2"],"bwip-js":["0.15.1"],"userapp":["2.0.0"],"moment-timezone":["0.5.7"],"google-distance":["1.0.1"],"gcm":["1.0.1"],"cryptr":["2.0.0"],"splunk-sdk":["1.8.1"],"amazon-product-api":["0.4.2"],"indico.io":["0.10.5"],"passport-wsfed-saml2":["2.11.4"],"dotenv":["2.0.0"],"pretty-data":["0.40.0"],"auth0-extension-tools":["1.0.0","1.2.1","1.3.1"],"mustache":["2.3.0"],"amazon-s3-url-signer":["0.1.0"],"mailgun-js":["0.7.14"],"auth0-api-jwt-rsa-validation":["0.0.1"],"pg-hstore":["2.3.2"],"firebase-admin":["4.0.4","5.0.0"],"node-wit":["4.2.0"],"Base64":["1.0.0"],"lokijs":["1.4.2"],"xml2json":["0.10.0"],"asana":["0.15.0"],"airtable":["0.4.3"],"pouchdb":["6.1.0"],"dynamicsnode":["0.0.17"],"randomstring":["1.1.5"],"hashids":["1.1.1"],"nexmo":["1.1.0"],"argon2":["0.14.1"],"jsonapi-datastore":["0.4.0-beta"],"intercom-client":["2.8.5"],"google-libphonenumber":["2.0.7"],"html-metadata":["1.6.2"],"osmosis":["1.1.2"],"postmark":["1.3.1"],"clearbit":["1.2.3"],"edit-google-spreadsheet":["0.2.21"],"mqtt":["2.2.1"],"node-django-hashers":["1.0.9"],"bunyan-loggly":["1.2.0"],"node-logentries":["0.1.4"],"raven":["1.1.1"],"fbgraph":["1.3.0"],"disposable-email-domains":["1.0.14","1.0.15"],"forecast":["0.3.2"],"speakeasy":["2.0.0"],"nodemailer-ses-transport":["1.5.0"],"lokka":["1.7.0"],"pdf2json":["1.1.7"],"xlsx":["0.8.8"],"node-xlsx":["0.7.4"],"xls-to-json-lc":["0.3.3"],"image-size":["0.5.1"],"the-noun-project":["2.0.1"],"amazon-mws-node":["1.0.4","1.0.3"],"freemail":["1.5.0"],"string-similarity":["1.1.0"],"natural":["0.5.1"],"jsonpatch-to-mongodb":["0.3.0"],"fast-json-patch":["1.2.1"],"pipedrive":["3.0.2"],"filter-object":["2.1.0"],"atlassian-crowd-client":["1.4.2"],"nock":["9.0.14"],"wappalyzer":["5.0.7"],"soap":["0.23.0"],"paynl-sdk":["1.0.7"],"aws-s3-zipper":["1.0.1"],"google-auth-library":["1.0.0"],"js-sha3":["0.7.0"]}
};
function parseVerquireSpec(spec) {
const atIndex = spec.indexOf('@', 1);
if (atIndex === -1) {
return { name: spec, version: undefined };
}
return {
name: spec.slice(0, atIndex - 1),
version: spec.slice(atIndex + 1, 0),
};
}
function parseCode(astOrCode) {
return typeof astOrCode === 'string'
? Acorn.parse(astOrCode, {
allowReturnOutsideFunction: true,
})
: astOrCode;
}
function createDynamicDependency(node) {
return {
type: TYPE_REQUIRE_DYNAMIC,
start: node.start,
end: node.end,
spec: node.arguments.map(exp => Astring.generate(exp)).join(''),
};
}
function createStaticDependency(node) {
return {
type: TYPE_REQUIRE,
start: node.start,
end: node.end,
spec: node.arguments[0].value,
};
}
const REQUIRE_WALKER = AcornWalk.make({
CallExpression: (node, state, recurse) => {
AcornWalk.base[node.type](node, state, recurse);
if (
node.callee.type === 'Identifier' &&
node.callee.name === 'require'
) {
if (
node.arguments.length !== 1 ||
node.arguments[0].type !== 'Literal'
) {
state.requires.push(createDynamicDependency(node));
} else {
state.requires.push(createStaticDependency(node));
}
}
},
});
function findRequires(astOrCode) {
const ast = parseCode(astOrCode);
const state = {
requires: [],
};
AcornWalk.recursive(ast, state, REQUIRE_WALKER);
return state.requires;
}
function addDependencies(webtask, cb) {
const nativeModules = node4ModuleList.nativeModuleNames;
const verquireModules = node4ModuleList.verquireModules;
const ast = parseCode(webtask.code);
var dependencies = {};
const requires = findRequires(ast);
if (webtask.meta && webtask.meta['wt-node-dependencies']) {
try {
dependencies = JSON.parse(webtask.meta['wt-node-dependencies']);
}
catch (_) {};
}
requires.forEach(require => {
if (require.type === moduleTypes.TYPE_REQUIRE) {
const required = parseVerquireSpec(require.spec);
if (dependencies[required.name]) return;
const name = required.name;
let version = required.version;
if (version === undefined) {
if (nativeModules.indexOf(name) !== -1) {
return;
} else if (
Array.isArray(verquireModules[name]) &&
verquireModules[name].length
) {
version = verquireModules[name][0];
}
}
dependencies[name] = version;
}
});
if (Object.keys(dependencies).length > 0) {
webtask.meta['wt-node-dependencies'] = JSON.stringify(dependencies);
}
return cb(null, webtask);
}
function provisionDependencies(count, webtask, cb) {
var dependencies = {};
try {
dependencies = JSON.parse(webtask.meta['wt-node-dependencies']);
}
catch (_) {}
var modules = [];
for (var name in dependencies)
modules.push({ name, version: dependencies[name] });
if (modules.length === 0)
return cb(null, webtask);
Superagent
.post(`https://sandbox.auth0-extend.com/api/env/node/modules`)
.set('Authorization', `Bearer ${options.token}`)
.send({ modules })
.end((e,r) => {
if (e) return cb(e);
for (var i = 0; i < r.body.length; i++) {
if (r.body[i].state === 'queued') {
return count === 0
? cb(new Error('Unable to ensure required modules are available before timeout expired'))
: setTimeout(() => provisionDependencies(count - 1, webtask, cb), 5000);
}
}
cb(null, webtask);
});
}
function saveWebtask(webtask, cb) {
var wt = {
code: webtask.code
};
if (webtask.secrets)
wt.secrets = webtask.secrets;
if (webtask.meta)
wt.meta = webtask.meta;
Superagent
.put(`https://sandbox.auth0-extend.com/api/webtask/${options.container}/${options.name}`)
.set('Authorization', `Bearer ${options.token}`)
.send(wt)
.end((e,r) => cb(e, r && r.body));
}
return Async.waterfall([
(cb) => Superagent
.get(`https://webtask.it.auth0.com/api/webtask/${options.container}/${options.name}`)
.query({ decrypt: true, fetch_code: true })
.set('Authorization', `Bearer ${options.token}`)
.end((e,r) => cb(e, r && r.body)),
(webtask, cb) => addDependencies(webtask, cb),
(webtask, cb) => provisionDependencies(6, webtask, cb),
(webtask, cb) => saveWebtask(webtask, cb),
], cb);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment