@lokalise/fastify-extras 30.4.0 → 30.5.0

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/README.md CHANGED
@@ -64,6 +64,24 @@ The `getRequestIdFastifyAppConfig()` method is exported and returns:
64
64
 
65
65
  Which can be passed to Fastify during instantiation.
66
66
 
67
+ The `getFastifyAppLoggingConfig(appLogLevel, requestLoggingLevels?)` method is exported and returns Fastify configuration for request logging. It accepts:
68
+
69
+ - `appLogLevel`, the application log level from your app configuration;
70
+ - `requestLoggingLevels` (optional), an array of log levels that should enable request logging. Defaults to `['debug', 'trace', 'info']`.
71
+
72
+ This method returns a `disableRequestLogging` configuration that:
73
+ - Enables request logging only when the app log level is in `requestLoggingLevels`;
74
+ - Automatically skips logging for service utility endpoints (`/`, `/health`, `/ready`, `/live`, `/metrics`).
75
+
76
+ Example usage:
77
+ ```typescript
78
+ import { getFastifyAppLoggingConfig } from '@lokalise/fastify-extras'
79
+
80
+ const app = fastify({
81
+ ...getFastifyAppLoggingConfig(appConfig.logLevel),
82
+ })
83
+ ```
84
+
67
85
  ### Public Healthcheck Plugin
68
86
 
69
87
  Plugin to monitor app status through public healthcheck.
package/dist/index.d.ts CHANGED
@@ -38,4 +38,4 @@ export { createErrorHandler, isZodError, type ErrorResponseObject } from './erro
38
38
  export type { ErrorHandlerParams, FreeformRecord } from './errors/errorHandler.js';
39
39
  export { generateJwtToken, decodeJwtToken } from './jwt-utils/tokenUtils.js';
40
40
  export { createStaticTokenAuthPreHandler } from './route-utils/authPreHandlers.js';
41
- export type { AnyFastifyInstance, CommonFastifyInstance } from './plugins/pluginsCommon.js';
41
+ export { getFastifyAppLoggingConfig, type AnyFastifyInstance, type CommonFastifyInstance, } from './plugins/pluginsCommon.js';
package/dist/index.js CHANGED
@@ -21,4 +21,5 @@ export { unhandledExceptionPlugin, commonErrorObjectResolver, } from './plugins/
21
21
  export { createErrorHandler, isZodError } from './errors/errorHandler.js';
22
22
  export { generateJwtToken, decodeJwtToken } from './jwt-utils/tokenUtils.js';
23
23
  export { createStaticTokenAuthPreHandler } from './route-utils/authPreHandlers.js';
24
+ export { getFastifyAppLoggingConfig, } from './plugins/pluginsCommon.js';
24
25
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACpB,cAAc,GACf,MAAM,4BAA4B,CAAA;AAGnC,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,GAC7B,MAAM,2CAA2C,CAAA;AAGlD,OAAO,EACL,gCAAgC,EAChC,0BAA0B,GAC3B,MAAM,+CAA+C,CAAA;AAGtD,OAAO,EACL,qCAAqC,EACrC,+BAA+B,GAChC,MAAM,oDAAoD,CAAA;AAG3D,OAAO,EACL,2BAA2B,EAC3B,qBAAqB,GACtB,MAAM,0CAA0C,CAAA;AAGjD,OAAO,EACL,wBAAwB,EACxB,4BAA4B,GAC7B,MAAM,mDAAmD,CAAA;AAO1D,OAAO,EAAE,mCAAmC,EAAE,MAAM,6DAA6D,CAAA;AAEjH,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AAEtE,OAAO,EACL,yBAAyB,EACzB,kCAAkC,GACnC,MAAM,+CAA+C,CAAA;AAGtD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAM1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,kDAAkD,CAAA;AAO1F,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAA;AAG7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,kDAAkD,CAAA;AAG1F,OAAO,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAA;AAG5F,OAAO,EAAE,2BAA2B,EAAE,MAAM,sDAAsD,CAAA;AAGlG,OAAO,EACL,eAAe,GAGhB,MAAM,wCA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EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAA;AAG7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,kDAAkD,CAAA;AAG1F,OAAO,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAA;AAG5F,OAAO,EAAE,2BAA2B,EAAE,MAAM,sDAAsD,CAAA;AAGlG,OAAO,EACL,eAAe,GAGhB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAA;AAC5D,OAAO,EACL,gBAAgB,EAChB,6BAA6B,GAG9B,MAAM,yCAAyC,CAAA;AAIhD,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAA;AAEhF,OAAO,EACL,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,uCAAuC,CAAA;AAG9C,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAA4B,MAAM,0BAA0B,CAAA;AAGnG,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAE5E,OAAO,EAAE,+BAA+B,EAAE,MAAM,kCAAkC,CAAA;AAClF,OAAO,EACL,0BAA0B,GAG3B,MAAM,4BAA4B,CAAA"}
@@ -1,4 +1,5 @@
1
- import type { CommonLogger } from '@lokalise/node-core';
2
- import type { FastifyInstance, FastifyTypeProviderDefault, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerDefault } from 'fastify';
1
+ import type { AppConfig, CommonLogger } from '@lokalise/node-core';
2
+ import type { FastifyInstance, FastifyServerOptions, FastifyTypeProviderDefault, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerDefault } from 'fastify';
3
3
  export type CommonFastifyInstance = FastifyInstance<RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, CommonLogger, FastifyTypeProviderDefault>;
