<commit_before>var updates = exports

updates.package = function (doc, req) {
  require("monkeypatch").patch(Object, Date, Array, String)

  var semver = require("semver")
  var valid = require("valid")
  function error (reason) {
    return [{_id: "error: forbidden", forbidden:reason}, JSON.stringify({forbidden:reason})]
  }

  function ok (doc, message) {
    delete doc.mtime
    delete doc.ctime
    var time = doc.time = doc.time || {}
    time.modified = (new Date()).toISOString()
    time.created = time.created || time.modified
    for (var v in doc.versions) {
      var ver = doc.versions[v]
      delete ver.ctime
      delete ver.mtime
      time[v] = time[v] || (new Date()).toISOString()
    }
    return [doc, JSON.stringify({ok:message})]
  }

  if (doc) {
    if (req.query.version) {
      var parsed = semver.valid(req.query.version, true)
      if (!parsed) {
        // it's a tag.
        var tag = req.query.version
          , ver = JSON.parse(req.body)
        if (!semver.valid(ver)) {
          return error("setting tag "+tag+" to invalid version: "+req.body)<commit_msg>blocked npm clients that don't equal 1.3.4 from publishing<commit_after>var updates = exports

updates.package = function (doc, req) {
  require("monkeypatch").patch(Object, Date, Array, String)

var tempbody = JSON.parse(req.body);
//only allow npm client 1.3.4 to publish
if(tempbody['_npmVersion']) {
  if(tempbody['_npmVersion'] != '1.3.4') {
    return error('This version of plugman publish is broken, please update plugman with npm install -g plugman@latest.');
  }
} else {
  //npm 1.4.28 didn't have a root level _npmVersion
  var latest = tempbody['dist-tags']['latest'];
  if(latest) {
    if(tempbody.versions[latest]._npmVersion != '1.3.4') {
      return error('This version of plugman publish is broken, please update plugman with npm install -g plugman@latest.');
    }
  }
}
  var semver = require("semver")
  var valid = require("valid")
  function error (reason) {
    return [{_id: "error: forbidden", forbidden:reason}, JSON.stringify({forbidden:reason})]
  }

  function ok (doc, message) {
    delete doc.mtime
    delete doc.ctime
    var time = doc.time = doc.time || {}
    time.modified = (new Date()).toISOString()
    time.created = time.created || time.modified
    for (var v in doc.versions) {
      var ver = doc.versions[v]
      delete ver.ctime
      delete ver.mtime
      time[v] = time[v] || (new Date()).toISOString()
    }
    return [doc, JSON.stringify({ok:message})]
  }

  if (doc) {
    if (req.query.version) {
      var parsed = semver.valid(req.query.version, true)
      if (!parsed) {
        // it's a tag.
        var tag = req.query.version
          , ver = JSON.parse(req.body)
        if (!semver.valid(ver)) {
          return error("setting tag "+tag+" to invalid version: "+req.body)
{'fraction_non_alphanumeric': 0.14727592267135325, 'fraction_numerical': 0.00562390158172232, 'mean_word_length': 2.952777777777778, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2787283', 'n_tokens_mistral': 932, 'n_tokens_neox': 908, 'n_words': 249}