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AK,EAAM,GAAU,MAAK,SAAU,GAC9C,MAAM,EAAK,eACX,EAAQ,EACV,IAAG,MAAM,EACX,IAAG,MAAM,KAET,MAAM,EAAK,+CAAiD,cAAc,MAE1E,EAAO,GAEX,IAEJ,IACe,MAAK,SAAU,GAE5B,IAAI,EAAO,UAAU,EAAK,GACtB,EAAe,kBAAkB,EAAK,EAAM,GAC5C,EAAkB,qBAAqB,EAAK,EAAM,GAUtD,OARA,UAAU,KAAK,CACb,IAAK,EACL,KAAM,EACN,SAAU,EACV,KAAM,EACN,aAAc,EACd,gBAAiB,IAEZ,CACT,GACF,CAcA,SAAS,YACP,OAAO,SACT,CAEA,SAAS,cACP,UAAY,EACd,CAlBA,SAAS,UAAY,SAAU,GAC7B,cAAc,KAAO,UAAY,EAAO,KACxC,cAAc,YAAc,EAAO,aAAe,cAAc,YAChE,cAAc,WAAa,EAAO,YAAc,cAAc,WAC1D,EAAO,kBACT,cAAc,gBAAkB,GAChC,EAAO,gBAAgB,SAAQ,SAAU,GACvC,cAAc,gBAAgB,KAAK,EAAI,cACzC,IAEJ,EAUA,SAAS,SAAW,SACpB,SAAS,SAAW,SACpB,SAAS,UAAY,UACrB,SAAS,YAAc,YAEvB,OAAO,QAAU","file":"/npm/fetch-vcr@3.2.0/lib/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/fetch-vcr@3.2.0/lib/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","var fetchImpl = require('./adapter/fetch-node')\nvar Response = require('./adapter/response-node')\n\nvar _require = require('./adapter/files-node')\nvar loadFile = _require.loadFile\nvar saveFile = _require.saveFile\n\nvar VCR_MODE = typeof process !== 'undefined' ? process.env['VCR_MODE'] : null\nvar DEBUG = typeof process !== 'undefined' ? process.env['DEBUG'] : false\n\n// Valid modes:\n// - 'playback': ONLY uses the fixture files (default)\n// - 'cache': tries to use the fixture and if not found then fetched and saves\n// - 'record': forces files to be written\n// - 'erase': deletes the fixture corresponding to the request\n\n\n// mode: 'playback' or 'cache' or 'record'\n// fixturePath: './_fixtures/'\nvar CONFIGURATION = {\n  mode: VCR_MODE,\n  fixturePath: './_fixtures',\n  headerBlacklist: ['authorization', 'user-agent'], // These need to be lowercase\n  ignoreUrls: [] // regex of urls to ignore\n}\n\nfunction debug(url, message) {\n  if (DEBUG) {\n    console.log(url, message)\n  }\n}\n\n// Use the correct constructor if there is a body.\n// In a browser it needs to be the single-arg constructor.\nfunction newResponse(bodyBuffer, opts) {\n  if (bodyBuffer || typeof window === 'undefined') {\n    return new Response(bodyBuffer, opts)\n  } else {\n    return new Response(null, opts)\n  }\n}\n\nfunction hashCode(str) {\n  var hash = 0,\n      i,\n      chr\n  if (str.length === 0) return hash\n  for (i = 0; i < str.length; i++) {\n    chr = str.charCodeAt(i)\n    hash = (hash << 5) - hash + chr\n    hash |= 0 // Convert to 32bit integer\n  }\n  return hash\n}\n\nfunction parseHeader(headers) {\n  if (headers.raw) return headers.raw();\n  var raw = {};\n  var itr = headers.entries()\n  var next = itr.next();\n  while (!next.done) {\n    raw[next.value[0]] = next.value[1];\n    next = itr.next();\n  }\n  return raw;\n}\n\nfunction buildHash(url, args) {\n  var json = {}\n  if (args) {\n    json.method = args.method\n    json.redirect = args.redirect\n    json.body = args.body // Include POST body in the hash\n\n    // Filter out all the headers in the headerBlacklist\n    if (args.headers) {\n      json.headers = {}\n      var headerKeys = Object.keys(args.headers)\n      for (var index in headerKeys) {\n        var key = headerKeys[index]\n        if (CONFIGURATION.headerBlacklist.indexOf(key.toLowerCase()) < 0) {\n          json.headers[key] = args.headers[key]\n        }\n      }\n    }\n  }\n  // const hash = crypto.createHash('sha256')\n  // hash.update(JSON.stringify(json))\n  // return hash.digest('hex')\n  return hashCode(JSON.stringify(json))\n}\n\nfunction buildFilenamePrefix(url, args, hash) {\n  args = args || { }\n  var [baseUrl, query] = url.split('?')\n  url = escape(baseUrl).replace(/\\//g, '_')\n  var method = args.method || 'GET'\n  method = method.toUpperCase()\n  var paramsHash = query ? '_' + hashCode(query) : ''\n  return url + paramsHash + '_' + method + '_' + hash\n}\n\nfunction buildOptionsFilename(url, args, hash) {\n  return buildFilenamePrefix(url, args, hash) + '_options.json'\n}\n\nfunction buildBodyFilename(url, args, hash) {\n  return buildFilenamePrefix(url, args, hash) + '_body.raw'\n}\n\nfunction loadFixture(url, args) {\n  var hash = buildHash(url, args)\n  var bodyFilename = buildBodyFilename(url, args, hash)\n  var optionsFilename = buildOptionsFilename(url, args, hash)\n  var root = CONFIGURATION.fixturePath\n\n  return Promise.all([fetchVCR.loadFile(root, optionsFilename), fetchVCR.loadFile(root, bodyFilename)]).then(function (resolvedValues) {\n    var optionsBuffer = resolvedValues[0]\n    var bodyBuffer = resolvedValues[1]\n\n    var opts = JSON.parse(optionsBuffer.toString())\n    if (opts.headers && opts.headers['content-type'] && opts.headers['content-type'][0] && /^application\\/json/.test(opts.headers['content-type'][0])) {\n      // Check that the JSON is parseable\n      // There is an odd thing that happens for api.github.com/search/repositories?q=github\n      // Extra text is at the end of the JSON when it is saved to the fixture.\n      // TODO: remove this hack by fixing it in fetch-vcr\n      try {\n        bodyBuffer = bodyBuffer.toString()\n        JSON.parse(bodyBuffer)\n      } catch (e) {\n        // JSON occasionally has extra stuff at the end. not sure why\n        // Sample message: \"Unexpected number in JSON at position 146432\"\n        var tokens = e.message.split(' ')\n        var num = parseInt(tokens[tokens.length - 1])\n        console.log('---------------------------------')\n        console.log('BUG: could not parse json. Using HACK')\n        console.log(url + ' ' + (args && args.method || 'GET'))\n        console.log('Message: \"' + e.message + '\"')\n        console.log('Parse character:', num)\n        console.log('---------------------------------')\n        bodyBuffer = bodyBuffer.substring(0, num)\n      }\n    }\n\n    // Use the correct constructor if there is a body\n    const clone = newResponse(bodyBuffer, opts)\n    clone.wasCached = true\n    return clone\n  })\n}\n\nfunction saveFixture(url, args, response) {\n  var hash = buildHash(url, args)\n  var bodyFilename = buildBodyFilename(url, args, hash)\n  var optionsFilename = buildOptionsFilename(url, args, hash)\n  // const requestFilename = buildOptionsFilename(url, args, hash) + '_request.log'\n  var root = CONFIGURATION.fixturePath\n\n  // Convert the response body to a Buffer for saving\n  debug(url, 'getting buffer to save')\n  // DO NOT .clone() this response because response.clone() does not work well. See https://github.com/bitinn/node-fetch/issues/151\n  return response.text().then(function (bodyBuffer) {\n    // Write the Response contents and the Response options\n    var json = {\n      url: response.url,\n      status: response.status,\n      statusText: response.statusText,\n      ok: response.ok,\n      headers: parseHeader(response.headers),\n    }\n\n    var optionsRaw = JSON.stringify(json)\n\n    return Promise.all([fetchVCR.saveFile(root, bodyFilename, bodyBuffer), fetchVCR.saveFile(root, optionsFilename, optionsRaw) /*, fetchVCR.saveFile(root, requestFilename, JSON.stringify(args || {})) */]).then(function () {\n      // send a new buffer because response.clone() does not work well. See https://github.com/bitinn/node-fetch/issues/151\n      // Use the correct constructor if there is a body\n      return newResponse(bodyBuffer, json)\n    })\n  })\n}\n\nfunction ignoredUrl(url) {\n  return CONFIGURATION.ignoreUrls.some(function (urlToIgnore) {\n    return url.match(urlToIgnore)\n  })\n}\n\n// Log each call that was made so tests can verify\nvar allCalled = []\n\nfunction fetchVCR(urlOrReq, args) {\n  let url = urlOrReq\n  if (typeof url !== 'string') {\n    url = url.url\n  }\n\n  // Try to load the response from the fixture.\n  // Then, if a fixture was not found, either fetch it for reals or error (depending on the VCR_MODE)\n  const promise = new Promise(function (resolve, reject) {\n    if (ignoredUrl(url)) {\n      debug(url, 'this url is ignored by configuration')\n      fetchImpl(url, args).then(resolve).catch(reject)\n    } else if (CONFIGURATION.mode === 'record') {\n      // Perform the fetch, save the response, and then yield the original response\n      fetchImpl(url, args).then(function (response) {\n        saveFixture(url, args, response).then(resolve).catch(reject)\n      }).catch(reject)\n    } else {\n      debug(url, 'checking for cached version')\n      // Check if cached version exists\n      loadFixture(url, args).then(resolve).catch(function (err) {\n        // Cached version does not exist\n        debug(url, 'cached version not found because', err.message)\n        if (CONFIGURATION.mode === 'cache') {\n          debug(url, 'making network request')\n          // Perform the fetch, save the response, and then yield the original response\n          fetchImpl(url, args).then(function (response) {\n            debug(url, 'saving network request')\n            saveFixture(url, args, response).then(function (val) {\n              debug(url, 'done saving')\n              resolve(val)\n            }).catch(reject)\n          }).catch(reject)\n        } else {\n          debug(url, 'NOT making network request because VCR_MODE=' + CONFIGURATION.mode)\n          // throw new Error('fetch-vcr ERROR: Fixture file was not found.')\n          reject(err) // TODO: Provide a more detailed message\n        }\n      })\n    }\n  })\n  return promise.then(function (resp) {\n    // Record that the request succeeded\n    var hash = buildHash(url, args)\n    var bodyFilename = buildBodyFilename(url, args, hash)\n    var optionsFilename = buildOptionsFilename(url, args, hash)\n\n    allCalled.push({\n      url: url,\n      args: args,\n      response: resp,\n      hash: hash,\n      bodyFilename: bodyFilename,\n      optionsFilename: optionsFilename\n    })\n    return resp\n  })\n}\n\nfetchVCR.configure = function (config) {\n  CONFIGURATION.mode = VCR_MODE || config.mode\n  CONFIGURATION.fixturePath = config.fixturePath || CONFIGURATION.fixturePath\n  CONFIGURATION.ignoreUrls = config.ignoreUrls || CONFIGURATION.ignoreUrls\n  if (config.headerBlacklist) {\n    CONFIGURATION.headerBlacklist = []\n    config.headerBlacklist.forEach(function (key) {\n      CONFIGURATION.headerBlacklist.push(key.toLowerCase())\n    })\n  }\n}\n\nfunction getCalled() {\n  return allCalled\n}\n\nfunction clearCalled() {\n  allCalled = []\n}\n\nfetchVCR.loadFile = loadFile\nfetchVCR.saveFile = saveFile\nfetchVCR.getCalled = getCalled\nfetchVCR.clearCalled = clearCalled\n\nmodule.exports = fetchVCR\n"]}