@vingitonga/elysia-winston-logger 0.1.1 → 0.1.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.
@@ -0,0 +1,55 @@
1
+ import { Elysia } from 'elysia';
2
+ import type { IPHeaders, Logger, RequestLoggerOptions } from './logger-types';
3
+ /**
4
+ * List of IP headers to check in order of priority.
5
+ *
6
+ * @remarks
7
+ * The order of the headers in this list determines the priority of the headers to use when determining the client IP address.
8
+ * If the first header is not present, the second header is checked, and so on.
9
+ */
10
+ export declare const headersToCheck: IPHeaders[];
11
+ /**
12
+ * Creates a middleware function that logs incoming requests and outgoing responses.
13
+ *
14
+ * @param logger - The logger object to use for logging. Defaults to console.
15
+ * @param options - The options object to configure the middleware.
16
+ * @param options.level - The log level to use. Defaults to "info".
17
+ * @param options.format - The log format to use. Can be a string or a function. Defaults to "json".
18
+ * @param options.skip - A function that returns true to skip logging for a specific request.
19
+ * @param options.includeHeaders - An array of headers to include in the log.
20
+ * @param options.ipHeaders - An array of headers to check for the client IP address.
21
+ *
22
+ * @returns A middleware function that logs incoming requests and outgoing responses.
23
+ */
24
+ export declare function ElysiaLogging(logger?: Logger, options?: RequestLoggerOptions): Elysia<"", {
25
+ decorator: {};
26
+ store: {};
27
+ derive: {
28
+ readonly ip: string | undefined;
29
+ };
30
+ resolve: {};
31
+ }, {
32
+ typebox: {};
33
+ error: {};
34
+ }, {
35
+ schema: {};
36
+ standaloneSchema: {};
37
+ macro: {};
38
+ macroFn: {};
39
+ parser: {};
40
+ response: import("elysia").ExtractErrorFromHandle<{
41
+ readonly ip: string | undefined;
42
+ }> & {};
43
+ }, {}, {
44
+ derive: {};
45
+ resolve: {};
46
+ schema: {};
47
+ standaloneSchema: {};
48
+ response: {};
49
+ }, {
50
+ derive: {};
51
+ resolve: {};
52
+ schema: {};
53
+ standaloneSchema: {};
54
+ response: {};
55
+ }>;
@@ -0,0 +1,35 @@
1
+ import type { Headers } from 'undici-types';
2
+ import type { BasicAuth, IPHeaders } from './logger-types';
3
+ /**
4
+ * Parses a Basic Authentication header string and returns an object containing the username and password.
5
+ *
6
+ * @param header - The Basic Authentication header string to parse.
7
+ *
8
+ * @returns An object containing the username and password, or undefined if the header is invalid.
9
+ */
10
+ export declare function parseBasicAuthHeader(header: string): BasicAuth | undefined;
11
+ /**
12
+ * Formats a duration in nanoseconds to a human-readable string.
13
+ *
14
+ * @param durationInNanoseconds - The duration in nanoseconds to format.
15
+ *
16
+ * @returns A string representing the formatted duration.
17
+ */
18
+ export declare function formatDuration(durationInNanoseconds: number): string;
19
+ /**
20
+ * Returns the IP address of the client making the request.
21
+ *
22
+ * @param headers - The headers object from the request.
23
+ * @param ipHeaders - An array of header names to check for the IP address. Defaults to common IP headers.
24
+ *
25
+ * @returns The IP address of the client, or undefined if not found.
26
+ */
27
+ export declare function getIP(headers: Headers, ipHeaders?: IPHeaders[]): string | undefined | null;
28
+ /**
29
+ * Returns the name of the formatting method for a given format string.
30
+ *
31
+ * @param format - The format string to get the formatting method name for.
32
+ *
33
+ * @returns The name of the formatting method.
34
+ */
35
+ export declare function getFormattingMethodName(format: string): string;
@@ -0,0 +1,38 @@
1
+ import { type Logger } from 'winston';
2
+ import { LogFormat } from './logger-types';
3
+ export declare const defaultLogger: Logger;
4
+ export declare const winstonLogger: (customLogger?: Logger, options?: {
5
+ level?: string;
6
+ format?: (typeof LogFormat)[keyof typeof LogFormat];
7
+ }) => import("elysia").default<"", {
8
+ decorator: {};
9
+ store: {};
10
+ derive: {
11
+ readonly ip: string | undefined;
12
+ };
13
+ resolve: {};
14
+ }, {
15
+ typebox: {};
16
+ error: {};
17
+ }, {
18
+ schema: {};
19
+ standaloneSchema: {};
20
+ macro: {};
21
+ macroFn: {};
22
+ parser: {};
23
+ response: import("elysia").ExtractErrorFromHandle<{
24
+ readonly ip: string | undefined;
25
+ }> & {};
26
+ }, {}, {
27
+ derive: {};
28
+ resolve: {};
29
+ schema: {};
30
+ standaloneSchema: {};
31
+ response: {};
32
+ }, {
33
+ derive: {};
34
+ resolve: {};
35
+ schema: {};
36
+ standaloneSchema: {};
37
+ response: {};
38
+ }>;