@niledatabase/server 5.3.1 → 5.3.2-alpha.0
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.js +49 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -55
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -747,27 +747,20 @@ async function GET(url, init, config) {
|
|
|
747
747
|
|
|
748
748
|
// src/utils/fetch.ts
|
|
749
749
|
function getTokenFromCookie(headers, cookieKey) {
|
|
750
|
-
const
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
for (const parts of cookie) {
|
|
754
|
-
const cookieParts = parts.split("=");
|
|
755
|
-
const _cookie = cookieParts.slice(1).join("=");
|
|
756
|
-
const name = cookieParts[0];
|
|
757
|
-
_cookies[name] = _cookie;
|
|
758
|
-
}
|
|
750
|
+
const cookieHeader = headers.get("cookie");
|
|
751
|
+
if (!cookieHeader) {
|
|
752
|
+
return null;
|
|
759
753
|
}
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
754
|
+
const cookies = cookieHeader.split("; ");
|
|
755
|
+
for (const parts of cookies) {
|
|
756
|
+
const cookieParts = parts.split("=");
|
|
757
|
+
const name = cookieParts[0];
|
|
758
|
+
const value = cookieParts.slice(1).join("=");
|
|
759
|
+
if (name === cookieKey) {
|
|
760
|
+
return value;
|
|
766
761
|
}
|
|
767
762
|
}
|
|
768
|
-
|
|
769
|
-
return _cookies[cookieKey];
|
|
770
|
-
}
|
|
763
|
+
return null;
|
|
771
764
|
}
|
|
772
765
|
function getTenantFromHttp(headers, context) {
|
|
773
766
|
const cookieTenant = getTokenFromCookie(headers, TENANT_COOKIE);
|
|
@@ -2262,43 +2255,45 @@ var updateHeaders = (val) => {
|
|
|
2262
2255
|
eventer.publish("headers" /* Headers */, val);
|
|
2263
2256
|
};
|
|
2264
2257
|
var watchHeaders = (cb) => eventer.subscribe("headers" /* Headers */, cb);
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
if (userId) {
|
|
2291
|
-
log = `${log}[USER:${userId}]`;
|
|
2292
|
-
}
|
|
2293
|
-
info(log, ...args);
|
|
2294
|
-
const called = caller.apply(this, args);
|
|
2295
|
-
return called;
|
|
2296
|
-
};
|
|
2258
|
+
var PoolWithLogger = class extends pg.Pool {
|
|
2259
|
+
nileConfig;
|
|
2260
|
+
logger;
|
|
2261
|
+
context;
|
|
2262
|
+
info;
|
|
2263
|
+
error;
|
|
2264
|
+
constructor(config, logger, context) {
|
|
2265
|
+
super(config);
|
|
2266
|
+
this.nileConfig = config;
|
|
2267
|
+
this.logger = logger;
|
|
2268
|
+
this.context = context;
|
|
2269
|
+
const { info, error } = this.logger("[pool]");
|
|
2270
|
+
this.info = info;
|
|
2271
|
+
this.error = error;
|
|
2272
|
+
}
|
|
2273
|
+
query(...args) {
|
|
2274
|
+
if (!this.nileConfig.connectionString) {
|
|
2275
|
+
if (!this.nileConfig.user || !this.nileConfig.password) {
|
|
2276
|
+
this.error(
|
|
2277
|
+
"Cannot connect to the database. User and/or password are missing. Generate them at https://console.thenile.dev"
|
|
2278
|
+
);
|
|
2279
|
+
} else if (!this.nileConfig.database) {
|
|
2280
|
+
this.error(
|
|
2281
|
+
"Unable to obtain database name. Is process.env.NILEDB_POSTGRES_URL set?"
|
|
2282
|
+
);
|
|
2297
2283
|
}
|
|
2298
|
-
return target[property];
|
|
2299
2284
|
}
|
|
2300
|
-
|
|
2301
|
-
|
|
2285
|
+
let log = "[QUERY]";
|
|
2286
|
+
const [tenantId, userId] = this.context;
|
|
2287
|
+
if (tenantId) {
|
|
2288
|
+
log = `${log}[TENANT:${tenantId}]`;
|
|
2289
|
+
}
|
|
2290
|
+
if (userId) {
|
|
2291
|
+
log = `${log}[USER:${userId}]`;
|
|
2292
|
+
}
|
|
2293
|
+
this.info(log, ...args);
|
|
2294
|
+
return super.query(...args);
|
|
2295
|
+
}
|
|
2296
|
+
};
|
|
2302
2297
|
|
|
2303
2298
|
// src/db/NileInstance.ts
|
|
2304
2299
|
var NileDatabase = class {
|
|
@@ -2323,8 +2318,7 @@ var NileDatabase = class {
|
|
|
2323
2318
|
const cloned = { ...config };
|
|
2324
2319
|
cloned.password = "***";
|
|
2325
2320
|
this.logger.debug(`Connection pool config ${JSON.stringify(cloned)}`);
|
|
2326
|
-
this.pool =
|
|
2327
|
-
new pg.Pool(remaining),
|
|
2321
|
+
this.pool = new PoolWithLogger(
|
|
2328
2322
|
this.config,
|
|
2329
2323
|
logger,
|
|
2330
2324
|
id === "base" ? [] : id.split(":")
|