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e,EAAK,GAAK,SAAS,GAChC,OAAI,EAAc,EAAY,GAE1B,EAAI,GAAG,oBAA6B,SAExC,EAAqB,EAAK,GAAK,SAAS,GACtC,OAAI,EAAc,EAAY,GAE1B,EAAI,GAAG,qCAA+C,SAE1D,EAAoB,EAAK,GAAK,SAAS,GACrC,GAAI,EAAO,OAAO,EAAY,GAE9B,GAAI,EAAI,GAAG,uBAA0B,OAAO,IAW5C,IAAI,EAAoB,EAAI,QAAQ,gBACpC,EAAI,QAAQ,gBAAkB,mBAC9B,EAAe,EAAK,GAAK,SAAS,GAQ5B,EACF,EAAI,QAAQ,gBAAkB,SAEvB,EAAI,QAAQ,gBAUrB,GACF,GACF,GACF,GACF,KAxDE,EAAI,KAAO,CAAC,EACL,KAwDX,CACF","file":"/npm/skipper@0.9.6/lib/skipper.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/skipper@0.9.6/lib/skipper.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\n * Module dependencies\n */\n\nvar _ = require('@sailshq/lodash');\nvar bodyParser = require('body-parser');\nvar toParseMultipartHTTPRequest = require('./private/multipart');\nvar Upstream = require('./private/Upstream');\n\n// Double-check that a valid Node version with support for streams2\n// is being used\nif (!require('semver').satisfies(process.version, '>=0.10.0')) {\n  console.error('`skipper` (bodyParser) requires node version >= 0.10.0.');\n  console.error('Please upgrade Node at http://nodejs.org/ or with `nvm`');\n  throw new Error('Invalid Node.js version');\n}\n\n/**\n * Skipper\n *\n * @param  {Object} options [description]\n * @return {Function}\n */\n\nmodule.exports = function toParseHTTPBody(options) {\n  options = options || {};\n\n  // Configure body parser components\n\n  // For URLEncoded, default the \"extended\" option to true for backwards compatibility,\n  // and to avoid a deprecation warning (see https://github.com/expressjs/body-parser#options-3)\n  // Also default request limit for JSON and URL-encoded parsers to 1mb for backwards compatibility.\n  var URLEncodedBodyParser = bodyParser.urlencoded(_.extend({extended: true, limit: '1mb'}, options));\n  var JSONBodyParser = bodyParser.json(_.extend({limit: '1mb'}, options));\n  var MultipartBodyParser = toParseMultipartHTTPRequest(options);\n\n\n  /**\n   * Connect/Express/Sails-compatible middleware.\n   *\n   * @param  {Request}   req  [description]\n   * @param  {Response}   res  [description]\n   * @param  {Function} next [description]\n   */\n\n  return function _parseHTTPBody(req, res, next) {\n\n    // If there's no `req.is`, bail out early because we won't be able to tell\n    // with certainty what the content-type is or isn't.\n    if (!req.is) {\n      return next(new Error('Consistency violation: `req.is` is not defined.\\n' +\n                            'This typically means that you are using an outdated version of Express.\\n'+\n                            'Skipper requires Express 3 or above.\\n'));\n    }\n\n    // Use custom body parser error handler if provided, otherwise\n    // just forward the error to the next Express error-handling middleware.\n    var handleError = function (err) {\n\n      if (options.onBodyParserError) {\n        try {\n          // If the logic is an async function, attach a `.catch()` to handle rejections.\n          if (options.onBodyParserError.constructor.name === 'AsyncFunction') {\n            var promise = options.onBodyParserError(err, req, res, next);\n            promise.catch(function(err){ next(err); });\n          }\n          // Otherwise just run the synchronous function.\n          else {\n            return options.onBodyParserError(err, req, res, next);\n          }\n        } catch (e) { return next(e); }\n        return;\n      }\n      else {\n        return next(err);\n      }\n    };//</handleError>\n\n    // Optimization: skip bodyParser for GET, OPTIONS, or body-less requests.\n    if (req.method.toLowerCase() === 'get' || req.method.toLowerCase() === 'options' || req.method.toLowerCase() === 'head') {\n\n      // But stub out a `req.file()` method with a usage error:\n      req.file = function() {\n        throw new Error('`req.file()` cannot be used with an HTTP GET, OPTIONS, or HEAD request.');\n      };\n\n      return next();\n    }\n\n    // FUTURE: Optimization: only run bodyParser if this is a known route\n\n    // log.verbose('Running request ('+req.method+' ' + req.url + ') through bodyParser...');\n\n    // Mock up a req.file handler that returns a noop upstream, so that user code\n    // can use `req.file` without having to check for it first.  This is useful in cases\n    // where there may or may not be file params coming in.  The Multipart parser will\n    // replace this with an actual upstream-acquiring function if the request isn't successfully\n    // handled by one of the other parsers first.\n    req.file = function(fieldName) {\n      var noopUpstream = new Upstream({\n        noop: true\n      });\n      noopUpstream.fieldName = 'NOOP_'+fieldName;\n      return noopUpstream;\n    };\n\n    if (\n      // If we have a content-length header...\n      !_.isUndefined(req.headers['content-length']) &&\n      // And the content length is declared to be zero...\n      (req.headers['content-length'] === 0 || req.headers['content-length'] === '0')) {\n      // Then we set the body to any empty object\n      // and skip all this body-parsing mishegoss.\n      req.body = {};\n      return next();\n    }\n\n    // Try to parse a request that has application/json content type\n    JSONBodyParser(req, res, function(err) {\n      if (err) { return handleError(err); }\n      // If the parser actually ran and did some parsing, then we're done.\n      if (req.is('application/json')) {return next();}\n      // Otherwise try the URL-encoded parser (application/x-www-form-urlencoded type)\n      URLEncodedBodyParser(req, res, function(err) {\n        if (err) { return handleError(err); }\n        // If the parser actually ran and did some parsing, then we're done.\n        if (req.is('application/x-www-form-urlencoded')) { return next(); }\n        // Otherwise try the multipart parser\n        MultipartBodyParser(req, res, function(err) {\n          if (err) { return handleError(err); }\n          // If the parser actually ran and did some parsing, then we're done.\n          if (req.is('multipart/form-data')) { return next(); }\n\n          /**\n           * OK, here's how the re-run of the JSON bodyparser works:\n           * ========================================================\n           * If the original pass of the bodyParser failed to parse anything, rerun it,\n           * but with an artificial `application/json` content-type header,\n           * forcing it to try and parse the request body as JSON.  This is just in case\n           * the user sent a JSON request body, but forgot to set the appropriate header\n           * (which is pretty much every time, I think.)\n           */\n          var backupContentType = req.headers['content-type'];\n          req.headers['content-type'] = 'application/json';\n          JSONBodyParser(req, res, function(err) {\n\n            // Revert content-type to what it originally was.\n            // This is so we don't inadvertently corrupt `req.headers`--\n            // our apps' actions might be looking for 'em.\n            //\n            // If the original request didn't include a content-type,\n            // remove the header entirely.\n            if (backupContentType) {\n              req.headers['content-type'] = backupContentType;\n            } else {\n              delete req.headers['content-type'];\n            }\n\n            // If an error occurred in the retry, it's not actually an error\n            // (we can't assume EVERY requeset was intended to be JSON)\n            if (err) {\n              // log.verbose('Attempted to retry bodyParse as JSON.  But no luck.', err);\n            }\n\n            // Proceed, whether or not the body was parsed.\n            next();\n          });//_∏_\n        });//_∏_\n      });//_∏_\n    });//_∏_\n  };//ƒ(req,res,next)\n};//ƒ(options)\n"]}