@niledatabase/server 3.0.0-alpha.13 → 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/server.cjs.development.js +33 -56
- 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 +33 -56
- 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
package/dist/server.esm.js
CHANGED
|
@@ -561,18 +561,6 @@ var getTenantId = function getTenantId(cfg) {
|
|
|
561
561
|
}
|
|
562
562
|
return null;
|
|
563
563
|
};
|
|
564
|
-
var getLocal = function getLocal(cfg) {
|
|
565
|
-
var config = cfg.config,
|
|
566
|
-
logger = cfg.logger;
|
|
567
|
-
if (process.env.NILEDB_LOCAL) {
|
|
568
|
-
var _Logger7 = Logger(config, '[local]'),
|
|
569
|
-
info = _Logger7.info;
|
|
570
|
-
logger && info(logger, 'NILEDB_LOCAL', process.env.NILEDB_LOCAL);
|
|
571
|
-
var apiUrl = new URL(process.env.NILEDB_LOCAL);
|
|
572
|
-
return apiUrl.href;
|
|
573
|
-
}
|
|
574
|
-
return 'http://localhost:3000';
|
|
575
|
-
};
|
|
576
564
|
/**
|
|
577
565
|
* @param cfg various overrides
|
|
578
566
|
* @returns the url for REST to use
|
|
@@ -581,8 +569,8 @@ var getBasePath = function getBasePath(cfg) {
|
|
|
581
569
|
var _config$api4;
|
|
582
570
|
var config = cfg.config,
|
|
583
571
|
logger = cfg.logger;
|
|
584
|
-
var
|
|
585
|
-
info =
|
|
572
|
+
var _Logger7 = Logger(config, '[basePath]'),
|
|
573
|
+
info = _Logger7.info;
|
|
586
574
|
var basePath = config == null || (_config$api4 = config.api) == null ? void 0 : _config$api4.basePath;
|
|
587
575
|
var version = '';
|
|
588
576
|
if (!/\/v\d\//.test(String(basePath))) {
|
|
@@ -604,8 +592,8 @@ var getBasePath = function getBasePath(cfg) {
|
|
|
604
592
|
var getControlPlane = function getControlPlane(cfg) {
|
|
605
593
|
var config = cfg.config,
|
|
606
594
|
logger = cfg.logger;
|
|
607
|
-
var
|
|
608
|
-
info =
|
|
595
|
+
var _Logger8 = Logger(config, '[basePath]'),
|
|
596
|
+
info = _Logger8.info;
|
|
609
597
|
if (config != null && config.configureUrl) {
|
|
610
598
|
logger && info(logger, 'config', config.configureUrl);
|
|
611
599
|
return config.configureUrl;
|
|
@@ -624,8 +612,8 @@ var getControlPlane = function getControlPlane(cfg) {
|
|
|
624
612
|
function getDbHost(cfg) {
|
|
625
613
|
var config = cfg.config,
|
|
626
614
|
logger = cfg.logger;
|
|
627
|
-
var
|
|
628
|
-
info =
|
|
615
|
+
var _Logger9 = Logger(config, '[db.host]'),
|
|
616
|
+
info = _Logger9.info;
|
|
629
617
|
if (config != null && config.db && config.db.host) {
|
|
630
618
|
logger && info(logger, 'config', config == null ? void 0 : config.db.host);
|
|
631
619
|
return config.db.host;
|
|
@@ -646,8 +634,8 @@ function getDbPort(cfg) {
|
|
|
646
634
|
var _config$db;
|
|
647
635
|
var config = cfg.config,
|
|
648
636
|
logger = cfg.logger;
|
|
649
|
-
var
|
|
650
|
-
info =
|
|
637
|
+
var _Logger10 = Logger(config, '[db.port]'),
|
|
638
|
+
info = _Logger10.info;
|
|
651
639
|
if (config != null && (_config$db = config.db) != null && _config$db.port && config.db.port != null) {
|
|
652
640
|
var _config$db2;
|
|
653
641
|
logger && info(logger, 'config', config == null ? void 0 : config.db.port);
|
|
@@ -671,19 +659,13 @@ var ApiConfig = /*#__PURE__*/function () {
|
|
|
671
659
|
function ApiConfig(_ref) {
|
|
672
660
|
var basePath = _ref.basePath,
|
|
673
661
|
cookieKey = _ref.cookieKey,
|
|
674
|
-
token = _ref.token
|
|
675
|
-
version = _ref.version,
|
|
676
|
-
localPath = _ref.localPath;
|
|
662
|
+
token = _ref.token;
|
|
677
663
|
this.cookieKey = void 0;
|
|
678
664
|
this.basePath = void 0;
|
|
679
|
-
this.version = void 0;
|
|
680
|
-
this.localPath = void 0;
|
|
681
665
|
this._token = void 0;
|
|
682
666
|
this.basePath = basePath;
|
|
683
667
|
this.cookieKey = cookieKey;
|
|
684
|
-
this.version = version;
|
|
685
668
|
this._token = token;
|
|
686
|
-
this.localPath = localPath != null ? localPath : 'http://localhost:3000';
|
|
687
669
|
}
|
|
688
670
|
return _createClass(ApiConfig, [{
|
|
689
671
|
key: "token",
|
|
@@ -700,9 +682,7 @@ var Config = /*#__PURE__*/function () {
|
|
|
700
682
|
var _this = this,
|
|
701
683
|
_config$db2,
|
|
702
684
|
_config$api$cookieKey2,
|
|
703
|
-
_config$
|
|
704
|
-
_config$api$version2,
|
|
705
|
-
_config$api4;
|
|
685
|
+
_config$api2;
|
|
706
686
|
this.user = void 0;
|
|
707
687
|
this.password = void 0;
|
|
708
688
|
this.databaseId = void 0;
|
|
@@ -716,7 +696,7 @@ var Config = /*#__PURE__*/function () {
|
|
|
716
696
|
this._userId = void 0;
|
|
717
697
|
this.configure = /*#__PURE__*/function () {
|
|
718
698
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
|
|
719
|
-
var _config$db, _config$api$cookieKey, _config$api
|
|
699
|
+
var _config$db, _config$api$cookieKey, _config$api;
|
|
720
700
|
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;
|
|
721
701
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
722
702
|
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,
|
|
@@ -3101,8 +3077,8 @@ function serverAuth(config, handlers) {
|
|
|
3101
3077
|
error = _Logger.error;
|
|
3102
3078
|
return /*#__PURE__*/function () {
|
|
3103
3079
|
var _login = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
3104
|
-
var _exec;
|
|
3105
|
-
var email, password, sessionUrl, sessionReq, sessionRes, providers, csrf, csrfReq, csrfRes, csrfToken, _yield$csrfRes$json, json,
|
|
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;
|
|
3106
3082
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
3107
3083
|
while (1) switch (_context.prev = _context.next) {
|
|
3108
3084
|
case 0:
|
|
@@ -3114,7 +3090,7 @@ function serverAuth(config, handlers) {
|
|
|
3114
3090
|
throw new Error('Server side login requires a user email and password.');
|
|
3115
3091
|
case 3:
|
|
3116
3092
|
info('Obtaining providers for', email);
|
|
3117
|
-
sessionUrl = new URL(config.api.
|
|
3093
|
+
sessionUrl = new URL(config.api.basePath + "/api/auth/providers");
|
|
3118
3094
|
sessionReq = new Request(sessionUrl, {
|
|
3119
3095
|
method: 'GET',
|
|
3120
3096
|
headers: new Headers({
|
|
@@ -3135,11 +3111,11 @@ function serverAuth(config, handlers) {
|
|
|
3135
3111
|
case 15:
|
|
3136
3112
|
_context.prev = 15;
|
|
3137
3113
|
_context.t0 = _context["catch"](9);
|
|
3138
|
-
info(sessionRes);
|
|
3114
|
+
info(sessionUrl, sessionRes);
|
|
3139
3115
|
error(_context.t0);
|
|
3140
3116
|
case 19:
|
|
3141
3117
|
info('Obtaining csrf');
|
|
3142
|
-
csrf = new URL(config.api.
|
|
3118
|
+
csrf = new URL(config.api.basePath + "/api/auth/csrf");
|
|
3143
3119
|
csrfReq = new Request(csrf, {
|
|
3144
3120
|
method: 'GET',
|
|
3145
3121
|
headers: new Headers({
|
|
@@ -3167,28 +3143,29 @@ function serverAuth(config, handlers) {
|
|
|
3167
3143
|
case 34:
|
|
3168
3144
|
json = _context.t2;
|
|
3169
3145
|
csrfToken = json == null ? void 0 : json.csrfToken;
|
|
3170
|
-
_context.next =
|
|
3146
|
+
_context.next = 42;
|
|
3171
3147
|
break;
|
|
3172
3148
|
case 38:
|
|
3173
3149
|
_context.prev = 38;
|
|
3174
3150
|
_context.t3 = _context["catch"](25);
|
|
3151
|
+
info(sessionUrl, csrfRes);
|
|
3175
3152
|
error(_context.t3, csrfRes);
|
|
3176
|
-
case
|
|
3177
|
-
_providers = providers, credentials =
|
|
3153
|
+
case 42:
|
|
3154
|
+
_ref2 = (_providers = providers) != null ? _providers : {}, credentials = _ref2.credentials;
|
|
3178
3155
|
csrfCookie = csrfRes == null ? void 0 : csrfRes.headers.get('set-cookie');
|
|
3179
3156
|
if (credentials) {
|
|
3180
|
-
_context.next =
|
|
3157
|
+
_context.next = 46;
|
|
3181
3158
|
break;
|
|
3182
3159
|
}
|
|
3183
3160
|
throw new Error('Unable to obtain credential provider. Aborting server side login.');
|
|
3184
|
-
case
|
|
3161
|
+
case 46:
|
|
3185
3162
|
signInUrl = new URL(credentials.callbackUrl);
|
|
3186
3163
|
if (csrfCookie) {
|
|
3187
|
-
_context.next =
|
|
3164
|
+
_context.next = 49;
|
|
3188
3165
|
break;
|
|
3189
3166
|
}
|
|
3190
3167
|
throw new Error('Unable to authenticate REST');
|
|
3191
|
-
case
|
|
3168
|
+
case 49:
|
|
3192
3169
|
info('Attempting sign in via proxy', signInUrl.href, 'with email', email);
|
|
3193
3170
|
postReq = new Request(signInUrl, {
|
|
3194
3171
|
method: 'POST',
|
|
@@ -3203,23 +3180,23 @@ function serverAuth(config, handlers) {
|
|
|
3203
3180
|
callbackUrl: credentials.callbackUrl
|
|
3204
3181
|
})
|
|
3205
3182
|
});
|
|
3206
|
-
_context.next =
|
|
3183
|
+
_context.next = 53;
|
|
3207
3184
|
return handlers.POST(postReq);
|
|
3208
|
-
case
|
|
3185
|
+
case 53:
|
|
3209
3186
|
loginRes = _context.sent;
|
|
3210
3187
|
authCookie = loginRes == null ? void 0 : loginRes.headers.get('set-cookie');
|
|
3211
3188
|
if (authCookie) {
|
|
3212
|
-
_context.next =
|
|
3189
|
+
_context.next = 57;
|
|
3213
3190
|
break;
|
|
3214
3191
|
}
|
|
3215
3192
|
throw new Error('authentication failed');
|
|
3216
|
-
case
|
|
3217
|
-
|
|
3193
|
+
case 57:
|
|
3194
|
+
_ref3 = (_exec = /(nile\.session-token=.+?);/.exec(authCookie)) != null ? _exec : [], token = _ref3[1];
|
|
3218
3195
|
info('Server login successful', authCookie, csrfCookie);
|
|
3219
3196
|
return _context.abrupt("return", new Headers({
|
|
3220
3197
|
cookie: [token, csrfCookie].join('; ')
|
|
3221
3198
|
}));
|
|
3222
|
-
case
|
|
3199
|
+
case 60:
|
|
3223
3200
|
case "end":
|
|
3224
3201
|
return _context.stop();
|
|
3225
3202
|
}
|