@niledatabase/server 3.0.0-alpha.33 → 3.0.0-alpha.35

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.
@@ -482,8 +482,12 @@ var getDatabaseId = function getDatabaseId(cfg) {
482
482
  return String(config == null ? void 0 : config.databaseId);
483
483
  }
484
484
  if (process.env.NILEDB_POSTGRES_URL) {
485
- var pgUrl = new URL(process.env.NILEDB_POSTGRES_URL);
486
- return pgUrl.pathname.substring(1);
485
+ try {
486
+ var pgUrl = new URL(process.env.NILEDB_POSTGRES_URL);
487
+ return pgUrl.pathname.substring(1);
488
+ } catch (e) {
489
+ // ok to fail
490
+ }
487
491
  }
488
492
  logger && info(logger + "[NILEDB_ID] " + process.env.NILEDB_ID);
489
493
  return process.env.NILEDB_ID;
@@ -546,6 +550,14 @@ var getDatabaseName = function getDatabaseName(cfg) {
546
550
  logger && info(logger + "[NILEDB_NAME] " + process.env.NILEDB_NAME);
547
551
  return process.env.NILEDB_NAME;
548
552
  }
553
+ if (process.env.NILEDB_POSTGRES_URL) {
554
+ try {
555
+ var pgUrl = new URL(process.env.NILEDB_POSTGRES_URL);
556
+ return pgUrl.pathname.substring(1);
557
+ } catch (e) {
558
+ // ok to fail
559
+ }
560
+ }
549
561
  return null;
550
562
  };
551
563
  var getTenantId = function getTenantId(cfg) {
@@ -573,7 +585,8 @@ var getBasePath = function getBasePath(cfg) {
573
585
  logger = cfg.logger;
574
586
  var _Logger7 = Logger(config, '[basePath]'),
575
587
  warn = _Logger7.warn,
576
- info = _Logger7.info;
588
+ info = _Logger7.info,
589
+ error = _Logger7.error;
577
590
  var basePath = config == null || (_config$api4 = config.api) == null ? void 0 : _config$api4.basePath;
578
591
  if (basePath) {
579
592
  logger && info(logger + "[config] " + basePath);
@@ -581,8 +594,14 @@ var getBasePath = function getBasePath(cfg) {
581
594
  }
582
595
  if (process.env.NILEDB_API_URL) {
583
596
  logger && info(logger + "[NILEDB_API_URL] " + process.env.NILEDB_API_URL);
584
- var apiUrl = new URL(process.env.NILEDB_API_URL);
585
- return apiUrl.href;
597
+ try {
598
+ var apiUrl = new URL(process.env.NILEDB_API_URL);
599
+ return apiUrl.href;
600
+ } catch (e) {
601
+ if (e instanceof Error) {
602
+ error(e.stack);
603
+ }
604
+ }
586
605
  }
587
606
  warn('not set. Must run auto-configuration');
588
607
  return undefined;
@@ -617,9 +636,13 @@ function getDbHost(cfg) {
617
636
  return config.db.host;
618
637
  }
619
638
  if (process.env.NILEDB_POSTGRES_URL) {
620
- var pgUrl = new URL(process.env.NILEDB_POSTGRES_URL);
621
- logger && info(logger + "[NILEDB_POSTGRES_URL] " + pgUrl.hostname);
622
- return pgUrl.hostname;
639
+ try {
640
+ var pgUrl = new URL(process.env.NILEDB_POSTGRES_URL);
641
+ logger && info(logger + "[NILEDB_POSTGRES_URL] " + pgUrl.hostname);
642
+ return pgUrl.hostname;
643
+ } catch (e) {
644
+ // ok to fail
645
+ }
623
646
  }
624
647
  if (process.env.NILEDB_HOST) {
625
648
  logger && info(logger + "[NILEDB_HOST] " + process.env.NILEDB_HOST);
@@ -643,6 +666,16 @@ function getDbPort(cfg) {
643
666
  logger && info(logger + "[NILEDB_PORT] " + process.env.NILEDB_PORT);
644
667
  return Number(process.env.NILEDB_PORT);
645
668
  }
669
+ if (process.env.NILEDB_POSTGRES_URL) {
670
+ try {
671
+ var pgUrl = new URL(process.env.NILEDB_POSTGRES_URL);
672
+ if (pgUrl.port) {
673
+ return Number(pgUrl.port);
674
+ }
675
+ } catch (e) {
676
+ // ok to fail
677
+ }
678
+ }
646
679
  logger && info(logger + "[default] 5432");
647
680
  return 5432;
648
681
  }
@@ -1356,7 +1389,7 @@ function _request() {
1356
1389
  return _request.apply(this, arguments);
1357
1390
  }
1358
1391
 
1359
- var key$7 = 'ME';
1392
+ var key$8 = 'ME';
1360
1393
  /**
1361
1394
  * @swagger
1362
1395
  * /api/me:
@@ -1407,16 +1440,16 @@ function _GET$4() {
1407
1440
  }));
1408
1441
  return _GET$4.apply(this, arguments);
1409
1442
  }
1410
- function route$a(_x4, _x5) {
1411
- return _route$a.apply(this, arguments);
1443
+ function route$b(_x4, _x5) {
1444
+ return _route$b.apply(this, arguments);
1412
1445
  }
1413
- function _route$a() {
1414
- _route$a = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(request, config) {
1446
+ function _route$b() {
1447
+ _route$b = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(request, config) {
1415
1448
  var url;
1416
1449
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1417
1450
  while (1) switch (_context2.prev = _context2.next) {
1418
1451
  case 0:
1419
- url = apiRoutes(config)[key$7];
1452
+ url = apiRoutes(config)[key$8];
1420
1453
  _context2.t0 = request.method;
1421
1454
  _context2.next = _context2.t0 === 'GET' ? 4 : 7;
1422
1455
  break;
@@ -1437,10 +1470,10 @@ function _route$a() {
1437
1470
  }
1438
1471
  }, _callee2);
1439
1472
  }));
1440
- return _route$a.apply(this, arguments);
1473
+ return _route$b.apply(this, arguments);
1441
1474
  }
1442
- function matches$a(configRoutes, request) {
1443
- return urlMatches(request.url, configRoutes[key$7]);
1475
+ function matches$b(configRoutes, request) {
1476
+ return urlMatches(request.url, configRoutes[key$8]);
1444
1477
  }
1445
1478
 
1446
1479
  function auth(_x, _x2) {
@@ -1808,11 +1841,11 @@ function _fetch2() {
1808
1841
  * description: Unauthorized
1809
1842
  * content: {}
1810
1843
  */
1811
- function POST$2(_x, _x2) {
1812
- return _POST$2.apply(this, arguments);
1844
+ function POST$3(_x, _x2) {
1845
+ return _POST$3.apply(this, arguments);
1813
1846
  }
1814
- function _POST$2() {
1815
- _POST$2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, init) {
1847
+ function _POST$3() {
1848
+ _POST$3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, init) {
1816
1849
  var yurl, tenantId, newTenantName, tenant, url;
1817
1850
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1818
1851
  while (1) switch (_context.prev = _context.next) {
@@ -1837,7 +1870,7 @@ function _POST$2() {
1837
1870
  }
1838
1871
  }, _callee);
1839
1872
  }));
1840
- return _POST$2.apply(this, arguments);
1873
+ return _POST$3.apply(this, arguments);
1841
1874
  }
1842
1875
 
1843
1876
  /**
@@ -1978,19 +2011,19 @@ function _PUT$2() {
1978
2011
  return _PUT$2.apply(this, arguments);
1979
2012
  }
1980
2013
 
1981
- var key$6 = 'USERS';
1982
- function route$9(_x, _x2) {
1983
- return _route$9.apply(this, arguments);
2014
+ var key$7 = 'USERS';
2015
+ function route$a(_x, _x2) {
2016
+ return _route$a.apply(this, arguments);
1984
2017
  }
1985
- function _route$9() {
1986
- _route$9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(request, config) {
2018
+ function _route$a() {
2019
+ _route$a = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(request, config) {
1987
2020
  var _Logger, info, session;
1988
2021
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1989
2022
  while (1) switch (_context.prev = _context.next) {
1990
2023
  case 0:
1991
2024
  _Logger = Logger(_extends({}, config, {
1992
2025
  debug: config.debug
1993
- }), "[ROUTES][" + key$6 + "]"), info = _Logger.info;
2026
+ }), "[ROUTES][" + key$7 + "]"), info = _Logger.info;
1994
2027
  _context.next = 3;
1995
2028
  return auth(request, config);
1996
2029
  case 3:
@@ -2007,7 +2040,7 @@ function _route$9() {
2007
2040
  return _context.abrupt("return", _context.sent);
2008
2041
  case 10:
2009
2042
  _context.next = 12;
2010
- return POST$2(config, {
2043
+ return POST$3(config, {
2011
2044
  request: request
2012
2045
  });
2013
2046
  case 12:
@@ -2029,10 +2062,10 @@ function _route$9() {
2029
2062
  }
2030
2063
  }, _callee);
2031
2064
  }));
2032
- return _route$9.apply(this, arguments);
2065
+ return _route$a.apply(this, arguments);
2033
2066
  }
2034
- function matches$9(configRoutes, request) {
2035
- return urlMatches(request.url, configRoutes[key$6]);
2067
+ function matches$a(configRoutes, request) {
2068
+ return urlMatches(request.url, configRoutes[key$7]);
2036
2069
  }
2037
2070
 
2038
2071
  /**
@@ -2131,11 +2164,11 @@ function _GET$2() {
2131
2164
  * schema:
2132
2165
  * $ref: '#/components/schemas/User'
2133
2166
  */
2134
- function POST$1(_x, _x2, _x3) {
2135
- return _POST$1.apply(this, arguments);
2167
+ function POST$2(_x, _x2, _x3) {
2168
+ return _POST$2.apply(this, arguments);
2136
2169
  }
2137
- function _POST$1() {
2138
- _POST$1 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, session, init) {
2170
+ function _POST$2() {
2171
+ _POST$2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, session, init) {
2139
2172
  var yurl, _yurl$pathname$split$, tenantId, url;
2140
2173
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2141
2174
  while (1) switch (_context.prev = _context.next) {
@@ -2158,7 +2191,7 @@ function _POST$1() {
2158
2191
  }
2159
2192
  }, _callee);
2160
2193
  }));
