snyk 1.1236.0 → 1.1237.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -80490,1331 +80490,650 @@ module.exports.MaxBufferError = MaxBufferError;
80490
80490
 
80491
80491
  /***/ }),
80492
80492
 
80493
- /***/ 59844:
80494
- /***/ ((module) => {
80493
+ /***/ 93481:
80494
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
80495
80495
 
80496
80496
  "use strict";
80497
80497
 
80498
- // rfc7231 6.1
80499
- const statusCodeCacheableByDefault = new Set([
80500
- 200,
80501
- 203,
80502
- 204,
80503
- 206,
80504
- 300,
80505
- 301,
80506
- 404,
80507
- 405,
80508
- 410,
80509
- 414,
80510
- 501,
80511
- ]);
80512
-
80513
- // This implementation does not understand partial responses (206)
80514
- const understoodStatuses = new Set([
80515
- 200,
80516
- 203,
80517
- 204,
80518
- 300,
80519
- 301,
80520
- 302,
80521
- 303,
80522
- 307,
80523
- 308,
80524
- 404,
80525
- 405,
80526
- 410,
80527
- 414,
80528
- 501,
80529
- ]);
80530
80498
 
80531
- const errorStatusCodes = new Set([
80532
- 500,
80533
- 502,
80534
- 503,
80535
- 504,
80536
- ]);
80499
+ const EventEmitter = __webpack_require__(82361);
80500
+ const urlLib = __webpack_require__(57310);
80501
+ const normalizeUrl = __webpack_require__(40015);
80502
+ const getStream = __webpack_require__(50404);
80503
+ const CachePolicy = __webpack_require__(26214);
80504
+ const Response = __webpack_require__(24259);
80505
+ const lowercaseKeys = __webpack_require__(25989);
80506
+ const cloneResponse = __webpack_require__(79715);
80507
+ const Keyv = __webpack_require__(64958);
80537
80508
 
80538
- const hopByHopHeaders = {
80539
- date: true, // included, because we add Age update Date
80540
- connection: true,
80541
- 'keep-alive': true,
80542
- 'proxy-authenticate': true,
80543
- 'proxy-authorization': true,
80544
- te: true,
80545
- trailer: true,
80546
- 'transfer-encoding': true,
80547
- upgrade: true,
80548
- };
80509
+ class CacheableRequest {
80510
+ constructor(request, cacheAdapter) {
80511
+ if (typeof request !== 'function') {
80512
+ throw new TypeError('Parameter `request` must be a function');
80513
+ }
80549
80514
 
80550
- const excludedFromRevalidationUpdate = {
80551
- // Since the old body is reused, it doesn't make sense to change properties of the body
80552
- 'content-length': true,
80553
- 'content-encoding': true,
80554
- 'transfer-encoding': true,
80555
- 'content-range': true,
80556
- };
80515
+ this.cache = new Keyv({
80516
+ uri: typeof cacheAdapter === 'string' && cacheAdapter,
80517
+ store: typeof cacheAdapter !== 'string' && cacheAdapter,
80518
+ namespace: 'cacheable-request'
80519
+ });
80557
80520
 
80558
- function toNumberOrZero(s) {
80559
- const n = parseInt(s, 10);
80560
- return isFinite(n) ? n : 0;
80561
- }
80521
+ return this.createCacheableRequest(request);
80522
+ }
80562
80523
 
80563
- // RFC 5861
80564
- function isErrorResponse(response) {
80565
- // consider undefined response as faulty
80566
- if(!response) {
80567
- return true
80568
- }
80569
- return errorStatusCodes.has(response.status);
80570
- }
80524
+ createCacheableRequest(request) {
80525
+ return (opts, cb) => {
80526
+ let url;
80527
+ if (typeof opts === 'string') {
80528
+ url = normalizeUrlObject(urlLib.parse(opts));
80529
+ opts = {};
80530
+ } else if (opts instanceof urlLib.URL) {
80531
+ url = normalizeUrlObject(urlLib.parse(opts.toString()));
80532
+ opts = {};
80533
+ } else {
80534
+ const [pathname, ...searchParts] = (opts.path || '').split('?');
80535
+ const search = searchParts.length > 0 ?
80536
+ `?${searchParts.join('?')}` :
80537
+ '';
80538
+ url = normalizeUrlObject({ ...opts, pathname, search });
80539
+ }
80571
80540
 
80572
- function parseCacheControl(header) {
80573
- const cc = {};
80574
- if (!header) return cc;
80541
+ opts = {
80542
+ headers: {},
80543
+ method: 'GET',
80544
+ cache: true,
80545
+ strictTtl: false,
80546
+ automaticFailover: false,
80547
+ ...opts,
80548
+ ...urlObjectToRequestOptions(url)
80549
+ };
80550
+ opts.headers = lowercaseKeys(opts.headers);
80575
80551
 
80576
- // TODO: When there is more than one value present for a given directive (e.g., two Expires header fields, multiple Cache-Control: max-age directives),
80577
- // the directive's value is considered invalid. Caches are encouraged to consider responses that have invalid freshness information to be stale
80578
- const parts = header.trim().split(/\s*,\s*/); // TODO: lame parsing
80579
- for (const part of parts) {
80580
- const [k, v] = part.split(/\s*=\s*/, 2);
80581
- cc[k] = v === undefined ? true : v.replace(/^"|"$/g, ''); // TODO: lame unquoting
80582
- }
80552
+ const ee = new EventEmitter();
80553
+ const normalizedUrlString = normalizeUrl(
80554
+ urlLib.format(url),
80555
+ {
80556
+ stripWWW: false,
80557
+ removeTrailingSlash: false,
80558
+ stripAuthentication: false
80559
+ }
80560
+ );
80561
+ const key = `${opts.method}:${normalizedUrlString}`;
80562
+ let revalidate = false;
80563
+ let madeRequest = false;
80583
80564
 
80584
- return cc;
80585
- }
80565
+ const makeRequest = opts => {
80566
+ madeRequest = true;
80567
+ let requestErrored = false;
80568
+ let requestErrorCallback;
80586
80569
 
80587
- function formatCacheControl(cc) {
80588
- let parts = [];
80589
- for (const k in cc) {
80590
- const v = cc[k];
80591
- parts.push(v === true ? k : k + '=' + v);
80592
- }
80593
- if (!parts.length) {
80594
- return undefined;
80595
- }
80596
- return parts.join(', ');
80597
- }
80570
+ const requestErrorPromise = new Promise(resolve => {
80571
+ requestErrorCallback = () => {
80572
+ if (!requestErrored) {
80573
+ requestErrored = true;
80574
+ resolve();
80575
+ }
80576
+ };
80577
+ });
80598
80578
 
80599
- module.exports = class CachePolicy {
80600
- constructor(
80601
- req,
80602
- res,
80603
- {
80604
- shared,
80605
- cacheHeuristic,
80606
- immutableMinTimeToLive,
80607
- ignoreCargoCult,
80608
- _fromObject,
80609
- } = {}
80610
- ) {
80611
- if (_fromObject) {
80612
- this._fromObject(_fromObject);
80613
- return;
80614
- }
80579
+ const handler = response => {
80580
+ if (revalidate && !opts.forceRefresh) {
80581
+ response.status = response.statusCode;
80582
+ const revalidatedPolicy = CachePolicy.fromObject(revalidate.cachePolicy).revalidatedPolicy(opts, response);
80583
+ if (!revalidatedPolicy.modified) {
80584
+ const headers = revalidatedPolicy.policy.responseHeaders();
80585
+ response = new Response(revalidate.statusCode, headers, revalidate.body, revalidate.url);
80586
+ response.cachePolicy = revalidatedPolicy.policy;
80587
+ response.fromCache = true;
80588
+ }
80589
+ }
80615
80590
 
80616
- if (!res || !res.headers) {
80617
- throw Error('Response headers missing');
80618
- }
80619
- this._assertRequestHasHeaders(req);
80591
+ if (!response.fromCache) {
80592
+ response.cachePolicy = new CachePolicy(opts, response, opts);
80593
+ response.fromCache = false;
80594
+ }
80620
80595
 
80621
- this._responseTime = this.now();
80622
- this._isShared = shared !== false;
80623
- this._cacheHeuristic =
80624
- undefined !== cacheHeuristic ? cacheHeuristic : 0.1; // 10% matches IE
80625
- this._immutableMinTtl =
80626
- undefined !== immutableMinTimeToLive
80627
- ? immutableMinTimeToLive
80628
- : 24 * 3600 * 1000;
80596
+ let clonedResponse;
80597
+ if (opts.cache && response.cachePolicy.storable()) {
80598
+ clonedResponse = cloneResponse(response);
80629
80599
 
80630
- this._status = 'status' in res ? res.status : 200;
80631
- this._resHeaders = res.headers;
80632
- this._rescc = parseCacheControl(res.headers['cache-control']);
80633
- this._method = 'method' in req ? req.method : 'GET';
80634
- this._url = req.url;
80635
- this._host = req.headers.host;
80636
- this._noAuthorization = !req.headers.authorization;
80637
- this._reqHeaders = res.headers.vary ? req.headers : null; // Don't keep all request headers if they won't be used
80638
- this._reqcc = parseCacheControl(req.headers['cache-control']);
80600
+ (async () => {
80601
+ try {
80602
+ const bodyPromise = getStream.buffer(response);
80639
80603
 
80640
- // Assume that if someone uses legacy, non-standard uncecessary options they don't understand caching,
80641
- // so there's no point stricly adhering to the blindly copy&pasted directives.
80642
- if (
80643
- ignoreCargoCult &&
80644
- 'pre-check' in this._rescc &&
80645
- 'post-check' in this._rescc
80646
- ) {
80647
- delete this._rescc['pre-check'];
80648
- delete this._rescc['post-check'];
80649
- delete this._rescc['no-cache'];
80650
- delete this._rescc['no-store'];
80651
- delete this._rescc['must-revalidate'];
80652
- this._resHeaders = Object.assign({}, this._resHeaders, {
80653
- 'cache-control': formatCacheControl(this._rescc),
80654
- });
80655
- delete this._resHeaders.expires;
80656
- delete this._resHeaders.pragma;
80657
- }
80604
+ await Promise.race([
80605
+ requestErrorPromise,
80606
+ new Promise(resolve => response.once('end', resolve))
80607
+ ]);
80658
80608
 
80659
- // When the Cache-Control header field is not present in a request, caches MUST consider the no-cache request pragma-directive
80660
- // as having the same effect as if "Cache-Control: no-cache" were present (see Section 5.2.1).
80661
- if (
80662
- res.headers['cache-control'] == null &&
80663
- /no-cache/.test(res.headers.pragma)
80664
- ) {
80665
- this._rescc['no-cache'] = true;
80666
- }
80667
- }
80609
+ if (requestErrored) {
80610
+ return;
80611
+ }
80668
80612
 
80669
- now() {
80670
- return Date.now();
80671
- }
80613
+ const body = await bodyPromise;
80672
80614
 
80673
- storable() {
80674
- // The "no-store" request directive indicates that a cache MUST NOT store any part of either this request or any response to it.
80675
- return !!(
80676
- !this._reqcc['no-store'] &&
80677
- // A cache MUST NOT store a response to any request, unless:
80678
- // The request method is understood by the cache and defined as being cacheable, and
80679
- ('GET' === this._method ||
80680
- 'HEAD' === this._method ||
80681
- ('POST' === this._method && this._hasExplicitExpiration())) &&
80682
- // the response status code is understood by the cache, and
80683
- understoodStatuses.has(this._status) &&
80684
- // the "no-store" cache directive does not appear in request or response header fields, and
80685
- !this._rescc['no-store'] &&
80686
- // the "private" response directive does not appear in the response, if the cache is shared, and
80687
- (!this._isShared || !this._rescc.private) &&
80688
- // the Authorization header field does not appear in the request, if the cache is shared,
80689
- (!this._isShared ||
80690
- this._noAuthorization ||
80691
- this._allowsStoringAuthenticated()) &&
80692
- // the response either:
80693
- // contains an Expires header field, or
80694
- (this._resHeaders.expires ||
80695
- // contains a max-age response directive, or
80696
- // contains a s-maxage response directive and the cache is shared, or
80697
- // contains a public response directive.
80698
- this._rescc['max-age'] ||
80699
- (this._isShared && this._rescc['s-maxage']) ||
80700
- this._rescc.public ||
80701
- // has a status code that is defined as cacheable by default
80702
- statusCodeCacheableByDefault.has(this._status))
80703
- );
80704
- }
80615
+ const value = {
80616
+ cachePolicy: response.cachePolicy.toObject(),
80617
+ url: response.url,
80618
+ statusCode: response.fromCache ? revalidate.statusCode : response.statusCode,
80619
+ body
80620
+ };
80705
80621
 
80706
- _hasExplicitExpiration() {
80707
- // 4.2.1 Calculating Freshness Lifetime
80708
- return (
80709
- (this._isShared && this._rescc['s-maxage']) ||
80710
- this._rescc['max-age'] ||
80711
- this._resHeaders.expires
80712
- );
80713
- }
80622
+ let ttl = opts.strictTtl ? response.cachePolicy.timeToLive() : undefined;
80623
+ if (opts.maxTtl) {
80624
+ ttl = ttl ? Math.min(ttl, opts.maxTtl) : opts.maxTtl;
80625
+ }
80714
80626
 
80715
- _assertRequestHasHeaders(req) {
80716
- if (!req || !req.headers) {
80717
- throw Error('Request headers missing');
80718
- }
80719
- }
80627
+ await this.cache.set(key, value, ttl);
80628
+ } catch (error) {
80629
+ ee.emit('error', new CacheableRequest.CacheError(error));
80630
+ }
80631
+ })();
80632
+ } else if (opts.cache && revalidate) {
80633
+ (async () => {
80634
+ try {
80635
+ await this.cache.delete(key);
80636
+ } catch (error) {
80637
+ ee.emit('error', new CacheableRequest.CacheError(error));
80638
+ }
80639
+ })();
80640
+ }
80720
80641
 
80721
- satisfiesWithoutRevalidation(req) {
80722
- this._assertRequestHasHeaders(req);
80642
+ ee.emit('response', clonedResponse || response);
80643
+ if (typeof cb === 'function') {
80644
+ cb(clonedResponse || response);
80645
+ }
80646
+ };
80723
80647
 
80724
- // When presented with a request, a cache MUST NOT reuse a stored response, unless:
80725
- // the presented request does not contain the no-cache pragma (Section 5.4), nor the no-cache cache directive,
80726
- // unless the stored response is successfully validated (Section 4.3), and
80727
- const requestCC = parseCacheControl(req.headers['cache-control']);
80728
- if (requestCC['no-cache'] || /no-cache/.test(req.headers.pragma)) {
80729
- return false;
80730
- }
80648
+ try {
80649
+ const req = request(opts, handler);
80650
+ req.once('error', requestErrorCallback);
80651
+ req.once('abort', requestErrorCallback);
80652
+ ee.emit('request', req);
80653
+ } catch (error) {
80654
+ ee.emit('error', new CacheableRequest.RequestError(error));
80655
+ }
80656
+ };
80731
80657
 
80732
- if (requestCC['max-age'] && this.age() > requestCC['max-age']) {
80733
- return false;
80734
- }
80658
+ (async () => {
80659
+ const get = async opts => {
80660
+ await Promise.resolve();
80735
80661
 
80736
- if (
80737
- requestCC['min-fresh'] &&
80738
- this.timeToLive() < 1000 * requestCC['min-fresh']
80739
- ) {
80740
- return false;
80741
- }
80662
+ const cacheEntry = opts.cache ? await this.cache.get(key) : undefined;
80663
+ if (typeof cacheEntry === 'undefined') {
80664
+ return makeRequest(opts);
80665
+ }
80742
80666
 
80743
- // the stored response is either:
80744
- // fresh, or allowed to be served stale
80745
- if (this.stale()) {
80746
- const allowsStale =
80747
- requestCC['max-stale'] &&
80748
- !this._rescc['must-revalidate'] &&
80749
- (true === requestCC['max-stale'] ||
80750
- requestCC['max-stale'] > this.age() - this.maxAge());
80751
- if (!allowsStale) {
80752
- return false;
80753
- }
80754
- }
80667
+ const policy = CachePolicy.fromObject(cacheEntry.cachePolicy);
80668
+ if (policy.satisfiesWithoutRevalidation(opts) && !opts.forceRefresh) {
80669
+ const headers = policy.responseHeaders();
80670
+ const response = new Response(cacheEntry.statusCode, headers, cacheEntry.body, cacheEntry.url);
80671
+ response.cachePolicy = policy;
80672
+ response.fromCache = true;
80755
80673
 
80756
- return this._requestMatches(req, false);
80757
- }
80674
+ ee.emit('response', response);
80675
+ if (typeof cb === 'function') {
80676
+ cb(response);
80677
+ }
80678
+ } else {
80679
+ revalidate = cacheEntry;
80680
+ opts.headers = policy.revalidationHeaders(opts);
80681
+ makeRequest(opts);
80682
+ }
80683
+ };
80758
80684
 
80759
- _requestMatches(req, allowHeadMethod) {
80760
- // The presented effective request URI and that of the stored response match, and
80761
- return (
80762
- (!this._url || this._url === req.url) &&
80763
- this._host === req.headers.host &&
80764
- // the request method associated with the stored response allows it to be used for the presented request, and
80765
- (!req.method ||
80766
- this._method === req.method ||
80767
- (allowHeadMethod && 'HEAD' === req.method)) &&
80768
- // selecting header fields nominated by the stored response (if any) match those presented, and
80769
- this._varyMatches(req)
80770
- );
80771
- }
80685
+ const errorHandler = error => ee.emit('error', new CacheableRequest.CacheError(error));
80686
+ this.cache.once('error', errorHandler);
80687
+ ee.on('response', () => this.cache.removeListener('error', errorHandler));
80772
80688
 
80773
- _allowsStoringAuthenticated() {
80774
- // following Cache-Control response directives (Section 5.2.2) have such an effect: must-revalidate, public, and s-maxage.
80775
- return (
80776
- this._rescc['must-revalidate'] ||
80777
- this._rescc.public ||
80778
- this._rescc['s-maxage']
80779
- );
80780
- }
80689
+ try {
80690
+ await get(opts);
80691
+ } catch (error) {
80692
+ if (opts.automaticFailover && !madeRequest) {
80693
+ makeRequest(opts);
80694
+ }
80781
80695
 
80782
- _varyMatches(req) {
80783
- if (!this._resHeaders.vary) {
80784
- return true;
80785
- }
80696
+ ee.emit('error', new CacheableRequest.CacheError(error));
80697
+ }
80698
+ })();
80786
80699
 
80787
- // A Vary header field-value of "*" always fails to match
80788
- if (this._resHeaders.vary === '*') {
80789
- return false;
80790
- }
80700
+ return ee;
80701
+ };
80702
+ }
80703
+ }
80791
80704
 
80792
- const fields = this._resHeaders.vary
80793
- .trim()
80794
- .toLowerCase()
80795
- .split(/\s*,\s*/);
80796
- for (const name of fields) {
80797
- if (req.headers[name] !== this._reqHeaders[name]) return false;
80798
- }
80799
- return true;
80800
- }
80705
+ function urlObjectToRequestOptions(url) {
80706
+ const options = { ...url };
80707
+ options.path = `${url.pathname || '/'}${url.search || ''}`;
80708
+ delete options.pathname;
80709
+ delete options.search;
80710
+ return options;
80711
+ }
80801
80712
 
80802
- _copyWithoutHopByHopHeaders(inHeaders) {
80803
- const headers = {};
80804
- for (const name in inHeaders) {
80805
- if (hopByHopHeaders[name]) continue;
80806
- headers[name] = inHeaders[name];
80807
- }
80808
- // 9.1. Connection
80809
- if (inHeaders.connection) {
80810
- const tokens = inHeaders.connection.trim().split(/\s*,\s*/);
80811
- for (const name of tokens) {
80812
- delete headers[name];
80813
- }
80814
- }
80815
- if (headers.warning) {
80816
- const warnings = headers.warning.split(/,/).filter(warning => {
80817
- return !/^\s*1[0-9][0-9]/.test(warning);
80818
- });
80819
- if (!warnings.length) {
80820
- delete headers.warning;
80821
- } else {
80822
- headers.warning = warnings.join(',').trim();
80823
- }
80824
- }
80825
- return headers;
80826
- }
80713
+ function normalizeUrlObject(url) {
80714
+ // If url was parsed by url.parse or new URL:
80715
+ // - hostname will be set
80716
+ // - host will be hostname[:port]
80717
+ // - port will be set if it was explicit in the parsed string
80718
+ // Otherwise, url was from request options:
80719
+ // - hostname or host may be set
80720
+ // - host shall not have port encoded
80721
+ return {
80722
+ protocol: url.protocol,
80723
+ auth: url.auth,
80724
+ hostname: url.hostname || url.host || 'localhost',
80725
+ port: url.port,
80726
+ pathname: url.pathname,
80727
+ search: url.search
80728
+ };
80729
+ }
80827
80730
 
80828
- responseHeaders() {
80829
- const headers = this._copyWithoutHopByHopHeaders(this._resHeaders);
80830
- const age = this.age();
80731
+ CacheableRequest.RequestError = class extends Error {
80732
+ constructor(error) {
80733
+ super(error.message);
80734
+ this.name = 'RequestError';
80735
+ Object.assign(this, error);
80736
+ }
80737
+ };
80831
80738
 
80832
- // A cache SHOULD generate 113 warning if it heuristically chose a freshness
80833
- // lifetime greater than 24 hours and the response's age is greater than 24 hours.
80834
- if (
80835
- age > 3600 * 24 &&
80836
- !this._hasExplicitExpiration() &&
80837
- this.maxAge() > 3600 * 24
80838
- ) {
80839
- headers.warning =
80840
- (headers.warning ? `${headers.warning}, ` : '') +
80841
- '113 - "rfc7234 5.5.4"';
80842
- }
80843
- headers.age = `${Math.round(age)}`;
80844
- headers.date = new Date(this.now()).toUTCString();
80845
- return headers;
80846
- }
80739
+ CacheableRequest.CacheError = class extends Error {
80740
+ constructor(error) {
80741
+ super(error.message);
80742
+ this.name = 'CacheError';
80743
+ Object.assign(this, error);
80744
+ }
80745
+ };
80847
80746
 
80848
- /**
80849
- * Value of the Date response header or current time if Date was invalid
80850
- * @return timestamp
80851
- */
80852
- date() {
80853
- const serverDate = Date.parse(this._resHeaders.date);
80854
- if (isFinite(serverDate)) {
80855
- return serverDate;
80856
- }
80857
- return this._responseTime;
80858
- }
80747
+ module.exports = CacheableRequest;
80859
80748
 
80860
- /**
80861
- * Value of the Age header, in seconds, updated for the current time.
80862
- * May be fractional.
80863
- *
80864
- * @return Number
80865
- */
80866
- age() {
80867
- let age = this._ageValue();
80868
80749
 
80869
- const residentTime = (this.now() - this._responseTime) / 1000;
80870
- return age + residentTime;
80871
- }
80750
+ /***/ }),
80872
80751
 
80873
- _ageValue() {
80874
- return toNumberOrZero(this._resHeaders.age);
80875
- }
80752
+ /***/ 75281:
80753
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
80876
80754
 
80877
- /**
80878
- * Value of applicable max-age (or heuristic equivalent) in seconds. This counts since response's `Date`.
80879
- *
80880
- * For an up-to-date value, see `timeToLive()`.
80881
- *
80882
- * @return Number
80883
- */
80884
- maxAge() {
80885
- if (!this.storable() || this._rescc['no-cache']) {
80886
- return 0;
80887
- }
80755
+ "use strict";
80888
80756
 
80889
- // Shared responses with cookies are cacheable according to the RFC, but IMHO it'd be unwise to do so by default
80890
- // so this implementation requires explicit opt-in via public header
80891
- if (
80892
- this._isShared &&
80893
- (this._resHeaders['set-cookie'] &&
80894
- !this._rescc.public &&
80895
- !this._rescc.immutable)
80896
- ) {
80897
- return 0;
80898
- }
80757
+ const os = __webpack_require__(22037);
80899
80758
 
80900
- if (this._resHeaders.vary === '*') {
80901
- return 0;
80902
- }
80759
+ const extractPathRegex = /\s+at.*(?:\(|\s)(.*)\)?/;
80760
+ const pathRegex = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:babel-polyfill|pirates)\/.*)?\w+)\.js:\d+:\d+)|native)/;
80761
+ const homeDir = typeof os.homedir === 'undefined' ? '' : os.homedir();
80903
80762
 
