@niledatabase/server 4.2.0-alpha.3 → 4.2.0-alpha.4
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 +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +36 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +36 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -338,6 +338,9 @@ declare class Api {
|
|
|
338
338
|
reset: () => void;
|
|
339
339
|
updateConfig: (config: Config) => void;
|
|
340
340
|
resetHeaders: (headers?: Headers) => void;
|
|
341
|
+
/**
|
|
342
|
+
* Merge headers together
|
|
343
|
+
*/
|
|
341
344
|
set headers(headers: Headers | Record<string, string>);
|
|
342
345
|
get headers(): Headers | undefined;
|
|
343
346
|
getCookie(req?: Request | Headers): string | null | undefined;
|
|
@@ -348,7 +351,7 @@ declare class Api {
|
|
|
348
351
|
returnResponse?: boolean;
|
|
349
352
|
}) => Promise<Response | undefined>;
|
|
350
353
|
session: (req?: Request | Headers | null | undefined) => Promise<Response | JWT | ActiveSession | null | undefined>;
|
|
351
|
-
setContext: (req: Request | Headers | Record<string, string>) => void;
|
|
354
|
+
setContext: (req: Request | Headers | Record<string, string> | unknown) => void;
|
|
352
355
|
}
|
|
353
356
|
|
|
354
357
|
declare class Server {
|
package/dist/index.d.ts
CHANGED
|
@@ -338,6 +338,9 @@ declare class Api {
|
|
|
338
338
|
reset: () => void;
|
|
339
339
|
updateConfig: (config: Config) => void;
|
|
340
340
|
resetHeaders: (headers?: Headers) => void;
|
|
341
|
+
/**
|
|
342
|
+
* Merge headers together
|
|
343
|
+
*/
|
|
341
344
|
set headers(headers: Headers | Record<string, string>);
|
|
342
345
|
get headers(): Headers | undefined;
|
|
343
346
|
getCookie(req?: Request | Headers): string | null | undefined;
|
|
@@ -348,7 +351,7 @@ declare class Api {
|
|
|
348
351
|
returnResponse?: boolean;
|
|
349
352
|
}) => Promise<Response | undefined>;
|
|
350
353
|
session: (req?: Request | Headers | null | undefined) => Promise<Response | JWT | ActiveSession | null | undefined>;
|
|
351
|
-
setContext: (req: Request | Headers | Record<string, string>) => void;
|
|
354
|
+
setContext: (req: Request | Headers | Record<string, string> | unknown) => void;
|
|
352
355
|
}
|
|
353
356
|
|
|
354
357
|
declare class Server {
|
package/dist/index.js
CHANGED
|
@@ -2566,6 +2566,9 @@ var Api = class {
|
|
|
2566
2566
|
this.#headers = new Headers(headers ?? {});
|
|
2567
2567
|
this.reset();
|
|
2568
2568
|
};
|
|
2569
|
+
/**
|
|
2570
|
+
* Merge headers together
|
|
2571
|
+
*/
|
|
2569
2572
|
set headers(headers) {
|
|
2570
2573
|
const updates = [];
|
|
2571
2574
|
if (headers instanceof Headers) {
|
|
@@ -2579,7 +2582,9 @@ var Api = class {
|
|
|
2579
2582
|
}
|
|
2580
2583
|
const merged = {};
|
|
2581
2584
|
this.#headers?.forEach((value, key12) => {
|
|
2582
|
-
|
|
2585
|
+
if (key12.toLowerCase() !== "cookie") {
|
|
2586
|
+
merged[key12.toLowerCase()] = value;
|
|
2587
|
+
}
|
|
2583
2588
|
});
|
|
2584
2589
|
for (const [key12, value] of updates) {
|
|
2585
2590
|
merged[key12] = value;
|
|
@@ -2606,8 +2611,18 @@ var Api = class {
|
|
|
2606
2611
|
this.config,
|
|
2607
2612
|
this.handlers
|
|
2608
2613
|
)(payload);
|
|
2609
|
-
this.headers = headers;
|
|
2610
2614
|
this.setContext(headers);
|
|
2615
|
+
try {
|
|
2616
|
+
const res = await loginRes.json();
|
|
2617
|
+
if (res.id) {
|
|
2618
|
+
this.config.userId = res.id;
|
|
2619
|
+
}
|
|
2620
|
+
} catch (e) {
|
|
2621
|
+
const { warn } = Logger(this.config, "[API][login]");
|
|
2622
|
+
if (warn) {
|
|
2623
|
+
warn("Unable to set user id from login attempt.");
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2611
2626
|
if (config?.returnResponse) {
|
|
2612
2627
|
return loginRes;
|
|
2613
2628
|
}
|
|
@@ -2622,23 +2637,26 @@ var Api = class {
|
|
|
2622
2637
|
return this.auth.getSession(this.#headers);
|
|
2623
2638
|
};
|
|
2624
2639
|
setContext = (req) => {
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
if (warn) {
|
|
2638
|
-
warn(
|
|
2639
|
-
"Set context expects a Request, Header instance or an object of Record<string, string>"
|
|
2640
|
-
);
|
|
2640
|
+
try {
|
|
2641
|
+
if (req instanceof Headers) {
|
|
2642
|
+
this.headers = req;
|
|
2643
|
+
return;
|
|
2644
|
+
} else if (req instanceof Request) {
|
|
2645
|
+
this.headers = new Headers(req.headers);
|
|
2646
|
+
return;
|
|
2647
|
+
}
|
|
2648
|
+
const headers = new Headers(req);
|
|
2649
|
+
if (headers) {
|
|
2650
|
+
this.headers = headers;
|
|
2651
|
+
return;
|
|
2641
2652
|
}
|
|
2653
|
+
} catch {
|
|
2654
|
+
}
|
|
2655
|
+
const { warn } = Logger(this.config, "[API]");
|
|
2656
|
+
if (warn) {
|
|
2657
|
+
warn(
|
|
2658
|
+
"Set context expects a Request, Header instance or an object of Record<string, string>"
|
|
2659
|
+
);
|
|
2642
2660
|
}
|
|
2643
2661
|
};
|
|
2644
2662
|
};
|