2161
- return _POST$1.apply(this, arguments);
2194
+ return _POST$2.apply(this, arguments);
2162
2195
  }
2163
2196
 
2164
2197
  /**
@@ -2267,19 +2300,19 @@ function _PUT$1() {
2267
2300
  return _PUT$1.apply(this, arguments);
2268
2301
  }
2269
2302
 
2270
- var key$5 = 'TENANT_USERS';
2271
- function route$8(_x, _x2) {
2272
- return _route$8.apply(this, arguments);
2303
+ var key$6 = 'TENANT_USERS';
2304
+ function route$9(_x, _x2) {
2305
+ return _route$9.apply(this, arguments);
2273
2306
  }
2274
- function _route$8() {
2275
- _route$8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(request, config) {
2307
+ function _route$9() {
2308
+ _route$9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(request, config) {
2276
2309
  var _Logger, info, session, yurl, _yurl$pathname$split$, tenantId;
2277
2310
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2278
2311
  while (1) switch (_context.prev = _context.next) {
2279
2312
  case 0:
2280
2313
  _Logger = Logger(_extends({}, config, {
2281
2314
  debug: config.debug
2282
- }), "[ROUTES][" + key$5 + "]"), info = _Logger.info;
2315
+ }), "[ROUTES][" + key$6 + "]"), info = _Logger.info;
2283
2316
  _context.next = 3;
2284
2317
  return auth(request, config);
2285
2318
  case 3:
@@ -2316,7 +2349,7 @@ function _route$8() {
2316
2349
  return _context.abrupt("return", _context.sent);
2317
2350
  case 18:
2318
2351
  _context.next = 20;
2319
- return POST$1(config, session, {
2352
+ return POST$2(config, session, {
2320
2353
  request: request
2321
2354
  });
2322
2355
  case 20:
@@ -2345,17 +2378,17 @@ function _route$8() {
2345
2378
  }
2346
2379
  }, _callee);
2347
2380
  }));
2348
- return _route$8.apply(this, arguments);
2381
+ return _route$9.apply(this, arguments);
2349
2382
  }
2350
- function matches$8(configRoutes, request) {
2383
+ function matches$9(configRoutes, request) {
2351
2384
  var url = new URL(request.url);
2352
2385
  var _url$pathname$split$r = url.pathname.split('/').reverse(),
2353
2386
  userId = _url$pathname$split$r[0],
2354
2387
  possibleTenantId = _url$pathname$split$r[1],
2355
2388
  tenantId = _url$pathname$split$r[2];
2356
- var route = configRoutes[key$5].replace('{tenantId}', tenantId).replace('{userId}', userId);
2389
+ var route = configRoutes[key$6].replace('{tenantId}', tenantId).replace('{userId}', userId);
2357
2390
  if (userId === 'users') {
2358
- route = configRoutes[key$5].replace('{tenantId}', possibleTenantId);
2391
+ route = configRoutes[key$6].replace('{tenantId}', possibleTenantId);
2359
2392
  }
2360
2393
  return urlMatches(request.url, route);
2361
2394
  }
@@ -2657,11 +2690,11 @@ function _PUT() {
2657
2690
  * schema:
2658
2691
  * $ref: '#/components/schemas/APIError'
2659
2692
  */
2660
- function POST(_x, _x2) {
2661
- return _POST.apply(this, arguments);
2693
+ function POST$1(_x, _x2) {
2694
+ return _POST$1.apply(this, arguments);
2662
2695
  }
2663
- function _POST() {
2664
- _POST = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, init) {
2696
+ function _POST$1() {
2697
+ _POST$1 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, init) {
2665
2698
  var url;
2666
2699
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2667
2700
  while (1) switch (_context.prev = _context.next) {
@@ -2679,7 +2712,7 @@ function _POST() {
2679
2712
  }
2680
2713
  }, _callee);
2681
2714
  }));
2682
- return _POST.apply(this, arguments);
2715
+ return _POST$1.apply(this, arguments);
2683
2716
  }
2684
2717
 
