keryx 0.12.2 → 0.12.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.
@@ -100,6 +100,7 @@ export class Connection<
100
100
  let error: TypedError | undefined;
101
101
 
102
102
  let action: Action | undefined;
103
+ let formattedParams: Record<string, unknown> | undefined;
103
104
  try {
104
105
  action = this.findAction(actionName);
105
106
  if (!action) {
@@ -112,7 +113,7 @@ export class Connection<
112
113
  // load the session once, if it hasn't been loaded yet
113
114
  if (!this.sessionLoaded) await this.loadSession();
114
115
 
115
- let formattedParams = await this.formatParams(params, action);
116
+ formattedParams = await this.formatParams(params, action);
116
117
 
117
118
  for (const middleware of action.middleware ?? []) {
118
119
  if (middleware.runBefore) {
@@ -145,17 +146,6 @@ export class Connection<
145
146
  } else {
146
147
  response = await action.run(formattedParams, this);
147
148
  }
148
-
149
- for (const middleware of action.middleware ?? []) {
150
- if (middleware.runAfter) {
151
- const middlewareResponse = await middleware.runAfter(
152
- formattedParams,
153
- this,
154
- );
155
- if (middlewareResponse && middlewareResponse?.updatedResponse)
156
- response = middlewareResponse.updatedResponse;
157
- }
158
- }
159
149
  } catch (e) {
160
150
  loggerResponsePrefix = "ERROR";
161
151
  error =
@@ -166,6 +156,19 @@ export class Connection<
166
156
  type: ErrorType.CONNECTION_ACTION_RUN,
167
157
  originalError: e,
168
158
  });
159
+ } finally {
160
+ if (action && formattedParams) {
161
+ for (const middleware of action.middleware ?? []) {
162
+ if (middleware.runAfter) {
163
+ const middlewareResponse = await middleware.runAfter(
164
+ formattedParams,
165
+ this,
166
+ );
167
+ if (middlewareResponse && middlewareResponse?.updatedResponse)
168
+ response = middlewareResponse.updatedResponse;
169
+ }
170
+ }
171
+ }
169
172
  }
170
173
 
171
174
  const duration = new Date().getTime() - reqStartTime;
@@ -410,9 +413,20 @@ const sanitizeParams = (
410
413
  }
411
414
  }
412
415
 
416
+ const maxParamLength = config.logger.maxParamLength;
417
+
413
418
  for (const [k, v] of Object.entries(params)) {
414
419
  if (secretFields.has(k)) {
415
420
  sanitizedParams[k] = REDACTED;
421
+ } else if (maxParamLength > 0) {
422
+ const stringified = typeof v === "string" ? v : JSON.stringify(v);
423
+ if (stringified && stringified.length > maxParamLength) {
424
+ sanitizedParams[k] =
425
+ stringified.slice(0, maxParamLength) +
426
+ `... (truncated, original length: ${stringified.length})`;
427
+ } else {
428
+ sanitizedParams[k] = v;
429
+ }
416
430
  } else {
417
431
  sanitizedParams[k] = v;
418
432
  }
package/config/logger.ts CHANGED
@@ -6,4 +6,6 @@ export const configLogger = {
6
6
  includeTimestamps: await loadFromEnvIfSet("LOG_INCLUDE_TIMESTAMPS", true),
7
7
  colorize: await loadFromEnvIfSet("LOG_COLORIZE", true),
8
8
  format: await loadFromEnvIfSet<LogFormat>("LOG_FORMAT", LogFormat.text),
9
+ /** Maximum length of individual param values in action logs before truncation. Set to 0 to disable truncation. */
10
+ maxParamLength: await loadFromEnvIfSet("LOG_MAX_PARAM_LENGTH", 100),
9
11
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keryx",
3
- "version": "0.12.2",
3
+ "version": "0.12.4",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "license": "MIT",