@niledatabase/server 3.0.0-alpha.19 → 3.0.0-alpha.20

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.
@@ -413,40 +413,43 @@ function _unsupportedIterableToArray(r, a) {
413
413
  }
414
414
  }
415
415
 
416
- function Logger(config) {
416
+ var red = '\x1b[31m';
417
+ var yellow = '\x1b[33m';
418
+ var reset = '\x1b[0m';
419
+ var baseLogger = function baseLogger(config) {
417
420
  for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
418
421
  params[_key - 1] = arguments[_key];
419
422
  }
420
423
  return {
421
- info: function info() {
424
+ info: function info(message, meta) {
422
425
  if (config != null && config.debug) {
423
- var _console;
424
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
425
- args[_key2] = arguments[_key2];
426
- }
427
- // eslint-disable-next-line no-console
428
- (_console = console).info.apply(_console, ['[niledb]'].concat(params, args));
426
+ console.info("[niledb][DEBUG]" + params.join('') + " " + message, meta ? "\n" + JSON.stringify(meta, null, 2) : '');
429
427
  }
430
428
  },
431
- warn: function warn() {
429
+ warn: function warn(message, meta) {
432
430
  if (config != null && config.debug) {
433
- var _console2;
434
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
435
- args[_key3] = arguments[_key3];
436
- }
437
- // eslint-disable-next-line no-console
438
- (_console2 = console).warn.apply(_console2, ['[niledb]'].concat(params, args));
431
+ console.warn(yellow + "[niledb][WARN]" + reset + params.join('') + " " + message, JSON.stringify(meta, null, 2));
439
432
  }
440
433
  },
441
- error: function error() {
442
- var _console3;
443
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
444
- args[_key4] = arguments[_key4];
445
- }
446
- // eslint-disable-next-line no-console
447
- (_console3 = console).error.apply(_console3, ['[niledb]', '[ERROR]'].concat(params, args));
434
+ error: function error(message, meta) {
435
+ console.error(red + "[niledb][ERROR]" + reset + params.join('') + " " + message, meta);
448
436
  }
449
437
  };
438
+ };
439
+ function Logger(config) {
440
+ var _config$logger$info, _config$logger, _config$logger$warn, _config$logger2, _config$logger$error, _config$logger3;
441
+ for (var _len2 = arguments.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
442
+ params[_key2 - 1] = arguments[_key2];
443
+ }
444
+ var base = baseLogger(config, params);
445
+ var info = (_config$logger$info = config == null || (_config$logger = config.logger) == null ? void 0 : _config$logger.info) != null ? _config$logger$info : base.info;
446
+ var warn = (_config$logger$warn = config == null || (_config$logger2 = config.logger) == null ? void 0 : _config$logger2.warn) != null ? _config$logger$warn : base.warn;
447
+ var error = (_config$logger$error = config == null || (_config$logger3 = config.logger) == null ? void 0 : _config$logger3.error) != null ? _config$logger$error : base.error;
448
+ return {
449
+ info: info,
450
+ warn: warn,
451
+ error: error
452
+ };
450
453
  }
451
454
 
