@niledatabase/server 4.2.0-alpha.3 → 4.2.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
@@ -2560,6 +2560,9 @@ var Api = class {
2560
2560
  this.#headers = new Headers(headers ?? {});
2561
2561
  this.reset();
2562
2562
  };
2563
+ /**
2564
+ * Merge headers together
2565
+ */
2563
2566
  set headers(headers) {
2564
2567
  const updates = [];
2565
2568
  if (headers instanceof Headers) {
@@ -2573,7 +2576,9 @@ var Api = class {
2573
2576
  }
2574
2577
  const merged = {};
2575
2578
  this.#headers?.forEach((value, key12) => {
2576
- merged[key12.toLowerCase()] = value;
2579
+ if (key12.toLowerCase() !== "cookie") {
2580
+ merged[key12.toLowerCase()] = value;
2581
+ }
2577
2582
  });
2578
2583
  for (const [key12, value] of updates) {
2579
2584
  merged[key12] = value;
@@ -2600,8 +2605,18 @@ var Api = class {
2600
2605
  this.config,
2601
2606
  this.handlers
2602
2607
  )(payload);
2603
- this.headers = headers;
2604
2608
  this.setContext(headers);
2609
+ try {
2610
+ const res = await loginRes.json();
2611
+ if (res.id) {
2612
+ this.config.userId = res.id;
2613
+ }
2614
+ } catch (e) {
2615
+ const { warn } = Logger(this.config, "[API][login]");
2616
+ if (warn) {
2617
+ warn("Unable to set user id from login attempt.");
2618
+ }
2619
+ }
2605
2620
  if (config?.returnResponse) {
2606
2621
  return loginRes;
2607
2622
  }
@@ -2616,23 +2631,26 @@ var Api = class {
2616
2631
  return this.auth.getSession(this.#headers);
2617
2632
  };
2618
2633
  setContext = (req) => {
2619
- if (req instanceof Headers) {
2620
- this.headers = req;
2621
- return;
2622
- } else if (req instanceof Request) {
2623
- this.headers = new Headers(req.headers);
2624
- return;
2625
- }
2626
- const headers = new Headers(req);
2627
- if (headers) {
2628
- this.headers = headers;
2629
- } else {
2630
- const { warn } = Logger(this.config, "[API]");
2631
- if (warn) {
2632
- warn(
2633
- "Set context expects a Request, Header instance or an object of Record<string, string>"
2634
- );
2634
+ try {
2635
+ if (req instanceof Headers) {
2636
+ this.headers = req;
2637
+ return;
2638
+ } else if (req instanceof Request) {
2639
+ this.headers = new Headers(req.headers);
2640
+ return;
2641
+ }
2642
+ const headers = new Headers(req);
2643
+ if (headers) {
2644
+ this.headers = headers;
2645
+ return;
2635
2646
  }
2647
+ } catch {
2648
+ }
2649
+ const { warn } = Logger(this.config, "[API]");
2650
+ if (warn) {
2651
+ warn(
2652
+ "Set context expects a Request, Header instance or an object of Record<string, string>"
2653
+ );
2636
2654
  }
2637
2655
  };
2638
2656
  };