2685
2718
  function isUUID(value) {
@@ -2690,19 +2723,19 @@ function isUUID(value) {
2690
2723
  var regex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5|7][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
2691
2724
  return regex.test(value);
2692
2725
  }
2693
- var key$4 = 'TENANTS';
2694
- function route$7(_x, _x2) {
2695
- return _route$7.apply(this, arguments);
2726
+ var key$5 = 'TENANTS';
2727
+ function route$8(_x, _x2) {
2728
+ return _route$8.apply(this, arguments);
2696
2729
  }
2697
- function _route$7() {
2698
- _route$7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(request, config) {
2730
+ function _route$8() {
2731
+ _route$8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(request, config) {
2699
2732
  var _Logger, info, session, _request$url$split$re, possibleTenantId;
2700
2733
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2701
2734
  while (1) switch (_context.prev = _context.next) {
2702
2735
  case 0:
2703
2736
  _Logger = Logger(_extends({}, config, {
2704
2737
  debug: config.debug
2705
- }), "[ROUTES][" + key$4 + "]"), info = _Logger.info;
2738
+ }), "[ROUTES][" + key$5 + "]"), info = _Logger.info;
2706
2739
  _context.next = 3;
2707
2740
  return auth(request, config);
2708
2741
  case 3:
@@ -2740,7 +2773,7 @@ function _route$7() {
2740
2773
  return _context.abrupt("return", _context.sent);
2741
2774
  case 18:
2742
2775
  _context.next = 20;
2743
- return POST(config, {
2776
+ return POST$1(config, {
2744
2777
  request: request
2745
2778
  });
2746
2779
  case 20:
@@ -2769,10 +2802,10 @@ function _route$7() {
2769
2802
  }
2770
2803
  }, _callee);
2771
2804
  }));
2772
- return _route$7.apply(this, arguments);
2805
+ return _route$8.apply(this, arguments);
2773
2806
  }
2774
- function matches$7(configRoutes, request) {
2775
- return urlMatches(request.url, configRoutes[key$4]);
2807
+ function matches$8(configRoutes, request) {
2808
+ return urlMatches(request.url, configRoutes[key$5]);
2776
2809
  }
2777
2810
 
2778
2811
  var proxyRoutes = function proxyRoutes(config) {
@@ -2787,17 +2820,17 @@ var proxyRoutes = function proxyRoutes(config) {
2787
2820
  };
2788
2821
  };
2789
2822
 
2790
- var key$3 = 'SIGNIN';
2791
- function route$6(_x, _x2) {
2792
- return _route$6.apply(this, arguments);
2823
+ var key$4 = 'SIGNIN';
2824
+ function route$7(_x, _x2) {
2825
+ return _route$7.apply(this, arguments);
2793
2826
  }
2794
- function _route$6() {
2795
- _route$6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, config) {
2827
+ function _route$7() {
2828
+ _route$7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, config) {
2796
2829
  var url, init, _URL$pathname$split$r, provider, passThroughUrl, params, res;
2797
2830
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2798
2831
  while (1) switch (_context.prev = _context.next) {
2799
2832
  case 0:
2800
- url = proxyRoutes(config)[key$3];
2833
+ url = proxyRoutes(config)[key$4];
2801
2834
  init = {
2802
2835
  method: req.method,
2803
2836
  headers: req.headers
@@ -2807,7 +2840,7 @@ function _route$6() {
2807
2840
  init.body = req.clone().body;
2808
2841
  }
2809
2842
  _URL$pathname$split$r = new URL(req.url).pathname.split('/').reverse(), provider = _URL$pathname$split$r[0];
2810
- url = proxyRoutes(config)[key$3] + "/" + provider;
2843
+ url = proxyRoutes(config)[key$4] + "/" + provider;
2811
2844
  }
2812
2845
  passThroughUrl = new URL(req.url);
2813
2846
  params = new URLSearchParams(passThroughUrl.search);
@@ -2825,17 +2858,17 @@ function _route$6() {
2825
2858
  }
2826
2859
  }, _callee);
2827
2860
  }));
2828
- return _route$6.apply(this, arguments);
2861
+ return _route$7.apply(this, arguments);
2829
2862
  }
2830
- function matches$6(configRoutes, request) {
2831
- return urlMatches(request.url, configRoutes[key$3]);
2863
+ function matches$7(configRoutes, request) {
2864
+ return urlMatches(request.url, configRoutes[key$4]);
2832
2865
  }
2833
2866
 
2834
- function route$5(_x, _x2) {
2835
- return _route$5.apply(this, arguments);
2867
+ function route$6(_x, _x2) {
2868
+ return _route$6.apply(this, arguments);
2836
2869
  }
2837
- function _route$5() {
2838
- _route$5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, config) {
2870
+ function _route$6() {
2871
+ _route$6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, config) {
2839
2872
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2840
2873
  while (1) switch (_context.prev = _context.next) {
2841
2874
  case 0:
@@ -2849,17 +2882,17 @@ function _route$5() {
2849
2882
  }
2850
2883
  }, _callee);
2851
2884
  }));
2852
- return _route$5.apply(this, arguments);
2885
+ return _route$6.apply(this, arguments);
2853
2886
  }
2854
- function matches$5(configRoutes, request) {
2887
+ function matches$6(configRoutes, request) {
2855
2888
  return urlMatches(request.url, configRoutes.SESSION);
2856
2889
  }
2857
2890
 
2858
- function route$4(_x, _x2) {
2859
- return _route$4.apply(this, arguments);
2891
+ function route$5(_x, _x2) {
2892
+ return _route$5.apply(this, arguments);
2860
2893
  }
2861
- function _route$4() {
2862
- _route$4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, config) {
2894
+ function _route$5() {
2895
+ _route$5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, config) {
2863
2896
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2864
2897
  while (1) switch (_context.prev = _context.next) {
2865
2898
  case 0:
@@ -2873,17 +2906,17 @@ function _route$4() {
2873
2906
  }
2874
2907
  }, _callee);
2875
2908
  }));
2876
- return _route$4.apply(this, arguments);
2909
+ return _route$5.apply(this, arguments);
2877
2910
  }
2878
- function matches$4(configRoutes, request) {
2911
+ function matches$5(configRoutes, request) {
2879
2912
  return urlMatches(request.url, configRoutes.PROVIDERS);
2880
2913
  }
2881
2914
 
2882
- function route$3(_x, _x2) {
2883
- return _route$3.apply(this, arguments);
2915
+ function route$4(_x, _x2) {
2916
+ return _route$4.apply(this, arguments);
2884
2917
  }
2885
- function _route$3() {
2886
- _route$3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, config) {
2918
+ function _route$4() {
2919
+ _route$4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, config) {
2887
2920
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2888
2921
  while (1) switch (_context.prev = _context.next) {
2889
2922
  case 0:
@@ -2897,25 +2930,25 @@ function _route$3() {
2897
2930
  }
2898
2931
  }, _callee);
2899
2932
  }));
2900
- return _route$3.apply(this, arguments);
2933
+ return _route$4.apply(this, arguments);
2901
2934
  }
2902
- function matches$3(configRoutes, request) {
2935
+ function matches$4(configRoutes, request) {
2903
2936
  return urlMatches(request.url, configRoutes.CSRF);
2904
2937
  }
2905
2938
 
2906
- var key$2 = 'CALLBACK';
2907
- function route$2(_x, _x2) {
2908
- return _route$2.apply(this, arguments);
2939
+ var key$3 = 'CALLBACK';
2940
+ function route$3(_x, _x2) {
2941
+ return _route$3.apply(this, arguments);
2909
2942
  }
2910
- function _route$2() {
2911
- _route$2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(request$1, config) {
2943
+ function _route$3() {
2944
+ _route$3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(request$1, config) {
2912
2945
  var _Logger, error, _URL$pathname$split$r, provider, passThroughUrl, params, url, res, location;
2913
2946
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2914
2947
  while (1) switch (_context.prev = _context.next) {
2915
2948
  case 0:
2916
2949
  _Logger = Logger(_extends({}, config, {
2917
2950
  debug: config.debug
2918
- }), "[ROUTES][" + key$2 + "]"), error = _Logger.error;
2951
+ }), "[ROUTES][" + key$3 + "]"), error = _Logger.error;
2919
2952
  _URL$pathname$split$r = new URL(request$1.url).pathname.split('/').reverse(), provider = _URL$pathname$split$r[0];
2920
2953
  passThroughUrl = new URL(request$1.url);
2921
2954
  params = new URLSearchParams(passThroughUrl.search);
@@ -2949,30 +2982,30 @@ function _route$2() {
2949
2982
  }
2950
2983
  }, _callee);
2951
2984
  }));
2952
- return _route$2.apply(this, arguments);
2985
+ return _route$3.apply(this, arguments);
2953
2986
  }
