@niledatabase/server 3.0.0-alpha.21 → 3.0.0-alpha.23

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.
@@ -1494,16 +1494,17 @@ function _fetch(_x, _x2, _x3) {
1494
1494
  function _fetch2() {
1495
1495
  _fetch2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, path, opts) {
1496
1496
  var _config$api, _config$api2, _response$status;
1497
- var _Logger, info, error, url, cookieKey, headers, basicHeaders, authHeader, token, tenantId, userId, useableUrl, response, res, errorHandler, msg, _res, message, _res2, _res2$errors, _message;
1497
+ var _Logger, debug, error, url, cookieKey, headers, basicHeaders, authHeader, token, tenantId, userId, useableUrl, response, _opts$method, _opts$method2, res, errorHandler, msg, _res, message, _res2, _res2$errors, _message;
1498
1498
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1499
1499
  while (1) switch (_context.prev = _context.next) {
1500
1500
  case 0:
1501
- _Logger = Logger(config, '[server]'), info = _Logger.info, error = _Logger.error;
1501
+ _Logger = Logger(config, '[server]'), debug = _Logger.debug, error = _Logger.error;
1502
1502
  url = "" + ((_config$api = config.api) == null ? void 0 : _config$api.basePath) + path;
1503
1503
  cookieKey = (_config$api2 = config.api) == null ? void 0 : _config$api2.cookieKey;
1504
1504
  headers = new Headers(opts == null ? void 0 : opts.headers);
1505
1505
  basicHeaders = new Headers(opts == null ? void 0 : opts.headers);
1506
1506
  basicHeaders.set('content-type', 'application/json; charset=utf-8');
1507
+ // this is old, but still maybe something worth keeping.
1507
1508
  authHeader = headers.get('Authorization');
1508
1509
  if (!authHeader) {
1509
1510
  token = getTokenFromCookie(headers, cookieKey);
@@ -1530,7 +1531,7 @@ function _fetch2() {
1530
1531
  }));
1531
1532
  case 14:
1532
1533
  useableUrl = url.replace('{tenantId}', encodeURIComponent(String(tenantId))).replace('{userId}', encodeURIComponent(String(userId)));
1533
- info("[fetch] " + useableUrl);
1534
+ debug("[fetch] " + useableUrl);
1534
1535
  _context.next = 18;
1535
1536
  return fetch(useableUrl, _extends({}, opts, {
1536
1537
  headers: basicHeaders
@@ -1543,105 +1544,108 @@ function _fetch2() {
1543
1544
  case 18:
1544
1545
  response = _context.sent;
1545
1546
  if (!(response && response.status >= 200 && response.status < 300)) {
1546
- _context.next = 40;
1547
+ _context.next = 41;
1547
1548
  break;
1548
1549
  }
1549
1550
  if (!(typeof response.clone === 'function')) {
1550
- _context.next = 39;
1551
+ _context.next = 40;
1551
1552
  break;
1552
1553
  }
1553
1554
  _context.prev = 21;
1554
- _context.t0 = info;
1555
- _context.next = 25;
1555
+ _context.t0 = debug;
1556
+ _context.t1 = "[fetch][response][" + ((_opts$method = opts == null ? void 0 : opts.method) != null ? _opts$method : 'GET') + "] " + response.status + " " + useableUrl;
1557
+ _context.next = 26;
1556
1558
  return response.clone().json();
1557
- case 25:
1558
- _context.t1 = _context.sent;
1559
- _context.t2 = "[fetch][response] " + _context.t1;
1560
- (0, _context.t0)(_context.t2);
1561
- _context.next = 39;
1559
+ case 26:
1560
+ _context.t2 = _context.sent;
1561
+ _context.t3 = {
1562
+ body: _context.t2
1563
+ };
1564
+ (0, _context.t0)(_context.t1, _context.t3);
1565
+ _context.next = 40;
1562
1566
  break;
1563
- case 30:
1564
- _context.prev = 30;
1565
- _context.t3 = _context["catch"](21);
1566
- _context.t4 = info;
1567
- _context.next = 35;
1567
+ case 31:
1568
+ _context.prev = 31;
1569
+ _context.t4 = _context["catch"](21);
1570
+ _context.t5 = debug;
1571
+ _context.t6 = "[fetch][response][" + ((_opts$method2 = opts == null ? void 0 : opts.method) != null ? _opts$method2 : 'GET') + "] " + response.status + " " + useableUrl;
1572
+ _context.next = 37;
1568
1573
  return response.clone().text();
1569
- case 35:
1570
- _context.t5 = _context.sent;
1571
- _context.t6 = "[fetch][response] " + _context.t5;
1572
- _context.t7 = {
1573
- e: _context.t3
1574
+ case 37:
1575
+ _context.t7 = _context.sent;
1576
+ _context.t8 = {
1577
+ body: _context.t7
1574
1578
  };
1575
- (0, _context.t4)(_context.t6, _context.t7);
1576
- case 39:
1577
- return _context.abrupt("return", response);
1579
+ (0, _context.t5)(_context.t6, _context.t8);
1578
1580
  case 40:
1581
+ return _context.abrupt("return", response);
1582
+ case 41:
1579
1583
  if (!((response == null ? void 0 : response.status) === 404)) {
1580
- _context.next = 42;
1584
+ _context.next = 43;
1581
1585
  break;
1582
1586
  }
1583
1587
  return _context.abrupt("return", new ResponseError('Not found', {
1584
1588
  status: 404
1585
1589
  }));
1586
- case 42:
1590
+ case 43:
1587
1591
  if (!((response == null ? void 0 : response.status) === 401)) {
1588
- _context.next = 44;
1592
+ _context.next = 45;
1589
1593
  break;
1590
1594
  }
1591
1595
  return _context.abrupt("return", new ResponseError('Unauthorized', {
1592
1596
  status: 401
1593
1597
  }));
1594
- case 44:
1598
+ case 45:
1595
1599
  if (!((response == null ? void 0 : response.status) === 405)) {
1596
- _context.next = 46;
1600
+ _context.next = 47;
1597
1601
  break;
1598
1602
  }
1599
1603
  return _context.abrupt("return", new ResponseError('Method not allowed', {
1600
1604
  status: 405
1601
1605
  }));
1602
- case 46:
1606
+ case 47:
1603
1607
  errorHandler = typeof (response == null ? void 0 : response.clone) === 'function' ? response.clone() : null;
1604
1608
  msg = '';
1605
- _context.prev = 48;
1606
- _context.next = 51;
1609
+ _context.prev = 49;
1610
+ _context.next = 52;
1607
1611
  return response == null ? void 0 : response.json();
1608
- case 51:
1612
+ case 52:
1609
1613
  res = _context.sent;
1610
- _context.next = 62;
1614
+ _context.next = 63;
1611
1615
  break;
1612
- case 54:
1613
- _context.prev = 54;
1614
- _context.t8 = _context["catch"](48);
1616
+ case 55:
1617
+ _context.prev = 55;
1618
+ _context.t9 = _context["catch"](49);
1615
1619
  if (!errorHandler) {
1616
- _context.next = 61;
1620
+ _context.next = 62;
1617
1621
  break;
1618
1622
  }
1619
- _context.next = 59;
1623
+ _context.next = 60;
1620
1624
  return errorHandler.text();
1621
- case 59:
1625
+ case 60:
1622
1626
  msg = _context.sent;
1623
1627
  if (msg) {
1624
1628
  error("[fetch][response] status: " + errorHandler.status + "]", {
1625
1629
  message: msg
1626
1630
  });
1627
1631
  }
1628
- case 61:
1632
+ case 62:
1629
1633
  if (!msg) {
1630
1634
  error('[fetch][response]', {
1631
- e: _context.t8
1635
+ e: _context.t9
1632
1636
  });
1633
1637
  }
1634
- case 62:
1638
+ case 63:
1635
1639
  if (!msg) {
1636
- _context.next = 64;
1640
+ _context.next = 65;
1637
1641
  break;
1638
1642
  }
1639
1643
  return _context.abrupt("return", new ResponseError(msg, {
1640
1644
  status: errorHandler == null ? void 0 : errorHandler.status
1641
1645
  }));
1642
- case 64:
1646
+ case 65:
1643
1647
  if (!(res && 'message' in res)) {
1644
- _context.next = 68;
1648
+ _context.next = 69;
1645
1649
  break;
1646
1650
  }
1647
1651
  _res = res, message = _res.message;
@@ -1649,9 +1653,9 @@ function _fetch2() {
1649
1653
  return _context.abrupt("return", new ResponseError(message, {
1650
1654
  status: 400
1651
1655
  }));
1652
- case 68:
1656
+ case 69:
1653
1657
  if (!(res && 'errors' in res)) {
1654
- _context.next = 72;
1658
+ _context.next = 73;
1655
1659
  break;
1656
1660
  }
1657
1661
  _res2 = res, _res2$errors = _res2.errors, _message = _res2$errors[0];
@@ -1659,18 +1663,18 @@ function _fetch2() {
1659
1663
  return _context.abrupt("return", new ResponseError(_message, {
1660
1664
  status: 400
1661
1665
  }));
1662
- case 72:
1666
+ case 73:
1663
1667
  error("[fetch][response] status: " + (errorHandler == null ? void 0 : errorHandler.status) + "] UNHANDLED ERROR", {
1664
1668
  res: res
1665
1669
  });
1666
1670
  return _context.abrupt("return", new ResponseError(null, {
1667
1671
  status: (_response$status = response == null ? void 0 : response.status) != null ? _response$status : 500
1668
1672
  }));
1669
- case 74:
1673
+ case 75:
1670
1674
  case "end":
1671
1675
  return _context.stop();
1672
1676
  }
1673
- }, _callee, null, [[21, 30], [48, 54]]);
1677
+ }, _callee, null, [[21, 31], [49, 55]]);
1674
1678
  }));
1675
1679
  return _fetch2.apply(this, arguments);
1676
1680
  }
@@ -4074,9 +4078,8 @@ var Server = /*#__PURE__*/function () {
4074
4078
  case 2:
4075
4079
  updatedConfig = _context.sent;
4076
4080
  this.setConfig(updatedConfig);
4077
- this.api = new Api(this.config);
4078
4081
  return _context.abrupt("return", this);
4079
- case 6:
4082
+ case 5:
4080
4083
  case "end":
4081
4084
  return _context.stop();
4082
4085
  }