@platformatic/service 2.62.1 → 2.63.1

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/config.d.ts CHANGED
@@ -64,6 +64,14 @@ export interface PlatformaticService {
64
64
  [k: string]: unknown;
65
65
  };
66
66
  };
67
+ formatters?: {
68
+ path: string;
69
+ };
70
+ timestamp?: "epochTime" | "unixTime" | "nullTime" | "isoTime";
71
+ redact?: {
72
+ paths: string[];
73
+ censor?: string;
74
+ };
67
75
  [k: string]: unknown;
68
76
  };
69
77
  loggerInstance?: {
package/lib/stackable.js CHANGED
@@ -10,7 +10,7 @@ const { client, collectMetrics } = require('@platformatic/metrics')
10
10
  const httpMetrics = require('@platformatic/fastify-http-metrics')
11
11
  const { extractTypeScriptCompileOptionsFromConfig } = require('./compile')
12
12
  const { compile } = require('@platformatic/ts-compiler')
13
- const { deepmerge } = require('@platformatic/utils')
13
+ const { deepmerge, buildPinoFormatters, buildPinoTimestamp } = require('@platformatic/utils')
14
14
 
15
15
  const kITC = Symbol.for('plt.runtime.itc')
16
16
 
@@ -56,7 +56,8 @@ class ServiceStackable {
56
56
  runtimeBasePath: this.runtimeConfig?.basePath ?? null,
57
57
  invalidateHttpCache: this.#invalidateHttpCache.bind(this),
58
58
  prometheus: { client, registry: this.metricsRegistry },
59
- setCustomHealthCheck: this.setCustomHealthCheck.bind(this)
59
+ setCustomHealthCheck: this.setCustomHealthCheck.bind(this),
60
+ setCustomReadinessCheck: this.setCustomReadinessCheck.bind(this)
60
61
  })
61
62
  }
62
63
 
