@niledatabase/server 5.0.0-alpha.1 → 5.0.0-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/express.js +102 -48
- package/dist/express.js.map +1 -1
- package/dist/express.mjs +102 -48
- package/dist/express.mjs.map +1 -1
- package/dist/index.d.mts +24 -3
- package/dist/index.d.ts +24 -3
- package/dist/index.js +658 -390
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +658 -390
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -33,7 +33,8 @@ var LoginUserResponseTokenTypeEnum = {
|
|
|
33
33
|
|
|
34
34
|
// src/api/utils/routes/index.ts
|
|
35
35
|
var NILEDB_API_URL = process.env.NILEDB_API_URL;
|
|
36
|
-
var
|
|
36
|
+
var DEFAULT_PREFIX = "/api";
|
|
37
|
+
var appRoutes = (prefix = DEFAULT_PREFIX) => ({
|
|
37
38
|
SIGNIN: `${prefix}${"/auth/signin" /* SIGNIN */}`,
|
|
38
39
|
PROVIDERS: `${prefix}${"/auth/providers" /* PROVIDERS */}`,
|
|
39
40
|
SESSION: `${prefix}${"/auth/session" /* SESSION */}`,
|
|
@@ -42,7 +43,8 @@ var appRoutes = (prefix = "/api") => ({
|
|
|
42
43
|
SIGNOUT: `${prefix}${"/auth/signout" /* SIGNOUT */}`,
|
|
43
44
|
ERROR: `${prefix}/auth/error`,
|
|
44
45
|
VERIFY_REQUEST: `${prefix}/auth/verify-request`,
|
|
45
|
-
|
|
46
|
+
VERIFY_EMAIL: `${prefix}${"/auth/verify-email" /* VERIFY_EMAIL */}`,
|
|
47
|
+
PASSWORD_RESET: `${prefix}${"/auth/reset-password" /* PASSWORD_RESET */}`,
|
|
46
48
|
ME: `${prefix}${"/me" /* ME */}`,
|
|
47
49
|
USERS: `${prefix}${"/users" /* USERS */}`,
|
|
48
50
|
USER_TENANTS: `${prefix}${"/users/{userId}/tenants" /* USER_TENANTS */}`,
|
|
@@ -76,7 +78,8 @@ var proxyRoutes = (config) => ({
|
|
|
76
78
|
SIGNOUT: makeRestUrl(config, "/auth/signout" /* SIGNOUT */),
|
|
77
79
|
ERROR: makeRestUrl(config, "/auth/error"),
|
|
78
80
|
VERIFY_REQUEST: makeRestUrl(config, "/auth/verify-request"),
|
|
79
|
-
PASSWORD_RESET: makeRestUrl(config, "/auth/reset-password")
|
|
81
|
+
PASSWORD_RESET: makeRestUrl(config, "/auth/reset-password" /* PASSWORD_RESET */),
|
|
82
|
+
VERIFY_EMAIL: makeRestUrl(config, "/auth/verify-email" /* VERIFY_EMAIL */)
|
|
80
83
|
});
|
|
81
84
|
function filterNullUndefined(obj) {
|
|
82
85
|
if (!obj) {
|
|
@@ -101,9 +104,9 @@ function makeRestUrl(config, path, qp) {
|
|
|
101
104
|
const strParams = params.toString();
|
|
102
105
|
return `${[url, path.substring(1, path.length)].join("/")}${strParams ? `?${strParams}` : ""}`;
|
|
103
106
|
}
|
|
104
|
-
function urlMatches(requestUrl,
|
|
107
|
+
function urlMatches(requestUrl, route17) {
|
|
105
108
|
const url = new URL(requestUrl);
|
|
106
|
-
return url.pathname.startsWith(
|
|
109
|
+
return url.pathname.startsWith(route17);
|
|
107
110
|
}
|
|
108
111
|
function isUUID(value) {
|
|
109
112
|
if (!value) {
|
|
@@ -173,9 +176,9 @@ function matchesLog(configRoutes, request2) {
|
|
|
173
176
|
}
|
|
174
177
|
|
|
175
178
|
// src/utils/constants.ts
|
|
176
|
-
var X_NILE_TENANT = "nile
|
|
177
|
-
var X_NILE_ORIGIN = "nile
|
|
178
|
-
var X_NILE_SECURECOOKIES = "nile
|
|
179
|
+
var X_NILE_TENANT = "nile-tenant-id";
|
|
180
|
+
var X_NILE_ORIGIN = "nile-origin";
|
|
181
|
+
var X_NILE_SECURECOOKIES = "nile-secure-cookies";
|
|
179
182
|
|
|
180
183
|
// src/api/utils/request.ts
|
|
181
184
|
async function request(url, _init, config) {
|
|
@@ -194,15 +197,29 @@ async function request(url, _init, config) {
|
|
|
194
197
|
}
|
|
195
198
|
if (config.secureCookies != null) {
|
|
196
199
|
updatedHeaders.set(X_NILE_SECURECOOKIES, String(config.secureCookies));
|
|
200
|
+
} else {
|
|
201
|
+
updatedHeaders.set(
|
|
202
|
+
X_NILE_SECURECOOKIES,
|
|
203
|
+
process.env.NODE_ENV === "production" ? "true" : "false"
|
|
204
|
+
);
|
|
197
205
|
}
|
|
198
206
|
updatedHeaders.set("host", requestUrl.host);
|
|
199
207
|
if (config.callbackUrl) {
|
|
200
208
|
const cbUrl = new URL(config.callbackUrl);
|
|
201
209
|
debug(`Obtained origin from config.callbackUrl ${config.callbackUrl}`);
|
|
202
210
|
updatedHeaders.set(X_NILE_ORIGIN, cbUrl.origin);
|
|
211
|
+
} else if (config.origin) {
|
|
212
|
+
debug(`Obtained origin from config.origin ${config.origin}`);
|
|
213
|
+
updatedHeaders.set(X_NILE_ORIGIN, config.origin);
|
|
203
214
|
} else {
|
|
204
|
-
|
|
205
|
-
|
|
215
|
+
const passedOrigin = request2.headers.get(X_NILE_ORIGIN);
|
|
216
|
+
if (passedOrigin) {
|
|
217
|
+
updatedHeaders.set(X_NILE_ORIGIN, passedOrigin);
|
|
218
|
+
} else {
|
|
219
|
+
const reqOrigin = config.routePrefix !== DEFAULT_PREFIX ? `${requestUrl.origin}${config.routePrefix}` : requestUrl.origin;
|
|
220
|
+
updatedHeaders.set(X_NILE_ORIGIN, reqOrigin);
|
|
221
|
+
debug(`Obtained origin from request ${reqOrigin}`);
|
|
222
|
+
}
|
|
206
223
|
}
|
|
207
224
|
const params = { ...init };
|
|
208
225
|
if (params.method?.toLowerCase() === "post" || params.method?.toLowerCase() === "put") {
|
|
@@ -306,7 +323,7 @@ function matches(configRoutes, request2) {
|
|
|
306
323
|
return urlMatches(request2.url, configRoutes[key]);
|
|
307
324
|
}
|
|
308
325
|
async function fetchMe(config, method, body) {
|
|
309
|
-
const clientUrl = `${config.
|
|
326
|
+
const clientUrl = `${config.serverOrigin}${config.routePrefix}${"/me" /* ME */}`;
|
|
310
327
|
const init = {
|
|
311
328
|
headers: config.headers,
|
|
312
329
|
method: method ?? "GET"
|
|
@@ -336,47 +353,6 @@ async function GET(url, init, config) {
|
|
|
336
353
|
return res;
|
|
337
354
|
}
|
|
338
355
|
|
|
339
|
-
// src/utils/Event/index.ts
|
|
340
|
-
var Eventer = class {
|
|
341
|
-
events = {};
|
|
342
|
-
publish(eventName, value) {
|
|
343
|
-
const callbacks = this.events[eventName];
|
|
344
|
-
if (callbacks) {
|
|
345
|
-
for (const callback of callbacks) {
|
|
346
|
-
callback(value);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
subscribe(eventName, callback) {
|
|
351
|
-
if (!this.events[eventName]) {
|
|
352
|
-
this.events[eventName] = [];
|
|
353
|
-
}
|
|
354
|
-
this.events[eventName].push(callback);
|
|
355
|
-
}
|
|
356
|
-
unsubscribe(eventName, callback) {
|
|
357
|
-
const callbacks = this.events[eventName];
|
|
358
|
-
if (!callbacks) return;
|
|
359
|
-
const index = callbacks.indexOf(callback);
|
|
360
|
-
if (index !== -1) {
|
|
361
|
-
callbacks.splice(index, 1);
|
|
362
|
-
}
|
|
363
|
-
if (callbacks.length === 0) {
|
|
364
|
-
delete this.events[eventName];
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
};
|
|
368
|
-
var eventer = new Eventer();
|
|
369
|
-
var watchTenantId = (cb) => eventer.subscribe("tenantId" /* Tenant */, cb);
|
|
370
|
-
var watchUserId = (cb) => eventer.subscribe("userId" /* User */, cb);
|
|
371
|
-
var evictPool = (val) => {
|
|
372
|
-
eventer.publish("EvictPool" /* EvictPool */, val);
|
|
373
|
-
};
|
|
374
|
-
var watchEvictPool = (cb) => eventer.subscribe("EvictPool" /* EvictPool */, cb);
|
|
375
|
-
var updateHeaders = (val) => {
|
|
376
|
-
eventer.publish("headers" /* Headers */, val);
|
|
377
|
-
};
|
|
378
|
-
var watchHeaders = (cb) => eventer.subscribe("headers" /* Headers */, cb);
|
|
379
|
-
|
|
380
356
|
// src/utils/fetch.ts
|
|
381
357
|
function getTokenFromCookie(headers, cookieKey) {
|
|
382
358
|
const cookie = headers.get("cookie")?.split("; ");
|
|
@@ -515,11 +491,11 @@ async function route3(request2, config) {
|
|
|
515
491
|
function matches3(configRoutes, request2) {
|
|
516
492
|
const url = new URL(request2.url);
|
|
517
493
|
const [userId, possibleTenantId, tenantId] = url.pathname.split("/").reverse();
|
|
518
|
-
let
|
|
494
|
+
let route17 = configRoutes[key3].replace("{tenantId}", tenantId).replace("{userId}", userId);
|
|
519
495
|
if (userId === "users") {
|
|
520
|
-
|
|
496
|
+
route17 = configRoutes[key3].replace("{tenantId}", possibleTenantId);
|
|
521
497
|
}
|
|
522
|
-
return urlMatches(request2.url,
|
|
498
|
+
return urlMatches(request2.url, route17);
|
|
523
499
|
}
|
|
524
500
|
async function fetchTenantUsers(config, method, payload) {
|
|
525
501
|
const { body, params } = {};
|
|
@@ -540,7 +516,7 @@ async function fetchTenantUsers(config, method, payload) {
|
|
|
540
516
|
if (params?.tenantId) {
|
|
541
517
|
q.set("tenantId", params.tenantId);
|
|
542
518
|
}
|
|
543
|
-
const clientUrl = `${config.
|
|
519
|
+
const clientUrl = `${config.serverOrigin}${config.routePrefix}${"/tenants/{tenantId}/users" /* TENANT_USERS */.replace(
|
|
544
520
|
"{tenantId}",
|
|
545
521
|
config.tenantId
|
|
546
522
|
)}`;
|
|
@@ -642,7 +618,7 @@ function matches4(configRoutes, request2) {
|
|
|
642
618
|
return urlMatches(request2.url, configRoutes[key4]);
|
|
643
619
|
}
|
|
644
620
|
async function fetchTenants(config, method, body) {
|
|
645
|
-
const clientUrl = `${config.
|
|
621
|
+
const clientUrl = `${config.serverOrigin}${config.routePrefix}${"/tenants" /* TENANTS */}`;
|
|
646
622
|
const init = {
|
|
647
623
|
method,
|
|
648
624
|
headers: config.headers
|
|
@@ -664,7 +640,7 @@ async function fetchTenant(config, method, body) {
|
|
|
664
640
|
"nile.tenantId is not a valid UUID. This may lead to unexpected behavior in your application."
|
|
665
641
|
);
|
|
666
642
|
}
|
|
667
|
-
const clientUrl = `${config.
|
|
643
|
+
const clientUrl = `${config.serverOrigin}${config.routePrefix}${"/tenants/{tenantId}" /* TENANT */.replace("{tenantId}", config.tenantId)}`;
|
|
668
644
|
const m = method ?? "GET";
|
|
669
645
|
const init = {
|
|
670
646
|
method: m,
|
|
@@ -688,7 +664,7 @@ async function fetchTenantsByUser(config) {
|
|
|
688
664
|
);
|
|
689
665
|
}
|
|
690
666
|
}
|
|
691
|
-
const clientUrl = `${config.
|
|
667
|
+
const clientUrl = `${config.serverOrigin}${config.routePrefix}${"/users/{userId}/tenants" /* USER_TENANTS */.replace(
|
|
692
668
|
"{userId}",
|
|
693
669
|
config.userId ?? "WARN_NOT_SET"
|
|
694
670
|
)}`;
|
|
@@ -718,7 +694,7 @@ function matches5(configRoutes, request2) {
|
|
|
718
694
|
return urlMatches(request2.url, configRoutes[key5]);
|
|
719
695
|
}
|
|
720
696
|
async function fetchSignIn(config, provider, body) {
|
|
721
|
-
const clientUrl = `${config.
|
|
697
|
+
const clientUrl = `${config.serverOrigin}${config.routePrefix}${"/auth/signin" /* SIGNIN */}/${provider}`;
|
|
722
698
|
const req = new Request(clientUrl, {
|
|
723
699
|
method: "POST",
|
|
724
700
|
headers: config.headers,
|
|
@@ -742,7 +718,7 @@ function matches6(configRoutes, request2) {
|
|
|
742
718
|
return urlMatches(request2.url, configRoutes.SESSION);
|
|
743
719
|
}
|
|
744
720
|
async function fetchSession(config) {
|
|
745
|
-
const clientUrl = `${config.
|
|
721
|
+
const clientUrl = `${config.serverOrigin}${config.routePrefix}${"/auth/session" /* SESSION */}`;
|
|
746
722
|
const req = new Request(clientUrl, {
|
|
747
723
|
method: "GET",
|
|
748
724
|
headers: config.headers
|
|
@@ -765,7 +741,7 @@ function matches7(configRoutes, request2) {
|
|
|
765
741
|
return urlMatches(request2.url, configRoutes.PROVIDERS);
|
|
766
742
|
}
|
|
767
743
|
async function fetchProviders(config) {
|
|
768
|
-
const clientUrl = `${config.
|
|
744
|
+
const clientUrl = `${config.serverOrigin}${config.routePrefix}${"/auth/providers" /* PROVIDERS */}`;
|
|
769
745
|
const req = new Request(clientUrl, {
|
|
770
746
|
method: "GET",
|
|
771
747
|
headers: config.headers
|
|
@@ -788,7 +764,7 @@ function matches8(configRoutes, request2) {
|
|
|
788
764
|
return urlMatches(request2.url, configRoutes.CSRF);
|
|
789
765
|
}
|
|
790
766
|
async function fetchCsrf(config) {
|
|
791
|
-
const clientUrl = `${config.
|
|
767
|
+
const clientUrl = `${config.serverOrigin}${config.routePrefix}${"/auth/csrf" /* CSRF */}`;
|
|
792
768
|
const req = new Request(clientUrl, {
|
|
793
769
|
method: "GET",
|
|
794
770
|
headers: config.headers
|
|
@@ -837,10 +813,10 @@ async function route9(req, config) {
|
|
|
837
813
|
function matches9(configRoutes, request2) {
|
|
838
814
|
return urlMatches(request2.url, configRoutes.CALLBACK);
|
|
839
815
|
}
|
|
840
|
-
async function fetchCallback(config, provider, body) {
|
|
841
|
-
const clientUrl = `${config.
|
|
816
|
+
async function fetchCallback(config, provider, body, request2, method = "POST") {
|
|
817
|
+
const clientUrl = `${config.serverOrigin}${config.routePrefix}${"/auth/callback" /* CALLBACK */}/${provider}${request2 ? `?${new URL(request2.url).searchParams}` : ""}`;
|
|
842
818
|
const req = new Request(clientUrl, {
|
|
843
|
-
method
|
|
819
|
+
method,
|
|
844
820
|
headers: config.headers,
|
|
845
821
|
body
|
|
846
822
|
});
|
|
@@ -866,7 +842,7 @@ function matches10(configRoutes, request2) {
|
|
|
866
842
|
return urlMatches(request2.url, configRoutes[key7]);
|
|
867
843
|
}
|
|
868
844
|
async function fetchSignOut(config, body) {
|
|
869
|
-
const clientUrl = `${config.
|
|
845
|
+
const clientUrl = `${config.serverOrigin}${config.routePrefix}${"/auth/signout" /* SIGNOUT */}`;
|
|
870
846
|
const req = new Request(clientUrl, {
|
|
871
847
|
method: "POST",
|
|
872
848
|
body,
|
|
@@ -934,6 +910,60 @@ async function route13(req, config) {
|
|
|
934
910
|
function matches13(configRoutes, request2) {
|
|
935
911
|
return urlMatches(request2.url, configRoutes.PASSWORD_RESET);
|
|
936
912
|
}
|
|
913
|
+
async function fetchResetPassword(config, method, body, params) {
|
|
914
|
+
const authParams = new URLSearchParams(params ?? {});
|
|
915
|
+
authParams?.set("json", "true");
|
|
916
|
+
const clientUrl = `${config.serverOrigin}${config.routePrefix}${"/auth/reset-password" /* PASSWORD_RESET */}?${authParams?.toString()}`;
|
|
917
|
+
const init = {
|
|
918
|
+
method,
|
|
919
|
+
headers: config.headers
|
|
920
|
+
};
|
|
921
|
+
if (body && method !== "GET") {
|
|
922
|
+
init.body = body;
|
|
923
|
+
}
|
|
924
|
+
const req = new Request(clientUrl, init);
|
|
925
|
+
return await config.handlers[method](req);
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
// src/api/routes/auth/verify-email.ts
|
|
929
|
+
var key11 = "VERIFY_EMAIL";
|
|
930
|
+
async function route14(req, config) {
|
|
931
|
+
const url = proxyRoutes(config)[key11];
|
|
932
|
+
const res = await request(
|
|
933
|
+
url,
|
|
934
|
+
{
|
|
935
|
+
method: req.method,
|
|
936
|
+
request: req
|
|
937
|
+
},
|
|
938
|
+
config
|
|
939
|
+
);
|
|
940
|
+
const location = res?.headers.get("location");
|
|
941
|
+
if (location) {
|
|
942
|
+
return new Response(res?.body, {
|
|
943
|
+
status: 302,
|
|
944
|
+
headers: res?.headers
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
return new Response(res?.body, {
|
|
948
|
+
status: res?.status,
|
|
949
|
+
headers: res?.headers
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
function matches14(configRoutes, request2) {
|
|
953
|
+
return urlMatches(request2.url, configRoutes[key11]);
|
|
954
|
+
}
|
|
955
|
+
async function fetchVerifyEmail(config, method, body) {
|
|
956
|
+
const clientUrl = `${config.serverOrigin}${config.routePrefix}${"/auth/verify-email" /* VERIFY_EMAIL */}`;
|
|
957
|
+
const init = {
|
|
958
|
+
method,
|
|
959
|
+
headers: config.headers
|
|
960
|
+
};
|
|
961
|
+
if (body) {
|
|
962
|
+
init.body = body;
|
|
963
|
+
}
|
|
964
|
+
const req = new Request(clientUrl, init);
|
|
965
|
+
return await config.handlers[method](req);
|
|
966
|
+
}
|
|
937
967
|
|
|
938
968
|
// src/api/handlers/GET.ts
|
|
939
969
|
function GETTER(configRoutes, config) {
|
|
@@ -987,6 +1017,10 @@ function GETTER(configRoutes, config) {
|
|
|
987
1017
|
info("matches verify-request");
|
|
988
1018
|
return route12(req, config);
|
|
989
1019
|
}
|
|
1020
|
+
if (matches14(configRoutes, req)) {
|
|
1021
|
+
info("matches verify-email");
|
|
1022
|
+
return route14(req, config);
|
|
1023
|
+
}
|
|
990
1024
|
if (matches11(configRoutes, req)) {
|
|
991
1025
|
info("matches error");
|
|
992
1026
|
return route11(req, config);
|
|
@@ -1005,8 +1039,8 @@ async function POST4(config, init) {
|
|
|
1005
1039
|
}
|
|
1006
1040
|
|
|
1007
1041
|
// src/api/routes/signup/index.tsx
|
|
1008
|
-
var
|
|
1009
|
-
async function
|
|
1042
|
+
var key12 = "SIGNUP";
|
|
1043
|
+
async function route15(request2, config) {
|
|
1010
1044
|
switch (request2.method) {
|
|
1011
1045
|
case "POST":
|
|
1012
1046
|
return await POST4(config, { request: request2 });
|
|
@@ -1014,8 +1048,8 @@ async function route14(request2, config) {
|
|
|
1014
1048
|
return new Response("method not allowed", { status: 405 });
|
|
1015
1049
|
}
|
|
1016
1050
|
}
|
|
1017
|
-
function
|
|
1018
|
-
return urlMatches(request2.url, configRoutes[
|
|
1051
|
+
function matches15(configRoutes, request2) {
|
|
1052
|
+
return urlMatches(request2.url, configRoutes[key12]);
|
|
1019
1053
|
}
|
|
1020
1054
|
async function fetchSignUp(config, payload) {
|
|
1021
1055
|
const { body, params } = payload ?? {};
|
|
@@ -1026,7 +1060,7 @@ async function fetchSignUp(config, payload) {
|
|
|
1026
1060
|
if (params?.tenantId) {
|
|
1027
1061
|
q.set("tenantId", params.tenantId);
|
|
1028
1062
|
}
|
|
1029
|
-
const clientUrl = `${config.
|
|
1063
|
+
const clientUrl = `${config.serverOrigin}${config.routePrefix}${"/signup" /* SIGNUP */}${q.size > 0 ? `?${q}` : ""}`;
|
|
1030
1064
|
const req = new Request(clientUrl, {
|
|
1031
1065
|
method: "POST",
|
|
1032
1066
|
headers: config.headers,
|
|
@@ -1040,24 +1074,21 @@ function POSTER(configRoutes, config) {
|
|
|
1040
1074
|
const { info, warn, error } = Logger(config, "[POST MATCHER]");
|
|
1041
1075
|
return async function POST5(req) {
|
|
1042
1076
|
if (matchesLog(configRoutes, req)) {
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
status: 200
|
|
1049
|
-
});
|
|
1050
|
-
} catch (e) {
|
|
1051
|
-
}
|
|
1077
|
+
try {
|
|
1078
|
+
const json = await req.clone().json();
|
|
1079
|
+
error(req.body && json);
|
|
1080
|
+
} catch {
|
|
1081
|
+
error(await req.text());
|
|
1052
1082
|
}
|
|
1083
|
+
return new Response(null, { status: 200 });
|
|
1053
1084
|
}
|
|
1054
1085
|
if (matches3(configRoutes, req)) {
|
|
1055
1086
|
info("matches tenant users");
|
|
1056
1087
|
return route3(req, config);
|
|
1057
1088
|
}
|
|
1058
|
-
if (
|
|
1089
|
+
if (matches15(configRoutes, req)) {
|
|
1059
1090
|
info("matches signup");
|
|
1060
|
-
return
|
|
1091
|
+
return route15(req, config);
|
|
1061
1092
|
}
|
|
1062
1093
|
if (matches2(configRoutes, req)) {
|
|
1063
1094
|
info("matches users");
|
|
@@ -1095,6 +1126,10 @@ function POSTER(configRoutes, config) {
|
|
|
1095
1126
|
info("matches signout");
|
|
1096
1127
|
return route10(req, config);
|
|
1097
1128
|
}
|
|
1129
|
+
if (matches14(configRoutes, req)) {
|
|
1130
|
+
info("matches verify-email");
|
|
1131
|
+
return route14(req, config);
|
|
1132
|
+
}
|
|
1098
1133
|
warn(`No POST routes matched ${req.url}`);
|
|
1099
1134
|
return new Response(null, { status: 404 });
|
|
1100
1135
|
};
|
|
@@ -1123,11 +1158,11 @@ async function PUT4(config, init) {
|
|
|
1123
1158
|
}
|
|
1124
1159
|
|
|
1125
1160
|
// src/api/routes/tenants/[tenantId]/users/[userId]/index.ts
|
|
1126
|
-
var
|
|
1127
|
-
async function
|
|
1161
|
+
var key13 = "TENANT_USER";
|
|
1162
|
+
async function route16(request2, config) {
|
|
1128
1163
|
const { info } = Logger(
|
|
1129
1164
|
{ ...config, debug: config.debug },
|
|
1130
|
-
`[ROUTES][${
|
|
1165
|
+
`[ROUTES][${key13}]`
|
|
1131
1166
|
);
|
|
1132
1167
|
const session = await auth(request2, config);
|
|
1133
1168
|
if (!session) {
|
|
@@ -1149,14 +1184,14 @@ async function route15(request2, config) {
|
|
|
1149
1184
|
return new Response("method not allowed", { status: 405 });
|
|
1150
1185
|
}
|
|
1151
1186
|
}
|
|
1152
|
-
function
|
|
1187
|
+
function matches16(configRoutes, request2) {
|
|
1153
1188
|
const url = new URL(request2.url);
|
|
1154
1189
|
const [, userId, possibleTenantId, tenantId] = url.pathname.split("/").reverse();
|
|
1155
|
-
let
|
|
1190
|
+
let route17 = configRoutes[key13].replace("{tenantId}", tenantId).replace("{userId}", userId);
|
|
1156
1191
|
if (userId === "users") {
|
|
1157
|
-
|
|
1192
|
+
route17 = configRoutes[key13].replace("{tenantId}", possibleTenantId);
|
|
1158
1193
|
}
|
|
1159
|
-
return urlMatches(request2.url,
|
|
1194
|
+
return urlMatches(request2.url, route17);
|
|
1160
1195
|
}
|
|
1161
1196
|
async function fetchTenantUser(config, method) {
|
|
1162
1197
|
if (!config.tenantId) {
|
|
@@ -1169,7 +1204,7 @@ async function fetchTenantUser(config, method) {
|
|
|
1169
1204
|
"the userId context is missing. Call nile.setContext({ userId })"
|
|
1170
1205
|
);
|
|
1171
1206
|
}
|
|
1172
|
-
const clientUrl = `${config.
|
|
1207
|
+
const clientUrl = `${config.serverOrigin}${config.routePrefix}${"/tenants/{tenantId}/users/{userId}" /* TENANT_USER */.replace(
|
|
1173
1208
|
"{tenantId}",
|
|
1174
1209
|
config.tenantId
|
|
1175
1210
|
).replace("{userId}", config.userId)}/link`;
|
|
@@ -1184,9 +1219,9 @@ async function fetchTenantUser(config, method) {
|
|
|
1184
1219
|
function DELETER(configRoutes, config) {
|
|
1185
1220
|
const { info, warn } = Logger(config, "[DELETE MATCHER]");
|
|
1186
1221
|
return async function DELETE4(req) {
|
|
1187
|
-
if (
|
|
1222
|
+
if (matches16(configRoutes, req)) {
|
|
1188
1223
|
info("matches tenant user");
|
|
1189
|
-
return
|
|
1224
|
+
return route16(req, config);
|
|
1190
1225
|
}
|
|
1191
1226
|
if (matches3(configRoutes, req)) {
|
|
1192
1227
|
info("matches tenant users");
|
|
@@ -1209,9 +1244,9 @@ function DELETER(configRoutes, config) {
|
|
|
1209
1244
|
function PUTER(configRoutes, config) {
|
|
1210
1245
|
const { info, warn } = Logger(config, "[PUT MATCHER]");
|
|
1211
1246
|
return async function PUT5(req) {
|
|
1212
|
-
if (
|
|
1247
|
+
if (matches16(configRoutes, req)) {
|
|
1213
1248
|
info("matches tenant user");
|
|
1214
|
-
return
|
|
1249
|
+
return route16(req, config);
|
|
1215
1250
|
}
|
|
1216
1251
|
if (matches3(configRoutes, req)) {
|
|
1217
1252
|
info("matches tenant users");
|
|
@@ -1429,7 +1464,6 @@ var stringCheck = (str) => {
|
|
|
1429
1464
|
// src/utils/Config/index.ts
|
|
1430
1465
|
var Config = class {
|
|
1431
1466
|
routes;
|
|
1432
|
-
// handlersWithContext;
|
|
1433
1467
|
handlers;
|
|
1434
1468
|
paths;
|
|
1435
1469
|
logger;
|
|
@@ -1450,6 +1484,10 @@ var Config = class {
|
|
|
1450
1484
|
*/
|
|
1451
1485
|
apiUrl;
|
|
1452
1486
|
origin;
|
|
1487
|
+
/**
|
|
1488
|
+
* important for separating the `origin` config value from a default in order to make requests
|
|
1489
|
+
*/
|
|
1490
|
+
serverOrigin;
|
|
1453
1491
|
debug;
|
|
1454
1492
|
/**
|
|
1455
1493
|
* To use secure cookies or not in the fetch
|
|
@@ -1468,7 +1506,8 @@ var Config = class {
|
|
|
1468
1506
|
this.secureCookies = getSecureCookies(envVarConfig);
|
|
1469
1507
|
this.callbackUrl = getCallbackUrl(envVarConfig);
|
|
1470
1508
|
this.debug = config?.debug;
|
|
1471
|
-
this.origin = config?.origin
|
|
1509
|
+
this.origin = config?.origin;
|
|
1510
|
+
this.serverOrigin = config?.origin ?? "http://localhost:3000";
|
|
1472
1511
|
this.apiUrl = getApiUrl(envVarConfig);
|
|
1473
1512
|
const user = getUsername(envVarConfig);
|
|
1474
1513
|
const password = getPassword(envVarConfig);
|
|
@@ -1539,6 +1578,47 @@ var Config = class {
|
|
|
1539
1578
|
}
|
|
1540
1579
|
};
|
|
1541
1580
|
|
|
1581
|
+
// src/utils/Event/index.ts
|
|
1582
|
+
var Eventer = class {
|
|
1583
|
+
events = {};
|
|
1584
|
+
publish(eventName, value) {
|
|
1585
|
+
const callbacks = this.events[eventName];
|
|
1586
|
+
if (callbacks) {
|
|
1587
|
+
for (const callback of callbacks) {
|
|
1588
|
+
callback(value);
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
subscribe(eventName, callback) {
|
|
1593
|
+
if (!this.events[eventName]) {
|
|
1594
|
+
this.events[eventName] = [];
|
|
1595
|
+
}
|
|
1596
|
+
this.events[eventName].push(callback);
|
|
1597
|
+
}
|
|
1598
|
+
unsubscribe(eventName, callback) {
|
|
1599
|
+
const callbacks = this.events[eventName];
|
|
1600
|
+
if (!callbacks) return;
|
|
1601
|
+
const index = callbacks.indexOf(callback);
|
|
1602
|
+
if (index !== -1) {
|
|
1603
|
+
callbacks.splice(index, 1);
|
|
1604
|
+
}
|
|
1605
|
+
if (callbacks.length === 0) {
|
|
1606
|
+
delete this.events[eventName];
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
};
|
|
1610
|
+
var eventer = new Eventer();
|
|
1611
|
+
var watchTenantId = (cb) => eventer.subscribe("tenantId" /* Tenant */, cb);
|
|
1612
|
+
var watchUserId = (cb) => eventer.subscribe("userId" /* User */, cb);
|
|
1613
|
+
var evictPool = (val) => {
|
|
1614
|
+
eventer.publish("EvictPool" /* EvictPool */, val);
|
|
1615
|
+
};
|
|
1616
|
+
var watchEvictPool = (cb) => eventer.subscribe("EvictPool" /* EvictPool */, cb);
|
|
1617
|
+
var updateHeaders = (val) => {
|
|
1618
|
+
eventer.publish("headers" /* Headers */, val);
|
|
1619
|
+
};
|
|
1620
|
+
var watchHeaders = (cb) => eventer.subscribe("headers" /* Headers */, cb);
|
|
1621
|
+
|
|
1542
1622
|
// src/db/PoolProxy.ts
|
|
1543
1623
|
function createProxyForPool(pool, config) {
|
|
1544
1624
|
const { info, error } = Logger(config, "[pool]");
|
|
@@ -1763,336 +1843,247 @@ var DBManager = class {
|
|
|
1763
1843
|
};
|
|
1764
1844
|
};
|
|
1765
1845
|
|
|
1766
|
-
// src/
|
|
1767
|
-
var
|
|
1846
|
+
// src/auth/index.ts
|
|
1847
|
+
var Auth = class {
|
|
1848
|
+
#logger;
|
|
1768
1849
|
#config;
|
|
1769
1850
|
constructor(config) {
|
|
1770
1851
|
this.#config = config;
|
|
1852
|
+
this.#logger = Logger(config, "[auth]");
|
|
1771
1853
|
}
|
|
1772
|
-
async
|
|
1773
|
-
const res = await
|
|
1854
|
+
async getSession(rawResponse = false) {
|
|
1855
|
+
const res = await fetchSession(this.#config);
|
|
1774
1856
|
if (rawResponse) {
|
|
1775
1857
|
return res;
|
|
1776
1858
|
}
|
|
1777
1859
|
try {
|
|
1778
|
-
|
|
1860
|
+
const session = await res.clone().json();
|
|
1861
|
+
if (Object.keys(session).length === 0) {
|
|
1862
|
+
return void 0;
|
|
1863
|
+
}
|
|
1864
|
+
return session;
|
|
1779
1865
|
} catch {
|
|
1780
1866
|
return res;
|
|
1781
1867
|
}
|
|
1782
1868
|
}
|
|
1783
|
-
async
|
|
1784
|
-
|
|
1785
|
-
if ("id" in me) {
|
|
1786
|
-
this.#config.userId = me.id;
|
|
1787
|
-
}
|
|
1788
|
-
const res = await fetchMe(this.#config, "DELETE");
|
|
1789
|
-
updateHeaders(new Headers());
|
|
1790
|
-
return res;
|
|
1869
|
+
async getCsrf(rawResponse = false) {
|
|
1870
|
+
return await getCsrf(this.#config, rawResponse);
|
|
1791
1871
|
}
|
|
1792
|
-
async
|
|
1793
|
-
const res = await
|
|
1872
|
+
async listProviders(rawResponse = false) {
|
|
1873
|
+
const res = await fetchProviders(this.#config);
|
|
1794
1874
|
if (rawResponse) {
|
|
1795
1875
|
return res;
|
|
1796
1876
|
}
|
|
1797
1877
|
try {
|
|
1798
|
-
return await res
|
|
1878
|
+
return await res.clone().json();
|
|
1799
1879
|
} catch {
|
|
1800
1880
|
return res;
|
|
1801
1881
|
}
|
|
1802
1882
|
}
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1883
|
+
async signOut() {
|
|
1884
|
+
const csrfRes = await this.getCsrf();
|
|
1885
|
+
if (!("csrfToken" in csrfRes)) {
|
|
1886
|
+
throw new Error("Unable to obtain CSRF token. Sign out failed.");
|
|
1887
|
+
}
|
|
1888
|
+
const body = JSON.stringify({
|
|
1889
|
+
csrfToken: csrfRes.csrfToken,
|
|
1890
|
+
json: true
|
|
1891
|
+
});
|
|
1892
|
+
const res = await fetchSignOut(this.#config, body);
|
|
1893
|
+
updateHeaders(new Headers({}));
|
|
1894
|
+
this.#config.headers = new Headers();
|
|
1895
|
+
return res;
|
|
1812
1896
|
}
|
|
1813
|
-
async
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
"
|
|
1819
|
-
JSON.stringify({ name: req })
|
|
1897
|
+
async signUp(payload, rawResponse) {
|
|
1898
|
+
this.#config.headers = new Headers();
|
|
1899
|
+
const { email, password, ...params } = payload;
|
|
1900
|
+
if (!email || !password) {
|
|
1901
|
+
throw new Error(
|
|
1902
|
+
"Server side sign up requires a user email and password."
|
|
1820
1903
|
);
|
|
1821
|
-
} else if (typeof req === "object" && ("name" in req || "id" in req)) {
|
|
1822
|
-
res = await fetchTenants(this.#config, "POST", JSON.stringify(req));
|
|
1823
1904
|
}
|
|
1905
|
+
const providers = await this.listProviders();
|
|
1906
|
+
const { credentials } = providers ?? {};
|
|
1907
|
+
if (!credentials) {
|
|
1908
|
+
throw new Error(
|
|
1909
|
+
"Unable to obtain credential provider. Aborting server side sign up."
|
|
1910
|
+
);
|
|
1911
|
+
}
|
|
1912
|
+
const csrf = await this.getCsrf();
|
|
1913
|
+
let csrfToken;
|
|
1914
|
+
if ("csrfToken" in csrf) {
|
|
1915
|
+
csrfToken = csrf.csrfToken;
|
|
1916
|
+
} else {
|
|
1917
|
+
throw new Error("Unable to obtain parse CSRF. Request blocked.");
|
|
1918
|
+
}
|
|
1919
|
+
const body = JSON.stringify({
|
|
1920
|
+
email,
|
|
1921
|
+
password,
|
|
1922
|
+
csrfToken,
|
|
1923
|
+
callbackUrl: credentials.callbackUrl
|
|
1924
|
+
});
|
|
1925
|
+
const res = await fetchSignUp(this.#config, { body, params });
|
|
1926
|
+
if (res.status > 299) {
|
|
1927
|
+
this.#logger.error(await res.clone().text());
|
|
1928
|
+
return void 0;
|
|
1929
|
+
}
|
|
1930
|
+
const token = parseToken(res.headers);
|
|
1931
|
+
if (!token) {
|
|
1932
|
+
throw new Error("Server side sign up failed. Session token not found");
|
|
1933
|
+
}
|
|
1934
|
+
this.#config.headers?.append("cookie", token);
|
|
1935
|
+
updateHeaders(this.#config.headers);
|
|
1824
1936
|
if (rawResponse) {
|
|
1825
1937
|
return res;
|
|
1826
1938
|
}
|
|
1827
1939
|
try {
|
|
1828
|
-
return await res
|
|
1829
|
-
} catch {
|
|
1830
|
-
return res;
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
async delete(req) {
|
|
1834
|
-
if (typeof req === "string") {
|
|
1835
|
-
this.#config.tenantId = req;
|
|
1836
|
-
}
|
|
1837
|
-
if (typeof req === "object" && "id" in req) {
|
|
1838
|
-
this.#config.tenantId = req.id;
|
|
1839
|
-
}
|
|
1840
|
-
const res = await fetchTenant(this.#config, "DELETE");
|
|
1841
|
-
return res;
|
|
1842
|
-
}
|
|
1843
|
-
async get(req, rawResponse) {
|
|
1844
|
-
if (typeof req === "string") {
|
|
1845
|
-
this.#config.tenantId = req;
|
|
1846
|
-
} else if (typeof req === "object" && "id" in req) {
|
|
1847
|
-
this.#config.tenantId = req.id;
|
|
1848
|
-
}
|
|
1849
|
-
const res = await fetchTenant(this.#config, "GET");
|
|
1850
|
-
if (rawResponse === true || req === true) {
|
|
1851
|
-
return res;
|
|
1852
|
-
}
|
|
1853
|
-
try {
|
|
1854
|
-
return await res?.clone().json();
|
|
1940
|
+
return await res.clone().json();
|
|
1855
1941
|
} catch {
|
|
1856
1942
|
return res;
|
|
1857
1943
|
}
|
|
1858
1944
|
}
|
|
1859
|
-
async
|
|
1860
|
-
let
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1945
|
+
async resetPassword(req) {
|
|
1946
|
+
let email = "";
|
|
1947
|
+
let password = "";
|
|
1948
|
+
let callbackUrl = null;
|
|
1949
|
+
let redirectUrl = null;
|
|
1950
|
+
if (req instanceof Request) {
|
|
1951
|
+
const body2 = await req.json();
|
|
1952
|
+
email = body2.email;
|
|
1953
|
+
password = body2.password;
|
|
1954
|
+
const cbFromHeaders = parseCallback(req.headers);
|
|
1955
|
+
if (cbFromHeaders) {
|
|
1956
|
+
callbackUrl = cbFromHeaders;
|
|
1865
1957
|
}
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
try {
|
|
1872
|
-
return await res?.clone().json();
|
|
1873
|
-
} catch {
|
|
1874
|
-
return res;
|
|
1875
|
-
}
|
|
1876
|
-
}
|
|
1877
|
-
async list(req) {
|
|
1878
|
-
const res = await fetchTenantsByUser(this.#config);
|
|
1879
|
-
if (req === true) {
|
|
1880
|
-
return res;
|
|
1881
|
-
}
|
|
1882
|
-
try {
|
|
1883
|
-
return await res?.clone().json();
|
|
1884
|
-
} catch {
|
|
1885
|
-
return res;
|
|
1886
|
-
}
|
|
1887
|
-
}
|
|
1888
|
-
async leaveTenant(req) {
|
|
1889
|
-
const me = await fetchMe(this.#config);
|
|
1890
|
-
try {
|
|
1891
|
-
const json = await me.json();
|
|
1892
|
-
if ("id" in json) {
|
|
1893
|
-
this.#config.userId = json.id;
|
|
1958
|
+
if (body2.callbackUrl) {
|
|
1959
|
+
callbackUrl = body2.callbackUrl;
|
|
1960
|
+
}
|
|
1961
|
+
if (body2.redirectUrl) {
|
|
1962
|
+
redirectUrl = body2.redirectUrl;
|
|
1894
1963
|
}
|
|
1895
|
-
} catch {
|
|
1896
|
-
}
|
|
1897
|
-
if (typeof req === "string") {
|
|
1898
|
-
this.#config.tenantId = req;
|
|
1899
|
-
} else {
|
|
1900
|
-
this.#handleContext(req);
|
|
1901
|
-
}
|
|
1902
|
-
return await fetchTenantUser(this.#config, "DELETE");
|
|
1903
|
-
}
|
|
1904
|
-
async addMember(req, rawResponse) {
|
|
1905
|
-
if (typeof req === "string") {
|
|
1906
|
-
this.#config.userId = req;
|
|
1907
1964
|
} else {
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
const res = await fetchTenantUser(this.#config, "PUT");
|
|
1911
|
-
return responseHandler(res, rawResponse);
|
|
1912
|
-
}
|
|
1913
|
-
async removeMember(req, rawResponse) {
|
|
1914
|
-
this.#handleContext(req);
|
|
1915
|
-
const res = await fetchTenantUser(this.#config, "DELETE");
|
|
1916
|
-
return responseHandler(res, rawResponse);
|
|
1917
|
-
}
|
|
1918
|
-
async users(req, rawResponse) {
|
|
1919
|
-
this.#handleContext(req);
|
|
1920
|
-
const res = await fetchTenantUsers(this.#config, "GET");
|
|
1921
|
-
return responseHandler(
|
|
1922
|
-
res,
|
|
1923
|
-
rawResponse || typeof req === "boolean" && req
|
|
1924
|
-
);
|
|
1925
|
-
}
|
|
1926
|
-
#handleContext(req) {
|
|
1927
|
-
if (typeof req === "object") {
|
|
1928
|
-
if ("tenantId" in req) {
|
|
1929
|
-
this.#config.tenantId = req.tenantId;
|
|
1965
|
+
if ("email" in req) {
|
|
1966
|
+
email = req.email;
|
|
1930
1967
|
}
|
|
1931
|
-
if ("
|
|
1932
|
-
|
|
1968
|
+
if ("password" in req) {
|
|
1969
|
+
password = req.password;
|
|
1933
1970
|
}
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
};
|
|
1937
|
-
async function responseHandler(res, rawResponse) {
|
|
1938
|
-
if (rawResponse) {
|
|
1939
|
-
return res;
|
|
1940
|
-
}
|
|
1941
|
-
try {
|
|
1942
|
-
return await res?.clone().json();
|
|
1943
|
-
} catch {
|
|
1944
|
-
return res;
|
|
1945
|
-
}
|
|
1946
|
-
}
|
|
1947
|
-
|
|
1948
|
-
// src/auth/index.ts
|
|
1949
|
-
var Auth = class {
|
|
1950
|
-
#logger;
|
|
1951
|
-
#config;
|
|
1952
|
-
constructor(config) {
|
|
1953
|
-
this.#config = config;
|
|
1954
|
-
this.#logger = Logger(config, "[auth]");
|
|
1955
|
-
}
|
|
1956
|
-
async getSession(rawResponse = false) {
|
|
1957
|
-
const res = await fetchSession(this.#config);
|
|
1958
|
-
if (rawResponse) {
|
|
1959
|
-
return res;
|
|
1960
|
-
}
|
|
1961
|
-
try {
|
|
1962
|
-
const session = await res.clone().json();
|
|
1963
|
-
if (Object.keys(session).length === 0) {
|
|
1964
|
-
return void 0;
|
|
1971
|
+
if ("callbackUrl" in req) {
|
|
1972
|
+
callbackUrl = req.callbackUrl ? req.callbackUrl : null;
|
|
1965
1973
|
}
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
return res;
|
|
1969
|
-
}
|
|
1970
|
-
}
|
|
1971
|
-
async getCsrf(rawResponse = false) {
|
|
1972
|
-
const res = await fetchCsrf(this.#config);
|
|
1973
|
-
const csrfCook = parseCSRF(res.headers);
|
|
1974
|
-
if (csrfCook) {
|
|
1975
|
-
const [, value] = csrfCook.split("=");
|
|
1976
|
-
const [token] = decodeURIComponent(value).split("|");
|
|
1977
|
-
const setCookie = res.headers.get("set-cookie");
|
|
1978
|
-
if (setCookie) {
|
|
1979
|
-
const cookie = [
|
|
1980
|
-
csrfCook,
|
|
1981
|
-
parseCallback(res.headers),
|
|
1982
|
-
parseToken(res.headers)
|
|
1983
|
-
].filter(Boolean).join("; ");
|
|
1984
|
-
this.#config.headers.set("cookie", cookie);
|
|
1985
|
-
updateHeaders(new Headers({ cookie }));
|
|
1974
|
+
if ("redirectUrl" in req) {
|
|
1975
|
+
redirectUrl = req.redirectUrl ? req.redirectUrl : null;
|
|
1986
1976
|
}
|
|
1987
|
-
|
|
1988
|
-
|
|
1977
|
+
}
|
|
1978
|
+
const fallbackCb = parseCallback(this.#config.headers);
|
|
1979
|
+
if (fallbackCb) {
|
|
1980
|
+
const [, value] = fallbackCb.split("=");
|
|
1981
|
+
if (value) {
|
|
1982
|
+
const parsedUrl = decodeURIComponent(value);
|
|
1983
|
+
if (!redirectUrl) {
|
|
1984
|
+
redirectUrl = `${new URL(parsedUrl).origin}${"/auth/reset-password" /* PASSWORD_RESET */}`;
|
|
1985
|
+
}
|
|
1989
1986
|
}
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
const cookieParts = [];
|
|
1993
|
-
if (existingCookie) {
|
|
1994
|
-
cookieParts.push(
|
|
1995
|
-
parseToken(this.#config.headers),
|
|
1996
|
-
parseCallback(this.#config.headers)
|
|
1997
|
-
);
|
|
1987
|
+
if (!callbackUrl) {
|
|
1988
|
+
callbackUrl = value;
|
|
1998
1989
|
}
|
|
1999
|
-
cookieParts.push(csrfCook);
|
|
2000
|
-
const cookie = cookieParts.filter(Boolean).join("; ");
|
|
2001
|
-
this.#config.headers.set("cookie", cookie);
|
|
2002
|
-
updateHeaders(new Headers({ cookie }));
|
|
2003
|
-
}
|
|
2004
|
-
if (rawResponse) {
|
|
2005
|
-
return res;
|
|
2006
1990
|
}
|
|
1991
|
+
await this.getCsrf();
|
|
1992
|
+
const body = JSON.stringify({
|
|
1993
|
+
email,
|
|
1994
|
+
password,
|
|
1995
|
+
redirectUrl,
|
|
1996
|
+
callbackUrl
|
|
1997
|
+
});
|
|
1998
|
+
let urlWithParams;
|
|
2007
1999
|
try {
|
|
2008
|
-
|
|
2000
|
+
const data = await fetchResetPassword(this.#config, "POST", body);
|
|
2001
|
+
const cloned = data.clone();
|
|
2002
|
+
if (data.status === 400) {
|
|
2003
|
+
const text = await cloned.text();
|
|
2004
|
+
this.#logger.error(text);
|
|
2005
|
+
return data;
|
|
2006
|
+
}
|
|
2007
|
+
const { url } = await data.json();
|
|
2008
|
+
urlWithParams = url;
|
|
2009
2009
|
} catch {
|
|
2010
|
-
return res;
|
|
2011
|
-
}
|
|
2012
|
-
}
|
|
2013
|
-
async listProviders(rawResponse = false) {
|
|
2014
|
-
const res = await fetchProviders(this.#config);
|
|
2015
|
-
if (rawResponse) {
|
|
2016
|
-
return res;
|
|
2017
2010
|
}
|
|
2011
|
+
let token;
|
|
2018
2012
|
try {
|
|
2019
|
-
|
|
2013
|
+
const worthyParams = new URL(urlWithParams).searchParams;
|
|
2014
|
+
const answer = await fetchResetPassword(
|
|
2015
|
+
this.#config,
|
|
2016
|
+
"GET",
|
|
2017
|
+
null,
|
|
2018
|
+
worthyParams
|
|
2019
|
+
);
|
|
2020
|
+
token = parseResetToken(answer.headers);
|
|
2020
2021
|
} catch {
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
}
|
|
2024
|
-
async signOut() {
|
|
2025
|
-
const csrfRes = await this.getCsrf();
|
|
2026
|
-
if (!("csrfToken" in csrfRes)) {
|
|
2027
|
-
throw new Error("Unable to obtain CSRF token. Sign out failed.");
|
|
2028
|
-
}
|
|
2029
|
-
const body = JSON.stringify({
|
|
2030
|
-
csrfToken: csrfRes.csrfToken,
|
|
2031
|
-
json: true
|
|
2032
|
-
});
|
|
2033
|
-
const res = await fetchSignOut(this.#config, body);
|
|
2034
|
-
updateHeaders(new Headers({}));
|
|
2035
|
-
this.#config.headers = new Headers();
|
|
2036
|
-
return res;
|
|
2037
|
-
}
|
|
2038
|
-
async signUp(payload, rawResponse) {
|
|
2039
|
-
this.#config.headers = new Headers();
|
|
2040
|
-
const { email, password, ...params } = payload;
|
|
2041
|
-
if (!email || !password) {
|
|
2042
|
-
throw new Error(
|
|
2043
|
-
"Server side sign up requires a user email and password."
|
|
2022
|
+
this.#logger.warn(
|
|
2023
|
+
"Unable to parse reset password url. Password not reset."
|
|
2044
2024
|
);
|
|
2045
2025
|
}
|
|
2046
|
-
const
|
|
2047
|
-
|
|
2048
|
-
|
|
2026
|
+
const cookie = this.#config.headers.get("cookie")?.split("; ");
|
|
2027
|
+
if (token) {
|
|
2028
|
+
cookie?.push(token);
|
|
2029
|
+
} else {
|
|
2049
2030
|
throw new Error(
|
|
2050
|
-
"Unable to
|
|
2031
|
+
"Unable to reset password, reset token is missing from response"
|
|
2051
2032
|
);
|
|
2052
2033
|
}
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
csrfToken = csrf.csrfToken;
|
|
2057
|
-
} else {
|
|
2058
|
-
throw new Error("Unable to obtain parse CSRF. Request blocked.");
|
|
2059
|
-
}
|
|
2060
|
-
const body = JSON.stringify({
|
|
2061
|
-
email,
|
|
2062
|
-
password,
|
|
2063
|
-
csrfToken,
|
|
2064
|
-
callbackUrl: credentials.callbackUrl
|
|
2034
|
+
this.#config.headers = new Headers({
|
|
2035
|
+
...this.#config.headers,
|
|
2036
|
+
cookie: cookie?.join("; ")
|
|
2065
2037
|
});
|
|
2066
|
-
const res = await
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
}
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2038
|
+
const res = await fetchResetPassword(this.#config, "PUT", body);
|
|
2039
|
+
cookie?.pop();
|
|
2040
|
+
const cleaned = cookie?.filter((c) => !c.includes("nile.session")) ?? [];
|
|
2041
|
+
cleaned.push(String(parseToken(res.headers)));
|
|
2042
|
+
const updatedHeaders = new Headers({ cookie: cleaned.join("; ") });
|
|
2043
|
+
updateHeaders(updatedHeaders);
|
|
2044
|
+
return res;
|
|
2045
|
+
}
|
|
2046
|
+
async callback(provider, body) {
|
|
2047
|
+
if (body instanceof Request) {
|
|
2048
|
+
this.#config.headers = body.headers;
|
|
2049
|
+
return await fetchCallback(
|
|
2050
|
+
this.#config,
|
|
2051
|
+
provider,
|
|
2052
|
+
void 0,
|
|
2053
|
+
body,
|
|
2054
|
+
"GET"
|
|
2055
|
+
);
|
|
2084
2056
|
}
|
|
2057
|
+
return await fetchCallback(this.#config, provider, body);
|
|
2085
2058
|
}
|
|
2086
2059
|
async signIn(provider, payload, rawResponse) {
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2060
|
+
if (payload instanceof Request) {
|
|
2061
|
+
const body2 = new URLSearchParams(await payload.text());
|
|
2062
|
+
const origin = new URL(payload.url).origin;
|
|
2063
|
+
const payloadUrl = body2?.get("callbackUrl");
|
|
2064
|
+
const csrfToken2 = body2?.get("csrfToken");
|
|
2065
|
+
const callbackUrl = `${!payloadUrl?.startsWith("http") ? origin : ""}${payloadUrl}`;
|
|
2066
|
+
if (!csrfToken2) {
|
|
2067
|
+
throw new Error(
|
|
2068
|
+
"CSRF token in missing from request. Request it by the client before calling sign in"
|
|
2069
|
+
);
|
|
2070
|
+
}
|
|
2071
|
+
this.#config.headers = new Headers(payload.headers);
|
|
2072
|
+
this.#config.headers.set(
|
|
2073
|
+
"Content-Type",
|
|
2074
|
+
"application/x-www-form-urlencoded"
|
|
2093
2075
|
);
|
|
2076
|
+
const params = new URLSearchParams({
|
|
2077
|
+
csrfToken: csrfToken2,
|
|
2078
|
+
json: String(true)
|
|
2079
|
+
});
|
|
2080
|
+
if (payloadUrl) {
|
|
2081
|
+
params.set("callbackUrl", callbackUrl);
|
|
2082
|
+
}
|
|
2083
|
+
return await fetchSignIn(this.#config, provider, params);
|
|
2094
2084
|
}
|
|
2095
|
-
|
|
2085
|
+
this.#config.headers = new Headers();
|
|
2086
|
+
const { info, error } = this.#logger;
|
|
2096
2087
|
const providers = await this.listProviders();
|
|
2097
2088
|
info("Obtaining csrf");
|
|
2098
2089
|
const csrf = await this.getCsrf();
|
|
@@ -2108,13 +2099,13 @@ var Auth = class {
|
|
|
2108
2099
|
"Unable to obtain credential provider. Aborting server side sign in."
|
|
2109
2100
|
);
|
|
2110
2101
|
}
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
JSON.stringify({ csrfToken })
|
|
2102
|
+
const { email, password } = payload ?? {};
|
|
2103
|
+
if (provider === "email" && (!email || !password)) {
|
|
2104
|
+
throw new Error(
|
|
2105
|
+
"Server side sign in requires a user email and password."
|
|
2116
2106
|
);
|
|
2117
2107
|
}
|
|
2108
|
+
info(`Obtaining providers for ${email}`);
|
|
2118
2109
|
info(`Attempting sign in with email ${email}`);
|
|
2119
2110
|
const body = JSON.stringify({
|
|
2120
2111
|
email,
|
|
@@ -2122,7 +2113,7 @@ var Auth = class {
|
|
|
2122
2113
|
csrfToken,
|
|
2123
2114
|
callbackUrl: credentials.callbackUrl
|
|
2124
2115
|
});
|
|
2125
|
-
const signInRes = await
|
|
2116
|
+
const signInRes = await this.callback(provider, body);
|
|
2126
2117
|
const authCookie = signInRes?.headers.get("set-cookie");
|
|
2127
2118
|
if (!authCookie) {
|
|
2128
2119
|
throw new Error("authentication failed");
|
|
@@ -2204,6 +2195,283 @@ function parseToken(headers) {
|
|
|
2204
2195
|
const [, token] = /((__Secure-)?nile\.session-token=[^;]+)/.exec(authCookie) ?? [];
|
|
2205
2196
|
return token;
|
|
2206
2197
|
}
|
|
2198
|
+
function parseResetToken(headers) {
|
|
2199
|
+
let authCookie = headers?.get("set-cookie");
|
|
2200
|
+
if (!authCookie) {
|
|
2201
|
+
authCookie = headers?.get("cookie");
|
|
2202
|
+
}
|
|
2203
|
+
if (!authCookie) {
|
|
2204
|
+
return void 0;
|
|
2205
|
+
}
|
|
2206
|
+
const [, token] = /((__Secure-)?nile\.reset=[^;]+)/.exec(authCookie) ?? [];
|
|
2207
|
+
return token;
|
|
2208
|
+
}
|
|
2209
|
+
|
|
2210
|
+
// src/auth/getCsrf.ts
|
|
2211
|
+
async function getCsrf(config, rawResponse = false) {
|
|
2212
|
+
const res = await fetchCsrf(config);
|
|
2213
|
+
const csrfCook = parseCSRF(res.headers);
|
|
2214
|
+
if (csrfCook) {
|
|
2215
|
+
const [, value] = csrfCook.split("=");
|
|
2216
|
+
const [token] = decodeURIComponent(value).split("|");
|
|
2217
|
+
const setCookie = res.headers.get("set-cookie");
|
|
2218
|
+
if (setCookie) {
|
|
2219
|
+
const cookie = [
|
|
2220
|
+
csrfCook,
|
|
2221
|
+
parseCallback(res.headers),
|
|
2222
|
+
parseToken(res.headers)
|
|
2223
|
+
].filter(Boolean).join("; ");
|
|
2224
|
+
config.headers.set("cookie", cookie);
|
|
2225
|
+
updateHeaders(new Headers({ cookie }));
|
|
2226
|
+
}
|
|
2227
|
+
if (!rawResponse) {
|
|
2228
|
+
return { csrfToken: token };
|
|
2229
|
+
}
|
|
2230
|
+
} else {
|
|
2231
|
+
const existingCookie = config.headers.get("cookie");
|
|
2232
|
+
const cookieParts = [];
|
|
2233
|
+
if (existingCookie) {
|
|
2234
|
+
cookieParts.push(
|
|
2235
|
+
parseToken(config.headers),
|
|
2236
|
+
parseCallback(config.headers)
|
|
2237
|
+
);
|
|
2238
|
+
}
|
|
2239
|
+
if (csrfCook) {
|
|
2240
|
+
cookieParts.push(csrfCook);
|
|
2241
|
+
} else {
|
|
2242
|
+
cookieParts.push(parseCSRF(config.headers));
|
|
2243
|
+
}
|
|
2244
|
+
const cookie = cookieParts.filter(Boolean).join("; ");
|
|
2245
|
+
config.headers.set("cookie", cookie);
|
|
2246
|
+
updateHeaders(new Headers({ cookie }));
|
|
2247
|
+
}
|
|
2248
|
+
if (rawResponse) {
|
|
2249
|
+
return res;
|
|
2250
|
+
}
|
|
2251
|
+
try {
|
|
2252
|
+
return await res.clone().json();
|
|
2253
|
+
} catch {
|
|
2254
|
+
return res;
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2258
|
+
// src/users/index.ts
|
|
2259
|
+
var Users = class {
|
|
2260
|
+
#config;
|
|
2261
|
+
#logger;
|
|
2262
|
+
constructor(config) {
|
|
2263
|
+
this.#config = config;
|
|
2264
|
+
this.#logger = Logger(config, "[me]");
|
|
2265
|
+
}
|
|
2266
|
+
async updateSelf(req, rawResponse) {
|
|
2267
|
+
const res = await fetchMe(this.#config, "PUT", JSON.stringify(req));
|
|
2268
|
+
if (rawResponse) {
|
|
2269
|
+
return res;
|
|
2270
|
+
}
|
|
2271
|
+
try {
|
|
2272
|
+
return await res?.clone().json();
|
|
2273
|
+
} catch {
|
|
2274
|
+
return res;
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
async removeSelf() {
|
|
2278
|
+
const me = await this.getSelf();
|
|
2279
|
+
if ("id" in me) {
|
|
2280
|
+
this.#config.userId = me.id;
|
|
2281
|
+
}
|
|
2282
|
+
const res = await fetchMe(this.#config, "DELETE");
|
|
2283
|
+
updateHeaders(new Headers());
|
|
2284
|
+
return res;
|
|
2285
|
+
}
|
|
2286
|
+
async getSelf(rawResponse) {
|
|
2287
|
+
const res = await fetchMe(this.#config);
|
|
2288
|
+
if (rawResponse) {
|
|
2289
|
+
return res;
|
|
2290
|
+
}
|
|
2291
|
+
try {
|
|
2292
|
+
return await res?.clone().json();
|
|
2293
|
+
} catch {
|
|
2294
|
+
return res;
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2297
|
+
async verifySelf(bypassEmail = process.env.NODE_ENV !== "production", rawResponse = false) {
|
|
2298
|
+
try {
|
|
2299
|
+
const me = await this.getSelf();
|
|
2300
|
+
if (me instanceof Response) {
|
|
2301
|
+
return me;
|
|
2302
|
+
}
|
|
2303
|
+
const res = await verifyEmailAddress(this.#config, me);
|
|
2304
|
+
return res;
|
|
2305
|
+
} catch {
|
|
2306
|
+
this.#logger?.warn(
|
|
2307
|
+
"Unable to verify email. The current user's email will be set to verified any way. Be sure to configure emails for production."
|
|
2308
|
+
);
|
|
2309
|
+
}
|
|
2310
|
+
if (bypassEmail) {
|
|
2311
|
+
return await this.updateSelf({ emailVerified: true }, rawResponse);
|
|
2312
|
+
}
|
|
2313
|
+
this.#logger.error(
|
|
2314
|
+
"Unable to verify email address. Configure your SMTP server in the console."
|
|
2315
|
+
);
|
|
2316
|
+
return void 0;
|
|
2317
|
+
}
|
|
2318
|
+
};
|
|
2319
|
+
async function verifyEmailAddress(config, user) {
|
|
2320
|
+
config.headers.set("content-type", "application/x-www-form-urlencoded");
|
|
2321
|
+
const { csrfToken } = await getCsrf(config);
|
|
2322
|
+
const res = await fetchVerifyEmail(
|
|
2323
|
+
config,
|
|
2324
|
+
"POST",
|
|
2325
|
+
new URLSearchParams({ csrfToken, email: user.email }).toString()
|
|
2326
|
+
);
|
|
2327
|
+
if (res.status > 299) {
|
|
2328
|
+
throw new Error(await res.text());
|
|
2329
|
+
}
|
|
2330
|
+
return res;
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2333
|
+
// src/tenants/index.ts
|
|
2334
|
+
var Tenants = class {
|
|
2335
|
+
#logger;
|
|
2336
|
+
#config;
|
|
2337
|
+
constructor(config) {
|
|
2338
|
+
this.#logger = Logger(config, "[tenants]");
|
|
2339
|
+
this.#config = config;
|
|
2340
|
+
}
|
|
2341
|
+
async create(req, rawResponse) {
|
|
2342
|
+
let res;
|
|
2343
|
+
if (typeof req === "string") {
|
|
2344
|
+
res = await fetchTenants(
|
|
2345
|
+
this.#config,
|
|
2346
|
+
"POST",
|
|
2347
|
+
JSON.stringify({ name: req })
|
|
2348
|
+
);
|
|
2349
|
+
} else if (typeof req === "object" && ("name" in req || "id" in req)) {
|
|
2350
|
+
res = await fetchTenants(this.#config, "POST", JSON.stringify(req));
|
|
2351
|
+
}
|
|
2352
|
+
if (rawResponse) {
|
|
2353
|
+
return res;
|
|
2354
|
+
}
|
|
2355
|
+
try {
|
|
2356
|
+
return await res?.clone().json();
|
|
2357
|
+
} catch {
|
|
2358
|
+
return res;
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
async delete(req) {
|
|
2362
|
+
if (typeof req === "string") {
|
|
2363
|
+
this.#config.tenantId = req;
|
|
2364
|
+
}
|
|
2365
|
+
if (typeof req === "object" && "id" in req) {
|
|
2366
|
+
this.#config.tenantId = req.id;
|
|
2367
|
+
}
|
|
2368
|
+
const res = await fetchTenant(this.#config, "DELETE");
|
|
2369
|
+
return res;
|
|
2370
|
+
}
|
|
2371
|
+
async get(req, rawResponse) {
|
|
2372
|
+
if (typeof req === "string") {
|
|
2373
|
+
this.#config.tenantId = req;
|
|
2374
|
+
} else if (typeof req === "object" && "id" in req) {
|
|
2375
|
+
this.#config.tenantId = req.id;
|
|
2376
|
+
}
|
|
2377
|
+
const res = await fetchTenant(this.#config, "GET");
|
|
2378
|
+
if (rawResponse === true || req === true) {
|
|
2379
|
+
return res;
|
|
2380
|
+
}
|
|
2381
|
+
try {
|
|
2382
|
+
return await res?.clone().json();
|
|
2383
|
+
} catch {
|
|
2384
|
+
return res;
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
async update(req, rawResponse) {
|
|
2388
|
+
let res;
|
|
2389
|
+
if (typeof req === "object" && ("name" in req || "id" in req)) {
|
|
2390
|
+
const { id, ...remaining } = req;
|
|
2391
|
+
if (id) {
|
|
2392
|
+
this.#config.tenantId = id;
|
|
2393
|
+
}
|
|
2394
|
+
res = await fetchTenant(this.#config, "PUT", JSON.stringify(remaining));
|
|
2395
|
+
}
|
|
2396
|
+
if (rawResponse) {
|
|
2397
|
+
return res;
|
|
2398
|
+
}
|
|
2399
|
+
try {
|
|
2400
|
+
return await res?.clone().json();
|
|
2401
|
+
} catch {
|
|
2402
|
+
return res;
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
async list(req) {
|
|
2406
|
+
const res = await fetchTenantsByUser(this.#config);
|
|
2407
|
+
if (req === true) {
|
|
2408
|
+
return res;
|
|
2409
|
+
}
|
|
2410
|
+
try {
|
|
2411
|
+
return await res?.clone().json();
|
|
2412
|
+
} catch {
|
|
2413
|
+
return res;
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
async leaveTenant(req) {
|
|
2417
|
+
const me = await fetchMe(this.#config);
|
|
2418
|
+
try {
|
|
2419
|
+
const json = await me.json();
|
|
2420
|
+
if ("id" in json) {
|
|
2421
|
+
this.#config.userId = json.id;
|
|
2422
|
+
}
|
|
2423
|
+
} catch {
|
|
2424
|
+
}
|
|
2425
|
+
if (typeof req === "string") {
|
|
2426
|
+
this.#config.tenantId = req;
|
|
2427
|
+
} else {
|
|
2428
|
+
this.#handleContext(req);
|
|
2429
|
+
}
|
|
2430
|
+
return await fetchTenantUser(this.#config, "DELETE");
|
|
2431
|
+
}
|
|
2432
|
+
async addMember(req, rawResponse) {
|
|
2433
|
+
if (typeof req === "string") {
|
|
2434
|
+
this.#config.userId = req;
|
|
2435
|
+
} else {
|
|
2436
|
+
this.#handleContext(req);
|
|
2437
|
+
}
|
|
2438
|
+
const res = await fetchTenantUser(this.#config, "PUT");
|
|
2439
|
+
return responseHandler(res, rawResponse);
|
|
2440
|
+
}
|
|
2441
|
+
async removeMember(req, rawResponse) {
|
|
2442
|
+
this.#handleContext(req);
|
|
2443
|
+
const res = await fetchTenantUser(this.#config, "DELETE");
|
|
2444
|
+
return responseHandler(res, rawResponse);
|
|
2445
|
+
}
|
|
2446
|
+
async users(req, rawResponse) {
|
|
2447
|
+
this.#handleContext(req);
|
|
2448
|
+
const res = await fetchTenantUsers(this.#config, "GET");
|
|
2449
|
+
return responseHandler(
|
|
2450
|
+
res,
|
|
2451
|
+
rawResponse || typeof req === "boolean" && req
|
|
2452
|
+
);
|
|
2453
|
+
}
|
|
2454
|
+
#handleContext(req) {
|
|
2455
|
+
if (typeof req === "object") {
|
|
2456
|
+
if ("tenantId" in req) {
|
|
2457
|
+
this.#config.tenantId = req.tenantId;
|
|
2458
|
+
}
|
|
2459
|
+
if ("userId" in req) {
|
|
2460
|
+
this.#config.tenantId = req.tenantId;
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
};
|
|
2465
|
+
async function responseHandler(res, rawResponse) {
|
|
2466
|
+
if (rawResponse) {
|
|
2467
|
+
return res;
|
|
2468
|
+
}
|
|
2469
|
+
try {
|
|
2470
|
+
return await res?.clone().json();
|
|
2471
|
+
} catch {
|
|
2472
|
+
return res;
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2207
2475
|
|
|
2208
2476
|
// src/api/handlers/withContext/index.ts
|
|
2209
2477
|
function handlersWithContext(config) {
|
|
@@ -2240,14 +2508,14 @@ function updateConfig(response, config) {
|
|
|
2240
2508
|
if (response?.status === 302) {
|
|
2241
2509
|
const location = response.headers.get("location");
|
|
2242
2510
|
if (location) {
|
|
2243
|
-
const
|
|
2244
|
-
origin =
|
|
2511
|
+
const urlLocation = new URL(location);
|
|
2512
|
+
origin = urlLocation.origin;
|
|
2245
2513
|
}
|
|
2246
2514
|
}
|
|
2247
2515
|
const setCookies = [];
|
|
2248
2516
|
if (response?.headers) {
|
|
2249
|
-
for (const [
|
|
2250
|
-
if (
|
|
2517
|
+
for (const [key14, value] of response.headers) {
|
|
2518
|
+
if (key14.toLowerCase() === "set-cookie") {
|
|
2251
2519
|
setCookies.push(value);
|
|
2252
2520
|
}
|
|
2253
2521
|
}
|
|
@@ -2406,25 +2674,25 @@ var Server = class {
|
|
|
2406
2674
|
}
|
|
2407
2675
|
}
|
|
2408
2676
|
if (headers instanceof Headers) {
|
|
2409
|
-
headers.forEach((value,
|
|
2410
|
-
updates.push([
|
|
2677
|
+
headers.forEach((value, key14) => {
|
|
2678
|
+
updates.push([key14.toLowerCase(), value]);
|
|
2411
2679
|
});
|
|
2412
2680
|
} else {
|
|
2413
|
-
for (const [
|
|
2414
|
-
updates.push([
|
|
2681
|
+
for (const [key14, value] of Object.entries(headers ?? {})) {
|
|
2682
|
+
updates.push([key14.toLowerCase(), value]);
|
|
2415
2683
|
}
|
|
2416
2684
|
}
|
|
2417
2685
|
const merged = {};
|
|
2418
|
-
this.#headers?.forEach((value,
|
|
2419
|
-
if (
|
|
2420
|
-
merged[
|
|
2686
|
+
this.#headers?.forEach((value, key14) => {
|
|
2687
|
+
if (key14.toLowerCase() !== "cookie") {
|
|
2688
|
+
merged[key14.toLowerCase()] = value;
|
|
2421
2689
|
}
|
|
2422
2690
|
});
|
|
2423
|
-
for (const [
|
|
2424
|
-
merged[
|
|
2691
|
+
for (const [key14, value] of updates) {
|
|
2692
|
+
merged[key14] = value;
|
|
2425
2693
|
}
|
|
2426
|
-
for (const [
|
|
2427
|
-
this.#headers.set(
|
|
2694
|
+
for (const [key14, value] of Object.entries(merged)) {
|
|
2695
|
+
this.#headers.set(key14, value);
|
|
2428
2696
|
}
|
|
2429
2697
|
this.#config.headers = this.#headers;
|
|
2430
2698
|
}
|