dowwntime 1.3.9 → 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
  });
@@ -28318,39 +28327,45 @@ const run = async (options) => {
28318
28327
  }));
28319
28328
  if (dereferenceResult.errors?.[0] || !dereferenceResult.schema) throw new Error("Failed to dereference OpenAPI spec.", { cause: dereferenceResult.errors?.[0] });
28320
28329
  const schema$6 = dereferenceResult.schema;
28321
- const baseUrl = options.baseUrl ?? schema$6.servers?.[0]?.url;
28322
- if (!baseUrl) throw new Error("No base URL found in OpenAPI spec and no baseUrl option provided.");
28330
+ const servers = options.baseUrl ? [{ url: options.baseUrl }] : schema$6.servers ?? [];
28331
+ if (servers.length === 0) throw new Error("No base URL found in OpenAPI spec and no baseUrl option provided.");
28332
+ const multipleServers = servers.length > 1;
28323
28333
  const fetchConfigurations = /* @__PURE__ */ new Map();
28324
- if (schema$6.paths) for (const path$4 of Object.keys(schema$6.paths)) {
28325
- const pathItem = schema$6.paths[path$4];
28326
- if (!pathItem) continue;
28327
- if (!pathItem.get) continue;
28328
- const url$2 = new URL(path$4, baseUrl);
28329
- let _path = path$4;
28330
- if ("200" in (pathItem.get?.responses ?? {}) && "text/event-stream" in (pathItem.get.responses?.["200"]?.content ?? {})) continue;
28331
- for (const param of pathItem.get.parameters || []) {
28332
- let exampleValue = options.getExampleValue?.(param.name, path$4) ?? param.example ?? param.examples?.[0] ?? param.schema?.example ?? param.schema?.examples?.[0];
28333
- if (!exampleValue && (param.required || param.in === "path") && "enum" in param.schema) {
28334
- const enumValues = param.schema.enum;
28335
- if (Array.isArray(enumValues) && enumValues.length > 0) exampleValue = enumValues[0];
28336
- }
28337
- if (!exampleValue && param.required) {
28338
- debug$1(`No example value for parameter ${param.name} in ${path$4}`);
28339
- continue;
28340
- }
28341
- if (param.in === "path") {
28342
- if (!exampleValue) {
28343
- debug$1(`No example value for path parameter ${param.name} in ${path$4}`);
28334
+ for (const server of servers) {
28335
+ const baseUrl = server.url;
28336
+ const serverLabel = server.description ?? new URL(baseUrl).host;
28337
+ if (schema$6.paths) for (const path$4 of Object.keys(schema$6.paths)) {
28338
+ const pathItem = schema$6.paths[path$4];
28339
+ if (!pathItem) continue;
28340
+ if (!pathItem.get) continue;
28341
+ const url$2 = new URL(path$4, baseUrl);
28342
+ let _path = path$4;
28343
+ if ("200" in (pathItem.get?.responses ?? {}) && "text/event-stream" in (pathItem.get.responses?.["200"]?.content ?? {})) continue;
28344
+ for (const param of pathItem.get.parameters || []) {
28345
+ let exampleValue = options.getExampleValue?.(param.name, path$4) ?? param.example ?? param.examples?.[0] ?? param.schema?.example ?? param.schema?.examples?.[0];
28346
+ if (!exampleValue && (param.required || param.in === "path") && "enum" in param.schema) {
28347
+ const enumValues = param.schema.enum;
28348
+ if (Array.isArray(enumValues) && enumValues.length > 0) exampleValue = enumValues[0];
28349
+ }
28350
+ if (!exampleValue && param.required) {
28351
+ debug$1(`No example value for parameter ${param.name} in ${path$4}`);
28344
28352
  continue;
28345
28353
  }
28346
- const placeholder = `{${param.name}}`;
28347
- _path = _path.replace(placeholder, exampleValue);
28348
- url$2.pathname = _path;
28354
+ if (param.in === "path") {
28355
+ if (!exampleValue) {
28356
+ debug$1(`No example value for path parameter ${param.name} in ${path$4}`);
28357
+ continue;
28358
+ }
28359
+ const placeholder = `{${param.name}}`;
28360
+ _path = _path.replace(placeholder, exampleValue);
28361
+ url$2.pathname = _path;
28362
+ }
28363
+ if (!exampleValue) continue;
28364
+ if (param.in === "query") url$2.searchParams.set(param.name, exampleValue);
28349
28365
  }
28350
- if (!exampleValue) continue;
28351
- if (param.in === "query") url$2.searchParams.set(param.name, exampleValue);
28366
+ const key = multipleServers ? `[${serverLabel}] ${path$4}` : path$4;
28367
+ fetchConfigurations.set(key, url$2);
28352
28368
  }
28353
- fetchConfigurations.set(path$4, url$2);
28354
28369
  }
28355
28370
  const measurements = new Storage(options.storagePath, options.maxSpaceUsageBytes ?? 262144 * .95);
28356
28371
  const measure = async (path$4) => {
@@ -28373,6 +28388,7 @@ const run = async (options) => {
28373
28388
  return {
28374
28389
  statusCode: 0,
28375
28390
  durationMs: Date.now() - start,
28391
+ body: void 0,
28376
28392
  url: url$2.toString(),
28377
28393
  timestamp: start
28378
28394
  };
@@ -28387,7 +28403,8 @@ const run = async (options) => {
28387
28403
  const durationMs = Math.round(results.reduce((acc, curr) => acc + (curr?.durationMs ?? 0), 0) / results.length);
28388
28404
  let status = "down";
28389
28405
  const statusCode = Math.max(...results.map((r) => r?.statusCode ?? 0));
28390
- 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);
28391
28408
  else status = statusCode >= 200 && statusCode < 300 ? "up" : "down";
28392
28409
  const measurement = {
28393
28410
  status,