@niledatabase/server 3.0.0-alpha.12 → 3.0.0-alpha.14
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/api/utils/request.d.ts +1 -1
- package/dist/server.cjs.development.js +130 -123
- package/dist/server.cjs.development.js.map +1 -1
- package/dist/server.cjs.production.min.js +1 -1
- package/dist/server.cjs.production.min.js.map +1 -1
- package/dist/server.esm.js +130 -123
- package/dist/server.esm.js.map +1 -1
- package/dist/utils/Config/envVars.d.ts +0 -1
- package/dist/utils/Config/index.d.ts +1 -5
- package/package.json +2 -2
|
@@ -565,18 +565,6 @@ var getTenantId = function getTenantId(cfg) {
|
|
|
565
565
|
}
|
|
566
566
|
return null;
|
|
567
567
|
};
|
|
568
|
-
var getLocal = function getLocal(cfg) {
|
|
569
|
-
var config = cfg.config,
|
|
570
|
-
logger = cfg.logger;
|
|
571
|
-
if (process.env.NILEDB_LOCAL) {
|
|
572
|
-
var _Logger7 = Logger(config, '[local]'),
|
|
573
|
-
info = _Logger7.info;
|
|
574
|
-
logger && info(logger, 'NILEDB_LOCAL', process.env.NILEDB_LOCAL);
|
|
575
|
-
var apiUrl = new URL(process.env.NILEDB_LOCAL);
|
|
576
|
-
return apiUrl.href;
|
|
577
|
-
}
|
|
578
|
-
return 'http://localhost:3000';
|
|
579
|
-
};
|
|
580
568
|
/**
|
|
581
569
|
* @param cfg various overrides
|
|
582
570
|
* @returns the url for REST to use
|
|
@@ -585,8 +573,8 @@ var getBasePath = function getBasePath(cfg) {
|
|
|
585
573
|
var _config$api4;
|
|
586
574
|
var config = cfg.config,
|
|
587
575
|
logger = cfg.logger;
|
|
588
|
-
var
|
|
589
|
-
info =
|
|
576
|
+
var _Logger7 = Logger(config, '[basePath]'),
|
|
577
|
+
info = _Logger7.info;
|
|
590
578
|
var basePath = config == null || (_config$api4 = config.api) == null ? void 0 : _config$api4.basePath;
|
|
591
579
|
var version = '';
|
|
592
580
|
if (!/\/v\d\//.test(String(basePath))) {
|
|
@@ -608,8 +596,8 @@ var getBasePath = function getBasePath(cfg) {
|
|
|
608
596
|
var getControlPlane = function getControlPlane(cfg) {
|
|
609
597
|
var config = cfg.config,
|
|
610
598
|
logger = cfg.logger;
|
|
611
|
-
var
|
|
612
|
-
info =
|
|
599
|
+
var _Logger8 = Logger(config, '[basePath]'),
|
|
600
|
+
info = _Logger8.info;
|
|
613
601
|
if (config != null && config.configureUrl) {
|
|
614
602
|
logger && info(logger, 'config', config.configureUrl);
|
|
615
603
|
return config.configureUrl;
|
|
@@ -628,8 +616,8 @@ var getControlPlane = function getControlPlane(cfg) {
|
|
|
628
616
|
function getDbHost(cfg) {
|
|
629
617
|
var config = cfg.config,
|
|
630
618
|
logger = cfg.logger;
|
|
631
|
-
var
|
|
632
|
-
info =
|
|
619
|
+
var _Logger9 = Logger(config, '[db.host]'),
|
|
620
|
+
info = _Logger9.info;
|
|
633
621
|
if (config != null && config.db && config.db.host) {
|
|
634
622
|
logger && info(logger, 'config', config == null ? void 0 : config.db.host);
|
|
635
623
|
return config.db.host;
|
|
@@ -650,8 +638,8 @@ function getDbPort(cfg) {
|
|
|
650
638
|
var _config$db;
|
|
651
639
|
var config = cfg.config,
|
|
652
640
|
logger = cfg.logger;
|
|
653
|
-
var
|
|
654
|
-
info =
|
|
641
|
+
var _Logger10 = Logger(config, '[db.port]'),
|
|
642
|
+
info = _Logger10.info;
|
|
655
643
|
if (config != null && (_config$db = config.db) != null && _config$db.port && config.db.port != null) {
|
|
656
644
|
var _config$db2;
|
|
657
645
|
logger && info(logger, 'config', config == null ? void 0 : config.db.port);
|
|
@@ -675,19 +663,13 @@ var ApiConfig = /*#__PURE__*/function () {
|
|
|
675
663
|
function ApiConfig(_ref) {
|
|
676
664
|
var basePath = _ref.basePath,
|
|
677
665
|
cookieKey = _ref.cookieKey,
|
|
678
|
-
token = _ref.token
|
|
679
|
-
version = _ref.version,
|
|
680
|
-
localPath = _ref.localPath;
|
|
666
|
+
token = _ref.token;
|
|
681
667
|
this.cookieKey = void 0;
|
|
682
668
|
this.basePath = void 0;
|
|
683
|
-
this.version = void 0;
|
|
684
|
-
this.localPath = void 0;
|
|
685
669
|
this._token = void 0;
|
|
686
670
|
this.basePath = basePath;
|
|
687
671
|
this.cookieKey = cookieKey;
|
|
688
|
-
this.version = version;
|
|
689
672
|
this._token = token;
|
|
690
|
-
this.localPath = localPath != null ? localPath : 'http://localhost:3000';
|
|
691
673
|
}
|
|
692
674
|
return _createClass(ApiConfig, [{
|
|
693
675
|
key: "token",
|
|
@@ -704,9 +686,7 @@ var Config = /*#__PURE__*/function () {
|
|
|
704
686
|
var _this = this,
|
|
705
687
|
_config$db2,
|
|
706
688
|
_config$api$cookieKey2,
|
|
707
|
-
_config$
|
|
708
|
-
_config$api$version2,
|
|
709
|
-
_config$api4;
|
|
689
|
+
_config$api2;
|
|
710
690
|
this.user = void 0;
|
|
711
691
|
this.password = void 0;
|
|
712
692
|
this.databaseId = void 0;
|
|
@@ -720,7 +700,7 @@ var Config = /*#__PURE__*/function () {
|
|
|
720
700
|
this._userId = void 0;
|
|
721
701
|
this.configure = /*#__PURE__*/function () {
|
|
722
702
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
|
|
723
|
-
var _config$db, _config$api$cookieKey, _config$api
|
|
703
|
+
var _config$db, _config$api$cookieKey, _config$api;
|
|
724
704
|
var _Logger, info, error, envVarConfig, _ref3, host, port, dbConfig, configuredHost, configuredPort, basePath, cp, databaseName, url, res, database, possibleError, json, message, _database, apiHost, dbHost, name, id, dburl;
|
|
725
705
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
726
706
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -818,9 +798,7 @@ var Config = /*#__PURE__*/function () {
|
|
|
818
798
|
cookieKey: (_config$api$cookieKey = config == null || (_config$api = config.api) == null ? void 0 : _config$api.cookieKey) != null ? _config$api$cookieKey : 'token',
|
|
819
799
|
token: getToken({
|
|
820
800
|
config: config
|
|
821
|
-
})
|
|
822
|
-
version: (_config$api$version = config == null || (_config$api2 = config.api) == null ? void 0 : _config$api2.version) != null ? _config$api$version : 2,
|
|
823
|
-
localPath: getLocal(envVarConfig)
|
|
801
|
+
})
|
|
824
802
|
});
|
|
825
803
|
_this.db = _extends({
|
|
826
804
|
user: _this.user,
|
|
@@ -869,12 +847,10 @@ var Config = /*#__PURE__*/function () {
|
|
|
869
847
|
var _configuredPort = _port != null ? _port : getDbPort(_envVarConfig);
|
|
870
848
|
this.api = new ApiConfig({
|
|
871
849
|
basePath: _basePath,
|
|
872
|
-
cookieKey: (_config$api$cookieKey2 = _config == null || (_config$
|
|
850
|
+
cookieKey: (_config$api$cookieKey2 = _config == null || (_config$api2 = _config.api) == null ? void 0 : _config$api2.cookieKey) != null ? _config$api$cookieKey2 : 'token',
|
|
873
851
|
token: getToken({
|
|
874
852
|
config: _config
|
|
875
|
-
})
|
|
876
|
-
version: (_config$api$version2 = _config == null || (_config$api4 = _config.api) == null ? void 0 : _config$api4.version) != null ? _config$api$version2 : 2,
|
|
877
|
-
localPath: getLocal(_envVarConfig)
|
|
853
|
+
})
|
|
878
854
|
});
|
|
879
855
|
this.db = _extends({
|
|
880
856
|
user: this.user,
|
|
@@ -1283,9 +1259,7 @@ function _request() {
|
|
|
1283
1259
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1284
1260
|
while (1) switch (_context.prev = _context.next) {
|
|
1285
1261
|
case 0:
|
|
1286
|
-
_Logger = Logger(
|
|
1287
|
-
debug: config == null ? void 0 : config.debug
|
|
1288
|
-
}), '[REQUEST]', "[" + url + "]"), info = _Logger.info, error = _Logger.error;
|
|
1262
|
+
_Logger = Logger(config, '[REQUEST]'), info = _Logger.info, error = _Logger.error;
|
|
1289
1263
|
request = _init.request, init = _objectWithoutPropertiesLoose(_init, _excluded);
|
|
1290
1264
|
requestUrl = new URL(request.url);
|
|
1291
1265
|
updatedHeaders = new Headers(request.headers);
|
|
@@ -1358,18 +1332,18 @@ var key$7 = 'ME';
|
|
|
1358
1332
|
* description: Unauthorized
|
|
1359
1333
|
* content: {}
|
|
1360
1334
|
*/
|
|
1361
|
-
function GET$3(_x, _x2, _x3) {
|
|
1335
|
+
function GET$3(_x, _x2, _x3, _x4) {
|
|
1362
1336
|
return _GET$3.apply(this, arguments);
|
|
1363
1337
|
}
|
|
1364
1338
|
function _GET$3() {
|
|
1365
|
-
_GET$3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url, init, log) {
|
|
1339
|
+
_GET$3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url, init, log, config) {
|
|
1366
1340
|
var res;
|
|
1367
1341
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1368
1342
|
while (1) switch (_context.prev = _context.next) {
|
|
1369
1343
|
case 0:
|
|
1370
1344
|
log('[GET]', url);
|
|
1371
1345
|
_context.next = 3;
|
|
1372
|
-
return request(url, init);
|
|
1346
|
+
return request(url, init, config);
|
|
1373
1347
|
case 3:
|
|
1374
1348
|
res = _context.sent;
|
|
1375
1349
|
return _context.abrupt("return", res);
|
|
@@ -1381,7 +1355,7 @@ function _GET$3() {
|
|
|
1381
1355
|
}));
|
|
1382
1356
|
return _GET$3.apply(this, arguments);
|
|
1383
1357
|
}
|
|
1384
|
-
function route$a(
|
|
1358
|
+
function route$a(_x5, _x6) {
|
|
1385
1359
|
return _route$a.apply(this, arguments);
|
|
1386
1360
|
}
|
|
1387
1361
|
function _route$a() {
|
|
@@ -1401,7 +1375,7 @@ function _route$a() {
|
|
|
1401
1375
|
_context2.next = 7;
|
|
1402
1376
|
return GET$3(url, {
|
|
1403
1377
|
request: request
|
|
1404
|
-
}, info);
|
|
1378
|
+
}, info, config);
|
|
1405
1379
|
case 7:
|
|
1406
1380
|
return _context2.abrupt("return", _context2.sent);
|
|
1407
1381
|
case 8:
|
|
@@ -1440,7 +1414,7 @@ function _auth() {
|
|
|
1440
1414
|
_context.next = 7;
|
|
1441
1415
|
return request(sessionUrl, {
|
|
1442
1416
|
request: req
|
|
1443
|
-
});
|
|
1417
|
+
}, config);
|
|
1444
1418
|
case 7:
|
|
1445
1419
|
res = _context.sent;
|
|
1446
1420
|
if (res) {
|
|
@@ -1594,60 +1568,68 @@ function _fetch2() {
|
|
|
1594
1568
|
case 38:
|
|
1595
1569
|
return _context.abrupt("return", response);
|
|
1596
1570
|
case 39:
|
|
1597
|
-
if (!((response == null ? void 0 : response.status) ===
|
|
1571
|
+
if (!((response == null ? void 0 : response.status) === 404)) {
|
|
1598
1572
|
_context.next = 41;
|
|
1599
1573
|
break;
|
|
1600
1574
|
}
|
|
1575
|
+
return _context.abrupt("return", new ResponseError('Not found', {
|
|
1576
|
+
status: 404
|
|
1577
|
+
}));
|
|
1578
|
+
case 41:
|
|
1579
|
+
if (!((response == null ? void 0 : response.status) === 401)) {
|
|
1580
|
+
_context.next = 43;
|
|
1581
|
+
break;
|
|
1582
|
+
}
|
|
1601
1583
|
return _context.abrupt("return", new ResponseError('Unauthorized', {
|
|
1602
1584
|
status: 401
|
|
1603
1585
|
}));
|
|
1604
|
-
case
|
|
1586
|
+
case 43:
|
|
1605
1587
|
if (!((response == null ? void 0 : response.status) === 405)) {
|
|
1606
|
-
_context.next =
|
|
1588
|
+
_context.next = 45;
|
|
1607
1589
|
break;
|
|
1608
1590
|
}
|
|
1609
1591
|
return _context.abrupt("return", new ResponseError('Method not allowed', {
|
|
1610
1592
|
status: 405
|
|
1611
1593
|
}));
|
|
1612
|
-
case
|
|
1594
|
+
case 45:
|
|
1613
1595
|
errorHandler = typeof (response == null ? void 0 : response.clone) === 'function' ? response.clone() : null;
|
|
1614
1596
|
msg = '';
|
|
1615
|
-
_context.prev =
|
|
1616
|
-
_context.next =
|
|
1597
|
+
_context.prev = 47;
|
|
1598
|
+
_context.next = 50;
|
|
1617
1599
|
return response == null ? void 0 : response.json();
|
|
1618
|
-
case
|
|
1600
|
+
case 50:
|
|
1619
1601
|
res = _context.sent;
|
|
1620
|
-
_context.next =
|
|
1602
|
+
_context.next = 61;
|
|
1621
1603
|
break;
|
|
1622
|
-
case
|
|
1623
|
-
_context.prev =
|
|
1624
|
-
_context.t5 = _context["catch"](
|
|
1604
|
+
case 53:
|
|
1605
|
+
_context.prev = 53;
|
|
1606
|
+
_context.t5 = _context["catch"](47);
|
|
1625
1607
|
if (!errorHandler) {
|
|
1626
|
-
_context.next =
|
|
1608
|
+
_context.next = 60;
|
|
1627
1609
|
break;
|
|
1628
1610
|
}
|
|
1629
|
-
_context.next =
|
|
1611
|
+
_context.next = 58;
|
|
1630
1612
|
return errorHandler.text();
|
|
1631
|
-
case
|
|
1613
|
+
case 58:
|
|
1632
1614
|
msg = _context.sent;
|
|
1633
1615
|
if (msg) {
|
|
1634
1616
|
error('[fetch]', '[response]', "[status: " + errorHandler.status + "]", msg);
|
|
1635
1617
|
}
|
|
1636
|
-
case
|
|
1618
|
+
case 60:
|
|
1637
1619
|
if (!msg) {
|
|
1638
1620
|
error('[fetch]', '[response]', _context.t5);
|
|
1639
1621
|
}
|
|
1640
|
-
case
|
|
1622
|
+
case 61:
|
|
1641
1623
|
if (!msg) {
|
|
1642
|
-
_context.next =
|
|
1624
|
+
_context.next = 63;
|
|
1643
1625
|
break;
|
|
1644
1626
|
}
|
|
1645
1627
|
return _context.abrupt("return", new ResponseError(msg, {
|
|
1646
1628
|
status: errorHandler == null ? void 0 : errorHandler.status
|
|
1647
1629
|
}));
|
|
1648
|
-
case
|
|
1630
|
+
case 63:
|
|
1649
1631
|
if (!(res && 'message' in res)) {
|
|
1650
|
-
_context.next =
|
|
1632
|
+
_context.next = 67;
|
|
1651
1633
|
break;
|
|
1652
1634
|
}
|
|
1653
1635
|
_res = res, message = _res.message;
|
|
@@ -1655,9 +1637,9 @@ function _fetch2() {
|
|
|
1655
1637
|
return _context.abrupt("return", new ResponseError(message, {
|
|
1656
1638
|
status: 400
|
|
1657
1639
|
}));
|
|
1658
|
-
case
|
|
1640
|
+
case 67:
|
|
1659
1641
|
if (!(res && 'errors' in res)) {
|
|
1660
|
-
_context.next =
|
|
1642
|
+
_context.next = 71;
|
|
1661
1643
|
break;
|
|
1662
1644
|
}
|
|
1663
1645
|
_res2 = res, _res2$errors = _res2.errors, _message = _res2$errors[0];
|
|
@@ -1665,16 +1647,16 @@ function _fetch2() {
|
|
|
1665
1647
|
return _context.abrupt("return", new ResponseError(_message, {
|
|
1666
1648
|
status: 400
|
|
1667
1649
|
}));
|
|
1668
|
-
case
|
|
1650
|
+
case 71:
|
|
1669
1651
|
error('[fetch]', '[response]', "[status: " + (errorHandler == null ? void 0 : errorHandler.status) + "]", 'UNHANDLED ERROR');
|
|
1670
1652
|
return _context.abrupt("return", new ResponseError(null, {
|
|
1671
1653
|
status: (_response$status = response == null ? void 0 : response.status) != null ? _response$status : 500
|
|
1672
1654
|
}));
|
|
1673
|
-
case
|
|
1655
|
+
case 73:
|
|
1674
1656
|
case "end":
|
|
1675
1657
|
return _context.stop();
|
|
1676
1658
|
}
|
|
1677
|
-
}, _callee, null, [[23, 31], [
|
|
1659
|
+
}, _callee, null, [[23, 31], [47, 53]]);
|
|
1678
1660
|
}));
|
|
1679
1661
|
return _fetch2.apply(this, arguments);
|
|
1680
1662
|
}
|
|
@@ -1766,7 +1748,7 @@ function _POST$2() {
|
|
|
1766
1748
|
url = apiRoutes(config).USERS(tenant ? tenant : undefined);
|
|
1767
1749
|
log && log('[POST]', url);
|
|
1768
1750
|
_context.next = 11;
|
|
1769
|
-
return request(url, init);
|
|
1751
|
+
return request(url, init, config);
|
|
1770
1752
|
case 11:
|
|
1771
1753
|
return _context.abrupt("return", _context.sent);
|
|
1772
1754
|
case 12:
|
|
@@ -1834,7 +1816,7 @@ function _GET$2() {
|
|
|
1834
1816
|
log('[GET]', url);
|
|
1835
1817
|
init.method = 'GET';
|
|
1836
1818
|
_context.next = 11;
|
|
1837
|
-
return request(url, init);
|
|
1819
|
+
return request(url, init, config);
|
|
1838
1820
|
case 11:
|
|
1839
1821
|
return _context.abrupt("return", _context.sent);
|
|
1840
1822
|
case 12:
|
|
@@ -1906,7 +1888,7 @@ function _PUT$1() {
|
|
|
1906
1888
|
url = apiRoutes(config).USER(userId);
|
|
1907
1889
|
log('[PUT]', url);
|
|
1908
1890
|
_context.next = 9;
|
|
1909
|
-
return request(url, init);
|
|
1891
|
+
return request(url, init, config);
|
|
1910
1892
|
case 9:
|
|
1911
1893
|
return _context.abrupt("return", _context.sent);
|
|
1912
1894
|
case 10:
|
|
@@ -2028,7 +2010,7 @@ function _GET$1() {
|
|
|
2028
2010
|
url = "" + apiRoutes(config).TENANT_USERS(tenantId);
|
|
2029
2011
|
log('[GET]', '[TENANT_USERS]', url);
|
|
2030
2012
|
_context.next = 8;
|
|
2031
|
-
return request(url, init);
|
|
2013
|
+
return request(url, init, config);
|
|
2032
2014
|
case 8:
|
|
2033
2015
|
return _context.abrupt("return", _context.sent);
|
|
2034
2016
|
case 9:
|
|
@@ -2099,7 +2081,7 @@ function _POST$1() {
|
|
|
2099
2081
|
url = apiRoutes(config).TENANT_USERS(tenantId);
|
|
2100
2082
|
log('[PUT]', url);
|
|
2101
2083
|
_context.next = 8;
|
|
2102
|
-
return request(url, init);
|
|
2084
|
+
return request(url, init, config);
|
|
2103
2085
|
case 8:
|
|
2104
2086
|
return _context.abrupt("return", _context.sent);
|
|
2105
2087
|
case 9:
|
|
@@ -2163,7 +2145,7 @@ function _DELETE$1() {
|
|
|
2163
2145
|
url = "" + apiRoutes(config).TENANT_USER(tenantId, userId);
|
|
2164
2146
|
log('[DELETE]', url);
|
|
2165
2147
|
_context.next = 10;
|
|
2166
|
-
return request(url, init);
|
|
2148
|
+
return request(url, init, config);
|
|
2167
2149
|
case 10:
|
|
2168
2150
|
return _context.abrupt("return", _context.sent);
|
|
2169
2151
|
case 11:
|
|
@@ -2223,7 +2205,7 @@ function _PUT() {
|
|
|
2223
2205
|
url = "" + apiRoutes(config).TENANT_USERS(tenantId);
|
|
2224
2206
|
log('[PUT]', url);
|
|
2225
2207
|
_context.next = 9;
|
|
2226
|
-
return request(url, init);
|
|
2208
|
+
return request(url, init, config);
|
|
2227
2209
|
case 9:
|
|
2228
2210
|
return _context.abrupt("return", _context.sent);
|
|
2229
2211
|
case 10:
|
|
@@ -2360,7 +2342,7 @@ function _GET() {
|
|
|
2360
2342
|
}
|
|
2361
2343
|
log('[GET]', url);
|
|
2362
2344
|
_context.next = 5;
|
|
2363
|
-
return request(url, init);
|
|
2345
|
+
return request(url, init, config);
|
|
2364
2346
|
case 5:
|
|
2365
2347
|
res = _context.sent;
|
|
2366
2348
|
return _context.abrupt("return", res);
|
|
@@ -2426,7 +2408,7 @@ function _DELETE() {
|
|
|
2426
2408
|
url = "" + apiRoutes(config).TENANT(tenantId);
|
|
2427
2409
|
log('[DELETE]', url);
|
|
2428
2410
|
_context.next = 9;
|
|
2429
|
-
return request(url, init);
|
|
2411
|
+
return request(url, init, config);
|
|
2430
2412
|
case 9:
|
|
2431
2413
|
return _context.abrupt("return", _context.sent);
|
|
2432
2414
|
case 10:
|
|
@@ -2493,7 +2475,7 @@ function _POST() {
|
|
|
2493
2475
|
url = "" + apiRoutes(config).TENANTS;
|
|
2494
2476
|
log('[POST]', url);
|
|
2495
2477
|
_context.next = 6;
|
|
2496
|
-
return request(url, init);
|
|
2478
|
+
return request(url, init, config);
|
|
2497
2479
|
case 6:
|
|
2498
2480
|
return _context.abrupt("return", _context.sent);
|
|
2499
2481
|
case 7:
|
|
@@ -2611,7 +2593,7 @@ function _route$6() {
|
|
|
2611
2593
|
_context.next = 8;
|
|
2612
2594
|
return request(url, _extends({}, init, {
|
|
2613
2595
|
request: req
|
|
2614
|
-
}));
|
|
2596
|
+
}), config);
|
|
2615
2597
|
case 8:
|
|
2616
2598
|
res = _context.sent;
|
|
2617
2599
|
return _context.abrupt("return", res);
|
|
@@ -2662,7 +2644,7 @@ function _route$4() {
|
|
|
2662
2644
|
return _context.abrupt("return", request(proxyRoutes(config).PROVIDERS, {
|
|
2663
2645
|
method: req.method,
|
|
2664
2646
|
request: req
|
|
2665
|
-
}));
|
|
2647
|
+
}, config));
|
|
2666
2648
|
case 1:
|
|
2667
2649
|
case "end":
|
|
2668
2650
|
return _context.stop();
|
|
@@ -2686,7 +2668,7 @@ function _route$3() {
|
|
|
2686
2668
|
return _context.abrupt("return", request(proxyRoutes(config).CSRF, {
|
|
2687
2669
|
method: req.method,
|
|
2688
2670
|
request: req
|
|
2689
|
-
}));
|
|
2671
|
+
}, config));
|
|
2690
2672
|
case 1:
|
|
2691
2673
|
case "end":
|
|
2692
2674
|
return _context.stop();
|
|
@@ -2720,7 +2702,7 @@ function _route$2() {
|
|
|
2720
2702
|
return request(url, {
|
|
2721
2703
|
request: request$1,
|
|
2722
2704
|
method: request$1.method
|
|
2723
|
-
})["catch"](function (e) {
|
|
2705
|
+
}, config)["catch"](function (e) {
|
|
2724
2706
|
error('an error as occurred', e);
|
|
2725
2707
|
});
|
|
2726
2708
|
case 7:
|
|
@@ -2773,7 +2755,7 @@ function _route$1() {
|
|
|
2773
2755
|
_context.next = 5;
|
|
2774
2756
|
return request(url, _extends({}, init, {
|
|
2775
2757
|
request: request$1
|
|
2776
|
-
}));
|
|
2758
|
+
}), config);
|
|
2777
2759
|
case 5:
|
|
2778
2760
|
res = _context.sent;
|
|
2779
2761
|
return _context.abrupt("return", res);
|
|
@@ -2801,7 +2783,7 @@ function _route() {
|
|
|
2801
2783
|
return _context.abrupt("return", request(proxyRoutes(config)[key], {
|
|
2802
2784
|
method: req.method,
|
|
2803
2785
|
request: req
|
|
2804
|
-
}));
|
|
2786
|
+
}, config));
|
|
2805
2787
|
case 1:
|
|
2806
2788
|
case "end":
|
|
2807
2789
|
return _context.stop();
|
|
@@ -3091,75 +3073,100 @@ var appRoutes = function appRoutes(prefix) {
|
|
|
3091
3073
|
*/
|
|
3092
3074
|
function serverAuth(config, handlers) {
|
|
3093
3075
|
var _Logger = Logger(config, '[server side login]'),
|
|
3094
|
-
info = _Logger.info
|
|
3076
|
+
info = _Logger.info,
|
|
3077
|
+
error = _Logger.error;
|
|
3095
3078
|
return /*#__PURE__*/function () {
|
|
3096
3079
|
var _login = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
3097
|
-
var
|
|
3098
|
-
var email, password, sessionUrl, sessionReq, sessionRes, providers, csrf, csrfReq, csrfRes,
|
|
3080
|
+
var _providers, _exec;
|
|
3081
|
+
var email, password, sessionUrl, sessionReq, sessionRes, providers, csrf, csrfReq, csrfRes, csrfToken, _yield$csrfRes$json, json, _ref2, credentials, csrfCookie, signInUrl, postReq, loginRes, authCookie, _ref3, token;
|
|
3099
3082
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
3100
3083
|
while (1) switch (_context.prev = _context.next) {
|
|
3101
3084
|
case 0:
|
|
3102
3085
|
email = _ref.email, password = _ref.password;
|
|
3103
|
-
|
|
3104
|
-
|
|
3086
|
+
if (!(!email || !password)) {
|
|
3087
|
+
_context.next = 3;
|
|
3088
|
+
break;
|
|
3089
|
+
}
|
|
3090
|
+
throw new Error('Server side login requires a user email and password.');
|
|
3091
|
+
case 3:
|
|
3092
|
+
info('Obtaining providers for', email);
|
|
3093
|
+
sessionUrl = new URL(config.api.basePath + "/api/auth/providers");
|
|
3105
3094
|
sessionReq = new Request(sessionUrl, {
|
|
3106
3095
|
method: 'GET',
|
|
3107
3096
|
headers: new Headers({
|
|
3108
3097
|
host: sessionUrl.host
|
|
3109
3098
|
})
|
|
3110
3099
|
});
|
|
3111
|
-
_context.next =
|
|
3100
|
+
_context.next = 8;
|
|
3112
3101
|
return handlers.POST(sessionReq);
|
|
3113
|
-
case
|
|
3102
|
+
case 8:
|
|
3114
3103
|
sessionRes = _context.sent;
|
|
3115
|
-
_context.
|
|
3104
|
+
_context.prev = 9;
|
|
3105
|
+
_context.next = 12;
|
|
3116
3106
|
return sessionRes == null ? void 0 : sessionRes.json();
|
|
3117
|
-
case
|
|
3107
|
+
case 12:
|
|
3118
3108
|
providers = _context.sent;
|
|
3109
|
+
_context.next = 19;
|
|
3110
|
+
break;
|
|
3111
|
+
case 15:
|
|
3112
|
+
_context.prev = 15;
|
|
3113
|
+
_context.t0 = _context["catch"](9);
|
|
3114
|
+
info(sessionUrl, sessionRes);
|
|
3115
|
+
error(_context.t0);
|
|
3116
|
+
case 19:
|
|
3119
3117
|
info('Obtaining csrf');
|
|
3120
|
-
csrf = new URL(config.api.
|
|
3118
|
+
csrf = new URL(config.api.basePath + "/api/auth/csrf");
|
|
3121
3119
|
csrfReq = new Request(csrf, {
|
|
3122
3120
|
method: 'GET',
|
|
3123
3121
|
headers: new Headers({
|
|
3124
3122
|
host: sessionUrl.host
|
|
3125
3123
|
})
|
|
3126
3124
|
});
|
|
3127
|
-
_context.next =
|
|
3125
|
+
_context.next = 24;
|
|
3128
3126
|
return handlers.POST(csrfReq);
|
|
3129
|
-
case
|
|
3127
|
+
case 24:
|
|
3130
3128
|
csrfRes = _context.sent;
|
|
3131
|
-
_context.
|
|
3129
|
+
_context.prev = 25;
|
|
3130
|
+
_context.next = 28;
|
|
3132
3131
|
return csrfRes == null ? void 0 : csrfRes.json();
|
|
3133
|
-
case
|
|
3134
|
-
_context.
|
|
3135
|
-
if (!(_context.
|
|
3136
|
-
_context.next =
|
|
3132
|
+
case 28:
|
|
3133
|
+
_context.t1 = _yield$csrfRes$json = _context.sent;
|
|
3134
|
+
if (!(_context.t1 != null)) {
|
|
3135
|
+
_context.next = 33;
|
|
3137
3136
|
break;
|
|
3138
3137
|
}
|
|
3139
|
-
_context.
|
|
3140
|
-
_context.next =
|
|
3138
|
+
_context.t2 = _yield$csrfRes$json;
|
|
3139
|
+
_context.next = 34;
|
|
3141
3140
|
break;
|
|
3142
|
-
case
|
|
3143
|
-
_context.
|
|
3144
|
-
case
|
|
3145
|
-
|
|
3146
|
-
csrfToken =
|
|
3147
|
-
|
|
3141
|
+
case 33:
|
|
3142
|
+
_context.t2 = {};
|
|
3143
|
+
case 34:
|
|
3144
|
+
json = _context.t2;
|
|
3145
|
+
csrfToken = json == null ? void 0 : json.csrfToken;
|
|
3146
|
+
_context.next = 42;
|
|
3147
|
+
break;
|
|
3148
|
+
case 38:
|
|
3149
|
+
_context.prev = 38;
|
|
3150
|
+
_context.t3 = _context["catch"](25);
|
|
3151
|
+
info(sessionUrl, csrfRes);
|
|
3152
|
+
error(_context.t3, csrfRes);
|
|
3153
|
+
case 42:
|
|
3154
|
+
_ref2 = (_providers = providers) != null ? _providers : {}, credentials = _ref2.credentials;
|
|
3148
3155
|
csrfCookie = csrfRes == null ? void 0 : csrfRes.headers.get('set-cookie');
|
|
3149
3156
|
if (credentials) {
|
|
3150
|
-
_context.next =
|
|
3157
|
+
_context.next = 46;
|
|
3151
3158
|
break;
|
|
3152
3159
|
}
|
|
3153
3160
|
throw new Error('Unable to obtain credential provider. Aborting server side login.');
|
|
3154
|
-
case
|
|
3161
|
+
case 46:
|
|
3155
3162
|
signInUrl = new URL(credentials.callbackUrl);
|
|
3156
3163
|
if (csrfCookie) {
|
|
3157
|
-
_context.next =
|
|
3164
|
+
_context.next = 49;
|
|
3158
3165
|
break;
|
|
3159
3166
|
}
|
|
3160
3167
|
throw new Error('Unable to authenticate REST');
|
|
3161
|
-
case
|
|
3162
|
-
info('Attempting sign in via', signInUrl.href, '
|
|
3168
|
+
case 49:
|
|
3169
|
+
info('Attempting sign in via proxy', signInUrl.href, 'with email', email);
|
|
3163
3170
|
postReq = new Request(signInUrl, {
|
|
3164
3171
|
method: 'POST',
|
|
3165
3172
|
headers: new Headers({
|
|
@@ -3173,27 +3180,27 @@ function serverAuth(config, handlers) {
|
|
|
3173
3180
|
callbackUrl: credentials.callbackUrl
|
|
3174
3181
|
})
|
|
3175
3182
|
});
|
|
3176
|
-
_context.next =
|
|
3183
|
+
_context.next = 53;
|
|
3177
3184
|
return handlers.POST(postReq);
|
|
3178
|
-
case
|
|
3185
|
+
case 53:
|
|
3179
3186
|
loginRes = _context.sent;
|
|
3180
3187
|
authCookie = loginRes == null ? void 0 : loginRes.headers.get('set-cookie');
|
|
3181
3188
|
if (authCookie) {
|
|
3182
|
-
_context.next =
|
|
3189
|
+
_context.next = 57;
|
|
3183
3190
|
break;
|
|
3184
3191
|
}
|
|
3185
3192
|
throw new Error('authentication failed');
|
|
3186
|
-
case
|
|
3193
|
+
case 57:
|
|
3187
3194
|
_ref3 = (_exec = /(nile\.session-token=.+?);/.exec(authCookie)) != null ? _exec : [], token = _ref3[1];
|
|
3188
3195
|
info('Server login successful', authCookie, csrfCookie);
|
|
3189
3196
|
return _context.abrupt("return", new Headers({
|
|
3190
3197
|
cookie: [token, csrfCookie].join('; ')
|
|
3191
3198
|
}));
|
|
3192
|
-
case
|
|
3199
|
+
case 60:
|
|
3193
3200
|
case "end":
|
|
3194
3201
|
return _context.stop();
|
|
3195
3202
|
}
|
|
3196
|
-
}, _callee);
|
|
3203
|
+
}, _callee, null, [[9, 15], [25, 38]]);
|
|
3197
3204
|
}));
|
|
3198
3205
|
function login(_x) {
|
|
3199
3206
|
return _login.apply(this, arguments);
|