dowwntime 1.4.0 → 1.5.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.
package/dist/cli.mjs CHANGED
@@ -14890,14 +14890,23 @@ const measureRequest = async (url$2, options) => {
14890
14890
  let tlsHandshakeAt;
14891
14891
  let firstByteAt;
14892
14892
  const req = ((typeof url$2 === "string" ? new URL(url$2) : url$2).protocol === "https:" ? https : http).request(url$2, options, (res) => {
14893
- res.on("data", () => {
14893
+ const chunks = [];
14894
+ res.on("data", (chunk) => {
14894
14895
  if (!firstByteAt) firstByteAt = Date.now();
14896
+ chunks.push(chunk);
14895
14897
  });
14896
14898
  res.on("end", () => {
14897
14899
  const durationMs = (firstByteAt ? firstByteAt - startAt : 0) - (tlsHandshakeAt ? tlsHandshakeAt - startAt : 0);
14900
+ let body;
14901
+ try {
14902
+ body = JSON.parse(Buffer.concat(chunks).toString());
14903
+ } catch {
14904
+ body = void 0;
14905
+ }
14898
14906
  resolve$1({
14899
14907
  statusCode: res.statusCode || 0,
14900
- durationMs: Math.max(0, durationMs)
14908
+ durationMs: Math.max(0, durationMs),
14909
+ body
14901
14910
  });
14902
14911
  });
14903
14912
  });
@@ -28379,6 +28388,7 @@ const run = async (options) => {
28379
28388
  return {
28380
28389
  statusCode: 0,
28381
28390
  durationMs: Date.now() - start,
28391
+ body: void 0,
28382
28392
  url: url$2.toString(),
28383
28393
  timestamp: start
28384
28394
  };
@@ -28393,7 +28403,8 @@ const run = async (options) => {
28393
28403
  const durationMs = Math.round(results.reduce((acc, curr) => acc + (curr?.durationMs ?? 0), 0) / results.length);
28394
28404
  let status = "down";
28395
28405
  const statusCode = Math.max(...results.map((r) => r?.statusCode ?? 0));
28396
- if (options.getStatus) status = options.getStatus(statusCode, path$4, durationMs);
28406
+ const lastBody = results.findLast((r) => r?.body !== void 0)?.body;
28407
+ if (options.getStatus) status = options.getStatus(statusCode, path$4, durationMs, lastBody);
28397
28408
  else status = statusCode >= 200 && statusCode < 300 ? "up" : "down";
28398
28409
  const measurement = {
28399
28410
  status,