@niledatabase/server 5.3.2-alpha.0 → 5.3.2-alpha.2

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
@@ -526,6 +526,30 @@ function headersToMap(headers) {
526
526
  }
527
527
 
528
528
  // src/api/utils/request.ts
529
+ var NULL_BODY_STATUSES = /* @__PURE__ */ new Set([204, 205, 304]);
530
+ function stripDecodedResponseHeaders(res) {
531
+ if (!(res instanceof Response) || res.status < 200 || res.status > 599) {
532
+ return res;
533
+ }
534
+ const hasContentEncoding = res.headers.has("content-encoding");
535
+ const hasTransferEncoding = res.headers.has("transfer-encoding");
536
+ if (!hasContentEncoding && !hasTransferEncoding) {
537
+ return res;
538
+ }
539
+ const headers = new Headers(res.headers);
540
+ if (hasContentEncoding) {
541
+ headers.delete("content-encoding");
542
+ headers.delete("content-length");
543
+ }
544
+ if (hasTransferEncoding) {
545
+ headers.delete("transfer-encoding");
546
+ }
547
+ return new Response(NULL_BODY_STATUSES.has(res.status) ? null : res.body, {
548
+ status: res.status,
549
+ statusText: res.statusText,
550
+ headers
551
+ });
552
+ }
529
553
  async function request(url, _init, config) {
530
554
  const { debug, info, error } = config.logger("[REQUEST]");
531
555
  const { request: request2, ...init } = _init;
@@ -614,7 +638,7 @@ async function request(url, _init, config) {
614
638
  _init
615
639
  );
616
640
  try {
617
- const res = await fetch(fullUrl, {
641
+ const fetchedRes = await fetch(fullUrl, {
618
642
  ...params
619
643
  }).catch((e) => {
620
644
  error("An error has occurred in the fetch", {
@@ -626,6 +650,7 @@ async function request(url, _init, config) {
626
650
  { status: 500 }
627
651
  );
628
652
  });
653
+ const res = stripDecodedResponseHeaders(fetchedRes);
629
654
  const loggingRes = typeof res?.clone === "function" ? res?.clone() : null;
630
655
  info(`[${params.method ?? "GET"}] ${fullUrl}`, {
631
656
  status: res?.status,
@@ -2576,8 +2601,10 @@ var Auth = class {
2576
2601
  return withNileContext(
2577
2602
  this.#config,
2578
2603
  async () => {
2579
- ctx.set({ headers: null });
2580
2604
  const { email, password, ...params } = payload;
2605
+ if (!params.tenantId) {
2606
+ ctx.set({ headers: null });
2607
+ }
2581
2608
  if (!email || !password) {
2582
2609
  throw new Error(
2583
2610
  "Server side sign up requires a user email and password."
@@ -2615,7 +2642,12 @@ var Auth = class {
2615
2642
  );
2616
2643
  }
2617
2644
  const { headers } = ctx.get();
2618
- headers?.append("cookie", token);
2645
+ const cookie = [
2646
+ parseCSRF(res.headers) ?? parseCSRF(headers),
2647
+ parseCallback(res.headers) ?? parseCallback(headers),
2648
+ token
2649
+ ].filter(Boolean).join("; ");
2650
+ headers.set("cookie", cookie);
2619
2651
  ctx.set({ headers });
2620
2652
  updateHeaders(headers);
2621
2653
  if (rawResponse) {
@@ -3058,8 +3090,8 @@ async function obtainCsrf(config, rawResponse = false) {
3058
3090
  if (setCookie) {
3059
3091
  const cookie = [
3060
3092
  csrfCook,
3061
- parseCallback(res.headers),
3062
- parseToken(res.headers)
3093
+ parseCallback(res.headers) ?? parseCallback(headers),
3094
+ parseToken(res.headers) ?? parseToken(headers)
3063
3095
  ].filter(Boolean).join("; ");
3064
3096
  headers.set("cookie", cookie);
3065
3097
  ctx.set({ headers });