80904
- if (this._isShared) {
80905
- if (this._rescc['proxy-revalidate']) {
80906
- return 0;
80907
- }
80908
- // if a response includes the s-maxage directive, a shared cache recipient MUST ignore the Expires field.
80909
- if (this._rescc['s-maxage']) {
80910
- return toNumberOrZero(this._rescc['s-maxage']);
80911
- }
80912
- }
80763
+ module.exports = (stack, options) => {
80764
+ options = Object.assign({pretty: false}, options);
80913
80765
 
80914
- // If a response includes a Cache-Control field with the max-age directive, a recipient MUST ignore the Expires field.
80915
- if (this._rescc['max-age']) {
80916
- return toNumberOrZero(this._rescc['max-age']);
80917
- }
80766
+ return stack.replace(/\\/g, '/')
80767
+ .split('\n')
80768
+ .filter(line => {
80769
+ const pathMatches = line.match(extractPathRegex);
80770
+ if (pathMatches === null || !pathMatches[1]) {
80771
+ return true;
80772
+ }
80918
80773
 
80919
- const defaultMinTtl = this._rescc.immutable ? this._immutableMinTtl : 0;
80774
+ const match = pathMatches[1];
80920
80775
 
80921
- const serverDate = this.date();
80922
- if (this._resHeaders.expires) {
80923
- const expires = Date.parse(this._resHeaders.expires);
80924
- // A cache recipient MUST interpret invalid date formats, especially the value "0", as representing a time in the past (i.e., "already expired").
80925
- if (Number.isNaN(expires) || expires < serverDate) {
80926
- return 0;
80927
- }
80928
- return Math.max(defaultMinTtl, (expires - serverDate) / 1000);
80929
- }
80776
+ // Electron
80777
+ if (
80778
+ match.includes('.app/Contents/Resources/electron.asar') ||
80779
+ match.includes('.app/Contents/Resources/default_app.asar')
80780
+ ) {
80781
+ return false;
80782
+ }
80930
80783
 
80931
- if (this._resHeaders['last-modified']) {
80932
- const lastModified = Date.parse(this._resHeaders['last-modified']);
80933
- if (isFinite(lastModified) && serverDate > lastModified) {
80934
- return Math.max(
80935
- defaultMinTtl,
80936
- ((serverDate - lastModified) / 1000) * this._cacheHeuristic
80937
- );
80938
- }
80939
- }
80784
+ return !pathRegex.test(match);
80785
+ })
80786
+ .filter(line => line.trim() !== '')
80787
+ .map(line => {
80788
+ if (options.pretty) {
80789
+ return line.replace(extractPathRegex, (m, p1) => m.replace(p1, p1.replace(homeDir, '~')));
80790
+ }
80940
80791
 
80941
- return defaultMinTtl;
80942
- }
80792
+ return line;
80793
+ })
80794
+ .join('\n');
80795
+ };
80943
80796
 
