@niledatabase/server 5.0.0-alpha.7 → 5.0.0-alpha.9
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.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +44 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -433,7 +433,7 @@ async function fetchTenantUsers(config, method, payload) {
|
|
|
433
433
|
const { body, params } = {};
|
|
434
434
|
if (!config.tenantId) {
|
|
435
435
|
throw new Error(
|
|
436
|
-
|
|
436
|
+
"Unable to fetch the user's tenants, the tenantId context is missing. Call nile.setContext({ tenantId })"
|
|
437
437
|
);
|
|
438
438
|
}
|
|
439
439
|
if (!isUUID(config.tenantId)) {
|
|
@@ -524,7 +524,7 @@ function matches4(configRoutes, request2) {
|
|
|
524
524
|
async function fetchInvite(config, method, body) {
|
|
525
525
|
if (!config.tenantId) {
|
|
526
526
|
throw new Error(
|
|
527
|
-
|
|
527
|
+
"Unable to fetch the invite for the tenant, the tenantId context is missing. Call nile.setContext({ tenantId })"
|
|
528
528
|
);
|
|
529
529
|
}
|
|
530
530
|
if (!isUUID(config.tenantId)) {
|
|
@@ -579,7 +579,7 @@ function matches5(configRoutes, request2) {
|
|
|
579
579
|
async function fetchInvites(config) {
|
|
580
580
|
if (!config.tenantId) {
|
|
581
581
|
throw new Error(
|
|
582
|
-
|
|
582
|
+
"Unable to fetch invites for the tenant, the tenantId context is missing. Call nile.setContext({ tenantId })"
|
|
583
583
|
);
|
|
584
584
|
}
|
|
585
585
|
if (!isUUID(config.tenantId)) {
|
|
@@ -692,7 +692,7 @@ async function fetchTenants(config, method, body) {
|
|
|
692
692
|
async function fetchTenant(config, method, body) {
|
|
693
693
|
if (!config.tenantId) {
|
|
694
694
|
throw new Error(
|
|
695
|
-
|
|
695
|
+
"Unable to fetch tenants, the tenantId context is missing. Call nile.setContext({ tenantId })"
|
|
696
696
|
);
|
|
697
697
|
}
|
|
698
698
|
if (!isUUID(config.tenantId)) {
|
|
@@ -2327,7 +2327,7 @@ var Auth = class {
|
|
|
2327
2327
|
}
|
|
2328
2328
|
if (urlError) {
|
|
2329
2329
|
error("Unable to log user in", { error: urlError });
|
|
2330
|
-
return
|
|
2330
|
+
return new Response(urlError, { status: signInRes.status });
|
|
2331
2331
|
}
|
|
2332
2332
|
}
|
|
2333
2333
|
if (!token) {
|
|
@@ -2509,29 +2509,26 @@ var Users = class {
|
|
|
2509
2509
|
async verifySelf(options, rawResponse = false) {
|
|
2510
2510
|
const bypassEmail = typeof options === "object" ? options.bypassEmail ?? process.env.NODE_ENV !== "production" : process.env.NODE_ENV !== "production";
|
|
2511
2511
|
const callbackUrl = typeof options === "object" ? options.callbackUrl : defaultCallbackUrl2(this.#config).callbackUrl;
|
|
2512
|
+
let res;
|
|
2512
2513
|
try {
|
|
2513
2514
|
const me = await this.getSelf();
|
|
2514
2515
|
if (me instanceof Response) {
|
|
2515
2516
|
return me;
|
|
2516
2517
|
}
|
|
2517
|
-
|
|
2518
|
-
this.#config,
|
|
2519
|
-
me,
|
|
2520
|
-
String(callbackUrl)
|
|
2521
|
-
);
|
|
2518
|
+
res = await verifyEmailAddress(this.#config, me, String(callbackUrl));
|
|
2522
2519
|
return res;
|
|
2523
2520
|
} catch {
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
);
|
|
2521
|
+
const message = "Unable to verify email.";
|
|
2522
|
+
this.#logger?.warn(message);
|
|
2523
|
+
res = new Response(message, { status: 400 });
|
|
2527
2524
|
}
|
|
2528
2525
|
if (bypassEmail) {
|
|
2529
|
-
|
|
2526
|
+
res = this.updateSelf({ emailVerified: true }, rawResponse);
|
|
2530
2527
|
}
|
|
2531
2528
|
this.#logger.error(
|
|
2532
2529
|
"Unable to verify email address. Configure your SMTP server in the console."
|
|
2533
2530
|
);
|
|
2534
|
-
return
|
|
2531
|
+
return res;
|
|
2535
2532
|
}
|
|
2536
2533
|
};
|
|
2537
2534
|
async function verifyEmailAddress(config, user, callback) {
|
|
@@ -2842,7 +2839,8 @@ function updateConfig(response, config) {
|
|
|
2842
2839
|
return {
|
|
2843
2840
|
...config,
|
|
2844
2841
|
origin,
|
|
2845
|
-
headers: headers ?? void 0
|
|
2842
|
+
headers: headers ?? void 0,
|
|
2843
|
+
preserveHeaders: true
|
|
2846
2844
|
};
|
|
2847
2845
|
}
|
|
2848
2846
|
|
|
@@ -2857,12 +2855,22 @@ function bindHandleOnRequest(instance) {
|
|
|
2857
2855
|
}
|
|
2858
2856
|
const ext = await create2(instance);
|
|
2859
2857
|
if (ext.onRequest) {
|
|
2858
|
+
const previousContext = instance.getContext();
|
|
2859
|
+
if (previousContext.preserveHeaders) {
|
|
2860
|
+
instance.setContext({ preserveHeaders: false });
|
|
2861
|
+
}
|
|
2860
2862
|
await ext.onRequest(_init.request);
|
|
2861
2863
|
const updatedContext = instance.getContext();
|
|
2862
2864
|
if (updatedContext?.headers) {
|
|
2863
2865
|
const cookie = updatedContext.headers.get("cookie");
|
|
2864
2866
|
if (cookie) {
|
|
2865
|
-
params.headers.set(
|
|
2867
|
+
params.headers.set(
|
|
2868
|
+
"cookie",
|
|
2869
|
+
mergeCookies(
|
|
2870
|
+
previousContext.preserveHeaders ? previousContext.headers?.get("cookie") : null,
|
|
2871
|
+
updatedContext.headers.get("cookie")
|
|
2872
|
+
)
|
|
2873
|
+
);
|
|
2866
2874
|
}
|
|
2867
2875
|
if (updatedContext.tenantId) {
|
|
2868
2876
|
params.headers.set(
|
|
@@ -2882,6 +2890,17 @@ function buildExtensionConfig(instance) {
|
|
|
2882
2890
|
handleOnRequest: bindHandleOnRequest(instance)
|
|
2883
2891
|
};
|
|
2884
2892
|
}
|
|
2893
|
+
function mergeCookies(...cookieStrings) {
|
|
2894
|
+
const cookieMap = /* @__PURE__ */ new Map();
|
|
2895
|
+
for (const str of cookieStrings) {
|
|
2896
|
+
if (!str) continue;
|
|
2897
|
+
for (const part of str.split(";")) {
|
|
2898
|
+
const [key17, value] = part.split("=").map((s) => s.trim());
|
|
2899
|
+
if (key17 && value) cookieMap.set(key17, value);
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
return [...cookieMap.entries()].map(([k, v]) => `${k}=${v}`).join("; ");
|
|
2903
|
+
}
|
|
2885
2904
|
|
|
2886
2905
|
// src/Server.ts
|
|
2887
2906
|
var Server = class {
|
|
@@ -2893,6 +2912,7 @@ var Server = class {
|
|
|
2893
2912
|
#paths;
|
|
2894
2913
|
#manager;
|
|
2895
2914
|
#headers;
|
|
2915
|
+
#preserveHeaders;
|
|
2896
2916
|
constructor(config) {
|
|
2897
2917
|
this.#config = new Config({
|
|
2898
2918
|
...config,
|
|
@@ -2918,6 +2938,7 @@ var Server = class {
|
|
|
2918
2938
|
...this.#config.handlers,
|
|
2919
2939
|
withContext: handlersWithContext(this.#config)
|
|
2920
2940
|
};
|
|
2941
|
+
this.#preserveHeaders = config?.preserveHeaders ?? false;
|
|
2921
2942
|
this.#paths = this.#config.paths;
|
|
2922
2943
|
this.#config.tenantId = getTenantId({ config: this.#config });
|
|
2923
2944
|
this.#manager = new DBManager(this.#config);
|
|
@@ -2984,6 +3005,10 @@ var Server = class {
|
|
|
2984
3005
|
ok = true;
|
|
2985
3006
|
this.#config.userId = req.userId;
|
|
2986
3007
|
}
|
|
3008
|
+
if (req && typeof req === "object" && "preserveHeaders" in req) {
|
|
3009
|
+
ok = true;
|
|
3010
|
+
this.#preserveHeaders = Boolean(req.preserveHeaders);
|
|
3011
|
+
}
|
|
2987
3012
|
if (ok) {
|
|
2988
3013
|
return;
|
|
2989
3014
|
}
|
|
@@ -3006,7 +3031,8 @@ var Server = class {
|
|
|
3006
3031
|
return {
|
|
3007
3032
|
headers: this.#headers,
|
|
3008
3033
|
userId: this.#config.userId,
|
|
3009
|
-
tenantId: this.#config.tenantId
|
|
3034
|
+
tenantId: this.#config.tenantId,
|
|
3035
|
+
preserveHeaders: this.#preserveHeaders
|
|
3010
3036
|
};
|
|
3011
3037
|
}
|
|
3012
3038
|
/**
|