452
455
  var getDatabaseId = function getDatabaseId(cfg) {
@@ -455,14 +458,14 @@ var getDatabaseId = function getDatabaseId(cfg) {
455
458
  var _Logger = Logger(config, '[databaseId]'),
456
459
  info = _Logger.info;
457
460
  if (config != null && config.databaseId) {
458
- logger && info(logger, 'config', config.databaseId);
461
+ logger && info(logger + "[config] " + config.databaseId);
459
462
  return String(config == null ? void 0 : config.databaseId);
460
463
  }
461
464
  if (process.env.NILEDB_POSTGRES_URL) {
462
465
  var pgUrl = new URL(process.env.NILEDB_POSTGRES_URL);
463
466
  return pgUrl.pathname.substring(1);
464
467
  }
465
- logger && info(logger, 'env', process.env.NILEDB_ID);
468
+ logger && info(logger + "[NILEDB_ID] " + process.env.NILEDB_ID);
466
469
  return process.env.NILEDB_ID;
467
470
  };
468
471
  var getUsername = function getUsername(cfg) {
@@ -471,10 +474,10 @@ var getUsername = function getUsername(cfg) {
471
474
  var _Logger2 = Logger(config, '[username]'),
472
475
  info = _Logger2.info;
473
476
  if (config != null && config.user) {
474
- logger && info(logger, 'config', config.user);
477
+ logger && info(logger + "[config] " + config.user);
475
478
  return String(config == null ? void 0 : config.user);
476
479
  }
477
- logger && info(logger, 'NILEDB_USER', process.env.NILEDB_USER);
480
+ logger && info(logger + "[NILEDB_USER] " + process.env.NILEDB_USER);
478
481
  return process.env.NILEDB_USER;
479
482
  };
480
483
  var getPassword = function getPassword(cfg) {
@@ -484,10 +487,10 @@ var getPassword = function getPassword(cfg) {
484
487
  var _Logger3 = Logger(config, '[password]'),
485
488
  info = _Logger3.info;
486
489
  if (config != null && config.password) {
487
- log && info(logger, 'config', config.password);
490
+ log && info(logger + "[config] " + config.password);
488
491
  return String(config.password);
489
492
  }
490
- log && info(logger, 'NILEDB_PASSWORD', process.env.NILEDB_PASSWORD);
493
+ logger && info(logger + "[NILEDB_PASSWORD] " + process.env.NILEDB_PASSWORD);
491
494
  return process.env.NILEDB_PASSWORD;
492
495
  };
493
496
  var getInfoBearer = function getInfoBearer(cfg) {
@@ -501,11 +504,11 @@ var getToken = function getToken(cfg) {
501
504
  info = _Logger4.info;
502
505
  if (config != null && (_config$api = config.api) != null && _config$api.token) {
503
506
  var _config$api2, _config$api3;
504
- logger && info(logger, 'config', (_config$api2 = config.api) == null ? void 0 : _config$api2.token);
507
+ logger && info(logger + "[config] " + ((_config$api2 = config.api) == null ? void 0 : _config$api2.token));
505
508
  return String((_config$api3 = config.api) == null ? void 0 : _config$api3.token);
506
509
  }
507
510
  if (process.env.NILEDB_TOKEN) {
508
- logger && info(logger, 'NILEDB_TOKEN', process.env.NILEDB_TOKEN);
511
+ logger && info(logger + "[NILEDB_TOKEN] " + process.env.NILEDB_TOKEN);
509
512
  return process.env.NILEDB_TOKEN;
510
513
  }
511
514
  return undefined;
@@ -516,11 +519,11 @@ var getDatabaseName = function getDatabaseName(cfg) {
516
519
  var _Logger5 = Logger(config, '[databaseName]'),
517
520
  info = _Logger5.info;
518
521
  if (config != null && config.databaseName) {
519
- logger && info(logger, 'config', config.databaseName);
522
+ logger && info(logger + "[config] " + config.databaseName);
520
523
  return String(config.databaseName);
521
524
  }
522
525
  if (process.env.NILEDB_NAME) {
523
- logger && info(logger, 'NILEDB_NAME', process.env.NILEDB_NAME);
526
+ logger && info(logger + "[NILEDB_NAME] " + process.env.NILEDB_NAME);
524
527
  return process.env.NILEDB_NAME;
525
528
  }
526
529
  return null;
@@ -531,11 +534,11 @@ var getTenantId = function getTenantId(cfg) {
531
534
  var _Logger6 = Logger(config, '[tenantId]'),
532
535
  info = _Logger6.info;
533
536
  if (config != null && config.tenantId) {
534
- logger && info(logger, 'config', config.tenantId);
537
+ logger && info(logger + "[config] " + config.tenantId);
535
538
  return config.tenantId;
536
539
  }
537
540
  if (process.env.NILEDB_TENANT) {
538
- logger && info(logger, 'NILEDB_TENANT', process.env.NILEDB_TENANT);
541
+ logger && info(logger + "[NILEDB_TENANT] " + process.env.NILEDB_TENANT);
539
542
  return process.env.NILEDB_TENANT;
540
543
  }
541
544
  return null;
@@ -549,18 +552,19 @@ var getBasePath = function getBasePath(cfg) {
549
552
  var config = cfg.config,
550
553
  logger = cfg.logger;
551
554
  var _Logger7 = Logger(config, '[basePath]'),
555
+ warn = _Logger7.warn,
552
556
  info = _Logger7.info;
553
557
  var basePath = config == null || (_config$api4 = config.api) == null ? void 0 : _config$api4.basePath;
554
558
  if (basePath) {
555
- logger && info(logger, 'config', basePath);
559
+ logger && info(logger + "[config] " + basePath);
556
560
  return basePath;
557
561
  }
558
562
  if (process.env.NILEDB_API_URL) {
559
- logger && info(logger, 'NILEDB_API_URL', process.env.NILEDB_API_URL);
563
+ logger && info(logger + "[NILEDB_API_URL] " + process.env.NILEDB_API_URL);
560
564
  var apiUrl = new URL(process.env.NILEDB_API_URL);
561
565
  return apiUrl.href;
562
566
  }
563
- info('not set. Must run auto-configuration');
567
+ warn('not set. Must run auto-configuration');
564
568
  return undefined;
565
569
  };
566
570
  var getControlPlane = function getControlPlane(cfg) {
@@ -569,18 +573,18 @@ var getControlPlane = function getControlPlane(cfg) {
569
573
  var _Logger8 = Logger(config, '[basePath]'),
570
574
  info = _Logger8.info;
571
575
  if (config != null && config.configureUrl) {
572
- logger && info(logger, 'config', config.configureUrl);
576
+ logger && info(logger + "[config] " + config.configureUrl);
573
577
  return config.configureUrl;
574
578
  }
575
579
  if (process.env.NILEDB_CONFIGURE) {
576
- logger && info(logger, 'NILEDB_CONFIGURE', process.env.NILEDB_CONFIGURE);
580
+ logger && info(logger + "[NILEDB_CONFIGURE] " + process.env.NILEDB_CONFIGURE);
577
581
  // backwards compatible, but not really
578
582
  if (!process.env.NILEDB_CONFIGURE.startsWith('http')) {
579
583
  return "https://" + process.env.NILEDB_CONFIGURE;
580
584
  }
581
585
  return process.env.NILEDB_CONFIGURE;
582
586
  }
583
- logger && info(logger, 'default', 'https://global.thenile.dev');
587
+ logger && info(logger + "[default] https://global.thenile.dev");
584
588
  return 'https://global.thenile.dev';
585
589
  };
586
590
  function getDbHost(cfg) {
@@ -589,19 +593,19 @@ function getDbHost(cfg) {
589
593
  var _Logger9 = Logger(config, '[db.host]'),
590
594
  info = _Logger9.info;
591
595
  if (config != null && config.db && config.db.host) {
592
- logger && info(logger, 'config', config == null ? void 0 : config.db.host);
596
+ logger && info(logger + "[config] " + (config == null ? void 0 : config.db.host));
593
597
  return config.db.host;
594
598
  }
595
599
  if (process.env.NILEDB_POSTGRES_URL) {
596
600
  var pgUrl = new URL(process.env.NILEDB_POSTGRES_URL);
597
- logger && info(logger, 'NILEDB_POSTGRES_URL', pgUrl.host);
601
+ logger && info(logger + "[NILEDB_POSTGRES_URL] " + pgUrl.host);
598
602
  return pgUrl.host;
599
603
  }
600
604
  if (process.env.NILEDB_HOST) {
601
- logger && info(logger, 'NILEDB_HOST', process.env.NILEDB_HOST);
605
+ logger && info(logger + "[NILEDB_HOST] " + process.env.NILEDB_HOST);
602
606
  return process.env.NILEDB_HOST;
603
607
  }
604
- logger && info(logger, 'default', 'db.thenile.dev');
608
+ logger && info(logger + "[default] db.thenile.dev");
605
609
  return 'db.thenile.dev';
606
610
  }
607
611
  function getDbPort(cfg) {
@@ -612,14 +616,14 @@ function getDbPort(cfg) {
612
616
  info = _Logger10.info;
613
617
  if (config != null && (_config$db = config.db) != null && _config$db.port && config.db.port != null) {
614
618
  var _config$db2;
615
- logger && info(logger, 'config', config == null ? void 0 : config.db.port);
619
+ logger && info(logger + "[config] " + (config == null ? void 0 : config.db.port));
616
620
  return Number((_config$db2 = config.db) == null ? void 0 : _config$db2.port);
617
621
  }
618
622
  if (process.env.NILEDB_PORT) {
619
- logger && info(logger, 'config', process.env.NILEDB_PORT);
623
+ logger && info(logger + "[NILEDB_PORT] " + process.env.NILEDB_PORT);
620
624
  return Number(process.env.NILEDB_PORT);
621
625
  }
622
- logger && info(logger, 'default', 5432);
626
+ logger && info(logger + "[default] 5432");
623
627
  return 5432;
624
628
  }
625
629
  // don't let people accidentally log secrets to production
@@ -702,7 +706,10 @@ var Config = /*#__PURE__*/function () {
702
706
  port: configuredPort,
703
707
  database: _this.databaseName
704
708
  }, dbConfig);
705
- info('[config set]', _this);
709
+ info('[config set]', {
710
+ db: _this.db,
711
+ api: _this.api
712
+ });
706
713
  return _context.abrupt("return", _this);
707
714
  case 12:
708
715
  cp = getControlPlane(envVarConfig);
@@ -714,7 +721,7 @@ var Config = /*#__PURE__*/function () {
714
721
  if (databaseName) {
715
722
  url.searchParams.set('databaseName', databaseName);
716
723
  }
717
- info('configuring from', url.href);
724
+ info("configuring from " + url.href);
718
725
  _context.next = 19;
719
726
  return fetch(url, {
720
727
  headers: {
@@ -792,7 +799,10 @@ var Config = /*#__PURE__*/function () {
792
799
  port: configuredPort,
793
800
  database: _this.databaseName
794
801
  }, dbConfig);
795
- info('[config set]', _this);
802
+ info('[config set]', {
803
+ db: _this.db,
804
+ api: _this.api
805
+ });
796
806
  return _context.abrupt("return", _this);
797
807
  case 50:
798
808
  case "end":
@@ -957,7 +967,7 @@ function createProxyForPool(pool, config) {
957
967
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
958
968
  args[_key] = arguments[_key];
959
969
  }
960
- info.apply(void 0, args);
970
+ info.apply(void 0, ['query'].concat(args));
961
971
  // @ts-expect-error - not mine
962
972
  var called = caller.apply(this, args);
963
973
  return called;
@@ -991,7 +1001,7 @@ var NileDatabase = /*#__PURE__*/function () {
991
1001
  remaining = _objectWithoutPropertiesLoose(poolConfig, _excluded$1);
992
1002
  config.db = poolConfig;
993
1003
  this.config = config;
994
- info(this.config.db);
1004
+ info(JSON.stringify(this.config.db));
995
1005
  this.pool = createProxyForPool(new pg.Pool(remaining), this.config);
996
1006
  if (typeof afterCreate === 'function') {
997
1007
  warn('Providing an pool configuration will stop automatic tenant context setting.');
@@ -1010,7 +1020,10 @@ var NileDatabase = /*#__PURE__*/function () {
1010
1020
  var _Logger2 = Logger(config, '[after create callback]'),
1011
1021
  error = _Logger2.error;
1012
1022
  if (err) {
1013
- error('after create failed', err);
1023
+ error('after create failed', {
1024
+ message: err.message,
1025
+ stack: err.stack
1026
+ });
1014
1027
  evictPool(_this.id);
1015
1028
  }
1016
1029
  });
@@ -1026,11 +1039,14 @@ var NileDatabase = /*#__PURE__*/function () {
1026
1039
  };
1027
1040
  }());
1028
1041
  this.pool.on('error', /*#__PURE__*/function () {
1029
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(e) {
1042
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(err) {
1030
1043
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1031
1044
  while (1) switch (_context2.prev = _context2.next) {
1032
1045
  case 0:
1033
- info('pool failed', e);
1046
+ info('pool failed', {
1047
+ message: err.message,
1048
+ stack: err.stack
1049
+ });
1034
1050
  if (_this.timer) {
1035
1051
  clearTimeout(_this.timer);
1036
1052
  }
@@ -1057,10 +1073,10 @@ var NileDatabase = /*#__PURE__*/function () {
1057
1073
  }
1058
1074
  this.timer = setTimeout(function () {
1059
1075
  var _Number;
1060
- info('Pool reached idleTimeoutMillis.', _this2.id, 'evicted after', (_Number = Number(_this2.config.db.idleTimeoutMillis)) != null ? _Number : 30000, 'ms');
1076
+ info("Pool reached idleTimeoutMillis. " + _this2.id + " evicted after " + ((_Number = Number(_this2.config.db.idleTimeoutMillis)) != null ? _Number : 30000) + "ms");
1061
1077
  _this2.pool.end(function () {
1062
1078
  evictPool(_this2.id);
1063
- info('Pool end called for', _this2.id);
1079
+ info("Pool end called for " + _this2.id);
1064
1080
  // something odd going on here. Without the callback, pool.end() is flakey
1065
1081
  });
1066
1082
  }, (_Number2 = Number(this.config.db.idleTimeoutMillis)) != null ? _Number2 : 30000);
@@ -1073,7 +1089,10 @@ function makeAfterCreate(config) {
1073
1089
  info = _Logger4.info;
1074
1090
  return function (conn, done) {
1075
1091
  conn.on('error', function errorHandler(error) {
1076
- warn('Connection was terminated by server', error);
1092
+ warn('Connection was terminated by server', {
1093
+ message: error.message,
1094
+ stack: error.stack
1095
+ });
1077
1096
  done(error, conn);
1078
1097
  });
1079
1098
  if (config.tenantId) {
@@ -1087,10 +1106,10 @@ function makeAfterCreate(config) {
1087
1106
  // in this example we use pg driver's connection API
1088
1107
  conn.query(query.join(';'), function (err) {
1089
1108
  if (query.length === 1) {
1090
- info('[tenant id]', config.tenantId);
1109
+ info("[tenant id] " + config.tenantId);
1091
1110
  }
1092
1111
  if (query.length === 2) {
1093
- info('[user id]', config.userId);
1112
+ info("[user id] " + config.userId);
1094
1113
  }
1095
1114
  done(err, conn);
1096
1115
  });
@@ -1108,12 +1127,13 @@ var DBManager = /*#__PURE__*/function () {
1108
1127
  this.poolWatcher = function (config) {
1109
1128
  return function (id) {
1110
1129
  var _Logger = Logger(config, '[DBManager]'),
1111
- info = _Logger.info;
1130
+ info = _Logger.info,
1131
+ warn = _Logger.warn;
1112
1132
  if (id && _this.connections.has(id)) {
1113
- info('Removing', id, 'from db connection pool.');
1133
+ info("Removing " + id + " from db connection pool.");
1114
1134
  _this.connections["delete"](id);
1115
1135
  } else {
1116
- info('missed eviction of', id);
1136
+ warn("missed eviction of " + id);
1117
1137
  }
1118
1138
  };
1119
1139
  };
@@ -1122,16 +1142,16 @@ var DBManager = /*#__PURE__*/function () {
1122
1142
  info = _Logger2.info;
1123
1143
  var id = _this.makeId(config.tenantId, config.userId);
1124
1144
  var existing = _this.connections.get(id);
1125
- info('# of instances:', _this.connections.size);
1145
+ info("# of instances: " + _this.connections.size);
1126
1146
  if (existing) {
1127
- info('returning existing', id);
1147
+ info("returning existing " + id);
1128
1148
  existing.startTimeout();
1129
1149
  return existing.pool;
1130
1150
  }
1131
1151
  var newOne = new NileDatabase(new Config(config), id);
1132
1152
  _this.connections.set(id, newOne);
1133
- info('created new', id);
1134
- info('# of instances:', _this.connections.size);
1153
+ info("created new " + id);
1154
+ info("# of instances: " + _this.connections.size);
1135
1155
  if (_this.cleared) {
1136
1156
  _this.cleared = false;
1137
1157
  }
@@ -1140,7 +1160,7 @@ var DBManager = /*#__PURE__*/function () {
1140
1160
  this.clear = function (config) {
1141
1161
  var _Logger3 = Logger(config, '[DBManager]'),
1142
1162
  info = _Logger3.info;
1143
- info('Clearing all connections', _this.connections.size);
1163
+ info("Clearing all connections " + _this.connections.size);
1144
1164
  _this.cleared = true;
1145
1165
  _this.connections.clear();
1146
1166
  };
@@ -1230,27 +1250,35 @@ function _request() {
1230
1250
  // @ts-expect-error - its there
1231
1251
  params.duplex = 'half';
1232
1252
  }
1233
- info("[" + ((_params$method = params.method) != null ? _params$method : 'GET') + "]", url);
1234
- _context.next = 11;
1253
+ _context.next = 10;
1235
1254
  return fetch(url, _extends({}, params))["catch"](function (e) {
1236
- error('An error has occurred in the fetch', e);
1255
+ error('An error has occurred in the fetch', {
1256
+ message: e.message,
1257
+ stack: e.stack
1258
+ });
1237
1259
  return new Response('An unexpected (most likely configuration) problem has occurred', {
1238
1260
  status: 500
1239
1261
  });
1240
1262
  });
1241
- case 11:
1263
+ case 10:
1242
1264
  res = _context.sent;
1243
1265
  loggingRes = typeof (res == null ? void 0 : res.clone) === 'function' ? res == null ? void 0 : res.clone() : null;
1244
1266
  _context.t0 = info;
1245
- _context.t1 = res == null ? void 0 : res.status;
1246
- _context.t2 = res == null ? void 0 : res.statusText;
1267
+ _context.t1 = "[" + ((_params$method = params.method) != null ? _params$method : 'GET') + "] " + url;
1268
+ _context.t2 = res == null ? void 0 : res.status;
1269
+ _context.t3 = res == null ? void 0 : res.statusText;
1247
1270
  _context.next = 18;
1248
1271
  return loggingRes == null ? void 0 : loggingRes.text();
1249
1272
  case 18:
1250
- _context.t3 = _context.sent;
1251
- (0, _context.t0)('[Response]', _context.t1, _context.t2, _context.t3);
1273
+ _context.t4 = _context.sent;
1274
+ _context.t5 = {
1275
+ status: _context.t2,
1276
+ statusText: _context.t3,
1277
+ text: _context.t4
1278
+ };
1279
+ (0, _context.t0)(_context.t1, _context.t5);
1252
1280
  return _context.abrupt("return", res);
1253
- case 21:
1281
+ case 22:
1254
1282
  case "end":
1255
1283
  return _context.stop();
1256
1284
  }
@@ -1288,22 +1316,21 @@ var key$7 = 'ME';
1288
1316
  * description: Unauthorized
1289
1317
  * content: {}
1290
1318
  */
1291
- function GET$4(_x, _x2, _x3, _x4) {
1319
+ function GET$4(_x, _x2, _x3) {
1292
1320
  return _GET$4.apply(this, arguments);
1293
1321
  }
1294
1322
  function _GET$4() {
1295
- _GET$4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(url, init, log, config) {
1323
+ _GET$4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(url, init, config) {
1296
1324
  var res;
1297
1325
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1298
1326
  while (1) switch (_context.prev = _context.next) {
1299
1327
  case 0:
1300
- log('[GET]', url);
1301
- _context.next = 3;
1328
+ _context.next = 2;
1302
1329
  return request(url, init, config);
1303
- case 3:
1330
+ case 2:
1304
1331
  res = _context.sent;
1305
1332
  return _context.abrupt("return", res);
1306
- case 5:
1333
+ case 4:
1307
1334
  case "end":
1308
1335
  return _context.stop();
1309
1336
  }
@@ -1311,34 +1338,31 @@ function _GET$4() {
1311
1338
  }));
1312
1339
  return _GET$4.apply(this, arguments);
1313
1340
  }
1314
- function route$a(_x5, _x6) {
1341
+ function route$a(_x4, _x5) {
1315
1342
  return _route$a.apply(this, arguments);
1316
1343
  }
1317
1344
  function _route$a() {
1318
1345
  _route$a = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(request, config) {
1319
- var url, _Logger, info;
1346
+ var url;
1320
1347
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1321
1348
  while (1) switch (_context2.prev = _context2.next) {
1322
1349
  case 0:
1323
1350
  url = apiRoutes(config)[key$7];
1324
- _Logger = Logger(_extends({}, config, {
1325
- debug: config.debug
1326
- }), '[ROUTES]', "[" + key$7 + "]"), info = _Logger.info;
1327
1351
  _context2.t0 = request.method;
1328
- _context2.next = _context2.t0 === 'GET' ? 5 : 8;
1352
+ _context2.next = _context2.t0 === 'GET' ? 4 : 7;
1329
1353
  break;
1330
- case 5:
1331
- _context2.next = 7;
1354
+ case 4:
1355
+ _context2.next = 6;
1332
1356
  return GET$4(url, {
1333
1357
  request: request
1334
- }, info, config);
1335
- case 7:
1358
+ }, config);
1359
+ case 6:
1336
1360
  return _context2.abrupt("return", _context2.sent);
1337
- case 8:
1361
+ case 7:
1338
1362
  return _context2.abrupt("return", new Response('method not allowed', {
1339
1363
  status: 405
1340
1364
  }));
1341
- case 9:
1365
+ case 8:
1342
1366
  case "end":
1343
1367
  return _context2.stop();
1344
1368
  }
@@ -1362,7 +1386,7 @@ function _auth() {
1362
1386
  _Logger = Logger(config, '[nileauth]'), info = _Logger.info, error = _Logger.error;
1363
1387
  info('checking auth');
1364
1388
  sessionUrl = config.api.basePath + "/auth/session";
1365
- info('using session', sessionUrl);
1389
+ info("using session" + sessionUrl);
1366
1390
  // handle the pass through with posts
1367
1391
  req.headers["delete"]('content-length');
1368
1392
  _context.next = 7;
@@ -1488,21 +1512,24 @@ function _fetch2() {
1488
1512
  }));
1489
1513
  case 14:
1490
1514
  useableUrl = url.replace('{tenantId}', encodeURIComponent(String(tenantId))).replace('{userId}', encodeURIComponent(String(userId)));
1491
- info('[fetch]', useableUrl);
1515
+ info("[fetch] " + useableUrl);
1492
1516
  _context.next = 18;
1493
1517
  return fetch(useableUrl, _extends({}, opts, {
1494
1518
  headers: basicHeaders
1495
1519
  }))["catch"](function (e) {
1496
- error('[fetch]', '[response]', e);
1520
+ error('[fetch][response]', {
1521
+ message: e.message,
1522
+ stack: e.stack
1523
+ });
1497
1524
  });
1498
1525
  case 18:
1499
1526
  response = _context.sent;
1500
1527
  if (!(response && response.status >= 200 && response.status < 300)) {
1501
- _context.next = 37;
1528
+ _context.next = 40;
1502
1529
  break;
1503
1530
  }
1504
1531
  if (!(typeof response.clone === 'function')) {
1505
- _context.next = 36;
1532
+ _context.next = 39;
1506
1533
  break;
1507
1534
  }
1508
1535
  _context.prev = 21;
@@ -1511,110 +1538,121 @@ function _fetch2() {
1511
1538
  return response.clone().json();
1512
1539
  case 25:
1513
1540
  _context.t1 = _context.sent;
1514
- (0, _context.t0)('[fetch]', '[response]', _context.t1);
1515
- _context.next = 36;
1541
+ _context.t2 = "[fetch][response] " + _context.t1;
1542
+ (0, _context.t0)(_context.t2);
1543
+ _context.next = 39;
1516
1544
  break;
1517
- case 29:
1518
- _context.prev = 29;
1519
- _context.t2 = _context["catch"](21);
1520
- _context.t3 = info;
1521
- _context.next = 34;
1545
+ case 30:
1546
+ _context.prev = 30;
1547
+ _context.t3 = _context["catch"](21);
1548
+ _context.t4 = info;
1549
+ _context.next = 35;
1522
1550
  return response.clone().text();
1523
- case 34:
1524
- _context.t4 = _context.sent;
1525
- (0, _context.t3)('[fetch]', '[response]', _context.t4);
1526
- case 36:
1551
+ case 35:
1552
+ _context.t5 = _context.sent;
1553
+ _context.t6 = "[fetch][response] " + _context.t5;
1554
+ _context.t7 = {
1555
+ e: _context.t3
1556
+ };
1557
+ (0, _context.t4)(_context.t6, _context.t7);
1558
+ case 39:
1527
1559
  return _context.abrupt("return", response);
1528
- case 37:
1560
+ case 40:
1529
1561
  if (!((response == null ? void 0 : response.status) === 404)) {
1530
- _context.next = 39;
1562
+ _context.next = 42;
1531
1563
  break;
1532
1564
  }
1533
1565
  return _context.abrupt("return", new ResponseError('Not found', {
1534
1566
  status: 404
1535
1567
  }));
1536
- case 39:
1568
+ case 42:
1537
1569
  if (!((response == null ? void 0 : response.status) === 401)) {
1538
- _context.next = 41;
1570
+ _context.next = 44;
1539
1571
  break;
1540
1572
  }
1541
1573
  return _context.abrupt("return", new ResponseError('Unauthorized', {
1542
1574
  status: 401
1543
1575
  }));
1544
- case 41:
1576
+ case 44:
1545
1577
  if (!((response == null ? void 0 : response.status) === 405)) {
1546
- _context.next = 43;
1578
+ _context.next = 46;
1547
1579
  break;
1548
1580
  }
1549
1581
  return _context.abrupt("return", new ResponseError('Method not allowed', {
1550
1582
  status: 405
1551
1583
  }));
1552
- case 43:
1584
+ case 46:
1553
1585
  errorHandler = typeof (response == null ? void 0 : response.clone) === 'function' ? response.clone() : null;
1554
1586
  msg = '';
1555
- _context.prev = 45;
1556
- _context.next = 48;
1587
+ _context.prev = 48;
1588
+ _context.next = 51;
1557
1589
  return response == null ? void 0 : response.json();
1558
- case 48:
1590
+ case 51:
1559
1591
  res = _context.sent;
1560
- _context.next = 59;
1592
+ _context.next = 62;
1561
1593
  break;
1562
- case 51:
1563
- _context.prev = 51;
1564
- _context.t5 = _context["catch"](45);
1594
+ case 54:
1595
+ _context.prev = 54;
1596
+ _context.t8 = _context["catch"](48);
1565
1597
  if (!errorHandler) {
1566
- _context.next = 58;
1598
+ _context.next = 61;
1567
1599
  break;
1568
1600
  }
1569
- _context.next = 56;
1601
+ _context.next = 59;
1570
1602
  return errorHandler.text();
1571
- case 56:
1603
+ case 59:
1572
1604
  msg = _context.sent;
1573
1605
  if (msg) {
1574
- error('[fetch]', '[response]', "[status: " + errorHandler.status + "]", msg);
1606
+ error("[fetch][response] status: " + errorHandler.status + "]", {
1607
+ message: msg
1608
+ });
1575
1609
  }
1576
- case 58:
1610
+ case 61:
1577
1611
  if (!msg) {
1578
- error('[fetch]', '[response]', _context.t5);
1612
+ error('[fetch][response]', {
1613
+ e: _context.t8
1614
+ });
1579
1615
  }
1580
- case 59:
1616
+ case 62:
1581
1617
  if (!msg) {
1582
- _context.next = 61;
1618
+ _context.next = 64;
1583
1619
  break;
1584
1620
  }
1585
1621
  return _context.abrupt("return", new ResponseError(msg, {
1586
1622
  status: errorHandler == null ? void 0 : errorHandler.status
1587
1623
  }));
1588
- case 61:
1624
+ case 64:
1589
1625
  if (!(res && 'message' in res)) {
1590
- _context.next = 65;
1626
+ _context.next = 68;
1591
1627
  break;
1592
1628
  }
1593
1629
  _res = res, message = _res.message;
1594
- error('[fetch]', '[response]', "[status: " + (errorHandler == null ? void 0 : errorHandler.status) + "]", message);
1630
+ error("[fetch][response] status: " + (errorHandler == null ? void 0 : errorHandler.status) + "] " + message);
1595
1631
  return _context.abrupt("return", new ResponseError(message, {
1596
1632
  status: 400
1597
1633
  }));
1598
- case 65:
1634
+ case 68:
1599
1635
  if (!(res && 'errors' in res)) {
1600
- _context.next = 69;
1636
+ _context.next = 72;
1601
1637
  break;
1602
1638
  }
1603
1639
  _res2 = res, _res2$errors = _res2.errors, _message = _res2$errors[0];
1604
- error('[fetch]', '[response]', "[status: " + (errorHandler == null ? void 0 : errorHandler.status) + "]", _message);
1640
+ error("[fetch][response] status: " + (errorHandler == null ? void 0 : errorHandler.status) + "] " + _message);
1605
1641
  return _context.abrupt("return", new ResponseError(_message, {
1606
1642
  status: 400
1607
1643
  }));
1608
- case 69:
1609
- error('[fetch]', '[response]', "[status: " + (errorHandler == null ? void 0 : errorHandler.status) + "]", 'UNHANDLED ERROR');
1644
+ case 72:
1645
+ error("[fetch][response] status: " + (errorHandler == null ? void 0 : errorHandler.status) + "] UNHANDLED ERROR", {
1646
+ res: res
1647
+ });
1610
1648
  return _context.abrupt("return", new ResponseError(null, {
1611
1649
  status: (_response$status = response == null ? void 0 : response.status) != null ? _response$status : 500
1612
1650
  }));
1613
- case 71:
1651
+ case 74:
1614
1652
  case "end":
1615
1653
  return _context.stop();
1616
1654
  }
1617
- }, _callee, null, [[21, 29], [45, 51]]);
1655
+ }, _callee, null, [[21, 30], [48, 54]]);
1618
1656
  }));
1619
1657
  return _fetch2.apply(this, arguments);
1620
1658
  }
@@ -1681,11 +1719,11 @@ function _fetch2() {
1681
1719
  * description: Unauthorized
1682
1720
  * content: {}
1683
1721
  */
1684
- function POST$2(_x, _x2, _x3) {
1722
+ function POST$2(_x, _x2) {
1685
1723
  return _POST$2.apply(this, arguments);
1686
1724
  }
1687
1725
  function _POST$2() {
1688
- _POST$2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, init, log) {
1726
+ _POST$2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, init) {
1689
1727
  var yurl, tenantId, tenant, url;
1690
1728
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1691
1729
  while (1) switch (_context.prev = _context.next) {
@@ -1696,12 +1734,11 @@ function _POST$2() {
1696
1734
  tenantId = yurl.searchParams.get('tenantId');
1697
1735
  tenant = tenantId != null ? tenantId : getTenantFromHttp(init.request.headers);
1698
1736
  url = apiRoutes(config).USERS(tenant ? tenant : undefined);
1699
- log && log('[POST]', url);
1700
- _context.next = 9;
1737
+ _context.next = 8;
1701
1738
  return request(url, init, config);
1702
- case 9:
1739
+ case 8:
1703
1740
  return _context.abrupt("return", _context.sent);
1704
- case 10:
1741
+ case 9:
1705
1742
  case "end":
1706
1743
  return _context.stop();
1707
1744
  }
@@ -1757,19 +1794,18 @@ function _GET$3() {
1757
1794
  _context.next = 6;
1758
1795
  break;
1759
1796
  }
1760
- log('[GET]', '[ERROR]', 'No tenant id provided.');
1797
+ log('[GET] No tenant id provided.');
1761
1798
  return _context.abrupt("return", new Response(null, {
1762
1799
  status: 404
1763
1800
  }));
1764
1801
  case 6:
1765
1802
  url = apiRoutes(config).TENANT_USERS(tenant);
1766
- log('[GET]', url);
1767
1803
  init.method = 'GET';
1768
- _context.next = 11;
1804
+ _context.next = 10;
1769
1805
  return request(url, init, config);
1770
- case 11:
1806
+ case 10:
1771
1807
  return _context.abrupt("return", _context.sent);
1772
- case 12:
1808
+ case 11:
1773
1809
  case "end":
1774
1810
  return _context.stop();
1775
1811
  }
@@ -1814,11 +1850,11 @@ function _GET$3() {
1814
1850
  * description: Unauthorized
1815
1851
  * content: {}
1816
1852
  */
1817
- function PUT$2(_x, _x2, _x3, _x4) {
1853
+ function PUT$2(_x, _x2, _x3) {
1818
1854
  return _PUT$2.apply(this, arguments);
1819
1855
  }
1820
1856
  function _PUT$2() {
1821
- _PUT$2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, session, init, log) {
1857
+ _PUT$2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, session, init) {
1822
1858
  var _URL$pathname$split$r, userId, url;
1823
1859
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1824
1860
  while (1) switch (_context.prev = _context.next) {
@@ -1836,12 +1872,11 @@ function _PUT$2() {
1836
1872
  // update the user
1837
1873
  _URL$pathname$split$r = new URL(init.request.url).pathname.split('/').reverse(), userId = _URL$pathname$split$r[0];
1838
1874
  url = apiRoutes(config).USER(userId);
1839
- log('[PUT]', url);
1840
- _context.next = 9;
1875
+ _context.next = 8;
1841
1876
  return request(url, init, config);
1842
- case 9:
1877
+ case 8:
1843
1878
  return _context.abrupt("return", _context.sent);
1844
- case 10:
1879
+ case 9:
1845
1880
  case "end":
1846
1881
  return _context.stop();
1847
1882
  }
@@ -1862,7 +1897,7 @@ function _route$9() {
1862
1897
  case 0:
1863
1898
  _Logger = Logger(_extends({}, config, {
1864
1899
  debug: config.debug
1865
- }), '[ROUTES]', "[" + key$6 + "]"), info = _Logger.info;
1900
+ }), "[ROUTES][" + key$6 + "]"), info = _Logger.info;
1866
1901
  _context.next = 3;
1867
1902
  return auth(request, config);
1868
1903
  case 3:
@@ -1881,14 +1916,14 @@ function _route$9() {
1881
1916
  _context.next = 12;
1882
1917
  return POST$2(config, {
1883
1918
  request: request
1884
- }, info);
1919
+ });
1885
1920
  case 12:
1886
1921
  return _context.abrupt("return", _context.sent);
1887
1922
  case 13:
1888
1923
  _context.next = 15;
1889
1924
  return PUT$2(config, session, {
1890
1925
  request: request
1891
- }, info);
1926
+ });
1892
1927
  case 15:
1893
1928
  return _context.abrupt("return", _context.sent);
1894
1929
  case 16:
@@ -1938,32 +1973,23 @@ function matches$9(configRoutes, request) {
1938
1973
  * schema:
1939
1974
  * $ref: '#/components/schemas/APIError'
1940
1975
  */
1941
- function GET$2(_x, _x2, _x3) {
1976
+ function GET$2(_x, _x2) {
1942
1977
  return _GET$2.apply(this, arguments);
1943
1978
  }
1944
1979
  function _GET$2() {
1945
- _GET$2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, init, log) {
1980
+ _GET$2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, init) {
1946
1981
  var yurl, _yurl$pathname$split$, tenantId, url;
1947
1982
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1948
1983
  while (1) switch (_context.prev = _context.next) {
1949
1984
  case 0:
1950
1985
  yurl = new URL(init.request.url);
1951
1986
  _yurl$pathname$split$ = yurl.pathname.split('/').reverse(), tenantId = _yurl$pathname$split$[1];
1952
- if (tenantId) {
1953
- _context.next = 4;
1954
- break;
1955
- }
1956
- return _context.abrupt("return", new Response(null, {
1957
- status: 404
1958
- }));
1959
- case 4:
1960
1987
  url = "" + apiRoutes(config).TENANT_USERS(tenantId);
1961
- log('[GET]', '[TENANT_USERS]', url);
1962
- _context.next = 8;
1988
+ _context.next = 5;
1963
1989
  return request(url, init, config);
1964
- case 8:
1990
+ case 5:
1965
1991
  return _context.abrupt("return", _context.sent);
1966
- case 9:
1992
+ case 6:
1967
1993
  case "end":
1968
1994
  return _context.stop();
1969
1995
  }
@@ -2012,11 +2038,11 @@ function _GET$2() {
2012
2038
  * schema:
2013
2039
  * $ref: '#/components/schemas/User'
2014
2040
  */
2015
- function POST$1(_x, _x2, _x3, _x4) {
2041
+ function POST$1(_x, _x2, _x3) {
2016
2042
  return _POST$1.apply(this, arguments);
2017
2043
  }
2018
2044
  function _POST$1() {
2019
- _POST$1 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, session, init, log) {
2045
+ _POST$1 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, session, init) {
2020
2046
  var yurl, _yurl$pathname$split$, tenantId, url;
2021
2047
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2022
2048
  while (1) switch (_context.prev = _context.next) {
@@ -2029,12 +2055,11 @@ function _POST$1() {
2029
2055
  });
2030
2056
  init.method = 'PUT';
2031
2057
  url = apiRoutes(config).TENANT_USERS(tenantId);
2032
- log('[PUT]', url);
2033
- _context.next = 8;
2058
+ _context.next = 7;
2034
2059
  return request(url, init, config);
2035
- case 8:
2060
+ case 7:
2036
2061
  return _context.abrupt("return", _context.sent);
2037
- case 9:
2062
+ case 8:
2038
2063
  case "end":
2039
2064
  return _context.stop();
2040
2065
  }
@@ -2069,36 +2094,27 @@ function _POST$1() {
2069
2094
  * "204":
2070
2095
  * description: User removed
2071
2096
  */
2072
- function DELETE$1(_x, _x2, _x3) {
2097
+ function DELETE$1(_x, _x2) {
2073
2098
  return _DELETE$1.apply(this, arguments);
2074
2099
  }
2075
2100
  function _DELETE$1() {
2076
- _DELETE$1 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, init, log) {
2101
+ _DELETE$1 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, init) {
2077
2102
  var yurl, _yurl$pathname$split$, userId, tenantId, url;
2078
2103
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2079
2104
  while (1) switch (_context.prev = _context.next) {
2080
2105
  case 0:
2081
2106
  yurl = new URL(init.request.url); // eslint-disable-next-line @typescript-eslint/no-unused-vars
2082
2107
  _yurl$pathname$split$ = yurl.pathname.split('/').reverse(), userId = _yurl$pathname$split$[0], tenantId = _yurl$pathname$split$[2];
2083
- if (tenantId) {
2084
- _context.next = 4;
2085
- break;
2086
- }
2087
- return _context.abrupt("return", new Response(null, {
2088
- status: 404
2089
- }));
2090
- case 4:
2091
2108
  init.method = 'DELETE';
2092
2109
  init.body = JSON.stringify({
2093
2110
  email: userId
2094
2111
  });
2095
2112
  url = "" + apiRoutes(config).TENANT_USER(tenantId, userId);
2096
- log('[DELETE]', url);
2097
- _context.next = 10;
2113
+ _context.next = 7;
2098
2114
  return request(url, init, config);
2099
- case 10:
2115
+ case 7:
2100
2116
  return _context.abrupt("return", _context.sent);
2101
- case 11:
2117
+ case 8:
2102
2118
  case "end":
2103
2119
  return _context.stop();
2104
2120
  }
@@ -2132,33 +2148,24 @@ function _DELETE$1() {
2132
2148
  * "201":
2133
2149
  * description: add user to tenant
2134
2150
  */
2135
- function PUT$1(_x, _x2, _x3) {
2151
+ function PUT$1(_x, _x2) {
2136
2152
  return _PUT$1.apply(this, arguments);
2137
2153
  }
2138
2154
  function _PUT$1() {
2139
- _PUT$1 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, init, log) {
2155
+ _PUT$1 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, init) {
2140
2156
  var yurl, _yurl$pathname$split$, tenantId, url;
2141
2157
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2142
2158
  while (1) switch (_context.prev = _context.next) {
2143
2159
  case 0:
2144
2160
  yurl = new URL(init.request.url);
2145
2161
  _yurl$pathname$split$ = yurl.pathname.split('/').reverse(), tenantId = _yurl$pathname$split$[1];
2146
- if (tenantId) {
2147
- _context.next = 4;
2148
- break;
2149
- }
2150
- return _context.abrupt("return", new Response(null, {
2151
- status: 404
2152
- }));
2153
- case 4:
2154
2162
  init.method = 'PUT';
2155
2163
  url = "" + apiRoutes(config).TENANT_USERS(tenantId);
2156
- log('[PUT]', url);
2157
- _context.next = 9;
2164
+ _context.next = 6;
2158
2165
  return request(url, init, config);
2159
- case 9:
2166
+ case 6:
2160
2167
  return _context.abrupt("return", _context.sent);
2161
- case 10:
2168
+ case 7:
2162
2169
  case "end":
2163
2170
  return _context.stop();
2164
2171
  }
@@ -2173,13 +2180,13 @@ function route$8(_x, _x2) {
2173
2180
  }
2174
2181
  function _route$8() {
2175
2182
  _route$8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(request, config) {
2176
- var _Logger, info, session;
2183
+ var _Logger, info, session, yurl, _yurl$pathname$split$, tenantId;
2177
2184
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2178
2185
  while (1) switch (_context.prev = _context.next) {
2179
2186
  case 0:
2180
2187
  _Logger = Logger(_extends({}, config, {
2181
2188
  debug: config.debug
2182
- }), '[ROUTES]', "[" + key$5 + "]"), info = _Logger.info;
2189
+ }), "[ROUTES][" + key$5 + "]"), info = _Logger.info;
2183
2190
  _context.next = 3;
2184
2191
  return auth(request, config);
2185
2192
  case 3:
@@ -2193,42 +2200,53 @@ function _route$8() {
2193
2200
  status: 401
2194
2201
  }));
2195
2202
  case 7:
2203
+ yurl = new URL(request.url);
2204
+ _yurl$pathname$split$ = yurl.pathname.split('/').reverse(), tenantId = _yurl$pathname$split$[1];
2205
+ if (tenantId) {
2206
+ _context.next = 12;
2207
+ break;
2208
+ }
2209
+ info('No tenant id found in path');
2210
+ return _context.abrupt("return", new Response(null, {
2211
+ status: 404
2212
+ }));
2213
+ case 12:
2196
2214
  _context.t0 = request.method;
2197
- _context.next = _context.t0 === 'GET' ? 10 : _context.t0 === 'POST' ? 13 : _context.t0 === 'PUT' ? 16 : _context.t0 === 'DELETE' ? 19 : 22;
2215
+ _context.next = _context.t0 === 'GET' ? 15 : _context.t0 === 'POST' ? 18 : _context.t0 === 'PUT' ? 21 : _context.t0 === 'DELETE' ? 24 : 27;
2198
2216
  break;
2199
- case 10:
2200
- _context.next = 12;
2217
+ case 15:
2218
+ _context.next = 17;
2201
2219
  return GET$2(config, {
2202
2220
  request: request
2203
- }, info);
2204
- case 12:
2221
+ });
2222
+ case 17:
2205
2223
  return _context.abrupt("return", _context.sent);
2206
- case 13:
2207
- _context.next = 15;
2224
+ case 18:
2225
+ _context.next = 20;
2208
2226
  return POST$1(config, session, {
2209
2227
  request: request
2210
- }, info);
2211
- case 15:
2228
+ });
2229
+ case 20:
2212
2230
  return _context.abrupt("return", _context.sent);
2213
- case 16:
2214
- _context.next = 18;
2231
+ case 21:
2232
+ _context.next = 23;
2215
2233
  return PUT$1(config, {
2216
2234
  request: request
2217
- }, info);
2218
- case 18:
2235
+ });
2236
+ case 23:
2219
2237
  return _context.abrupt("return", _context.sent);
2220
- case 19:
2221
- _context.next = 21;
2238
+ case 24:
2239
+ _context.next = 26;
2222
2240
  return DELETE$1(config, {
2223
2241
  request: request
2224
- }, info);
2225
- case 21:
2242
+ });
2243
+ case 26:
2226
2244
  return _context.abrupt("return", _context.sent);
2227
- case 22:
2245
+ case 27:
2228
2246
  return _context.abrupt("return", new Response('method not allowed', {
2229
2247
  status: 405
2230
2248
  }));
2231
- case 23:
2249
+ case 28:
2232
2250
  case "end":
2233
2251
  return _context.stop();
2234
2252
  }
@@ -2277,11 +2295,11 @@ function matches$8(configRoutes, request) {
2277
2295
  * description: Unauthorized
2278
2296
  * content: {}
2279
2297
  */
2280
- function GET$1(_x, _x2, _x3, _x4) {
2298
+ function GET$1(_x, _x2, _x3) {
2281
2299
  return _GET$1.apply(this, arguments);
2282
2300
  }
2283
2301
  function _GET$1() {
2284
- _GET$1 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, session, init, log) {
2302
+ _GET$1 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, session, init) {
2285
2303
  var url, res;
2286
2304
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2287
2305
  while (1) switch (_context.prev = _context.next) {
@@ -2290,13 +2308,12 @@ function _GET$1() {
2290
2308
  if (typeof session === 'object' && 'user' in session && session.user) {
2291
2309
  url = "" + apiRoutes(config).USER_TENANTS(session.user.id);
2292
2310
  }
2293
- log('[GET]', url);
2294
- _context.next = 5;
2311
+ _context.next = 4;
2295
2312
  return request(url, init, config);
2296
- case 5:
2313
+ case 4:
2297
2314
  res = _context.sent;
2298
2315
  return _context.abrupt("return", res);
2299
- case 7:
2316
+ case 6:
2300
2317
  case "end":
2301
2318
  return _context.stop();
2302
2319
  }
@@ -2350,16 +2367,16 @@ function _GET() {
2350
2367
  yurl = new URL(init.request.url);
2351
2368
  _yurl$pathname$split$ = yurl.pathname.split('/').reverse(), tenantId = _yurl$pathname$split$[0];
2352
2369
  if (tenantId) {
2353
- _context.next = 4;
2370
+ _context.next = 5;
2354
2371
  break;
2355
2372
  }
2373
+ log('[GET] No tenant id provided.');
2356
2374
  return _context.abrupt("return", new Response(null, {
2357
2375
  status: 404
2358
2376
  }));
2359
- case 4:
2377
+ case 5:
2360
2378
  init.method = 'GET';
2361
2379
  url = "" + apiRoutes(config).TENANT(tenantId);
2362
- log('[GET]', url);
2363
2380
  _context.next = 9;
2364
2381
  return request(url, init, config);
2365
2382
  case 9:
@@ -2403,11 +2420,11 @@ function _GET() {
2403
2420
  * schema:
2404
2421
  * $ref: '#/components/schemas/APIError'
2405
2422
  */
2406
- function DELETE(_x, _x2, _x3) {
2423
+ function DELETE(_x, _x2) {
2407
2424
  return _DELETE.apply(this, arguments);
2408
2425
  }
2409
2426
  function _DELETE() {
2410
- _DELETE = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, init, log) {
2427
+ _DELETE = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, init) {
2411
2428
  var yurl, _yurl$pathname$split$, tenantId, url;
2412
2429
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2413
2430
  while (1) switch (_context.prev = _context.next) {
@@ -2424,12 +2441,11 @@ function _DELETE() {
2424
2441
  case 4:
2425
2442
  init.method = 'DELETE';
2426
2443
  url = "" + apiRoutes(config).TENANT(tenantId);
2427
- log('[DELETE]', url);
2428
- _context.next = 9;
2444
+ _context.next = 8;
2429
2445
  return request(url, init, config);
2430
- case 9:
2446
+ case 8:
2431
2447
  return _context.abrupt("return", _context.sent);
2432
- case 10:
2448
+ case 9:
2433
2449
  case "end":
2434
2450
  return _context.stop();
2435
2451
  }
@@ -2472,11 +2488,11 @@ function _DELETE() {
2472
2488
  * schema:
2473
2489
  * $ref: '#/components/schemas/APIError'
2474
2490
  */
2475
- function PUT(_x, _x2, _x3) {
2491
+ function PUT(_x, _x2) {
2476
2492
  return _PUT.apply(this, arguments);
2477
2493
  }
2478
2494
  function _PUT() {
2479
- _PUT = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, init, log) {
2495
+ _PUT = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, init) {
2480
2496
  var yurl, _yurl$pathname$split$, tenantId, url;
2481
2497
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2482
2498
  while (1) switch (_context.prev = _context.next) {
@@ -2494,12 +2510,11 @@ function _PUT() {
2494
2510
  init.body = init.request.body;
2495
2511
  init.method = 'PUT';
2496
2512
  url = "" + apiRoutes(config).TENANT(tenantId);
2497
- log('[PUT]', url);
2498
- _context.next = 10;
2513
+ _context.next = 9;
2499
2514
  return request(url, init, config);
2500
- case 10:
2515
+ case 9:
2501
2516
  return _context.abrupt("return", _context.sent);
2502
- case 11:
2517
+ case 10:
2503
2518
  case "end":
2504
2519
  return _context.stop();
2505
2520
  }
@@ -2549,11 +2564,11 @@ function _PUT() {
2549
2564
  * schema:
2550
2565
  * $ref: '#/components/schemas/APIError'
2551
2566
  */
2552
- function POST(_x, _x2, _x3) {
2567
+ function POST(_x, _x2) {
2553
2568
  return _POST.apply(this, arguments);
2554
2569
  }
2555
2570
  function _POST() {
2556
- _POST = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, init, log) {
2571
+ _POST = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, init) {
2557
2572
  var url;
2558
2573
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2559
2574
  while (1) switch (_context.prev = _context.next) {
@@ -2561,12 +2576,11 @@ function _POST() {
2561
2576
  init.body = init.request.body;
2562
2577
  init.method = 'POST';
2563
2578
  url = "" + apiRoutes(config).TENANTS;
2564
- log('[POST]', url);
2565
- _context.next = 6;
2579
+ _context.next = 5;
2566
2580
  return request(url, init, config);
2567
- case 6:
2581
+ case 5:
2568
2582
  return _context.abrupt("return", _context.sent);
2569
- case 7:
2583
+ case 6:
2570
2584
  case "end":
2571
2585
  return _context.stop();
2572
2586
  }
@@ -2595,7 +2609,7 @@ function _route$7() {
2595
2609
  case 0:
2596
2610
  _Logger = Logger(_extends({}, config, {
2597
2611
  debug: config.debug
2598
- }), '[ROUTES]', "[" + key$4 + "]"), info = _Logger.info;
2612
+ }), "[ROUTES][" + key$4 + "]"), info = _Logger.info;
2599
2613
  _context.next = 3;
2600
2614
  return auth(request, config);
2601
2615
  case 3:
@@ -2628,28 +2642,28 @@ function _route$7() {
2628
2642
  _context.next = 17;
2629
2643
  return GET$1(config, session, {
2630
2644
  request: request
2631
- }, info);
2645
+ });
2632
2646
  case 17:
2633
2647
  return _context.abrupt("return", _context.sent);
2634
2648
  case 18:
2635
2649
  _context.next = 20;
2636
2650
  return POST(config, {
2637
2651
  request: request
2638
- }, info);
2652
+ });
2639
2653
  case 20:
2640
2654
  return _context.abrupt("return", _context.sent);
2641
2655
  case 21:
2642
2656
  _context.next = 23;
2643
2657
  return DELETE(config, {
2644
2658
  request: request
2645
- }, info);
2659
+ });
2646
2660
  case 23:
2647
2661
  return _context.abrupt("return", _context.sent);
2648
2662
  case 24:
2649
2663
  _context.next = 26;
2650
2664
  return PUT(config, {
2651
2665
  request: request
2652
- }, info);
2666
+ });
2653
2667
  case 26:
2654
2668
  return _context.abrupt("return", _context.sent);
2655
2669
  case 27:
@@ -2808,7 +2822,7 @@ function _route$2() {
2808
2822
  case 0:
2809
2823
  _Logger = Logger(_extends({}, config, {
2810
2824
  debug: config.debug
2811
- }), '[ROUTES]', "[" + key$2 + "]"), error = _Logger.error;
2825
+ }), "[ROUTES][" + key$2 + "]"), error = _Logger.error;
2812
2826
  _URL$pathname$split$r = new URL(request$1.url).pathname.split('/').reverse(), provider = _URL$pathname$split$r[0];
2813
2827
  passThroughUrl = new URL(request$1.url);
2814
2828
  params = new URLSearchParams(passThroughUrl.search);
@@ -3248,7 +3262,7 @@ function serverAuth(config, handlers) {
3248
3262
  }
3249
3263
  throw new Error('Server side login requires a user email and password.');
3250
3264
  case 3:
3251
- info('Obtaining providers for', email);
3265
+ info("Obtaining providers for " + email);
3252
3266
  sessionUrl = new URL("" + ORIGIN + routes.PROVIDERS);
3253
3267
  sessionReq = new Request(sessionUrl, {
3254
3268
  method: 'GET',
@@ -3276,7 +3290,9 @@ function serverAuth(config, handlers) {
3276
3290
  case 17:
3277
3291
  _context.prev = 17;
3278
3292
  _context.t0 = _context["catch"](11);
3279
- info(sessionUrl, sessionRes);
3293
+ info(sessionUrl, {
3294
+ sessionRes: sessionRes
3295
+ });
3280
3296
  error(_context.t0);
3281
3297
  case 21:
3282
3298
  info('Obtaining csrf');
@@ -3313,8 +3329,12 @@ function serverAuth(config, handlers) {
3313
3329
  case 40:
3314
3330
  _context.prev = 40;
3315
3331
  _context.t3 = _context["catch"](27);
3316
- info(sessionUrl, csrfRes);
3317
- error(_context.t3, csrfRes);
3332
+ info(sessionUrl, {
3333
+ csrfRes: csrfRes
3334
+ });
3335
+ error(_context.t3, {
3336
+ csrfRes: csrfRes
3337
+ });
3318
3338
  case 44:
3319
3339
  _ref2 = (_providers = providers) != null ? _providers : {}, credentials = _ref2.credentials;
3320
3340
  csrfCookie = csrfRes == null ? void 0 : csrfRes.headers.get('set-cookie');
@@ -3331,7 +3351,7 @@ function serverAuth(config, handlers) {
3331
3351
  }
3332
3352
  throw new Error('Unable to authenticate REST');
3333
3353
  case 51:
3334
- info('Attempting sign in with email', email);
3354
+ info("Attempting sign in with email " + email);
3335
3355
  postReq = new Request(signInUrl, {
3336
3356
  method: 'POST',
3337
3357
  headers: new Headers({
@@ -3363,7 +3383,10 @@ function serverAuth(config, handlers) {
3363
3383
  }
3364
3384
  throw new Error('Server login failed');
3365
3385
  case 62:
3366
- info('Server login successful', authCookie, csrfCookie);
3386
+ info('Server login successful', {
3387
+ authCookie: authCookie,
3388
+ csrfCookie: csrfCookie
3389
+ });
3367
3390
  return _context.abrupt("return", new Headers({
3368
3391
  cookie: [token, csrfCookie].join('; ')
3369
3392
  }));