@niledatabase/server 5.0.0-alpha.5 → 5.0.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,14 @@
1
1
  import pg, { PoolConfig, PoolClient } from 'pg';
2
2
 
3
+ type LogFunction = (message: string | unknown, meta?: Record<string, unknown>) => void;
4
+ type Loggable = {
5
+ info: LogFunction;
6
+ debug: LogFunction;
7
+ warn: LogFunction;
8
+ error: LogFunction;
9
+ };
10
+ type LogReturn = (prefixes?: string | string[]) => Loggable;
11
+
3
12
  type ExtensionCtx = {
4
13
  handleOnRequest: (config: Config, _init: RequestInit & {
5
14
  request: Request;
@@ -24,7 +33,7 @@ declare class Config {
24
33
  };
25
34
  extensionCtx: ExtensionCtx;
26
35
  extensions?: Extension[];
27
- logger: LoggerType;
36
+ logger: LogReturn;
28
37
  /**
29
38
  * Stores the set tenant id from Server for use in sub classes
30
39
  */
@@ -433,7 +442,7 @@ type NileConfig = {
433
442
  /**
434
443
  * Some kind of logger if you want to send to an external service
435
444
  */
436
- logger?: LoggerType;
445
+ logger?: LogReturn;
437
446
  /**
438
447
  * The configuration value that maps to `NILEDB_API_URL` - its going to be nile-auth (or similar service)
439
448
  */
package/dist/index.d.ts CHANGED
@@ -1,5 +1,14 @@
1
1
  import pg, { PoolConfig, PoolClient } from 'pg';
2
2
 
3
+ type LogFunction = (message: string | unknown, meta?: Record<string, unknown>) => void;
4
+ type Loggable = {
5
+ info: LogFunction;
6
+ debug: LogFunction;
7
+ warn: LogFunction;
8
+ error: LogFunction;
9
+ };
10
+ type LogReturn = (prefixes?: string | string[]) => Loggable;
11
+
3
12
  type ExtensionCtx = {
4
13
  handleOnRequest: (config: Config, _init: RequestInit & {
5
14
  request: Request;
@@ -24,7 +33,7 @@ declare class Config {
24
33
  };
25
34
  extensionCtx: ExtensionCtx;
26
35
  extensions?: Extension[];
27
- logger: LoggerType;
36
+ logger: LogReturn;
28
37
  /**
29
38
  * Stores the set tenant id from Server for use in sub classes
30
39
  */
@@ -433,7 +442,7 @@ type NileConfig = {
433
442
  /**
434
443
  * Some kind of logger if you want to send to an external service
435
444
  */
436
- logger?: LoggerType;
445
+ logger?: LogReturn;
437
446
  /**
438
447
  * The configuration value that maps to `NILEDB_API_URL` - its going to be nile-auth (or similar service)
439
448
  */
package/dist/index.js CHANGED
@@ -31,6 +31,12 @@ var LoginUserResponseTokenTypeEnum = {
31
31
  IdToken: "ID_TOKEN"
32
32
  };
33
33
 
34
+ // src/utils/constants.ts
35
+ var TENANT_COOKIE = "nile.tenant-id";
36
+ var USER_COOKIE = "nile.user-id";
37
+ var HEADER_ORIGIN = "nile-origin";
38
+ var HEADER_SECURE_COOKIES = "nile-secure-cookies";
39
+
34
40
  // src/api/utils/routes/index.ts
35
41
  var NILEDB_API_URL = process.env.NILEDB_API_URL;
36
42
  var DEFAULT_PREFIX = "/api";
@@ -120,74 +126,9 @@ function isUUID(value) {
120
126
  return regex.test(value);
121
127
  }
122
128
 
123
- // src/utils/Logger.ts
124
- var red = "\x1B[31m";
125
- var yellow = "\x1B[38;2;255;255;0m";
126
- var purple = "\x1B[38;2;200;160;255m";
127
- var orange = "\x1B[38;2;255;165;0m";
128
- var reset = "\x1B[0m";
129
- var baseLogger = (config, ...params) => ({
130
- info(message, meta) {
131
- if (config?.debug) {
132
- console.info(
133
- `${orange}[niledb]${reset}${purple}[DEBUG]${reset}${params.join(
134
- ""
135
- )}${reset} ${message}`,
136
- meta ? `${JSON.stringify(meta)}` : ""
137
- );
138
- }
139
- },
140
- debug(message, meta) {
141
- if (config?.debug) {
142
- console.debug(
143
- `${orange}[niledb]${reset}${purple}[DEBUG]${reset}${params.join(
144
- ""
145
- )}${reset} ${message}`,
146
- meta ? `${JSON.stringify(meta)}` : ""
147
- );
148
- }
149
- },
150
- warn(message, meta) {
151
- if (config?.debug) {
152
- console.warn(
153
- `${orange}[niledb]${reset}${yellow}[WARN]${reset}${params.join(
154
- ""
155
- )}${reset} ${message}`,
156
- meta ? JSON.stringify(meta) : ""
157
- );
158
- }
159
- },
160
- error(message, meta) {
161
- console.error(
162
- `${orange}[niledb]${reset}${red}[ERROR]${reset}${params.join(
163
- ""
164
- )}${red} ${message}`,
165
- meta ? meta : "",
166
- `${reset}`
167
- );
168
- }
169
- });
170
- function Logger(config, ...params) {
171
- const base = baseLogger(config, params);
172
- const info = config?.logger?.info ?? base.info;
173
- const debug = config?.logger?.debug ?? base.debug;
174
- const warn = config?.logger?.warn ?? base.warn;
175
- const error = config?.logger?.error ?? base.error;
176
- return { info, warn, error, debug };
177
- }
178
- function matchesLog(configRoutes, request2) {
179
- return urlMatches(request2.url, configRoutes.LOG);
180
- }
181
-
182
- // src/utils/constants.ts
183
- var TENANT_COOKIE = "nile.tenant-id";
184
- var USER_COOKIE = "nile.user-id";
185
- var HEADER_ORIGIN = "nile-origin";
186
- var HEADER_SECURE_COOKIES = "nile-secure-cookies";
187
-
188
129
  // src/api/utils/request.ts
189
130
  async function request(url, _init, config) {
190
- const { debug, info, error } = Logger(config, "[REQUEST]");
131
+ const { debug, info, error } = config.logger("[REQUEST]");
191
132
  const { request: request2, ...init } = _init;
192
133
  const requestUrl = new URL(request2.url);
193
134
  const updatedHeaders = new Headers({});
@@ -285,7 +226,7 @@ async function request(url, _init, config) {
285
226
 
286
227
  // src/api/utils/auth.ts
287
228
  async function auth(req, config) {
288
- const { info, error } = Logger(config, "[nileauth]");
229
+ const { info, error } = config.logger("[nileauth]");
289
230
  info("checking auth");
290
231
  const sessionUrl = `${config.apiUrl}/auth/session`;
291
232
  info(`using session ${sessionUrl}`);
@@ -428,10 +369,7 @@ async function PUT2(config, init) {
428
369
  // src/api/routes/users/index.ts
429
370
  var key2 = "USERS";
430
371
  async function route2(request2, config) {
431
- const { info } = Logger(
432
- { ...config, debug: config.debug },
433
- `[ROUTES][${key2}]`
434
- );
372
+ const { info } = config.logger(`[ROUTES][${key2}]`);
435
373
  switch (request2.method) {
436
374
  case "GET":
437
375
  return await GET2(config, { request: request2 }, info);
@@ -472,10 +410,7 @@ async function POST2(config, init) {
472
410
  // src/api/routes/tenants/[tenantId]/users/index.ts
473
411
  var key3 = "TENANT_USERS";
474
412
  async function route3(request2, config) {
475
- const { info } = Logger(
476
- { ...config, debug: config.debug },
477
- `[ROUTES][${key3}]`
478
- );
413
+ const { info } = config.logger(`[ROUTES][${key3}]`);
479
414
  const yurl = new URL(request2.url);
480
415
  const [, tenantId] = yurl.pathname.split("/").reverse();
481
416
  if (!tenantId) {
@@ -507,8 +442,8 @@ async function fetchTenantUsers(config, method, payload) {
507
442
  'Unable to fetch tenant, the tenantId context is missing. Call nile.setContext({ tenantId }), set nile.tenantId = "tenantId", or add it to the function call'
508
443
  );
509
444
  }
510
- if (!isUUID(config.tenantId) && config.logger?.warn) {
511
- config.logger?.warn(
445
+ if (!isUUID(config.tenantId)) {
446
+ config.logger("fetchTenantUsers").warn(
512
447
  "nile.tenantId is not a valid UUID. This may lead to unexpected behavior in your application."
513
448
  );
514
449
  }
@@ -598,8 +533,8 @@ async function fetchInvite(config, method, body) {
598
533
  'Unable to fetch tenant, the tenantId context is missing. Call nile.setContext({ tenantId }), set nile.tenantId = "tenantId", or add it to the function call'
599
534
  );
600
535
  }
601
- if (!isUUID(config.tenantId) && config.logger?.warn) {
602
- config.logger?.warn(
536
+ if (!isUUID(config.tenantId)) {
537
+ config.logger("fetchInvite").warn(
603
538
  "nile.tenantId is not a valid UUID. This may lead to unexpected behavior in your application."
604
539
  );
605
540
  }
@@ -653,8 +588,8 @@ async function fetchInvites(config) {
653
588
  'Unable to fetch tenant, the tenantId context is missing. Call nile.setContext({ tenantId }), set nile.tenantId = "tenantId", or add it to the function call'
654
589
  );
655
590
  }
656
- if (!isUUID(config.tenantId) && config.logger?.warn) {
657
- config.logger?.warn(
591
+ if (!isUUID(config.tenantId)) {
592
+ config.logger("fetchInvites").warn(
658
593
  "nile.tenantId is not a valid UUID. This may lead to unexpected behavior in your application."
659
594
  );
660
595
  }
@@ -722,10 +657,7 @@ async function POST4(config, init) {
722
657
  // src/api/routes/tenants/index.ts
723
658
  var key6 = "TENANTS";
724
659
  async function route6(request2, config) {
725
- const { info } = Logger(
726
- { ...config, debug: config.debug },
727
- `[ROUTES][${key6}]`
728
- );
660
+ const { info } = config.logger(`[ROUTES][${key6}]`);
729
661
  const session = await auth(request2, config);
730
662
  if (!session) {
731
663
  info("401");
@@ -769,8 +701,8 @@ async function fetchTenant(config, method, body) {
769
701
  'Unable to fetch tenant, the tenantId context is missing. Call nile.setContext({ tenantId }), set nile.tenantId = "tenantId", or add it to the function call'
770
702
  );
771
703
  }
772
- if (!isUUID(config.tenantId) && config.logger?.warn) {
773
- config.logger?.warn(
704
+ if (!isUUID(config.tenantId)) {
705
+ config.logger("fetch tenant").warn(
774
706
  "nile.tenantId is not a valid UUID. This may lead to unexpected behavior in your application."
775
707
  );
776
708
  }
@@ -787,21 +719,17 @@ async function fetchTenant(config, method, body) {
787
719
  return await config.handlers[m](req);
788
720
  }
789
721
  async function fetchTenantsByUser(config) {
790
- if (config.logger?.warn) {
791
- if (!config.userId) {
792
- config.logger?.warn(
793
- "nile.userId is not set. The call will still work for the API, but the database context is not set properly and may lead to unexpected behavior in your application."
794
- );
795
- } else if (!isUUID(config.userId)) {
796
- config.logger?.warn(
797
- "nile.userId is not a valid UUID. This may lead to unexpected behavior in your application."
798
- );
799
- }
722
+ const { warn } = config.logger("fetchTenantsByUser");
723
+ if (!config.userId) {
724
+ warn(
725
+ "nile.userId is not set. The call will still work for the API, but the database context is not set properly and may lead to unexpected behavior in your application."
726
+ );
727
+ } else if (!isUUID(config.userId)) {
728
+ warn(
729
+ "nile.userId is not a valid UUID. This may lead to unexpected behavior in your application."
730
+ );
800
731
  }
801
- const clientUrl = `${config.serverOrigin}${config.routePrefix}${"/users/{userId}/tenants" /* USER_TENANTS */.replace(
802
- "{userId}",
803
- config.userId ?? "WARN_NOT_SET"
804
- )}`;
732
+ const clientUrl = `${config.serverOrigin}${config.routePrefix}${"/tenants" /* TENANTS */}`;
805
733
  const req = new Request(clientUrl, { headers: config.headers });
806
734
  return await config.handlers.GET(req);
807
735
  }
@@ -909,10 +837,7 @@ async function fetchCsrf(config) {
909
837
  // src/api/routes/auth/callback.ts
910
838
  var key8 = "CALLBACK";
911
839
  async function route11(req, config) {
912
- const { error } = Logger(
913
- { ...config, debug: config.debug },
914
- `[ROUTES][${key8}]`
915
- );
840
+ const { error } = config.logger(`[ROUTES][${key8}]`);
916
841
  const [provider] = new URL(req.url).pathname.split("/").reverse();
917
842
  try {
918
843
  const passThroughUrl = new URL(req.url);
@@ -1103,7 +1028,7 @@ async function fetchVerifyEmail(config, method, body) {
1103
1028
 
1104
1029
  // src/api/handlers/GET.ts
1105
1030
  function GETTER(configRoutes, config) {
1106
- const { info, warn } = Logger(config, "[GET MATCHER]");
1031
+ const { info, warn } = config.logger("[GET MATCHER]");
1107
1032
  return async function GET7(req) {
1108
1033
  if (matches(configRoutes, req)) {
1109
1034
  info("matches me");
@@ -1174,6 +1099,68 @@ function GETTER(configRoutes, config) {
1174
1099
  };
1175
1100
  }
1176
1101
 
1102
+ // src/utils/Logger.ts
1103
+ var red = "\x1B[31m";
1104
+ var yellow = "\x1B[38;2;255;255;0m";
1105
+ var purple = "\x1B[38;2;200;160;255m";
1106
+ var orange = "\x1B[38;2;255;165;0m";
1107
+ var reset = "\x1B[0m";
1108
+ var baseLogger = (config, ...params) => ({
1109
+ info(message, meta) {
1110
+ if (config?.debug) {
1111
+ console.info(
1112
+ `${orange}[niledb]${reset}${purple}[DEBUG]${reset}${params.join(
1113
+ ""
1114
+ )}${reset} ${message}`,
1115
+ meta ? `${JSON.stringify(meta)}` : ""
1116
+ );
1117
+ }
1118
+ },
1119
+ debug(message, meta) {
1120
+ if (config?.debug) {
1121
+ console.debug(
1122
+ `${orange}[niledb]${reset}${purple}[DEBUG]${reset}${params.join(
1123
+ ""
1124
+ )}${reset} ${message}`,
1125
+ meta ? `${JSON.stringify(meta)}` : ""
1126
+ );
1127
+ }
1128
+ },
1129
+ warn(message, meta) {
1130
+ if (config?.debug) {
1131
+ console.warn(
1132
+ `${orange}[niledb]${reset}${yellow}[WARN]${reset}${params.join(
1133
+ ""
1134
+ )}${reset} ${message}`,
1135
+ meta ? JSON.stringify(meta) : ""
1136
+ );
1137
+ }
1138
+ },
1139
+ error(message, meta) {
1140
+ console.error(
1141
+ `${orange}[niledb]${reset}${red}[ERROR]${reset}${params.join(
1142
+ ""
1143
+ )}${red} ${message}`,
1144
+ meta ? meta : "",
1145
+ `${reset}`
1146
+ );
1147
+ }
1148
+ });
1149
+ function Logger(config) {
1150
+ return (prefixes) => {
1151
+ const { info, debug, warn, error } = config && typeof config?.logger === "function" ? config.logger(prefixes) : baseLogger(config, prefixes);
1152
+ return {
1153
+ info,
1154
+ debug,
1155
+ warn,
1156
+ error
1157
+ };
1158
+ };
1159
+ }
1160
+ function matchesLog(configRoutes, request2) {
1161
+ return urlMatches(request2.url, configRoutes.LOG);
1162
+ }
1163
+
1177
1164
  // src/api/routes/signup/POST.ts
1178
1165
  async function POST5(config, init) {
1179
1166
  init.body = init.request.body;
@@ -1215,7 +1202,7 @@ async function fetchSignUp(config, payload) {
1215
1202
 
1216
1203
  // src/api/handlers/POST.ts
1217
1204
  function POSTER(configRoutes, config) {
1218
- const { info, warn, error } = Logger(config, "[POST MATCHER]");
1205
+ const { info, warn, error } = config.logger("[POST MATCHER]");
1219
1206
  return async function POST6(req) {
1220
1207
  if (matchesLog(configRoutes, req)) {
1221
1208
  try {
@@ -1308,10 +1295,7 @@ async function PUT5(config, init) {
1308
1295
  // src/api/routes/tenants/[tenantId]/users/[userId]/index.ts
1309
1296
  var key15 = "TENANT_USER";
1310
1297
  async function route18(request2, config) {
1311
- const { info } = Logger(
1312
- { ...config, debug: config.debug },
1313
- `[ROUTES][${key15}]`
1314
- );
1298
+ const { info } = config.logger(`[ROUTES][${key15}]`);
1315
1299
  const session = await auth(request2, config);
1316
1300
  if (!session) {
1317
1301
  info("401");
@@ -1394,7 +1378,7 @@ function matches19(configRoutes, request2) {
1394
1378
 
1395
1379
  // src/api/handlers/DELETE.ts
1396
1380
  function DELETER(configRoutes, config) {
1397
- const { info, warn } = Logger(config, "[DELETE MATCHER]");
1381
+ const { info, warn } = config.logger("[DELETE MATCHER]");
1398
1382
  return async function DELETE5(req) {
1399
1383
  if (matches19(configRoutes, req)) {
1400
1384
  info("matches tenant invite id");
@@ -1423,7 +1407,7 @@ function DELETER(configRoutes, config) {
1423
1407
 
1424
1408
  // src/api/handlers/PUT.ts
1425
1409
  function PUTER(configRoutes, config) {
1426
- const { info, warn } = Logger(config, "[PUT MATCHER]");
1410
+ const { info, warn } = config.logger("[PUT MATCHER]");
1427
1411
  return async function PUT6(req) {
1428
1412
  if (matches4(configRoutes, req)) {
1429
1413
  info("matches tenant invite");
@@ -1503,14 +1487,14 @@ var getSecureCookies = (cfg) => {
1503
1487
  var getUsername = (cfg) => {
1504
1488
  const { config } = cfg;
1505
1489
  const logger = config.logger;
1506
- const { info } = Logger(config, "[username]");
1490
+ const { info } = logger();
1507
1491
  if (config?.user) {
1508
- logger && info(`${logger}[config] ${config.user}`);
1492
+ info(`[config] ${config.user}`);
1509
1493
  return String(config?.user);
1510
1494
  }
1511
1495
  const user = stringCheck(process.env.NILEDB_USER);
1512
1496
  if (user) {
1513
- logger && info(`${logger}[NILEDB_USER] ${user}`);
1497
+ info(`[NILEDB_USER] ${user}`);
1514
1498
  return user;
1515
1499
  }
1516
1500
  const pg2 = stringCheck(process.env.NILEDB_POSTGRES_URL);
@@ -1531,14 +1515,13 @@ var getPassword = (cfg) => {
1531
1515
  const { config } = cfg;
1532
1516
  const logger = config.logger;
1533
1517
  const log = logProtector(logger);
1534
- const { info } = Logger(config, "[password]");
1535
1518
  if (stringCheck(config?.password)) {
1536
- log && info(`${logger}[config] ***`);
1519
+ log && log("[config]").info("***");
1537
1520
  return String(config?.password);
1538
1521
  }
1539
1522
  const pass = stringCheck(process.env.NILEDB_PASSWORD);
1540
1523
  if (pass) {
1541
- logger && info(`${logger}[NILEDB_PASSWORD] ***`);
1524
+ logger("[NILEDB_PASSWORD]").info("***");
1542
1525
  return pass;
1543
1526
  }
1544
1527
  const pg2 = stringCheck(process.env.NILEDB_POSTGRES_URL);
@@ -1557,15 +1540,14 @@ var getPassword = (cfg) => {
1557
1540
  };
1558
1541
  var getDatabaseName = (cfg) => {
1559
1542
  const { config } = cfg;
1560
- const logger = config.logger;
1561
- const { info } = Logger(config, "[databaseName]");
1543
+ const { info } = config.logger("[databaseName]");
1562
1544
  if (stringCheck(config?.databaseName)) {
1563
- logger && info(`${logger}[config] ${config?.databaseName}`);
1545
+ info(`[config] ${config?.databaseName}`);
1564
1546
  return String(config?.databaseName);
1565
1547
  }
1566
1548
  const name = stringCheck(process.env.NILEDB_NAME);
1567
1549
  if (name) {
1568
- logger && info(`${logger}[NILEDB_NAME] ${name}`);
1550
+ info(`[NILEDB_NAME] ${name}`);
1569
1551
  return name;
1570
1552
  }
1571
1553
  if (process.env.NILEDB_POSTGRES_URL) {
@@ -1581,14 +1563,13 @@ var getDatabaseName = (cfg) => {
1581
1563
  };
1582
1564
  var getTenantId = (cfg) => {
1583
1565
  const { config } = cfg;
1584
- const logger = config.logger;
1585
- const { info } = Logger(config, "[tenantId]");
1566
+ const { info } = config.logger("[tenantId]");
1586
1567
  if (stringCheck(config?.tenantId)) {
1587
- logger && info(`${logger}[config] ${config?.tenantId}`);
1568
+ info(`[config] ${config?.tenantId}`);
1588
1569
  return String(config?.tenantId);
1589
1570
  }
1590
1571
  if (stringCheck(process.env.NILEDB_TENANT)) {
1591
- logger && info(`${logger}[NILEDB_TENANT] ${process.env.NILEDB_TENANT}`);
1572
+ info(`[NILEDB_TENANT] ${process.env.NILEDB_TENANT}`);
1592
1573
  return String(process.env.NILEDB_TENANT);
1593
1574
  }
1594
1575
  return null;
@@ -1596,37 +1577,37 @@ var getTenantId = (cfg) => {
1596
1577
  function getDbHost(cfg) {
1597
1578
  const { config } = cfg;
1598
1579
  const logger = config.logger;
1599
- const { info } = Logger(config, "[db.host]");
1580
+ const { info } = logger("[db.host]");
1600
1581
  if (stringCheck(config?.db && config.db.host)) {
1601
- logger && info(`${logger}[config] ${config?.db?.host}`);
1582
+ info(`[config] ${config?.db?.host}`);
1602
1583
  return String(config?.db?.host);
1603
1584
  }
1604
1585
  if (stringCheck(process.env.NILEDB_HOST)) {
1605
- logger && info(`${logger}[NILEDB_HOST] ${process.env.NILEDB_HOST}`);
1586
+ info(`[NILEDB_HOST] ${process.env.NILEDB_HOST}`);
1606
1587
  return process.env.NILEDB_HOST;
1607
1588
  }
1608
1589
  const pg2 = stringCheck(process.env.NILEDB_POSTGRES_URL);
1609
1590
  if (pg2) {
1610
1591
  try {
1611
1592
  const pgUrl = new URL(pg2);
1612
- logger && info(`${logger}[NILEDB_POSTGRES_URL] ${pgUrl.hostname}`);
1593
+ info(`[NILEDB_POSTGRES_URL] ${pgUrl.hostname}`);
1613
1594
  return pgUrl.hostname;
1614
1595
  } catch (e) {
1615
1596
  }
1616
1597
  }
1617
- logger && info(`${logger}[default] db.thenile.dev`);
1598
+ info("[default] db.thenile.dev");
1618
1599
  return "db.thenile.dev";
1619
1600
  }
1620
1601
  function getDbPort(cfg) {
1621
1602
  const { config } = cfg;
1622
1603
  const logger = config.logger;
1623
- const { info } = Logger(config, "[db.port]");
1604
+ const { info } = logger("[db.port]");
1624
1605
  if (config?.db?.port && config.db.port != null) {
1625
- logger && info(`${logger}[config] ${config?.db.port}`);
1606
+ info(`[config] ${config?.db.port}`);
1626
1607
  return Number(config.db?.port);
1627
1608
  }
1628
1609
  if (stringCheck(process.env.NILEDB_PORT)) {
1629
- logger && info(`${logger}[NILEDB_PORT] ${process.env.NILEDB_PORT}`);
1610
+ info(`[NILEDB_PORT] ${process.env.NILEDB_PORT}`);
1630
1611
  return Number(process.env.NILEDB_PORT);
1631
1612
  }
1632
1613
  const pg2 = stringCheck(process.env.NILEDB_POSTGRES_URL);
@@ -1639,7 +1620,7 @@ function getDbPort(cfg) {
1639
1620
  } catch (e) {
1640
1621
  }
1641
1622
  }
1642
- logger && info(`${logger}[default] 5432`);
1623
+ info("[default] 5432");
1643
1624
  return 5432;
1644
1625
  }
1645
1626
  var logProtector = (logger) => {
@@ -1692,7 +1673,6 @@ var Config = class {
1692
1673
  */
1693
1674
  routePrefix;
1694
1675
  db;
1695
- // api: ApiConfig;
1696
1676
  constructor(config) {
1697
1677
  this.routePrefix = config?.routePrefix ?? "/api";
1698
1678
  this.debug = config?.debug;
@@ -1700,7 +1680,7 @@ var Config = class {
1700
1680
  this.extensions = config?.extensions;
1701
1681
  this.extensionCtx = config?.extensionCtx;
1702
1682
  this.serverOrigin = config?.origin ?? "http://localhost:3000";
1703
- this.logger = config?.logger ?? Logger(this);
1683
+ this.logger = Logger(config);
1704
1684
  const envVarConfig = {
1705
1685
  config: { ...config, logger: this.logger }
1706
1686
  };
@@ -1821,7 +1801,7 @@ var watchHeaders = (cb) => eventer.subscribe("headers" /* Headers */, cb);
1821
1801
 
1822
1802
  // src/db/PoolProxy.ts
1823
1803
  function createProxyForPool(pool, config) {
1824
- const { info, error } = Logger(config, "[pool]");
1804
+ const { info, error } = config.logger("[pool]");
1825
1805
  return new Proxy(pool, {
1826
1806
  get(target, property) {
1827
1807
  if (property === "query") {
@@ -1857,7 +1837,7 @@ var NileDatabase = class {
1857
1837
  config;
1858
1838
  timer;
1859
1839
  constructor(config, id) {
1860
- const { warn, info, debug } = Logger(config, "[NileInstance]");
1840
+ const { warn, info, debug } = config.logger("[NileInstance]");
1861
1841
  this.id = id;
1862
1842
  const poolConfig = {
1863
1843
  min: 0,
@@ -1886,7 +1866,7 @@ var NileDatabase = class {
1886
1866
  `${this.id}-${this.timer}`
1887
1867
  );
1888
1868
  afterCreate2(client, (err) => {
1889
- const { error } = Logger(config, "[after create callback]");
1869
+ const { error } = config.logger("[after create callback]");
1890
1870
  if (err) {
1891
1871
  clearTimeout(this.timer);
1892
1872
  error("after create failed", {
@@ -1914,7 +1894,7 @@ var NileDatabase = class {
1914
1894
  });
1915
1895
  }
1916
1896
  startTimeout() {
1917
- const { debug } = Logger(this.config, "[NileInstance]");
1897
+ const { debug } = this.config.logger("[NileInstance]");
1918
1898
  if (this.timer) {
1919
1899
  clearTimeout(this.timer);
1920
1900
  }
@@ -1929,7 +1909,7 @@ var NileDatabase = class {
1929
1909
  }, Number(this.config.db.idleTimeoutMillis) ?? 3e4);
1930
1910
  }
1931
1911
  shutdown() {
1932
- const { debug } = Logger(this.config, "[NileInstance]");
1912
+ const { debug } = this.config.logger("[NileInstance]");
1933
1913
  debug(`attempting to shut down ${this.id}`);
1934
1914
  clearTimeout(this.timer);
1935
1915
  this.pool.end(() => {
@@ -1939,7 +1919,7 @@ var NileDatabase = class {
1939
1919
  };
1940
1920
  var NileInstance_default = NileDatabase;
1941
1921
  function makeAfterCreate(config, id) {
1942
- const { error, warn, debug } = Logger(config, "[afterCreate]");
1922
+ const { error, warn, debug } = config.logger("[afterCreate]");
1943
1923
  return (conn, done) => {
1944
1924
  conn.on("error", function errorHandler(e) {
1945
1925
  error(`Connection ${id} was terminated by server`, {
@@ -2003,7 +1983,7 @@ var DBManager = class {
2003
1983
  watchEvictPool(this.poolWatcherFn);
2004
1984
  }
2005
1985
  poolWatcher = (config) => (id) => {
2006
- const { info, warn } = Logger(config, "[DBManager]");
1986
+ const { info, warn } = Logger(config)("[DBManager]");
2007
1987
  if (id && this.connections.has(id)) {
2008
1988
  info(`Removing ${id} from db connection pool.`);
2009
1989
  const connection = this.connections.get(id);
@@ -2014,7 +1994,7 @@ var DBManager = class {
2014
1994
  }
2015
1995
  };
2016
1996
  getConnection = (config) => {
2017
- const { info } = Logger(config, "[DBManager]");
1997
+ const { info } = Logger(config)("[DBManager]");
2018
1998
  const id = this.makeId(config.tenantId, config.userId);
2019
1999
  const existing = this.connections.get(id);
2020
2000
  info(`# of instances: ${this.connections.size}`);
@@ -2033,7 +2013,7 @@ var DBManager = class {
2033
2013
  return newOne.pool;
2034
2014
  };
2035
2015
  clear = (config) => {
2036
- const { info } = Logger(config, "[DBManager]");
2016
+ const { info } = Logger(config)("[DBManager]");
2037
2017
  info(`Clearing all connections ${this.connections.size}`);
2038
2018
  this.cleared = true;
2039
2019
  this.connections.forEach((connection) => {
@@ -2049,7 +2029,7 @@ var Auth = class {
2049
2029
  #config;
2050
2030
  constructor(config) {
2051
2031
  this.#config = config;
2052
- this.#logger = Logger(config, "[auth]");
2032
+ this.#logger = config.logger("[auth]");
2053
2033
  }
2054
2034
  async getSession(rawResponse = false) {
2055
2035
  const res = await fetchSession(this.#config);
@@ -2499,7 +2479,7 @@ var Users = class {
2499
2479
  #logger;
2500
2480
  constructor(config) {
2501
2481
  this.#config = config;
2502
- this.#logger = Logger(config, "[me]");
2482
+ this.#logger = config.logger("[me]");
2503
2483
  }
2504
2484
  async updateSelf(req, rawResponse) {
2505
2485
  const res = await fetchMe(this.#config, "PUT", JSON.stringify(req));
@@ -2591,10 +2571,8 @@ function defaultCallbackUrl2(config) {
2591
2571
 
2592
2572
  // src/tenants/index.ts
2593
2573
  var Tenants = class {
2594
- #logger;
2595
2574
  #config;
2596
2575
  constructor(config) {
2597
- this.#logger = Logger(config, "[tenants]");
2598
2576
  this.#config = config;
2599
2577
  }
2600
2578
  async create(req, rawResponse) {
@@ -2877,6 +2855,7 @@ function updateConfig(response, config) {
2877
2855
  // src/api/utils/extensions.ts
2878
2856
  function bindHandleOnRequest(instance) {
2879
2857
  return async function handleOnRequest(config, _init, params) {
2858
+ const { debug } = config.logger("[EXTENSIONS]");
2880
2859
  if (config.extensions) {
2881
2860
  for (const create2 of config.extensions) {
2882
2861
  if (typeof create2 !== "function") {
@@ -2890,13 +2869,11 @@ function bindHandleOnRequest(instance) {
2890
2869
  const cookie = modHeaders.get("cookie");
2891
2870
  if (cookie) {
2892
2871
  params.headers.set("cookie", cookie);
2893
- config.logger.debug(
2894
- `extension ${ext.id ?? create2.name} modified cookie`
2895
- );
2872
+ debug(`${ext.id ?? create2.name} modified cookie`);
2896
2873
  }
2897
2874
  }
2898
2875
  }
2899
- config.logger.debug(`extension ${ext.id ?? create2.name} ran onRequest`);
2876
+ debug(`${ext.id ?? create2.name} ran onRequest`);
2900
2877
  }
2901
2878
  }
2902
2879
  };
@@ -3019,7 +2996,7 @@ var Server = class {
3019
2996
  return;
3020
2997
  }
3021
2998
  }
3022
- const { warn } = Logger(this.#config, "[API]");
2999
+ const { warn } = Logger(this.#config)("[API]");
3023
3000
  if (warn) {
3024
3001
  warn(
3025
3002
  "Set context expects a Request, Header instance or an object of Record<string, string>"