bruce-models 1.7.7 → 1.7.8

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.
@@ -466,12 +466,18 @@ class CacheControl {
466
466
  }
467
467
  }
468
468
 
469
+ // TODO: Currently checks for CSV vs json specifically,
470
+ // Need to see if our api is generally good at setting content-type headers.
471
+ // Make it less specific to CSV.
469
472
  function parseResult(data) {
470
473
  return __awaiter(this, void 0, void 0, function* () {
471
474
  if (data.status == 200) {
475
+ let type = data.headers.get("Content-Type");
476
+ if (type) {
477
+ type = type.trim().toLowerCase();
478
+ }
472
479
  let encoding = "";
473
- const type = data.headers.get("Content-Type");
474
- const charset = type ? type.split(";").find((x) => x.trim().toLowerCase().startsWith("charset=")) : "";
480
+ const charset = type ? type.split(";").find((x) => x.startsWith("charset=")) : "";
475
481
  if (charset && charset.includes("=")) {
476
482
  encoding = charset.split("=")[1];
477
483
  encoding = encoding.toLowerCase();
@@ -485,11 +491,18 @@ function parseResult(data) {
485
491
  if (!text || !text.trim()) {
486
492
  return null;
487
493
  }
494
+ if (type && type.includes("text/csv")) {
495
+ return text;
496
+ }
488
497
  return JSON.parse(text);
489
498
  }
490
499
  else {
491
500
  const buffer = yield data.arrayBuffer();
492
- return JSON.parse(new TextDecoder(encoding).decode(buffer));
501
+ const text = new TextDecoder(encoding).decode(buffer);
502
+ if (type && type.includes("text/csv")) {
503
+ return text;
504
+ }
505
+ return JSON.parse(text);
493
506
  }
494
507
  }
495
508
  else {