@niledatabase/server 4.0.0 → 4.0.1-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.mjs CHANGED
@@ -2346,7 +2346,7 @@ var Api = class {
2346
2346
  auth;
2347
2347
  tenants;
2348
2348
  routes;
2349
- _headers;
2349
+ #headers;
2350
2350
  handlers;
2351
2351
  paths;
2352
2352
  constructor(config) {
@@ -2400,9 +2400,9 @@ var Api = class {
2400
2400
  };
2401
2401
  }
2402
2402
  reset = () => {
2403
- this.users = new Users(this.config, this._headers);
2404
- this.tenants = new Tenants(this.config, this._headers);
2405
- this.auth = new Auth(this.config, this._headers, {
2403
+ this.users = new Users(this.config, this.#headers);
2404
+ this.tenants = new Tenants(this.config, this.#headers);
2405
+ this.auth = new Auth(this.config, this.#headers, {
2406
2406
  resetHeaders: this.resetHeaders
2407
2407
  });
2408
2408
  };
@@ -2411,15 +2411,35 @@ var Api = class {
2411
2411
  this.handlers = Handlers(this.routes, config);
2412
2412
  };
2413
2413
  resetHeaders = (headers) => {
2414
- this._headers = new Headers(headers ?? {});
2414
+ this.#headers = new Headers(headers ?? {});
2415
2415
  this.reset();
2416
2416
  };
2417
2417
  set headers(headers) {
2418
- this._headers = headers;
2418
+ const updates = [];
2419
+ if (headers instanceof Headers) {
2420
+ headers.forEach((value, key12) => {
2421
+ updates.push([key12.toLowerCase(), value]);
2422
+ });
2423
+ } else {
2424
+ for (const [key12, value] of Object.entries(headers)) {
2425
+ updates.push([key12.toLowerCase(), value]);
2426
+ }
2427
+ }
2428
+ const merged = {};
2429
+ this.#headers?.forEach((value, key12) => {
2430
+ merged[key12.toLowerCase()] = value;
2431
+ });
2432
+ for (const [key12, value] of updates) {
2433
+ merged[key12] = value;
2434
+ }
2435
+ this.#headers = new Headers();
2436
+ for (const [key12, value] of Object.entries(merged)) {
2437
+ this.#headers.set(key12, value);
2438
+ }
2419
2439
  this.reset();
2420
2440
  }
2421
2441
  get headers() {
2422
- return this._headers;
2442
+ return this.#headers;
2423
2443
  }
2424
2444
  login = async (payload, config) => {
2425
2445
  const [headers, loginRes] = await serverLogin(
@@ -2438,7 +2458,7 @@ var Api = class {
2438
2458
  } else if (req instanceof Request) {
2439
2459
  return auth(req, this.config);
2440
2460
  }
2441
- return this.auth.getSession(this._headers);
2461
+ return this.auth.getSession(this.#headers);
2442
2462
  };
2443
2463
  };
2444
2464