@niledatabase/server 3.0.0-alpha.8 → 3.0.0-alpha.9

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.
@@ -613,7 +613,11 @@ var getControlPlane = function getControlPlane(cfg) {
613
613
  logger && info(logger, 'NILEDB_CONFIGURE', process.env.NILEDB_CONFIGURE);
614
614
  return process.env.NILEDB_CONFIGURE;
615
615
  }
616
- logger && info(logger, 'default', process.env.NILEDB_CONFIGURE);
616
+ if (config != null && config.configureUrl) {
617
+ logger && info(logger, 'NILEDB_CONFIGURE', config.configureUrl);
618
+ return config.configureUrl;
619
+ }
620
+ logger && info(logger, 'default', 'https://global.thenile.dev');
617
621
  return 'https://global.thenile.dev';
618
622
  };
619
623
  function getDbHost(cfg) {
@@ -3081,6 +3085,8 @@ var appRoutes = function appRoutes(prefix) {
3081
3085
  * a helper function to log in server side.
3082
3086
  */
3083
3087
  function serverAuth(config, handlers) {
3088
+ var _Logger = Logger(config, '[serverAuth]'),
3089
+ info = _Logger.info;
3084
3090
  return /*#__PURE__*/function () {
3085
3091
  var _login = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
3086
3092
  var _yield$csrfRes$json, _exec;
@@ -3089,6 +3095,7 @@ function serverAuth(config, handlers) {
3089
3095
  while (1) switch (_context.prev = _context.next) {
3090
3096
  case 0:
3091
3097
  email = _ref.email, password = _ref.password;
3098
+ info('Obtaining session');
3092
3099
  sessionUrl = new URL(config.api.localPath + "/api/auth/providers");
3093
3100
  sessionReq = new Request(sessionUrl, {
3094
3101
  method: 'GET',
@@ -3096,14 +3103,15 @@ function serverAuth(config, handlers) {
3096
3103
  host: sessionUrl.host
3097
3104
  })
3098
3105
  });
3099
- _context.next = 5;
3106
+ _context.next = 6;
3100
3107
  return handlers.POST(sessionReq);
3101
- case 5:
3108
+ case 6:
3102
3109
  sessionRes = _context.sent;
3103
- _context.next = 8;
3110
+ _context.next = 9;
3104
3111
  return sessionRes == null ? void 0 : sessionRes.json();
3105
- case 8:
3112
+ case 9:
3106
3113
  providers = _context.sent;
3114
+ info('Obtaining csrf');
3107
3115
  csrf = new URL(config.api.localPath + "/api/auth/csrf");
3108
3116
  csrfReq = new Request(csrf, {
3109
3117
  method: 'GET',
@@ -3111,36 +3119,36 @@ function serverAuth(config, handlers) {
3111
3119
  host: sessionUrl.host
3112
3120
  })
3113
3121
  });
3114
- _context.next = 13;
3122
+ _context.next = 15;
3115
3123
  return handlers.POST(csrfReq);
3116
- case 13:
3124
+ case 15:
3117
3125
  csrfRes = _context.sent;
3118
- _context.next = 16;
3126
+ _context.next = 18;
3119
3127
  return csrfRes == null ? void 0 : csrfRes.json();
3120
- case 16:
3128
+ case 18:
3121
3129
  _context.t0 = _yield$csrfRes$json = _context.sent;
3122
3130
  if (!(_context.t0 != null)) {
3123
- _context.next = 21;
3131
+ _context.next = 23;
3124
3132
  break;
3125
3133
  }
3126
3134
  _context.t1 = _yield$csrfRes$json;
3127
- _context.next = 22;
3135
+ _context.next = 24;
3128
3136
  break;
3129
- case 21:
3137
+ case 23:
3130
3138
  _context.t1 = {};
3131
- case 22:
3139
+ case 24:
3132
3140
  _ref2 = _context.t1;
3133
3141
  csrfToken = _ref2.csrfToken;
3134
3142
  credentials = providers.credentials;
3135
3143
  csrfCookie = csrfRes == null ? void 0 : csrfRes.headers.get('set-cookie');
3136
- expect(csrfCookie).toContain('nile.csrf-token=');
3137
3144
  signInUrl = new URL(credentials.callbackUrl);
3138
3145
  if (csrfCookie) {
3139
- _context.next = 30;
3146
+ _context.next = 31;
3140
3147
  break;
3141
3148
  }
3142
- throw new Error('unable to authenticate REST');
3143
- case 30:
3149
+ throw new Error('Unable to authenticate REST');
3150
+ case 31:
3151
+ info('Attempting sign in to', signInUrl.href);
3144
3152
  postReq = new Request(signInUrl, {
3145
3153
  method: 'POST',
3146
3154
  headers: new Headers({
@@ -3154,23 +3162,23 @@ function serverAuth(config, handlers) {
3154
3162
  callbackUrl: credentials.callbackUrl
3155
3163
  })
3156
3164
  });
3157
- _context.next = 33;
3165
+ _context.next = 35;
3158
3166
  return handlers.POST(postReq);
3159
- case 33:
3167
+ case 35:
3160
3168
  loginRes = _context.sent;
3161
3169
  authCookie = loginRes == null ? void 0 : loginRes.headers.get('set-cookie');
3162
3170
  if (authCookie) {
3163
- _context.next = 37;
3171
+ _context.next = 39;
3164
3172
  break;
3165
3173
  }
3166
3174
  throw new Error('authentication failed');
3167
- case 37:
3168
- expect(authCookie).toContain('nile.session-token=');
3175
+ case 39:
3176
+ info('Server login successful');
3169
3177
  _ref3 = (_exec = /(nile\.session-token=.+?);/.exec(authCookie)) != null ? _exec : [], token = _ref3[1];
3170
3178
  return _context.abrupt("return", new Headers({
3171
3179
  cookie: [token, csrfCookie].join('; ')
3172
3180
  }));
3173
- case 40:
3181
+ case 42:
3174
3182
  case "end":
3175
3183
  return _context.stop();
3176
3184
  }