@niledatabase/server 5.0.0-alpha.27 → 5.0.0-alpha.28
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 +46 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +46 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -471,8 +471,17 @@ var ctx = {
|
|
|
471
471
|
if (partial.headers === null) {
|
|
472
472
|
store.headers = new Headers();
|
|
473
473
|
} else if (partial.headers && store.headers instanceof Headers) {
|
|
474
|
-
for (const [
|
|
475
|
-
|
|
474
|
+
for (const [key17, value] of new Headers(partial.headers).entries()) {
|
|
475
|
+
if (key17.toLowerCase() === "cookie") {
|
|
476
|
+
const existingCookies = parseCookieHeader(
|
|
477
|
+
store.headers.get("cookie") || ""
|
|
478
|
+
);
|
|
479
|
+
const newCookies = parseCookieHeader(value);
|
|
480
|
+
const mergedCookies = { ...existingCookies, ...newCookies };
|
|
481
|
+
store.headers.set("cookie", serializeCookies(mergedCookies));
|
|
482
|
+
} else {
|
|
483
|
+
store.headers.set(key17, value);
|
|
484
|
+
}
|
|
476
485
|
}
|
|
477
486
|
}
|
|
478
487
|
if ("tenantId" in partial)
|
|
@@ -537,6 +546,16 @@ function serializeContext(context) {
|
|
|
537
546
|
preserveHeaders: context.preserveHeaders
|
|
538
547
|
});
|
|
539
548
|
}
|
|
549
|
+
function parseCookieHeader(header) {
|
|
550
|
+
return header.split(";").map((c) => c.trim()).filter(Boolean).reduce((acc, curr) => {
|
|
551
|
+
const [key17, ...val] = curr.split("=");
|
|
552
|
+
if (key17) acc[key17] = val.join("=");
|
|
553
|
+
return acc;
|
|
554
|
+
}, {});
|
|
555
|
+
}
|
|
556
|
+
function serializeCookies(cookies) {
|
|
557
|
+
return Object.entries(cookies).map(([k, v]) => `${k}=${v}`).join("; ");
|
|
558
|
+
}
|
|
540
559
|
|
|
541
560
|
// src/api/routes/me/index.ts
|
|
542
561
|
var key = "ME";
|
|
@@ -2688,7 +2707,7 @@ var Auth = class {
|
|
|
2688
2707
|
].filter(Boolean).join("; ");
|
|
2689
2708
|
const uHeaders = new Headers({ cookie });
|
|
2690
2709
|
updateHeaders(uHeaders);
|
|
2691
|
-
ctx.set({ headers: uHeaders });
|
|
2710
|
+
ctx.set({ headers: uHeaders, preserveHeaders: true });
|
|
2692
2711
|
} else {
|
|
2693
2712
|
error("Unable to set context after sign in", {
|
|
2694
2713
|
headers: signInRes.headers
|
|
@@ -2842,6 +2861,22 @@ async function obtainCsrf(config, rawResponse = false) {
|
|
|
2842
2861
|
}
|
|
2843
2862
|
}
|
|
2844
2863
|
|
|
2864
|
+
// src/utils/qualifyDomain.ts
|
|
2865
|
+
function fQUrl2(callbackUrl, path) {
|
|
2866
|
+
if (path.startsWith("/")) {
|
|
2867
|
+
if (callbackUrl) {
|
|
2868
|
+
const { origin } = new URL(callbackUrl);
|
|
2869
|
+
return `${origin}${path}`;
|
|
2870
|
+
}
|
|
2871
|
+
}
|
|
2872
|
+
try {
|
|
2873
|
+
new URL(path);
|
|
2874
|
+
} catch {
|
|
2875
|
+
throw new Error("An invalid URL has been passed.");
|
|
2876
|
+
}
|
|
2877
|
+
return path;
|
|
2878
|
+
}
|
|
2879
|
+
|
|
2845
2880
|
// src/users/index.ts
|
|
2846
2881
|
var Users = class {
|
|
2847
2882
|
#config;
|
|
@@ -2911,7 +2946,10 @@ var Users = class {
|
|
|
2911
2946
|
async verifySelf(options, rawResponse = false) {
|
|
2912
2947
|
return withNileContext(this.#config, async () => {
|
|
2913
2948
|
const bypassEmail = typeof options === "object" && options?.bypassEmail === true;
|
|
2914
|
-
const callbackUrl =
|
|
2949
|
+
const callbackUrl = fQUrl2(
|
|
2950
|
+
defaultCallbackUrl2().callbackUrl,
|
|
2951
|
+
typeof options === "object" ? String(options.callbackUrl) : "/"
|
|
2952
|
+
);
|
|
2915
2953
|
let res;
|
|
2916
2954
|
try {
|
|
2917
2955
|
const me = await this.getSelf();
|
|
@@ -3182,11 +3220,12 @@ var Tenants = class {
|
|
|
3182
3220
|
if ("email" in req) {
|
|
3183
3221
|
identifier = req.email;
|
|
3184
3222
|
}
|
|
3223
|
+
const { callbackUrl: cbUrl } = defaultCallbackUrl3(this.#config);
|
|
3185
3224
|
if ("callbackUrl" in req) {
|
|
3186
|
-
callbackUrl = fQUrl2(req.callbackUrl ?? ""
|
|
3225
|
+
callbackUrl = fQUrl2(cbUrl, req.callbackUrl ?? "/");
|
|
3187
3226
|
}
|
|
3188
3227
|
if ("redirectUrl" in req) {
|
|
3189
|
-
redirectUrl = fQUrl2(req.redirectUrl ?? ""
|
|
3228
|
+
redirectUrl = fQUrl2(cbUrl, req.redirectUrl ?? "/");
|
|
3190
3229
|
}
|
|
3191
3230
|
}
|
|
3192
3231
|
const { headers } = ctx.get();
|
|
@@ -3288,21 +3327,6 @@ function defaultCallbackUrl3(config) {
|
|
|
3288
3327
|
}
|
|
3289
3328
|
return { callbackUrl: cb, redirectUrl: redirect };
|
|
3290
3329
|
}
|
|
3291
|
-
function fQUrl2(path, config) {
|
|
3292
|
-
if (path.startsWith("/")) {
|
|
3293
|
-
const { callbackUrl } = defaultCallbackUrl3(config);
|
|
3294
|
-
if (callbackUrl) {
|
|
3295
|
-
const { origin } = new URL(callbackUrl);
|
|
3296
|
-
return `${origin}${path}`;
|
|
3297
|
-
}
|
|
3298
|
-
}
|
|
3299
|
-
try {
|
|
3300
|
-
new URL(path);
|
|
3301
|
-
} catch {
|
|
3302
|
-
throw new Error("An invalid URL has been passed.");
|
|
3303
|
-
}
|
|
3304
|
-
return path;
|
|
3305
|
-
}
|
|
3306
3330
|
|
|
3307
3331
|
// src/api/handlers/withContext/index.ts
|
|
3308
3332
|
function handlersWithContext(config) {
|
|
@@ -3395,6 +3419,7 @@ var Server = class {
|
|
|
3395
3419
|
watchHeaders((headers) => {
|
|
3396
3420
|
if (headers) {
|
|
3397
3421
|
this.#config.context.headers = new Headers(headers);
|
|
3422
|
+
this.#config.context.preserveHeaders = true;
|
|
3398
3423
|
this.#reset();
|
|
3399
3424
|
}
|
|
3400
3425
|
});
|