@kalutskii/foundation 0.7.10 → 0.7.12
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.ts +95 -38
- package/dist/index.js +143 -60
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SQL } from 'drizzle-orm';
|
|
2
|
-
import { ErrorHandler,
|
|
2
|
+
import { ErrorHandler, Context, TypedResponse, MiddlewareHandler } from 'hono';
|
|
3
|
+
import * as kleur_colors from 'kleur/colors';
|
|
3
4
|
import z$1, { z, ZodObject, ZodRawShape } from 'zod';
|
|
4
5
|
import { Locale } from 'date-fns';
|
|
5
6
|
import { SymmetricAlgorithm } from 'hono/utils/jwt/jwa';
|
|
@@ -19,12 +20,6 @@ declare function sqlWhere(table: unknown, where: Record<string, unknown>): SQL;
|
|
|
19
20
|
*/
|
|
20
21
|
declare const onHandlerError: ErrorHandler;
|
|
21
22
|
|
|
22
|
-
/**
|
|
23
|
-
* Logs request method, response status, duration, URL details, and a body preview.
|
|
24
|
-
* Multipart bodies remain unread to avoid buffering uploaded file content into logs.
|
|
25
|
-
*/
|
|
26
|
-
declare const honoLoggingHandler: MiddlewareHandler;
|
|
27
|
-
|
|
28
23
|
declare const SUCCESS_STATUS_CODES: readonly [200, 201, 202, 307];
|
|
29
24
|
declare const EXCEPTION_STATUS_CODES: readonly [400, 401, 403, 404, 405, 409, 500];
|
|
30
25
|
|
|
@@ -109,6 +104,98 @@ declare function fetchSafely<TResult extends APIContractResult<unknown>>(fetcher
|
|
|
109
104
|
*/
|
|
110
105
|
declare function fetchAndThrow<TResult extends APIContractResult<unknown>>(fetcher: () => Promise<TResult>): Promise<APIContractData<TResult>>;
|
|
111
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Terminal color configuration for every supported logging level.
|
|
109
|
+
* The `LogLevel` contract prevents missing or unsupported level entries.
|
|
110
|
+
*/
|
|
111
|
+
declare const logLevelColors: {
|
|
112
|
+
readonly info: typeof kleur_colors.print;
|
|
113
|
+
readonly warn: typeof kleur_colors.print;
|
|
114
|
+
readonly error: typeof kleur_colors.print;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Public placeholder written instead of sensitive query and JSON values.
|
|
118
|
+
* One stable marker keeps redacted output recognizable across log consumers.
|
|
119
|
+
*/
|
|
120
|
+
declare const REDACTED_LOG_VALUE = "[redacted]";
|
|
121
|
+
/**
|
|
122
|
+
* Normalized key fragments treated as sensitive by logging redaction.
|
|
123
|
+
* Matching ignores case and separators so compound field names remain covered.
|
|
124
|
+
*/
|
|
125
|
+
declare const sensitiveLogKeyParts: readonly ["password", "passwd", "token", "secret", "authorization", "apikey", "credential"];
|
|
126
|
+
/**
|
|
127
|
+
* Terminal colors assigned to the supported HTTP response status ranges.
|
|
128
|
+
* Unlisted ranges intentionally retain the terminal's default text appearance.
|
|
129
|
+
*/
|
|
130
|
+
declare const httpStatusColors: readonly [{
|
|
131
|
+
readonly range: readonly [200, 299];
|
|
132
|
+
readonly color: typeof kleur_colors.print;
|
|
133
|
+
}, {
|
|
134
|
+
readonly range: readonly [400, 499];
|
|
135
|
+
readonly color: typeof kleur_colors.print;
|
|
136
|
+
}, {
|
|
137
|
+
readonly range: readonly [500, 599];
|
|
138
|
+
readonly color: typeof kleur_colors.print;
|
|
139
|
+
}];
|
|
140
|
+
|
|
141
|
+
declare const logLevelsArray: readonly ["info", "warn", "error"];
|
|
142
|
+
type LogLevel = (typeof logLevelsArray)[number];
|
|
143
|
+
declare const logLevelsRecord: Readonly<{
|
|
144
|
+
ERROR: "error";
|
|
145
|
+
INFO: "info";
|
|
146
|
+
WARN: "warn";
|
|
147
|
+
}>;
|
|
148
|
+
declare const logLevel: Readonly<{
|
|
149
|
+
ERROR: "error";
|
|
150
|
+
INFO: "info";
|
|
151
|
+
WARN: "warn";
|
|
152
|
+
}>;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Logs Hono request metadata with query parameters and a normalized body preview.
|
|
156
|
+
* Sensitive values are redacted by partial key match before output is written.
|
|
157
|
+
*/
|
|
158
|
+
declare const loggingMiddleware: MiddlewareHandler;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Replaces sensitive query values using partial, case-insensitive key matching.
|
|
162
|
+
* A new collection is returned so the caller's search parameters remain unchanged.
|
|
163
|
+
*/
|
|
164
|
+
declare function redactSensitiveSearchParams(searchParams: URLSearchParams): URLSearchParams;
|
|
165
|
+
/**
|
|
166
|
+
* Replaces values under sensitive keys throughout a serialized JSON structure.
|
|
167
|
+
* Invalid JSON and payloads without matching keys are returned byte-for-byte unchanged.
|
|
168
|
+
*/
|
|
169
|
+
declare function redactSensitiveJSON(json: string): string;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Writes timestamped and colorized messages using a stable service column.
|
|
173
|
+
* Error messages may include a stack trace on a subordinate second line.
|
|
174
|
+
*/
|
|
175
|
+
declare const log: {
|
|
176
|
+
/**
|
|
177
|
+
* Writes an informational message with an optional service label.
|
|
178
|
+
* Missing service names use the shared `log` fallback label.
|
|
179
|
+
*/
|
|
180
|
+
info(message: string, service?: string): void;
|
|
181
|
+
/**
|
|
182
|
+
* Writes a warning message with an optional service label.
|
|
183
|
+
* Missing service names use the shared `log` fallback label.
|
|
184
|
+
*/
|
|
185
|
+
warn(message: string, service?: string): void;
|
|
186
|
+
/**
|
|
187
|
+
* Writes an error message with optional service and stack trace context.
|
|
188
|
+
* Provided stack traces are rendered beneath the primary message.
|
|
189
|
+
*/
|
|
190
|
+
error(message: string, service?: string, stack?: string): void;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Selects a terminal color function for one HTTP response status.
|
|
195
|
+
* Successes are green, client errors yellow, and server errors red.
|
|
196
|
+
*/
|
|
197
|
+
declare function getColoredHTTPStatus(status: number): (text: string) => string;
|
|
198
|
+
|
|
112
199
|
/**
|
|
113
200
|
* Canonical metadata shared by upload controls and runtime validation.
|
|
114
201
|
* Every supported format defines display, MIME, and extension values.
|
|
@@ -500,36 +587,6 @@ declare function measureExecutionTime<T>(execution: () => Promise<T>): Promise<M
|
|
|
500
587
|
*/
|
|
501
588
|
declare function generateRandomString(length?: number): string;
|
|
502
589
|
|
|
503
|
-
/**
|
|
504
|
-
* Selects a terminal color function for one HTTP response status.
|
|
505
|
-
* Successes are green, client errors yellow, and server errors red.
|
|
506
|
-
*
|
|
507
|
-
* @example
|
|
508
|
-
* getColoredHTTPStatus(404)('404');
|
|
509
|
-
*/
|
|
510
|
-
declare function getColoredHTTPStatus(status: number): (text: string) => string;
|
|
511
|
-
/**
|
|
512
|
-
* Shared logging interface for informational, warning, and error messages.
|
|
513
|
-
* Every level supports a service label while errors may include a stack trace.
|
|
514
|
-
*/
|
|
515
|
-
declare const log: {
|
|
516
|
-
/**
|
|
517
|
-
* Writes an informational message with an optional service label.
|
|
518
|
-
* Missing service names use the shared `log` fallback label.
|
|
519
|
-
*/
|
|
520
|
-
info: (message: string, service?: string) => void;
|
|
521
|
-
/**
|
|
522
|
-
* Writes a warning message with an optional service label.
|
|
523
|
-
* Missing service names use the shared `log` fallback label.
|
|
524
|
-
*/
|
|
525
|
-
warn: (message: string, service?: string) => void;
|
|
526
|
-
/**
|
|
527
|
-
* Writes an error message with optional service and stack trace context.
|
|
528
|
-
* Stack traces are rendered beneath the primary error message when supplied.
|
|
529
|
-
*/
|
|
530
|
-
error: (message: string, service?: string, stack?: string) => void;
|
|
531
|
-
};
|
|
532
|
-
|
|
533
590
|
/**
|
|
534
591
|
* Utility type that simplifies a given type T by flattening its structure.
|
|
535
592
|
* This is particularly useful for improving the readability of complex types.
|
|
@@ -832,4 +889,4 @@ declare const asQuery: <T extends z.ZodTypeAny>(schema: T) => z.ZodPreprocess<T>
|
|
|
832
889
|
*/
|
|
833
890
|
declare const isPlainObject: (value: unknown) => value is Record<string, unknown>;
|
|
834
891
|
|
|
835
|
-
export { type APIContractData, type APIContractError, type APIContractResult, type APIError, type APISuccess, type AsQuery, type AtLeastOne, DEFAULT_UPLOAD_MAX_FILE_SIZE, EXCEPTION_STATUS_CODES, type ExceptionStatusCode, type FetchResult, type FileFormat, type FileFormatConfig, type HonoFileRespondOptions, type HonoRespondOptions, type JWTServiceOptions, type JWTSignOptions, type MeasuredExecution, type Payload, type PayloadSchema, type ReplaceDotsWithUnderscores, SUCCESS_STATUS_CODES, type Simplify, type StringEnumRecord, type SuccessStatusCode, type UploadFilesValidationOptions, type UploadFilesValidationResult, type UploadPreset, type UploadValidationError, type ZodBulkExcludeSelection, type ZodBulkIncludeSelection, type ZodBulkSelection, ZodJWTService, type ZodPaginationOptions, type ZodSearchSchemaOptions, type ZodUploadFileSchemaOptions, asQuery, createStringEnumRecord, createUploadAccept, createZodSearchWhereSchema, defineUploadPreset, documentUploadPreset, failure, fetchAndThrow, fetchSafely, fileFormat, fileFormatsArray, fileFormatsConfig, fileFormatsRecord, fileRespond, formatTime, generateRandomString, getColoredHTTPStatus, getFileExtension, getFormattedDate, getFormattedTime, getUTCOffset, getZonedTime,
|
|
892
|
+
export { type APIContractData, type APIContractError, type APIContractResult, type APIError, type APISuccess, type AsQuery, type AtLeastOne, DEFAULT_UPLOAD_MAX_FILE_SIZE, EXCEPTION_STATUS_CODES, type ExceptionStatusCode, type FetchResult, type FileFormat, type FileFormatConfig, type HonoFileRespondOptions, type HonoRespondOptions, type JWTServiceOptions, type JWTSignOptions, type LogLevel, type MeasuredExecution, type Payload, type PayloadSchema, REDACTED_LOG_VALUE, type ReplaceDotsWithUnderscores, SUCCESS_STATUS_CODES, type Simplify, type StringEnumRecord, type SuccessStatusCode, type UploadFilesValidationOptions, type UploadFilesValidationResult, type UploadPreset, type UploadValidationError, type ZodBulkExcludeSelection, type ZodBulkIncludeSelection, type ZodBulkSelection, ZodJWTService, type ZodPaginationOptions, type ZodSearchSchemaOptions, type ZodUploadFileSchemaOptions, asQuery, createStringEnumRecord, createUploadAccept, createZodSearchWhereSchema, defineUploadPreset, documentUploadPreset, failure, fetchAndThrow, fetchSafely, fileFormat, fileFormatsArray, fileFormatsConfig, fileFormatsRecord, fileRespond, formatTime, generateRandomString, getColoredHTTPStatus, getFileExtension, getFormattedDate, getFormattedTime, getUTCOffset, getZonedTime, httpStatusColors, imageUploadPreset, isFileExtensionSupported, isFileFormatSupported, isFileMimeTypeSupported, isPlainObject, log, logLevel, logLevelColors, logLevelsArray, logLevelsRecord, loggingMiddleware, matchesMimeType, measureExecutionTime, normalizeFileExtension, onHandlerError, parseQueryValue, redactSensitiveJSON, redactSensitiveSearchParams, respond, safeExecute, sensitiveLogKeyParts, sqlWhere, success, uploadValidationError, uploadValidationErrorsArray, uploadValidationErrorsRecord, validateUploadFile, validateUploadFiles, zodAtLeastOne, zodBulkSelectionSchema, zodPaginationSchema, zodPaginationShape, zodSearchQuerySchema, zodSearchSchema, zodUploadFileSchema };
|
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@ function sqlWhere(table, where) {
|
|
|
12
12
|
|
|
13
13
|
// src/hono/hono.execution.ts
|
|
14
14
|
import { HTTPException } from "hono/http-exception";
|
|
15
|
-
import { red as
|
|
15
|
+
import { red as red3 } from "kleur/colors";
|
|
16
16
|
|
|
17
17
|
// src/http/http.factory.ts
|
|
18
18
|
function success({ status, data }) {
|
|
@@ -22,19 +22,8 @@ function failure({ status, error }) {
|
|
|
22
22
|
return { kind: "error", status, error };
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
// src/
|
|
26
|
-
|
|
27
|
-
function generateRandomString(length = 10) {
|
|
28
|
-
const randomValues = crypto.getRandomValues(new Uint32Array(length));
|
|
29
|
-
let result = "";
|
|
30
|
-
for (let i = 0; i < length; i++) {
|
|
31
|
-
result += DEFAULT_CHARACTERS[randomValues[i] % DEFAULT_CHARACTERS.length];
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// src/utilities/logging.utilities.ts
|
|
37
|
-
import { blue, dim, green, red, white, yellow } from "kleur/colors";
|
|
25
|
+
// src/logging/logging.services.ts
|
|
26
|
+
import { dim, red as red2, white } from "kleur/colors";
|
|
38
27
|
|
|
39
28
|
// src/utilities/datetime.utilities.ts
|
|
40
29
|
import { format } from "date-fns";
|
|
@@ -62,50 +51,90 @@ function formatTime(time, { locale = ru, tz = "Europe/London" } = {}) {
|
|
|
62
51
|
return `${format(zonedTime, "HH:mm:ss, d MMMM yyyy", { locale })} ${getUTCOffset(zonedTime, tz)}`;
|
|
63
52
|
}
|
|
64
53
|
|
|
65
|
-
// src/
|
|
66
|
-
|
|
54
|
+
// src/logging/logging.constants.ts
|
|
55
|
+
import { blue, green, red, yellow } from "kleur/colors";
|
|
56
|
+
|
|
57
|
+
// src/utilities/enums.utilities.ts
|
|
58
|
+
function createStringEnumRecord(values) {
|
|
59
|
+
return Object.freeze(Object.fromEntries(values.map((value) => [value.replace(/\./g, "_").toUpperCase(), value])));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/logging/logging.enums.ts
|
|
63
|
+
var logLevelsArray = ["info", "warn", "error"];
|
|
64
|
+
var logLevelsRecord = createStringEnumRecord(logLevelsArray);
|
|
65
|
+
var logLevel = logLevelsRecord;
|
|
66
|
+
|
|
67
|
+
// src/logging/logging.constants.ts
|
|
68
|
+
var logLevelColors = {
|
|
69
|
+
[logLevel.INFO]: blue,
|
|
70
|
+
[logLevel.WARN]: yellow,
|
|
71
|
+
[logLevel.ERROR]: red
|
|
72
|
+
};
|
|
73
|
+
var REDACTED_LOG_VALUE = "[redacted]";
|
|
74
|
+
var sensitiveLogKeyParts = [
|
|
75
|
+
"password",
|
|
76
|
+
"passwd",
|
|
77
|
+
"token",
|
|
78
|
+
"secret",
|
|
79
|
+
"authorization",
|
|
80
|
+
"apikey",
|
|
81
|
+
"credential"
|
|
82
|
+
];
|
|
83
|
+
var httpStatusColors = [
|
|
67
84
|
{ range: [200, 299], color: green },
|
|
68
85
|
{ range: [400, 499], color: yellow },
|
|
69
86
|
{ range: [500, 599], color: red }
|
|
70
87
|
];
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const statusColor = HTTP_STATUS_COLORS.find(({ range: [minimum, maximum] }) => {
|
|
74
|
-
return status >= minimum && status <= maximum;
|
|
75
|
-
});
|
|
76
|
-
return statusColor ? statusColor.color : (text) => text;
|
|
77
|
-
}
|
|
88
|
+
|
|
89
|
+
// src/logging/logging.services.ts
|
|
78
90
|
function writeLog(message, level, service = "log", stack) {
|
|
79
91
|
const timestamp = dim(getFormattedTime());
|
|
80
|
-
const serviceName =
|
|
92
|
+
const serviceName = logLevelColors[level](service.padEnd(12));
|
|
81
93
|
const formattedMessage = white(message);
|
|
82
94
|
console.log(`[${timestamp}] ${serviceName} | ${formattedMessage}`);
|
|
83
95
|
if (stack)
|
|
84
|
-
console.log(`[${timestamp}] ${
|
|
96
|
+
console.log(`[${timestamp}] ${red2("\u21B3 trace").padEnd(18)} | ${dim(stack)}`);
|
|
85
97
|
}
|
|
86
98
|
var log = {
|
|
87
99
|
/**
|
|
88
100
|
* Writes an informational message with an optional service label.
|
|
89
101
|
* Missing service names use the shared `log` fallback label.
|
|
90
102
|
*/
|
|
91
|
-
info
|
|
103
|
+
info(message, service) {
|
|
104
|
+
writeLog(message, "info", service);
|
|
105
|
+
},
|
|
92
106
|
/**
|
|
93
107
|
* Writes a warning message with an optional service label.
|
|
94
108
|
* Missing service names use the shared `log` fallback label.
|
|
95
109
|
*/
|
|
96
|
-
warn
|
|
110
|
+
warn(message, service) {
|
|
111
|
+
writeLog(message, "warn", service);
|
|
112
|
+
},
|
|
97
113
|
/**
|
|
98
114
|
* Writes an error message with optional service and stack trace context.
|
|
99
|
-
*
|
|
115
|
+
* Provided stack traces are rendered beneath the primary message.
|
|
100
116
|
*/
|
|
101
|
-
error
|
|
117
|
+
error(message, service, stack) {
|
|
118
|
+
writeLog(message, "error", service, stack);
|
|
119
|
+
}
|
|
102
120
|
};
|
|
103
121
|
|
|
122
|
+
// src/utilities/generation.utilities.ts
|
|
123
|
+
var DEFAULT_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
124
|
+
function generateRandomString(length = 10) {
|
|
125
|
+
const randomValues = crypto.getRandomValues(new Uint32Array(length));
|
|
126
|
+
let result = "";
|
|
127
|
+
for (let i = 0; i < length; i++) {
|
|
128
|
+
result += DEFAULT_CHARACTERS[randomValues[i] % DEFAULT_CHARACTERS.length];
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
|
|
104
133
|
// src/hono/hono.execution.ts
|
|
105
134
|
function proceedUnhandledError(error) {
|
|
106
135
|
const errorId = generateRandomString(6);
|
|
107
136
|
const errorMessage = error instanceof Error ? error.stack ?? error.message : JSON.stringify(error);
|
|
108
|
-
log.error(`Unhandled error: ${
|
|
137
|
+
log.error(`Unhandled error: ${red3(errorMessage)}`, errorId);
|
|
109
138
|
return failure({ status: 500, error: `Internal server error | ${errorId}` });
|
|
110
139
|
}
|
|
111
140
|
var onHandlerError = (error, c) => {
|
|
@@ -117,32 +146,6 @@ var onHandlerError = (error, c) => {
|
|
|
117
146
|
return c.json(response, response.status);
|
|
118
147
|
};
|
|
119
148
|
|
|
120
|
-
// src/hono/hono.logging.ts
|
|
121
|
-
import { blue as blue2, bold, dim as dim2, white as white2 } from "kleur/colors";
|
|
122
|
-
var honoLoggingHandler = async (c, next) => {
|
|
123
|
-
const requestUrl = new URL(c.req.url);
|
|
124
|
-
const searchParams = requestUrl.searchParams.toString();
|
|
125
|
-
const body = c.req.header("content-type")?.includes("multipart/form-data") ? (
|
|
126
|
-
// If the request is multipart/form-data, we avoid reading the body
|
|
127
|
-
// to prevent consuming the stream, and instead log a placeholder.
|
|
128
|
-
"[multipart]"
|
|
129
|
-
) : (
|
|
130
|
-
// Otherwise, we read the request body as text and normalize whitespace.
|
|
131
|
-
(await c.req.raw.clone().text()).replaceAll(/\s+/g, " ").trim()
|
|
132
|
-
);
|
|
133
|
-
const bodyPreview = body.length > 80 ? `${body.slice(0, 40)}\u2026${body.slice(-40)}` : body;
|
|
134
|
-
const startTime = performance.now();
|
|
135
|
-
await next();
|
|
136
|
-
const duration = Math.round(performance.now() - startTime);
|
|
137
|
-
const coloredMethod = bold(blue2(c.req.method.padEnd(4)));
|
|
138
|
-
const coloredStatus = getColoredHTTPStatus(c.res.status)(String(c.res.status).padEnd(4));
|
|
139
|
-
const coloredTime = dim2(`${duration}ms`.padStart(6));
|
|
140
|
-
const coloredPath = white2(c.req.path.padEnd(32));
|
|
141
|
-
const coloredSearchParams = searchParams ? dim2(` (${searchParams})`) : "";
|
|
142
|
-
const coloredBody = bodyPreview ? dim2(` ${bodyPreview}`) : "";
|
|
143
|
-
log.info(`${coloredMethod} ${coloredStatus} ${coloredTime} ${coloredPath}${coloredSearchParams}${coloredBody}`, "hono");
|
|
144
|
-
};
|
|
145
|
-
|
|
146
149
|
// src/hono/hono.respond.ts
|
|
147
150
|
function respond(c, options) {
|
|
148
151
|
return c.json(success({ status: options.status, data: options.data ?? {} }), options.status);
|
|
@@ -171,10 +174,81 @@ async function fetchAndThrow(fetcher) {
|
|
|
171
174
|
return response.data;
|
|
172
175
|
}
|
|
173
176
|
|
|
174
|
-
// src/
|
|
175
|
-
|
|
176
|
-
|
|
177
|
+
// src/logging/logging.middleware.ts
|
|
178
|
+
import { blue as blue2, bold, dim as dim2, white as white2 } from "kleur/colors";
|
|
179
|
+
|
|
180
|
+
// src/logging/logging.security.ts
|
|
181
|
+
function isSensitiveLogKey(key) {
|
|
182
|
+
const normalizedKey = key.toLowerCase().replaceAll(/[^a-z]/g, "");
|
|
183
|
+
return sensitiveLogKeyParts.some((sensitivePart) => normalizedKey.includes(sensitivePart));
|
|
184
|
+
}
|
|
185
|
+
function redactSensitiveValue(value) {
|
|
186
|
+
if (Array.isArray(value)) {
|
|
187
|
+
const entries2 = value.map(redactSensitiveValue);
|
|
188
|
+
return {
|
|
189
|
+
value: entries2.map((entry) => entry.value),
|
|
190
|
+
redacted: entries2.some((entry) => entry.redacted)
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
if (typeof value !== "object" || value === null)
|
|
194
|
+
return { value, redacted: false };
|
|
195
|
+
let redacted = false;
|
|
196
|
+
const entries = Object.entries(value).map(([key, entryValue]) => {
|
|
197
|
+
if (isSensitiveLogKey(key)) {
|
|
198
|
+
redacted = true;
|
|
199
|
+
return [key, REDACTED_LOG_VALUE];
|
|
200
|
+
}
|
|
201
|
+
const nestedEntry = redactSensitiveValue(entryValue);
|
|
202
|
+
redacted ||= nestedEntry.redacted;
|
|
203
|
+
return [key, nestedEntry.value];
|
|
204
|
+
});
|
|
205
|
+
return { value: Object.fromEntries(entries), redacted };
|
|
177
206
|
}
|
|
207
|
+
function redactSensitiveSearchParams(searchParams) {
|
|
208
|
+
const redactedSearchParams = new URLSearchParams(searchParams);
|
|
209
|
+
for (const key of new Set(redactedSearchParams.keys())) {
|
|
210
|
+
if (isSensitiveLogKey(key))
|
|
211
|
+
redactedSearchParams.set(key, REDACTED_LOG_VALUE);
|
|
212
|
+
}
|
|
213
|
+
return redactedSearchParams;
|
|
214
|
+
}
|
|
215
|
+
function redactSensitiveJSON(json) {
|
|
216
|
+
if (json === void 0 || null)
|
|
217
|
+
return json;
|
|
218
|
+
try {
|
|
219
|
+
const parsedValue = JSON.parse(json);
|
|
220
|
+
const result = redactSensitiveValue(parsedValue);
|
|
221
|
+
return result.redacted ? JSON.stringify(result.value) : json;
|
|
222
|
+
} catch {
|
|
223
|
+
return json;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// src/logging/logging.utilities.ts
|
|
228
|
+
function getColoredHTTPStatus(status) {
|
|
229
|
+
const statusColor = httpStatusColors.find(({ range: [minimum, maximum] }) => {
|
|
230
|
+
return status >= minimum && status <= maximum;
|
|
231
|
+
});
|
|
232
|
+
return statusColor ? statusColor.color : (text) => text;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// src/logging/logging.middleware.ts
|
|
236
|
+
var loggingMiddleware = async (c, next) => {
|
|
237
|
+
const contentType = c.req.header("content-type");
|
|
238
|
+
const searchParams = redactSensitiveSearchParams(new URL(c.req.url).searchParams).toString();
|
|
239
|
+
const body = contentType?.includes("multipart/form-data") ? "[multipart]" : redactSensitiveJSON((await c.req.raw.clone().text()).replaceAll(/\s+/g, " ").trim());
|
|
240
|
+
const bodyPreview = body.length > 60 ? `${body.slice(0, 30)}\u2026${body.slice(-30)}` : body;
|
|
241
|
+
const startTime = performance.now();
|
|
242
|
+
await next();
|
|
243
|
+
const duration = Math.round(performance.now() - startTime);
|
|
244
|
+
const coloredMethod = bold(blue2(c.req.method.padEnd(4)));
|
|
245
|
+
const coloredStatus = getColoredHTTPStatus(c.res.status)(String(c.res.status).padEnd(4));
|
|
246
|
+
const coloredTime = dim2(`${duration}ms`.padStart(6));
|
|
247
|
+
const coloredPath = white2(c.req.path.padEnd(32));
|
|
248
|
+
const coloredSearchParams = searchParams ? dim2(` (${searchParams})`) : "";
|
|
249
|
+
const coloredBody = bodyPreview ? dim2(` ${bodyPreview}`) : "";
|
|
250
|
+
log.info(`${coloredMethod} ${coloredStatus} ${coloredTime} ${coloredPath}${coloredSearchParams}${coloredBody}`, "hono");
|
|
251
|
+
};
|
|
178
252
|
|
|
179
253
|
// src/upload/upload.enums.ts
|
|
180
254
|
var fileFormatsArray = [
|
|
@@ -448,6 +522,7 @@ var asQuery = (schema) => z5.preprocess(parseQueryValue, schema);
|
|
|
448
522
|
export {
|
|
449
523
|
DEFAULT_UPLOAD_MAX_FILE_SIZE,
|
|
450
524
|
EXCEPTION_STATUS_CODES,
|
|
525
|
+
REDACTED_LOG_VALUE,
|
|
451
526
|
SUCCESS_STATUS_CODES,
|
|
452
527
|
ZodJWTService,
|
|
453
528
|
asQuery,
|
|
@@ -472,20 +547,28 @@ export {
|
|
|
472
547
|
getFormattedTime,
|
|
473
548
|
getUTCOffset,
|
|
474
549
|
getZonedTime,
|
|
475
|
-
|
|
550
|
+
httpStatusColors,
|
|
476
551
|
imageUploadPreset,
|
|
477
552
|
isFileExtensionSupported,
|
|
478
553
|
isFileFormatSupported,
|
|
479
554
|
isFileMimeTypeSupported,
|
|
480
555
|
isPlainObject,
|
|
481
556
|
log,
|
|
557
|
+
logLevel,
|
|
558
|
+
logLevelColors,
|
|
559
|
+
logLevelsArray,
|
|
560
|
+
logLevelsRecord,
|
|
561
|
+
loggingMiddleware,
|
|
482
562
|
matchesMimeType,
|
|
483
563
|
measureExecutionTime,
|
|
484
564
|
normalizeFileExtension,
|
|
485
565
|
onHandlerError,
|
|
486
566
|
parseQueryValue,
|
|
567
|
+
redactSensitiveJSON,
|
|
568
|
+
redactSensitiveSearchParams,
|
|
487
569
|
respond,
|
|
488
570
|
safeExecute,
|
|
571
|
+
sensitiveLogKeyParts,
|
|
489
572
|
sqlWhere,
|
|
490
573
|
success,
|
|
491
574
|
uploadValidationError,
|