@niledatabase/server 4.0.0 → 4.0.1-alpha.1
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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +31 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -284,12 +284,12 @@ declare class Users extends Config {
|
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
declare class Api {
|
|
287
|
+
#private;
|
|
287
288
|
config: Config;
|
|
288
289
|
users: Users;
|
|
289
290
|
auth: Auth;
|
|
290
291
|
tenants: Tenants;
|
|
291
292
|
routes: Routes;
|
|
292
|
-
_headers: undefined | Headers;
|
|
293
293
|
handlers: {
|
|
294
294
|
GET: (req: Request) => Promise<void | Response>;
|
|
295
295
|
POST: (req: Request) => Promise<void | Response>;
|
|
@@ -306,7 +306,7 @@ declare class Api {
|
|
|
306
306
|
reset: () => void;
|
|
307
307
|
updateConfig: (config: Config) => void;
|
|
308
308
|
resetHeaders: (headers?: Headers) => void;
|
|
309
|
-
set headers(headers: Headers);
|
|
309
|
+
set headers(headers: Headers | Record<string, string>);
|
|
310
310
|
get headers(): Headers | undefined;
|
|
311
311
|
login: (payload: {
|
|
312
312
|
email: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -284,12 +284,12 @@ declare class Users extends Config {
|
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
declare class Api {
|
|
287
|
+
#private;
|
|
287
288
|
config: Config;
|
|
288
289
|
users: Users;
|
|
289
290
|
auth: Auth;
|
|
290
291
|
tenants: Tenants;
|
|
291
292
|
routes: Routes;
|
|
292
|
-
_headers: undefined | Headers;
|
|
293
293
|
handlers: {
|
|
294
294
|
GET: (req: Request) => Promise<void | Response>;
|
|
295
295
|
POST: (req: Request) => Promise<void | Response>;
|
|
@@ -306,7 +306,7 @@ declare class Api {
|
|
|
306
306
|
reset: () => void;
|
|
307
307
|
updateConfig: (config: Config) => void;
|
|
308
308
|
resetHeaders: (headers?: Headers) => void;
|
|
309
|
-
set headers(headers: Headers);
|
|
309
|
+
set headers(headers: Headers | Record<string, string>);
|
|
310
310
|
get headers(): Headers | undefined;
|
|
311
311
|
login: (payload: {
|
|
312
312
|
email: string;
|
package/dist/index.js
CHANGED
|
@@ -1019,6 +1019,9 @@ function makeBasicHeaders(config, opts) {
|
|
|
1019
1019
|
if (config && config.api.secureCookies != null) {
|
|
1020
1020
|
headers.set(X_NILE_SECURECOOKIES, String(config.api.secureCookies));
|
|
1021
1021
|
}
|
|
1022
|
+
if (config && config.api.origin) {
|
|
1023
|
+
headers.set(X_NILE_ORIGIN, config.api.origin);
|
|
1024
|
+
}
|
|
1022
1025
|
return headers;
|
|
1023
1026
|
}
|
|
1024
1027
|
async function _fetch(config, path, opts) {
|
|
@@ -2352,7 +2355,7 @@ var Api = class {
|
|
|
2352
2355
|
auth;
|
|
2353
2356
|
tenants;
|
|
2354
2357
|
routes;
|
|
2355
|
-
|
|
2358
|
+
#headers;
|
|
2356
2359
|
handlers;
|
|
2357
2360
|
paths;
|
|
2358
2361
|
constructor(config) {
|
|
@@ -2406,9 +2409,9 @@ var Api = class {
|
|
|
2406
2409
|
};
|
|
2407
2410
|
}
|
|
2408
2411
|
reset = () => {
|
|
2409
|
-
this.users = new Users(this.config, this
|
|
2410
|
-
this.tenants = new Tenants(this.config, this
|
|
2411
|
-
this.auth = new Auth(this.config, this
|
|
2412
|
+
this.users = new Users(this.config, this.#headers);
|
|
2413
|
+
this.tenants = new Tenants(this.config, this.#headers);
|
|
2414
|
+
this.auth = new Auth(this.config, this.#headers, {
|
|
2412
2415
|
resetHeaders: this.resetHeaders
|
|
2413
2416
|
});
|
|
2414
2417
|
};
|
|
@@ -2417,15 +2420,35 @@ var Api = class {
|
|
|
2417
2420
|
this.handlers = Handlers(this.routes, config);
|
|
2418
2421
|
};
|
|
2419
2422
|
resetHeaders = (headers) => {
|
|
2420
|
-
this
|
|
2423
|
+
this.#headers = new Headers(headers ?? {});
|
|
2421
2424
|
this.reset();
|
|
2422
2425
|
};
|
|
2423
2426
|
set headers(headers) {
|
|
2424
|
-
|
|
2427
|
+
const updates = [];
|
|
2428
|
+
if (headers instanceof Headers) {
|
|
2429
|
+
headers.forEach((value, key12) => {
|
|
2430
|
+
updates.push([key12.toLowerCase(), value]);
|
|
2431
|
+
});
|
|
2432
|
+
} else {
|
|
2433
|
+
for (const [key12, value] of Object.entries(headers)) {
|
|
2434
|
+
updates.push([key12.toLowerCase(), value]);
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
const merged = {};
|
|
2438
|
+
this.#headers?.forEach((value, key12) => {
|
|
2439
|
+
merged[key12.toLowerCase()] = value;
|
|
2440
|
+
});
|
|
2441
|
+
for (const [key12, value] of updates) {
|
|
2442
|
+
merged[key12] = value;
|
|
2443
|
+
}
|
|
2444
|
+
this.#headers = new Headers();
|
|
2445
|
+
for (const [key12, value] of Object.entries(merged)) {
|
|
2446
|
+
this.#headers.set(key12, value);
|
|
2447
|
+
}
|
|
2425
2448
|
this.reset();
|
|
2426
2449
|
}
|
|
2427
2450
|
get headers() {
|
|
2428
|
-
return this
|
|
2451
|
+
return this.#headers;
|
|
2429
2452
|
}
|
|
2430
2453
|
login = async (payload, config) => {
|
|
2431
2454
|
const [headers, loginRes] = await serverLogin(
|
|
@@ -2444,7 +2467,7 @@ var Api = class {
|
|
|
2444
2467
|
} else if (req instanceof Request) {
|
|
2445
2468
|
return auth(req, this.config);
|
|
2446
2469
|
}
|
|
2447
|
-
return this.auth.getSession(this
|
|
2470
|
+
return this.auth.getSession(this.#headers);
|
|
2448
2471
|
};
|
|
2449
2472
|
};
|
|
2450
2473
|
|