@@ -111,6 +112,7 @@ class ServiceStackable {
111
112
  async getConfig () {
112
113
  const config = Object.assign({}, this.configManager.current)
113
114
  config.server = Object.assign({}, config.server)
115
+
114
116
  const logger = config.server.loggerInstance
115
117
 
116
118
  if (logger) {
@@ -190,6 +192,17 @@ class ServiceStackable {
190
192
  return await this.customHealthCheck()
191
193
  }
192
194
 
195
+ setCustomReadinessCheck (fn) {
196
+ this.customReadinessCheck = fn
197
+ }
198
+
199
+ async getCustomReadinessCheck () {
200
+ if (!this.customReadinessCheck) {
201
+ return true
202
+ }
203
+ return await this.customReadinessCheck()
204
+ }
205
+
193
206
  // This method is not a part of Stackable interface because we need to register
194
207
  // fastify metrics before the server is started.
195
208
  async #collectMetrics () {
@@ -390,6 +403,13 @@ class ServiceStackable {
390
403
  pinoOptions.base = { pid: process.pid, hostname: hostname(), worker: this.context.worker.index }
391
404
  }
392
405
 
406
+ if (this.loggerConfig?.formatters) {
407
+ pinoOptions.formatters = buildPinoFormatters(this.loggerConfig?.formatters)
408
+ }
409
+ if (this.loggerConfig?.timestamp) {
410
+ pinoOptions.timestamp = buildPinoTimestamp(this.loggerConfig?.timestamp)
411
+ }
412
+
393
413
  this.logger = pino(pinoOptions)
394
414
 
395
415
  // Only one of logger and loggerInstance should be set
package/lib/utils.js CHANGED
@@ -3,6 +3,7 @@
3
3
  const { access, readFile, stat } = require('node:fs/promises')
4
4
  const { resolve, join, relative, dirname, basename } = require('node:path')
5
5
  const { isatty } = require('tty')
6
+ const { setPinoFormatters, setPinoTimestamp } = require('@platformatic/utils')
6
7
 
7
8
  async function isFileAccessible (filename, directory) {
8
9
  try {
@@ -16,27 +17,36 @@ async function isFileAccessible (filename, directory) {
16
17
 
17
18
  /* c8 ignore start */
18
19
  function addLoggerToTheConfig (config) {
20
+ if (config.server?.loggerInstance) {
21
+ return
22
+ }
23
+
19
24
  // We might have a config with no server
20
25
  if (!config.server) {
21
26
  config.server = {}
22
27
  }
23
- // Set the logger if not present
24
- if (!config.server.loggerInstance) {
25
- let logger = config.server.logger
26
- if (!logger) {
27
- config.server.logger = { level: 'info' }
28
- logger = config.server.logger
29
- }
30
28
 
31
- // If TTY use pino-pretty
32
- if (isatty(1)) {
33
- if (!logger.transport) {
34
- logger.transport = {
35
- target: 'pino-pretty',
36
- }
29
+ let logger = config.server.logger
30
+ if (!logger) {
31
+ config.server.logger = { level: 'info' }
32
+ logger = config.server.logger
33
+ }
34
+
35
+ // If TTY use pino-pretty
36
+ if (isatty(1)) {
37
+ if (!logger.transport) {
38
+ logger.transport = {
39
+ target: 'pino-pretty',
37
40
  }
38
41
  }
39
42
  }
43
+
44
+ if (config.server.logger?.formatters) {
45
+ setPinoFormatters(config.server.logger)
46
+ }
47
+ if (config.server.logger?.timestamp) {
48
+ setPinoTimestamp(config.server.logger)
49
+ }
40
50
  }
41
51
  /* c8 ignore stop */
42
52
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/service",
3
- "version": "2.62.1",
3
+ "version": "2.63.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -20,7 +20,7 @@
20
20
  "@fastify/aws-lambda": "^5.0.0",
21
21
  "@fastify/compress": "^8.0.0",
22
22
  "bindings": "^1.5.0",
23
- "borp": "^0.19.0",
23
+ "borp": "^0.20.0",
24
24
  "eslint": "9",
25
25
  "json-schema-to-typescript": "^15.0.0",
26
26
  "neostandard": "^0.12.0",
@@ -31,7 +31,7 @@
31
31
  "strip-ansi": "^7.1.0",
32
32
  "tsd": "^0.32.0",
33
33
  "typescript": "^5.5.4",
34
- "undici": "7.4.0",
34
+ "undici": "7.8.0",
35
35
  "vscode-json-languageservice": "^5.3.9",
36
36
  "why-is-node-running": "^2.2.2",
37
37
  "yaml": "^2.4.1"
@@ -47,7 +47,7 @@
47
47
  "@fastify/swagger": "^9.0.0",
48
48
  "@fastify/under-pressure": "^9.0.0",
49
49
  "@platformatic/fastify-http-metrics": "^0.3.0",
50
- "@scalar/fastify-api-reference": "1.28.23",
50
+ "@scalar/fastify-api-reference": "1.28.31",
51
51
  "@types/ws": "^8.5.10",
52
52
  "ajv": "^8.12.0",
53
53
  "cli-progress": "^3.12.0",
@@ -76,14 +76,14 @@
76
76
  "rfdc": "^1.3.1",
77
77
  "semgrator": "^0.3.0",
78
78
  "undici": "^7.0.0",
79
- "@platformatic/client": "2.62.1",
80
- "@platformatic/config": "2.62.1",
81
- "@platformatic/generators": "2.62.1",
82
- "@platformatic/scalar-theme": "2.62.1",
83
- "@platformatic/metrics": "2.62.1",
84
- "@platformatic/telemetry": "2.62.1",
85
- "@platformatic/utils": "2.62.1",
86
- "@platformatic/ts-compiler": "2.62.1"
79
+ "@platformatic/config": "2.63.1",
80
+ "@platformatic/client": "2.63.1",
81
+ "@platformatic/generators": "2.63.1",
82
+ "@platformatic/metrics": "2.63.1",
83
+ "@platformatic/scalar-theme": "2.63.1",
84
+ "@platformatic/telemetry": "2.63.1",
85
+ "@platformatic/utils": "2.63.1",
86
+ "@platformatic/ts-compiler": "2.63.1"
87
87
  },
88
88
  "scripts": {
89
89
  "test": "pnpm run lint && borp -T --concurrency=1 --timeout=300000 && tsd",
package/schema.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/service/2.62.1.json",
3
- "version": "2.62.1",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/service/2.63.1.json",
3
+ "version": "2.63.1",
4
4
  "title": "Platformatic Service",
5
5
  "type": "object",
6
6
  "properties": {
@@ -180,6 +180,46 @@
180
180
  }
181
181
  },
182
182
  "additionalProperties": false
183
+ },
184
+ "formatters": {
185
+ "type": "object",
186
+ "properties": {
187
+ "path": {
188
+ "type": "string",
189
+ "resolvePath": true
190
+ }
191
+ },
192
+ "required": [
193
+ "path"
194
+ ],
195
+ "additionalProperties": false
196
+ },
197
+ "timestamp": {
198
+ "enum": [
199
+ "epochTime",
200
+ "unixTime",
201
+ "nullTime",
202
+ "isoTime"
203
+ ]
204
+ },
205
+ "redact": {
206
+ "type": "object",
207
+ "properties": {
208
+ "paths": {
209
+ "type": "array",
210
+ "items": {
211
+ "type": "string"
212
+ }
213
+ },
214
+ "censor": {
215
+ "type": "string",
216
+ "default": "[redacted]"
217
+ }
218
+ },
219
+ "required": [
220
+ "paths"
221
+ ],
222
+ "additionalProperties": false
183
223
  }
184
224
  },
185
225
  "required": [