4
4
  export type AnyFastifyInstance = FastifyInstance<any, any, any, any, any>;
5
+ export declare function getFastifyAppLoggingConfig(appLogLevel: AppConfig['logLevel'], requestLoggingLevels?: string[]): Pick<FastifyServerOptions, 'disableRequestLogging'>;
@@ -1,2 +1,12 @@
1
- export {};
1
+ // Service utility endpoints to exclude from request logging
2
+ const REQUEST_LOGGING_SKIP_PATHS = new Set(['/', '/health', '/ready', '/live', '/metrics']);
3
+ const REQUEST_LOGGING_LEVELS = ['debug', 'trace', 'info'];
4
+ export function getFastifyAppLoggingConfig(appLogLevel, requestLoggingLevels = REQUEST_LOGGING_LEVELS) {
5
+ const enableRequestLogging = requestLoggingLevels.includes(appLogLevel);
6
+ return {
7
+ disableRequestLogging: enableRequestLogging
8
+ ? (req) => REQUEST_LOGGING_SKIP_PATHS.has(req.url)
9
+ : true,
10
+ };
11
+ }
2
12
  //# sourceMappingURL=pluginsCommon.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pluginsCommon.js","sourceRoot":"","sources":["../../lib/plugins/pluginsCommon.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"pluginsCommon.js","sourceRoot":"","sources":["../../lib/plugins/pluginsCommon.ts"],"names":[],"mappings":"AAqBA,4DAA4D;AAC5D,MAAM,0BAA0B,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAA;AAC3F,MAAM,sBAAsB,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;AAEzD,MAAM,UAAU,0BAA0B,CACxC,WAAkC,EAClC,oBAAoB,GAAG,sBAAsB;IAE7C,MAAM,oBAAoB,GAAG,oBAAoB,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA;IACvE,OAAO;QACL,qBAAqB,EAAE,oBAAoB;YACzC,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,0BAA0B,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;YAClD,CAAC,CAAC,IAAI;KACT,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lokalise/fastify-extras",
3
- "version": "30.4.0",
3
+ "version": "30.5.0",
4
4
  "description": "Opinionated set of fastify plugins, commonly used in Lokalise",
5
5
  "author": {
6
6
  "name": "Lokalise",
@@ -52,7 +52,7 @@
52
52
  "@lokalise/node-core": ">=14.0.0",
53
53
  "@opentelemetry/api": ">=1.9.0",
54
54
  "bullmq": "^5.19.0",
55
- "fastify": "^5.5.0",
55
+ "fastify": "^5.7.1",
56
56
  "fastify-type-provider-zod": ">=6.0.0",
57
57
  "ioredis": "^5.7.0",
58
58
  "newrelic": ">=11.13.0",
@@ -72,11 +72,11 @@
72
72
  "@types/node": "^24.7.0",
73
73
  "@vitest/coverage-v8": "^3.2.4",
74
74
  "auto-changelog": "^2.4.0",
75
- "bullmq": "^5.61.0",
76
- "fastify": "^5.6.1",
75
+ "bullmq": "^5.67.1",
76
+ "fastify": "^5.7.2",
77
77
  "fastify-type-provider-zod": "^6.0.0",
78
78
  "ioredis": "^5.6.1",
79
- "newrelic": "13.9.2",
79
+ "newrelic": "13.10.0",
80
80
  "pino": "^10.0.0",
81
81
  "pino-pretty": "^13.1.1",
82
82
  "rimraf": "^6.0.1",