80944
- timeToLive() {
80945
- const age = this.maxAge() - this.age();
80946
- const staleIfErrorAge = age + toNumberOrZero(this._rescc['stale-if-error']);
80947
- const staleWhileRevalidateAge = age + toNumberOrZero(this._rescc['stale-while-revalidate']);
80948
- return Math.max(0, age, staleIfErrorAge, staleWhileRevalidateAge) * 1000;
80949
- }
80950
80797
 
80951
- stale() {
80952
- return this.maxAge() <= this.age();
80953
- }
80798
+ /***/ }),
80954
80799
 
80955
- _useStaleIfError() {
80956
- return this.maxAge() + toNumberOrZero(this._rescc['stale-if-error']) > this.age();
80957
- }
80800
+ /***/ 87730:
80801
+ /***/ ((__unused_webpack_module, exports) => {
80958
80802
 
80959
- useStaleWhileRevalidate() {
80960
- return this.maxAge() + toNumberOrZero(this._rescc['stale-while-revalidate']) > this.age();
80961
- }
80803
+ "use strict";
80962
80804
 
80963
- static fromObject(obj) {
80964
- return new this(undefined, undefined, { _fromObject: obj });
80965
- }
80966
80805
 
80967
- _fromObject(obj) {
80968
- if (this._responseTime) throw Error('Reinitialized');
80969
- if (!obj || obj.v !== 1) throw Error('Invalid serialization');
80806
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
80970
80807
 
80971
- this._responseTime = obj.t;
80972
- this._isShared = obj.sh;
80973
- this._cacheHeuristic = obj.ch;
80974
- this._immutableMinTtl =
80975
- obj.imm !== undefined ? obj.imm : 24 * 3600 * 1000;
80976
- this._status = obj.st;
80977
- this._resHeaders = obj.resh;
80978
- this._rescc = obj.rescc;
80979
- this._method = obj.m;
80980
- this._url = obj.u;
80981
- this._host = obj.h;
80982
- this._noAuthorization = obj.a;
80983
- this._reqHeaders = obj.reqh;
80984
- this._reqcc = obj.reqcc;
80985
- }
80808
+ const NODE_INITIAL = 0;
80809
+ const NODE_SUCCESS = 1;
80810
+ const NODE_ERRORED = 2;
80811
+ const START_OF_INPUT = `\u0001`;
80812
+ const END_OF_INPUT = `\u0000`;
80813
+ const HELP_COMMAND_INDEX = -1;
80814
+ const HELP_REGEX = /^(-h|--help)(?:=([0-9]+))?$/;
80815
+ const OPTION_REGEX = /^(--[a-z]+(?:-[a-z]+)*|-[a-zA-Z]+)$/;
80816
+ const BATCH_REGEX = /^-[a-zA-Z]{2,}$/;
80817
+ const BINDING_REGEX = /^([^=]+)=([\s\S]*)$/;
80818
+ const DEBUG = process.env.DEBUG_CLI === `1`;
80986
80819
 
80987
- toObject() {
80988
- return {
80989
- v: 1,
80990
- t: this._responseTime,
80991
- sh: this._isShared,
80992
- ch: this._cacheHeuristic,
80993
- imm: this._immutableMinTtl,
80994
- st: this._status,
80995
- resh: this._resHeaders,
80996
- rescc: this._rescc,
80997
- m: this._method,
80998
- u: this._url,
80999
- h: this._host,
81000
- a: this._noAuthorization,
81001
- reqh: this._reqHeaders,
81002
- reqcc: this._reqcc,
81003
- };
80820
+ /**
80821
+ * A generic usage error with the name `UsageError`.
80822
+ *
80823
+ * It should be used over `Error` only when it's the user's fault.
80824
+ */
80825
+ class UsageError extends Error {
80826
+ constructor(message) {
80827
+ super(message);
80828
+ this.clipanion = { type: `usage` };
80829
+ this.name = `UsageError`;
81004
80830
  }
81005
-
81006
- /**
81007
- * Headers for sending to the origin server to revalidate stale response.
81008
- * Allows server to return 304 to allow reuse of the previous response.
81009
- *
81010
- * Hop by hop headers are always stripped.
81011
- * Revalidation headers may be added or removed, depending on request.
81012
- */
81013
- revalidationHeaders(incomingReq) {
81014
- this._assertRequestHasHeaders(incomingReq);
81015
- const headers = this._copyWithoutHopByHopHeaders(incomingReq.headers);
81016
-
81017
- // This implementation does not understand range requests
81018
- delete headers['if-range'];
81019
-
81020
- if (!this._requestMatches(incomingReq, true) || !this.storable()) {
81021
- // revalidation allowed via HEAD
81022
- // not for the same resource, or wasn't allowed to be cached anyway
81023
- delete headers['if-none-match'];
81024
- delete headers['if-modified-since'];
81025
- return headers;
80831
+ }
80832
+ class UnknownSyntaxError extends Error {
80833
+ constructor(input, candidates) {
80834
+ super();
80835
+ this.input = input;
80836
+ this.candidates = candidates;
80837
+ this.clipanion = { type: `none` };
80838
+ this.name = `UnknownSyntaxError`;
80839
+ if (this.candidates.length === 0) {
80840
+ this.message = `Command not found, but we're not sure what's the alternative.`;
81026
80841
  }
81027
-
81028
- /* MUST send that entity-tag in any cache validation request (using If-Match or If-None-Match) if an entity-tag has been provided by the origin server. */
81029
- if (this._resHeaders.etag) {
81030
- headers['if-none-match'] = headers['if-none-match']
81031
- ? `${headers['if-none-match']}, ${this._resHeaders.etag}`
81032
- : this._resHeaders.etag;
80842
+ else if (this.candidates.length === 1 && this.candidates[0].reason !== null) {
80843
+ const [{ usage, reason }] = this.candidates;
80844
+ this.message = `${reason}\n\n$ ${usage}`;
81033
80845
  }
80846
+ else if (this.candidates.length === 1) {
80847
+ const [{ usage }] = this.candidates;
80848
+ this.message = `Command not found; did you mean:\n\n$ ${usage}\n${whileRunning(input)}`;
80849
+ }
80850
+ else {
80851
+ this.message = `Command not found; did you mean one of:\n\n${this.candidates.map(({ usage }, index) => {
80852
+ return `${`${index}.`.padStart(4)} ${usage}`;
80853
+ }).join(`\n`)}\n\n${whileRunning(input)}`;
80854
+ }
80855
+ }
80856
+ }
80857
+ class AmbiguousSyntaxError extends Error {
80858
+ constructor(input, usages) {
80859
+ super();
80860
+ this.input = input;
80861
+ this.usages = usages;
80862
+ this.clipanion = { type: `none` };
80863
+ this.name = `AmbiguousSyntaxError`;
80864
+ this.message = `Cannot find who to pick amongst the following alternatives:\n\n${this.usages.map((usage, index) => {
80865
+ return `${`${index}.`.padStart(4)} ${usage}`;
80866
+ }).join(`\n`)}\n\n${whileRunning(input)}`;
80867
+ }
80868
+ }
80869
+ const whileRunning = (input) => `While running ${input.filter(token => {
80870
+ return token !== END_OF_INPUT;
80871
+ }).map(token => {
80872
+ const json = JSON.stringify(token);
80873
+ if (token.match(/\s/) || token.length === 0 || json !== `"${token}"`) {
80874
+ return json;
80875
+ }
80876
+ else {
80877
+ return token;
80878
+ }
80879
+ }).join(` `)}`;
81034
80880
 
81035
- // Clients MAY issue simple (non-subrange) GET requests with either weak validators or strong validators. Clients MUST NOT use weak validators in other forms of request.
81036
- const forbidsWeakValidators =
81037
- headers['accept-ranges'] ||
81038
- headers['if-match'] ||
81039
- headers['if-unmodified-since'] ||
81040
- (this._method && this._method != 'GET');
81041
-
81042
- /* SHOULD send the Last-Modified value in non-subrange cache validation requests (using If-Modified-Since) if only a Last-Modified value has been provided by the origin server.
81043
- Note: This implementation does not understand partial responses (206) */
81044
- if (forbidsWeakValidators) {
81045
- delete headers['if-modified-since'];
81046
-
81047
- if (headers['if-none-match']) {
81048
- const etags = headers['if-none-match']
81049
- .split(/,/)
81050
- .filter(etag => {
81051
- return !/^\s*W\//.test(etag);
81052
- });
81053
- if (!etags.length) {
81054
- delete headers['if-none-match'];
81055
- } else {
81056
- headers['if-none-match'] = etags.join(',').trim();
80881
+ // ------------------------------------------------------------------------
80882
+ function debug(str) {
80883
+ if (DEBUG) {
80884
+ console.log(str);
80885
+ }
80886
+ }
80887
+ const basicHelpState = {
80888
+ candidateUsage: null,
80889
+ errorMessage: null,
80890
+ ignoreOptions: false,
80891
+ path: [],
80892
+ positionals: [],
80893
+ options: [],
80894
+ remainder: null,
80895
+ selectedIndex: HELP_COMMAND_INDEX
80896
+ };
80897
+ function makeStateMachine() {
80898
+ return {
80899
+ nodes: [makeNode(), makeNode(), makeNode()],
80900
+ };
80901
+ }
80902
+ function makeAnyOfMachine(inputs) {
80903
+ const output = makeStateMachine();
80904
+ const heads = [];
80905
+ let offset = output.nodes.length;
80906
+ for (const input of inputs) {
80907
+ heads.push(offset);
80908
+ for (let t = 0; t < input.nodes.length; ++t)
80909
+ if (!isTerminalNode(t))
80910
+ output.nodes.push(cloneNode(input.nodes[t], offset));
80911
+ offset += input.nodes.length - 2;
80912
+ }
80913
+ for (const head of heads)
80914
+ registerShortcut(output, NODE_INITIAL, head);
80915
+ return output;
80916
+ }
80917
+ function injectNode(machine, node) {
80918
+ machine.nodes.push(node);
80919
+ return machine.nodes.length - 1;
80920
+ }
80921
+ function simplifyMachine(input) {
80922
+ const visited = new Set();
80923
+ const process = (node) => {
80924
+ if (visited.has(node))
80925
+ return;
80926
+ visited.add(node);
80927
+ const nodeDef = input.nodes[node];
80928
+ for (const transitions of Object.values(nodeDef.statics))
80929
+ for (const { to } of transitions)
80930
+ process(to);
80931
+ for (const [, { to }] of nodeDef.dynamics)
80932
+ process(to);
80933
+ for (const { to } of nodeDef.shortcuts)
80934
+ process(to);
80935
+ const shortcuts = new Set(nodeDef.shortcuts.map(({ to }) => to));
80936
+ while (nodeDef.shortcuts.length > 0) {
80937
+ const { to } = nodeDef.shortcuts.shift();
80938
+ const toDef = input.nodes[to];
80939
+ for (const [segment, transitions] of Object.entries(toDef.statics)) {
80940
+ let store = !Object.prototype.hasOwnProperty.call(nodeDef.statics, segment)
80941
+ ? nodeDef.statics[segment] = []
80942
+ : nodeDef.statics[segment];
80943
+ for (const transition of transitions) {
80944
+ if (!store.some(({ to }) => transition.to === to)) {
80945
+ store.push(transition);
80946
+ }
80947
+ }
80948
+ }
80949
+ for (const [test, transition] of toDef.dynamics)
80950
+ if (!nodeDef.dynamics.some(([otherTest, { to }]) => test === otherTest && transition.to === to))
80951
+ nodeDef.dynamics.push([test, transition]);
80952
+ for (const transition of toDef.shortcuts) {
80953
+ if (!shortcuts.has(transition.to)) {
80954
+ nodeDef.shortcuts.push(transition);
80955
+ shortcuts.add(transition.to);
81057
80956
  }
81058
80957
  }
81059
- } else if (
81060
- this._resHeaders['last-modified'] &&
81061
- !headers['if-modified-since']
81062
- ) {
81063
- headers['if-modified-since'] = this._resHeaders['last-modified'];
81064
80958
  }
81065
-
81066
- return headers;
80959
+ };
80960
+ process(NODE_INITIAL);
80961
+ }
80962
+ function debugMachine(machine, { prefix = `` } = {}) {
80963
+ debug(`${prefix}Nodes are:`);
80964
+ for (let t = 0; t < machine.nodes.length; ++t) {
80965
+ debug(`${prefix} ${t}: ${JSON.stringify(machine.nodes[t])}`);
81067
80966
  }
81068
-
81069
- /**
81070
- * Creates new CachePolicy with information combined from the previews response,
81071
- * and the new revalidation response.
81072
- *
81073
- * Returns {policy, modified} where modified is a boolean indicating
81074
- * whether the response body has been modified, and old cached body can't be used.
81075
- *
81076
- * @return {Object} {policy: CachePolicy, modified: Boolean}
81077
- */
81078
- revalidatedPolicy(request, response) {
81079
- this._assertRequestHasHeaders(request);
81080
- if(this._useStaleIfError() && isErrorResponse(response)) { // I consider the revalidation request unsuccessful
81081
- return {
81082
- modified: false,
81083
- matches: false,
81084
- policy: this,
81085
- };
80967
+ }
80968
+ function runMachineInternal(machine, input, partial = false) {
80969
+ debug(`Running a vm on ${JSON.stringify(input)}`);
80970
+ let branches = [{ node: NODE_INITIAL, state: {
80971
+ candidateUsage: null,
80972
+ errorMessage: null,
80973
+ ignoreOptions: false,
80974
+ options: [],
80975
+ path: [],
80976
+ positionals: [],
80977
+ remainder: null,
80978
+ selectedIndex: null,
80979
+ } }];
80980
+ debugMachine(machine, { prefix: ` ` });
80981
+ const tokens = [START_OF_INPUT, ...input];
80982
+ for (let t = 0; t < tokens.length; ++t) {
80983
+ const segment = tokens[t];
80984
+ debug(` Processing ${JSON.stringify(segment)}`);
80985
+ const nextBranches = [];
80986
+ for (const { node, state } of branches) {
80987
+ debug(` Current node is ${node}`);
80988
+ const nodeDef = machine.nodes[node];
80989
+ if (node === NODE_ERRORED) {
80990
+ nextBranches.push({ node, state });
80991
+ continue;
80992
+ }
80993
+ console.assert(nodeDef.shortcuts.length === 0, `Shortcuts should have been eliminated by now`);
80994
+ const hasExactMatch = Object.prototype.hasOwnProperty.call(nodeDef.statics, segment);
80995
+ if (!partial || t < tokens.length - 1 || hasExactMatch) {
80996
+ if (hasExactMatch) {
80997
+ const transitions = nodeDef.statics[segment];
80998
+ for (const { to, reducer } of transitions) {
80999
+ nextBranches.push({ node: to, state: typeof reducer !== `undefined` ? execute(reducers, reducer, state, segment) : state });
81000
+ debug(` Static transition to ${to} found`);
81001
+ }
81002
+ }
81003
+ else {
81004
+ debug(` No static transition found`);
81005
+ }
81006
+ }
81007
+ else {
81008
+ let hasMatches = false;
81009
+ for (const candidate of Object.keys(nodeDef.statics)) {
81010
+ if (!candidate.startsWith(segment))
81011
+ continue;
81012
+ if (segment === candidate) {
81013
+ for (const { to, reducer } of nodeDef.statics[candidate]) {
81014
+ nextBranches.push({ node: to, state: typeof reducer !== `undefined` ? execute(reducers, reducer, state, segment) : state });
81015
+ debug(` Static transition to ${to} found`);
81016
+ }
81017
+ }
81018
+ else {
81019
+ for (const { to, reducer } of nodeDef.statics[candidate]) {
81020
+ nextBranches.push({ node: to, state: Object.assign(Object.assign({}, state), { remainder: candidate.slice(segment.length) }) });
81021
+ debug(` Static transition to ${to} found (partial match)`);
81022
+ }
81023
+ }
81024
+ hasMatches = true;
81025
+ }
81026
+ if (!hasMatches) {
81027
+ debug(` No partial static transition found`);
81028
+ }
81029
+ }
81030
+ if (segment !== END_OF_INPUT) {
81031
+ for (const [test, { to, reducer }] of nodeDef.dynamics) {
81032
+ if (execute(tests, test, state, segment)) {
81033
+ nextBranches.push({ node: to, state: typeof reducer !== `undefined` ? execute(reducers, reducer, state, segment) : state });
81034
+ debug(` Dynamic transition to ${to} found (via ${test})`);
81035
+ }
81036
+ }
81037
+ }
81086
81038
  }
81087
- if (!response || !response.headers) {
81088
- throw Error('Response headers missing');
81039
+ if (nextBranches.length === 0 && segment === END_OF_INPUT && input.length === 1) {
81040
+ return [{
81041
+ node: NODE_INITIAL,
81042
+ state: basicHelpState,
81043
+ }];
81089
81044
  }
81090
-
81091
- // These aren't going to be supported exactly, since one CachePolicy object
81092
- // doesn't know about all the other cached objects.
81093
- let matches = false;
81094
- if (response.status !== undefined && response.status != 304) {
81095
- matches = false;
81096
- } else if (
81097
- response.headers.etag &&
81098
- !/^\s*W\//.test(response.headers.etag)
81099
- ) {
81100
- // "All of the stored responses with the same strong validator are selected.
81101
- // If none of the stored responses contain the same strong validator,
81102
- // then the cache MUST NOT use the new response to update any stored responses."
81103
- matches =
81104
- this._resHeaders.etag &&
81105
- this._resHeaders.etag.replace(/^\s*W\//, '') ===
81106
- response.headers.etag;
81107
- } else if (this._resHeaders.etag && response.headers.etag) {
81108
- // "If the new response contains a weak validator and that validator corresponds
81109
- // to one of the cache's stored responses,
81110
- // then the most recent of those matching stored responses is selected for update."
81111
- matches =
81112
- this._resHeaders.etag.replace(/^\s*W\//, '') ===
81113
- response.headers.etag.replace(/^\s*W\//, '');
81114
- } else if (this._resHeaders['last-modified']) {
81115
- matches =
81116
- this._resHeaders['last-modified'] ===
81117
- response.headers['last-modified'];
81118
- } else {
81119
- // If the new response does not include any form of validator (such as in the case where
81120
- // a client generates an If-Modified-Since request from a source other than the Last-Modified
81121
- // response header field), and there is only one stored response, and that stored response also
81122
- // lacks a validator, then that stored response is selected for update.
81123
- if (
81124
- !this._resHeaders.etag &&
81125
- !this._resHeaders['last-modified'] &&
81126
- !response.headers.etag &&
81127
- !response.headers['last-modified']
81128
- ) {
81129
- matches = true;
81130
- }
81045
+ if (nextBranches.length === 0) {
81046
+ throw new UnknownSyntaxError(input, branches.filter(({ node }) => {
81047
+ return node !== NODE_ERRORED;
81048
+ }).map(({ state }) => {
81049
+ return { usage: state.candidateUsage, reason: null };
81050
+ }));
81131
81051
  }
81132
-
81133
- if (!matches) {
81134
- return {
81135
- policy: new this.constructor(request, response),
81136
- // Client receiving 304 without body, even if it's invalid/mismatched has no option
81137
- // but to reuse a cached body. We don't have a good way to tell clients to do
81138
- // error recovery in such case.
81139
- modified: response.status != 304,
81140
- matches: false,
81141
- };
81052
+ if (nextBranches.every(({ node }) => node === NODE_ERRORED)) {
81053
+ throw new UnknownSyntaxError(input, nextBranches.map(({ state }) => {
81054
+ return { usage: state.candidateUsage, reason: state.errorMessage };
81055
+ }));
81142
81056
  }
81143
-
81144
- // use other header fields provided in the 304 (Not Modified) response to replace all instances
81145
- // of the corresponding header fields in the stored response.
81146
- const headers = {};
81147
- for (const k in this._resHeaders) {
81148
- headers[k] =
81149
- k in response.headers && !excludedFromRevalidationUpdate[k]
81150
- ? response.headers[k]
81151
- : this._resHeaders[k];
81057
+ branches = trimSmallerBranches(nextBranches);
81058
+ }
81059
+ if (branches.length > 0) {
81060
+ debug(` Results:`);
81061
+ for (const branch of branches) {
81062
+ debug(` - ${branch.node} -> ${JSON.stringify(branch.state)}`);
81152
81063
  }
81153
-
81154
- const newResponse = Object.assign({}, response, {
81155
- status: this._status,
81156
- method: this._method,
81157
- headers,
81158
- });
81159
- return {
81160
- policy: new this.constructor(request, newResponse, {
81161
- shared: this._isShared,
81162
- cacheHeuristic: this._cacheHeuristic,
81163
- immutableMinTimeToLive: this._immutableMinTtl,
81164
- }),
81165
- modified: false,
81166
- matches: true,
81167
- };
81168
81064
  }
81169
- };
81170
-
81171
-
81172
- /***/ }),
81173
-
81174
- /***/ 93481:
81175
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
81176
-
81177
- "use strict";
81178
-
81179
-
81180
- const EventEmitter = __webpack_require__(82361);
81181
- const urlLib = __webpack_require__(57310);
81182
- const normalizeUrl = __webpack_require__(40015);
81183
- const getStream = __webpack_require__(50404);
81184
- const CachePolicy = __webpack_require__(59844);
81185
- const Response = __webpack_require__(24259);
81186
- const lowercaseKeys = __webpack_require__(25989);
81187
- const cloneResponse = __webpack_require__(79715);
81188
- const Keyv = __webpack_require__(64958);
81189
-
81190
- class CacheableRequest {
81191
- constructor(request, cacheAdapter) {
81192
- if (typeof request !== 'function') {
81193
- throw new TypeError('Parameter `request` must be a function');
81194
- }
81195
-
81196
- this.cache = new Keyv({
81197
- uri: typeof cacheAdapter === 'string' && cacheAdapter,
81198
- store: typeof cacheAdapter !== 'string' && cacheAdapter,
81199
- namespace: 'cacheable-request'
81200
- });
81201
-
81202
- return this.createCacheableRequest(request);
81203
- }
81204
-
81205
- createCacheableRequest(request) {
81206
- return (opts, cb) => {
81207
- let url;
81208
- if (typeof opts === 'string') {
81209
- url = normalizeUrlObject(urlLib.parse(opts));
81210
- opts = {};
81211
- } else if (opts instanceof urlLib.URL) {
81212
- url = normalizeUrlObject(urlLib.parse(opts.toString()));
81213
- opts = {};
81214
- } else {
81215
- const [pathname, ...searchParts] = (opts.path || '').split('?');
81216
- const search = searchParts.length > 0 ?
81217
- `?${searchParts.join('?')}` :
81218
- '';
81219
- url = normalizeUrlObject({ ...opts, pathname, search });
81220
- }
81221
-
81222
- opts = {
81223
- headers: {},
81224
- method: 'GET',
81225
- cache: true,
81226
- strictTtl: false,
81227
- automaticFailover: false,
81228
- ...opts,
81229
- ...urlObjectToRequestOptions(url)
81230
- };
81231
- opts.headers = lowercaseKeys(opts.headers);
81232
-
81233
- const ee = new EventEmitter();
81234
- const normalizedUrlString = normalizeUrl(
81235
- urlLib.format(url),
81236
- {
81237
- stripWWW: false,
81238
- removeTrailingSlash: false,
81239
- stripAuthentication: false
81240
- }
81241
- );
81242
- const key = `${opts.method}:${normalizedUrlString}`;
81243
- let revalidate = false;
81244
- let madeRequest = false;
81245
-
81246
- const makeRequest = opts => {
81247
- madeRequest = true;
81248
- let requestErrored = false;
81249
- let requestErrorCallback;
81250
-
81251
- const requestErrorPromise = new Promise(resolve => {
81252
- requestErrorCallback = () => {
81253
- if (!requestErrored) {
81254
- requestErrored = true;
81255
- resolve();
81256
- }
81257
- };
81258
- });
81259
-
81260
- const handler = response => {
81261
- if (revalidate && !opts.forceRefresh) {
81262
- response.status = response.statusCode;
81263
- const revalidatedPolicy = CachePolicy.fromObject(revalidate.cachePolicy).revalidatedPolicy(opts, response);
81264
- if (!revalidatedPolicy.modified) {
81265
- const headers = revalidatedPolicy.policy.responseHeaders();
81266
- response = new Response(revalidate.statusCode, headers, revalidate.body, revalidate.url);
81267
- response.cachePolicy = revalidatedPolicy.policy;
81268
- response.fromCache = true;
81269
- }
81270
- }
81271
-
81272
- if (!response.fromCache) {
81273
- response.cachePolicy = new CachePolicy(opts, response, opts);
81274
- response.fromCache = false;
81275
- }
81276
-
81277
- let clonedResponse;
81278
- if (opts.cache && response.cachePolicy.storable()) {
81279
- clonedResponse = cloneResponse(response);
81280
-
81281
- (async () => {
81282
- try {
81283
- const bodyPromise = getStream.buffer(response);
81284
-
81285
- await Promise.race([
81286
- requestErrorPromise,
81287
- new Promise(resolve => response.once('end', resolve))
81288
- ]);
81289
-
81290
- if (requestErrored) {
81291
- return;
81292
- }
81293
-
81294
- const body = await bodyPromise;
81295
-
81296
- const value = {
81297
- cachePolicy: response.cachePolicy.toObject(),
81298
- url: response.url,
81299
- statusCode: response.fromCache ? revalidate.statusCode : response.statusCode,
81300
- body
81301
- };
81302
-
81303
- let ttl = opts.strictTtl ? response.cachePolicy.timeToLive() : undefined;
81304
- if (opts.maxTtl) {
81305
- ttl = ttl ? Math.min(ttl, opts.maxTtl) : opts.maxTtl;
81306
- }
81307
-
81308
- await this.cache.set(key, value, ttl);
81309
- } catch (error) {
81310
- ee.emit('error', new CacheableRequest.CacheError(error));
81311
- }
81312
- })();
81313
- } else if (opts.cache && revalidate) {
81314
- (async () => {
81315
- try {
81316
- await this.cache.delete(key);
81317
- } catch (error) {
81318
- ee.emit('error', new CacheableRequest.CacheError(error));
81319
- }
81320
- })();
81321
- }
81322
-
81323
- ee.emit('response', clonedResponse || response);
81324
- if (typeof cb === 'function') {
81325
- cb(clonedResponse || response);
81326
- }
81327
- };
81328
-
81329
- try {
81330
- const req = request(opts, handler);
81331
- req.once('error', requestErrorCallback);
81332
- req.once('abort', requestErrorCallback);
81333
- ee.emit('request', req);
81334
- } catch (error) {
81335
- ee.emit('error', new CacheableRequest.RequestError(error));
81336
- }
81337
- };
81338
-
81339
- (async () => {
81340
- const get = async opts => {
81341
- await Promise.resolve();
81342
-
81343
- const cacheEntry = opts.cache ? await this.cache.get(key) : undefined;
81344
- if (typeof cacheEntry === 'undefined') {
81345
- return makeRequest(opts);
81346
- }
81347
-
81348
- const policy = CachePolicy.fromObject(cacheEntry.cachePolicy);
81349
- if (policy.satisfiesWithoutRevalidation(opts) && !opts.forceRefresh) {
81350
- const headers = policy.responseHeaders();
81351
- const response = new Response(cacheEntry.statusCode, headers, cacheEntry.body, cacheEntry.url);
81352
- response.cachePolicy = policy;
81353
- response.fromCache = true;
81354
-
81355
- ee.emit('response', response);
81356
- if (typeof cb === 'function') {
81357
- cb(response);
81358
- }
81359
- } else {
81360
- revalidate = cacheEntry;
81361
- opts.headers = policy.revalidationHeaders(opts);
81362
- makeRequest(opts);
81363
- }
81364
- };
81365
-
81366
- const errorHandler = error => ee.emit('error', new CacheableRequest.CacheError(error));
81367
- this.cache.once('error', errorHandler);
81368
- ee.on('response', () => this.cache.removeListener('error', errorHandler));
81369
-
81370
- try {
81371
- await get(opts);
81372
- } catch (error) {
81373
- if (opts.automaticFailover && !madeRequest) {
81374
- makeRequest(opts);
81375
- }
81376
-
81377
- ee.emit('error', new CacheableRequest.CacheError(error));
81378
- }
81379
- })();
81380
-
81381
- return ee;
81382
- };
81383
- }
81384
- }
81385
-
81386
- function urlObjectToRequestOptions(url) {
81387
- const options = { ...url };
81388
- options.path = `${url.pathname || '/'}${url.search || ''}`;
81389
- delete options.pathname;
81390
- delete options.search;
81391
- return options;
81392
- }
81393
-
81394
- function normalizeUrlObject(url) {
81395
- // If url was parsed by url.parse or new URL:
81396
- // - hostname will be set
81397
- // - host will be hostname[:port]
81398
- // - port will be set if it was explicit in the parsed string
81399
- // Otherwise, url was from request options:
81400
- // - hostname or host may be set
81401
- // - host shall not have port encoded
81402
- return {
81403
- protocol: url.protocol,
81404
- auth: url.auth,
81405
- hostname: url.hostname || url.host || 'localhost',
81406
- port: url.port,
81407
- pathname: url.pathname,
81408
- search: url.search
81409
- };
81410
- }
81411
-
81412
- CacheableRequest.RequestError = class extends Error {
81413
- constructor(error) {
81414
- super(error.message);
81415
- this.name = 'RequestError';
81416
- Object.assign(this, error);
81417
- }
81418
- };
81419
-
81420
- CacheableRequest.CacheError = class extends Error {
81421
- constructor(error) {
81422
- super(error.message);
81423
- this.name = 'CacheError';
81424
- Object.assign(this, error);
81425
- }
81426
- };
81427
-
81428
- module.exports = CacheableRequest;
81429
-
81430
-
81431
- /***/ }),
81432
-
81433
- /***/ 75281:
81434
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
81435
-
81436
- "use strict";
81437
-
81438
- const os = __webpack_require__(22037);
81439
-
81440
- const extractPathRegex = /\s+at.*(?:\(|\s)(.*)\)?/;
81441
- const pathRegex = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:babel-polyfill|pirates)\/.*)?\w+)\.js:\d+:\d+)|native)/;
81442
- const homeDir = typeof os.homedir === 'undefined' ? '' : os.homedir();
81443
-
81444
- module.exports = (stack, options) => {
81445
- options = Object.assign({pretty: false}, options);
81446
-
81447
- return stack.replace(/\\/g, '/')
81448
- .split('\n')
81449
- .filter(line => {
81450
- const pathMatches = line.match(extractPathRegex);
81451
- if (pathMatches === null || !pathMatches[1]) {
81452
- return true;
81453
- }
81454
-
81455
- const match = pathMatches[1];
81456
-
81457
- // Electron
81458
- if (
81459
- match.includes('.app/Contents/Resources/electron.asar') ||
81460
- match.includes('.app/Contents/Resources/default_app.asar')
81461
- ) {
81462
- return false;
81463
- }
81464
-
81465
- return !pathRegex.test(match);
81466
- })
81467
- .filter(line => line.trim() !== '')
81468
- .map(line => {
81469
- if (options.pretty) {
81470
- return line.replace(extractPathRegex, (m, p1) => m.replace(p1, p1.replace(homeDir, '~')));
81471
- }
81472
-
81473
- return line;
81474
- })
81475
- .join('\n');
81476
- };
81477
-
81478
-
81479
- /***/ }),
81480
-
81481
- /***/ 87730:
81482
- /***/ ((__unused_webpack_module, exports) => {
81483
-
81484
- "use strict";
81485
-
81486
-
81487
- Object.defineProperty(exports, "__esModule", ({ value: true }));
81488
-
81489
- const NODE_INITIAL = 0;
81490
- const NODE_SUCCESS = 1;
81491
- const NODE_ERRORED = 2;
81492
- const START_OF_INPUT = `\u0001`;
81493
- const END_OF_INPUT = `\u0000`;
81494
- const HELP_COMMAND_INDEX = -1;
81495
- const HELP_REGEX = /^(-h|--help)(?:=([0-9]+))?$/;
81496
- const OPTION_REGEX = /^(--[a-z]+(?:-[a-z]+)*|-[a-zA-Z]+)$/;
81497
- const BATCH_REGEX = /^-[a-zA-Z]{2,}$/;
81498
- const BINDING_REGEX = /^([^=]+)=([\s\S]*)$/;
81499
- const DEBUG = process.env.DEBUG_CLI === `1`;
81500
-
81501
- /**
81502
- * A generic usage error with the name `UsageError`.
81503
- *
81504
- * It should be used over `Error` only when it's the user's fault.
81505
- */
81506
- class UsageError extends Error {
81507
- constructor(message) {
81508
- super(message);
81509
- this.clipanion = { type: `usage` };
81510
- this.name = `UsageError`;
81065
+ else {
81066
+ debug(` No results`);
81511
81067
  }
81068
+ return branches;
81512
81069
  }
81513
- class UnknownSyntaxError extends Error {
81514
- constructor(input, candidates) {
81515
- super();
81516
- this.input = input;
81517
- this.candidates = candidates;
81518
- this.clipanion = { type: `none` };
81519
- this.name = `UnknownSyntaxError`;
81520
- if (this.candidates.length === 0) {
81521
- this.message = `Command not found, but we're not sure what's the alternative.`;
81522
- }
81523
- else if (this.candidates.length === 1 && this.candidates[0].reason !== null) {
81524
- const [{ usage, reason }] = this.candidates;
81525
- this.message = `${reason}\n\n$ ${usage}`;
81070
+ function checkIfNodeIsFinished(node, state) {
81071
+ if (state.selectedIndex !== null)
81072
+ return true;
81073
+ if (Object.prototype.hasOwnProperty.call(node.statics, END_OF_INPUT))
81074
+ for (const { to } of node.statics[END_OF_INPUT])
81075
+ if (to === NODE_SUCCESS)
81076
+ return true;
81077
+ return false;
81078
+ }
81079
+ function suggestMachine(machine, input, partial) {
81080
+ // If we're accepting partial matches, then exact matches need to be
81081
+ // prefixed with an extra space.
81082
+ const prefix = partial && input.length > 0 ? [``] : [];
81083
+ const branches = runMachineInternal(machine, input, partial);
81084
+ const suggestions = [];
81085
+ const suggestionsJson = new Set();
81086
+ const traverseSuggestion = (suggestion, node, skipFirst = true) => {
81087
+ let nextNodes = [node];
81088
+ while (nextNodes.length > 0) {
81089
+ const currentNodes = nextNodes;
81090
+ nextNodes = [];
81091
+ for (const node of currentNodes) {
81092
+ const nodeDef = machine.nodes[node];
81093
+ const keys = Object.keys(nodeDef.statics);
81094
+ for (const key of Object.keys(nodeDef.statics)) {
81095
+ const segment = keys[0];
81096
+ for (const { to, reducer } of nodeDef.statics[segment]) {
81097
+ if (reducer !== `pushPath`)
81098
+ continue;
81099
+ if (!skipFirst)
81100
+ suggestion.push(segment);
81101
+ nextNodes.push(to);
81102
+ }
81103
+ }
81104
+ }
81105
+ skipFirst = false;
81526
81106
  }
81527
- else if (this.candidates.length === 1) {
81528
- const [{ usage }] = this.candidates;
81529
- this.message = `Command not found; did you mean:\n\n$ ${usage}\n${whileRunning(input)}`;
81107
+ const json = JSON.stringify(suggestion);
81108
+ if (suggestionsJson.has(json))
81109
+ return;
81110
+ suggestions.push(suggestion);
81111
+ suggestionsJson.add(json);
81112
+ };
81113
+ for (const { node, state } of branches) {
81114
+ if (state.remainder !== null) {
81115
+ traverseSuggestion([state.remainder], node);
81116
+ continue;
81530
81117
  }
81531
- else {
81532
- this.message = `Command not found; did you mean one of:\n\n${this.candidates.map(({ usage }, index) => {
81533
- return `${`${index}.`.padStart(4)} ${usage}`;
81534
- }).join(`\n`)}\n\n${whileRunning(input)}`;
81118
+ const nodeDef = machine.nodes[node];
81119
+ const isFinished = checkIfNodeIsFinished(nodeDef, state);
81120
+ for (const [candidate, transitions] of Object.entries(nodeDef.statics))
81121
+ if ((isFinished && candidate !== END_OF_INPUT) || (!candidate.startsWith(`-`) && transitions.some(({ reducer }) => reducer === `pushPath`)))
81122
+ traverseSuggestion([...prefix, candidate], node);
81123
+ if (!isFinished)
81124
+ continue;
81125
+ for (const [test, { to }] of nodeDef.dynamics) {
81126
+ if (to === NODE_ERRORED)
81127
+ continue;
81128
+ const tokens = suggest(test, state);
81129
+ if (tokens === null)
81130
+ continue;
81131
+ for (const token of tokens) {
81132
+ traverseSuggestion([...prefix, token], node);
81133
+ }
81535
81134
  }
81536
81135
  }
81537
- }
81538
- class AmbiguousSyntaxError extends Error {
81539
- constructor(input, usages) {
81540
- super();
81541
- this.input = input;
81542
- this.usages = usages;
81543
- this.clipanion = { type: `none` };
81544
- this.name = `AmbiguousSyntaxError`;
81545
- this.message = `Cannot find who to pick amongst the following alternatives:\n\n${this.usages.map((usage, index) => {
81546
- return `${`${index}.`.padStart(4)} ${usage}`;
81547
- }).join(`\n`)}\n\n${whileRunning(input)}`;
81548
- }
81549
- }
81550
- const whileRunning = (input) => `While running ${input.filter(token => {
81551
- return token !== END_OF_INPUT;
81552
- }).map(token => {
81553
- const json = JSON.stringify(token);
81554
- if (token.match(/\s/) || token.length === 0 || json !== `"${token}"`) {
81555
- return json;
81556
- }
81557
- else {
81558
- return token;
81559
- }
81560
- }).join(` `)}`;
81561
-
81562
- // ------------------------------------------------------------------------
81563
- function debug(str) {
81564
- if (DEBUG) {
81565
- console.log(str);
81566
- }
81567
- }
81568
- const basicHelpState = {
81569
- candidateUsage: null,
81570
- errorMessage: null,
81571
- ignoreOptions: false,
81572
- path: [],
81573
- positionals: [],
81574
- options: [],
81575
- remainder: null,
81576
- selectedIndex: HELP_COMMAND_INDEX
81577
- };
81578
- function makeStateMachine() {
81579
- return {
81580
- nodes: [makeNode(), makeNode(), makeNode()],
81581
- };
81582
- }
81583
- function makeAnyOfMachine(inputs) {
81584
- const output = makeStateMachine();
81585
- const heads = [];
81586
- let offset = output.nodes.length;
81587
- for (const input of inputs) {
81588
- heads.push(offset);
81589
- for (let t = 0; t < input.nodes.length; ++t)
81590
- if (!isTerminalNode(t))
81591
- output.nodes.push(cloneNode(input.nodes[t], offset));
81592
- offset += input.nodes.length - 2;
81593
- }
81594
- for (const head of heads)
81595
- registerShortcut(output, NODE_INITIAL, head);
81596
- return output;
81597
- }
81598
- function injectNode(machine, node) {
81599
- machine.nodes.push(node);
81600
- return machine.nodes.length - 1;
81601
- }
81602
- function simplifyMachine(input) {
81603
- const visited = new Set();
81604
- const process = (node) => {
81605
- if (visited.has(node))
81606
- return;
81607
- visited.add(node);
81608
- const nodeDef = input.nodes[node];
81609
- for (const transitions of Object.values(nodeDef.statics))
81610
- for (const { to } of transitions)
81611
- process(to);
81612
- for (const [, { to }] of nodeDef.dynamics)
81613
- process(to);
81614
- for (const { to } of nodeDef.shortcuts)
81615
- process(to);
81616
- const shortcuts = new Set(nodeDef.shortcuts.map(({ to }) => to));
81617
- while (nodeDef.shortcuts.length > 0) {
81618
- const { to } = nodeDef.shortcuts.shift();
81619
- const toDef = input.nodes[to];
81620
- for (const [segment, transitions] of Object.entries(toDef.statics)) {
81621
- let store = !Object.prototype.hasOwnProperty.call(nodeDef.statics, segment)
81622
- ? nodeDef.statics[segment] = []
81623
- : nodeDef.statics[segment];
81624
- for (const transition of transitions) {
81625
- if (!store.some(({ to }) => transition.to === to)) {
81626
- store.push(transition);
81627
- }
81628
- }
81629
- }
81630
- for (const [test, transition] of toDef.dynamics)
81631
- if (!nodeDef.dynamics.some(([otherTest, { to }]) => test === otherTest && transition.to === to))
81632
- nodeDef.dynamics.push([test, transition]);
81633
- for (const transition of toDef.shortcuts) {
81634
- if (!shortcuts.has(transition.to)) {
81635
- nodeDef.shortcuts.push(transition);
81636
- shortcuts.add(transition.to);
81637
- }
81638
- }
81639
- }
81640
- };
81641
- process(NODE_INITIAL);
81642
- }
81643
- function debugMachine(machine, { prefix = `` } = {}) {
81644
- debug(`${prefix}Nodes are:`);
81645
- for (let t = 0; t < machine.nodes.length; ++t) {
81646
- debug(`${prefix} ${t}: ${JSON.stringify(machine.nodes[t])}`);
81647
- }
81648
- }
81649
- function runMachineInternal(machine, input, partial = false) {
81650
- debug(`Running a vm on ${JSON.stringify(input)}`);
81651
- let branches = [{ node: NODE_INITIAL, state: {
81652
- candidateUsage: null,
81653
- errorMessage: null,
81654
- ignoreOptions: false,
81655
- options: [],
81656
- path: [],
81657
- positionals: [],
81658
- remainder: null,
81659
- selectedIndex: null,
81660
- } }];
81661
- debugMachine(machine, { prefix: ` ` });
81662
- const tokens = [START_OF_INPUT, ...input];
81663
- for (let t = 0; t < tokens.length; ++t) {
81664
- const segment = tokens[t];
81665
- debug(` Processing ${JSON.stringify(segment)}`);
81666
- const nextBranches = [];
81667
- for (const { node, state } of branches) {
81668
- debug(` Current node is ${node}`);
81669
- const nodeDef = machine.nodes[node];
81670
- if (node === NODE_ERRORED) {
81671
- nextBranches.push({ node, state });
81672
- continue;
81673
- }
81674
- console.assert(nodeDef.shortcuts.length === 0, `Shortcuts should have been eliminated by now`);
81675
- const hasExactMatch = Object.prototype.hasOwnProperty.call(nodeDef.statics, segment);
81676
- if (!partial || t < tokens.length - 1 || hasExactMatch) {
81677
- if (hasExactMatch) {
81678
- const transitions = nodeDef.statics[segment];
81679
- for (const { to, reducer } of transitions) {
81680
- nextBranches.push({ node: to, state: typeof reducer !== `undefined` ? execute(reducers, reducer, state, segment) : state });
81681
- debug(` Static transition to ${to} found`);
81682
- }
81683
- }
81684
- else {
81685
- debug(` No static transition found`);
81686
- }
81687
- }
81688
- else {
81689
- let hasMatches = false;
81690
- for (const candidate of Object.keys(nodeDef.statics)) {
81691
- if (!candidate.startsWith(segment))
81692
- continue;
81693
- if (segment === candidate) {
81694
- for (const { to, reducer } of nodeDef.statics[candidate]) {
81695
- nextBranches.push({ node: to, state: typeof reducer !== `undefined` ? execute(reducers, reducer, state, segment) : state });
81696
- debug(` Static transition to ${to} found`);
81697
- }
81698
- }
81699
- else {
81700
- for (const { to, reducer } of nodeDef.statics[candidate]) {
81701
- nextBranches.push({ node: to, state: Object.assign(Object.assign({}, state), { remainder: candidate.slice(segment.length) }) });
81702
- debug(` Static transition to ${to} found (partial match)`);
81703
- }
81704
- }
81705
- hasMatches = true;
81706
- }
81707
- if (!hasMatches) {
81708
- debug(` No partial static transition found`);
81709
- }
81710
- }
81711
- if (segment !== END_OF_INPUT) {
81712
- for (const [test, { to, reducer }] of nodeDef.dynamics) {
81713
- if (execute(tests, test, state, segment)) {
81714
- nextBranches.push({ node: to, state: typeof reducer !== `undefined` ? execute(reducers, reducer, state, segment) : state });
81715
- debug(` Dynamic transition to ${to} found (via ${test})`);
81716
- }
81717
- }
81718
- }
81719
- }
81720
- if (nextBranches.length === 0 && segment === END_OF_INPUT && input.length === 1) {
81721
- return [{
81722
- node: NODE_INITIAL,
81723
- state: basicHelpState,
81724
- }];
81725
- }
81726
- if (nextBranches.length === 0) {
81727
- throw new UnknownSyntaxError(input, branches.filter(({ node }) => {
81728
- return node !== NODE_ERRORED;
81729
- }).map(({ state }) => {
81730
- return { usage: state.candidateUsage, reason: null };
81731
- }));
81732
- }
81733
- if (nextBranches.every(({ node }) => node === NODE_ERRORED)) {
81734
- throw new UnknownSyntaxError(input, nextBranches.map(({ state }) => {
81735
- return { usage: state.candidateUsage, reason: state.errorMessage };
81736
- }));
81737
- }
81738
- branches = trimSmallerBranches(nextBranches);
81739
- }
81740
- if (branches.length > 0) {
81741
- debug(` Results:`);
81742
- for (const branch of branches) {
81743
- debug(` - ${branch.node} -> ${JSON.stringify(branch.state)}`);
81744
- }
81745
- }
81746
- else {
81747
- debug(` No results`);
81748
- }
81749
- return branches;
81750
- }
81751
- function checkIfNodeIsFinished(node, state) {
81752
- if (state.selectedIndex !== null)
81753
- return true;
81754
- if (Object.prototype.hasOwnProperty.call(node.statics, END_OF_INPUT))
81755
- for (const { to } of node.statics[END_OF_INPUT])
81756
- if (to === NODE_SUCCESS)
81757
- return true;
81758
- return false;
81759
- }
81760
- function suggestMachine(machine, input, partial) {
81761
- // If we're accepting partial matches, then exact matches need to be
81762
- // prefixed with an extra space.
81763
- const prefix = partial && input.length > 0 ? [``] : [];
81764
- const branches = runMachineInternal(machine, input, partial);
81765
- const suggestions = [];
81766
- const suggestionsJson = new Set();
81767
- const traverseSuggestion = (suggestion, node, skipFirst = true) => {
81768
- let nextNodes = [node];
81769
- while (nextNodes.length > 0) {
81770
- const currentNodes = nextNodes;
81771
- nextNodes = [];
81772
- for (const node of currentNodes) {
81773
- const nodeDef = machine.nodes[node];
81774
- const keys = Object.keys(nodeDef.statics);
81775
- for (const key of Object.keys(nodeDef.statics)) {
81776
- const segment = keys[0];
81777
- for (const { to, reducer } of nodeDef.statics[segment]) {
81778
- if (reducer !== `pushPath`)
81779
- continue;
81780
- if (!skipFirst)
81781
- suggestion.push(segment);
81782
- nextNodes.push(to);
81783
- }
81784
- }
81785
- }
81786
- skipFirst = false;
81787
- }
81788
- const json = JSON.stringify(suggestion);
81789
- if (suggestionsJson.has(json))
81790
- return;
81791
- suggestions.push(suggestion);
81792
- suggestionsJson.add(json);
81793
- };
81794
- for (const { node, state } of branches) {
81795
- if (state.remainder !== null) {
81796
- traverseSuggestion([state.remainder], node);
81797
- continue;
81798
- }
81799
- const nodeDef = machine.nodes[node];
81800
- const isFinished = checkIfNodeIsFinished(nodeDef, state);
81801
- for (const [candidate, transitions] of Object.entries(nodeDef.statics))
81802
- if ((isFinished && candidate !== END_OF_INPUT) || (!candidate.startsWith(`-`) && transitions.some(({ reducer }) => reducer === `pushPath`)))
81803
- traverseSuggestion([...prefix, candidate], node);
81804
- if (!isFinished)
81805
- continue;
81806
- for (const [test, { to }] of nodeDef.dynamics) {
81807
- if (to === NODE_ERRORED)
81808
- continue;
81809
- const tokens = suggest(test, state);
81810
- if (tokens === null)
81811
- continue;
81812
- for (const token of tokens) {
81813
- traverseSuggestion([...prefix, token], node);
81814
- }
81815
- }
81816
- }
81817
- return [...suggestions].sort();
81136
+ return [...suggestions].sort();
81818
81137
  }
81819
81138
  function runMachine(machine, input) {
81820
81139
  const branches = runMachineInternal(machine, [...input, END_OF_INPUT]);
@@ -101110,6 +100429,688 @@ var gunzip = function (maxRecursion) {
101110
100429
  module.exports = gunzip
101111
100430
 
101112
100431
 
100432
+ /***/ }),
100433
+
100434
+ /***/ 26214:
100435
+ /***/ ((module) => {
100436
+
100437
+ "use strict";
100438
+
100439
+ // rfc7231 6.1
100440
+ const statusCodeCacheableByDefault = new Set([
100441
+ 200,
100442
+ 203,
100443
+ 204,
100444
+ 206,
100445
+ 300,
100446
+ 301,
100447
+ 308,
100448
+ 404,
100449
+ 405,
100450
+ 410,
100451
+ 414,
100452
+ 501,
100453
+ ]);
100454
+
100455
+ // This implementation does not understand partial responses (206)
100456
+ const understoodStatuses = new Set([
100457
+ 200,
100458
+ 203,
100459
+ 204,
100460
+ 300,
100461
+ 301,
100462
+ 302,
100463
+ 303,
100464
+ 307,
100465
+ 308,
100466
+ 404,
100467
+ 405,
100468
+ 410,
100469
+ 414,
100470
+ 501,
100471
+ ]);
100472
+
100473
+ const errorStatusCodes = new Set([
100474
+ 500,
100475
+ 502,
100476
+ 503,
100477
+ 504,
100478
+ ]);
100479
+
100480
+ const hopByHopHeaders = {
100481
+ date: true, // included, because we add Age update Date
100482
+ connection: true,
100483
+ 'keep-alive': true,
100484
+ 'proxy-authenticate': true,
100485
+ 'proxy-authorization': true,
100486
+ te: true,
100487
+ trailer: true,
100488
+ 'transfer-encoding': true,
100489
+ upgrade: true,
100490
+ };
100491
+
100492
+ const excludedFromRevalidationUpdate = {
100493
+ // Since the old body is reused, it doesn't make sense to change properties of the body
100494
+ 'content-length': true,
100495
+ 'content-encoding': true,
100496
+ 'transfer-encoding': true,
100497
+ 'content-range': true,
100498
+ };
100499
+
100500
+ function toNumberOrZero(s) {
100501
+ const n = parseInt(s, 10);
100502
+ return isFinite(n) ? n : 0;
100503
+ }
100504
+
100505
+ // RFC 5861
100506
+ function isErrorResponse(response) {
100507
+ // consider undefined response as faulty
100508
+ if(!response) {
100509
+ return true
100510
+ }
100511
+ return errorStatusCodes.has(response.status);
100512
+ }
100513
+
100514
+ function parseCacheControl(header) {
100515
+ const cc = {};
100516
+ if (!header) return cc;
100517
+
100518
+ // TODO: When there is more than one value present for a given directive (e.g., two Expires header fields, multiple Cache-Control: max-age directives),
100519
+ // the directive's value is considered invalid. Caches are encouraged to consider responses that have invalid freshness information to be stale
100520
+ const parts = header.trim().split(/,/);
100521
+ for (const part of parts) {
100522
+ const [k, v] = part.split(/=/, 2);
100523
+ cc[k.trim()] = v === undefined ? true : v.trim().replace(/^"|"$/g, '');
100524
+ }
100525
+
100526
+ return cc;
100527
+ }
100528
+
100529
+ function formatCacheControl(cc) {
100530
+ let parts = [];
100531
+ for (const k in cc) {
100532
+ const v = cc[k];
100533
+ parts.push(v === true ? k : k + '=' + v);
100534
+ }
100535
+ if (!parts.length) {
100536
+ return undefined;
100537
+ }
100538
+ return parts.join(', ');
100539
+ }
100540
+
100541
+ module.exports = class CachePolicy {
100542
+ constructor(
100543
+ req,
100544
+ res,
100545
+ {
100546
+ shared,
100547
+ cacheHeuristic,
100548
+ immutableMinTimeToLive,
100549
+ ignoreCargoCult,
100550
+ _fromObject,
100551
+ } = {}
100552
+ ) {
100553
+ if (_fromObject) {
100554
+ this._fromObject(_fromObject);
100555
+ return;
100556
+ }
100557
+
100558
+ if (!res || !res.headers) {
100559
+ throw Error('Response headers missing');
100560
+ }
100561
+ this._assertRequestHasHeaders(req);
100562
+
100563
+ this._responseTime = this.now();
100564
+ this._isShared = shared !== false;
100565
+ this._cacheHeuristic =
100566
+ undefined !== cacheHeuristic ? cacheHeuristic : 0.1; // 10% matches IE
100567
+ this._immutableMinTtl =
100568
+ undefined !== immutableMinTimeToLive
100569
+ ? immutableMinTimeToLive
100570
+ : 24 * 3600 * 1000;
100571
+
100572
+ this._status = 'status' in res ? res.status : 200;
100573
+ this._resHeaders = res.headers;
100574
+ this._rescc = parseCacheControl(res.headers['cache-control']);
100575
+ this._method = 'method' in req ? req.method : 'GET';
100576
+ this._url = req.url;
100577
+ this._host = req.headers.host;
100578
+ this._noAuthorization = !req.headers.authorization;
100579
+ this._reqHeaders = res.headers.vary ? req.headers : null; // Don't keep all request headers if they won't be used
100580
+ this._reqcc = parseCacheControl(req.headers['cache-control']);
100581
+
100582
+ // Assume that if someone uses legacy, non-standard uncecessary options they don't understand caching,
100583
+ // so there's no point stricly adhering to the blindly copy&pasted directives.
100584
+ if (
100585
+ ignoreCargoCult &&
100586
+ 'pre-check' in this._rescc &&
100587
+ 'post-check' in this._rescc
100588
+ ) {
100589
+ delete this._rescc['pre-check'];
100590
+ delete this._rescc['post-check'];
100591
+ delete this._rescc['no-cache'];
100592
+ delete this._rescc['no-store'];
100593
+ delete this._rescc['must-revalidate'];
100594
+ this._resHeaders = Object.assign({}, this._resHeaders, {
100595
+ 'cache-control': formatCacheControl(this._rescc),
100596
+ });
100597
+ delete this._resHeaders.expires;
100598
+ delete this._resHeaders.pragma;
100599
+ }
100600
+
100601
+ // When the Cache-Control header field is not present in a request, caches MUST consider the no-cache request pragma-directive
100602
+ // as having the same effect as if "Cache-Control: no-cache" were present (see Section 5.2.1).
100603
+ if (
100604
+ res.headers['cache-control'] == null &&
100605
+ /no-cache/.test(res.headers.pragma)
100606
+ ) {
100607
+ this._rescc['no-cache'] = true;
100608
+ }
100609
+ }
100610
+
100611
+ now() {
100612
+ return Date.now();
100613
+ }
100614
+
100615
+ storable() {
100616
+ // The "no-store" request directive indicates that a cache MUST NOT store any part of either this request or any response to it.
100617
+ return !!(
100618
+ !this._reqcc['no-store'] &&
100619
+ // A cache MUST NOT store a response to any request, unless:
100620
+ // The request method is understood by the cache and defined as being cacheable, and
100621
+ ('GET' === this._method ||
100622
+ 'HEAD' === this._method ||
100623
+ ('POST' === this._method && this._hasExplicitExpiration())) &&
100624
+ // the response status code is understood by the cache, and
100625
+ understoodStatuses.has(this._status) &&
100626
+ // the "no-store" cache directive does not appear in request or response header fields, and
100627
+ !this._rescc['no-store'] &&
100628
+ // the "private" response directive does not appear in the response, if the cache is shared, and
100629
+ (!this._isShared || !this._rescc.private) &&
100630
+ // the Authorization header field does not appear in the request, if the cache is shared,
100631
+ (!this._isShared ||
100632
+ this._noAuthorization ||
100633
+ this._allowsStoringAuthenticated()) &&
100634
+ // the response either:
100635
+ // contains an Expires header field, or
100636
+ (this._resHeaders.expires ||
100637
+ // contains a max-age response directive, or
100638
+ // contains a s-maxage response directive and the cache is shared, or
100639
+ // contains a public response directive.
100640
+ this._rescc['max-age'] ||
100641
+ (this._isShared && this._rescc['s-maxage']) ||
100642
+ this._rescc.public ||
100643
+ // has a status code that is defined as cacheable by default
100644
+ statusCodeCacheableByDefault.has(this._status))
100645
+ );
100646
+ }
100647
+
100648
+ _hasExplicitExpiration() {
100649
+ // 4.2.1 Calculating Freshness Lifetime
100650
+ return (
100651
+ (this._isShared && this._rescc['s-maxage']) ||
100652
+ this._rescc['max-age'] ||
100653
+ this._resHeaders.expires
100654
+ );
100655
+ }
100656
+
100657
+ _assertRequestHasHeaders(req) {
100658
+ if (!req || !req.headers) {
100659
+ throw Error('Request headers missing');
100660
+ }
100661
+ }
100662
+
100663
+ satisfiesWithoutRevalidation(req) {
100664
+ this._assertRequestHasHeaders(req);
100665
+
100666
+ // When presented with a request, a cache MUST NOT reuse a stored response, unless:
100667
+ // the presented request does not contain the no-cache pragma (Section 5.4), nor the no-cache cache directive,
100668
+ // unless the stored response is successfully validated (Section 4.3), and
100669
+ const requestCC = parseCacheControl(req.headers['cache-control']);
100670
+ if (requestCC['no-cache'] || /no-cache/.test(req.headers.pragma)) {
100671
+ return false;
100672
+ }
100673
+
100674
+ if (requestCC['max-age'] && this.age() > requestCC['max-age']) {
100675
+ return false;
100676
+ }
100677
+
100678
+ if (
100679
+ requestCC['min-fresh'] &&
100680
+ this.timeToLive() < 1000 * requestCC['min-fresh']
100681
+ ) {
100682
+ return false;
100683
+ }
100684
+
100685
+ // the stored response is either:
100686
+ // fresh, or allowed to be served stale
100687
+ if (this.stale()) {
100688
+ const allowsStale =
100689
+ requestCC['max-stale'] &&
100690
+ !this._rescc['must-revalidate'] &&
100691
+ (true === requestCC['max-stale'] ||
100692
+ requestCC['max-stale'] > this.age() - this.maxAge());
100693
+ if (!allowsStale) {
100694
+ return false;
100695
+ }
100696
+ }
100697
+
100698
+ return this._requestMatches(req, false);
100699
+ }
100700
+
100701
+ _requestMatches(req, allowHeadMethod) {
100702
+ // The presented effective request URI and that of the stored response match, and
100703
+ return (
100704
+ (!this._url || this._url === req.url) &&
100705
+ this._host === req.headers.host &&
100706
+ // the request method associated with the stored response allows it to be used for the presented request, and
100707
+ (!req.method ||
100708
+ this._method === req.method ||
100709
+ (allowHeadMethod && 'HEAD' === req.method)) &&
100710
+ // selecting header fields nominated by the stored response (if any) match those presented, and
100711
+ this._varyMatches(req)
100712
+ );
100713
+ }
100714
+
100715
+ _allowsStoringAuthenticated() {
100716
+ // following Cache-Control response directives (Section 5.2.2) have such an effect: must-revalidate, public, and s-maxage.
100717
+ return (
100718
+ this._rescc['must-revalidate'] ||
100719
+ this._rescc.public ||
100720
+ this._rescc['s-maxage']
100721
+ );
100722
+ }
100723
+
100724
+ _varyMatches(req) {
100725
+ if (!this._resHeaders.vary) {
100726
+ return true;
100727
+ }
100728
+
100729
+ // A Vary header field-value of "*" always fails to match
100730
+ if (this._resHeaders.vary === '*') {
100731
+ return false;
100732
+ }
100733
+
100734
+ const fields = this._resHeaders.vary
100735
+ .trim()
100736
+ .toLowerCase()
100737
+ .split(/\s*,\s*/);
100738
+ for (const name of fields) {
100739
+ if (req.headers[name] !== this._reqHeaders[name]) return false;
100740
+ }
100741
+ return true;
100742
+ }
100743
+
100744
+ _copyWithoutHopByHopHeaders(inHeaders) {
100745
+ const headers = {};
100746
+ for (const name in inHeaders) {
100747
+ if (hopByHopHeaders[name]) continue;
100748
+ headers[name] = inHeaders[name];
100749
+ }
100750
+ // 9.1. Connection
100751
+ if (inHeaders.connection) {
100752
+ const tokens = inHeaders.connection.trim().split(/\s*,\s*/);
100753
+ for (const name of tokens) {
100754
+ delete headers[name];
100755
+ }
100756
+ }
100757
+ if (headers.warning) {
100758
+ const warnings = headers.warning.split(/,/).filter(warning => {
100759
+ return !/^\s*1[0-9][0-9]/.test(warning);
100760
+ });
100761
+ if (!warnings.length) {
100762
+ delete headers.warning;
100763
+ } else {
100764
+ headers.warning = warnings.join(',').trim();
100765
+ }
100766
+ }
100767
+ return headers;
100768
+ }
100769
+
100770
+ responseHeaders() {
100771
+ const headers = this._copyWithoutHopByHopHeaders(this._resHeaders);
100772
+ const age = this.age();
100773
+
100774
+ // A cache SHOULD generate 113 warning if it heuristically chose a freshness
100775
+ // lifetime greater than 24 hours and the response's age is greater than 24 hours.
100776
+ if (
100777
+ age > 3600 * 24 &&
100778
+ !this._hasExplicitExpiration() &&
100779
+ this.maxAge() > 3600 * 24
100780
+ ) {
100781
+ headers.warning =
100782
+ (headers.warning ? `${headers.warning}, ` : '') +
100783
+ '113 - "rfc7234 5.5.4"';
100784
+ }
100785
+ headers.age = `${Math.round(age)}`;
100786
+ headers.date = new Date(this.now()).toUTCString();
100787
+ return headers;
100788
+ }
100789
+
100790
+ /**
100791
+ * Value of the Date response header or current time if Date was invalid
100792
+ * @return timestamp
100793
+ */
100794
+ date() {
100795
+ const serverDate = Date.parse(this._resHeaders.date);
100796
+ if (isFinite(serverDate)) {
100797
+ return serverDate;
100798
+ }
100799
+ return this._responseTime;
100800
+ }
100801
+
100802
+ /**
100803
+ * Value of the Age header, in seconds, updated for the current time.
100804
+ * May be fractional.
100805
+ *
100806
+ * @return Number
100807
+ */
100808
+ age() {
100809
+ let age = this._ageValue();
100810
+
100811
+ const residentTime = (this.now() - this._responseTime) / 1000;
100812
+ return age + residentTime;
100813
+ }
100814
+
100815
+ _ageValue() {
100816
+ return toNumberOrZero(this._resHeaders.age);
100817
+ }
100818
+
100819
+ /**
100820
+ * Value of applicable max-age (or heuristic equivalent) in seconds. This counts since response's `Date`.
100821
+ *
100822
+ * For an up-to-date value, see `timeToLive()`.
100823
+ *
100824
+ * @return Number
100825
+ */
100826
+ maxAge() {
100827
+ if (!this.storable() || this._rescc['no-cache']) {
100828
+ return 0;
100829
+ }
100830
+
100831
+ // Shared responses with cookies are cacheable according to the RFC, but IMHO it'd be unwise to do so by default
100832
+ // so this implementation requires explicit opt-in via public header
100833
+ if (
100834
+ this._isShared &&
100835
+ (this._resHeaders['set-cookie'] &&
100836
+ !this._rescc.public &&
100837
+ !this._rescc.immutable)
100838
+ ) {
100839
+ return 0;
100840
+ }
100841
+
100842
+ if (this._resHeaders.vary === '*') {
100843
+ return 0;
100844
+ }
100845
+
100846
+ if (this._isShared) {
100847
+ if (this._rescc['proxy-revalidate']) {
100848
+ return 0;
100849
+ }
100850
+ // if a response includes the s-maxage directive, a shared cache recipient MUST ignore the Expires field.
100851
+ if (this._rescc['s-maxage']) {
100852
+ return toNumberOrZero(this._rescc['s-maxage']);
100853
+ }
100854
+ }
100855
+
100856
+ // If a response includes a Cache-Control field with the max-age directive, a recipient MUST ignore the Expires field.
100857
+ if (this._rescc['max-age']) {
100858
+ return toNumberOrZero(this._rescc['max-age']);
100859
+ }
100860
+
100861
+ const defaultMinTtl = this._rescc.immutable ? this._immutableMinTtl : 0;
100862
+
100863
+ const serverDate = this.date();
100864
+ if (this._resHeaders.expires) {
100865
+ const expires = Date.parse(this._resHeaders.expires);
100866
+ // A cache recipient MUST interpret invalid date formats, especially the value "0", as representing a time in the past (i.e., "already expired").
100867
+ if (Number.isNaN(expires) || expires < serverDate) {
100868
+ return 0;
100869
+ }
100870
+ return Math.max(defaultMinTtl, (expires - serverDate) / 1000);
100871
+ }
100872
+
100873
+ if (this._resHeaders['last-modified']) {
100874
+ const lastModified = Date.parse(this._resHeaders['last-modified']);
100875
+ if (isFinite(lastModified) && serverDate > lastModified) {
100876
+ return Math.max(
100877
+ defaultMinTtl,
100878
+ ((serverDate - lastModified) / 1000) * this._cacheHeuristic
100879
+ );
100880
+ }
100881
+ }
100882
+
100883
+ return defaultMinTtl;
100884
+ }
100885
+
100886
+ timeToLive() {
100887
+ const age = this.maxAge() - this.age();
100888
+ const staleIfErrorAge = age + toNumberOrZero(this._rescc['stale-if-error']);
100889
+ const staleWhileRevalidateAge = age + toNumberOrZero(this._rescc['stale-while-revalidate']);
100890
+ return Math.max(0, age, staleIfErrorAge, staleWhileRevalidateAge) * 1000;
100891
+ }
100892
+
100893
+ stale() {
100894
+ return this.maxAge() <= this.age();
100895
+ }
100896
+
100897
+ _useStaleIfError() {
100898
+ return this.maxAge() + toNumberOrZero(this._rescc['stale-if-error']) > this.age();
100899
+ }
100900
+
100901
+ useStaleWhileRevalidate() {
100902
+ return this.maxAge() + toNumberOrZero(this._rescc['stale-while-revalidate']) > this.age();
100903
+ }
100904
+
100905
+ static fromObject(obj) {
100906
+ return new this(undefined, undefined, { _fromObject: obj });
100907
+ }
100908
+
100909
+ _fromObject(obj) {
100910
+ if (this._responseTime) throw Error('Reinitialized');
100911
+ if (!obj || obj.v !== 1) throw Error('Invalid serialization');
100912
+
100913
+ this._responseTime = obj.t;
100914
+ this._isShared = obj.sh;
100915
+ this._cacheHeuristic = obj.ch;
100916
+ this._immutableMinTtl =
100917
+ obj.imm !== undefined ? obj.imm : 24 * 3600 * 1000;
100918
+ this._status = obj.st;
100919
+ this._resHeaders = obj.resh;
100920
+ this._rescc = obj.rescc;
100921
+ this._method = obj.m;
100922
+ this._url = obj.u;
100923
+ this._host = obj.h;
100924
+ this._noAuthorization = obj.a;
100925
+ this._reqHeaders = obj.reqh;
100926
+ this._reqcc = obj.reqcc;
100927
+ }
100928
+
100929
+ toObject() {
100930
+ return {
100931
+ v: 1,
100932
+ t: this._responseTime,
100933
+ sh: this._isShared,
100934
+ ch: this._cacheHeuristic,
100935
+ imm: this._immutableMinTtl,
100936
+ st: this._status,
100937
+ resh: this._resHeaders,
100938
+ rescc: this._rescc,
100939
+ m: this._method,
100940
+ u: this._url,
100941
+ h: this._host,
100942
+ a: this._noAuthorization,
100943
+ reqh: this._reqHeaders,
100944
+ reqcc: this._reqcc,
100945
+ };
100946
+ }
100947
+
100948
+ /**
100949
+ * Headers for sending to the origin server to revalidate stale response.
100950
+ * Allows server to return 304 to allow reuse of the previous response.
100951
+ *
100952
+ * Hop by hop headers are always stripped.
100953
+ * Revalidation headers may be added or removed, depending on request.
100954
+ */
100955
+ revalidationHeaders(incomingReq) {
100956
+ this._assertRequestHasHeaders(incomingReq);
100957
+ const headers = this._copyWithoutHopByHopHeaders(incomingReq.headers);
100958
+
100959
+ // This implementation does not understand range requests
100960
+ delete headers['if-range'];
100961
+
100962
+ if (!this._requestMatches(incomingReq, true) || !this.storable()) {
100963
+ // revalidation allowed via HEAD
100964
+ // not for the same resource, or wasn't allowed to be cached anyway
100965
+ delete headers['if-none-match'];
100966
+ delete headers['if-modified-since'];
100967
+ return headers;
100968
+ }
100969
+
100970
+ /* MUST send that entity-tag in any cache validation request (using If-Match or If-None-Match) if an entity-tag has been provided by the origin server. */
100971
+ if (this._resHeaders.etag) {
100972
+ headers['if-none-match'] = headers['if-none-match']
100973
+ ? `${headers['if-none-match']}, ${this._resHeaders.etag}`
100974
+ : this._resHeaders.etag;
100975
+ }
100976
+
100977
+ // Clients MAY issue simple (non-subrange) GET requests with either weak validators or strong validators. Clients MUST NOT use weak validators in other forms of request.
100978
+ const forbidsWeakValidators =
100979
+ headers['accept-ranges'] ||
100980
+ headers['if-match'] ||
100981
+ headers['if-unmodified-since'] ||
100982
+ (this._method && this._method != 'GET');
100983
+
100984
+ /* SHOULD send the Last-Modified value in non-subrange cache validation requests (using If-Modified-Since) if only a Last-Modified value has been provided by the origin server.
100985
+ Note: This implementation does not understand partial responses (206) */
100986
+ if (forbidsWeakValidators) {
100987
+ delete headers['if-modified-since'];
100988
+
100989
+ if (headers['if-none-match']) {
100990
+ const etags = headers['if-none-match']
100991
+ .split(/,/)
100992
+ .filter(etag => {
100993
+ return !/^\s*W\//.test(etag);
100994
+ });
100995
+ if (!etags.length) {
100996
+ delete headers['if-none-match'];
100997
+ } else {
100998
+ headers['if-none-match'] = etags.join(',').trim();
100999
+ }
101000
+ }
101001
+ } else if (
101002
+ this._resHeaders['last-modified'] &&
101003
+ !headers['if-modified-since']
101004
+ ) {
101005
+ headers['if-modified-since'] = this._resHeaders['last-modified'];
101006
+ }
101007
+
101008
+ return headers;
101009
+ }
101010
+
101011
+ /**
101012
+ * Creates new CachePolicy with information combined from the previews response,
101013
+ * and the new revalidation response.
101014
+ *
101015
+ * Returns {policy, modified} where modified is a boolean indicating
101016
+ * whether the response body has been modified, and old cached body can't be used.
101017
+ *
101018
+ * @return {Object} {policy: CachePolicy, modified: Boolean}
101019
+ */
101020
+ revalidatedPolicy(request, response) {
101021
+ this._assertRequestHasHeaders(request);
101022
+ if(this._useStaleIfError() && isErrorResponse(response)) { // I consider the revalidation request unsuccessful
101023
+ return {
101024
+ modified: false,
101025
+ matches: false,
101026
+ policy: this,
101027
+ };
101028
+ }
101029
+ if (!response || !response.headers) {
101030
+ throw Error('Response headers missing');
101031
+ }
101032
+
101033
+ // These aren't going to be supported exactly, since one CachePolicy object
101034
+ // doesn't know about all the other cached objects.
101035
+ let matches = false;
101036
+ if (response.status !== undefined && response.status != 304) {
101037
+ matches = false;
101038
+ } else if (
101039
+ response.headers.etag &&
101040
+ !/^\s*W\//.test(response.headers.etag)
101041
+ ) {
101042
+ // "All of the stored responses with the same strong validator are selected.
101043
+ // If none of the stored responses contain the same strong validator,
101044
+ // then the cache MUST NOT use the new response to update any stored responses."
101045
+ matches =
101046
+ this._resHeaders.etag &&
101047
+ this._resHeaders.etag.replace(/^\s*W\//, '') ===
101048
+ response.headers.etag;
101049
+ } else if (this._resHeaders.etag && response.headers.etag) {
101050
+ // "If the new response contains a weak validator and that validator corresponds
101051
+ // to one of the cache's stored responses,
101052
+ // then the most recent of those matching stored responses is selected for update."
101053
+ matches =
101054
+ this._resHeaders.etag.replace(/^\s*W\//, '') ===
101055
+ response.headers.etag.replace(/^\s*W\//, '');
101056
+ } else if (this._resHeaders['last-modified']) {
101057
+ matches =
101058
+ this._resHeaders['last-modified'] ===
101059
+ response.headers['last-modified'];
101060
+ } else {
101061
+ // If the new response does not include any form of validator (such as in the case where
101062
+ // a client generates an If-Modified-Since request from a source other than the Last-Modified
101063
+ // response header field), and there is only one stored response, and that stored response also
101064
+ // lacks a validator, then that stored response is selected for update.
101065
+ if (
101066
+ !this._resHeaders.etag &&
101067
+ !this._resHeaders['last-modified'] &&
101068
+ !response.headers.etag &&
101069
+ !response.headers['last-modified']
101070
+ ) {
101071
+ matches = true;
101072
+ }
101073
+ }
101074
+
101075
+ if (!matches) {
101076
+ return {
101077
+ policy: new this.constructor(request, response),
101078
+ // Client receiving 304 without body, even if it's invalid/mismatched has no option
101079
+ // but to reuse a cached body. We don't have a good way to tell clients to do
101080
+ // error recovery in such case.
101081
+ modified: response.status != 304,
101082
+ matches: false,
101083
+ };
101084
+ }
101085
+
101086
+ // use other header fields provided in the 304 (Not Modified) response to replace all instances
101087
+ // of the corresponding header fields in the stored response.
101088
+ const headers = {};
101089
+ for (const k in this._resHeaders) {
101090
+ headers[k] =
101091
+ k in response.headers && !excludedFromRevalidationUpdate[k]
101092
+ ? response.headers[k]
101093
+ : this._resHeaders[k];
101094
+ }
101095
+
101096
+ const newResponse = Object.assign({}, response, {
101097
+ status: this._status,
101098
+ method: this._method,
101099
+ headers,
101100
+ });
101101
+ return {
101102
+ policy: new this.constructor(request, newResponse, {
101103
+ shared: this._isShared,
101104
+ cacheHeuristic: this._cacheHeuristic,
101105
+ immutableMinTimeToLive: this._immutableMinTtl,
101106
+ }),
101107
+ modified: false,
101108
+ matches: true,
101109
+ };
101110
+ }
101111
+ };
101112
+
101113
+
101113
101114
  /***/ }),
101114
101115
 
101115
101116
  /***/ 21354:
@@ -176230,7 +176231,7 @@ if ( true && module.exports) {
176230
176231
  /* module decorator */ module = __webpack_require__.nmd(module);
176231
176232
 
176232
176233
  try {
176233
- process.dlopen(module, __dirname + __webpack_require__(71017).sep + __webpack_require__.p + "eb317cf9255f67c17789c294700ceae7.node");
176234
+ process.dlopen(module, __dirname + __webpack_require__(71017).sep + __webpack_require__.p + "17fed5a77894e71b805c3fa99ec729cf.node");
176234
176235
  } catch (error) {
176235
176236
  throw new Error('node-loader:\n' + error);
176236
176237
  }
@@ -176244,7 +176245,7 @@ try {
176244
176245
  /* module decorator */ module = __webpack_require__.nmd(module);
176245
176246
 
176246
176247
  try {
176247
- process.dlopen(module, __dirname + __webpack_require__(71017).sep + __webpack_require__.p + "92eff85f9573c780002e035fccee4980.node");
176248
+ process.dlopen(module, __dirname + __webpack_require__(71017).sep + __webpack_require__.p + "64a3fccd81dc83aaf074ed7d2cf31fdf.node");
176248
176249
  } catch (error) {
176249
176250
  throw new Error('node-loader:\n' + error);
176250
176251
  }