Skip to content
Snippets Groups Projects
onDeleteAccount.js 7.96 MiB
Newer Older
  • Learn to ignore specific revisions
  • Hugo SUBTIL's avatar
    Hugo SUBTIL committed
    8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 8784 8785 8786 8787 8788 8789 8790 8791 8792 8793 8794 8795 8796 8797 8798 8799 8800 8801 8802 8803 8804 8805 8806 8807 8808 8809 8810 8811 8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 8872 8873 8874 8875 8876 8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 8900 8901 8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 8973 8974 8975 8976 8977 8978 8979 8980 8981 8982 8983 8984 8985 8986 8987 8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 9000
      var aPathLen = a.path ? a.path.length : 0;
      var bPathLen = b.path ? b.path.length : 0;
      cmp = bPathLen - aPathLen;
      if (cmp !== 0) {
        return cmp;
      }
    
      // ascending for time: a CMP b
      var aTime = a.creation ? a.creation.getTime() : MAX_TIME;
      var bTime = b.creation ? b.creation.getTime() : MAX_TIME;
      cmp = aTime - bTime;
      if (cmp !== 0) {
        return cmp;
      }
    
      // break ties for the same millisecond (precision of JavaScript's clock)
      cmp = a.creationIndex - b.creationIndex;
    
      return cmp;
    }
    
    // Gives the permutation of all possible pathMatch()es of a given path. The
    // array is in longest-to-shortest order.  Handy for indexing.
    function permutePath(path) {
      if (path === '/') {
        return ['/'];
      }
      if (path.lastIndexOf('/') === path.length-1) {
        path = path.substr(0,path.length-1);
      }
      var permutations = [path];
      while (path.length > 1) {
        var lindex = path.lastIndexOf('/');
        if (lindex === 0) {
          break;
        }
        path = path.substr(0,lindex);
        permutations.push(path);
      }
      permutations.push('/');
      return permutations;
    }
    
    function getCookieContext(url) {
      if (url instanceof Object) {
        return url;
      }
      // NOTE: decodeURI will throw on malformed URIs (see GH-32).
      // Therefore, we will just skip decoding for such URIs.
      try {
        url = decodeURI(url);
      }
      catch(err) {
        // Silently swallow error
      }
    
      return urlParse(url);
    }
    
    function Cookie(options) {
      options = options || {};
    
      Object.keys(options).forEach(function(prop) {
        if (Cookie.prototype.hasOwnProperty(prop) &&
            Cookie.prototype[prop] !== options[prop] &&
            prop.substr(0,1) !== '_')
        {
          this[prop] = options[prop];
        }
      }, this);
    
      this.creation = this.creation || new Date();
    
      // used to break creation ties in cookieCompare():
      Object.defineProperty(this, 'creationIndex', {
        configurable: false,
        enumerable: false, // important for assert.deepEqual checks
        writable: true,
        value: ++Cookie.cookiesCreated
      });
    }
    
    Cookie.cookiesCreated = 0; // incremented each time a cookie is created
    
    Cookie.parse = parse;
    Cookie.fromJSON = fromJSON;
    
    Cookie.prototype.key = "";
    Cookie.prototype.value = "";
    
    // the order in which the RFC has them:
    Cookie.prototype.expires = "Infinity"; // coerces to literal Infinity
    Cookie.prototype.maxAge = null; // takes precedence over expires for TTL
    Cookie.prototype.domain = null;
    Cookie.prototype.path = null;
    Cookie.prototype.secure = false;
    Cookie.prototype.httpOnly = false;
    Cookie.prototype.extensions = null;
    
    // set by the CookieJar:
    Cookie.prototype.hostOnly = null; // boolean when set
    Cookie.prototype.pathIsDefault = null; // boolean when set
    Cookie.prototype.creation = null; // Date when set; defaulted by Cookie.parse
    Cookie.prototype.lastAccessed = null; // Date when set
    Object.defineProperty(Cookie.prototype, 'creationIndex', {
      configurable: true,
      enumerable: false,
      writable: true,
      value: 0
    });
    
    Cookie.serializableProperties = Object.keys(Cookie.prototype)
      .filter(function(prop) {
        return !(
          Cookie.prototype[prop] instanceof Function ||
          prop === 'creationIndex' ||
          prop.substr(0,1) === '_'
        );
      });
    
    Cookie.prototype.inspect = function inspect() {
      var now = Date.now();
      return 'Cookie="'+this.toString() +
        '; hostOnly='+(this.hostOnly != null ? this.hostOnly : '?') +
        '; aAge='+(this.lastAccessed ? (now-this.lastAccessed.getTime())+'ms' : '?') +
        '; cAge='+(this.creation ? (now-this.creation.getTime())+'ms' : '?') +
        '"';
    };
    
    // Use the new custom inspection symbol to add the custom inspect function if
    // available.
    if (util.inspect.custom) {
      Cookie.prototype[util.inspect.custom] = Cookie.prototype.inspect;
    }
    
    Cookie.prototype.toJSON = function() {
      var obj = {};
    
      var props = Cookie.serializableProperties;
      for (var i=0; i<props.length; i++) {
        var prop = props[i];
        if (this[prop] === Cookie.prototype[prop]) {
          continue; // leave as prototype default
        }
    
        if (prop === 'expires' ||
            prop === 'creation' ||
            prop === 'lastAccessed')
        {
          if (this[prop] === null) {
            obj[prop] = null;
          } else {
            obj[prop] = this[prop] == "Infinity" ? // intentionally not ===
              "Infinity" : this[prop].toISOString();
          }
        } else if (prop === 'maxAge') {
          if (this[prop] !== null) {
            // again, intentionally not ===
            obj[prop] = (this[prop] == Infinity || this[prop] == -Infinity) ?
              this[prop].toString() : this[prop];
          }
        } else {
          if (this[prop] !== Cookie.prototype[prop]) {
            obj[prop] = this[prop];
          }
        }
      }
    
      return obj;
    };
    
    Cookie.prototype.clone = function() {
      return fromJSON(this.toJSON());
    };
    
    Cookie.prototype.validate = function validate() {
      if (!COOKIE_OCTETS.test(this.value)) {
        return false;
      }
      if (this.expires != Infinity && !(this.expires instanceof Date) && !parseDate(this.expires)) {
        return false;
      }
      if (this.maxAge != null && this.maxAge <= 0) {
        return false; // "Max-Age=" non-zero-digit *DIGIT
      }
      if (this.path != null && !PATH_VALUE.test(this.path)) {
        return false;
      }
    
      var cdomain = this.cdomain();
      if (cdomain) {
        if (cdomain.match(/\.$/)) {
          return false; // S4.1.2.3 suggests that this is bad. domainMatch() tests confirm this
        }
        var suffix = pubsuffix.getPublicSuffix(cdomain);
        if (suffix == null) { // it's a public suffix
          return false;
        }
      }
      return true;
    };
    
    Cookie.prototype.setExpires = function setExpires(exp) {
      if (exp instanceof Date) {
        this.expires = exp;
      } else {
        this.expires = parseDate(exp) || "Infinity";
      }
    };
    
    Cookie.prototype.setMaxAge = function setMaxAge(age) {
      if (age === Infinity || age === -Infinity) {
        this.maxAge = age.toString(); // so JSON.stringify() works
      } else {
        this.maxAge = age;
      }
    };
    
    // gives Cookie header format
    Cookie.prototype.cookieString = function cookieString() {
      var val = this.value;
      if (val == null) {
        val = '';
      }
      if (this.key === '') {
        return val;
      }
      return this.key+'='+val;
    };
    
    // gives Set-Cookie header format
    Cookie.prototype.toString = function toString() {
      var str = this.cookieString();
    
      if (this.expires != Infinity) {
        if (this.expires instanceof Date) {
          str += '; Expires='+formatDate(this.expires);
        } else {
          str += '; Expires='+this.expires;
        }
      }
    
      if (this.maxAge != null && this.maxAge != Infinity) {
        str += '; Max-Age='+this.maxAge;
      }
    
      if (this.domain && !this.hostOnly) {
        str += '; Domain='+this.domain;
      }
      if (this.path) {
        str += '; Path='+this.path;
      }
    
      if (this.secure) {
        str += '; Secure';
      }
      if (this.httpOnly) {
        str += '; HttpOnly';
      }
      if (this.extensions) {
        this.extensions.forEach(function(ext) {
          str += '; '+ext;
        });
      }
    
      return str;
    };
    
    // TTL() partially replaces the "expiry-time" parts of S5.3 step 3 (setCookie()
    // elsewhere)
    // S5.3 says to give the "latest representable date" for which we use Infinity
    // For "expired" we use 0
    Cookie.prototype.TTL = function TTL(now) {
      /* RFC6265 S4.1.2.2 If a cookie has both the Max-Age and the Expires
       * attribute, the Max-Age attribute has precedence and controls the
       * expiration date of the cookie.
       * (Concurs with S5.3 step 3)
       */
      if (this.maxAge != null) {
        return this.maxAge<=0 ? 0 : this.maxAge*1000;
      }
    
      var expires = this.expires;
      if (expires != Infinity) {
        if (!(expires instanceof Date)) {
          expires = parseDate(expires) || Infinity;
        }
    
        if (expires == Infinity) {
          return Infinity;
        }
    
        return expires.getTime() - (now || Date.now());
      }
    
      return Infinity;
    };
    
    // expiryTime() replaces the "expiry-time" parts of S5.3 step 3 (setCookie()
    // elsewhere)
    Cookie.prototype.expiryTime = function expiryTime(now) {
      if (this.maxAge != null) {
        var relativeTo = now || this.creation || new Date();
        var age = (this.maxAge <= 0) ? -Infinity : this.maxAge*1000;
        return relativeTo.getTime() + age;
      }
    
      if (this.expires == Infinity) {
        return Infinity;
      }
      return this.expires.getTime();
    };
    
    // expiryDate() replaces the "expiry-time" parts of S5.3 step 3 (setCookie()
    // elsewhere), except it returns a Date
    Cookie.prototype.expiryDate = function expiryDate(now) {
      var millisec = this.expiryTime(now);
      if (millisec == Infinity) {
        return new Date(MAX_TIME);
      } else if (millisec == -Infinity) {
        return new Date(MIN_TIME);
      } else {
        return new Date(millisec);
      }
    };
    
    // This replaces the "persistent-flag" parts of S5.3 step 3
    Cookie.prototype.isPersistent = function isPersistent() {
      return (this.maxAge != null || this.expires != Infinity);
    };
    
    // Mostly S5.1.2 and S5.2.3:
    Cookie.prototype.cdomain =
    Cookie.prototype.canonicalizedDomain = function canonicalizedDomain() {
      if (this.domain == null) {
        return null;
      }
      return canonicalDomain(this.domain);
    };
    
    function CookieJar(store, options) {
      if (typeof options === "boolean") {
        options = {rejectPublicSuffixes: options};
      } else if (options == null) {
        options = {};
      }
      if (options.rejectPublicSuffixes != null) {
        this.rejectPublicSuffixes = options.rejectPublicSuffixes;
      }
      if (options.looseMode != null) {
        this.enableLooseMode = options.looseMode;
      }
    
      if (!store) {
        store = new MemoryCookieStore();
      }
      this.store = store;
    }
    CookieJar.prototype.store = null;
    CookieJar.prototype.rejectPublicSuffixes = true;
    CookieJar.prototype.enableLooseMode = false;
    var CAN_BE_SYNC = [];
    
    CAN_BE_SYNC.push('setCookie');
    CookieJar.prototype.setCookie = function(cookie, url, options, cb) {
      var err;
      var context = getCookieContext(url);
      if (options instanceof Function) {
        cb = options;
        options = {};
      }
    
      var host = canonicalDomain(context.hostname);
      var loose = this.enableLooseMode;
      if (options.loose != null) {
        loose = options.loose;
      }
    
      // S5.3 step 1
      if (!(cookie instanceof Cookie)) {
        cookie = Cookie.parse(cookie, { loose: loose });
      }
      if (!cookie) {
        err = new Error("Cookie failed to parse");
        return cb(options.ignoreError ? null : err);
      }
    
      // S5.3 step 2
      var now = options.now || new Date(); // will assign later to save effort in the face of errors
    
      // S5.3 step 3: NOOP; persistent-flag and expiry-time is handled by getCookie()
    
      // S5.3 step 4: NOOP; domain is null by default
    
      // S5.3 step 5: public suffixes
      if (this.rejectPublicSuffixes && cookie.domain) {
        var suffix = pubsuffix.getPublicSuffix(cookie.cdomain());
        if (suffix == null) { // e.g. "com"
          err = new Error("Cookie has domain set to a public suffix");
          return cb(options.ignoreError ? null : err);
        }
      }
    
      // S5.3 step 6:
      if (cookie.domain) {
        if (!domainMatch(host, cookie.cdomain(), false)) {
          err = new Error("Cookie not in this host's domain. Cookie:"+cookie.cdomain()+" Request:"+host);
          return cb(options.ignoreError ? null : err);
        }
    
        if (cookie.hostOnly == null) { // don't reset if already set
          cookie.hostOnly = false;
        }
    
      } else {
        cookie.hostOnly = true;
        cookie.domain = host;
      }
    
      //S5.2.4 If the attribute-value is empty or if the first character of the
      //attribute-value is not %x2F ("/"):
      //Let cookie-path be the default-path.
      if (!cookie.path || cookie.path[0] !== '/') {
        cookie.path = defaultPath(context.pathname);
        cookie.pathIsDefault = true;
      }
    
      // S5.3 step 8: NOOP; secure attribute
      // S5.3 step 9: NOOP; httpOnly attribute
    
      // S5.3 step 10
      if (options.http === false && cookie.httpOnly) {
        err = new Error("Cookie is HttpOnly and this isn't an HTTP API");
        return cb(options.ignoreError ? null : err);
      }
    
      var store = this.store;
    
      if (!store.updateCookie) {
        store.updateCookie = function(oldCookie, newCookie, cb) {
          this.putCookie(newCookie, cb);
        };
      }
    
      function withCookie(err, oldCookie) {
        if (err) {
          return cb(err);
        }
    
        var next = function(err) {
          if (err) {
            return cb(err);
          } else {
            cb(null, cookie);
          }
        };
    
        if (oldCookie) {
          // S5.3 step 11 - "If the cookie store contains a cookie with the same name,
          // domain, and path as the newly created cookie:"
          if (options.http === false && oldCookie.httpOnly) { // step 11.2
            err = new Error("old Cookie is HttpOnly and this isn't an HTTP API");
            return cb(options.ignoreError ? null : err);
          }
          cookie.creation = oldCookie.creation; // step 11.3
          cookie.creationIndex = oldCookie.creationIndex; // preserve tie-breaker
          cookie.lastAccessed = now;
          // Step 11.4 (delete cookie) is implied by just setting the new one:
          store.updateCookie(oldCookie, cookie, next); // step 12
    
        } else {
          cookie.creation = cookie.lastAccessed = now;
          store.putCookie(cookie, next); // step 12
        }
      }
    
      store.findCookie(cookie.domain, cookie.path, cookie.key, withCookie);
    };
    
    // RFC6365 S5.4
    CAN_BE_SYNC.push('getCookies');
    CookieJar.prototype.getCookies = function(url, options, cb) {
      var context = getCookieContext(url);
      if (options instanceof Function) {
        cb = options;
        options = {};
      }
    
      var host = canonicalDomain(context.hostname);
      var path = context.pathname || '/';
    
      var secure = options.secure;
      if (secure == null && context.protocol &&
          (context.protocol == 'https:' || context.protocol == 'wss:'))
      {
        secure = true;
      }
    
      var http = options.http;
      if (http == null) {
        http = true;
      }
    
      var now = options.now || Date.now();
      var expireCheck = options.expire !== false;
      var allPaths = !!options.allPaths;
      var store = this.store;
    
      function matchingCookie(c) {
        // "Either:
        //   The cookie's host-only-flag is true and the canonicalized
        //   request-host is identical to the cookie's domain.
        // Or:
        //   The cookie's host-only-flag is false and the canonicalized
        //   request-host domain-matches the cookie's domain."
        if (c.hostOnly) {
          if (c.domain != host) {
            return false;
          }
        } else {
          if (!domainMatch(host, c.domain, false)) {
            return false;
          }
        }
    
        // "The request-uri's path path-matches the cookie's path."
        if (!allPaths && !pathMatch(path, c.path)) {
          return false;
        }
    
        // "If the cookie's secure-only-flag is true, then the request-uri's
        // scheme must denote a "secure" protocol"
        if (c.secure && !secure) {
          return false;
        }
    
        // "If the cookie's http-only-flag is true, then exclude the cookie if the
        // cookie-string is being generated for a "non-HTTP" API"
        if (c.httpOnly && !http) {
          return false;
        }
    
        // deferred from S5.3
        // non-RFC: allow retention of expired cookies by choice
        if (expireCheck && c.expiryTime() <= now) {
          store.removeCookie(c.domain, c.path, c.key, function(){}); // result ignored
          return false;
        }
    
        return true;
      }
    
      store.findCookies(host, allPaths ? null : path, function(err,cookies) {
        if (err) {
          return cb(err);
        }
    
        cookies = cookies.filter(matchingCookie);
    
        // sorting of S5.4 part 2
        if (options.sort !== false) {
          cookies = cookies.sort(cookieCompare);
        }
    
        // S5.4 part 3
        var now = new Date();
        cookies.forEach(function(c) {
          c.lastAccessed = now;
        });
        // TODO persist lastAccessed
    
        cb(null,cookies);
      });
    };
    
    CAN_BE_SYNC.push('getCookieString');
    CookieJar.prototype.getCookieString = function(/*..., cb*/) {
      var args = Array.prototype.slice.call(arguments,0);
      var cb = args.pop();
      var next = function(err,cookies) {
        if (err) {
          cb(err);
        } else {
          cb(null, cookies
            .sort(cookieCompare)
            .map(function(c){
              return c.cookieString();
            })
            .join('; '));
        }
      };
      args.push(next);
      this.getCookies.apply(this,args);
    };
    
    CAN_BE_SYNC.push('getSetCookieStrings');
    CookieJar.prototype.getSetCookieStrings = function(/*..., cb*/) {
      var args = Array.prototype.slice.call(arguments,0);
      var cb = args.pop();
      var next = function(err,cookies) {
        if (err) {
          cb(err);
        } else {
          cb(null, cookies.map(function(c){
            return c.toString();
          }));
        }
      };
      args.push(next);
      this.getCookies.apply(this,args);
    };
    
    CAN_BE_SYNC.push('serialize');
    CookieJar.prototype.serialize = function(cb) {
      var type = this.store.constructor.name;
      if (type === 'Object') {
        type = null;
      }
    
      // update README.md "Serialization Format" if you change this, please!
      var serialized = {
        // The version of tough-cookie that serialized this jar. Generally a good
        // practice since future versions can make data import decisions based on
        // known past behavior. When/if this matters, use `semver`.
        version: 'tough-cookie@'+VERSION,
    
        // add the store type, to make humans happy:
        storeType: type,
    
        // CookieJar configuration:
        rejectPublicSuffixes: !!this.rejectPublicSuffixes,
    
        // this gets filled from getAllCookies:
        cookies: []
      };
    
      if (!(this.store.getAllCookies &&
            typeof this.store.getAllCookies === 'function'))
      {
        return cb(new Error('store does not support getAllCookies and cannot be serialized'));
      }
    
      this.store.getAllCookies(function(err,cookies) {
        if (err) {
          return cb(err);
        }
    
        serialized.cookies = cookies.map(function(cookie) {
          // convert to serialized 'raw' cookies
          cookie = (cookie instanceof Cookie) ? cookie.toJSON() : cookie;
    
          // Remove the index so new ones get assigned during deserialization
          delete cookie.creationIndex;
    
          return cookie;
        });
    
        return cb(null, serialized);
      });
    };
    
    // well-known name that JSON.stringify calls
    CookieJar.prototype.toJSON = function() {
      return this.serializeSync();
    };
    
    // use the class method CookieJar.deserialize instead of calling this directly
    CAN_BE_SYNC.push('_importCookies');
    CookieJar.prototype._importCookies = function(serialized, cb) {
      var jar = this;
      var cookies = serialized.cookies;
      if (!cookies || !Array.isArray(cookies)) {
        return cb(new Error('serialized jar has no cookies array'));
      }
      cookies = cookies.slice(); // do not modify the original
    
      function putNext(err) {
        if (err) {
          return cb(err);
        }
    
        if (!cookies.length) {
          return cb(err, jar);
        }
    
        var cookie;
        try {
          cookie = fromJSON(cookies.shift());
        } catch (e) {
          return cb(e);
        }
    
        if (cookie === null) {
          return putNext(null); // skip this cookie
        }
    
        jar.store.putCookie(cookie, putNext);
      }
    
      putNext();
    };
    
    CookieJar.deserialize = function(strOrObj, store, cb) {
      if (arguments.length !== 3) {
        // store is optional
        cb = store;
        store = null;
      }
    
      var serialized;
      if (typeof strOrObj === 'string') {
        serialized = jsonParse(strOrObj);
        if (serialized instanceof Error) {
          return cb(serialized);
        }
      } else {
        serialized = strOrObj;
      }
    
      var jar = new CookieJar(store, serialized.rejectPublicSuffixes);
      jar._importCookies(serialized, function(err) {
        if (err) {
          return cb(err);
        }
        cb(null, jar);
      });
    };
    
    CookieJar.deserializeSync = function(strOrObj, store) {
      var serialized = typeof strOrObj === 'string' ?
        JSON.parse(strOrObj) : strOrObj;
      var jar = new CookieJar(store, serialized.rejectPublicSuffixes);
    
      // catch this mistake early:
      if (!jar.store.synchronous) {
        throw new Error('CookieJar store is not synchronous; use async API instead.');
      }
    
      jar._importCookiesSync(serialized);
      return jar;
    };
    CookieJar.fromJSON = CookieJar.deserializeSync;
    
    CookieJar.prototype.clone = function(newStore, cb) {
      if (arguments.length === 1) {
        cb = newStore;
        newStore = null;
      }
    
      this.serialize(function(err,serialized) {
        if (err) {
          return cb(err);
        }
        CookieJar.deserialize(serialized, newStore, cb);
      });
    };
    
    CAN_BE_SYNC.push('removeAllCookies');
    CookieJar.prototype.removeAllCookies = function(cb) {
      var store = this.store;
    
      // Check that the store implements its own removeAllCookies(). The default
      // implementation in Store will immediately call the callback with a "not
      // implemented" Error.
      if (store.removeAllCookies instanceof Function &&
          store.removeAllCookies !== Store.prototype.removeAllCookies)
      {
        return store.removeAllCookies(cb);
      }
    
      store.getAllCookies(function(err, cookies) {
        if (err) {
          return cb(err);
        }
    
        if (cookies.length === 0) {
          return cb(null);
        }
    
        var completedCount = 0;
        var removeErrors = [];
    
        function removeCookieCb(removeErr) {
          if (removeErr) {
            removeErrors.push(removeErr);
          }
    
          completedCount++;
    
          if (completedCount === cookies.length) {
            return cb(removeErrors.length ? removeErrors[0] : null);
          }
        }
    
        cookies.forEach(function(cookie) {
          store.removeCookie(cookie.domain, cookie.path, cookie.key, removeCookieCb);
        });
      });
    };
    
    CookieJar.prototype._cloneSync = syncWrap('clone');
    CookieJar.prototype.cloneSync = function(newStore) {
      if (!newStore.synchronous) {
        throw new Error('CookieJar clone destination store is not synchronous; use async API instead.');
      }
      return this._cloneSync(newStore);
    };
    
    // Use a closure to provide a true imperative API for synchronous stores.
    function syncWrap(method) {
      return function() {
        if (!this.store.synchronous) {
          throw new Error('CookieJar store is not synchronous; use async API instead.');
        }
    
        var args = Array.prototype.slice.call(arguments);
        var syncErr, syncResult;
        args.push(function syncCb(err, result) {
          syncErr = err;
          syncResult = result;
        });
        this[method].apply(this, args);
    
        if (syncErr) {
          throw syncErr;
        }
        return syncResult;
      };
    }
    
    // wrap all declared CAN_BE_SYNC methods in the sync wrapper
    CAN_BE_SYNC.forEach(function(method) {
      CookieJar.prototype[method+'Sync'] = syncWrap(method);
    });
    
    exports.version = VERSION;
    exports.CookieJar = CookieJar;
    exports.Cookie = Cookie;
    exports.Store = Store;
    exports.MemoryCookieStore = MemoryCookieStore;
    exports.parseDate = parseDate;
    exports.formatDate = formatDate;
    exports.parse = parse;
    exports.fromJSON = fromJSON;
    exports.domainMatch = domainMatch;
    exports.defaultPath = defaultPath;
    exports.pathMatch = pathMatch;
    exports.getPublicSuffix = pubsuffix.getPublicSuffix;
    exports.cookieCompare = cookieCompare;
    exports.permuteDomain = __webpack_require__(71).permuteDomain;
    exports.permutePath = permutePath;
    exports.canonicalDomain = canonicalDomain;
    
    
    /***/ }),
    /* 62 */
    /***/ ((module) => {
    
    "use strict";
    module.exports = require("net");
    
    /***/ }),
    /* 63 */
    /***/ ((module) => {
    
    "use strict";
    module.exports = require("url");
    
    /***/ }),
    /* 64 */
    /***/ ((module) => {
    
    "use strict";
    module.exports = require("util");
    
    /***/ }),
    /* 65 */
    /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
    
    "use strict";
    /*!
     * Copyright (c) 2018, Salesforce.com, Inc.
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice,
     * this list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form must reproduce the above copyright notice,
     * this list of conditions and the following disclaimer in the documentation
     * and/or other materials provided with the distribution.
     *
     * 3. Neither the name of Salesforce.com nor the names of its contributors may
     * be used to endorse or promote products derived from this software without
     * specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     * POSSIBILITY OF SUCH DAMAGE.
     */
    
    var psl = __webpack_require__(66);
    
    function getPublicSuffix(domain) {
      return psl.get(domain);
    }
    
    exports.getPublicSuffix = getPublicSuffix;
    
    
    /***/ }),
    /* 66 */
    /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
    
    "use strict";
    /*eslint no-var:0, prefer-arrow-callback: 0, object-shorthand: 0 */
    
    
    
    var Punycode = __webpack_require__(67);
    
    
    var internals = {};
    
    
    //
    // Read rules from file.
    //
    internals.rules = (__webpack_require__(68).map)(function (rule) {
    
      return {
        rule: rule,
        suffix: rule.replace(/^(\*\.|\!)/, ''),
        punySuffix: -1,
        wildcard: rule.charAt(0) === '*',
        exception: rule.charAt(0) === '!'
      };
    });
    
    
    //
    // Check is given string ends with `suffix`.
    //
    internals.endsWith = function (str, suffix) {
    
      return str.indexOf(suffix, str.length - suffix.length) !== -1;
    };
    
    
    //
    // Find rule for a given domain.
    //
    internals.findRule = function (domain) {
    
      var punyDomain = Punycode.toASCII(domain);
      return internals.rules.reduce(function (memo, rule) {
    
        if (rule.punySuffix === -1){
          rule.punySuffix = Punycode.toASCII(rule.suffix);
        }
        if (!internals.endsWith(punyDomain, '.' + rule.punySuffix) && punyDomain !== rule.punySuffix) {
          return memo;
        }
        // This has been commented out as it never seems to run. This is because
        // sub tlds always appear after their parents and we never find a shorter
        // match.
        //if (memo) {
        //  var memoSuffix = Punycode.toASCII(memo.suffix);
        //  if (memoSuffix.length >= punySuffix.length) {
        //    return memo;
        //  }
        //}
        return rule;
      }, null);
    };
    
    
    //
    // Error codes and messages.
    //
    exports.errorCodes = {
      DOMAIN_TOO_SHORT: 'Domain name too short.',
      DOMAIN_TOO_LONG: 'Domain name too long. It should be no more than 255 chars.',
      LABEL_STARTS_WITH_DASH: 'Domain name label can not start with a dash.',
      LABEL_ENDS_WITH_DASH: 'Domain name label can not end with a dash.',
      LABEL_TOO_LONG: 'Domain name label should be at most 63 chars long.',
      LABEL_TOO_SHORT: 'Domain name label should be at least 1 character long.',
      LABEL_INVALID_CHARS: 'Domain name label can only contain alphanumeric characters or dashes.'
    };