@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.js +37 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -532,6 +532,30 @@ function headersToMap(headers) {
|
|
|
532
532
|
}
|
|
533
533
|
|
|
534
534
|
// src/api/utils/request.ts
|
|
535
|
+
var NULL_BODY_STATUSES = /* @__PURE__ */ new Set([204, 205, 304]);
|
|
536
|
+
function stripDecodedResponseHeaders(res) {
|
|
537
|
+
if (!(res instanceof Response) || res.status < 200 || res.status > 599) {
|
|
538
|
+
return res;
|
|
539
|
+
}
|
|
540
|
+
const hasContentEncoding = res.headers.has("content-encoding");
|
|
541
|
+
const hasTransferEncoding = res.headers.has("transfer-encoding");
|
|
542
|
+
if (!hasContentEncoding && !hasTransferEncoding) {
|
|
543
|
+
return res;
|
|
544
|
+
}
|
|
545
|
+
const headers = new Headers(res.headers);
|
|
546
|
+
if (hasContentEncoding) {
|
|
547
|
+
headers.delete("content-encoding");
|
|
548
|
+
headers.delete("content-length");
|
|
549
|
+
}
|
|
550
|
+
if (hasTransferEncoding) {
|
|
551
|
+
headers.delete("transfer-encoding");
|
|
552
|
+
}
|
|
553
|
+
return new Response(NULL_BODY_STATUSES.has(res.status) ? null : res.body, {
|
|
554
|
+
status: res.status,
|
|
555
|
+
statusText: res.statusText,
|
|
556
|
+
headers
|
|
557
|
+
});
|
|
558
|
+
}
|
|
535
559
|
async function request(url, _init, config) {
|
|
536
560
|
const { debug, info, error } = config.logger("[REQUEST]");
|
|
537
561
|
const { request: request2, ...init } = _init;
|
|
@@ -620,7 +644,7 @@ async function request(url, _init, config) {
|
|
|
620
644
|
_init
|
|
621
645
|
);
|
|
622
646
|
try {
|
|
623
|
-
const
|
|
647
|
+
const fetchedRes = await fetch(fullUrl, {
|
|
624
648
|
...params
|
|
625
649
|
}).catch((e) => {
|
|
626
650
|
error("An error has occurred in the fetch", {
|
|
@@ -632,6 +656,7 @@ async function request(url, _init, config) {
|
|
|
632
656
|
{ status: 500 }
|
|
633
657
|
);
|
|
634
658
|
});
|
|
659
|
+
const res = stripDecodedResponseHeaders(fetchedRes);
|
|
635
660
|
const loggingRes = typeof res?.clone === "function" ? res?.clone() : null;
|
|
636
661
|
info(`[${params.method ?? "GET"}] ${fullUrl}`, {
|
|
637
662
|
status: res?.status,
|
|
@@ -2582,8 +2607,10 @@ var Auth = class {
|
|
|
2582
2607
|
return withNileContext(
|
|
2583
2608
|
this.#config,
|
|
2584
2609
|
async () => {
|
|
2585
|
-
ctx.set({ headers: null });
|
|
2586
2610
|
const { email, password, ...params } = payload;
|
|
2611
|
+
if (!params.tenantId) {
|
|
2612
|
+
ctx.set({ headers: null });
|
|
2613
|
+
}
|
|
2587
2614
|
if (!email || !password) {
|
|
2588
2615
|
throw new Error(
|
|
2589
2616
|
"Server side sign up requires a user email and password."
|
|
@@ -2621,7 +2648,12 @@ var Auth = class {
|
|
|
2621
2648
|
);
|
|
2622
2649
|
}
|
|
2623
2650
|
const { headers } = ctx.get();
|
|
2624
|
-
|
|
2651
|
+
const cookie = [
|
|
2652
|
+
parseCSRF(res.headers) ?? parseCSRF(headers),
|
|
2653
|
+
parseCallback(res.headers) ?? parseCallback(headers),
|
|
2654
|
+
token
|
|
2655
|
+
].filter(Boolean).join("; ");
|
|
2656
|
+
headers.set("cookie", cookie);
|
|
2625
2657
|
ctx.set({ headers });
|
|
2626
2658
|
updateHeaders(headers);
|
|
2627
2659
|
if (rawResponse) {
|
|
@@ -3064,8 +3096,8 @@ async function obtainCsrf(config, rawResponse = false) {
|
|
|
3064
3096
|
if (setCookie) {
|
|
3065
3097
|
const cookie = [
|
|
3066
3098
|
csrfCook,
|
|
3067
|
-
parseCallback(res.headers),
|
|
3068
|
-
parseToken(res.headers)
|
|
3099
|
+
parseCallback(res.headers) ?? parseCallback(headers),
|
|
3100
|
+
parseToken(res.headers) ?? parseToken(headers)
|
|
3069
3101
|
].filter(Boolean).join("; ");
|
|
3070
3102
|
headers.set("cookie", cookie);
|
|
3071
3103
|
ctx.set({ headers });
|