@niledatabase/server 3.0.0-alpha.22 → 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,107 +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 = 42;
1547
+ _context.next = 41;
1547
1548
  break;
1548
1549
  }
1549
1550
  if (!(typeof response.clone === 'function')) {
1550
- _context.next = 41;
1551
+ _context.next = 40;
1551
1552
  break;
1552
1553
  }
1553
1554
  _context.prev = 21;
1554
- _context.t0 = info;
1555
- _context.t1 = JSON;
1555
+ _context.t0 = debug;
1556
+ _context.t1 = "[fetch][response][" + ((_opts$method = opts == null ? void 0 : opts.method) != null ? _opts$method : 'GET') + "] " + response.status + " " + useableUrl;
1556
1557
  _context.next = 26;
1557
1558
  return response.clone().json();
1558
1559
  case 26:
1559
1560
  _context.t2 = _context.sent;
1560
- _context.t3 = _context.t1.stringify.call(_context.t1, _context.t2);
1561
- _context.t4 = "[fetch][response] " + _context.t3;
1562
- (0, _context.t0)(_context.t4);
1563
- _context.next = 41;
1561
+ _context.t3 = {
1562
+ body: _context.t2
1563
+ };
1564
+ (0, _context.t0)(_context.t1, _context.t3);
1565
+ _context.next = 40;
1564
1566
  break;
1565
- case 32:
1566
- _context.prev = 32;
1567
- _context.t5 = _context["catch"](21);
1568
- _context.t6 = info;
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;
1569
1572
  _context.next = 37;
1570
1573
  return response.clone().text();
1571
1574
  case 37:
1572
1575
  _context.t7 = _context.sent;
1573
- _context.t8 = "[fetch][response] " + _context.t7;
1574
- _context.t9 = {
1575
- e: _context.t5
1576
+ _context.t8 = {
1577
+ body: _context.t7
1576
1578
  };
1577
- (0, _context.t6)(_context.t8, _context.t9);
1578
- case 41:
1579
+ (0, _context.t5)(_context.t6, _context.t8);
1580
+ case 40:
1579
1581
  return _context.abrupt("return", response);
1580
- case 42:
1582
+ case 41:
1581
1583
  if (!((response == null ? void 0 : response.status) === 404)) {
1582
- _context.next = 44;
1584
+ _context.next = 43;
1583
1585
  break;
1584
1586
  }
1585
1587
  return _context.abrupt("return", new ResponseError('Not found', {
1586
1588
  status: 404
1587
1589
  }));
1588
- case 44:
1590
+ case 43:
1589
1591
  if (!((response == null ? void 0 : response.status) === 401)) {
1590
- _context.next = 46;
1592
+ _context.next = 45;
1591
1593
  break;
1592
1594
  }
1593
1595
  return _context.abrupt("return", new ResponseError('Unauthorized', {
1594
1596
  status: 401
1595
1597
  }));
1596
- case 46:
1598
+ case 45:
1597
1599
  if (!((response == null ? void 0 : response.status) === 405)) {
1598
- _context.next = 48;
1600
+ _context.next = 47;
1599
1601
  break;
1600
1602
  }
1601
1603
  return _context.abrupt("return", new ResponseError('Method not allowed', {
1602
1604
  status: 405
1603
1605
  }));
1604
- case 48:
1606
+ case 47:
1605
1607
  errorHandler = typeof (response == null ? void 0 : response.clone) === 'function' ? response.clone() : null;
1606
1608
  msg = '';
1607
- _context.prev = 50;
1608
- _context.next = 53;
1609
+ _context.prev = 49;
1610
+ _context.next = 52;
1609
1611
  return response == null ? void 0 : response.json();
1610
- case 53:
1612
+ case 52:
1611
1613
  res = _context.sent;
1612
- _context.next = 64;
1614
+ _context.next = 63;
1613
1615
  break;
1614
- case 56:
1615
- _context.prev = 56;
1616
- _context.t10 = _context["catch"](50);
1616
+ case 55:
1617
+ _context.prev = 55;
1618
+ _context.t9 = _context["catch"](49);
1617
1619
  if (!errorHandler) {
1618
- _context.next = 63;
1620
+ _context.next = 62;
1619
1621
  break;
1620
1622
  }
1621
- _context.next = 61;
1623
+ _context.next = 60;
1622
1624
  return errorHandler.text();
1623
- case 61:
1625
+ case 60:
1624
1626
  msg = _context.sent;
1625
1627
  if (msg) {
1626
1628
  error("[fetch][response] status: " + errorHandler.status + "]", {
1627
1629
  message: msg
1628
1630
  });
1629
1631
  }
1630
- case 63:
1632
+ case 62:
1631
1633
  if (!msg) {
1632
1634
  error('[fetch][response]', {
1633
- e: _context.t10
1635
+ e: _context.t9
1634
1636
  });
1635
1637
  }
1636
- case 64:
1638
+ case 63:
1637
1639
  if (!msg) {
1638
- _context.next = 66;
1640
+ _context.next = 65;
1639
1641
  break;
1640
1642
  }
1641
1643
  return _context.abrupt("return", new ResponseError(msg, {
1642
1644
  status: errorHandler == null ? void 0 : errorHandler.status
1643
1645
  }));
1644
- case 66:
1646
+ case 65:
1645
1647
  if (!(res && 'message' in res)) {
1646
- _context.next = 70;
1648
+ _context.next = 69;
1647
1649
  break;
1648
1650
  }
1649
1651
  _res = res, message = _res.message;
@@ -1651,9 +1653,9 @@ function _fetch2() {
1651
1653
  return _context.abrupt("return", new ResponseError(message, {
1652
1654
  status: 400
1653
1655
  }));
1654
- case 70:
1656
+ case 69:
1655
1657
  if (!(res && 'errors' in res)) {
1656
- _context.next = 74;
1658
+ _context.next = 73;
1657
1659
  break;
1658
1660
  }
1659
1661
  _res2 = res, _res2$errors = _res2.errors, _message = _res2$errors[0];
@@ -1661,18 +1663,18 @@ function _fetch2() {
1661
1663
  return _context.abrupt("return", new ResponseError(_message, {
1662
1664
  status: 400
1663
1665
  }));
1664
- case 74:
1666
+ case 73:
1665
1667
  error("[fetch][response] status: " + (errorHandler == null ? void 0 : errorHandler.status) + "] UNHANDLED ERROR", {
1666
1668
  res: res
1667
1669
  });
1668
1670
  return _context.abrupt("return", new ResponseError(null, {
1669
1671
  status: (_response$status = response == null ? void 0 : response.status) != null ? _response$status : 500
1670
1672
  }));
1671
- case 76:
1673
+ case 75:
1672
1674
  case "end":
1673
1675
  return _context.stop();
1674
1676
  }
1675
- }, _callee, null, [[21, 32], [50, 56]]);
1677
+ }, _callee, null, [[21, 31], [49, 55]]);
1676
1678
  }));
1677
1679
  return _fetch2.apply(this, arguments);
1678
1680
  }
@@ -4076,9 +4078,8 @@ var Server = /*#__PURE__*/function () {
4076
4078
  case 2:
4077
4079
  updatedConfig = _context.sent;
4078
4080
  this.setConfig(updatedConfig);
4079
- this.api = new Api(this.config);
4080
4081
  return _context.abrupt("return", this);
4081
- case 6:
4082
+ case 5:
4082
4083
  case "end":
4083
4084
  return _context.stop();
4084
4085
  }