@niledatabase/server 4.1.1 → 4.2.0-alpha.1

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
@@ -257,6 +257,7 @@ declare class Tenants extends Config {
257
257
  get tenantUrl(): string;
258
258
  createTenant: <T = Tenant | Response>(req: NileRequest<{
259
259
  name: string;
260
+ id?: string;
260
261
  }> | Headers | string, init?: RequestInit) => Promise<T>;
261
262
  getTenant: <T = Tenant | Response>(req: NileRequest<{
262
263
  id: string;
@@ -327,7 +328,7 @@ declare class Api {
327
328
  returnResponse?: boolean;
328
329
  }) => Promise<Response | undefined>;
329
330
  session: (req?: Request | Headers | null | undefined) => Promise<Response | JWT | ActiveSession | null | undefined>;
330
- setContext: (req: Request | Headers) => void;
331
+ setContext: (req: Request | Headers | Record<string, string>) => void;
331
332
  }
332
333
 
333
334
  declare class Server {
package/dist/index.d.ts CHANGED
@@ -257,6 +257,7 @@ declare class Tenants extends Config {
257
257
  get tenantUrl(): string;
258
258
  createTenant: <T = Tenant | Response>(req: NileRequest<{
259
259
  name: string;
260
+ id?: string;
260
261
  }> | Headers | string, init?: RequestInit) => Promise<T>;
261
262
  getTenant: <T = Tenant | Response>(req: NileRequest<{
262
263
  id: string;
@@ -327,7 +328,7 @@ declare class Api {
327
328
  returnResponse?: boolean;
328
329
  }) => Promise<Response | undefined>;
329
330
  session: (req?: Request | Headers | null | undefined) => Promise<Response | JWT | ActiveSession | null | undefined>;
330
- setContext: (req: Request | Headers) => void;
331
+ setContext: (req: Request | Headers | Record<string, string>) => void;
331
332
  }
332
333
 
333
334
  declare class Server {
package/dist/index.js CHANGED
@@ -325,12 +325,12 @@ var getPassword = (cfg) => {
325
325
  const log = logProtector(logger);
326
326
  const { info } = Logger(config, "[password]");
327
327
  if (stringCheck(config?.password)) {
328
- log && info(`${logger}[config] ${config?.password}`);
328
+ log && info(`${logger}[config] ***`);
329
329
  return String(config?.password);
330
330
  }
331
331
  const pass = stringCheck(process.env.NILEDB_PASSWORD);
332
332
  if (pass) {
333
- logger && info(`${logger}[NILEDB_PASSWORD] ${pass}`);
333
+ logger && info(`${logger}[NILEDB_PASSWORD] ***`);
334
334
  return pass;
335
335
  }
336
336
  const pg2 = stringCheck(process.env.NILEDB_POSTGRES_URL);
@@ -619,7 +619,9 @@ var Config = class {
619
619
  database: this.databaseName,
620
620
  ...dbConfig
621
621
  };
622
- info("[config set]", { db: this.db, api: this.api });
622
+ const cloned = { ...this.db };
623
+ cloned.password = "***";
624
+ info("[config set]", { db: cloned, api: this.api });
623
625
  return this;
624
626
  } else {
625
627
  const msg = [];
@@ -807,7 +809,9 @@ var NileDatabase = class {
807
809
  const { afterCreate, ...remaining } = poolConfig;
808
810
  config.db = poolConfig;
809
811
  this.config = config;
810
- debug(`Connection pool config ${JSON.stringify(this.config.db)}`);
812
+ const cloned = { ...this.config.db };
813
+ cloned.password = "***";
814
+ debug(`Connection pool config ${JSON.stringify(cloned)}`);
811
815
  this.pool = createProxyForPool(new pg__default.default.Pool(remaining), this.config);
812
816
  if (typeof afterCreate === "function") {
813
817
  warn(
@@ -2305,6 +2309,14 @@ var Tenants = class extends Config {
2305
2309
  "content-type": "application/json"
2306
2310
  }
2307
2311
  });
2312
+ } else if ("name" in req || "id" in req) {
2313
+ _req = new Request(`${this.api.basePath}${this.tenantsUrl}`, {
2314
+ body: JSON.stringify(req),
2315
+ method: "POST",
2316
+ headers: {
2317
+ "content-type": "application/json"
2318
+ }
2319
+ });
2308
2320
  } else {
2309
2321
  _req = req;
2310
2322
  }
@@ -2601,12 +2613,19 @@ var Api = class {
2601
2613
  setContext = (req) => {
2602
2614
  if (req instanceof Headers) {
2603
2615
  setContext(req);
2616
+ return;
2604
2617
  } else if (req instanceof Request) {
2605
2618
  setContext(req.headers);
2619
+ return;
2606
2620
  }
2607
- const { warn } = Logger(this.config, "[API]");
2608
- if (warn) {
2609
- warn("Set context expects a Request or Header object");
2621
+ const headers = new Headers(req);
2622
+ if (headers) {
2623
+ setContext(headers);
2624
+ } else {
2625
+ const { warn } = Logger(this.config, "[API]");
2626
+ if (warn) {
2627
+ warn("Set context expects a Request or Header object");
2628
+ }
2610
2629
  }
2611
2630
  };
2612
2631
  };