2954
- function matches$2(configRoutes, request) {
2987
+ function matches$3(configRoutes, request) {
2955
2988
  return urlMatches(request.url, configRoutes.CALLBACK);
2956
2989
  }
2957
2990
 
2958
- var key$1 = 'SIGNOUT';
2959
- function route$1(_x, _x2) {
2960
- return _route$1.apply(this, arguments);
2991
+ var key$2 = 'SIGNOUT';
2992
+ function route$2(_x, _x2) {
2993
+ return _route$2.apply(this, arguments);
2961
2994
  }
2962
- function _route$1() {
2963
- _route$1 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(request$1, config) {
2995
+ function _route$2() {
2996
+ _route$2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(request$1, config) {
2964
2997
  var url, init, _URL$pathname$split$r, provider, res;
2965
2998
  return _regeneratorRuntime().wrap(function _callee$(_context) {
2966
2999
  while (1) switch (_context.prev = _context.next) {
2967
3000
  case 0:
2968
- url = proxyRoutes(config)[key$1];
3001
+ url = proxyRoutes(config)[key$2];
2969
3002
  init = {
2970
3003
  method: request$1.method
2971
3004
  };
2972
3005
  if (request$1.method === 'POST') {
2973
3006
  init.body = request$1.body;
2974
3007
  _URL$pathname$split$r = new URL(request$1.url).pathname.split('/').reverse(), provider = _URL$pathname$split$r[0];
2975
- url = proxyRoutes(config)[key$1] + "/" + provider;
3008
+ url = proxyRoutes(config)[key$2] + "/" + provider;
2976
3009
  }
2977
3010
  _context.next = 5;
2978
3011
  return request(url, _extends({}, init, {
@@ -2987,22 +3020,22 @@ function _route$1() {
2987
3020
  }
2988
3021
  }, _callee);
2989
3022
  }));
2990
- return _route$1.apply(this, arguments);
3023
+ return _route$2.apply(this, arguments);
2991
3024
  }
2992
- function matches$1(configRoutes, request) {
2993
- return urlMatches(request.url, configRoutes[key$1]);
3025
+ function matches$2(configRoutes, request) {
3026
+ return urlMatches(request.url, configRoutes[key$2]);
2994
3027
  }
2995
3028
 
2996
- var key = 'ERROR';
2997
- function route(_x, _x2) {
2998
- return _route.apply(this, arguments);
3029
+ var key$1 = 'ERROR';
3030
+ function route$1(_x, _x2) {
3031
+ return _route$1.apply(this, arguments);
2999
3032
  }
3000
- function _route() {
3001
- _route = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, config) {
3033
+ function _route$1() {
3034
+ _route$1 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, config) {
3002
3035
  return _regeneratorRuntime().wrap(function _callee$(_context) {
3003
3036
  while (1) switch (_context.prev = _context.next) {
3004
3037
  case 0:
3005
- return _context.abrupt("return", request(proxyRoutes(config)[key], {
3038
+ return _context.abrupt("return", request(proxyRoutes(config)[key$1], {
3006
3039
  method: req.method,
3007
3040
  request: req
3008
3041
  }, config));
@@ -3012,10 +3045,10 @@ function _route() {
3012
3045
  }
3013
3046
  }, _callee);
3014
3047
  }));
3015
- return _route.apply(this, arguments);
3048
+ return _route$1.apply(this, arguments);
3016
3049
  }
3017
- function matches(configRoutes, request) {
3018
- return urlMatches(request.url, configRoutes[key]);
3050
+ function matches$1(configRoutes, request) {
3051
+ return urlMatches(request.url, configRoutes[key$1]);
3019
3052
  }
3020
3053
 
3021
3054
  function GETTER(configRoutes, config) {
@@ -3027,82 +3060,82 @@ function GETTER(configRoutes, config) {
3027
3060
  return _regeneratorRuntime().wrap(function _callee$(_context) {
3028
3061
  while (1) switch (_context.prev = _context.next) {
3029
3062
  case 0:
3030
- if (!matches$a(configRoutes, req)) {
3063
+ if (!matches$b(configRoutes, req)) {
3031
3064
  _context.next = 3;
3032
3065
  break;
3033
3066
  }
3034
3067
  info('matches me');
3035
- return _context.abrupt("return", route$a(req, config));
3068
+ return _context.abrupt("return", route$b(req, config));
3036
3069
  case 3:
3037
- if (!matches$8(configRoutes, req)) {
3070
+ if (!matches$9(configRoutes, req)) {
3038
3071
  _context.next = 6;
3039
3072
  break;
3040
3073
  }
3041
3074
  info('matches tenant users');
3042
- return _context.abrupt("return", route$8(req, config));
3075
+ return _context.abrupt("return", route$9(req, config));
3043
3076
  case 6:
3044
- if (!matches$9(configRoutes, req)) {
3077
+ if (!matches$a(configRoutes, req)) {
3045
3078
  _context.next = 9;
3046
3079
  break;
3047
3080
  }
3048
3081
  info('matches users');
3049
- return _context.abrupt("return", route$9(req, config));
3082
+ return _context.abrupt("return", route$a(req, config));
3050
3083
  case 9:
3051
- if (!matches$7(configRoutes, req)) {
3084
+ if (!matches$8(configRoutes, req)) {
3052
3085
  _context.next = 12;
3053
3086
  break;
3054
3087
  }
3055
3088
  info('matches tenants');
3056
- return _context.abrupt("return", route$7(req, config));
3089
+ return _context.abrupt("return", route$8(req, config));
3057
3090
  case 12:
3058
- if (!matches$5(configRoutes, req)) {
3091
+ if (!matches$6(configRoutes, req)) {
3059
3092
  _context.next = 15;
3060
3093
  break;
3061
3094
  }
3062
3095
  info('matches session');
3063
- return _context.abrupt("return", route$5(req, config));
3096
+ return _context.abrupt("return", route$6(req, config));
3064
3097
  case 15:
3065
- if (!matches$6(configRoutes, req)) {
3098
+ if (!matches$7(configRoutes, req)) {
3066
3099
  _context.next = 18;
3067
3100
  break;
3068
3101
  }
3069
3102
  info('matches signin');
3070
- return _context.abrupt("return", route$6(req, config));
3103
+ return _context.abrupt("return", route$7(req, config));
3071
3104
  case 18:
3072
- if (!matches$4(configRoutes, req)) {
3105
+ if (!matches$5(configRoutes, req)) {
3073
3106
  _context.next = 21;
3074
3107
  break;
3075
3108
  }
3076
3109
  info('matches providers');
3077
- return _context.abrupt("return", route$4(req, config));
3110
+ return _context.abrupt("return", route$5(req, config));
3078
3111
  case 21:
3079
- if (!matches$3(configRoutes, req)) {
3112
+ if (!matches$4(configRoutes, req)) {
3080
3113
  _context.next = 24;
3081
3114
  break;
3082
3115
  }
3083
3116
  info('matches csrf');
3084
- return _context.abrupt("return", route$3(req, config));
3117
+ return _context.abrupt("return", route$4(req, config));
3085
3118
  case 24:
3086
- if (!matches$2(configRoutes, req)) {
3119
+ if (!matches$3(configRoutes, req)) {
3087
3120
  _context.next = 27;
3088
3121
  break;
3089
3122
  }
3090
3123
  info('matches callback');
3091
- return _context.abrupt("return", route$2(req, config));
3124
+ return _context.abrupt("return", route$3(req, config));
3092
3125
  case 27:
3093
- if (!matches$1(configRoutes, req)) {
3126
+ if (!matches$2(configRoutes, req)) {
3094
3127
  _context.next = 30;
3095
3128
  break;
3096
3129
  }
3097
3130
  info('matches signout');
3098
- return _context.abrupt("return", route$1(req, config));
3131
+ return _context.abrupt("return", route$2(req, config));
3099
3132
  case 30:
3100
- if (!matches(configRoutes, req)) {
3133
+ if (!matches$1(configRoutes, req)) {
3101
3134
  _context.next = 33;
3102
3135
  break;
3103
3136
  }
3104
3137
  info('matches error');
3105
- return _context.abrupt("return", route(req, config));
3138
+ return _context.abrupt("return", route$1(req, config));
3106
3139
  case 33:
3107
3140
  warn('No GET routes matched');
3108
3141
  return _context.abrupt("return", new Response(null, {
@@ -3121,83 +3154,212 @@ function GETTER(configRoutes, config) {
3121
3154
  }();
3122
3155
  }
3123
3156
 
3124
- function POSTER(configRoutes, config) {
3125
- var _Logger = Logger(config, '[POST MATCHER]'),
3126
- info = _Logger.info,
3127
- warn = _Logger.warn;
3128
- return /*#__PURE__*/function () {
3129
- var _POST = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
3130
- return _regeneratorRuntime().wrap(function _callee$(_context) {
3131
- while (1) switch (_context.prev = _context.next) {
3132
- case 0:
3133
- if (!matches$8(configRoutes, req)) {
3134
- _context.next = 3;
3135
- break;
3136
- }
3137
- info('matches tenant users');
3138
- return _context.abrupt("return", route$8(req, config));
3139
- case 3:
3140
- if (!matches$9(configRoutes, req)) {
3141
- _context.next = 6;
3142
- break;
3143
- }
3144
- info('matches users');
3145
- return _context.abrupt("return", route$9(req, config));
3146
- case 6:
3147
- if (!matches$7(configRoutes, req)) {
3148
- _context.next = 9;
3149
- break;
3150
- }
3151
- info('matches tenants');
3152
- return _context.abrupt("return", route$7(req, config));
3153
- case 9:
3154
- if (!matches$5(configRoutes, req)) {
3155
- _context.next = 12;
3156
- break;
3157
- }
3158
- info('matches session');
3159
- return _context.abrupt("return", route$5(req, config));
3160
- case 12:
3161
- if (!matches$6(configRoutes, req)) {
3162
- _context.next = 15;
3163
- break;
3164
- }
3165
- info('matches signin');
3166
- return _context.abrupt("return", route$6(req, config));
3167
- case 15:
3168
- if (!matches$4(configRoutes, req)) {
3169
- _context.next = 18;
3170
- break;
3171
- }
3172
- info('matches providers');
3173
- return _context.abrupt("return", route$4(req, config));
3174
- case 18:
3175
- if (!matches$3(configRoutes, req)) {
3176
- _context.next = 21;
3177
- break;
3157
+ /**
3158
+ * @swagger
3159
+ * /api/signup:
3160
+ * post:
3161
+ * tags:
3162
+ * - users
3163
+ * summary: signs a user up
3164
+ * description: signs a user up and logs them in. Expects a email and password combo
3165
+ * operationId: signUp
3166
+ * parameters:
3167
+ * - name: tenantId
3168
+ * description: A tenant id to add the user to when they are created
3169
+ * in: query
3170
+ * schema:
3171
+ * type: string
3172
+ * - name: newTenantName
3173
+ * description: A tenant name to create, then the user to when they are created
3174
+ * in: query
3175
+ * schema:
3176
+ * type: string
3177
+ * requestBody:
3178
+ * description: |-
3179
+ * The email and password combination the user will use to authenticate.
3180
+ * The `name` is optional; if provided it will be recorded in the `users` table.
3181
+ * The `newTenant` is optional; if provided, it is used as the name of a new tenant record associated with the newly created user.
3182
+ * content:
3183
+ * application/json:
3184
+ * schema:
3185
+ * $ref: '#/components/schemas/CreateBasicUserRequest'
3186
+ * examples:
3187
+ * Create User Request:
3188
+ * summary: Creates a user with basic credentials
3189
+ * description: Create User Request
3190
+ * value:
3191
+ * email: a.user@somedomain.com
3192
+ * password: somepassword
3193
+ * name: A. User
3194
+ * Create User Request with Tenant:
3195
+ * summary: Creates a user and a new tenant for that user
3196
+ * description: Create User Request with Tenant
3197
+ * value:
3198
+ * email: a.user@somedomain.com
3199
+ * password: somepassword
3200
+ * name: A. User
3201
+ * newTenant: My Sandbox
3202
+ * responses:
3203
+ * "201":
3204
+ * description: User and session created
3205
+ * content:
3206
+ * application/json:
3207
+ * schema:
3208
+ * $ref: "#/components/schemas/User"
3209
+ * "400":
3210
+ * description: API/Database failures
3211
+ * content:
3212
+ * text/plain:
3213
+ * schema:
3214
+ * type: string
3215
+ * "401":
3216
+ * description: Unauthorized
3217
+ * content: {}
3218
+ */
3219
+ function POST(_x, _x2) {
3220
+ return _POST.apply(this, arguments);
3221
+ }
3222
+ function _POST() {
3223
+ _POST = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, init) {
3224
+ var url;
3225
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
3226
+ while (1) switch (_context.prev = _context.next) {
3227
+ case 0:
3228
+ init.body = init.request.body;
3229
+ init.method = 'POST';
3230
+ url = "" + apiRoutes(config).SIGNUP;
3231
+ _context.next = 5;
3232
+ return request(url, init, config);
3233
+ case 5:
3234
+ return _context.abrupt("return", _context.sent);
3235
+ case 6:
3236
+ case "end":
3237
+ return _context.stop();
3238
+ }
3239
+ }, _callee);
3240
+ }));
3241
+ return _POST.apply(this, arguments);
3242
+ }
3243
+
3244
+ var key = 'SIGNUP';
3245
+ function route(_x, _x2) {
3246
+ return _route.apply(this, arguments);
3247
+ }
3248
+ function _route() {
3249
+ _route = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(request, config) {
3250
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
3251
+ while (1) switch (_context.prev = _context.next) {
3252
+ case 0:
3253
+ _context.t0 = request.method;
3254
+ _context.next = _context.t0 === 'POST' ? 3 : 6;
3255
+ break;
3256
+ case 3:
3257
+ _context.next = 5;
3258
+ return POST(config, {
3259
+ request: request
3260
+ });
3261
+ case 5:
3262
+ return _context.abrupt("return", _context.sent);
3263
+ case 6:
3264
+ return _context.abrupt("return", new Response('method not allowed', {
3265
+ status: 405
3266
+ }));
3267
+ case 7:
3268
+ case "end":
3269
+ return _context.stop();
3270
+ }
3271
+ }, _callee);
3272
+ }));
3273
+ return _route.apply(this, arguments);
3274
+ }
3275
+ function matches(configRoutes, request) {
3276
+ return urlMatches(request.url, configRoutes[key]);
3277
+ }
3278
+
3279
+ function POSTER(configRoutes, config) {
3280
+ var _Logger = Logger(config, '[POST MATCHER]'),
3281
+ info = _Logger.info,
3282
+ warn = _Logger.warn;
3283
+ return /*#__PURE__*/function () {
3284
+ var _POST = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
3285
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
3286
+ while (1) switch (_context.prev = _context.next) {
3287
+ case 0:
3288
+ if (!matches$9(configRoutes, req)) {
3289
+ _context.next = 3;
3290
+ break;
3178
3291
  }
3179
- info('matches csrf');
3180
- return _context.abrupt("return", route$3(req, config));
3292
+ info('matches tenant users');
3293
+ return _context.abrupt("return", route$9(req, config));
3294
+ case 3:
3295
+ if (!matches(configRoutes, req)) {
3296
+ _context.next = 6;
3297
+ break;
3298
+ }
3299
+ info('matches signup');
3300
+ return _context.abrupt("return", route(req, config));
3301
+ case 6:
3302
+ if (!matches$a(configRoutes, req)) {
3303
+ _context.next = 9;
3304
+ break;
3305
+ }
3306
+ info('matches users');
3307
+ return _context.abrupt("return", route$a(req, config));
3308
+ case 9:
3309
+ if (!matches$8(configRoutes, req)) {
3310
+ _context.next = 12;
3311
+ break;
3312
+ }
3313
+ info('matches tenants');
3314
+ return _context.abrupt("return", route$8(req, config));
3315
+ case 12:
3316
+ if (!matches$6(configRoutes, req)) {
3317
+ _context.next = 15;
3318
+ break;
3319
+ }
3320
+ info('matches session');
3321
+ return _context.abrupt("return", route$6(req, config));
3322
+ case 15:
3323
+ if (!matches$7(configRoutes, req)) {
3324
+ _context.next = 18;
3325
+ break;
3326
+ }
3327
+ info('matches signin');
3328
+ return _context.abrupt("return", route$7(req, config));
3329
+ case 18:
3330
+ if (!matches$5(configRoutes, req)) {
3331
+ _context.next = 21;
3332
+ break;
3333
+ }
3334
+ info('matches providers');
3335
+ return _context.abrupt("return", route$5(req, config));
3181
3336
  case 21:
3182
- if (!matches$2(configRoutes, req)) {
3337
+ if (!matches$4(configRoutes, req)) {
3183
3338
  _context.next = 24;
3184
3339
  break;
3185
3340
  }
3186
- info('matches callback');
3187
- return _context.abrupt("return", route$2(req, config));
3341
+ info('matches csrf');
3342
+ return _context.abrupt("return", route$4(req, config));
3188
3343
  case 24:
3189
- if (!matches$1(configRoutes, req)) {
3344
+ if (!matches$3(configRoutes, req)) {
3190
3345
  _context.next = 27;
3191
3346
  break;
3192
3347
  }
3193
- info('matches signout');
3194
- return _context.abrupt("return", route$1(req, config));
3348
+ info('matches callback');
3349
+ return _context.abrupt("return", route$3(req, config));
3195
3350
  case 27:
3351
+ if (!matches$2(configRoutes, req)) {
3352
+ _context.next = 30;
3353
+ break;
3354
+ }
3355
+ info('matches signout');
3356
+ return _context.abrupt("return", route$2(req, config));
3357
+ case 30:
3196
3358
  warn('No POST routes matched');
3197
3359
  return _context.abrupt("return", new Response(null, {
3198
3360
  status: 404
3199
3361
  }));
3200
- case 29:
3362
+ case 32:
3201
3363
  case "end":
3202
3364
  return _context.stop();
3203
3365
  }
@@ -3219,19 +3381,19 @@ function DELETER(configRoutes, config) {
3219
3381
  return _regeneratorRuntime().wrap(function _callee$(_context) {
3220
3382
  while (1) switch (_context.prev = _context.next) {
3221
3383
  case 0:
3222
- if (!matches$8(configRoutes, req)) {
3384
+ if (!matches$9(configRoutes, req)) {
3223
3385
  _context.next = 3;
3224
3386
  break;
3225
3387
  }
3226
3388
  info('matches tenant users');
3227
- return _context.abrupt("return", route$8(req, config));
3389
+ return _context.abrupt("return", route$9(req, config));
3228
3390
  case 3:
3229
- if (!matches$7(configRoutes, req)) {
3391
+ if (!matches$8(configRoutes, req)) {
3230
3392
  _context.next = 6;
3231
3393
  break;
3232
3394
  }
3233
3395
  info('matches tenants');
3234
- return _context.abrupt("return", route$7(req, config));
3396
+ return _context.abrupt("return", route$8(req, config));
3235
3397
  case 6:
3236
3398
  warn('No DELETE routes matched');
3237
3399
  return _context.abrupt("return", new Response(null, {
@@ -3259,26 +3421,26 @@ function PUTER(configRoutes, config) {
3259
3421
  return _regeneratorRuntime().wrap(function _callee$(_context) {
3260
3422
  while (1) switch (_context.prev = _context.next) {
3261
3423
  case 0:
3262
- if (!matches$8(configRoutes, req)) {
3424
+ if (!matches$9(configRoutes, req)) {
3263
3425
  _context.next = 3;
3264
3426
  break;
3265
3427
  }
3266
3428
  info('matches tenant users');
3267
- return _context.abrupt("return", route$8(req, config));
3429
+ return _context.abrupt("return", route$9(req, config));
3268
3430
  case 3:
3269
- if (!matches$9(configRoutes, req)) {
3431
+ if (!matches$a(configRoutes, req)) {
3270
3432
  _context.next = 6;
3271
3433
  break;
3272
3434
  }
3273
3435
  info('matches users');
3274
- return _context.abrupt("return", route$9(req, config));
3436
+ return _context.abrupt("return", route$a(req, config));
3275
3437
  case 6:
3276
- if (!matches$7(configRoutes, req)) {
3438
+ if (!matches$8(configRoutes, req)) {
3277
3439
  _context.next = 9;
3278
3440
  break;
3279
3441
  }
3280
3442
  info('matches tenants');
3281
- return _context.abrupt("return", route$7(req, config));
3443
+ return _context.abrupt("return", route$8(req, config));
3282
3444
  case 9:
3283
3445
  warn('No PUT routes matched');
3284
3446
  return _context.abrupt("return", new Response(null, {
@@ -3459,7 +3621,7 @@ var Requester = /*#__PURE__*/function (_Config) {
3459
3621
  }();
3460
3622
  _proto.post = /*#__PURE__*/function () {
3461
3623
  var _post = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(req, url, init) {
3462
- var response;
3624
+ var response, cloned;
3463
3625
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
3464
3626
  while (1) switch (_context3.prev = _context3.next) {
3465
3627
  case 0:
@@ -3468,17 +3630,25 @@ var Requester = /*#__PURE__*/function (_Config) {
3468
3630
  case 2:
3469
3631
  response = _context3.sent;
3470
3632
  if (!(response && response.status >= 200 && response.status < 300)) {
3471
- _context3.next = 5;
3633
+ _context3.next = 13;
3472
3634
  break;
3473
3635
  }
3474
- return _context3.abrupt("return", response.json());
3475
- case 5:
3636
+ cloned = response.clone();
3637
+ _context3.prev = 5;
3638
+ _context3.next = 8;
3639
+ return cloned.json();
3640
+ case 8:
3641
+ return _context3.abrupt("return", _context3.sent);
3642
+ case 11:
3643
+ _context3.prev = 11;
3644
+ _context3.t0 = _context3["catch"](5);
3645
+ case 13:
3476
3646
  return _context3.abrupt("return", response);
3477
- case 6:
3647
+ case 14:
3478
3648
  case "end":
3479
3649
  return _context3.stop();
3480
3650
  }
3481
- }, _callee3, this);
3651
+ }, _callee3, this, [[5, 11]]);
3482
3652
  }));
3483
3653
  function post(_x9, _x10, _x11) {
3484
3654
  return _post.apply(this, arguments);
@@ -3487,7 +3657,7 @@ var Requester = /*#__PURE__*/function (_Config) {
3487
3657
  }();
3488
3658
  _proto.get = /*#__PURE__*/function () {
3489
3659
  var _get = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(req, url, init) {
3490
- var response;
3660
+ var response, cloned;
3491
3661
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
3492
3662
  while (1) switch (_context4.prev = _context4.next) {
3493
3663
  case 0:
@@ -3496,17 +3666,25 @@ var Requester = /*#__PURE__*/function (_Config) {
3496
3666
  case 2:
3497
3667
  response = _context4.sent;
3498
3668
  if (!(response && response.status >= 200 && response.status < 300)) {
3499
- _context4.next = 5;
3669
+ _context4.next = 13;
3500
3670
  break;
3501
3671
  }
3502
- return _context4.abrupt("return", response.json());
3503
- case 5:
3672
+ cloned = response.clone();
3673
+ _context4.prev = 5;
3674
+ _context4.next = 8;
3675
+ return cloned.json();
3676
+ case 8:
3677
+ return _context4.abrupt("return", _context4.sent);
3678
+ case 11:
3679
+ _context4.prev = 11;
3680
+ _context4.t0 = _context4["catch"](5);
3681
+ case 13:
3504
3682
  return _context4.abrupt("return", response);
3505
- case 6:
3683
+ case 14:
3506
3684
  case "end":
3507
3685
  return _context4.stop();
3508
3686
  }
3509
- }, _callee4, this);
3687
+ }, _callee4, this, [[5, 11]]);
3510
3688
  }));
3511
3689
  function get(_x12, _x13, _x14) {
3512
3690
  return _get.apply(this, arguments);
@@ -3515,7 +3693,7 @@ var Requester = /*#__PURE__*/function (_Config) {
3515
3693
  }();
3516
3694
  _proto.put = /*#__PURE__*/function () {
3517
3695
  var _put = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(req, url, init) {
3518
- var response;
3696
+ var response, cloned;
3519
3697
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
3520
3698
  while (1) switch (_context5.prev = _context5.next) {
3521
3699
  case 0:
@@ -3524,17 +3702,25 @@ var Requester = /*#__PURE__*/function (_Config) {
3524
3702
  case 2:
3525
3703
  response = _context5.sent;
3526
3704
  if (!(response && response.status >= 200 && response.status < 300)) {
3527
- _context5.next = 5;
3705
+ _context5.next = 13;
3528
3706
  break;
3529
3707
  }
3530
- return _context5.abrupt("return", response.json());
3531
- case 5:
3708
+ cloned = response.clone();
3709
+ _context5.prev = 5;
3710
+ _context5.next = 8;
3711
+ return cloned.json();
3712
+ case 8:
3713
+ return _context5.abrupt("return", _context5.sent);
3714
+ case 11:
3715
+ _context5.prev = 11;
3716
+ _context5.t0 = _context5["catch"](5);
3717
+ case 13:
3532
3718
  return _context5.abrupt("return", response);
3533
- case 6:
3719
+ case 14:
3534
3720
  case "end":
3535
3721
  return _context5.stop();
3536
3722
  }
3537
- }, _callee5, this);
3723
+ }, _callee5, this, [[5, 11]]);
3538
3724
  }));
3539
3725
  function put(_x15, _x16, _x17) {
3540
3726
  return _put.apply(this, arguments);
@@ -3551,14 +3737,8 @@ var Requester = /*#__PURE__*/function (_Config) {
3551
3737
  return this.request('DELETE', url, req, init);
3552
3738
  case 2:
3553
3739
  response = _context6.sent;
3554
- if (!(response && response.status >= 200 && response.status < 300)) {
3555
- _context6.next = 5;
3556
- break;
3557
- }
3558
- return _context6.abrupt("return", response.json());
3559
- case 5:
3560
3740
  return _context6.abrupt("return", response);
3561
- case 6:
3741
+ case 4:
3562
3742
  case "end":
3563
3743
  return _context6.stop();
3564
3744
  }
@@ -3874,6 +4054,55 @@ var Tenants = /*#__PURE__*/function (_Config) {
3874
4054
  return _ref3.apply(this, arguments);
3875
4055
  };
3876
4056
  }();
4057
+ _this.deleteTenant = /*#__PURE__*/function () {
4058
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(req, init) {
4059
+ var _requester, _init;
4060
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
4061
+ while (1) switch (_context4.prev = _context4.next) {
4062
+ case 0:
4063
+ if (typeof req === 'string') {
4064
+ _this.tenantId = req;
4065
+ }
4066
+ _requester = new Requester(_this);
4067
+ _init = _this.handleHeaders(init);
4068
+ return _context4.abrupt("return", _requester["delete"](req, _this.tenantUrl, _init));
4069
+ case 4:
4070
+ case "end":
4071
+ return _context4.stop();
4072
+ }
4073
+ }, _callee4);
4074
+ }));
4075
+ return function (_x7, _x8) {
4076
+ return _ref4.apply(this, arguments);
4077
+ };
4078
+ }();
4079
+ _this.updateTenant = /*#__PURE__*/function () {
4080
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(req, init) {
4081
+ var _req, _requester, _init;
4082
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
4083
+ while (1) switch (_context5.prev = _context5.next) {
4084
+ case 0:
4085
+ if (req && 'name' in req) {
4086
+ _req = new Request("" + _this.api.basePath + _this.tenantUrl, {
4087
+ body: JSON.stringify(req),
4088
+ method: 'PUT'
4089
+ });
4090
+ } else {
4091
+ _req = req;
4092
+ }
4093
+ _requester = new Requester(_this);
4094
+ _init = _this.handleHeaders(init);
4095
+ return _context5.abrupt("return", _requester.put(_req, _this.tenantUrl, _init));
4096
+ case 4:
4097
+ case "end":
4098
+ return _context5.stop();
4099
+ }
4100
+ }, _callee5);
4101
+ }));
4102
+ return function (_x9, _x10) {
4103
+ return _ref5.apply(this, arguments);
4104
+ };
4105
+ }();
3877
4106
  _this.headers = headers;
3878
4107
  return _this;
3879
4108
  }
@@ -3941,8 +4170,8 @@ var Users = /*#__PURE__*/function (_Config) {
3941
4170
  return _ref.apply(this, arguments);
3942
4171
  };
3943
4172
  }();
3944
- _this.updateUser = /*#__PURE__*/function () {
3945
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(userId, req, init) {
4173
+ _this.createTenantUser = /*#__PURE__*/function () {
4174
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(req, init) {
3946
4175
  var _requester, _init;
3947
4176
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
3948
4177
  while (1) switch (_context2.prev = _context2.next) {
@@ -3950,7 +4179,7 @@ var Users = /*#__PURE__*/function (_Config) {
3950
4179
  _requester = new Requester(_this);
3951
4180
  _init = _this.handleHeaders(init);
3952
4181
  _context2.next = 4;
3953
- return _requester.put(req, _this.usersUrl + "/" + userId, _init);
4182
+ return _requester.post(req, _this.tenantUsersUrl, _init);
3954
4183
  case 4:
3955
4184
  return _context2.abrupt("return", _context2.sent);
3956
4185
  case 5:
@@ -3959,33 +4188,42 @@ var Users = /*#__PURE__*/function (_Config) {
3959
4188
  }
3960
4189
  }, _callee2);
3961
4190
  }));
3962
- return function (_x3, _x4, _x5) {
4191
+ return function (_x3, _x4) {
3963
4192
  return _ref2.apply(this, arguments);
3964
4193
  };
3965
4194
  }();
3966
- _this.listUsers = /*#__PURE__*/function () {
4195
+ _this.updateUser = /*#__PURE__*/function () {
3967
4196
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(req, init) {
3968
- var _requester, _init;
4197
+ var _req, _requester, _init;
3969
4198
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
3970
4199
  while (1) switch (_context3.prev = _context3.next) {
3971
4200
  case 0:
4201
+ if (req && 'id' in req) {
4202
+ _req = new Request("" + _this.api.basePath + _this.tenantUserUrl, {
4203
+ body: JSON.stringify(req),
4204
+ method: 'PUT'
4205
+ });
4206
+ _this.userId = String(req.id);
4207
+ } else {
4208
+ _req = req;
4209
+ }
3972
4210
  _requester = new Requester(_this);
3973
4211
  _init = _this.handleHeaders(init);
3974
- _context3.next = 4;
3975
- return _requester.get(req, _this.tenantUsersUrl, _init);
3976
- case 4:
3977
- return _context3.abrupt("return", _context3.sent);
4212
+ _context3.next = 5;
4213
+ return _requester.put(_req, _this.tenantUserUrl, _init);
3978
4214
  case 5:
4215
+ return _context3.abrupt("return", _context3.sent);
4216
+ case 6:
3979
4217
  case "end":
3980
4218
  return _context3.stop();
3981
4219
  }
3982
4220
  }, _callee3);
3983
4221
  }));
3984
- return function (_x6, _x7) {
4222
+ return function (_x5, _x6) {
3985
4223
  return _ref3.apply(this, arguments);
3986
4224
  };
3987
4225
  }();
3988
- _this.linkUser = /*#__PURE__*/function () {
4226
+ _this.listUsers = /*#__PURE__*/function () {
3989
4227
  var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(req, init) {
3990
4228
  var _requester, _init;
3991
4229
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
@@ -3994,7 +4232,7 @@ var Users = /*#__PURE__*/function (_Config) {
3994
4232
  _requester = new Requester(_this);
3995
4233
  _init = _this.handleHeaders(init);
3996
4234
  _context4.next = 4;
3997
- return _requester.put(req, _this.tenantUsersUrl, _init);
4235
+ return _requester.get(req, _this.tenantUsersUrl, _init);
3998
4236
  case 4:
3999
4237
  return _context4.abrupt("return", _context4.sent);
4000
4238
  case 5:
@@ -4003,68 +4241,65 @@ var Users = /*#__PURE__*/function (_Config) {
4003
4241
  }
4004
4242
  }, _callee4);
4005
4243
  }));
4006
- return function (_x8, _x9) {
4244
+ return function (_x7, _x8) {
4007
4245
  return _ref4.apply(this, arguments);
4008
4246
  };
4009
4247
  }();
4010
- _this.tenantUsersDeleteUrl = function (userId) {
4011
- var _this$tenantId;
4012
- return "/tenants/" + ((_this$tenantId = _this.tenantId) != null ? _this$tenantId : '{tenantId}') + "/users/" + (userId != null ? userId : '{userId}');
4013
- };
4014
- _this.getUserId = /*#__PURE__*/function () {
4015
- var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(req) {
4016
- var body;
4248
+ _this.linkUser = /*#__PURE__*/function () {
4249
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(req, init) {
4250
+ var _requester, _init;
4017
4251
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
4018
4252
  while (1) switch (_context5.prev = _context5.next) {
4019
4253
  case 0:
4020
- if (!(req instanceof Request)) {
4021
- _context5.next = 6;
4022
- break;
4023
- }
4024
- _context5.next = 3;
4025
- return new Response(req == null ? void 0 : req.body).json();
4026
- case 3:
4027
- body = _context5.sent;
4028
- if (!body) {
4029
- _context5.next = 6;
4030
- break;
4254
+ _requester = new Requester(_this);
4255
+ if (typeof req === 'string') {
4256
+ _this.userId = req;
4257
+ } else {
4258
+ if ('id' in req) {
4259
+ _this.userId = req.id;
4260
+ }
4261
+ if ('tenantId' in req) {
4262
+ _this.tenantId = req.tenantId;
4263
+ }
4031
4264
  }
4032
- return _context5.abrupt("return", body.id);
4265
+ _init = _this.handleHeaders(init);
4266
+ _context5.next = 5;
4267
+ return _requester.put(req, _this.linkUsersUrl, _init);
4268
+ case 5:
4269
+ return _context5.abrupt("return", _context5.sent);
4033
4270
  case 6:
4034
- if (!('id' in req)) {
4035
- _context5.next = 8;
4036
- break;
4037
- }
4038
- return _context5.abrupt("return", req.id);
4039
- case 8:
4040
- return _context5.abrupt("return", null);
4041
- case 9:
4042
4271
  case "end":
4043
4272
  return _context5.stop();
4044
4273
  }
4045
4274
  }, _callee5);
4046
4275
  }));
4047
- return function (_x10) {
4276
+ return function (_x9, _x10) {
4048
4277
  return _ref5.apply(this, arguments);
4049
4278
  };
4050
4279
  }();
4051
4280
  _this.unlinkUser = /*#__PURE__*/function () {
4052
4281
  var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(req, init) {
4053
- var _requester, userId, _init;
4282
+ var _requester, _init;
4054
4283
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
4055
4284
  while (1) switch (_context6.prev = _context6.next) {
4056
4285
  case 0:
4286
+ if (typeof req === 'string') {
4287
+ _this.userId = req;
4288
+ } else {
4289
+ if ('id' in req) {
4290
+ _this.userId = req.id;
4291
+ }
4292
+ if ('tenantId' in req) {
4293
+ _this.tenantId = req.tenantId;
4294
+ }
4295
+ }
4057
4296
  _requester = new Requester(_this);
4058
- _context6.next = 3;
4059
- return _this.getUserId(req);
4060
- case 3:
4061
- userId = _context6.sent;
4062
4297
  _init = _this.handleHeaders(init);
4063
- _context6.next = 7;
4064
- return _requester["delete"](req, _this.tenantUsersDeleteUrl(userId), _init);
4065
- case 7:
4298
+ _context6.next = 5;
4299
+ return _requester["delete"](req, _this.linkUsersUrl, _init);
4300
+ case 5:
4066
4301
  return _context6.abrupt("return", _context6.sent);
4067
- case 8:
4302
+ case 6:
4068
4303
  case "end":
4069
4304
  return _context6.stop();
4070
4305
  }
@@ -4096,6 +4331,28 @@ var Users = /*#__PURE__*/function (_Config) {
4096
4331
  return _ref7.apply(this, arguments);
4097
4332
  };
4098
4333
  }();
4334
+ _this.updateMe = /*#__PURE__*/function () {
4335
+ var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(req, init) {
4336
+ var _requester, _init;
4337
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
4338
+ while (1) switch (_context8.prev = _context8.next) {
4339
+ case 0:
4340
+ _requester = new Requester(_this);
4341
+ _init = _this.handleHeaders(init);
4342
+ _context8.next = 4;
4343
+ return _requester.put(req, _this.meUrl, _init);
4344
+ case 4:
4345
+ return _context8.abrupt("return", _context8.sent);
4346
+ case 5:
4347
+ case "end":
4348
+ return _context8.stop();
4349
+ }
4350
+ }, _callee8);
4351
+ }));
4352
+ return function (_x15, _x16) {
4353
+ return _ref8.apply(this, arguments);
4354
+ };
4355
+ }();
4099
4356
  _this.headers = headers;
4100
4357
  return _this;
4101
4358
  }
@@ -4124,8 +4381,20 @@ var Users = /*#__PURE__*/function (_Config) {
4124
4381
  }, {
4125
4382
  key: "tenantUsersUrl",
4126
4383
  get: function get() {
4127
- var _this$tenantId2;
4128
- return "/tenants/" + ((_this$tenantId2 = this.tenantId) != null ? _this$tenantId2 : '{tenantId}') + "/users";
4384
+ var _this$tenantId;
4385
+ return "/tenants/" + ((_this$tenantId = this.tenantId) != null ? _this$tenantId : '{tenantId}') + "/users";
4386
+ }
4387
+ }, {
4388
+ key: "linkUsersUrl",
4389
+ get: function get() {
4390
+ var _this$tenantId2, _this$userId;
4391
+ return "/tenants/" + ((_this$tenantId2 = this.tenantId) != null ? _this$tenantId2 : '{tenantId}') + "/users/" + ((_this$userId = this.userId) != null ? _this$userId : '{userId}') + "/link";
4392
+ }
4393
+ }, {
4394
+ key: "tenantUserUrl",
4395
+ get: function get() {
4396
+ var _this$tenantId3, _this$userId2;
4397
+ return "/tenants/" + ((_this$tenantId3 = this.tenantId) != null ? _this$tenantId3 : '{tenantId}') + "/users/" + ((_this$userId2 = this.userId) != null ? _this$userId2 : '{userId}');
4129
4398
  }
4130
4399
  }, {
4131
4400
  key: "meUrl",