dowwntime 1.4.0 → 1.5.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/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
  });
@@ -28323,7 +28332,11 @@ const run = async (options) => {
28323
28332
  const multipleServers = servers.length > 1;
28324
28333
  const fetchConfigurations = /* @__PURE__ */ new Map();
28325
28334
  for (const server of servers) {
28326
- const baseUrl = server.url;
28335
+ let baseUrl = server.url;
28336
+ if (server.variables) for (const [name, variable] of Object.entries(server.variables)) {
28337
+ const v = variable;
28338
+ if (v.default != null) baseUrl = baseUrl.replaceAll(`{${name}}`, v.default);
28339
+ }
28327
28340
  const serverLabel = server.description ?? new URL(baseUrl).host;
28328
28341
  if (schema$6.paths) for (const path$4 of Object.keys(schema$6.paths)) {
28329
28342
  const pathItem = schema$6.paths[path$4];
@@ -28379,6 +28392,7 @@ const run = async (options) => {
28379
28392
  return {
28380
28393
  statusCode: 0,
28381
28394
  durationMs: Date.now() - start,
28395
+ body: void 0,
28382
28396
  url: url$2.toString(),
28383
28397
  timestamp: start
28384
28398
  };
@@ -28393,7 +28407,8 @@ const run = async (options) => {
28393
28407
  const durationMs = Math.round(results.reduce((acc, curr) => acc + (curr?.durationMs ?? 0), 0) / results.length);
28394
28408
  let status = "down";
28395
28409
  const statusCode = Math.max(...results.map((r) => r?.statusCode ?? 0));
28396
- if (options.getStatus) status = options.getStatus(statusCode, path$4, durationMs);
28410
+ const lastBody = results.findLast((r) => r?.body !== void 0)?.body;
28411
+ if (options.getStatus) status = options.getStatus(statusCode, path$4, durationMs, lastBody);
28397
28412
  else status = statusCode >= 200 && statusCode < 300 ? "up" : "down";
28398
28413
  const measurement = {
28399
28414
  status,