@datadog/datadog-ci-plugin-terraform 5.21.2 → 5.22.1

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.
package/dist/bundle.js CHANGED
@@ -10914,7 +10914,7 @@ var require_glob = /* @__PURE__ */ __commonJSMin(((exports) => {
10914
10914
  var require_package$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
10915
10915
  module.exports = {
10916
10916
  "name": "@datadog/datadog-ci-base",
10917
- "version": "5.21.2",
10917
+ "version": "5.22.1",
10918
10918
  "description": "Base package for Datadog CI",
10919
10919
  "license": "Apache-2.0",
10920
10920
  "keywords": ["datadog", "datadog-ci"],
@@ -11016,7 +11016,7 @@ var require_package$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
11016
11016
  "inquirer": "^8.2.7",
11017
11017
  "is-docker": "^4.0.0",
11018
11018
  "jest-diff": "^30.2.0",
11019
- "js-yaml": "^4.2.0",
11019
+ "js-yaml": "^4.3.1",
11020
11020
  "jszip": "^3.10.1",
11021
11021
  "proxy-agent": "^6.4.0",
11022
11022
  "semver": "^7.6.3",
@@ -11024,7 +11024,7 @@ var require_package$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
11024
11024
  "terminal-link": "^2.1.1",
11025
11025
  "tiny-async-pool": "^2.1.0",
11026
11026
  "typanion": "^3.14.0",
11027
- "undici": "^7.28.0",
11027
+ "undici": "^7.29.0",
11028
11028
  "upath": "^2.0.1"
11029
11029
  },
11030
11030
  "devDependencies": {
@@ -44423,12 +44423,19 @@ var require_request$2 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
44423
44423
  arr.push(val[i]);
44424
44424
  } else if (val[i] === null) arr.push("");
44425
44425
  else if (typeof val[i] === "object") throw new InvalidArgumentError(`invalid ${key} header`);
44426
- else arr.push(`${val[i]}`);
44426
+ else {
44427
+ const str = `${val[i]}`;
44428
+ if (!isValidHeaderValue(str)) throw new InvalidArgumentError(`invalid ${key} header`);
44429
+ arr.push(str);
44430
+ }
44427
44431
  val = arr;
44428
44432
  } else if (typeof val === "string") {
44429
44433
  if (!isValidHeaderValue(val)) throw new InvalidArgumentError(`invalid ${key} header`);
44430
44434
  } else if (val === null) val = "";
44431
- else val = `${val}`;
44435
+ else {
44436
+ val = `${val}`;
44437
+ if (!isValidHeaderValue(val)) throw new InvalidArgumentError(`invalid ${key} header`);
44438
+ }
44432
44439
  if (headerName === "host") {
44433
44440
  if (request.host !== null) throw new InvalidArgumentError("duplicate host header");
44434
44441
  if (typeof val !== "string") throw new InvalidArgumentError("invalid host header");
@@ -48206,7 +48213,7 @@ var require_client_h1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
48206
48213
  const util = require_util$5();
48207
48214
  const { channels } = require_diagnostics();
48208
48215
  const timers = require_timers();
48209
- const { RequestContentLengthMismatchError, ResponseContentLengthMismatchError, RequestAbortedError, HeadersTimeoutError, HeadersOverflowError, SocketError, InformationalError, BodyTimeoutError, HTTPParserError, ResponseExceededMaxSizeError } = require_errors$1();
48216
+ const { RequestContentLengthMismatchError, ResponseContentLengthMismatchError, RequestAbortedError, InvalidArgumentError, HeadersTimeoutError, HeadersOverflowError, SocketError, InformationalError, BodyTimeoutError, HTTPParserError, ResponseExceededMaxSizeError } = require_errors$1();
48210
48217
  const { kUrl, kReset, kClient, kParser, kBlocking, kRunning, kPending, kSize, kWriting, kQueue, kNoRef, kKeepAliveDefaultTimeout, kHostHeader, kPendingIdx, kRunningIdx, kError, kPipelining, kSocket, kKeepAliveTimeoutValue, kMaxHeadersSize, kKeepAliveMaxTimeout, kKeepAliveTimeoutThreshold, kHeadersTimeout, kBodyTimeout, kStrictContentLength, kMaxRequests, kCounter, kMaxResponseSize, kOnError, kResume, kHTTPContext, kClosed } = require_symbols();
48211
48218
  const constants = require_constants$4();
48212
48219
  const EMPTY_BUF = Buffer.alloc(0);
@@ -48856,7 +48863,17 @@ var require_client_h1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
48856
48863
  if (request.contentType == null) headers.push("content-type", contentType);
48857
48864
  body = bodyStream.stream;
48858
48865
  contentLength = bodyStream.length;
48859
- } else if (util.isBlobLike(body) && request.contentType == null && body.type) headers.push("content-type", body.type);
48866
+ } else if (util.isBlobLike(body) && request.contentType == null) {
48867
+ const contentType = body.type;
48868
+ if (contentType) {
48869
+ const contentTypeValue = `${contentType}`;
48870
+ if (!util.isValidHeaderValue(contentTypeValue)) {
48871
+ util.errorRequest(client, request, new InvalidArgumentError("invalid content-type header"));
48872
+ return false;
48873
+ }
48874
+ headers.push("content-type", contentTypeValue);
48875
+ }
48876
+ }
48860
48877
  if (body && typeof body.read === "function") body.read(0);
48861
48878
  const bodyLength = util.bodyLength(body);
48862
48879
  contentLength = bodyLength ?? contentLength;
@@ -51660,6 +51677,17 @@ var require_retry_handler = /* @__PURE__ */ __commonJSMin(((exports, module) =>
51660
51677
  const retryTime = new Date(retryAfter).getTime();
51661
51678
  return isNaN(retryTime) ? 0 : retryTime - Date.now();
51662
51679
  }
51680
+ function validatePartialResponseContentLength(headers, range, statusCode, retryCount) {
51681
+ const contentLength = headers["content-length"];
51682
+ if (contentLength == null) return;
51683
+ if (!Number.isFinite(range.start) || !Number.isFinite(range.end)) return;
51684
+ const length = Number(contentLength);
51685
+ const expectedLength = range.end - range.start + 1;
51686
+ if (!Number.isFinite(length) || length !== expectedLength) throw new RequestRetryError("Content-Length mismatch", statusCode, {
51687
+ headers,
51688
+ data: { count: retryCount }
51689
+ });
51690
+ }
51663
51691
  module.exports = class RetryHandler {
51664
51692
  constructor(opts, { dispatch, handler }) {
51665
51693
  const { retryOptions, ...dispatchOpts } = opts;
@@ -51805,6 +51833,7 @@ var require_retry_handler = /* @__PURE__ */ __commonJSMin(((exports, module) =>
51805
51833
  headers,
51806
51834
  data: { count: this.retryCount }
51807
51835
  });
51836
+ validatePartialResponseContentLength(headers, contentRange, statusCode, this.retryCount);
51808
51837
  const { start, size, end = size ? size - 1 : null } = contentRange;
51809
51838
  assert$20(this.start === start, "content-range mismatch");
51810
51839
  assert$20(this.end == null || this.end === end, "content-range mismatch");
@@ -51818,6 +51847,7 @@ var require_retry_handler = /* @__PURE__ */ __commonJSMin(((exports, module) =>
51818
51847
  this.handler.onResponseStart?.(controller, statusCode, headers, statusMessage);
51819
51848
  return;
51820
51849
  }
51850
+ validatePartialResponseContentLength(headers, range, statusCode, this.retryCount);
51821
51851
  const { start, size, end = size ? size - 1 : null } = range;
51822
51852
  assert$20(start != null && Number.isFinite(start), "content-range mismatch");
51823
51853
  assert$20(end != null && Number.isFinite(end), "invalid content-length");
@@ -55450,8 +55480,100 @@ var require_dns = /* @__PURE__ */ __commonJSMin(((exports, module) => {
55450
55480
  //#endregion
55451
55481
  //#region ../../node_modules/undici/lib/util/cache.js
55452
55482
  var require_cache$2 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
55453
- const { safeHTTPMethods, pathHasQueryOrFragment, hasSafeIterator } = require_util$5();
55483
+ const { safeHTTPMethods, pathHasQueryOrFragment, hasSafeIterator, isValidHTTPToken } = require_util$5();
55454
55484
  const { serializePathWithQuery } = require_util$5();
55485
+ const MAX_DELTA_SECONDS = 2147483647;
55486
+ const RESTRICTIVE_DIRECTIVE_NAMES = [
55487
+ "no-store",
55488
+ "private",
55489
+ "no-cache"
55490
+ ];
55491
+ const kInvalidCacheControlDirectives = Symbol("invalid cache-control directives");
55492
+ function trimOWS(value) {
55493
+ return value.replace(/^[\t ]+|[\t ]+$/g, "");
55494
+ }
55495
+ function arrayIncludes(array, value) {
55496
+ for (let i = 0; i < array.length; i++) if (array[i] === value) return true;
55497
+ return false;
55498
+ }
55499
+ function trimOWSStart(value) {
55500
+ return value.replace(/^[\t ]+/, "");
55501
+ }
55502
+ function trimOWSEnd(value) {
55503
+ return value.replace(/[\t ]+$/, "");
55504
+ }
55505
+ function findUnescapedQuote(value, start) {
55506
+ let escaped = false;
55507
+ for (let i = start; i < value.length; i++) if (escaped) escaped = false;
55508
+ else if (value[i] === "\\") escaped = true;
55509
+ else if (value[i] === "\"") return i;
55510
+ return -1;
55511
+ }
55512
+ function splitCacheControlHeaderValue(value) {
55513
+ const directives = [];
55514
+ let start = 0;
55515
+ let quoteStart = -1;
55516
+ let inQuote = false;
55517
+ let escaped = false;
55518
+ for (let i = 0; i < value.length; i++) if (inQuote) {
55519
+ if (escaped) escaped = false;
55520
+ else if (value[i] === "\\") escaped = true;
55521
+ else if (value[i] === "\"") {
55522
+ inQuote = false;
55523
+ quoteStart = -1;
55524
+ }
55525
+ } else if (value[i] === "\"") {
55526
+ inQuote = true;
55527
+ quoteStart = i;
55528
+ } else if (value[i] === ",") {
55529
+ directives.push({
55530
+ value: value.substring(start, i),
55531
+ fromMalformedQuote: false
55532
+ });
55533
+ start = i + 1;
55534
+ }
55535
+ if (!inQuote) {
55536
+ directives.push({
55537
+ value: value.substring(start),
55538
+ fromMalformedQuote: false
55539
+ });
55540
+ return directives;
55541
+ }
55542
+ const tail = value.substring(start);
55543
+ const quoteOffset = quoteStart - start;
55544
+ let tailStart = 0;
55545
+ for (let i = 0; i < tail.length; i++) if (tail[i] === ",") {
55546
+ directives.push({
55547
+ value: tail.substring(tailStart, i),
55548
+ fromMalformedQuote: tailStart > quoteOffset
55549
+ });
55550
+ tailStart = i + 1;
55551
+ }
55552
+ directives.push({
55553
+ value: tail.substring(tailStart),
55554
+ fromMalformedQuote: tailStart > quoteOffset
55555
+ });
55556
+ return directives;
55557
+ }
55558
+ function markInvalidCacheControlDirective(directives, key) {
55559
+ let invalidDirectives = directives[kInvalidCacheControlDirectives];
55560
+ if (invalidDirectives === void 0) {
55561
+ invalidDirectives = /* @__PURE__ */ new Set();
55562
+ Object.defineProperty(directives, kInvalidCacheControlDirectives, { value: invalidDirectives });
55563
+ }
55564
+ invalidDirectives.add(key);
55565
+ }
55566
+ function hasInvalidCacheControlDirective(directives, key) {
55567
+ return directives[kInvalidCacheControlDirectives]?.has(key) === true;
55568
+ }
55569
+ function getMalformedRestrictiveDirectiveName(key) {
55570
+ for (const directiveName of RESTRICTIVE_DIRECTIVE_NAMES) if (key.startsWith(directiveName) && key.length > directiveName.length && !isValidHTTPToken(key[directiveName.length])) return directiveName;
55571
+ let tokenOnlyKey = "";
55572
+ let hasInvalidTokenChar = false;
55573
+ for (let i = 0; i < key.length; i++) if (isValidHTTPToken(key[i])) tokenOnlyKey += key[i];
55574
+ else hasInvalidTokenChar = true;
55575
+ if (hasInvalidTokenChar && arrayIncludes(RESTRICTIVE_DIRECTIVE_NAMES, tokenOnlyKey)) return tokenOnlyKey;
55576
+ }
55455
55577
  /**
55456
55578
  * @param {import('../../types/dispatcher.d.ts').default.DispatchOptions} opts
55457
55579
  */
@@ -55466,6 +55588,14 @@ var require_cache$2 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
55466
55588
  headers: opts.headers
55467
55589
  };
55468
55590
  }
55591
+ function appendHeader(headers, key, val) {
55592
+ const headerName = key.toLowerCase();
55593
+ const current = headers[headerName];
55594
+ const values = Array.isArray(val) ? val : [val];
55595
+ if (current === void 0) headers[headerName] = Array.isArray(val) ? val.slice() : val;
55596
+ else if (Array.isArray(current)) current.push(...values);
55597
+ else headers[headerName] = [current, ...values];
55598
+ }
55469
55599
  /**
55470
55600
  * @param {Record<string, string[] | string>}
55471
55601
  * @returns {Record<string, string[] | string>}
@@ -55479,9 +55609,9 @@ var require_cache$2 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
55479
55609
  if (!Array.isArray(x)) throw new Error("opts.headers is not a valid header map");
55480
55610
  const [key, val] = x;
55481
55611
  if (typeof key !== "string" || typeof val !== "string") throw new Error("opts.headers is not a valid header map");
55482
- headers[key.toLowerCase()] = val;
55612
+ appendHeader(headers, key, val);
55483
55613
  }
55484
- else for (const key of Object.keys(opts.headers)) headers[key.toLowerCase()] = opts.headers[key];
55614
+ else for (const key of Object.keys(opts.headers)) appendHeader(headers, key, opts.headers[key]);
55485
55615
  } else throw new Error("opts.headers is not an object");
55486
55616
  return headers;
55487
55617
  }
@@ -55525,20 +55655,31 @@ var require_cache$2 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
55525
55655
  * @type {import('../../types/cache-interceptor.d.ts').default.CacheControlDirectives}
55526
55656
  */
55527
55657
  const output = {};
55528
- let directives;
55529
- if (Array.isArray(header)) {
55530
- directives = [];
55531
- for (const directive of header) directives.push(...directive.split(","));
55532
- } else directives = header.split(",");
55658
+ const invalidNumericDirectives = /* @__PURE__ */ new Set();
55659
+ const invalidNoArgumentDirectives = /* @__PURE__ */ new Set();
55660
+ const directives = splitCacheControlHeaderValue(Array.isArray(header) ? header.join(",") : header);
55533
55661
  for (let i = 0; i < directives.length; i++) {
55534
- const directive = directives[i].toLowerCase();
55662
+ const directiveRecord = directives[i];
55663
+ const directive = directiveRecord.value.toLowerCase();
55664
+ const fromMalformedQuote = directiveRecord.fromMalformedQuote;
55535
55665
  const keyValueDelimiter = directive.indexOf("=");
55536
55666
  let key;
55537
55667
  let value;
55668
+ let keyHasTrailingWhitespace = false;
55669
+ let valueHasLeadingWhitespace = false;
55538
55670
  if (keyValueDelimiter !== -1) {
55539
- key = directive.substring(0, keyValueDelimiter).trimStart();
55540
- value = directive.substring(keyValueDelimiter + 1);
55541
- } else key = directive.trim();
55671
+ const rawKey = directive.substring(0, keyValueDelimiter);
55672
+ const rawValue = directive.substring(keyValueDelimiter + 1);
55673
+ keyHasTrailingWhitespace = trimOWSEnd(rawKey) !== rawKey;
55674
+ valueHasLeadingWhitespace = trimOWSStart(rawValue) !== rawValue;
55675
+ key = trimOWS(rawKey);
55676
+ value = trimOWSStart(rawValue);
55677
+ } else key = trimOWS(directive);
55678
+ const malformedRestrictiveDirectiveName = getMalformedRestrictiveDirectiveName(key);
55679
+ if (malformedRestrictiveDirectiveName !== void 0) {
55680
+ output[malformedRestrictiveDirectiveName] = true;
55681
+ continue;
55682
+ }
55542
55683
  switch (key) {
55543
55684
  case "min-fresh":
55544
55685
  case "max-stale":
@@ -55546,54 +55687,99 @@ var require_cache$2 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
55546
55687
  case "s-maxage":
55547
55688
  case "stale-while-revalidate":
55548
55689
  case "stale-if-error": {
55549
- if (value === void 0 || value[0] === " ") continue;
55690
+ if (fromMalformedQuote || invalidNumericDirectives.has(key)) continue;
55691
+ if (value === void 0 || keyHasTrailingWhitespace || valueHasLeadingWhitespace) {
55692
+ delete output[key];
55693
+ invalidNumericDirectives.add(key);
55694
+ markInvalidCacheControlDirective(output, key);
55695
+ continue;
55696
+ }
55550
55697
  if (value.length >= 2 && value[0] === "\"" && value[value.length - 1] === "\"") value = value.substring(1, value.length - 1);
55551
- const parsedValue = parseInt(value, 10);
55552
- if (parsedValue !== parsedValue) continue;
55553
- if (key === "max-age" && key in output && output[key] >= parsedValue) continue;
55554
- output[key] = parsedValue;
55698
+ if (!/^[0-9]+$/.test(value)) {
55699
+ delete output[key];
55700
+ invalidNumericDirectives.add(key);
55701
+ markInvalidCacheControlDirective(output, key);
55702
+ continue;
55703
+ }
55704
+ const parsedValue = Math.min(parseInt(value, 10), MAX_DELTA_SECONDS);
55705
+ if (key === "min-fresh") {
55706
+ if (!(key in output) || output[key] < parsedValue) output[key] = parsedValue;
55707
+ } else if (!(key in output) || output[key] > parsedValue) output[key] = parsedValue;
55555
55708
  break;
55556
55709
  }
55557
55710
  case "private":
55558
- case "no-cache": if (value) {
55559
- if (value[0] === "\"") {
55560
- const headers = [value.substring(1)];
55561
- let foundEndingQuote = value[value.length - 1] === "\"";
55562
- if (!foundEndingQuote) for (let j = i + 1; j < directives.length; j++) {
55563
- const nextPart = directives[j];
55564
- const nextPartLength = nextPart.length;
55565
- headers.push(nextPart.trim());
55566
- if (nextPartLength !== 0 && nextPart[nextPartLength - 1] === "\"") {
55711
+ case "no-cache":
55712
+ if (fromMalformedQuote) {
55713
+ output[key] = true;
55714
+ break;
55715
+ }
55716
+ if (value !== void 0 && value.length === 0) {
55717
+ output[key] = true;
55718
+ break;
55719
+ }
55720
+ if (value) {
55721
+ if (value[0] === "\"") {
55722
+ value = trimOWSEnd(value);
55723
+ let fieldList = "";
55724
+ let lastQuotedPart = i;
55725
+ let foundEndingQuote = false;
55726
+ const closingQuote = findUnescapedQuote(value, 1);
55727
+ if (closingQuote !== -1) {
55728
+ fieldList = value.substring(1, closingQuote);
55567
55729
  foundEndingQuote = true;
55730
+ } else {
55731
+ const fieldListParts = [value.substring(1)];
55732
+ for (let j = i + 1; j < directives.length; j++) {
55733
+ const nextPart = trimOWS(directives[j].value);
55734
+ const closingQuote = findUnescapedQuote(nextPart, 0);
55735
+ lastQuotedPart = j;
55736
+ if (closingQuote !== -1) {
55737
+ fieldListParts.push(nextPart.substring(0, closingQuote));
55738
+ foundEndingQuote = true;
55739
+ break;
55740
+ }
55741
+ fieldListParts.push(nextPart);
55742
+ }
55743
+ fieldList = fieldListParts.join(",");
55744
+ }
55745
+ if (!foundEndingQuote) {
55746
+ output[key] = true;
55568
55747
  break;
55569
55748
  }
55570
- }
55571
- if (foundEndingQuote) {
55572
- let lastHeader = headers[headers.length - 1];
55573
- if (lastHeader[lastHeader.length - 1] === "\"") {
55574
- lastHeader = lastHeader.substring(0, lastHeader.length - 1);
55575
- headers[headers.length - 1] = lastHeader;
55749
+ i = lastQuotedPart;
55750
+ const headers = fieldList.split(",");
55751
+ let validFieldNames = true;
55752
+ for (let j = 0; j < headers.length; j++) {
55753
+ headers[j] = trimOWS(headers[j]);
55754
+ if (!isValidHTTPToken(headers[j])) validFieldNames = false;
55576
55755
  }
55577
- for (let j = 0; j < headers.length; j++) headers[j] = headers[j].trim();
55578
- if (key in output) output[key] = output[key].concat(headers);
55756
+ if (!validFieldNames) output[key] = true;
55757
+ else if (output[key] !== true) if (key in output) output[key] = output[key].concat(headers);
55579
55758
  else output[key] = headers;
55759
+ } else {
55760
+ const fieldName = trimOWS(value);
55761
+ if (!isValidHTTPToken(fieldName)) output[key] = true;
55762
+ else if (output[key] !== true) if (key in output) output[key] = output[key].concat(fieldName);
55763
+ else output[key] = [fieldName];
55580
55764
  }
55581
- } else {
55582
- const fieldName = value.trim();
55583
- if (key in output) output[key] = output[key].concat(fieldName);
55584
- else output[key] = [fieldName];
55765
+ break;
55585
55766
  }
55586
- break;
55587
- }
55588
55767
  case "public":
55589
- case "no-store":
55590
55768
  case "must-revalidate":
55591
55769
  case "proxy-revalidate":
55592
55770
  case "immutable":
55593
55771
  case "no-transform":
55594
55772
  case "must-understand":
55595
55773
  case "only-if-cached":
55596
- if (value) continue;
55774
+ if (fromMalformedQuote || invalidNoArgumentDirectives.has(key)) continue;
55775
+ if (value !== void 0) {
55776
+ delete output[key];
55777
+ invalidNoArgumentDirectives.add(key);
55778
+ continue;
55779
+ }
55780
+ output[key] = true;
55781
+ break;
55782
+ case "no-store":
55597
55783
  output[key] = true;
55598
55784
  break;
55599
55785
  default: continue;
@@ -55603,20 +55789,52 @@ var require_cache$2 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
55603
55789
  }
55604
55790
  /**
55605
55791
  * @param {string | string[]} varyHeader Vary header from the server
55792
+ * @returns {string[]}
55793
+ */
55794
+ function splitVaryHeader(varyHeader) {
55795
+ const values = Array.isArray(varyHeader) ? varyHeader : [varyHeader];
55796
+ const output = [];
55797
+ for (let i = 0; i < values.length; i++) {
55798
+ const parts = values[i].split(",");
55799
+ for (let j = 0; j < parts.length; j++) output.push(parts[j]);
55800
+ }
55801
+ return output;
55802
+ }
55803
+ /**
55804
+ * @param {string | string[]} varyHeader Vary header from the server
55805
+ * @returns {boolean}
55806
+ */
55807
+ function hasVaryStar(varyHeader) {
55808
+ const values = splitVaryHeader(varyHeader);
55809
+ for (let i = 0; i < values.length; i++) if (trimOWS(values[i]).indexOf("*") !== -1) return true;
55810
+ return false;
55811
+ }
55812
+ /**
55813
+ * @param {string | string[]} varyHeader Vary header from the server
55606
55814
  * @param {Record<string, string | string[]>} headers Request headers
55607
- * @returns {Record<string, string | string[]>}
55815
+ * @returns {Record<string, string | string[] | null> | undefined}
55608
55816
  */
55609
55817
  function parseVaryHeader(varyHeader, headers) {
55610
- if (typeof varyHeader === "string" && varyHeader.includes("*")) return headers;
55818
+ if (hasVaryStar(varyHeader)) return headers;
55611
55819
  const output = {};
55612
- const varyingHeaders = typeof varyHeader === "string" ? varyHeader.split(",") : varyHeader;
55820
+ const varyingHeaders = splitVaryHeader(varyHeader);
55613
55821
  for (const header of varyingHeaders) {
55614
- const trimmedHeader = header.trim().toLowerCase();
55615
- output[trimmedHeader] = headers[trimmedHeader] ?? null;
55822
+ const trimmedHeader = trimOWS(header).toLowerCase();
55823
+ if (trimmedHeader.length === 0) continue;
55824
+ if (!isValidHTTPToken(trimmedHeader)) return;
55825
+ const headerValue = headers[trimmedHeader];
55826
+ output[trimmedHeader] = Array.isArray(headerValue) ? headerValue.slice() : headerValue ?? null;
55616
55827
  }
55617
55828
  return output;
55618
55829
  }
55619
55830
  /**
55831
+ * @param {string | string[]} varyHeader Vary header from the server
55832
+ * @returns {boolean}
55833
+ */
55834
+ function isInvalidOrWildcardVaryHeader(varyHeader) {
55835
+ return hasVaryStar(varyHeader) || parseVaryHeader(varyHeader, {}) === void 0;
55836
+ }
55837
+ /**
55620
55838
  * Note: this deviates from the spec a little. Empty etags ("", W/"") are valid,
55621
55839
  * however, including them in cached resposnes serves little to no purpose.
55622
55840
  *
@@ -55650,7 +55868,7 @@ var require_cache$2 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
55650
55868
  function assertCacheMethods(methods, name = "CacheMethods") {
55651
55869
  if (!Array.isArray(methods)) throw new TypeError(`expected type of ${name} needs to be an array, got ${methods === null ? "null" : typeof methods}`);
55652
55870
  if (methods.length === 0) throw new TypeError(`${name} needs to have at least one method`);
55653
- for (const method of methods) if (!safeHTTPMethods.includes(method)) throw new TypeError(`element of ${name}-array needs to be one of following values: ${safeHTTPMethods.join(", ")}, got ${method}`);
55871
+ for (const method of methods) if (!arrayIncludes(safeHTTPMethods, method)) throw new TypeError(`element of ${name}-array needs to be one of following values: ${safeHTTPMethods.join(", ")}, got ${method}`);
55654
55872
  }
55655
55873
  /**
55656
55874
  * Creates a string key for request deduplication purposes.
@@ -55681,7 +55899,10 @@ var require_cache$2 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
55681
55899
  assertCacheKey,
55682
55900
  assertCacheValue,
55683
55901
  parseCacheControlHeader,
55902
+ hasInvalidCacheControlDirective,
55684
55903
  parseVaryHeader,
55904
+ hasVaryStar,
55905
+ isInvalidOrWildcardVaryHeader,
55685
55906
  isEtagUsable,
55686
55907
  assertCacheMethods,
55687
55908
  assertCacheStore,
@@ -55704,6 +55925,11 @@ var require_date = /* @__PURE__ */ __commonJSMin(((exports, module) => {
55704
55925
  default: return parseRfc850Date(date);
55705
55926
  }
55706
55927
  }
55928
+ function makeDate(year, monthIdx, day, hour, minute, second, weekday) {
55929
+ const result = new Date(Date.UTC(year, monthIdx, day, hour, minute, second));
55930
+ if (year >= 0 && year <= 99) result.setUTCFullYear(year);
55931
+ return result.getUTCFullYear() === year && result.getUTCMonth() === monthIdx && result.getUTCDate() === day && result.getUTCHours() === hour && result.getUTCMinutes() === minute && result.getUTCSeconds() === second && result.getUTCDay() === weekday ? result : void 0;
55932
+ }
55707
55933
  /**
55708
55934
  * @see https://httpwg.org/specs/rfc9110.html#preferred.date.format
55709
55935
  *
@@ -55798,8 +56024,7 @@ var require_date = /* @__PURE__ */ __commonJSMin(((exports, module) => {
55798
56024
  if (code2 < 48 || code2 > 57) return;
55799
56025
  second = (code1 - 48) * 10 + (code2 - 48);
55800
56026
  }
55801
- const result = new Date(Date.UTC(year, monthIdx, day, hour, minute, second));
55802
- return result.getUTCDay() === weekday ? result : void 0;
56027
+ return makeDate(year, monthIdx, day, hour, minute, second, weekday);
55803
56028
  }
55804
56029
  /**
55805
56030
  * @see https://httpwg.org/specs/rfc9110.html#obsolete.date.formats
@@ -55894,9 +56119,7 @@ var require_date = /* @__PURE__ */ __commonJSMin(((exports, module) => {
55894
56119
  if (yearDigit3 < 48 || yearDigit3 > 57) return;
55895
56120
  const yearDigit4 = date.charCodeAt(23);
55896
56121
  if (yearDigit4 < 48 || yearDigit4 > 57) return;
55897
- const year = (yearDigit1 - 48) * 1e3 + (yearDigit2 - 48) * 100 + (yearDigit3 - 48) * 10 + (yearDigit4 - 48);
55898
- const result = new Date(Date.UTC(year, monthIdx, day, hour, minute, second));
55899
- return result.getUTCDay() === weekday ? result : void 0;
56122
+ return makeDate((yearDigit1 - 48) * 1e3 + (yearDigit2 - 48) * 100 + (yearDigit3 - 48) * 10 + (yearDigit4 - 48), monthIdx, day, hour, minute, second, weekday);
55900
56123
  }
55901
56124
  /**
55902
56125
  * @see https://httpwg.org/specs/rfc9110.html#obsolete.date.formats
@@ -56003,8 +56226,7 @@ var require_date = /* @__PURE__ */ __commonJSMin(((exports, module) => {
56003
56226
  if (code2 < 48 || code2 > 57) return;
56004
56227
  second = (code1 - 48) * 10 + (code2 - 48);
56005
56228
  }
56006
- const result = new Date(Date.UTC(year, monthIdx, day, hour, minute, second));
56007
- return result.getUTCDay() === weekday ? result : void 0;
56229
+ return makeDate(year, monthIdx, day, hour, minute, second, weekday);
56008
56230
  }
56009
56231
  module.exports = { parseHttpDate };
56010
56232
  }));
@@ -56012,7 +56234,7 @@ var require_date = /* @__PURE__ */ __commonJSMin(((exports, module) => {
56012
56234
  //#region ../../node_modules/undici/lib/handler/cache-handler.js
56013
56235
  var require_cache_handler = /* @__PURE__ */ __commonJSMin(((exports, module) => {
56014
56236
  const util = require_util$5();
56015
- const { parseCacheControlHeader, parseVaryHeader, isEtagUsable } = require_cache$2();
56237
+ const { parseCacheControlHeader, hasInvalidCacheControlDirective, parseVaryHeader, hasVaryStar, isInvalidOrWildcardVaryHeader, isEtagUsable } = require_cache$2();
56016
56238
  const { parseHttpDate } = require_date();
56017
56239
  function noop() {}
56018
56240
  const HEURISTICALLY_CACHEABLE_STATUS_CODES = [
@@ -56031,6 +56253,62 @@ var require_cache_handler = /* @__PURE__ */ __commonJSMin(((exports, module) =>
56031
56253
  ];
56032
56254
  const NOT_UNDERSTOOD_STATUS_CODES = [206];
56033
56255
  const MAX_RESPONSE_AGE = 2147483647e3;
56256
+ function trimOWS(value) {
56257
+ return value.replace(/^[\t ]+|[\t ]+$/g, "");
56258
+ }
56259
+ function arrayIncludes(array, value) {
56260
+ for (let i = 0; i < array.length; i++) if (array[i] === value) return true;
56261
+ return false;
56262
+ }
56263
+ function appendConnectionHeaderTokens(headersToRemove, connectionHeader) {
56264
+ const values = Array.isArray(connectionHeader) ? connectionHeader : [connectionHeader];
56265
+ for (let i = 0; i < values.length; i++) {
56266
+ const tokens = values[i].split(",");
56267
+ for (let j = 0; j < tokens.length; j++) headersToRemove.push(trimOWS(tokens[j]).toLowerCase());
56268
+ }
56269
+ }
56270
+ function getSameOriginPath(cacheKey, location) {
56271
+ if (typeof location !== "string") return;
56272
+ let originUrl;
56273
+ let requestUrl;
56274
+ let locationUrl;
56275
+ try {
56276
+ originUrl = new URL(cacheKey.origin);
56277
+ requestUrl = new URL(cacheKey.path, originUrl);
56278
+ locationUrl = new URL(location, requestUrl);
56279
+ } catch {
56280
+ return;
56281
+ }
56282
+ if (locationUrl.origin !== originUrl.origin) return;
56283
+ return locationUrl.pathname + locationUrl.search;
56284
+ }
56285
+ function deleteCachedUri(store, cacheKey, path) {
56286
+ deleteCachedValue(store, {
56287
+ ...cacheKey,
56288
+ path
56289
+ });
56290
+ for (let i = 0; i < util.safeHTTPMethods.length; i++) {
56291
+ const method = util.safeHTTPMethods[i];
56292
+ if (method !== cacheKey.method) deleteCachedValue(store, {
56293
+ ...cacheKey,
56294
+ method,
56295
+ path
56296
+ });
56297
+ }
56298
+ }
56299
+ function deleteLocationTargets(store, cacheKey, headerValue) {
56300
+ if (headerValue === void 0) return;
56301
+ const values = Array.isArray(headerValue) ? headerValue : [headerValue];
56302
+ for (let i = 0; i < values.length; i++) {
56303
+ const path = getSameOriginPath(cacheKey, values[i]);
56304
+ if (path !== void 0) deleteCachedUri(store, cacheKey, path);
56305
+ }
56306
+ }
56307
+ function invalidateUnsafeRequest(store, cacheKey, resHeaders) {
56308
+ deleteCachedUri(store, cacheKey, cacheKey.path);
56309
+ deleteLocationTargets(store, cacheKey, resHeaders.location);
56310
+ deleteLocationTargets(store, cacheKey, resHeaders["content-location"]);
56311
+ }
56034
56312
  /**
56035
56313
  * @typedef {import('../../types/dispatcher.d.ts').default.DispatchHandler} DispatchHandler
56036
56314
  *
@@ -56090,32 +56368,52 @@ var require_cache_handler = /* @__PURE__ */ __commonJSMin(((exports, module) =>
56090
56368
  onResponseStart(controller, statusCode, resHeaders, statusMessage) {
56091
56369
  const downstreamOnHeaders = () => this.#handler.onResponseStart?.(controller, statusCode, resHeaders, statusMessage);
56092
56370
  const handler = this;
56093
- if (!util.safeHTTPMethods.includes(this.#cacheKey.method) && statusCode >= 200 && statusCode <= 399) {
56094
- try {
56095
- this.#store.delete(this.#cacheKey)?.catch?.(noop);
56096
- } catch {}
56371
+ if (!arrayIncludes(util.safeHTTPMethods, this.#cacheKey.method) && statusCode >= 200 && statusCode <= 399) {
56372
+ invalidateUnsafeRequest(this.#store, this.#cacheKey, resHeaders);
56097
56373
  return downstreamOnHeaders();
56098
56374
  }
56099
56375
  const cacheControlHeader = resHeaders["cache-control"];
56100
- const heuristicallyCacheable = resHeaders["last-modified"] && HEURISTICALLY_CACHEABLE_STATUS_CODES.includes(statusCode);
56101
- if (!cacheControlHeader && !resHeaders["expires"] && !heuristicallyCacheable && !this.#cacheByDefault) return downstreamOnHeaders();
56376
+ const heuristicallyCacheable = resHeaders["last-modified"] && arrayIncludes(HEURISTICALLY_CACHEABLE_STATUS_CODES, statusCode);
56377
+ if (!cacheControlHeader && !resHeaders["expires"] && !heuristicallyCacheable && !this.#cacheByDefault) {
56378
+ if (statusCode === 304 && resHeaders.vary && isInvalidOrWildcardVaryHeader(resHeaders.vary)) deleteCachedValue(this.#store, this.#cacheKey);
56379
+ return downstreamOnHeaders();
56380
+ }
56102
56381
  const cacheControlDirectives = cacheControlHeader ? parseCacheControlHeader(cacheControlHeader) : {};
56103
- if (!canCacheResponse(this.#cacheType, statusCode, resHeaders, cacheControlDirectives, this.#cacheKey.headers)) return downstreamOnHeaders();
56382
+ if (!canCacheResponse(this.#cacheType, statusCode, resHeaders, cacheControlDirectives, this.#cacheKey.headers)) {
56383
+ if (statusCode === 304 && (cacheControlHeader || revalidationResponseDisallowsCachedReuse(this.#cacheType, resHeaders, cacheControlDirectives))) deleteCachedValue(this.#store, this.#cacheKey);
56384
+ return downstreamOnHeaders();
56385
+ }
56104
56386
  const now = Date.now();
56105
- const resAge = resHeaders.age ? getAge(resHeaders.age) : void 0;
56106
- if (resAge && resAge >= MAX_RESPONSE_AGE) return downstreamOnHeaders();
56107
- const resDate = typeof resHeaders.date === "string" ? parseHttpDate(resHeaders.date) : void 0;
56387
+ const resAge = Object.hasOwn(resHeaders, "age") ? getAge(resHeaders.age) : void 0;
56388
+ if (resAge !== void 0 && resAge >= MAX_RESPONSE_AGE) {
56389
+ deleteCachedValueIfNotModified(statusCode, this.#store, this.#cacheKey);
56390
+ return downstreamOnHeaders();
56391
+ }
56392
+ const resDate = Object.hasOwn(resHeaders, "date") ? getDate(resHeaders.date) : void 0;
56393
+ if (resDate === null) {
56394
+ deleteCachedValueIfNotModified(statusCode, this.#store, this.#cacheKey);
56395
+ return downstreamOnHeaders();
56396
+ }
56397
+ const apparentAge = resDate ? Math.max(0, now - resDate.getTime()) : 0;
56398
+ const currentAge = Math.max(apparentAge, resAge ?? 0);
56108
56399
  const staleAt = determineStaleAt(this.#cacheType, now, resAge, resHeaders, resDate, cacheControlDirectives) ?? this.#cacheByDefault;
56109
- if (staleAt === void 0 || resAge && resAge > staleAt) return downstreamOnHeaders();
56110
- const baseTime = resDate ? resDate.getTime() : now;
56400
+ if (staleAt === void 0 || currentAge >= staleAt) {
56401
+ if (cacheControlHeader || staleAt !== void 0) deleteCachedValueIfNotModified(statusCode, this.#store, this.#cacheKey);
56402
+ return downstreamOnHeaders();
56403
+ }
56404
+ const baseTime = now - currentAge;
56111
56405
  const absoluteStaleAt = staleAt + baseTime;
56112
- if (now >= absoluteStaleAt) return downstreamOnHeaders();
56406
+ if (now >= absoluteStaleAt) {
56407
+ deleteCachedValueIfNotModified(statusCode, this.#store, this.#cacheKey);
56408
+ return downstreamOnHeaders();
56409
+ }
56113
56410
  let varyDirectives;
56114
56411
  if (this.#cacheKey.headers && resHeaders.vary) {
56115
56412
  varyDirectives = parseVaryHeader(resHeaders.vary, this.#cacheKey.headers);
56116
56413
  if (!varyDirectives) return downstreamOnHeaders();
56117
56414
  }
56118
- const deleteAt = determineDeleteAt(baseTime, cacheControlDirectives, absoluteStaleAt);
56415
+ const cachedAt = baseTime;
56416
+ const deleteAt = determineDeleteAt(baseTime, now, cacheControlDirectives, absoluteStaleAt);
56119
56417
  const strippedHeaders = stripNecessaryHeaders(resHeaders, cacheControlDirectives);
56120
56418
  /**
56121
56419
  * @type {import('../../types/cache-interceptor.d.ts').default.CacheValue}
@@ -56126,7 +56424,7 @@ var require_cache_handler = /* @__PURE__ */ __commonJSMin(((exports, module) =>
56126
56424
  headers: strippedHeaders,
56127
56425
  vary: varyDirectives,
56128
56426
  cacheControlDirectives,
56129
- cachedAt: resAge ? now - resAge : now,
56427
+ cachedAt,
56130
56428
  staleAt: absoluteStaleAt,
56131
56429
  deleteAt
56132
56430
  };
@@ -56136,6 +56434,7 @@ var require_cache_handler = /* @__PURE__ */ __commonJSMin(((exports, module) =>
56136
56434
  value.statusCode = cachedValue.statusCode;
56137
56435
  value.statusMessage = cachedValue.statusMessage;
56138
56436
  value.etag = cachedValue.etag;
56437
+ value.vary = varyDirectives ?? cachedValue.vary;
56139
56438
  value.headers = {
56140
56439
  ...cachedValue.headers,
56141
56440
  ...strippedHeaders
@@ -56214,6 +56513,27 @@ var require_cache_handler = /* @__PURE__ */ __commonJSMin(((exports, module) =>
56214
56513
  }
56215
56514
  };
56216
56515
  /**
56516
+ * @param {import('../../types/cache-interceptor.d.ts').default.CacheStore} store
56517
+ * @param {import('../../types/cache-interceptor.d.ts').default.CacheKey} cacheKey
56518
+ */
56519
+ function deleteCachedValue(store, cacheKey) {
56520
+ try {
56521
+ store.delete(cacheKey)?.catch?.(noop);
56522
+ } catch {}
56523
+ }
56524
+ function deleteCachedValueIfNotModified(statusCode, store, cacheKey) {
56525
+ if (statusCode === 304) deleteCachedValue(store, cacheKey);
56526
+ }
56527
+ /**
56528
+ * @param {import('../../types/cache-interceptor.d.ts').default.CacheOptions['type']} cacheType
56529
+ * @param {import('../../types/header.d.ts').IncomingHttpHeaders} resHeaders
56530
+ * @param {import('../../types/cache-interceptor.d.ts').default.CacheControlDirectives} cacheControlDirectives
56531
+ * @returns {boolean}
56532
+ */
56533
+ function revalidationResponseDisallowsCachedReuse(cacheType, resHeaders, cacheControlDirectives) {
56534
+ return cacheControlDirectives["no-store"] === true || cacheType === "shared" && cacheControlDirectives.private === true || (resHeaders.vary ? isInvalidOrWildcardVaryHeader(resHeaders.vary) : false);
56535
+ }
56536
+ /**
56217
56537
  * @see https://www.rfc-editor.org/rfc/rfc9111.html#name-storing-responses-to-authen
56218
56538
  *
56219
56539
  * @param {import('../../types/cache-interceptor.d.ts').default.CacheOptions['type']} cacheType
@@ -56223,26 +56543,46 @@ var require_cache_handler = /* @__PURE__ */ __commonJSMin(((exports, module) =>
56223
56543
  * @param {import('../../types/header.d.ts').IncomingHttpHeaders} [reqHeaders]
56224
56544
  */
56225
56545
  function canCacheResponse(cacheType, statusCode, resHeaders, cacheControlDirectives, reqHeaders) {
56226
- if (statusCode < 200 || NOT_UNDERSTOOD_STATUS_CODES.includes(statusCode)) return false;
56227
- if (!HEURISTICALLY_CACHEABLE_STATUS_CODES.includes(statusCode) && !resHeaders["expires"] && !cacheControlDirectives.public && cacheControlDirectives["max-age"] === void 0 && !(cacheControlDirectives.private && cacheType === "private") && !(cacheControlDirectives["s-maxage"] !== void 0 && cacheType === "shared")) return false;
56546
+ if (statusCode < 200 || arrayIncludes(NOT_UNDERSTOOD_STATUS_CODES, statusCode)) return false;
56547
+ if (!arrayIncludes(HEURISTICALLY_CACHEABLE_STATUS_CODES, statusCode) && !resHeaders["expires"] && !cacheControlDirectives.public && cacheControlDirectives["max-age"] === void 0 && !(cacheControlDirectives.private && cacheType === "private") && !(cacheControlDirectives["s-maxage"] !== void 0 && cacheType === "shared")) return false;
56228
56548
  if (cacheControlDirectives["no-store"]) return false;
56229
56549
  if (cacheType === "shared" && cacheControlDirectives.private === true) return false;
56230
- if (resHeaders.vary?.includes("*")) return false;
56231
- if (reqHeaders?.authorization) {
56550
+ if (resHeaders.vary && hasVaryStar(resHeaders.vary)) return false;
56551
+ if (reqHeaders != null && Object.hasOwn(reqHeaders, "authorization")) {
56232
56552
  if (!cacheControlDirectives.public && !cacheControlDirectives["s-maxage"] && !cacheControlDirectives["must-revalidate"]) return false;
56233
56553
  if (typeof reqHeaders.authorization !== "string") return false;
56234
- if (Array.isArray(cacheControlDirectives["no-cache"]) && cacheControlDirectives["no-cache"].includes("authorization")) return false;
56235
- if (Array.isArray(cacheControlDirectives["private"]) && cacheControlDirectives["private"].includes("authorization")) return false;
56554
+ if (Array.isArray(cacheControlDirectives["no-cache"]) && arrayIncludes(cacheControlDirectives["no-cache"], "authorization")) return false;
56555
+ if (Array.isArray(cacheControlDirectives["private"]) && arrayIncludes(cacheControlDirectives["private"], "authorization")) return false;
56236
56556
  }
56237
56557
  return true;
56238
56558
  }
56239
56559
  /**
56560
+ * @param {string | string[]} dateHeader
56561
+ * @returns {Date | null | undefined}
56562
+ */
56563
+ function getDate(dateHeader) {
56564
+ let dateValue = dateHeader;
56565
+ if (Array.isArray(dateValue)) {
56566
+ if (dateValue.length !== 1) return null;
56567
+ dateValue = dateValue[0];
56568
+ }
56569
+ if (typeof dateValue !== "string") return null;
56570
+ return parseHttpDate(dateValue);
56571
+ }
56572
+ /**
56240
56573
  * @param {string | string[]} ageHeader
56241
56574
  * @returns {number | undefined}
56242
56575
  */
56243
56576
  function getAge(ageHeader) {
56244
- const age = parseInt(Array.isArray(ageHeader) ? ageHeader[0] : ageHeader);
56245
- return isNaN(age) ? void 0 : age * 1e3;
56577
+ let ageValue = ageHeader;
56578
+ if (Array.isArray(ageValue)) {
56579
+ if (ageValue.length !== 1) return MAX_RESPONSE_AGE;
56580
+ ageValue = ageValue[0];
56581
+ }
56582
+ if (typeof ageValue !== "string" || !/^[\t ]*[0-9]+[\t ]*$/.test(ageValue)) return MAX_RESPONSE_AGE;
56583
+ const age = BigInt(ageValue.replace(/^[\t ]+|[\t ]+$/g, ""));
56584
+ if (age >= BigInt(MAX_RESPONSE_AGE / 1e3)) return MAX_RESPONSE_AGE;
56585
+ return Number(age) * 1e3;
56246
56586
  }
56247
56587
  /**
56248
56588
  * @param {import('../../types/cache-interceptor.d.ts').default.CacheOptions['type']} cacheType
@@ -56256,44 +56596,53 @@ var require_cache_handler = /* @__PURE__ */ __commonJSMin(((exports, module) =>
56256
56596
  */
56257
56597
  function determineStaleAt(cacheType, now, age, resHeaders, responseDate, cacheControlDirectives) {
56258
56598
  if (cacheType === "shared") {
56599
+ if (hasInvalidCacheControlDirective(cacheControlDirectives, "s-maxage")) return 0;
56259
56600
  const sMaxAge = cacheControlDirectives["s-maxage"];
56260
- if (sMaxAge !== void 0) return sMaxAge > 0 ? sMaxAge * 1e3 : void 0;
56601
+ if (sMaxAge !== void 0) return sMaxAge * 1e3;
56261
56602
  }
56603
+ if (hasInvalidCacheControlDirective(cacheControlDirectives, "max-age")) return 0;
56262
56604
  const maxAge = cacheControlDirectives["max-age"];
56263
- if (maxAge !== void 0) return maxAge > 0 ? maxAge * 1e3 : void 0;
56264
- if (typeof resHeaders.expires === "string") {
56605
+ if (maxAge !== void 0) return maxAge * 1e3;
56606
+ if (Object.hasOwn(resHeaders, "expires")) {
56607
+ if (typeof resHeaders.expires !== "string") return 0;
56265
56608
  const expiresDate = parseHttpDate(resHeaders.expires);
56266
- if (expiresDate) {
56267
- if (now >= expiresDate.getTime()) return;
56268
- if (responseDate) {
56269
- if (responseDate >= expiresDate) return;
56270
- if (age !== void 0 && age > expiresDate - responseDate) return;
56271
- }
56272
- return expiresDate.getTime() - now;
56609
+ if (!expiresDate) return 0;
56610
+ if (now >= expiresDate.getTime()) return 0;
56611
+ if (responseDate) {
56612
+ if (responseDate >= expiresDate) return 0;
56613
+ const freshnessLifetime = expiresDate.getTime() - responseDate.getTime();
56614
+ if (age !== void 0 && age >= freshnessLifetime) return 0;
56615
+ return freshnessLifetime;
56273
56616
  }
56617
+ return expiresDate.getTime() - now;
56274
56618
  }
56275
56619
  if (typeof resHeaders["last-modified"] === "string") {
56276
- const lastModified = new Date(resHeaders["last-modified"]);
56277
- if (isValidDate(lastModified)) {
56620
+ const lastModified = parseHttpDate(resHeaders["last-modified"]);
56621
+ if (lastModified) {
56278
56622
  if (lastModified.getTime() >= now) return;
56279
56623
  return (now - lastModified.getTime()) * .1;
56280
56624
  }
56281
56625
  }
56282
- if (cacheControlDirectives.immutable) return 31536e3;
56626
+ if (cacheControlDirectives.immutable) return 31536e6;
56283
56627
  }
56284
56628
  /**
56285
- * @param {number} now
56629
+ * @param {number} baseTime
56630
+ * @param {number} cachedAt
56286
56631
  * @param {import('../../types/cache-interceptor.d.ts').default.CacheControlDirectives} cacheControlDirectives
56287
56632
  * @param {number} staleAt
56288
56633
  */
56289
- function determineDeleteAt(now, cacheControlDirectives, staleAt) {
56634
+ function determineDeleteAt(baseTime, cachedAt, cacheControlDirectives, staleAt) {
56290
56635
  let staleWhileRevalidate = -Infinity;
56291
56636
  let staleIfError = -Infinity;
56292
56637
  let immutable = -Infinity;
56293
56638
  if (cacheControlDirectives["stale-while-revalidate"]) staleWhileRevalidate = staleAt + cacheControlDirectives["stale-while-revalidate"] * 1e3;
56294
56639
  if (cacheControlDirectives["stale-if-error"]) staleIfError = staleAt + cacheControlDirectives["stale-if-error"] * 1e3;
56295
- if (cacheControlDirectives.immutable && staleWhileRevalidate === -Infinity && staleIfError === -Infinity) immutable = now + 31536e6;
56296
- if (staleWhileRevalidate === -Infinity && staleIfError === -Infinity && immutable === -Infinity) return staleAt + (staleAt - now);
56640
+ if (cacheControlDirectives.immutable && staleWhileRevalidate === -Infinity && staleIfError === -Infinity) immutable = cachedAt + 31536e6;
56641
+ if (staleWhileRevalidate === -Infinity && staleIfError === -Infinity && immutable === -Infinity) {
56642
+ const freshnessLifetime = staleAt - baseTime;
56643
+ const datePrecisionPadding = Math.min(Math.max(cachedAt - baseTime, 0), 1e3);
56644
+ return staleAt + freshnessLifetime + datePrecisionPadding;
56645
+ }
56297
56646
  return Math.max(staleAt, staleWhileRevalidate, staleIfError, immutable);
56298
56647
  }
56299
56648
  /**
@@ -56314,24 +56663,16 @@ var require_cache_handler = /* @__PURE__ */ __commonJSMin(((exports, module) =>
56314
56663
  "upgrade",
56315
56664
  "age"
56316
56665
  ];
56317
- if (resHeaders["connection"]) if (Array.isArray(resHeaders["connection"])) headersToRemove.push(...resHeaders["connection"].map((header) => header.trim()));
56318
- else headersToRemove.push(...resHeaders["connection"].split(",").map((header) => header.trim()));
56666
+ if (resHeaders["connection"]) appendConnectionHeaderTokens(headersToRemove, resHeaders["connection"]);
56319
56667
  if (Array.isArray(cacheControlDirectives["no-cache"])) headersToRemove.push(...cacheControlDirectives["no-cache"]);
56320
56668
  if (Array.isArray(cacheControlDirectives["private"])) headersToRemove.push(...cacheControlDirectives["private"]);
56321
56669
  let strippedHeaders;
56322
- for (const headerName of headersToRemove) if (resHeaders[headerName]) {
56670
+ for (const headerName of headersToRemove) if (Object.hasOwn(resHeaders, headerName)) {
56323
56671
  strippedHeaders ??= { ...resHeaders };
56324
56672
  delete strippedHeaders[headerName];
56325
56673
  }
56326
56674
  return strippedHeaders ?? resHeaders;
56327
56675
  }
56328
- /**
56329
- * @param {Date} date
56330
- * @returns {boolean}
56331
- */
56332
- function isValidDate(date) {
56333
- return date instanceof Date && Number.isFinite(date.valueOf());
56334
- }
56335
56676
  module.exports = CacheHandler;
56336
56677
  }));
56337
56678
  //#endregion
@@ -56493,10 +56834,30 @@ var require_memory_cache_store = /* @__PURE__ */ __commonJSMin(((exports, module
56493
56834
  }
56494
56835
  };
56495
56836
  function findEntry(key, entries, now) {
56496
- return entries.find((entry) => entry.deleteAt > now && entry.method === key.method && (entry.vary == null || Object.keys(entry.vary).every((headerName) => {
56497
- if (entry.vary[headerName] === null) return key.headers[headerName] === void 0;
56498
- return entry.vary[headerName] === key.headers[headerName];
56499
- })));
56837
+ for (let i = 0; i < entries.length; i++) {
56838
+ const entry = entries[i];
56839
+ if (entry.deleteAt > now && entry.method === key.method && varyMatches(key, entry)) return entry;
56840
+ }
56841
+ }
56842
+ function varyMatches(key, entry) {
56843
+ if (entry.vary == null) return true;
56844
+ for (const headerName in entry.vary) if (Object.hasOwn(entry.vary, headerName) && !headerValueEquals(key.headers?.[headerName], entry.vary[headerName])) return false;
56845
+ return true;
56846
+ }
56847
+ /**
56848
+ * @param {string|string[]|null|undefined} lhs
56849
+ * @param {string|string[]|null|undefined} rhs
56850
+ * @returns {boolean}
56851
+ */
56852
+ function headerValueEquals(lhs, rhs) {
56853
+ if (lhs == null && rhs == null) return true;
56854
+ if (lhs == null && rhs != null || lhs != null && rhs == null) return false;
56855
+ if (Array.isArray(lhs) && Array.isArray(rhs)) {
56856
+ if (lhs.length !== rhs.length) return false;
56857
+ for (let i = 0; i < lhs.length; i++) if (lhs[i] !== rhs[i]) return false;
56858
+ return true;
56859
+ }
56860
+ return lhs === rhs;
56500
56861
  }
56501
56862
  module.exports = MemoryCacheStore;
56502
56863
  }));
@@ -56520,7 +56881,7 @@ var require_cache_revalidation_handler = /* @__PURE__ */ __commonJSMin(((exports
56520
56881
  var CacheRevalidationHandler = class {
56521
56882
  #successful = false;
56522
56883
  /**
56523
- * @type {((boolean, any) => void) | null}
56884
+ * @type {((success: boolean, context?: any, statusCode?: number, headers?: import('../../types/header.d.ts').IncomingHttpHeaders) => void) | null}
56524
56885
  */
56525
56886
  #callback;
56526
56887
  /**
@@ -56533,7 +56894,7 @@ var require_cache_revalidation_handler = /* @__PURE__ */ __commonJSMin(((exports
56533
56894
  */
56534
56895
  #allowErrorStatusCodes;
56535
56896
  /**
56536
- * @param {(boolean) => void} callback Function to call if the cached value is valid
56897
+ * @param {(success: boolean, context?: any, statusCode?: number, headers?: import('../../types/header.d.ts').IncomingHttpHeaders) => void} callback Function to call if the cached value is valid
56537
56898
  * @param {import('../../types/dispatcher.d.ts').default.DispatchHandlers} handler
56538
56899
  * @param {boolean} allowErrorStatusCodes
56539
56900
  */
@@ -56553,7 +56914,7 @@ var require_cache_revalidation_handler = /* @__PURE__ */ __commonJSMin(((exports
56553
56914
  onResponseStart(controller, statusCode, headers, statusMessage) {
56554
56915
  assert$11(this.#callback != null);
56555
56916
  this.#successful = statusCode === 304 || this.#allowErrorStatusCodes && statusCode >= 500 && statusCode <= 504;
56556
- this.#callback(this.#successful, this.#context);
56917
+ this.#callback(this.#successful, this.#context, statusCode, headers);
56557
56918
  this.#callback = null;
56558
56919
  if (this.#successful) return true;
56559
56920
  this.#handler.onRequestStart?.(controller, this.#context);
@@ -56588,8 +56949,9 @@ var require_cache$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
56588
56949
  const CacheHandler = require_cache_handler();
56589
56950
  const MemoryCacheStore = require_memory_cache_store();
56590
56951
  const CacheRevalidationHandler = require_cache_revalidation_handler();
56591
- const { assertCacheStore, assertCacheMethods, makeCacheKey, normalizeHeaders, parseCacheControlHeader } = require_cache$2();
56952
+ const { assertCacheStore, assertCacheMethods, makeCacheKey, normalizeHeaders, parseCacheControlHeader, isInvalidOrWildcardVaryHeader } = require_cache$2();
56592
56953
  const { AbortError } = require_errors$1();
56954
+ const { parseHttpDate } = require_date();
56593
56955
  /**
56594
56956
  * @param {(string | RegExp)[] | undefined} origins
56595
56957
  * @param {string} name
@@ -56603,6 +56965,25 @@ var require_cache$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
56603
56965
  }
56604
56966
  }
56605
56967
  const nop = () => {};
56968
+ function trimOWS(value) {
56969
+ return value.replace(/^[\t ]+|[\t ]+$/g, "");
56970
+ }
56971
+ function arrayIncludes(array, value) {
56972
+ for (let i = 0; i < array.length; i++) if (array[i] === value) return true;
56973
+ return false;
56974
+ }
56975
+ function hasPragmaNoCache(headers) {
56976
+ const pragma = headers?.pragma;
56977
+ if (!pragma) return false;
56978
+ const values = Array.isArray(pragma) ? pragma : [pragma];
56979
+ for (let i = 0; i < values.length; i++) {
56980
+ const value = values[i];
56981
+ if (typeof value !== "string") continue;
56982
+ const directives = value.split(",");
56983
+ for (let j = 0; j < directives.length; j++) if (trimOWS(directives[j]).toLowerCase() === "no-cache") return true;
56984
+ }
56985
+ return false;
56986
+ }
56606
56987
  /**
56607
56988
  * @typedef {(options: import('../../types/dispatcher.d.ts').default.DispatchOptions, handler: import('../../types/dispatcher.d.ts').default.DispatchHandler) => void} DispatchFn
56608
56989
  */
@@ -56620,13 +57001,57 @@ var require_cache$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
56620
57001
  }
56621
57002
  /**
56622
57003
  * @param {import('../../types/cache-interceptor.d.ts').default.GetResult} result
57004
+ * @param {import('../../types/cache-interceptor.d.ts').default.CacheOptions['type']} cacheType
57005
+ * @returns {boolean}
57006
+ */
57007
+ function staleResponseRequiresRevalidation(result, cacheType) {
57008
+ return result.cacheControlDirectives?.["must-revalidate"] === true || cacheType === "shared" && (result.cacheControlDirectives?.["proxy-revalidate"] === true || result.cacheControlDirectives?.["s-maxage"] !== void 0);
57009
+ }
57010
+ /**
57011
+ * @param {import('../../types/cache-interceptor.d.ts').default.CacheOptions['type']} cacheType
57012
+ * @param {import('../../types/header.d.ts').IncomingHttpHeaders} headers
57013
+ * @returns {boolean}
57014
+ */
57015
+ function revalidationResponseDisallowsCachedReuse(cacheType, headers) {
57016
+ if (headers.vary && isInvalidOrWildcardVaryHeader(headers.vary)) return true;
57017
+ const cacheControl = headers["cache-control"];
57018
+ if (!cacheControl) return false;
57019
+ const cacheControlDirectives = parseCacheControlHeader(cacheControl);
57020
+ return cacheControlDirectives["no-store"] === true || cacheType === "shared" && cacheControlDirectives.private === true;
57021
+ }
57022
+ function revalidationResponseUpdatesCacheControl(headers) {
57023
+ return headers["cache-control"] !== void 0;
57024
+ }
57025
+ function deleteCachedValue(store, cacheKey) {
57026
+ try {
57027
+ store.delete(cacheKey)?.catch?.(nop);
57028
+ } catch {}
57029
+ }
57030
+ function getUsableLastModified(headers) {
57031
+ const lastModified = headers?.["last-modified"];
57032
+ if (typeof lastModified === "string" && parseHttpDate(lastModified)) return lastModified;
57033
+ }
57034
+ function makeRevalidationHeaders(opts, result) {
57035
+ const headers = {
57036
+ ...opts.headers,
57037
+ "if-modified-since": getUsableLastModified(result.headers) ?? new Date(result.cachedAt).toUTCString()
57038
+ };
57039
+ if (result.etag) headers["if-none-match"] = result.etag;
57040
+ if (result.vary) {
57041
+ for (const key in result.vary) if (result.vary[key] != null) headers[key] = result.vary[key];
57042
+ }
57043
+ return headers;
57044
+ }
57045
+ /**
57046
+ * @param {import('../../types/cache-interceptor.d.ts').default.GetResult} result
56623
57047
  * @param {import('../../types/cache-interceptor.d.ts').default.CacheControlDirectives | undefined} cacheControlDirectives
57048
+ * @param {import('../../types/cache-interceptor.d.ts').default.CacheOptions['type']} cacheType
56624
57049
  * @returns {boolean}
56625
57050
  */
56626
- function isStale(result, cacheControlDirectives) {
57051
+ function isStale(result, cacheControlDirectives, cacheType) {
56627
57052
  const now = Date.now();
56628
57053
  if (now > result.staleAt) {
56629
- if (cacheControlDirectives?.["max-stale"]) return now > result.staleAt + cacheControlDirectives["max-stale"] * 1e3;
57054
+ if (!staleResponseRequiresRevalidation(result, cacheType) && cacheControlDirectives?.["max-stale"]) return now > result.staleAt + cacheControlDirectives["max-stale"] * 1e3;
56630
57055
  return true;
56631
57056
  }
56632
57057
  if (cacheControlDirectives?.["min-fresh"]) return result.staleAt - now <= cacheControlDirectives["min-fresh"] * 1e3;
@@ -56635,11 +57060,12 @@ var require_cache$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
56635
57060
  /**
56636
57061
  * Check if we're within the stale-while-revalidate window for a stale response
56637
57062
  * @param {import('../../types/cache-interceptor.d.ts').default.GetResult} result
57063
+ * @param {import('../../types/cache-interceptor.d.ts').default.CacheOptions['type']} cacheType
56638
57064
  * @returns {boolean}
56639
57065
  */
56640
- function withinStaleWhileRevalidateWindow(result) {
57066
+ function withinStaleWhileRevalidateWindow(result, cacheType) {
56641
57067
  const staleWhileRevalidate = result.cacheControlDirectives?.["stale-while-revalidate"];
56642
- if (!staleWhileRevalidate) return false;
57068
+ if (!staleWhileRevalidate || staleResponseRequiresRevalidation(result, cacheType)) return false;
56643
57069
  return Date.now() <= result.staleAt + staleWhileRevalidate * 1e3;
56644
57070
  }
56645
57071
  /**
@@ -56737,22 +57163,15 @@ var require_cache$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
56737
57163
  const now = Date.now();
56738
57164
  if (now > result.deleteAt) return dispatch(opts, new CacheHandler(globalOpts, cacheKey, handler));
56739
57165
  const age = Math.round((now - result.cachedAt) / 1e3);
56740
- if (reqCacheControl?.["max-age"] && age >= reqCacheControl["max-age"]) return dispatch(opts, handler);
56741
- const stale = isStale(result, reqCacheControl);
56742
- const revalidate = needsRevalidation(result, reqCacheControl, opts);
57166
+ const requestMaxAgeExpired = reqCacheControl?.["max-age"] !== void 0 && age >= reqCacheControl["max-age"];
57167
+ const stale = requestMaxAgeExpired || isStale(result, reqCacheControl, globalOpts.type);
57168
+ const revalidate = requestMaxAgeExpired || needsRevalidation(result, reqCacheControl, opts);
56743
57169
  if (stale || revalidate) {
56744
57170
  if (util.isStream(opts.body) && util.bodyLength(opts.body) !== 0) return dispatch(opts, new CacheHandler(globalOpts, cacheKey, handler));
56745
- if (!revalidate && withinStaleWhileRevalidateWindow(result)) {
57171
+ if (!revalidate && withinStaleWhileRevalidateWindow(result, globalOpts.type)) {
56746
57172
  sendCachedValue(handler, opts, result, age, null, true);
56747
57173
  queueMicrotask(() => {
56748
- const headers = {
56749
- ...opts.headers,
56750
- "if-modified-since": new Date(result.cachedAt).toUTCString()
56751
- };
56752
- if (result.etag) headers["if-none-match"] = result.etag;
56753
- if (result.vary) {
56754
- for (const key in result.vary) if (result.vary[key] != null) headers[key] = result.vary[key];
56755
- }
57174
+ const headers = makeRevalidationHeaders(opts, result);
56756
57175
  dispatch({
56757
57176
  ...opts,
56758
57177
  headers
@@ -56768,22 +57187,26 @@ var require_cache$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
56768
57187
  return true;
56769
57188
  }
56770
57189
  let withinStaleIfErrorThreshold = false;
56771
- const staleIfErrorExpiry = result.cacheControlDirectives["stale-if-error"] ?? reqCacheControl?.["stale-if-error"];
56772
- if (staleIfErrorExpiry) withinStaleIfErrorThreshold = now < result.staleAt + staleIfErrorExpiry * 1e3;
56773
- const headers = {
56774
- ...opts.headers,
56775
- "if-modified-since": new Date(result.cachedAt).toUTCString()
56776
- };
56777
- if (result.etag) headers["if-none-match"] = result.etag;
56778
- if (result.vary) {
56779
- for (const key in result.vary) if (result.vary[key] != null) headers[key] = result.vary[key];
57190
+ if (!staleResponseRequiresRevalidation(result, globalOpts.type)) {
57191
+ const staleIfErrorExpiry = result.cacheControlDirectives["stale-if-error"] ?? reqCacheControl?.["stale-if-error"];
57192
+ if (staleIfErrorExpiry) withinStaleIfErrorThreshold = now < result.staleAt + staleIfErrorExpiry * 1e3;
56780
57193
  }
57194
+ const headers = makeRevalidationHeaders(opts, result);
56781
57195
  return dispatch({
56782
57196
  ...opts,
56783
57197
  headers
56784
- }, new CacheRevalidationHandler((success, context) => {
56785
- if (success) sendCachedValue(handler, opts, result, age, context, stale);
56786
- else if (util.isStream(result.body)) result.body.on("error", nop).destroy();
57198
+ }, new CacheRevalidationHandler((success, context, statusCode, headers) => {
57199
+ if (success) {
57200
+ if (statusCode === 304) {
57201
+ if (revalidationResponseDisallowsCachedReuse(globalOpts.type, headers)) {
57202
+ if (util.isStream(result.body)) result.body.on("error", nop).destroy();
57203
+ deleteCachedValue(globalOpts.store, cacheKey);
57204
+ return dispatch(opts, new CacheHandler(globalOpts, cacheKey, handler));
57205
+ }
57206
+ if (revalidationResponseUpdatesCacheControl(headers)) deleteCachedValue(globalOpts.store, cacheKey);
57207
+ }
57208
+ sendCachedValue(handler, opts, result, age, context, stale);
57209
+ } else if (util.isStream(result.body)) result.body.on("error", nop).destroy();
56787
57210
  }, new CacheHandler(globalOpts, cacheKey, handler), withinStaleIfErrorThreshold));
56788
57211
  }
56789
57212
  if (util.isStream(opts.body)) opts.body.on("error", nop).destroy();
@@ -56807,10 +57230,14 @@ var require_cache$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
56807
57230
  cacheByDefault,
56808
57231
  type
56809
57232
  };
56810
- const safeMethodsToNotCache = util.safeHTTPMethods.filter((method) => methods.includes(method) === false);
57233
+ const safeMethodsToNotCache = [];
57234
+ for (let i = 0; i < util.safeHTTPMethods.length; i++) {
57235
+ const method = util.safeHTTPMethods[i];
57236
+ if (!arrayIncludes(methods, method)) safeMethodsToNotCache.push(method);
57237
+ }
56811
57238
  return (dispatch) => {
56812
57239
  return (opts, handler) => {
56813
- if (!opts.origin || safeMethodsToNotCache.includes(opts.method)) return dispatch(opts, handler);
57240
+ if (!opts.origin || arrayIncludes(safeMethodsToNotCache, opts.method)) return dispatch(opts, handler);
56814
57241
  if (origins !== void 0) {
56815
57242
  const requestOrigin = opts.origin.toString().toLowerCase();
56816
57243
  let isAllowed = false;
@@ -56832,7 +57259,7 @@ var require_cache$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
56832
57259
  ...opts,
56833
57260
  headers: normalizeHeaders(opts)
56834
57261
  };
56835
- const reqCacheControl = opts.headers?.["cache-control"] ? parseCacheControlHeader(opts.headers["cache-control"]) : void 0;
57262
+ const reqCacheControl = opts.headers?.["cache-control"] ? parseCacheControlHeader(opts.headers["cache-control"]) : hasPragmaNoCache(opts.headers) ? { "no-cache": true } : void 0;
56836
57263
  if (reqCacheControl?.["no-store"]) return dispatch(opts, handler);
56837
57264
  /**
56838
57265
  * @type {import('../../types/cache-interceptor.d.ts').default.CacheKey}
@@ -57760,7 +58187,8 @@ var require_sqlite_cache_store = /* @__PURE__ */ __commonJSMin(((exports, module
57760
58187
  if (lhs == null && rhs != null || lhs != null && rhs == null) return false;
57761
58188
  if (Array.isArray(lhs) && Array.isArray(rhs)) {
57762
58189
  if (lhs.length !== rhs.length) return false;
57763
- return lhs.every((x, i) => x === rhs[i]);
58190
+ for (let i = 0; i < lhs.length; i++) if (lhs[i] !== rhs[i]) return false;
58191
+ return true;
57764
58192
  }
57765
58193
  return lhs === rhs;
57766
58194
  }
@@ -60647,16 +61075,54 @@ var require_util$2 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
60647
61075
  function validateCookiePath(path) {
60648
61076
  for (let i = 0; i < path.length; ++i) {
60649
61077
  const code = path.charCodeAt(i);
60650
- if (code < 32 || code === 127 || code === 59) throw new Error("Invalid cookie path");
61078
+ if (code < 32 || code > 126 || code === 59) throw new Error("Invalid cookie path");
60651
61079
  }
60652
61080
  }
60653
61081
  /**
60654
- * I have no idea why these values aren't allowed to be honest,
60655
- * but Deno tests these. - Khafra
61082
+ * <let-dig> ::= <letter> | <digit>
61083
+ *
61084
+ * <letter> ::= any one of the 52 alphabetic characters A through Z in
61085
+ * upper case and a through z in lower case
61086
+ *
61087
+ * <digit> ::= any one of the ten digits 0 through 9r
61088
+ *
61089
+ * @see https://www.rfc-editor.org/rfc/rfc1034#section-3.5
61090
+ * @param {number} code
61091
+ */
61092
+ function isLetterOrDigit(code) {
61093
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122;
61094
+ }
61095
+ /**
61096
+ * Validates a cookie domain against the "preferred name syntax".
61097
+ *
61098
+ * <domain> ::= <subdomain> | " "
61099
+ * <subdomain> ::= <label> | <subdomain> "." <label>
61100
+ * <label> ::= <let-dig> [ [ <ldh-str> ] <let-dig> ]
61101
+ * <ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str>
61102
+ * <let-dig-hyp> ::= <let-dig> | "-"
61103
+ *
61104
+ * @see https://www.rfc-editor.org/rfc/rfc1034#section-3.5
61105
+ * @see https://www.rfc-editor.org/rfc/rfc1123#section-2.1
61106
+ * @see https://www.rfc-editor.org/rfc/rfc1035#section-2.3.4
60656
61107
  * @param {string} domain
60657
61108
  */
60658
61109
  function validateCookieDomain(domain) {
60659
- if (domain.startsWith("-") || domain.endsWith(".") || domain.endsWith("-")) throw new Error("Invalid cookie domain");
61110
+ if (domain === " ") return;
61111
+ if (domain.length > 255) throw new Error("Invalid cookie domain");
61112
+ let labelLength = 0;
61113
+ for (let i = 0; i < domain.length; ++i) {
61114
+ const code = domain.charCodeAt(i);
61115
+ if (code === 46) {
61116
+ if (labelLength === 0) throw new Error("Invalid cookie domain");
61117
+ if (domain.charCodeAt(i - 1) === 45) throw new Error("Invalid cookie domain");
61118
+ labelLength = 0;
61119
+ continue;
61120
+ }
61121
+ if (labelLength === 0 && !isLetterOrDigit(code)) throw new Error("Invalid cookie domain");
61122
+ if (!isLetterOrDigit(code) && code !== 45) throw new Error("Invalid cookie domain");
61123
+ if (++labelLength > 63) throw new Error("Invalid cookie domain");
61124
+ }
61125
+ if (labelLength === 0 || domain.charCodeAt(domain.length - 1) === 45) throw new Error("Invalid cookie domain");
60660
61126
  }
60661
61127
  const IMFDays = [
60662
61128
  "Sun",
@@ -60771,7 +61237,11 @@ var require_util$2 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
60771
61237
  for (const part of cookie.unparsed) {
60772
61238
  if (!part.includes("=")) throw new Error("Invalid unparsed");
60773
61239
  const [key, ...value] = part.split("=");
60774
- out.push(`${key.trim()}=${value.join("=")}`);
61240
+ const trimmedKey = key.trim();
61241
+ const joinedValue = value.join("=");
61242
+ validateCookieName(trimmedKey);
61243
+ validateCookieValue(joinedValue);
61244
+ out.push(`${trimmedKey}=${joinedValue}`);
60775
61245
  }
60776
61246
  return out.join("; ");
60777
61247
  }
@@ -64513,7 +64983,7 @@ var require_tags = /* @__PURE__ */ __commonJSMin(((exports) => {
64513
64983
  return mod && mod.__esModule ? mod : { "default": mod };
64514
64984
  };
64515
64985
  Object.defineProperty(exports, "__esModule", { value: true });
64516
- exports.getSpanTags = exports.getMissingRequiredGitTags = exports.REQUIRED_GIT_TAGS = exports.parseMeasuresFile = exports.parseTagsFile = exports.parseMetrics = exports.parseTags = exports.SERVICE = exports.SERVERLESS_CLI_VERSION_TAG_VALUE = exports.SERVERLESS_CLI_VERSION_TAG_NAME = exports.SBOM_TOOL_GENERATOR_VERSION = exports.SBOM_TOOL_GENERATOR_NAME = exports.PR_NUMBER = exports.GIT_PULL_REQUEST_BASE_BRANCH = exports.GIT_PULL_REQUEST_BASE_BRANCH_HEAD_SHA = exports.GIT_PULL_REQUEST_BASE_BRANCH_SHA = exports.GIT_HEAD_SHA = exports.GIT_TAG = exports.GIT_SHA = exports.GIT_COMMIT_MESSAGE = exports.GIT_COMMIT_COMMITTER_NAME = exports.GIT_COMMIT_COMMITTER_EMAIL = exports.GIT_COMMIT_COMMITTER_DATE = exports.GIT_COMMIT_AUTHOR_NAME = exports.GIT_COMMIT_AUTHOR_EMAIL = exports.GIT_COMMIT_AUTHOR_DATE = exports.GIT_BRANCH = exports.CI_ENV_VARS = exports.CI_NODE_LABELS = exports.CI_NODE_NAME = exports.CI_STAGE_NAME = exports.CI_JOB_ID = exports.CI_JOB_NAME = exports.CI_JOB_URL = exports.GIT_REPOSITORY_URL = exports.CI_WORKSPACE_PATH = exports.CI_PIPELINE_NUMBER = exports.CI_PIPELINE_NAME = exports.CI_PIPELINE_ID = exports.CI_PROVIDER_NAME = exports.CI_PIPELINE_URL = void 0;
64986
+ exports.getSpanTags = exports.getMissingRequiredGitTags = exports.REQUIRED_GIT_TAGS = exports.parseMeasuresFile = exports.parseTagsFile = exports.parseMetrics = exports.parseTags = exports.SERVICE = exports.SERVERLESS_CLI_VERSION_TAG_VALUE = exports.SERVERLESS_CLI_VERSION_TAG_NAME = exports.SBOM_TOOL_GENERATOR_VERSION = exports.SBOM_TOOL_GENERATOR_NAME = exports.PR_NUMBER = exports.GIT_PULL_REQUEST_BASE_BRANCH = exports.GIT_PULL_REQUEST_BASE_BRANCH_HEAD_SHA = exports.GIT_PULL_REQUEST_BASE_BRANCH_SHA = exports.GIT_HEAD_SHA = exports.GIT_TAG = exports.GIT_SHA = exports.GIT_COMMIT_MESSAGE = exports.GIT_COMMIT_COMMITTER_NAME = exports.GIT_COMMIT_COMMITTER_EMAIL = exports.GIT_COMMIT_COMMITTER_DATE = exports.GIT_COMMIT_AUTHOR_NAME = exports.GIT_COMMIT_AUTHOR_EMAIL = exports.GIT_COMMIT_AUTHOR_DATE = exports.GIT_BRANCH = exports.CI_ENV_VARS = exports.CI_NODE_LABELS = exports.CI_NODE_NAME = exports.CI_STAGE_NAME = exports.CI_JOB_ID = exports.CI_JOB_NAME = exports.CI_JOB_URL = exports.GIT_REPOSITORY_URL = exports.CI_WORKSPACE_PATH = exports.CI_PIPELINE_NUMBER = exports.CI_PIPELINE_DISPLAY_NAME = exports.CI_PIPELINE_NAME = exports.CI_PIPELINE_ID = exports.CI_PROVIDER_NAME = exports.CI_PIPELINE_URL = void 0;
64517
64987
  const fs_1$3 = __importDefault(require("fs"));
64518
64988
  const chalk_1 = __importDefault(require_source());
64519
64989
  const upath_1 = __importDefault(require_upath());
@@ -64526,6 +64996,7 @@ var require_tags = /* @__PURE__ */ __commonJSMin(((exports) => {
64526
64996
  exports.CI_PROVIDER_NAME = "ci.provider.name";
64527
64997
  exports.CI_PIPELINE_ID = "ci.pipeline.id";
64528
64998
  exports.CI_PIPELINE_NAME = "ci.pipeline.name";
64999
+ exports.CI_PIPELINE_DISPLAY_NAME = "ci.pipeline.display_name";
64529
65000
  exports.CI_PIPELINE_NUMBER = "ci.pipeline.number";
64530
65001
  exports.CI_WORKSPACE_PATH = "ci.workspace_path";
64531
65002
  exports.GIT_REPOSITORY_URL = "git.repository_url";
@@ -65097,7 +65568,7 @@ var require_ci = /* @__PURE__ */ __commonJSMin(((exports) => {
65097
65568
  }
65098
65569
  }
65099
65570
  if (env.BUILDKITE) {
65100
- const { BUILDKITE_AGENT_ID, BUILDKITE_BRANCH, BUILDKITE_COMMIT, BUILDKITE_REPO, BUILDKITE_TAG, BUILDKITE_BUILD_ID, BUILDKITE_PIPELINE_SLUG, BUILDKITE_BUILD_NUMBER, BUILDKITE_BUILD_URL, BUILDKITE_JOB_ID, BUILDKITE_BUILD_CHECKOUT_PATH, BUILDKITE_BUILD_AUTHOR, BUILDKITE_BUILD_AUTHOR_EMAIL, BUILDKITE_MESSAGE, BUILDKITE_PULL_REQUEST, BUILDKITE_PULL_REQUEST_BASE_BRANCH } = env;
65571
+ const { BUILDKITE_AGENT_ID, BUILDKITE_BRANCH, BUILDKITE_COMMIT, BUILDKITE_REPO, BUILDKITE_TAG, BUILDKITE_BUILD_ID, BUILDKITE_PIPELINE_SLUG, BUILDKITE_PIPELINE_NAME, BUILDKITE_BUILD_NUMBER, BUILDKITE_BUILD_URL, BUILDKITE_JOB_ID, BUILDKITE_BUILD_CHECKOUT_PATH, BUILDKITE_BUILD_AUTHOR, BUILDKITE_BUILD_AUTHOR_EMAIL, BUILDKITE_MESSAGE, BUILDKITE_PULL_REQUEST, BUILDKITE_PULL_REQUEST_BASE_BRANCH } = env;
65101
65572
  const extraTags = Object.keys(env).filter((envVar) => envVar.startsWith("BUILDKITE_AGENT_META_DATA_")).map((metadataKey) => {
65102
65573
  return `${metadataKey.replace("BUILDKITE_AGENT_META_DATA_", "").toLowerCase()}:${env[metadataKey]}`;
65103
65574
  });
@@ -65106,6 +65577,7 @@ var require_ci = /* @__PURE__ */ __commonJSMin(((exports) => {
65106
65577
  [tags_1.CI_PROVIDER_NAME]: exports.CI_ENGINES.BUILDKITE,
65107
65578
  [tags_1.CI_PIPELINE_ID]: BUILDKITE_BUILD_ID,
65108
65579
  [tags_1.CI_PIPELINE_NAME]: BUILDKITE_PIPELINE_SLUG,
65580
+ [tags_1.CI_PIPELINE_DISPLAY_NAME]: BUILDKITE_PIPELINE_NAME,
65109
65581
  [tags_1.CI_PIPELINE_NUMBER]: BUILDKITE_BUILD_NUMBER,
65110
65582
  [tags_1.CI_PIPELINE_URL]: BUILDKITE_BUILD_URL,
65111
65583
  [tags_1.CI_JOB_URL]: `${BUILDKITE_BUILD_URL}#${BUILDKITE_JOB_ID}`,
@@ -76008,6 +76480,7 @@ var require_datadog_route = /* @__PURE__ */ __commonJSMin(((exports) => {
76008
76480
  "/synthetics/mobile/applications/:applicationId/multipart-upload-complete",
76009
76481
  "/synthetics/mobile/applications/validation-job-status/:jobId",
76010
76482
  "/synthetics/settings",
76483
+ "/synthetics/suites/:suiteId",
76011
76484
  "/synthetics/tests/:testId",
76012
76485
  "/synthetics/tests/:testId/version_history/:version?only_check_existence=true",
76013
76486
  "/synthetics/tests/:testType/:testId",
@@ -76347,6 +76820,7 @@ var require_gitdb = /* @__PURE__ */ __commonJSMin(((exports) => {
76347
76820
  const semver_1 = require_semver();
76348
76821
  const upath_1 = __importDefault(require_upath());
76349
76822
  const get_git_data_1 = require_get_git_data();
76823
+ const request_1 = require_request();
76350
76824
  const datadog_route_1 = require_datadog_route();
76351
76825
  const retry_1 = require_retry();
76352
76826
  const API_TIMEOUT = 15e3;
@@ -76354,6 +76828,12 @@ var require_gitdb = /* @__PURE__ */ __commonJSMin(((exports) => {
76354
76828
  maxCommits: 1e3,
76355
76829
  oldestCommits: "1 month ago"
76356
76830
  };
76831
+ const formatResponseData = (data) => typeof data === "string" ? data : JSON.stringify(data);
76832
+ const formatRequestError = (reqName, error) => {
76833
+ if (!(0, request_1.isRequestError)(error)) return `${reqName} request failed: ${String(error)}`;
76834
+ if (!error.response) return `${reqName} request failed: ${error.message}`;
76835
+ return `${reqName} request failed (status ${[error.response.status, error.response.statusText].filter(Boolean).join(" ")}): ${formatResponseData(error.response.data)}`;
76836
+ };
76357
76837
  const getCommitsToInclude = (log, request, git, repositoryURL) => __awaiter(void 0, void 0, void 0, function* () {
76358
76838
  let latestCommits;
76359
76839
  try {
@@ -76508,7 +76988,10 @@ var require_gitdb = /* @__PURE__ */ __commonJSMin(((exports) => {
76508
76988
  timeout: API_TIMEOUT
76509
76989
  }));
76510
76990
  const commits = response.data;
76511
- if (!commits || commits.data === void 0) throw new Error(`Invalid API response: ${response}`);
76991
+ if (!commits || commits.data === void 0) {
76992
+ const status = [response.status, response.statusText].filter(Boolean).join(" ");
76993
+ throw new Error(`Invalid API response from search_commits (status ${status}): ${formatResponseData(response.data)}`);
76994
+ }
76512
76995
  return commits.data.map((c) => {
76513
76996
  if (c.type !== "commit" || c.id === void 0) throw new Error("Invalid commit type response");
76514
76997
  return validateCommit(c.id);
@@ -76587,15 +77070,17 @@ var require_gitdb = /* @__PURE__ */ __commonJSMin(((exports) => {
76587
77070
  });
76588
77071
  exports.uploadPackfile = uploadPackfile;
76589
77072
  const runRequest = (log, reqName, request) => __awaiter(void 0, void 0, void 0, function* () {
76590
- return (0, retry_1.retryRequest)(request, {
76591
- retries: 2,
76592
- onRetry: (e, attempt) => {
76593
- let errorMessage = `${e}`;
76594
- const maybeHttpError = e;
76595
- if (maybeHttpError.response && maybeHttpError.response.statusText) errorMessage = `${maybeHttpError.message} (${maybeHttpError.response.statusText})`;
76596
- log.warn(`[attempt ${attempt}] Retrying ${reqName} request: ${errorMessage}`);
76597
- }
76598
- });
77073
+ try {
77074
+ return yield (0, retry_1.retryRequest)(request, {
77075
+ retries: 2,
77076
+ onRetry: (error, attempt) => {
77077
+ log.warn(`[attempt ${attempt}] ${formatRequestError(reqName, error)}; retrying`);
77078
+ }
77079
+ });
77080
+ } catch (error) {
77081
+ if ((0, request_1.isRequestError)(error)) error.message = formatRequestError(reqName, error);
77082
+ throw error;
77083
+ }
76599
77084
  });
76600
77085
  }));
76601
77086
  //#endregion